diff --git a/htdocs/admin/fichinter.php b/htdocs/admin/fichinter.php index ade26bbafdd..62779230379 100644 --- a/htdocs/admin/fichinter.php +++ b/htdocs/admin/fichinter.php @@ -189,6 +189,23 @@ else if ($action == 'set_FICHINTER_DRAFT_WATERMARK') } } +elseif ($action == 'set_FICHINTER_PRINT_PRODUCTS') +{ + $val = GETPOST('FICHINTER_PRINT_PRODUCTS','alpha'); + $res = dolibarr_set_const($db, "FICHINTER_PRINT_PRODUCTS",($val == 'on'),'bool',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $mesg = "".$langs->trans("Error").""; + } +} + /* * View @@ -469,6 +486,22 @@ print ''; print ''; print "\n"; + +// print products on fichinter +$var=! $var; +print '
'; diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 67b3a93b4ee..daf189c748b 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -1,1741 +1,1748 @@ - - * Copyright (C) 2004-2012 Laurent Destailleur| '.$langs->trans("Ref").' | '; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); - print ' | ||||
| ".$langs->trans("Company")." | ".$object->client->getNomUrl(1)." | ||||
| '.$langs->trans("TotalDuration").' | '; - print ''.convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' | '; - 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 '||||
';
-
- print '
| '; - if ($action == 'classify') - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); - } - else - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); - } - print ' | '; - print '||||
| '.$langs->trans("Status").' | '.$object->getLibStatut(4).' | ||||
| '.$langs->trans('Description').' | '; - print ''.$langs->trans('Date').' | '; - print ''.$langs->trans('Duration').' | '; - print ''; - print " | |||||
| '; - print ''; // ancre pour retourner sur la ligne - print dol_htmlentitiesbr($objp->description); - - // Date - print ' | '.dol_print_date($db->jdate($objp->date_intervention),'dayhour').' | '; - - // Duration - print ''.convertSecondToTime($objp->duree).' | '; - - print "\n"; - - - // Icone d'edition et suppression - if ($object->statut == 0 && $user->rights->ficheinter->creer) - { - print ''; - print 'id.'&action=editline&line_id='.$objp->rowid.'#'.$objp->rowid.'">'; - print img_edit(); - print ''; - print ' | '; - print ''; - print 'id.'&action=ask_deleteline&line_id='.$objp->rowid.'">'; - print img_delete(); - print ' | '; - if ($num > 1) - { - print ''; - if ($i > 0) - { - print 'id.'&action=up&line_id='.$objp->rowid.'">'; - print img_up(); - print ''; - } - if ($i < $num-1) - { - print 'id.'&action=down&line_id='.$objp->rowid.'">'; - print img_down(); - print ''; - } - print ' | '; - } - } - else - { - print ''; - } - - 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"; - $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); - - /* - * Linked object block - */ - $somethingshown=$object->showLinkedObjectBlock(); - - //print ' | ';
+
+ * Copyright (C) 2004-2012 Laurent Destailleur '.$object->error.' ';
+ }
+}
+
+else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+
+ $result = $object->setDraft($user);
+ if ($result >= 0)
+ {
+ // 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->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $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->duree = GETPOST('duree','int');
+ $object->fk_project = GETPOST('projectid','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']);
+ }
+
+ $id = $object->create();
+
+ 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')) $lines = $srcobject->fetch_lines();
+
+ $fk_parent_line=0;
+ $num=count($lines);
+
+ for ($i=0;$i<$num;$i++)
+ {
+ $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
+
+ if ($product_type == 1 || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products
+ // service prédéfini
+ if ($lines[$i]->fk_product > 0)
+ {
+ $product_static = new Product($db);
+
+ // Define output language
+ if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
+ {
+ $prod = new Product($db, $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
+ {
+ $label = $lines[$i]->product_label;
+ }
+
+ $product_static->type=$lines[$i]->fk_product_type;
+ $product_static->id=$lines[$i]->fk_product;
+ $product_static->ref=$lines[$i]->ref;
+ $product_static->libelle=$label;
+ $desc=$product_static->getNomUrl(1);
+ $desc.= ' - '.$label;
+ $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
+ if ($conf->global->PRODUIT_DESC_IN_FORM)
+ $desc .= ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?''.dol_htmlentitiesbr($lines[$i]->desc):''; + } + else { + $desc = dol_htmlentitiesbr($lines[$i]->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 == 1) + { //service + $duration = 3600; + } + else + { //product + $duration = 0; + } + + $result = $object->addline( + $user, + $id, + $desc, + $date_intervention, + $duration + ); + + if ($result < 0) + { + $error++; + break; + } + + } + } + + } + else + { + $mesg=$srcobject->error; + $error++; + } + } + else + { + $mesg=$object->error; + $error++; + } + } + else + { + $result = $object->create($user); + if ($result > 0) + { + $id=$result; // Force raffraichissement sur fiche venant d'etre cree + } + else + { + $langs->load("errors"); + $mesg=' '.$langs->trans($object->error).' ';
+ $action = 'create';
+ }
+ }
+ }
+ else
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).' ';
+ $action = 'create';
+ }
+}
+
+else if ($action == 'update' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+
+ $object->socid = $socid;
+ $object->fk_project = GETPOST('projectid','int');
+ $object->author = $user->id;
+ $object->description = GETPOST('description','alpha');
+ $object->ref = $ref;
+
+ $result=$object->update($user);
+ if ($result<0) {
+ setEventMessage($object->error,'errors');
+ }
+}
+
+/*
+ * Build doc
+*/
+else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post
+{
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->fetch_lines();
+
+ if (GETPOST('model','alpha'))
+ {
+ $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->client->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')
+{
+ if ($object->fetch($id))
+ {
+ 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) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+ }
+}
+
+// Set into a project
+else if ($action == 'classin' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $result=$object->setProject(GETPOST('projectid','int'));
+ if ($result < 0) dol_print_error($db,$object->error);
+}
+
+else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
+{
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $result=$object->delete($user);
+ if ($result<0) {
+ setEventMessage($object->error,'errors');
+ }
+
+ header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter');
+ exit;
+}
+
+else if ($action == 'setdescription' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $result=$object->set_description($user,GETPOST('description'));
+ if ($result < 0) dol_print_error($db,$object->error);
+}
+else if ($action == 'setnote_public' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
+ if ($result < 0) dol_print_error($db,$object->error);
+}
+else if ($action == 'setnote_private' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private');
+ if ($result < 0) dol_print_error($db,$object->error);
+}
+
+// Add line
+else if ($action == "addline" && $user->rights->ficheinter->creer)
+{
+ if (!GETPOST('np_desc'))
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).' ';
+ $error++;
+ }
+ if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).' ';
+ $error++;
+ }
+ if (! $error)
+ {
+ $db->begin();
+
+ $ret=$object->fetch($id);
+ $object->fetch_thirdparty();
+
+ $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 = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
+
+ $result=$object->addline(
+ $user,
+ $id,
+ $desc,
+ $date_intervention,
+ $duration
+ );
+
+ // 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->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+
+ if ($result >= 0)
+ {
+ $db->commit();
+
+ 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)
+{
+ $object->fetch($id);
+ $result=$object->setBilled();
+ if ($result > 0)
+ {
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$object->error.' ';
+ }
+}
+
+/*
+ * 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(GETPOST('line_id','int')) <= 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;
+ $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->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ 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(GETPOST('line_id','int')) <= 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->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+}
+
+/*
+ * Ordonnancement des lignes
+*/
+
+else if ($action == 'up' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->line_up(GETPOST('line_id','int'));
+
+ // 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->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
+ exit;
+}
+
+else if ($action == 'down' && $user->rights->ficheinter->creer)
+{
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->line_down(GETPOST('line_id','int'));
+
+ // 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->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
+ exit;
+}
+
+
+/*
+ * Add file in email form
+*/
+if (GETPOST('addfile','alpha'))
+{
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir_tmp = $vardir.'/temp';
+
+ dol_add_file_process($upload_dir_tmp,0,0);
+ $action='presend';
+}
+
+/*
+ * Remove file in email form
+*/
+if (GETPOST('removedfile','alpha'))
+{
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ // Set tmp user directory
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir_tmp = $vardir.'/temp';
+
+ // TODO Delete only files that was uploaded from email form
+ dol_remove_file_process(GETPOST('removedfile','alpha'),0);
+ $action='presend';
+}
+
+/*
+ * Send mail
+*/
+if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
+{
+ $langs->load('mails');
+
+ if ($object->fetch($id) > 0)
+ {
+ $object->fetch_thirdparty();
+
+ if (GETPOST('sendto','alpha'))
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = GETPOST('sendto','alpha');
+ $sendtoid = 0;
+ }
+ elseif (GETPOST('receiver','alpha') != '-1')
+ {
+ // Recipient was provided from combo list
+ if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
+ {
+ $sendto = $object->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email');
+ $sendtoid = GETPOST('receiver','alpha');
+ }
+ }
+
+ if (dol_strlen($sendto))
+ {
+ $langs->load("commercial");
+
+ $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
+ $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
+ $message = GETPOST('message');
+ $sendtocc = GETPOST('sendtocc','alpha');
+ $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
+
+ if ($action == 'send')
+ {
+ if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha');
+ else $subject = $langs->transnoentities('Intervention').' '.$object->ref;
+ $actiontypecode='AC_OTH_AUTO';
+ $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
+ if ($message)
+ {
+ $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
+ $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
+ $actionmsg.=$message;
+ }
+ $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ }
+
+ // Create form object
+ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ $formmail = new FormMail($db);
+
+ $attachedfiles=$formmail->get_attached_files();
+ $filepath = $attachedfiles['paths'];
+ $filename = $attachedfiles['names'];
+ $mimetype = $attachedfiles['mimes'];
+
+ // Envoi de la propal
+ require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
+ if ($mailfile->error)
+ {
+ $mesg=''.$mailfile->error.' ';
+ }
+ else
+ {
+ $result=$mailfile->sendfile();
+ if ($result)
+ {
+ $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
+ setEventMessage($mesg);
+ $error=0;
+
+ // Initialisation donnees
+ $object->sendtoid = $sendtoid;
+ $object->actiontypecode = $actiontypecode;
+ $object->actionmsg = $actionmsg;
+ $object->actionmsg2 = $actionmsg2;
+ $object->fk_element = $object->id;
+ $object->elementtype = $object->element;
+
+ // Appel des triggers
+ include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf);
+ if ($result < 0) {
+ $error++; $this->errors=$interface->errors;
+ }
+ // Fin appel triggers
+
+ if ($error)
+ {
+ dol_print_error($db);
+ }
+ else
+ {
+ // Redirect here
+ // This avoid sending mail twice if going out and then back to page
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg='';
+ if ($mailfile->error)
+ {
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.=' ';
+ }
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.=' '.$langs->trans('ErrorMailRecipientIsEmpty').' ! ';
+ dol_syslog('Recipient email is empty');
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).' ';
+ dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.');
+ }
+
+ $action='presend';
+}
+
+else if ($action == 'update_extras')
+{
+ $object->fetch($id);
+ // Fill array 'array_options' with data from update form
+ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+
+ // Actions on extra fields (by external module or standard code)
+ // FIXME 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))
+ {
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $result=$object->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
+ }
+ else if ($reshook < 0) $error++;
+}
+
+if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer)
+{
+ if ($action == 'addcontact')
+ {
+ $result = $object->fetch($id);
+
+ 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')
+ {
+ if ($object->fetch($id))
+ {
+ $result=$object->swapContactStatus(GETPOST('ligne','int'));
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ }
+
+ // Efface un contact
+ else if ($action == 'deletecontact')
+ {
+ $object->fetch($id);
+ $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);
+
+llxHeader();
+
+if ($action == 'create')
+{
+ /*
+ * Mode creation
+ * Creation d'une nouvelle fiche d'intervention
+ */
+
+ $soc=new Societe($db);
+
+ print_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();
+ $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 : ''));
+ $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
+
+ // Object source contacts list
+ $srccontactslist = $objectsrc->liste_contact(-1,'external',1);
+ }
+ }
+ else {
+ $projectid = GETPOST('projectid','int');
+ $note_private = '';
+ $note_public = '';
+ }
+
+ 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->fetch($socid);
+
+ print ' |
| '.$langs->trans("Ref").' | '; + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); + print ' | ||||
| ".$langs->trans("Company")." | ".$object->client->getNomUrl(1)." | ||||
| '.$langs->trans("TotalDuration").' | '; + print ''.convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' | '; + 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 '||||
';
+
+ print '
| '; + if ($action == 'classify') + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); + } + else + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); + } + print ' | '; + print '||||
| '.$langs->trans("Status").' | '.$object->getLibStatut(4).' | ||||
| '.$langs->trans('Description').' | '; + print ''.$langs->trans('Date').' | '; + print ''.$langs->trans('Duration').' | '; + print ''; + print " | |||||
| '; + print ''; // ancre pour retourner sur la ligne + print dol_htmlentitiesbr($objp->description); + + // Date + print ' | '.dol_print_date($db->jdate($objp->date_intervention),'dayhour').' | '; + + // Duration + print ''.convertSecondToTime($objp->duree).' | '; + + print "\n"; + + + // Icone d'edition et suppression + if ($object->statut == 0 && $user->rights->ficheinter->creer) + { + print ''; + print 'id.'&action=editline&line_id='.$objp->rowid.'#'.$objp->rowid.'">'; + print img_edit(); + print ''; + print ' | '; + print ''; + print 'id.'&action=ask_deleteline&line_id='.$objp->rowid.'">'; + print img_delete(); + print ' | '; + if ($num > 1) + { + print ''; + if ($i > 0) + { + print 'id.'&action=up&line_id='.$objp->rowid.'">'; + print img_up(); + print ''; + } + if ($i < $num-1) + { + print 'id.'&action=down&line_id='.$objp->rowid.'">'; + print img_down(); + print ''; + } + print ' | '; + } + } + else + { + print ''; + } + + 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"; + $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); + + /* + * Linked object block + */ + $somethingshown=$object->showLinkedObjectBlock(); + + //print ' | ';
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 ' |