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