dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2014-2018 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2014-2018 Charlene Benke <charlies@patas-monkey.com>
9  * Copyright (C) 2015-2016 Abbes Bahfir <bafbes@gmail.com>
10  * Copyright (C) 2018 Philippe Grand <philippe.grand@atoo-net.com>
11  * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 require '../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39 if (!empty($conf->projet->enabled))
40 {
41  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
42  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
43 }
44 if ($conf->contrat->enabled)
45 {
46  require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php";
47  require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
48 }
49 if (!empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php"))
50 {
51  require_once DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php';
52 }
53 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
55 
56 // Load translation files required by the page
57 $langs->loadLangs(array('bills', 'companies', 'interventions'));
58 
59 $id = GETPOST('id', 'int');
60 $ref = GETPOST('ref', 'alpha');
61 $socid = (int) GETPOST('socid', 'int');
62 $contratid = (int) GETPOST('contratid', 'int');
63 $action = GETPOST('action', 'alpha');
64 $cancel = GETPOST('cancel', 'alpha');
65 $confirm = GETPOST('confirm', 'alpha');
66 $mesg = GETPOST('msg', 'alpha');
67 $origin = GETPOST('origin', 'alpha');
68 $originid = (GETPOST('originid', 'int') ?GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
69 $note_public = GETPOST('note_public', 'restricthtml');
70 $lineid = GETPOST('line_id', 'int');
71 
72 //PDF
73 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
74 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
75 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
76 
77 // Security check
78 if ($user->socid) $socid = $user->socid;
79 $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
80 
81 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82 $hookmanager->initHooks(array('interventioncard', 'globalcard'));
83 
84 $object = new Fichinter($db);
85 $extrafields = new ExtraFields($db);
86 
87 $extrafields->fetch_name_optionals_label($object->table_element);
88 
89 // Load object
90 if ($id > 0 || !empty($ref))
91 {
92  $ret = $object->fetch($id, $ref);
93  if ($ret > 0) $ret = $object->fetch_thirdparty();
94  if ($ret < 0) dol_print_error('', $object->error);
95 }
96 
97 $permissionnote = $user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php
98 $permissiondellink = $user->rights->ficheinter->creer; // Used by the include of actions_dellink.inc.php
99 
100 $error = 0;
101 
102 
103 /*
104  * Actions
105  */
106 
107 $parameters = array('socid'=>$socid);
108 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110 
111 if (empty($reshook))
112 {
113  if ($cancel)
114  {
115  if (!empty($backtopage))
116  {
117  header("Location: ".$backtopage);
118  exit;
119  }
120  $action = '';
121  }
122 
123  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
124 
125  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
126 
127  // Action clone object
128  if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->ficheinter->creer)
129  {
130  if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers'))
131  {
132  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
133  } else {
134  if ($object->id > 0)
135  {
136  // Because createFromClone modifies the object, we must clone it so that we can restore it later
137  $orig = clone $object;
138 
139  $result = $object->createFromClone($user, $socid);
140  if ($result > 0)
141  {
142  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
143  exit;
144  } else {
145  setEventMessages($object->error, $object->errors, 'errors');
146  $object = $orig;
147  $action = '';
148  }
149  }
150  }
151  }
152 
153  if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer)
154  {
155  $result = $object->setValid($user);
156 
157  if ($result >= 0)
158  {
159  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
160  {
161  // Define output language
162  $outputlangs = $langs;
163  $newlang = '';
164  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
165  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
166  if (!empty($newlang))
167  {
168  $outputlangs = new Translate("", $conf);
169  $outputlangs->setDefaultLang($newlang);
170  }
171  $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
172  }
173 
174  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
175  exit;
176  } else {
177  $mesg = $object->error;
178  }
179  } elseif ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) {
180  $result = $object->setDraft($user);
181  if ($result >= 0)
182  {
183  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
184  {
185  // Define output language
186  $outputlangs = $langs;
187  $newlang = '';
188  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
189  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
190  if (!empty($newlang)) {
191  $outputlangs = new Translate("", $conf);
192  $outputlangs->setDefaultLang($newlang);
193  }
194  $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
195  }
196 
197  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
198  exit;
199  } else {
200  $mesg = $object->error;
201  }
202  } elseif ($action == 'add' && $user->rights->ficheinter->creer) {
203  $object->socid = $socid;
204  $object->duration = (int) GETPOST('duration', 'int');
205  $object->fk_project = (int) GETPOST('projectid', 'int');
206  $object->fk_contrat = (int) GETPOST('contratid', 'int');
207  $object->author = $user->id;
208  $object->description = GETPOST('description', 'restricthtml');
209  $object->ref = $ref;
210  $object->model_pdf = GETPOST('model', 'alpha');
211  $object->note_private = GETPOST('note_private', 'restricthtml');
212  $object->note_public = GETPOST('note_public', 'restricthtml');
213 
214  if ($object->socid > 0)
215  {
216  // If creation from another object of another module (Example: origin=propal, originid=1)
217  if (!empty($origin) && !empty($originid))
218  {
219  // Parse element/subelement (ex: project_task)
220  $regs = array();
221  $element = $subelement = GETPOST('origin', 'alphanohtml');
222  if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs))
223  {
224  $element = $regs[1];
225  $subelement = $regs[2];
226  }
227 
228  // For compatibility
229  if ($element == 'order') {
230  $element = $subelement = 'commande';
231  }
232  if ($element == 'propal') {
233  $element = 'comm/propal'; $subelement = 'propal';
234  }
235  if ($element == 'contract') {
236  $element = $subelement = 'contrat';
237  }
238 
239  $object->origin = $origin;
240  $object->origin_id = $originid;
241 
242  // Possibility to add external linked objects with hooks
243  $object->linked_objects[$object->origin] = $object->origin_id;
244  if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects']))
245  {
246  $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
247  }
248 
249  // Extrafields
250 
251  // Fill array 'array_options' with data from add form
252  $ret = $extrafields->setOptionalsFromPost(null, $object);
253  if ($ret < 0) {
254  $error++;
255  $action = 'create';
256  }
257  $array_options = $extrafields->getOptionalsFromPost($object->table_element);
258 
259  $object->array_options = $array_options;
260 
261  $id = $object->create($user);
262 
263  if ($id > 0)
264  {
265  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
266 
267  $classname = ucfirst($subelement);
268  $srcobject = new $classname($db);
269 
270  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
271  $result = $srcobject->fetch($object->origin_id);
272  if ($result > 0)
273  {
274  $srcobject->fetch_thirdparty();
275  $lines = $srcobject->lines;
276  if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
277  {
278  $srcobject->fetch_lines();
279  $lines = $srcobject->lines;
280  }
281 
282  if (is_array($lines)) {
283  $num = count($lines);
284 
285  for ($i = 0; $i < $num; $i++)
286  {
287  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : Product::TYPE_PRODUCT);
288 
289  if ($product_type == Product::TYPE_SERVICE || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products
290  $duration = 3600; // Default to one hour
291 
292  // Predefined products & services
293  if ($lines[$i]->fk_product > 0)
294  {
295  $prod = new Product($db);
296  $prod->id = $lines[$i]->fk_product;
297 
298  // Define output language
299  if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
300  $prod->getMultiLangs();
301  // We show if duration is present on service (so we get it)
302  $prod->fetch($lines[$i]->fk_product);
303  $outputlangs = $langs;
304  $newlang = '';
305  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
306  if (empty($newlang)) $newlang = $srcobject->thirdparty->default_lang;
307  if (!empty($newlang)) {
308  $outputlangs = new Translate("", $conf);
309  $outputlangs->setDefaultLang($newlang);
310  }
311  $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
312  } else {
313  $prod->fetch($lines[$i]->fk_product);
314  $label = $lines[$i]->product_label;
315  }
316 
317  if ($prod->duration_value && $conf->global->FICHINTER_USE_SERVICE_DURATION) {
318  switch ($prod->duration_unit) {
319  default:
320  case 'h':
321  $mult = 3600;
322  break;
323  case 'd':
324  $mult = 3600 * 24;
325  break;
326  case 'w':
327  $mult = 3600 * 24 * 7;
328  break;
329  case 'm':
330  $mult = (int) 3600 * 24 * (365 / 12); // Average month duration
331  break;
332  case 'y':
333  $mult = 3600 * 24 * 365;
334  break;
335  }
336  $duration = $prod->duration_value * $mult * $lines[$i]->qty;
337  }
338 
339  $desc = $lines[$i]->product_ref;
340  $desc .= ' - ';
341  $desc .= $label;
342  $desc .= '<br>';
343  }
344  // Common part (predefined or free line)
345  $desc .= dol_htmlentitiesbr($lines[$i]->desc);
346  $desc .= '<br>';
347  $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
348 
349  $timearray = dol_getdate(dol_now());
350  $date_intervention = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
351 
352  if ($product_type == Product::TYPE_PRODUCT) {
353  $duration = 0;
354  }
355 
356  $predef = '';
357 
358  // Extrafields
359  $extrafields->fetch_name_optionals_label($object->table_element_line);
360  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
361 
362  $result = $object->addline(
363  $user,
364  $id,
365  $desc,
366  $date_intervention,
367  $duration,
368  $array_options
369  );
370 
371  if ($result < 0)
372  {
373  $error++;
374  break;
375  }
376  }
377  }
378  }
379  } else {
380  $mesg = $srcobject->error;
381  $error++;
382  }
383  } else {
384  $mesg = $object->error;
385  $error++;
386  }
387  } else {
388  // Fill array 'array_options' with data from add form
389  $ret = $extrafields->setOptionalsFromPost(null, $object);
390  if ($ret < 0) {
391  $error++;
392  $action = 'create';
393  }
394 
395  if (!$error)
396  {
397  // Extrafields
398  $array_options = $extrafields->getOptionalsFromPost($object->table_element);
399 
400  $object->array_options = $array_options;
401 
402  $result = $object->create($user);
403  if ($result > 0)
404  {
405  $id = $result; // Force raffraichissement sur fiche venant d'etre cree
406  } else {
407  $langs->load("errors");
408  setEventMessages($object->error, $object->errors, 'errors');
409  $action = 'create';
410  }
411  }
412  }
413  } else {
414  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty"));
415  $action = 'create';
416  }
417  } elseif ($action == 'update' && $user->rights->ficheinter->creer) {
418  $object->socid = $socid;
419  $object->fk_project = (int) GETPOST('projectid', 'int');
420  $object->fk_contrat = (int) GETPOST('contratid', 'int');
421  $object->author = $user->id;
422  $object->description = GETPOST('description', 'restricthtml');
423  $object->ref = $ref;
424 
425  $result = $object->update($user);
426  if ($result < 0) {
427  setEventMessages($object->error, $object->errors, 'errors');
428  }
429  }
430 
431  // Set into a project
432  elseif ($action == 'classin' && $user->rights->ficheinter->creer)
433  {
434  $result = $object->setProject(GETPOST('projectid', 'int'));
435  if ($result < 0) dol_print_error($db, $object->error);
436  }
437 
438  // Set into a contract
439  elseif ($action == 'setcontract' && $user->rights->contrat->creer)
440  {
441  $result = $object->set_contrat($user, GETPOST('contratid', 'int'));
442  if ($result < 0) dol_print_error($db, $object->error);
443  } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
444  {
445  $result = $object->delete($user);
446  if ($result < 0) {
447  setEventMessages($object->error, $object->errors, 'errors');
448  }
449 
450  header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter&restore_lastsearch_values=1');
451  exit;
452  } elseif ($action == 'setdescription' && $user->rights->ficheinter->creer)
453  {
454  $result = $object->set_description($user, GETPOST('description'));
455  if ($result < 0) dol_print_error($db, $object->error);
456  }
457 
458  // Add line
459  elseif ($action == "addline" && $user->rights->ficheinter->creer)
460  {
461  if (!GETPOST('np_desc', 'restricthtml') && empty($conf->global->FICHINTER_EMPTY_LINE_DESC))
462  {
463  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description"));
464  $error++;
465  }
466  if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && !GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int'))
467  {
468  $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Duration"));
469  $error++;
470  }
471  if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && GETPOST('durationhour', 'int') >= 24 && GETPOST('durationmin', 'int') > 0)
472  {
473  $mesg = $langs->trans("ErrorValueTooHigh");
474  $error++;
475  }
476  if (!$error)
477  {
478  $db->begin();
479 
480  $desc = GETPOST('np_desc', 'restricthtml');
481  $date_intervention = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
482  $duration = empty($conf->global->FICHINTER_WITHOUT_DURATION) ? convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int')) : 0;
483 
484  // Extrafields
485  $extrafields->fetch_name_optionals_label($object->table_element_line);
486  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
487 
488  $result = $object->addline(
489  $user,
490  $id,
491  $desc,
492  $date_intervention,
493  $duration,
494  $array_options
495  );
496 
497  // Define output language
498  $outputlangs = $langs;
499  $newlang = '';
500  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
501  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
502  if (!empty($newlang))
503  {
504  $outputlangs = new Translate("", $conf);
505  $outputlangs->setDefaultLang($newlang);
506  }
507 
508  if ($result >= 0)
509  {
510  $db->commit();
511 
512  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->model_pdf, $outputlangs);
513  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
514  exit;
515  } else {
516  $mesg = $object->error;
517  $db->rollback();
518  }
519  }
520  }
521 
522  // Classify Billed
523  elseif ($action == 'classifybilled' && $user->rights->ficheinter->creer)
524  {
525  $result = $object->setStatut(2);
526  if ($result > 0) {
527  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
528  exit;
529  } else {
530  setEventMessages($object->error, $object->errors, 'errors');
531  }
532  }
533 
534  // Classify unbilled
535  elseif ($action == 'classifyunbilled' && $user->rights->ficheinter->creer)
536  {
537  $result = $object->setStatut(1);
538  if ($result > 0)
539  {
540  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
541  exit;
542  } else {
543  $mesg = $object->error;
544  }
545  }
546 
547  // Classify Done
548  elseif ($action == 'classifydone' && $user->rights->ficheinter->creer)
549  {
550  $result = $object->setStatut(3);
551  if ($result > 0)
552  {
553  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
554  exit;
555  } else {
556  setEventMessages($object->error, $object->errors, 'errors');
557  }
558  }
559 
560  // Reopen
561  elseif ($action == 'confirm_reopen' && $user->rights->ficheinter->creer)
562  {
563  $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
564  if ($result > 0)
565  {
566  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
567  exit;
568  }
569  else {
570  $mesg = $object->error;
571  }
572  }
573 
574  /*
575  * Mise a jour d'une ligne d'intervention
576  */
577  elseif ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save', 'alpha') == $langs->trans("Save")) {
578  $objectline = new FichinterLigne($db);
579  if ($objectline->fetch($lineid) <= 0) {
580  dol_print_error($db);
581  exit;
582  }
583 
584  if ($object->fetch($objectline->fk_fichinter) <= 0) {
585  dol_print_error($db);
586  exit;
587  }
588  $object->fetch_thirdparty();
589 
590  $desc = GETPOST('np_desc', 'restricthtml');
591  $date_inter = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
592  $duration = convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int'));
593 
594  $objectline->datei = $date_inter;
595  $objectline->desc = $desc;
596  $objectline->duration = $duration;
597 
598  // Extrafields
599  $extrafields->fetch_name_optionals_label($object->table_element_line);
600  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
601  $objectline->array_options = $array_options;
602 
603  $result = $objectline->update($user);
604  if ($result < 0) {
605  dol_print_error($db);
606  exit;
607  }
608 
609  // Define output language
610  $outputlangs = $langs;
611  $newlang = '';
612  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
613  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
614  if (!empty($newlang)) {
615  $outputlangs = new Translate("", $conf);
616  $outputlangs->setDefaultLang($newlang);
617  }
618  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->model_pdf, $outputlangs);
619 
620  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
621  exit;
622  }
623 
624  /*
625  * Supprime une ligne d'intervention AVEC confirmation
626  */
627  elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer)
628  {
629  $objectline = new FichinterLigne($db);
630  if ($objectline->fetch($lineid) <= 0)
631  {
632  dol_print_error($db);
633  exit;
634  }
635  $result = $objectline->deleteline($user);
636 
637  if ($object->fetch($objectline->fk_fichinter) <= 0)
638  {
639  dol_print_error($db);
640  exit;
641  }
642 
643  // Define output language
644  $outputlangs = $langs;
645  $newlang = '';
646  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
647  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
648  if (!empty($newlang))
649  {
650  $outputlangs = new Translate("", $conf);
651  $outputlangs->setDefaultLang($newlang);
652  }
653  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->model_pdf, $outputlangs);
654  }
655 
656  /*
657  * Set position of lines
658  */
659  elseif ($action == 'up' && $user->rights->ficheinter->creer)
660  {
661  $object->line_up($lineid);
662 
663  // Define output language
664  $outputlangs = $langs;
665  $newlang = '';
666  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
667  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
668  if (!empty($newlang))
669  {
670  $outputlangs = new Translate("", $conf);
671  $outputlangs->setDefaultLang($newlang);
672  }
673  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->model_pdf, $outputlangs);
674 
675  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
676  exit;
677  } elseif ($action == 'down' && $user->rights->ficheinter->creer)
678  {
679  $object->line_down($lineid);
680 
681  // Define output language
682  $outputlangs = $langs;
683  $newlang = '';
684  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
685  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
686  if (!empty($newlang))
687  {
688  $outputlangs = new Translate("", $conf);
689  $outputlangs->setDefaultLang($newlang);
690  }
691  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->model_pdf, $outputlangs);
692 
693  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
694  exit;
695  }
696 
697  // Actions when printing a doc from card
698  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
699 
700  // Actions to send emails
701  $triggersendname = 'FICHINTER_SENTBYMAIL';
702  $autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
703  $trackid = 'int'.$object->id;
704  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
705 
706  // Actions to build doc
707  $upload_dir = $conf->ficheinter->dir_output;
708  $permissiontoadd = $user->rights->ficheinter->creer;
709  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
710 
711  if ($action == 'update_extras')
712  {
713  $object->oldcopy = dol_clone($object);
714 
715  // Fill array 'array_options' with data from update form
716  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
717  if ($ret < 0) $error++;
718 
719  if (!$error)
720  {
721  // Actions on extra fields
722  $result = $object->insertExtraFields('INTERVENTION_MODIFY');
723  if ($result < 0)
724  {
725  $error++;
726  }
727  }
728 
729  if ($error) $action = 'edit_extras';
730  }
731 
732  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer)
733  {
734  if ($action == 'addcontact')
735  {
736  if ($result > 0 && $id > 0)
737  {
738  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
739  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
740  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
741  }
742 
743  if ($result >= 0)
744  {
745  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
746  exit;
747  } else {
748  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
749  {
750  $langs->load("errors");
751  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
752  } else {
753  $mesg = $object->error;
754  }
755  }
756  }
757 
758  // bascule du statut d'un contact
759  elseif ($action == 'swapstatut')
760  {
761  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
762  }
763 
764  // Efface un contact
765  elseif ($action == 'deletecontact')
766  {
767  $result = $object->delete_contact(GETPOST('lineid', 'int'));
768 
769  if ($result >= 0)
770  {
771  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
772  exit;
773  } else {
774  dol_print_error($db);
775  }
776  }
777  }
778 }
779 
780 
781 /*
782  * View
783  */
784 
785 $form = new Form($db);
786 $formfile = new FormFile($db);
787 if ($conf->contrat->enabled) $formcontract = new FormContract($db);
788 if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
789 
790 llxHeader('', $langs->trans("Intervention"));
791 
792 if ($action == 'create')
793 {
794  // Create new intervention
795 
796  $soc = new Societe($db);
797 
798  print load_fiche_titre($langs->trans("AddIntervention"), '', 'intervention');
799 
800  if ($error > 0) {
801  dol_htmloutput_errors($mesg);
802  } else {
803  dol_htmloutput_mesg($mesg);
804  }
805 
806  if ($socid) $res = $soc->fetch($socid);
807 
808  if (GETPOST('origin', 'alphanohtml') && GETPOST('originid', 'int'))
809  {
810  // Parse element/subelement (ex: project_task)
811  $regs = array();
812  $element = $subelement = GETPOST('origin', 'alphanohtml');
813  if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs))
814  {
815  $element = $regs[1];
816  $subelement = $regs[2];
817  }
818 
819  if ($element == 'project')
820  {
821  $projectid = GETPOST('originid', 'int');
822  } else {
823  // For compatibility
824  if ($element == 'order' || $element == 'commande') {
825  $element = $subelement = 'commande';
826  }
827  if ($element == 'propal') {
828  $element = 'comm/propal'; $subelement = 'propal';
829  }
830  if ($element == 'contract') {
831  $element = $subelement = 'contrat';
832  }
833 
834  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
835 
836  $classname = ucfirst($subelement);
837  $objectsrc = new $classname($db);
838  $objectsrc->fetch(GETPOST('originid'));
839  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
840  {
841  $objectsrc->fetch_lines();
842  $lines = $objectsrc->lines;
843  }
844  $objectsrc->fetch_thirdparty();
845 
846  $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
847 
848  $soc = $objectsrc->thirdparty;
849 
850  $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private', 'restricthtml')));
851  $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public', 'restricthtml'));
852 
853  // Object source contacts list
854  $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
855  }
856  } else {
857  $projectid = GETPOST('projectid', 'int');
858  }
859 
860  if (!$conf->global->FICHEINTER_ADDON)
861  {
862  dol_print_error($db, $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
863  exit;
864  }
865 
866  $object->date = dol_now();
867 
868  $obj = $conf->global->FICHEINTER_ADDON;
869  $obj = "mod_".$obj;
870 
871  //$modFicheinter = new $obj;
872  //$numpr = $modFicheinter->getNextValue($soc, $object);
873 
874  if ($socid > 0)
875  {
876  $soc = new Societe($db);
877  $soc->fetch($socid);
878 
879  print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
880  print '<input type="hidden" name="token" value="'.newToken().'">';
881  print '<input type="hidden" name="socid" value='.$soc->id.'>';
882  print '<input type="hidden" name="action" value="add">';
883 
885 
886  print '<table class="border centpercent">';
887 
888  print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
889 
890  // Ref
891  print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
892 
893  // Description (must be a textarea and not html must be allowed (used in list view)
894  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
895  print '<td>';
896  print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
897  print '</td></tr>';
898 
899  // Project
900  if (!empty($conf->projet->enabled))
901  {
902  $formproject = new FormProjets($db);
903 
904  $langs->load("project");
905 
906  print '<tr><td>'.$langs->trans("Project").'</td><td>';
907  /* 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
908  if ($societe->fournisseur==1)
909  $numprojet=select_projects(-1,$_POST["projectid"],'projectid');
910  else
911  $numprojet=select_projects($societe->id,$_POST["projectid"],'projectid');
912  */
913  $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid');
914  if ($numprojet == 0)
915  {
916  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
917  }
918  print '</td></tr>';
919  }
920 
921  // Contract
922  if ($conf->contrat->enabled)
923  {
924  $langs->load("contracts");
925  print '<tr><td>'.$langs->trans("Contract").'</td><td>';
926  $numcontrat = $formcontract->select_contract($soc->id, GETPOST('contratid', 'int'), 'contratid', 0, 1, 1);
927  if ($numcontrat == 0)
928  {
929  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$soc->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddContract").'"></span></a>';
930  }
931  print '</td></tr>';
932  }
933 
934  // Model
935  print '<tr>';
936  print '<td>'.$langs->trans("DefaultModel").'</td>';
937  print '<td>';
939  print $form->selectarray('model', $liste, $conf->global->FICHEINTER_ADDON_PDF);
940  print "</td></tr>";
941 
942  // Public note
943  print '<tr>';
944  print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
945  print '<td>';
946  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
947  print $doleditor->Create(1);
948  //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
949  print '</td></tr>';
950 
951  // Private note
952  if (empty($user->socid))
953  {
954  print '<tr>';
955  print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
956  print '<td>';
957  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
958  print $doleditor->Create(1);
959  //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
960  print '</td></tr>';
961  }
962 
963  // Other attributes
964  $parameters = array();
965  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
966  print $hookmanager->resPrint;
967  if (empty($reshook))
968  {
969  print $object->showOptionals($extrafields, 'edit');
970  }
971 
972  // Show link to origin object
973  if (!empty($origin) && !empty($originid) && is_object($objectsrc))
974  {
975  $newclassname = $classname;
976  if ($newclassname == 'Propal') $newclassname = 'CommercialProposal';
977  print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
978 
979  // Amount
980  /* Hide amount because we only copy services so amount may differ than source
981  print '<tr><td>' . $langs->trans('AmountHT') . '</td><td>' . price($objectsrc->total_ht) . '</td></tr>';
982  print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td>' . price($objectsrc->total_tva) . "</td></tr>";
983  if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
984  {
985  print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1) . "</td></tr>";
986  }
987 
988  if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
989  {
990  print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2) . "</td></tr>";
991  }
992 
993  print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td>' . price($objectsrc->total_ttc) . "</td></tr>";
994 
995  if (!empty($conf->multicurrency->enabled))
996  {
997  print '<tr><td>' . $langs->trans('MulticurrencyAmountHT') . '</td><td>' . price($objectsrc->multicurrency_total_ht) . '</td></tr>';
998  print '<tr><td>' . $langs->trans('MulticurrencyAmountVAT') . '</td><td>' . price($objectsrc->multicurrency_total_tva) . "</td></tr>";
999  print '<tr><td>' . $langs->trans('MulticurrencyAmountTTC') . '</td><td>' . price($objectsrc->multicurrency_total_ttc) . "</td></tr>";
1000  }
1001  */
1002  }
1003 
1004  print '</table>';
1005 
1006  if (is_object($objectsrc))
1007  {
1008  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1009  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1010  } elseif ($origin == 'project' && !empty($projectid)) {
1011  print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1012  }
1013 
1015 
1016  print '<div class="center">';
1017  print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
1018  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1019  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1020  print '</div>';
1021 
1022  print '</form>';
1023 
1024  // Show origin lines
1025  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1026  $title = $langs->trans('Services');
1027  print load_fiche_titre($title);
1028 
1029  print '<table class="noborder centpercent">';
1030 
1031  $objectsrc->printOriginLinesList(empty($conf->global->FICHINTER_PRINT_PRODUCTS) ? 'services' : ''); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
1032 
1033  print '</table>';
1034  }
1035  } else {
1036  print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
1037  print '<input type="hidden" name="token" value="'.newToken().'">';
1038 
1040 
1041  if (is_object($objectsrc))
1042  {
1043  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1044  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1045  } elseif ($origin == 'project' && !empty($projectid)) {
1046  print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1047  }
1048  print '<table class="border centpercent">';
1049  print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
1050  print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300');
1051  print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1052  print '</td></tr>';
1053  print '</table>';
1054 
1056 
1057  print '<div class="center">';
1058  print '<input type="hidden" name="action" value="create">';
1059  print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
1060  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1061  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1062  print '</div>';
1063 
1064  print '</form>';
1065  }
1066 } elseif ($id > 0 || !empty($ref))
1067 {
1068  /*
1069  * Affichage en mode visu
1070  */
1071 
1072  $object->fetch($id, $ref);
1073  $object->fetch_thirdparty();
1074 
1075  $soc = new Societe($db);
1076  $soc->fetch($object->socid);
1077 
1078  if ($error > 0) {
1079  dol_htmloutput_errors($mesg);
1080  } else {
1081  dol_htmloutput_mesg($mesg);
1082  }
1083 
1084  $head = fichinter_prepare_head($object);
1085 
1086  print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, 'intervention');
1087 
1088  $formconfirm = '';
1089 
1090  // Confirm deletion of intervention
1091  if ($action == 'delete')
1092  {
1093  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
1094  }
1095 
1096  // Confirm validation
1097  if ($action == 'validate')
1098  {
1099  // on verifie si l'objet est en numerotation provisoire
1100  $ref = substr($object->ref, 1, 4);
1101  if ($ref == 'PROV')
1102  {
1103  $numref = $object->getNextNumRef($soc);
1104  if (empty($numref))
1105  {
1106  $error++;
1107  setEventMessages($object->error, $object->errors, 'errors');
1108  }
1109  } else {
1110  $numref = $object->ref;
1111  }
1112  $text = $langs->trans('ConfirmValidateIntervention', $numref);
1113 
1114  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
1115  }
1116 
1117  // Confirm back to draft
1118  if ($action == 'modify')
1119  {
1120  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
1121  }
1122 
1123  // Confirm back to open
1124  if ($action == 'reopen')
1125  {
1126  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Reopen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
1127  }
1128 
1129  // Confirm deletion of line
1130  if ($action == 'ask_deleteline')
1131  {
1132  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
1133  }
1134 
1135  // Clone confirmation
1136  if ($action == 'clone') {
1137  // Create an array for form
1138  $formquestion = array(
1139  // 'text' => $langs->trans("ConfirmClone"),
1140  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
1141  // 1),
1142  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
1143  // => 1),
1144  array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '', '', 0, 0, null, 0, 'minwidth200')));
1145  // Paiement incomplet. On demande si motif = escompte ou autre
1146  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1147  }
1148 
1149  if (!$formconfirm)
1150  {
1151  $parameters = array('formConfirm' => $formconfirm, 'lineid'=>$lineid);
1152  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1153  if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
1154  elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
1155  }
1156 
1157  // Print form confirm
1158  print $formconfirm;
1159 
1160 
1161  // Intervention card
1162  $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1163 
1164 
1165  $morehtmlref = '<div class="refidno">';
1166  // Ref customer
1167  //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', 0, 1);
1168  //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', null, null, '', 1);
1169  // Thirdparty
1170  $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
1171  // Project
1172  if (!empty($conf->projet->enabled))
1173  {
1174  $langs->load("projects");
1175  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
1176  if ($user->rights->ficheinter->creer)
1177  {
1178  if ($action != 'classify') {
1179  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
1180  }
1181  if ($action == 'classify') {
1182  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1183  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1184  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1185  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
1186  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1187  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1188  $morehtmlref .= '</form>';
1189  } else {
1190  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1191  }
1192  } else {
1193  if (!empty($object->fk_project)) {
1194  $proj = new Project($db);
1195  $proj->fetch($object->fk_project);
1196  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
1197  $morehtmlref .= $proj->ref;
1198  $morehtmlref .= '</a>';
1199  } else {
1200  $morehtmlref .= '';
1201  }
1202  }
1203  }
1204  $morehtmlref .= '</div>';
1205 
1206  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1207 
1208 
1209  print '<div class="fichecenter">';
1210  print '<div class="fichehalfleft">';
1211  print '<div class="underbanner clearboth"></div>';
1212 
1213  print '<table class="border tableforfield" width="100%">';
1214 
1215  if (!empty($conf->global->FICHINTER_USE_PLANNED_AND_DONE_DATES))
1216  {
1217  // Date Start
1218  print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
1219  print '<td>';
1220  print $object->dateo ? dol_print_date($object->dateo, 'daytext') : '&nbsp;';
1221  print '</td>';
1222  print '</tr>';
1223 
1224  // Date End
1225  print '<tr><td>'.$langs->trans("Datee").'</td>';
1226  print '<td>';
1227  print $object->datee ? dol_print_date($object->datee, 'daytext') : '&nbsp;';
1228  print '</td>';
1229  print '</tr>';
1230 
1231  // Date Terminate/close
1232  print '<tr><td>'.$langs->trans("Datet").'</td>';
1233  print '<td>';
1234  print $object->datet ? dol_print_date($object->datet, 'daytext') : '&nbsp;';
1235  print '</td>';
1236  print '</tr>';
1237  }
1238 
1239  // Description (must be a textarea and not html must be allowed (used in list view)
1240  print '<tr><td class="titlefield">';
1241  print $form->editfieldkey("Description", 'description', $object->description, $object, $user->rights->ficheinter->creer, 'textarea');
1242  print '</td><td>';
1243  print $form->editfieldval("Description", 'description', $object->description, $object, $user->rights->ficheinter->creer, 'textarea:8:80');
1244  print '</td>';
1245  print '</tr>';
1246 
1247  // Contract
1248  if ($conf->contrat->enabled)
1249  {
1250  $langs->load('contracts');
1251  print '<tr>';
1252  print '<td>';
1253 
1254  print '<table class="nobordernopadding centpercent"><tr><td>';
1255  print $langs->trans('Contract');
1256  print '</td>';
1257  if ($action != 'contrat')
1258  {
1259  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=contrat&amp;id='.$object->id.'">';
1260  print img_edit($langs->trans('SetContract'), 1);
1261  print '</a></td>';
1262  }
1263  print '</tr></table>';
1264  print '</td><td>';
1265  if ($action == 'contrat')
1266  {
1267  $formcontract = new Formcontract($db);
1268  $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
1269  } else {
1270  if ($object->fk_contrat)
1271  {
1272  $contratstatic = new Contrat($db);
1273  $contratstatic->fetch($object->fk_contrat);
1274  //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1275  print $contratstatic->getNomUrl(0, '', 1);
1276  } else {
1277  print "&nbsp;";
1278  }
1279  }
1280  print '</td>';
1281  print '</tr>';
1282  }
1283 
1284  // Other attributes
1285  $cols = 2;
1286  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1287 
1288  print '</table>';
1289 
1290  print '</div>';
1291  print '<div class="fichehalfright">';
1292  print '<div class="ficheaddleft">';
1293  print '<div class="underbanner clearboth"></div>';
1294 
1295  print '<table class="border tableforfield centpercent">';
1296 
1297  if (empty($conf->global->FICHINTER_DISABLE_DETAILS))
1298  {
1299  // Duration
1300  print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
1301  print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
1302  print '</tr>';
1303  }
1304 
1305  print "</table>";
1306 
1307  print '</div>';
1308  print '</div>';
1309  print '</div>';
1310 
1311  print '<div class="clearboth"></div><br>';
1312 
1313 
1314  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
1315  {
1316  $blocname = 'contacts';
1317  $title = $langs->trans('ContactsAddresses');
1318  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1319  }
1320 
1321  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB))
1322  {
1323  $blocname = 'notes';
1324  $title = $langs->trans('Notes');
1325  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1326  }
1327 
1328  // Line of interventions
1329  if (empty($conf->global->FICHINTER_DISABLE_DETAILS))
1330  {
1331  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
1332  print '<input type="hidden" name="token" value="'.newToken().'">';
1333  print '<input type="hidden" name="id" value="'.$object->id.'">';
1334  if ($action == 'editline') {
1335  print '<input type="hidden" name="action" value="updateline">';
1336  print '<input type="hidden" name="line_id" value="'.GETPOST('line_id', 'int').'">';
1337  } else {
1338  print '<input type="hidden" name="action" value="addline">';
1339  }
1340 
1341  // Intervention lines
1342  $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
1343  $sql .= ' ft.date as date_intervention';
1344  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1345  $sql .= ' WHERE ft.fk_fichinter = '.$object->id;
1346  if (!empty($conf->global->FICHINTER_HIDE_EMPTY_DURATION)) {
1347  $sql .= ' AND ft.duree <> 0';
1348  }
1349  $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
1350 
1351  $resql = $db->query($sql);
1352  if ($resql)
1353  {
1354  $num = $db->num_rows($resql);
1355  $i = 0;
1356 
1357  if ($num)
1358  {
1359  print '<br>';
1360  print '<table class="noborder centpercent">';
1361  print '<tr class="liste_titre">';
1362 
1363  // No.
1364  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
1365  print '<td width="5" class="center linecolnum"></td>';
1366  }
1367 
1368  print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
1369  print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
1370  print '<td class="liste_titre right">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ? $langs->trans('Duration') : '').'</td>';
1371  print '<td class="liste_titre">&nbsp;</td>';
1372  print '<td class="liste_titre">&nbsp;</td>';
1373  print "</tr>\n";
1374  }
1375  while ($i < $num) {
1376  $objp = $db->fetch_object($resql);
1377 
1378  // Ligne en mode visu
1379  if ($action != 'editline' || GETPOST('line_id', 'int') != $objp->rowid) {
1380  print '<tr class="oddeven">';
1381 
1382  // No.
1383  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
1384  print '<td class="center linecolnum">'.($i + 1).'</td>';
1385  }
1386 
1387  print '<td>';
1388  print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1389  print dol_htmlentitiesbr($objp->description);
1390 
1391  // Date
1392  print '<td class="center" width="150">'.(empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR) ?dol_print_date($db->jdate($objp->date_intervention), 'dayhour') : dol_print_date($db->jdate($objp->date_intervention), 'day')).'</td>';
1393 
1394  // Duration
1395  print '<td class="right" width="150">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ?convertSecondToTime($objp->duree) : '').'</td>';
1396 
1397  print "</td>\n";
1398 
1399  // Icon to edit and delete
1400  if ($object->statut == 0 && $user->rights->ficheinter->creer)
1401  {
1402  print '<td class="center">';
1403  print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;line_id='.$objp->rowid.'#'.$objp->rowid.'">';
1404  print img_edit();
1405  print '</a>';
1406  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=ask_deleteline&amp;line_id='.$objp->rowid.'">';
1407  print img_delete();
1408  print '</a></td>';
1409  print '<td class="center">';
1410  if ($num > 1)
1411  {
1412  if ($i > 0)
1413  {
1414  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=up&amp;line_id='.$objp->rowid.'">';
1415  print img_up();
1416  print '</a>';
1417  }
1418  if ($i < $num - 1)
1419  {
1420  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=down&amp;line_id='.$objp->rowid.'">';
1421  print img_down();
1422  print '</a>';
1423  }
1424  }
1425  print '</td>';
1426  } else {
1427  print '<td colspan="2">&nbsp;</td>';
1428  }
1429 
1430  print '</tr>';
1431 
1432  $line = new FichinterLigne($db);
1433  $line->fetch($objp->rowid);
1434 
1435  $extrafields->fetch_name_optionals_label($line->table_element);
1436 
1437  $line->fetch_optionals();
1438 
1439  print $line->showOptionals($extrafields, 'view', array('colspan'=>5));
1440  }
1441 
1442  // Line in update mode
1443  if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id', 'int') == $objp->rowid)
1444  {
1445  print '<tr class="oddeven nohover">';
1446 
1447  // No.
1448  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
1449  print '<td class="center linecolnum">'.($i + 1).'</td>';
1450  }
1451 
1452  print '<td>';
1453  print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1454 
1455  // Editeur wysiwyg
1456  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1457  $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%');
1458  $doleditor->Create();
1459  print '</td>';
1460 
1461  // Date d'intervention
1462  print '<td class="center nowrap">';
1463  if (!empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
1464  print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
1465  } else {
1466  print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
1467  }
1468  print '</td>';
1469 
1470  // Duration
1471  print '<td class="right">';
1472  if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) {
1473  $selectmode = 'select';
1474  if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION))
1475  $selectmode = 'text';
1476  $form->select_duration('duration', $objp->duree, 0, $selectmode);
1477  }
1478  print '</td>';
1479 
1480  print '<td class="center" colspan="5" valign="center">';
1481  print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
1482  print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
1483  print '</tr>'."\n";
1484 
1485  $line = new FichinterLigne($db);
1486  $line->fetch($objp->rowid);
1487 
1488  $extrafields->fetch_name_optionals_label($line->table_element);
1489  $line->fetch_optionals();
1490 
1491  print $line->showOptionals($extrafields, 'edit', array('colspan'=>5));
1492  }
1493 
1494  $i++;
1495  }
1496 
1497  $db->free($resql);
1498 
1499  // Add new line
1500  if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline' && empty($conf->global->FICHINTER_DISABLE_DETAILS))
1501  {
1502  if (!$num)
1503  {
1504  print '<br>';
1505  print '<table class="noborder centpercent">';
1506  print '<tr class="liste_titre">';
1507 
1508  // No.
1509  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
1510  print '<td width="5" class="center linecolnum"></td>';
1511  }
1512 
1513  print '<td>';
1514  print '<a name="add"></a>'; // ancre
1515  print $langs->trans('Description').'</td>';
1516  print '<td class="center">'.$langs->trans('Date').'</td>';
1517  print '<td class="right">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ? $langs->trans('Duration') : '').'</td>';
1518  print '<td colspan="3">&nbsp;</td>';
1519  print "</tr>\n";
1520  }
1521 
1522  print '<tr class="oddeven nohover">'."\n";
1523 
1524  // No.
1525  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
1526  print '<td class="center linecolnum">'.($i + 1).'</td>';
1527  }
1528 
1529  print '<td>';
1530  // editeur wysiwyg
1531  if (empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) {
1532  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1533  $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%');
1534  $doleditor->Create();
1535  }
1536  print '</td>';
1537 
1538  // Date intervention
1539  print '<td class="center nowrap">';
1540  $now = dol_now();
1541  $timearray = dol_getdate($now);
1542  if (!GETPOST('diday', 'int')) {
1543  $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1544  } else {
1545  $timewithnohour = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
1546  }
1547  if (!empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
1548  print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
1549  } else {
1550  print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
1551  }
1552  print '</td>';
1553 
1554  // Duration
1555  print '<td class="right">';
1556  if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) {
1557  $selectmode = 'select';
1558  if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) {
1559  $selectmode = 'text';
1560  }
1561  $form->select_duration('duration', (!GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int')) ? 3600 : (60 * 60 * GETPOST('durationhour', 'int') + 60 * GETPOST('durationmin', 'int')), 0, $selectmode);
1562  }
1563  print '</td>';
1564 
1565  print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline"></td>';
1566  print '</tr>';
1567 
1568  //Line extrafield
1569 
1570  $lineadd = new FichinterLigne($db);
1571 
1572  $extrafields->fetch_name_optionals_label($lineadd->table_element);
1573 
1574  print $lineadd->showOptionals($extrafields, 'edit', array('colspan'=>5));
1575 
1576  if (!$num) print '</table>';
1577  }
1578 
1579  if ($num) print '</table>';
1580  } else {
1581  dol_print_error($db);
1582  }
1583 
1584  print '</form>'."\n";
1585  }
1586 
1588 
1589  print "\n";
1590 
1591 
1592  /*
1593  * Actions buttons
1594  */
1595 
1596  print '<div class="tabsAction">';
1597 
1598  $parameters = array();
1599  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1600  // modified by hook
1601  if (empty($reshook))
1602  {
1603  if ($user->socid == 0)
1604  {
1605  if ($action != 'editdescription' && ($action != 'presend')) {
1606  // Validate
1607  if ($object->statut == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || !empty($conf->global->FICHINTER_DISABLE_DETAILS))) {
1608  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)) {
1609  print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate"';
1610  print '>'.$langs->trans("Validate").'</a></div>';
1611  }
1612  }
1613 
1614  // Modify
1615  if ($object->statut == Fichinter::STATUS_VALIDATED && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->unvalidate)))
1616  {
1617  print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify">';
1618  if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) print $langs->trans("Modify");
1619  else print $langs->trans("SetToDraft");
1620  print '</a></div>';
1621  }
1622 
1623  // Reopen
1624  if ($object->statut >= Fichinter::STATUS_CLOSED)
1625  {
1626  if ($user->rights->ficheinter->creer)
1627  {
1628  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen">'.$langs->trans('Reopen').'</a></div>';
1629  } else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Reopen').'</a></div>';
1630  }
1631 
1632  // Send
1633  if (empty($user->socid)) {
1634  if ($object->statut > Fichinter::STATUS_DRAFT)
1635  {
1636  if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)
1637  {
1638  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
1639  } else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
1640  }
1641  }
1642 
1643  // create intervention model
1644  if ($conf->global->MAIN_FEATURES_LEVEL >= 1 && $object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer && (count($object->lines) > 0)) {
1645  print '<div class="inline-block divButAction">';
1646  print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id.'&action=create">'.$langs->trans("ChangeIntoRepeatableIntervention").'</a>';
1647  print '</div>';
1648  }
1649 
1650  // Proposal
1651  if ($conf->service->enabled && !empty($conf->propal->enabled) && $object->statut > Fichinter::STATUS_DRAFT)
1652  {
1653  $langs->load("propal");
1654  if ($object->statut < Fichinter::STATUS_BILLED)
1655  {
1656  if ($user->rights->propal->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddProp").'</a></div>';
1657  else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddProp").'</a></div>';
1658  }
1659  }
1660 
1661  // Invoicing
1662  if (!empty($conf->facture->enabled) && $object->statut > Fichinter::STATUS_DRAFT)
1663  {
1664  $langs->load("bills");
1665  if ($object->statut < Fichinter::STATUS_BILLED)
1666  {
1667  if ($user->rights->facture->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddBill").'</a></div>';
1668  else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddBill").'</a></div>';
1669  }
1670 
1671  if (!empty($conf->global->FICHINTER_CLASSIFY_BILLED)) // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
1672  {
1673  if ($object->statut != Fichinter::STATUS_BILLED)
1674  {
1675  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("InterventionClassifyBilled").'</a></div>';
1676  } else {
1677  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifyunbilled">'.$langs->trans("InterventionClassifyUnBilled").'</a></div>';
1678  }
1679  }
1680  }
1681 
1682  // Done
1683  if (empty($conf->global->FICHINTER_CLASSIFY_BILLED) && $object->statut > Fichinter::STATUS_DRAFT && $object->statut < Fichinter::STATUS_CLOSED)
1684  {
1685  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifydone">'.$langs->trans("InterventionClassifyDone").'</a></div>';
1686  }
1687 
1688  // Clone
1689  if ($user->rights->ficheinter->creer) {
1690  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object=ficheinter">'.$langs->trans("ToClone").'</a></div>';
1691  }
1692 
1693  // Delete
1694  if (($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
1695  {
1696  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'"';
1697  print '>'.$langs->trans('Delete').'</a></div>';
1698  }
1699  }
1700  }
1701  }
1702 
1703  print '</div>';
1704 
1705  if ($action != 'presend')
1706  {
1707  print '<div class="fichecenter"><div class="fichehalfleft">';
1708 
1709  /*
1710  * Built documents
1711  */
1712  $filename = dol_sanitizeFileName($object->ref);
1713  $filedir = $conf->ficheinter->dir_output."/".$filename;
1714  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1715  $genallowed = $user->rights->ficheinter->lire;
1716  $delallowed = $user->rights->ficheinter->creer;
1717  print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
1718 
1719  // Show links to link elements
1720  $linktoelem = $form->showLinkToObjectBlock($object, null, array('fichinter'));
1721  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1722 
1723 
1724  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1725 
1726  // List of actions on element
1727  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1728  $formactions = new FormActions($db);
1729  $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1);
1730 
1731  print '</div></div></div>';
1732  }
1733 
1734 
1735  // Select mail models is same action as presend
1736  if (GETPOST('modelselected')) {
1737  $action = 'presend';
1738  }
1739 
1740  // Presend form
1741  $modelmail = 'fichinter_send';
1742  $defaulttopic = 'SendInterventionRef';
1743  $diroutput = $conf->ficheinter->dir_output;
1744  $trackid = 'int'.$object->id;
1745 
1746  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1747 }
1748 
1749 
1750 llxFooter();
1751 
1752 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage products or services.
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into FICHEINTER_ADDON_PDF.
Class to manage contracts.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
const STATUS_DRAFT
Draft status.
const TYPE_SERVICE
Service.
fichinter_prepare_head($object)
Prepare array with list of tabs.
const TYPE_PRODUCT
Regular product.
const STATUS_VALIDATED
Validated status.
convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
Convert hours and minutes into seconds.
Definition: date.lib.php:152
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
img_down($titlealt= 'default', $selected=0, $moreclass= '')
Show down arrow logo.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_up($titlealt= 'default', $selected=0, $moreclass= '')
Show top arrow logo.
Class to manage building of HTML components.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
const STATUS_CLOSED
Closed.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_htmloutput_mesg($mesgstring= '', $mesgarray=array(), $style= 'ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
Class to manage generation of HTML components for contract module.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage intervention lines.
const STATUS_BILLED
Billed.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
dol_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
convertSecondToTime($iSecond, $format= 'all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition: date.lib.php:180