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