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