* Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2011-2013 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Ferran Marcet * Copyright (C) 2014-2015 Charlie Benke * Copyright (C) 2015-2016 Abbes Bahfir * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/fichinter/card.php * \brief Page of intervention * \ingroup ficheinter */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } if ($conf->contrat->enabled) { require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php"; require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"; } if (! empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php")) { require_once DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php'; } require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("bills"); $langs->load("companies"); $langs->load("interventions"); $id = GETPOST('id','int'); $ref = GETPOST('ref','alpha'); $socid = GETPOST('socid','int'); $contratid = GETPOST('contratid','int'); $action = GETPOST('action','alpha'); $confirm = GETPOST('confirm','alpha'); $mesg = GETPOST('msg','alpha'); $origin=GETPOST('origin','alpha'); $originid=(GETPOST('originid','int')?GETPOST('originid','int'):GETPOST('origin_id','int')); // For backward compatibility $note_public = GETPOST('note_public'); $lineid = GETPOST('line_id','int'); //PDF $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'ficheinter', $id, 'fichinter'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('interventioncard','globalcard')); $object = new Fichinter($db); $extrafields = new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Load object if ($id > 0 || ! empty($ref)) { $ret=$object->fetch($id, $ref); if ($ret > 0) $ret=$object->fetch_thirdparty(); if ($ret < 0) dol_print_error('',$object->error); } $permissionnote=$user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink=$user->rights->ficheinter->creer; // Used by the include of actions_dellink.inc.php /* * Actions */ $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->ficheinter->creer) { if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { if ($object->id > 0) { // Because createFromClone modifies the object, we must clone it so that we can restore it later $orig = clone $object; $result=$object->createFromClone($socid); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); $object = $orig; $action=''; } } } } if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer) { $result = $object->setValid($user); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->modelpdf:GETPOST('model','alpha'), $outputlangs); } header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { $mesg='
'.$object->error.'
'; } } else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) { $result = $object->setDraft($user); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->modelpdf:GETPOST('model','alpha'), $outputlangs); } header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { $mesg='
'.$object->error.'
'; } } else if ($action == 'add' && $user->rights->ficheinter->creer) { $object->socid = $socid; $object->duration = GETPOST('duration','int'); $object->fk_project = GETPOST('projectid','int'); $object->fk_contrat = GETPOST('contratid','int'); $object->author = $user->id; $object->description = GETPOST('description'); $object->ref = $ref; $object->modelpdf = GETPOST('model','alpha'); $object->note_private = GETPOST('note_private'); $object->note_public = GETPOST('note_public'); if ($object->socid > 0) { // If creation from another object of another module (Example: origin=propal, originid=1) if (!empty($origin) && !empty($originid) ) { // Parse element/subelement (ex: project_task) $element = $subelement = $_POST['origin']; if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) { $element = $regs[1]; $subelement = $regs[2]; } // For compatibility if ($element == 'order') { $element = $subelement = 'commande'; } if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } if ($element == 'contract') { $element = $subelement = 'contrat'; } $object->origin = $origin; $object->origin_id = $originid; // Possibility to add external linked objects with hooks $object->linked_objects[$object->origin] = $object->origin_id; if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) { $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } // Extrafields $extrafields = new ExtraFields($db); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $array_options = $extrafields->getOptionalsFromPost($extralabels); $object->array_options = $array_options; $id = $object->create($user); if ($id > 0) { dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $classname = ucfirst($subelement); $srcobject = new $classname($db); dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); $result=$srcobject->fetch($object->origin_id); if ($result > 0) { $srcobject->fetch_thirdparty(); $lines = $srcobject->lines; if (empty($lines) && method_exists($srcobject,'fetch_lines')) { $srcobject->fetch_lines(); $lines = $srcobject->lines; } $fk_parent_line=0; $num=count($lines); for ($i=0;$i<$num;$i++) { $product_type=($lines[$i]->product_type?$lines[$i]->product_type:Product::TYPE_PRODUCT); if ($product_type == Product::TYPE_SERVICE || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products $duration = 3600; // Default to one hour // Predefined products & services if ($lines[$i]->fk_product > 0) { $prod = new Product($db); $prod->id = $lines[$i]->fk_product; // Define output language if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $prod->getMultiLangs(); // We show if duration is present on service (so we get it) $prod->fetch($lines[$i]->fk_product); $outputlangs = $langs; $newlang=''; if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); if (empty($newlang)) $newlang=$srcobject->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label; } else { $prod->fetch($lines[$i]->fk_product); $label .= $lines[$i]->product_label; } if ($prod->duration_value && $conf->global->FICHINTER_USE_SERVICE_DURATION) { switch ($prod->duration_unit) { default: case 'h': $mult = 3600; break; case 'd': $mult = 3600 * 24; break; case 'w': $mult = 3600 * 24 * 7; break; case 'm': $mult = (int) 3600 * 24 * (365 / 12); // Average month duration break; case 'y': $mult = 3600 * 24 * 365; break; } $duration = $prod->duration_value * $mult * $lines[$i]->qty; } $desc = $lines[$i]->product_ref; $desc .= ' - '; $desc .= $label; $desc .= '
'; } // Common part (predefined or free line) $desc .= dol_htmlentitiesbr($lines[$i]->desc); $desc .= '
'; $desc .= ' (' . $langs->trans('Quantity') . ': ' . $lines[$i]->qty . ')'; $timearray=dol_getdate(mktime()); $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); if ($product_type == Product::TYPE_PRODUCT) { $duration = 0; } $predef = ''; // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); $result = $object->addline( $user, $id, $desc, $date_intervention, $duration, $array_options ); if ($result < 0) { $error++; break; } } } } else { $mesg=$srcobject->error; $error++; } } else { $mesg=$object->error; $error++; } } else { // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) { $error ++; $action = 'create'; } if (! $error) { // Extrafields $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $array_options = $extrafields->getOptionalsFromPost($extralabels); $object->array_options = $array_options; $result = $object->create($user); if ($result > 0) { $id=$result; // Force raffraichissement sur fiche venant d'etre cree } else { $langs->load("errors"); setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; } } } } else { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'
'; $action = 'create'; } } else if ($action == 'update' && $user->rights->ficheinter->creer) { $object->socid = $socid; $object->fk_project = GETPOST('projectid','int'); $object->fk_contrat = GETPOST('contratid','int'); $object->author = $user->id; $object->description = GETPOST('description','alpha'); $object->ref = $ref; $result=$object->update($user); if ($result<0) { setEventMessages($object->error, $object->errors, 'errors'); } } /* * Build doc */ else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post { $object->fetch_lines(); // Save last template used to generate document if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } } // Remove file in doc form else if ($action == 'remove_file') { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $object->fetch_thirdparty(); $langs->load("other"); $upload_dir = $conf->ficheinter->dir_output; $file = $upload_dir . '/' . GETPOST('file'); $ret=dol_delete_file($file,0,0,0,$object); if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); } // Set into a project else if ($action == 'classin' && $user->rights->ficheinter->creer) { $result=$object->setProject(GETPOST('projectid','int')); if ($result < 0) dol_print_error($db,$object->error); } // Set into a contract else if ($action == 'setcontract' && $user->rights->contrat->creer) { $result=$object->set_contrat($user,GETPOST('contratid','int')); if ($result < 0) dol_print_error($db,$object->error); } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) { $result=$object->delete($user); if ($result<0) { setEventMessages($object->error, $object->errors, 'errors'); } header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter'); exit; } else if ($action == 'setdescription' && $user->rights->ficheinter->creer) { $result=$object->set_description($user,GETPOST('description')); if ($result < 0) dol_print_error($db,$object->error); } // Add line else if ($action == "addline" && $user->rights->ficheinter->creer) { if (!GETPOST('np_desc') && empty($conf->global->FICHINTER_EMPTY_LINE_DESC) ) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'
'; $error++; } if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && !GETPOST('durationhour','int') && !GETPOST('durationmin','int')) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'
'; $error++; } if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && GETPOST('durationhour','int') >= 24 && GETPOST('durationmin','int') > 0) { $mesg='
'.$langs->trans("ErrorValueTooHigh").'
'; $error++; } if (! $error) { $db->begin(); $desc=GETPOST('np_desc'); $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); $duration = empty($conf->global->FICHINTER_WITHOUT_DURATION)?convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')) : 0; // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); $result=$object->addline( $user, $id, $desc, $date_intervention, $duration, $array_options ); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } if ($result >= 0) { $db->commit(); if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { $mesg=$object->error; $db->rollback(); } } } // Classify Billed else if ($action == 'classifybilled' && $user->rights->ficheinter->creer) { $result=$object->setStatut(2); if ($result > 0) { header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } // Classify Billed else if ($action == 'classifyunbilled' && $user->rights->ficheinter->creer) { $result=$object->setStatut(1); if ($result > 0) { header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { $mesg='
'.$object->error.'
'; } } // Classify Billed else if ($action == 'classifydone' && $user->rights->ficheinter->creer) { $result=$object->setStatut(3); if ($result > 0) { header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } /* * Mise a jour d'une ligne d'intervention */ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save")) { $objectline = new FichinterLigne($db); if ($objectline->fetch($lineid) <= 0) { dol_print_error($db); exit; } if ($object->fetch($objectline->fk_fichinter) <= 0) { dol_print_error($db); exit; } $object->fetch_thirdparty(); $desc = GETPOST('np_desc'); $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int')); $objectline->datei = $date_inter; $objectline->desc = $desc; $objectline->duration = $duration; // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); $objectline->array_options = $array_options; $result = $objectline->update($user); if ($result < 0) { dol_print_error($db); exit; } // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } /* * Supprime une ligne d'intervention AVEC confirmation */ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer) { $objectline = new FichinterLigne($db); if ($objectline->fetch($lineid) <= 0) { dol_print_error($db); exit; } $result=$objectline->deleteline($user); if ($object->fetch($objectline->fk_fichinter) <= 0) { dol_print_error($db); exit; } // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); } /* * Ordonnancement des lignes */ else if ($action == 'up' && $user->rights->ficheinter->creer) { $object->line_up($lineid); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid); exit; } else if ($action == 'down' && $user->rights->ficheinter->creer) { $object->line_down($lineid); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid); exit; } /* * Send mail */ // Actions to send emails $actiontypecode='AC_OTH_AUTO'; $trigger_name='FICHINTER_SENTBYMAIL'; $paramname='id'; $mode='emailfromintervention'; $trackid='int'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); if ($ret < 0) $error++; if (! $error) { // Actions on extra fields (by external module or standard code) // TODO le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('interventiondao')); $parameters=array('id'=>$object->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { $result=$object->updateExtraField($_POST["attribute"]); if ($result < 0) { $error++; } } else if ($reshook < 0) $error++; } if ($error) $action = 'edit_extras'; } if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) { if ($action == 'addcontact') { if ($result > 0 && $id > 0) { $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha')); } if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; } else { $mesg = '
'.$object->error.'
'; } } } // bascule du statut d'un contact else if ($action == 'swapstatut') { $result=$object->swapContactStatus(GETPOST('ligne','int')); } // Efface un contact else if ($action == 'deletecontact') { $result = $object->delete_contact(GETPOST('lineid','int')); if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { dol_print_error($db); } } } } /* * View */ $form = new Form($db); $formfile = new FormFile($db); if ($conf->contrat->enabled) $formcontract = new FormContract($db); if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } llxHeader('',$langs->trans("Intervention")); if ($action == 'create') { /* * Mode creation * Creation d'une nouvelle fiche d'intervention */ $soc=new Societe($db); print load_fiche_titre($langs->trans("AddIntervention")); dol_htmloutput_mesg($mesg); if ($socid) $res=$soc->fetch($socid); if (GETPOST('origin') && GETPOST('originid')) { // Parse element/subelement (ex: project_task) $element = $subelement = GETPOST('origin'); if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) { $element = $regs[1]; $subelement = $regs[2]; } if ($element == 'project') { $projectid=GETPOST('originid'); } else { // For compatibility if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } if ($element == 'contract') { $element = $subelement = 'contrat'; } dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $classname = ucfirst($subelement); $objectsrc = new $classname($db); $objectsrc->fetch(GETPOST('originid')); if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) { $objectsrc->fetch_lines(); $lines = $objectsrc->lines; } $objectsrc->fetch_thirdparty(); $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); $soc = $objectsrc->client; $note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private'))); $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public')); // Object source contacts list $srccontactslist = $objectsrc->liste_contact(-1,'external',1); } } else { $projectid = GETPOST('projectid','int'); } if (! $conf->global->FICHEINTER_ADDON) { dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined")); exit; } $object->date = dol_now(); $obj = $conf->global->FICHEINTER_ADDON; $obj = "mod_".$obj; //$modFicheinter = new $obj; //$numpr = $modFicheinter->getNextValue($soc, $object); if ($socid > 0) { $soc=new Societe($db); $soc->fetch($socid); print '
'; print ''; dol_fiche_head(''); print ''; print ''; print ''; print ''; // Ref print ''; // Description (must be a textarea and not html must be allowed (used in list view) print ''; print ''; // Project if (! empty($conf->projet->enabled)) { $formproject=new FormProjets($db); $langs->load("project"); print ''; } // Contract if ($conf->contrat->enabled) { $langs->load("contracts"); print ''; } // Model print ''; print ''; print '"; // Public note print ''; print ''; print ''; // Private note if (empty($user->societe_id)) { print ''; print ''; print ''; } // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); } // Show link to origin object if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { $newclassname=$classname; if ($newclassname=='Propal') $newclassname='CommercialProposal'; print ''; } print '
'.$langs->trans("ThirdParty").''.$soc->getNomUrl(1).'
'.$langs->trans('Ref').''.$langs->trans("Draft").'
'.$langs->trans("Description").''; print ''; print '
'.$langs->trans("Project").''; /* Fix: If a project must be linked to any companies (suppliers or not), project must be not be set as limited to customer but must be not linked to any particular thirdparty if ($societe->fournisseur==1) $numprojet=select_projects(-1,$_POST["projectid"],'projectid'); else $numprojet=select_projects($societe->id,$_POST["projectid"],'projectid'); */ $numprojet=$formproject->select_projects($soc->id,$projectid,'projectid'); if ($numprojet==0) { print '   '.$langs->trans("AddProject").''; } print '
'.$langs->trans("Contract").''; $numcontrat=$formcontract->select_contract($soc->id,GETPOST('contratid','int'),'contratid',0,1); if ($numcontrat==0) { print '   '.$langs->trans("AddContract").''; } print '
'.$langs->trans("DefaultModel").''; $liste=ModelePDFFicheinter::liste_modeles($db); print $form->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF); print "
'.$langs->trans('NotePublic').''; $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); //print ''; print '
'.$langs->trans('NotePrivate').''; $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); //print ''; print '
'.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).'
'; if (is_object($objectsrc)) { print ''; print ''; } elseif ($origin == 'project' && !empty($projectid)) { print ''; } dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } else { dol_fiche_head(''); print '
'; if (is_object($objectsrc)) { print ''; print ''; } elseif ($origin == 'project' && !empty($projectid)) { print ''; } print ''; print ''; print '
'.$langs->trans("ThirdParty").''; print $form->select_company('','socid','','SelectThirdParty',1); print '
'; dol_fiche_end(); print '
'; print ''; print ''; print '     '; print ''; print '
'; print '
'; } } else if ($id > 0 || ! empty($ref)) { /* * Affichage en mode visu */ $object->fetch($id, $ref); $object->fetch_thirdparty(); $soc=new Societe($db); $soc->fetch($object->socid); dol_htmloutput_mesg($mesg); $head = fichinter_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention'); $formconfirm=''; // Confirm deletion of intervention if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1); } // Confirm validation if ($action == 'validate') { // on verifie si l'objet est en numerotation provisoire $ref = substr($object->ref, 1, 4); if ($ref == 'PROV') { $numref = $object->getNextNumRef($soc); if (empty($numref)) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } } else { $numref = $object->ref; } $text=$langs->trans('ConfirmValidateIntervention',$numref); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate','',1,1); } // Confirm back to draft if ($action == 'modify') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1); } // Confirm deletion of line if ($action == 'ask_deleteline') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1); } // Clone confirmation if ($action == 'clone') { // Create an array for form $formquestion = array( // 'text' => $langs->trans("ConfirmClone"), // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => // 1), // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' // => 1), array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '', '', 0, 0, null, 0, 'minwidth200'))); // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneIntervention'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } if (!$formconfirm) { $parameters=array('lineid'=>$lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) $formconfirm.=$hookmanager->resPrint; elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint; } // Print form confirm print $formconfirm; // Intervention card $linkback = ''.$langs->trans("BackToList").''; $morehtmlref='
'; // Ref customer //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', 0, 1); //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); // Project if (! empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; if ($user->rights->commande->creer) { if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; if ($action == 'classify') { //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref.='
'; $morehtmlref.=''; $morehtmlref.=''; $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref.=''; $morehtmlref.='
'; } else { $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); } } else { if (! empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); $morehtmlref.=''; $morehtmlref.=$proj->ref; $morehtmlref.=''; } else { $morehtmlref.=''; } } } $morehtmlref.='
'; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); print '
'; print '
'; print '
'; print ''; if (! empty($conf->global->FICHINTER_USE_PLANNED_AND_DONE_DATES)) { // Date Start print ''; print ''; print ''; // Date End print ''; print ''; print ''; // Date Terminate/close print ''; print ''; print ''; } // Description (must be a textarea and not html must be allowed (used in list view) print ''; print ''; // Contrat if ($conf->contrat->enabled) { $langs->load('contrat'); print ''; print ''; print ''; } // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'.$langs->trans("Dateo").''; print $object->dateo ? dol_print_date($object->dateo, 'daytext') : ' '; print '
'.$langs->trans("Datee").''; print $object->datee ? dol_print_date($object->datee, 'daytext') : ' '; print '
'.$langs->trans("Datet").''; print $object->datet ? dol_print_date($object->datet, 'daytext') : ' '; print '
'; print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea'); print ''; print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea:8:80'); print '
'; print ''; if ($action != 'contrat') { print ''; } print '
'; print $langs->trans('Contract'); print 'id.'">'; print img_edit($langs->trans('SetContract'),1); print '
'; print '
'; if ($action == 'contrat') { $formcontract= new Formcontract($db); $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1); } else { if ($object->fk_contrat) { $contratstatic = new Contrat($db); $contratstatic->fetch($object->fk_contrat); //print ''.$projet->title.''; print $contratstatic->getNomUrl(0,'',1); } else { print " "; } } print '
'; print '
'; print '
'; print '
'; print '
'; print ''; if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) { // Duration print ''; print ''; print ''; } print "
'.$langs->trans("TotalDuration").''.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'
"; print '
'; print '
'; print '
'; print '

'; if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { $blocname = 'contacts'; $title = $langs->trans('ContactsAddresses'); include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; } if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $blocname = 'notes'; $title = $langs->trans('Notes'); include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; } // Line of interventions if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) { print '
'; print ''; print ''; if ($action == 'editline') { print ''; print ''; } else { print ''; } // Intervention lines $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,'; $sql.= ' ft.date as date_intervention'; $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft'; $sql.= ' WHERE ft.fk_fichinter = '.$object->id; if (!empty($conf->global->FICHINTER_HIDE_EMPTY_DURATION)) $sql.= ' AND ft.duree <> 0'; $sql.= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid'; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; // Ligne en mode visu if ($action != 'editline' || GETPOST('line_id','int') != $objp->rowid) { print ''; print ''; // Duration print ''; print "\n"; // Icone d'edition et suppression if ($object->statut == 0 && $user->rights->ficheinter->creer) { print ''; print ''; if ($num > 1) { print ''; } } else { print ''; } print ''; $line = new FichinterLigne($db); $line->fetch($objp->rowid); $extrafieldsline = new ExtraFields($db); $extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element); $line->fetch_optionals($line->rowid, $extralabelslines); print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>5)); } // Line in update mode if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id','int') == $objp->rowid) { print ''; print ''; // Date d'intervention print ''; // Duration print ''; print ''; print '' . "\n"; $line = new FichinterLigne($db); $line->fetch($objp->rowid); $extrafieldsline = new ExtraFields($db); $extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element); $line->fetch_optionals($line->rowid, $extralabelslines); print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5)); } $i++; } $db->free($resql); // Add new line if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline' && empty($conf->global->FICHINTER_DISABLE_DETAILS)) { if (! $num) print '
'.$langs->trans('Description').''.$langs->trans('Date').''.(empty($conf->global->FICHINTER_WITHOUT_DURATION)?$langs->trans('Duration'):'').' 
'; print ''; // ancre pour retourner sur la ligne print dol_htmlentitiesbr($objp->description); // Date print ''.dol_print_date($db->jdate($objp->date_intervention),'dayhour').''.(empty($conf->global->FICHINTER_WITHOUT_DURATION)?convertSecondToTime($objp->duree):'').''; print 'rowid.'#'.$objp->rowid.'">'; print img_edit(); print ''; print ''; print 'rowid.'">'; print img_delete(); print ''; if ($i > 0) { print 'rowid.'">'; print img_up(); print ''; } if ($i < $num-1) { print 'rowid.'">'; print img_down(); print ''; } print ' 
'; print ''; // ancre pour retourner sur la ligne // Editeur wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('np_desc',$objp->description,'',164,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,'90%'); $doleditor->Create(); print ''; $form->select_date($db->jdate($objp->date_intervention),'di',1,1,0,"date_intervention"); print ''; if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) { $selectmode = 'select'; if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) $selectmode = 'text'; $form->select_duration('duration', $objp->duree, 0, $selectmode); } print ''; print '
'; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=true; print '\n"; print ''; // Date intervention print ''; // Duration print ''; print ''; print ''; //Line extrafield $lineadd = new FichinterLigne($db); $extrafieldsline = new ExtraFields($db); $extralabelslines=$extrafieldsline->fetch_name_optionals_label($lineadd->table_element); print $lineadd->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5)); if (! $num) print '
'; print ''; // ancre print $langs->trans('Description').''.$langs->trans('Date').''.(empty($conf->global->FICHINTER_WITHOUT_DURATION)?$langs->trans('Duration'):'').' 
'; // editeur wysiwyg if (empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) { require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'alpha'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%'); $doleditor->Create(); } print ''; $now=dol_now(); $timearray=dol_getdate($now); if (! GETPOST('diday','int')) $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); else $timewithnohour=dol_mktime(GETPOST('dihour','int'),GETPOST('dimin','int'), 0,GETPOST('dimonth','int'),GETPOST('diday','int'),GETPOST('diyear','int')); $form->select_date($timewithnohour,'di',1,1,0,"addinter"); print ''; if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) { $selectmode = 'select'; if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) $selectmode = 'text'; $form->select_duration('duration', (!GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int')) ? 3600 : (60 * 60 * GETPOST('durationhour', 'int') + 60 * GETPOST('durationmin', 'int')), 0, $selectmode); } print '
'; } if ($num) print ''; } else { dol_print_error($db); } print '
'."\n"; } dol_fiche_end(); print "\n"; /* * Actions buttons */ print '
'; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if (empty($reshook)) { if ($user->societe_id == 0) { if ($action != 'editdescription' && ($action != 'presend')) { // Validate if ($object->statut == 0 && (count($object->lines) > 0 || !empty($conf->global->FICHINTER_DISABLE_DETAILS))) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->validate)) { print ''; } } // Modify if ($object->statut == 1 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->unvalidate))) { print ''; } // Send if ($object->statut > 0) { if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) { print ''; } else print ''; } // Event agenda if (! empty($conf->global->FICHINTER_ADDLINK_TO_EVENT)) { if (! empty($conf->agenda->enabled) && $object->statut > 0) { $langs->load("agenda"); if ($object->statut < 2) { if ($user->rights->agenda->myactions->create) print ''; else print ''; } } } // Proposal if (! empty($conf->propal->enabled) && $object->statut > 0) { $langs->load("propal"); if ($object->statut < 2) { if ($user->rights->propal->creer) print ''; else print ''; } } // Invoicing if (! empty($conf->facture->enabled) && $object->statut > 0) { $langs->load("bills"); if ($object->statut < 2) { if ($user->rights->facture->creer) print ''; else print ''; } if (! empty($conf->global->FICHINTER_CLASSIFY_BILLED)) // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1 { if ($object->statut != 2) { print ''; } else { print ''; } } } // Done if (empty($conf->global->FICHINTER_CLASSIFY_BILLED) && $object->statut > 0 && $object->statut < 3) { print ''; } // Clone if ($user->rights->ficheinter->creer) { print ''; } // Delete if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) { print ''; } } } } print '
'; if ($action != 'presend') { print '
'; /* * Built documents */ $filename=dol_sanitizeFileName($object->ref); $filedir=$conf->ficheinter->dir_output . "/".$object->ref; $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=$user->rights->ficheinter->creer; $delallowed=$user->rights->ficheinter->supprimer; $genallowed=1; $delallowed=1; $var=true; //print "
\n"; print $somethingshown=$formfile->showdocuments('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('fichinter')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); print '
'; // List of actions on element include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions=new FormActions($db); $somethingshown=$formactions->showactions($object,'fichinter',$socid); print '
'; } /* * Action presend */ if (GETPOST('modelselected')) { $action = 'presend'; } if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); $file=$fileparams['fullname']; // Define output language $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (!empty($newlang)) { $outputlangs = new Translate('', $conf); $outputlangs->setDefaultLang($newlang); $outputlangs->load('interventions'); } // Build document if it not exists if (! $file || ! is_readable($file)) { $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) { dol_print_error($db,$result); exit; } $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); $file=$fileparams['fullname']; } print '
'; print '
'; print load_fiche_titre($langs->trans('SendInterventionByMail')); dol_fiche_head(''); // Create form object include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user')); if($formmail->fromtype === 'user'){ $formmail->fromid = $user->id; } $formmail->trackid='int'.$object->id; if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set { include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'int'.$object->id); } $formmail->withfrom=1; $liste=array(); foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value; $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste; $formmail->withtocc=$liste; $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; $formmail->withtopic=$outputlangs->trans('SendInterventionRef','__FICHINTERREF__'); $formmail->withfile=2; $formmail->withbody=1; $formmail->withdeliveryreceipt=1; $formmail->withcancel=1; // Tableau des substitutions $formmail->setSubstitFromObject($object); $formmail->substit['__FICHINTERREF__']=$object->ref; //Find the good contact adress $custcontact=''; $contactarr=array(); $contactarr=$object->liste_contact(-1,'external'); if (is_array($contactarr) && count($contactarr)>0) { foreach($contactarr as $contact) { if ($contact['libelle']==$langs->trans('TypeContact_fichinter_external_CUSTOMER')) { require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $contactstatic=new Contact($db); $contactstatic->fetch($contact['id']); $custcontact=$contactstatic->getFullName($langs,1); } } if (!empty($custcontact)) { $formmail->substit['__CONTACTCIVNAME__']=$custcontact; } } // Tableau des parametres complementaires $formmail->param['action']='send'; $formmail->param['models']='fichinter_send'; $formmail->param['models_id']=GETPOST('modelmailselected','int'); $formmail->param['fichinter_id']=$object->id; $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files if (GETPOST("mode")=='init') { $formmail->clear_attached_files(); $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); } print $formmail->get_form(); dol_fiche_end(); } } llxFooter(); $db->close();