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