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