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