dolibarr 25.0.0-alpha
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-2026 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-2026 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-2026 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024-2026 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';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
49require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
53if (isModEnabled('project')) {
54 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
56}
57if (isModEnabled('contract')) {
58 require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php";
59 require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
60}
61if (getDolGlobalString('FICHEINTER_ADDON') && is_readable(DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_" . getDolGlobalString('FICHEINTER_ADDON').".php")) {
62 require_once DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_" . getDolGlobalString('FICHEINTER_ADDON').'.php';
63}
64if (isModEnabled('category')) {
65 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
66}
67require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
68
69// Load translation files required by the page
70$langs->loadLangs(array('bills', 'companies', 'interventions', 'stocks'));
71
72$id = GETPOSTINT('id');
73$ref = GETPOST('ref', 'alpha');
74$ref_client = GETPOST('ref_client', 'alpha');
75$socid = GETPOSTINT('socid');
76$contratid = GETPOSTINT('contratid');
77$action = GETPOST('action', 'alpha');
78$cancel = GETPOST('cancel', 'alpha');
79$confirm = GETPOST('confirm', 'alpha');
80$backtopage = GETPOST('backtopage', 'alpha');
81
82$mesg = GETPOST('msg', 'alpha');
83$origin = GETPOST('origin', 'alpha');
84$originid = (GETPOSTINT('originid') ? GETPOSTINT('originid') : GETPOSTINT('origin_id')); // For backward compatibility
85$note_public = GETPOST('note_public', 'restricthtml');
86$note_private = GETPOST('note_private', 'restricthtml');
87$lineid = GETPOSTINT('line_id');
88
89$error = 0;
90
91// PDF
92$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
93$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
94$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
95
96// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
97$hookmanager->initHooks(array('fichintercard', 'interventioncard', 'globalcard'));
98
99$object = new Fichinter($db);
100
101$objectsrc = null;
102
103$extrafields->fetch_name_optionals_label($object->table_element);
104
105// Load object
106if ($id > 0 || !empty($ref)) {
107 $ret = $object->fetch($id, $ref);
108 if ($ret > 0) {
109 $ret = $object->fetch_thirdparty();
110 }
111 if ($ret < 0) {
112 dol_print_error(null, $object->error);
113 }
114}
115
116// Security check
117if ($user->isExternalUser()) {
118 $socid = $user->isExternalUser();
119}
120$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
121
122$permissionnote = $user->hasRight('ficheinter', 'creer'); // Used by the include of actions_setnotes.inc.php
123$permissiondellink = $user->hasRight('ficheinter', 'creer'); // Used by the include of actions_dellink.inc.php
124$permissiontodelete = (($object->status == Fichinter::STATUS_DRAFT && $user->hasRight('ficheinter', 'creer')) || $user->hasRight('ficheinter', 'supprimer'));
125$permissiontoread = $user->hasRight('ficheinter', 'lire');
126$permissiontoadd = $user->hasRight('ficheinter', 'creer');
127$permissiontoeditextra = $permissiontoadd;
128if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
129 // For action 'update_extras', is there a specific permission set for the attribute to update
130 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
131}
132
133
134$classname = '';
135
136/*
137 * Actions
138 */
139
140$parameters = array('socid' => $socid);
141$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
142if ($reshook < 0) {
143 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
144}
145
146if (empty($reshook)) {
147 $backurlforlist = DOL_URL_ROOT.'/fichinter/list.php';
148
149 if (empty($backtopage) || ($cancel && empty($id))) {
150 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
151 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
152 $backtopage = $backurlforlist;
153 } else {
154 $backtopage = DOL_URL_ROOT.'/fichinter/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
155 }
156 }
157 }
158
159 if ($cancel) {
160 if (!empty($backtopageforcancel)) {
161 header("Location: ".$backtopageforcancel);
162 exit;
163 } elseif (!empty($backtopage)) {
164 header("Location: ".$backtopage);
165 exit;
166 }
167 $action = '';
168 }
169
170 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
171
172 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
173
174 // Action clone object
175 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
176 if (false && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
177 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
178 } else {
179 if ($object->id > 0) {
180 // Because createFromClone modifies the object, we must clone it so that we can restore it later
181 $orig = clone $object;
182 $clone_notes = false;
183 if (GETPOSTISSET('clone_notes') && GETPOST('clone_notes') === 'on') {
184 $clone_notes = true;
185 }
186 $clone_contacts = false;
187 if (GETPOSTISSET('clone_contacts') && GETPOST('clone_contacts') === 'on') {
188 $clone_contacts = true;
189 }
190
191 $result = $object->createFromClone($user, $socid, $clone_contacts, $clone_notes);
192 if ($result > 0) {
193 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
194 exit;
195 } else {
196 setEventMessages($object->error, $object->errors, 'errors');
197 $object = $orig;
198 $action = '';
199 }
200 }
201 }
202 }
203
204 if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
205 $result = $object->setValid($user);
206
207 if ($result >= 0) {
208 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
209 // Define output language
210 $outputlangs = $langs;
211 $newlang = '';
212 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
213 $newlang = GETPOST('lang_id', 'aZ09');
214 }
215 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
216 $newlang = $object->thirdparty->default_lang;
217 }
218 if (!empty($newlang)) {
219 $outputlangs = new Translate("", $conf);
220 $outputlangs->setDefaultLang($newlang);
221 }
222 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
223 }
224
225 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
226 exit;
227 } else {
228 $mesg = $object->error;
229 }
230 } elseif ($action == 'confirm_sign' && $confirm == 'yes' && $permissiontoadd) {
231 $result = $object->setSignedStatus($user, GETPOSTINT('signed_status'), 0, 'FICHINTER_MODIFY');
232 if ($result >= 0) {
233 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
234 // Define output language
235 $outputlangs = $langs;
236 $newlang = '';
237 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
238 $newlang = GETPOST('lang_id', 'aZ09');
239 }
240 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
241 $newlang = $object->thirdparty->default_lang;
242 }
243 if (!empty($newlang)) {
244 $outputlangs = new Translate("", $conf);
245 $outputlangs->setDefaultLang($newlang);
246 }
247 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
248 }
249
250 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
251 exit;
252 } else {
253 $mesg = $object->error;
254 }
255 } elseif ($action == 'confirm_unsign' && $confirm == 'yes' && $permissiontoadd) {
256 $result = $object->setSignedStatus($user, Fichinter::$SIGNED_STATUSES['STATUS_NO_SIGNATURE'], 0, 'FICHINTER_MODIFY');
257 if ($result >= 0) {
258 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
259 // Define output language
260 $outputlangs = $langs;
261 $newlang = '';
262 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
263 $newlang = GETPOST('lang_id', 'aZ09');
264 }
265 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
266 $newlang = $object->thirdparty->default_lang;
267 }
268 if (!empty($newlang)) {
269 $outputlangs = new Translate("", $conf);
270 $outputlangs->setDefaultLang($newlang);
271 }
272 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
273 }
274
275 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
276 exit;
277 } else {
278 $mesg = $object->error;
279 }
280 } elseif ($action == 'confirm_modify' && $confirm == 'yes' && $permissiontoadd) {
281 $result = $object->setDraft($user);
282 if ($result >= 0) {
283 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
284 // Define output language
285 $outputlangs = $langs;
286 $newlang = '';
287 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
288 $newlang = GETPOST('lang_id', 'aZ09');
289 }
290 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
291 $newlang = $object->thirdparty->default_lang;
292 }
293 if (!empty($newlang)) {
294 $outputlangs = new Translate("", $conf);
295 $outputlangs->setDefaultLang($newlang);
296 }
297 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
298 }
299
300 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
301 exit;
302 } else {
303 $mesg = $object->error;
304 }
305 } elseif ($action == 'confirm_done' && $confirm == 'yes' && $permissiontoadd) {
306 $result = $object->setClose($user);
307
308 if ($result >= 0) {
309 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
310 // Define output language
311 $outputlangs = $langs;
312 $newlang = '';
313 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
314 $newlang = GETPOST('lang_id', 'aZ09');
315 }
316 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
317 $newlang = $object->thirdparty->default_lang;
318 }
319 if (!empty($newlang)) {
320 $outputlangs = new Translate("", $conf);
321 $outputlangs->setDefaultLang($newlang);
322 }
323 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
324 }
325
326 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
327 exit;
328 } else {
329 $mesg = $object->error;
330 }
331 } elseif ($action == 'add' && $permissiontoadd) {
332 $selectedLines = GETPOST('toselect', 'array:int');
333 $object->socid = $socid;
334 $object->duration = GETPOSTINT('duration');
335 $object->fk_project = GETPOSTINT('projectid');
336 $object->fk_contrat = GETPOSTINT('contratid');
337 $object->user_author_id = $user->id;
338 $object->description = GETPOST('description', 'restricthtml');
339 $object->ref = $ref;
340 $object->ref_client = $ref_client;
341 $object->model_pdf = GETPOST('model', 'alpha');
342 $object->note_private = GETPOST('note_private', 'restricthtml');
343 $object->note_public = GETPOST('note_public', 'restricthtml');
344
345 if ($object->socid > 0) {
346 // If creation from another object of another module (Example: origin=propal, originid=1)
347 if (!empty($origin) && !empty($originid)) {
348 // Parse element/subelement (ex: project_task)
349 $regs = array();
350 $element = $subelement = GETPOST('origin', 'alphanohtml');
351 if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
352 $element = $regs[1];
353 $subelement = $regs[2];
354 }
355
356 // For compatibility
357 if ($element == 'order') {
358 $element = $subelement = 'commande';
359 }
360 if ($element == 'propal') {
361 $element = 'comm/propal';
362 $subelement = 'propal';
363 }
364 if ($element == 'contract') {
365 $element = $subelement = 'contrat';
366 }
367
368 $object->origin = $origin;
369 $object->origin_id = $originid;
370
371 // Possibility to add external linked objects with hooks
372 $object->linked_objects[$object->origin] = $object->origin_id;
373 if (GETPOSTISARRAY('other_linked_objects')) {
374 $object->linked_objects = array_merge($object->linked_objects, GETPOST('other_linked_objects', 'array:int'));
375 }
376
377 // Extrafields
378
379 // Fill array 'array_options' with data from add form
380 $ret = $extrafields->setOptionalsFromPost(null, $object);
381 if ($ret < 0) {
382 $error++;
383 $action = 'create';
384 }
385 //$array_options = $extrafields->getOptionalsFromPost($object->table_element);
386
387 //$object->array_options = $array_options;
388
389 $id = $object->create($user);
390
391 if ($id > 0) {
392 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
393
394 $classname = ucfirst($subelement);
395 $srcobject = new $classname($db);
396 '@phan-var-force Commande|Propal|Contrat $srcobject'; // Can be other class, but CommonObject is too generic
399 dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
400 $result = $srcobject->fetch($object->origin_id);
401 if ($result > 0) {
402 $srcobject->fetch_thirdparty();
403 $lines = $srcobject->lines;
404 if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
405 $srcobject->fetch_lines();
406 $lines = $srcobject->lines;
407 }
408
409 if (is_array($lines)) {
410 $num = count($lines);
411
412 for ($i = 0; $i < $num; $i++) {
413 if (!in_array($lines[$i]->id, $selectedLines)) {
414 continue; // Skip unselected lines
415 }
416
417 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : Product::TYPE_PRODUCT);
418
419 if ($product_type == Product::TYPE_SERVICE || getDolGlobalString('FICHINTER_PRINT_PRODUCTS')) { //only services except if config includes products
420 $duration = 3600; // Default to one hour
421 $desc = '';
422 // Predefined products & services
423 if ($lines[$i]->fk_product > 0) {
424 $prod = new Product($db);
425 $prod->id = $lines[$i]->fk_product;
426
427 // Define output language
428 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
429 $prod->getMultiLangs();
430 // We show if duration is present on service (so we get it)
431 $prod->fetch($lines[$i]->fk_product);
432 $outputlangs = $langs;
433 $newlang = '';
434 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
435 $newlang = GETPOST('lang_id', 'aZ09');
436 }
437 if (empty($newlang)) {
438 $newlang = $srcobject->thirdparty->default_lang;
439 }
440 if (!empty($newlang)) {
441 $outputlangs = new Translate("", $conf);
442 $outputlangs->setDefaultLang($newlang);
443 }
444 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
445 } else {
446 $prod->fetch($lines[$i]->fk_product);
447 $label = $lines[$i]->product_label;
448 }
449
450 if ($prod->duration_value && getDolGlobalString('FICHINTER_USE_SERVICE_DURATION')) {
451 switch ($prod->duration_unit) {
452 default:
453 case 'h':
454 $mult = 3600;
455 break;
456 case 'd':
457 $mult = 3600 * 24;
458 break;
459 case 'w':
460 $mult = 3600 * 24 * 7;
461 break;
462 case 'm':
463 $mult = (int) (3600 * 24 * (365 / 12)); // Average month duration
464 break;
465 case 'y':
466 $mult = 3600 * 24 * 365;
467 break;
468 }
469 $duration = (int) $prod->duration_value * $mult * $lines[$i]->qty;
470 }
471
472 $desc = $lines[$i]->product_ref;
473 $desc .= ' - ';
474 $desc .= $label;
475 $desc .= '<br>';
476 }
477 // Common part (predefined or free line)
478 $desc .= dol_htmlentitiesbr($lines[$i]->desc);
479 $desc .= '<br>';
480 $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
481
482 $timearray = dol_getdate(dol_now());
483 $date_intervention = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
484
485 if ($product_type == Product::TYPE_PRODUCT) {
486 $duration = 0;
487 }
488
489 $predef = '';
490
491 // Extrafields
492 $extrafields->fetch_name_optionals_label($object->table_element_line);
493 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
494
495 $result = $object->addline(
496 $user,
497 $id,
498 $desc,
499 $date_intervention,
500 $duration,
501 $array_options
502 );
503
504 if ($result < 0) {
505 $error++;
506 break;
507 }
508 }
509 }
510 }
511 } else {
512 $langs->load("errors");
513 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
514 $action = 'create';
515 $error++;
516 }
517 } else {
518 $langs->load("errors");
519 setEventMessages($object->error, $object->errors, 'errors');
520 $action = 'create';
521 $error++;
522 }
523 } else {
524 // Fill array 'array_options' with data from add form
525 $ret = $extrafields->setOptionalsFromPost(null, $object);
526 if ($ret < 0) {
527 $error++;
528 $action = 'create';
529 }
530
531 if (!$error) {
532 // Extrafields
533 $array_options = $extrafields->getOptionalsFromPost($object->table_element);
534
535 $object->array_options = $array_options;
536
537 $result = $object->create($user);
538
539 if ($result > 0) {
540 $id = $result; // Force refresh on a newly created record
541
542 // Category association
543 $categories = GETPOST('categories', 'array');
544 $object->setCategories($categories);
545 } else {
546 $langs->load("errors");
547 setEventMessages($object->error, $object->errors, 'errors');
548 $action = 'create';
549 $error++;
550 }
551 }
552 }
553 } else {
554 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty"));
555 $action = 'create';
556 $error++;
557 }
558 } elseif ($action == 'update' && $permissiontoadd) {
559 $object->socid = $socid;
560 $object->fk_project = GETPOSTINT('projectid');
561 $object->fk_contrat = GETPOSTINT('contratid');
562 $object->user_author_id = $user->id;
563 $object->description = GETPOST('description', 'restricthtml');
564 $object->ref = $ref;
565 $object->ref_client = $ref_client;
566
567 $result = $object->update($user);
568 if ($result < 0) {
569 setEventMessages($object->error, $object->errors, 'errors');
570 }
571 } elseif ($action == 'classin' && $permissiontoadd) {
572 // Set into a project
573 $result = $object->setProject(GETPOSTINT('projectid'));
574 if ($result < 0) {
575 dol_print_error($db, $object->error);
576 }
577 } elseif ($action == 'setcontract' && $permissiontoadd) {
578 // Set into a contract
579 $result = $object->set_contrat($user, GETPOSTINT('contratid'));
580 if ($result < 0) {
581 dol_print_error($db, $object->error);
582 }
583 } elseif ($action == 'settags' && isModEnabled('category') && $permissiontoadd) {
584 // Set tags
585 $result = $object->setCategories(GETPOST('categories', 'array'));
586 if ($result < 0) {
587 setEventMessages($object->error, $object->errors, 'errors');
588 }
589 } elseif ($action == 'setref_client' && $permissiontoadd) {
590 // Set customer reference
591 $result = $object->setRefClient($user, GETPOST('ref_client', 'alpha'));
592 if ($result < 0) {
593 setEventMessages($object->error, $object->errors, 'errors');
594 }
595 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
596 $result = $object->delete($user);
597 if ($result < 0) {
598 setEventMessages($object->error, $object->errors, 'errors');
599 }
600
601 header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter&restore_lastsearch_values=1');
602 exit;
603 } elseif ($action == 'setdescription' && $permissiontoadd) {
604 $result = $object->set_description($user, GETPOST('description'));
605 if ($result < 0) {
606 dol_print_error($db, $object->error);
607 }
608 } elseif ($action == "addline" && $permissiontoadd) {
609 // Add line
610 if (!GETPOST('np_desc', 'restricthtml') && !getDolGlobalString('FICHINTER_EMPTY_LINE_DESC')) {
611 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description"));
612 $error++;
613 }
614 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION') && !GETPOSTINT('durationhour') && !GETPOSTINT('durationmin')) {
615 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Duration"));
616 $error++;
617 }
618 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION') && GETPOSTINT('durationhour') >= 24 && GETPOSTINT('durationmin') > 0) {
619 $mesg = $langs->trans("ErrorValueTooHigh");
620 $error++;
621 }
622 if (!$error) {
623 $db->begin();
624
625 $desc = GETPOST('np_desc', 'restricthtml');
626 $date_intervention = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
627 $duration = !getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? convertTime2Seconds(GETPOSTINT('durationhour'), GETPOSTINT('durationmin')) : 0;
628
629 // Extrafields
630 $extrafields->fetch_name_optionals_label($object->table_element_line);
631 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
632
633 $result = $object->addline(
634 $user,
635 $id,
636 $desc,
637 $date_intervention,
638 $duration,
639 $array_options
640 );
641
642 // Define output language
643 $outputlangs = $langs;
644 $newlang = '';
645 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
646 $newlang = GETPOST('lang_id', 'aZ09');
647 }
648 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
649 $newlang = $object->thirdparty->default_lang;
650 }
651 if (!empty($newlang)) {
652 $outputlangs = new Translate("", $conf);
653 $outputlangs->setDefaultLang($newlang);
654 }
655
656 if ($result >= 0) {
657 $db->commit();
658
659 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
660 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
661 }
662 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
663 exit;
664 } else {
665 $mesg = $object->error;
666 $db->rollback();
667 }
668 }
669 } elseif ($action == 'confirm_addtitleline' && $permissiontoadd) {
670 // Handling adding a new title line for subtotals module
671
672 $langs->load('subtotals');
673
674 $desc = GETPOST('subtotallinedesc', 'alphanohtml');
675 $depth = GETPOSTINT('subtotallinelevel') ?? 1;
676
677 $subtotal_options = array();
678
679 foreach (Fichinter::$TITLE_OPTIONS as $option) {
680 $value = GETPOST($option, 'alphanohtml');
681 if ($value) {
682 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
683 }
684 }
685
686 // Insert line
687 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
688
689 if ($result >= 0) {
690 if ($result == 0) {
691 setEventMessages($object->error, $object->errors, 'warnings');
692 }
693 $ret = $object->fetch($object->id); // Reload to get new records
694 $object->fetch_thirdparty();
695
696 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
697 // Define output language
698 $outputlangs = $langs;
699 $newlang = GETPOST('lang_id', 'alpha');
700 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
701 $newlang = $object->thirdparty->default_lang;
702 }
703 if (!empty($newlang)) {
704 $outputlangs = new Translate("", $conf);
705 $outputlangs->setDefaultLang($newlang);
706 }
707
708 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
709 }
710 } else {
711 setEventMessages($object->error, $object->errors, 'errors');
712 }
713 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
714 exit();
715 } elseif ($action == 'confirm_addsubtotalline' && $permissiontoadd) {
716 // Handling adding a new subtotal line for subtotals module
717
718 $langs->load('subtotals');
719
720 $choosen_line = GETPOST('subtotaltitleline', 'alphanohtml');
721 foreach ($object->lines as $line) {
722 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
723 $desc = $line->desc;
724 $depth = -$line->qty;
725 }
726 }
727
728 $subtotal_options = array();
729
730 foreach (Fichinter::$SUBTOTAL_OPTIONS as $option) {
731 $value = GETPOST($option, 'alphanohtml');
732 if ($value) {
733 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
734 }
735 }
736
737 // Insert line
738 if (isset($desc) && isset($depth)) {
739 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
740 } else {
741 $result = -1;
742 $object->errors[] = $langs->trans("CorrespondingTitleNotFound");
743 }
744
745 if ($result >= 0) {
746 $ret = $object->fetch($object->id); // Reload to get new records
747 $object->fetch_thirdparty();
748
749 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
750 // Define output language
751 $outputlangs = $langs;
752 $newlang = GETPOST('lang_id', 'alpha');
753 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
754 $newlang = $object->thirdparty->default_lang;
755 }
756 if (!empty($newlang)) {
757 $outputlangs = new Translate("", $conf);
758 $outputlangs->setDefaultLang($newlang);
759 }
760
761 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
762 }
763 } else {
764 setEventMessages($object->error, $object->errors, 'errors');
765 }
766 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
767 exit();
768 } elseif ($action == 'confirm_addtextline' && $permissiontoadd) {
769 // Handling adding a new text line for subtotals module
770
771 $langs->load('subtotals');
772
773 $desc = GETPOST('subtotaltextcontent', 'restricthtml');
774
775 // Insert line
776 $result = $object->addSubtotalLine($langs, $desc, 0, array());
777
778 if ($result >= 0) {
779 if ($result == 0) {
780 setEventMessages($object->error, $object->errors, 'warnings');
781 }
782 $ret = $object->fetch($object->id); // Reload to get new records
783 $object->fetch_thirdparty();
784
785 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
786 // Define output language
787 $outputlangs = $langs;
788 $newlang = GETPOST('lang_id', 'alpha');
789 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
790 $newlang = $object->thirdparty->default_lang;
791 }
792 if (!empty($newlang)) {
793 $outputlangs = new Translate("", $conf);
794 $outputlangs->setDefaultLang($newlang);
795 }
796
797 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
798 }
799 } else {
800 setEventMessages($object->error, $object->errors, 'errors');
801 }
802 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
803 exit();
804 } elseif ($action == 'classifybilled' && $permissiontoadd) {
805 // Classify Billed
806 $result = $object->setStatut(Fichinter::STATUS_BILLED);
807 if ($result > 0) {
808 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
809 exit;
810 } else {
811 setEventMessages($object->error, $object->errors, 'errors');
812 }
813 } elseif ($action == 'classifyunbilled' && $permissiontoadd) {
814 // Classify unbilled
815 $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
816 if ($result > 0) {
817 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
818 exit;
819 } else {
820 $mesg = $object->error;
821 }
822 } elseif ($action == 'confirm_reopen' && $permissiontoadd) {
823 // Reopen
824 $result = $object->setReopen($user);
825 if ($result > 0) {
826 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
827 exit;
828 } else {
829 $mesg = $object->error;
830 }
831 } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $permissiontoadd) {
832 $result = $object->setCanceled($user);
833
834 if ($result < 0) {
835 setEventMessages($object->error, $object->errors, 'errors');
836 }
837 } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('save', 'alpha')) {
838 // Update an intervention line
839 $objectline = new FichinterLigne($db);
840 if ($objectline->fetch($lineid) <= 0) {
842 exit;
843 }
844
845 if ($object->fetch($objectline->fk_fichinter) <= 0) {
847 exit;
848 }
849 $object->fetch_thirdparty();
850
851 $desc = GETPOST('np_desc', 'restricthtml');
852 $date_inter = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
853 $duration = convertTime2Seconds(GETPOSTINT('durationhour'), GETPOSTINT('durationmin'));
854
855 $objectline->date = $date_inter;
856 $objectline->desc = $desc;
857 if ($objectline->special_code != SUBTOTALS_SPECIAL_CODE) {
858 $objectline->duration = $duration;
859 }
860
861 // Extrafields
862 $extrafields->fetch_name_optionals_label($object->table_element_line);
863 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
864 if (is_array($array_options)) {
865 $objectline->array_options = array_merge($objectline->array_options, $array_options);
866 }
867
868 $result = $objectline->update($user);
869 if ($result < 0) {
870 // Surface validation errors (e.g. mandatory extrafield left empty) as an
871 // event message on the same page instead of breaking with a full Dolibarr
872 // error screen that loses the user's edit context.
873 setEventMessages($objectline->error, $objectline->errors, 'errors');
874 }
875
876 // Define output language
877 $outputlangs = $langs;
878 $newlang = '';
879 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
880 $newlang = GETPOST('lang_id', 'aZ09');
881 }
882 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
883 $newlang = $object->thirdparty->default_lang;
884 }
885 if (!empty($newlang)) {
886 $outputlangs = new Translate("", $conf);
887 $outputlangs->setDefaultLang($newlang);
888 }
889 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
890 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
891 }
892
893 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
894 exit;
895 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoadd) {
896 // Delete an intervention line WITH confirmation
897 $objectline = new FichinterLigne($db);
898 if ($objectline->fetch($lineid) <= 0) {
900 exit;
901 }
902 $result = $objectline->deleteLine($user);
903
904 if ($object->fetch($objectline->fk_fichinter) <= 0) {
906 exit;
907 }
908
909 // Define output language
910 $outputlangs = $langs;
911 $newlang = '';
912 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
913 $newlang = GETPOST('lang_id', 'aZ09');
914 }
915 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
916 $newlang = $object->thirdparty->default_lang;
917 }
918 if (!empty($newlang)) {
919 $outputlangs = new Translate("", $conf);
920 $outputlangs->setDefaultLang($newlang);
921 }
922 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
923 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
924 }
925 } elseif ($action == 'confirm_delete_subtotalline' && $confirm == 'yes' && $permissiontoadd) {
926 // Remove a subtotal / title / text line (subtotals module)
927 $object->fetch($id);
928
929 $result = $object->deleteSubtotalLine($langs, GETPOSTINT('lineid'), (bool) GETPOST('deletecorrespondingsubtotalline'));
930 if ($result > 0) {
931 $object->line_order(true);
932 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
933 exit;
934 } else {
935 setEventMessages($object->error, $object->errors, 'errors');
936 $action = '';
937 }
938 } elseif ($action == 'up' && $permissiontoadd) {
939 // Set position of lines
940 $object->line_up($lineid);
941
942 // Define output language
943 $outputlangs = $langs;
944 $newlang = '';
945 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
946 $newlang = GETPOST('lang_id', 'aZ09');
947 }
948 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
949 $newlang = $object->thirdparty->default_lang;
950 }
951 if (!empty($newlang)) {
952 $outputlangs = new Translate("", $conf);
953 $outputlangs->setDefaultLang($newlang);
954 }
955 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
956 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
957 }
958
959 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
960 exit;
961 } elseif ($action == 'down' && $permissiontoadd) {
962 $object->line_down($lineid);
963
964 // Define output language
965 $outputlangs = $langs;
966 $newlang = '';
967 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
968 $newlang = GETPOST('lang_id', 'aZ09');
969 }
970 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
971 $newlang = $object->thirdparty->default_lang;
972 }
973 if (!empty($newlang)) {
974 $outputlangs = new Translate("", $conf);
975 $outputlangs->setDefaultLang($newlang);
976 }
977 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
978 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
979 }
980
981 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
982 exit;
983 }
984
985 // Actions when printing a doc from card
986 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
987
988 // Actions to send emails
989 $triggersendname = 'FICHINTER_SENTBYMAIL';
990 $autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
991 $trackid = 'int'.$object->id;
992 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
993
994 // Actions to build doc
995 $upload_dir = getMultidirOutput($object);
996 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
997
998 if ($action == 'update_extras' && $permissiontoeditextra) {
999 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
1000
1001 $attribute_name = GETPOST('attribute', 'aZ09');
1002
1003 // Fill array 'array_options' with data from update form
1004 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
1005 if ($ret < 0) {
1006 $error++;
1007 }
1008
1009 if (!$error) {
1010 // Actions on extra fields
1011 $result = $object->updateExtraField($attribute_name, 'FICHINTER_MODIFY');
1012 if ($result < 0) {
1013 setEventMessages($object->error, $object->errors, 'errors');
1014 $error++;
1015 }
1016 }
1017
1018 if ($error) {
1019 $action = 'edit_extras';
1020 }
1021 }
1022
1023 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1024 if ($action == 'addcontact' && $permissiontoadd) {
1025 if ($result > 0 && $id > 0) {
1026 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
1027 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1028 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1029 }
1030
1031 if ($result >= 0) {
1032 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1033 exit;
1034 } else {
1035 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1036 $langs->load("errors");
1037 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
1038 } else {
1039 $mesg = $object->error;
1040 }
1041 }
1042 } elseif ($action == 'swapstatut' && $permissiontoadd) {
1043 // Toggle the status of a contact
1044 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
1045 } elseif ($action == 'deletecontact' && $permissiontoadd) {
1046 // Delete a contact
1047 $result = $object->delete_contact(GETPOSTINT('lineid'));
1048
1049 if ($result >= 0) {
1050 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1051 exit;
1052 } else {
1054 }
1055 }
1056 }
1057}
1058
1059
1060/*
1061 * View
1062 */
1063
1064$form = new Form($db);
1065$formfile = new FormFile($db);
1066$formcontract = null;
1067$formproject = null;
1068if (isModEnabled('contract')) {
1069 $formcontract = new FormContract($db);
1070}
1071if (isModEnabled('project')) {
1072 $formproject = new FormProjets($db);
1073}
1074
1075$title = $object->ref . " - " . $langs->trans('Card');
1076if ($action == 'create') {
1077 $title = $langs->trans("NewIntervention");
1078}
1079$help_url = 'EN:Module_Interventions|FR:Module_Fiches_d\'interventions';
1080
1081llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-fichinter page-card');
1082
1083// Create new intervention
1084if ($action == 'create') {
1085 $soc = new Societe($db);
1086 if ($socid > 0) {
1087 $soc->fetch($socid);
1088 }
1089
1090 print load_fiche_titre($langs->trans("NewIntervention"), '', 'intervention');
1091
1092 if ($error > 0) {
1093 dol_htmloutput_errors($mesg);
1094 } else {
1095 dol_htmloutput_mesg($mesg);
1096 }
1097
1098 if (GETPOST('origin', 'alphanohtml') && GETPOSTINT('originid')) {
1099 // Parse element/subelement (ex: project_task)
1100 $regs = array();
1101 $element = $subelement = GETPOST('origin', 'alphanohtml');
1102 if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
1103 $element = $regs[1];
1104 $subelement = $regs[2];
1105 }
1106
1107 if ($element == 'project') {
1108 $projectid = GETPOSTINT('originid');
1109 } else {
1110 // For compatibility
1111 if ($element == 'order' || $element == 'commande') {
1112 $element = $subelement = 'commande';
1113 }
1114 if ($element == 'propal') {
1115 $element = 'comm/propal';
1116 $subelement = 'propal';
1117 }
1118 if ($element == 'contract') {
1119 $element = $subelement = 'contrat';
1120 }
1121
1122 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1123
1124 $classname = ucfirst($subelement);
1125 $objectsrc = new $classname($db);
1126 '@phan-var-force Commande|Propal|Contrat $objectsrc';
1127 $objectsrc->fetch(GETPOSTINT('originid'));
1128 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1129 $objectsrc->fetch_lines();
1130 $lines = $objectsrc->lines;
1131 }
1132 $objectsrc->fetch_thirdparty();
1133
1134 $projectid = (int) $objectsrc->fk_project;
1135
1136 $soc = $objectsrc->thirdparty;
1137
1138 $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private', 'restricthtml')));
1139 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public', 'restricthtml'));
1140
1141 // Replicate extrafields
1142 $objectsrc->fetch_optionals();
1143 $object->array_options = $objectsrc->array_options;
1144
1145 // Object source contacts list
1146 $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
1147 }
1148 } else {
1149 $projectid = GETPOSTINT('projectid');
1150 $note_private = GETPOST("note_private", "alpha");
1151 $note_public = GETPOST("note_public", "alpha");
1152 }
1153
1154 if (!$conf->global->FICHEINTER_ADDON) {
1155 dol_print_error($db, $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
1156 exit;
1157 }
1158
1159 $object->datec = dol_now();
1160
1161 $obj = getDolGlobalString('FICHEINTER_ADDON');
1162 $obj = "mod_".$obj;
1163
1164 //$modFicheinter = new $obj;
1165 //$numpr = $modFicheinter->getNextValue($soc, $object);
1166
1167 print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
1168 print '<input type="hidden" name="token" value="'.newToken().'">';
1169 print '<input type="hidden" name="socid" value='.$soc->id.'>';
1170 print '<input type="hidden" name="action" value="add">';
1171 print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
1172 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1173
1174 print dol_get_fiche_head([]);
1175
1176 print '<table class="border centpercent">';
1177
1178 // Ref
1179 print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
1180
1181 // Ref customer
1182 print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
1183 print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
1184 print '</tr>';
1185
1186 // Thirdparty
1187 print '<tr>';
1188 print '<td class="fieldrequired">'.$langs->trans('ThirdParty').'</td>';
1189 if ($socid > 0) {
1190 print '<td>';
1191 print $soc->getNomUrl(1);
1192 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1193 print '</td>';
1194 } else {
1195 print '<td>';
1196 print img_picto('', 'company', 'class="pictofixedwidth"');
1197 $filter = '(s.status:=:1)';
1198 print $form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth150 widthcentpercentminusxx maxwidth500');
1199 print ' <a href="'.dolBuildUrl(DOL_URL_ROOT . '/societe/card.php', ['action' => 'create', 'customer' => 3, 'backtopage' => dolBuildUrl($_SERVER["PHP_SELF"], ['action' => 'create'])]).'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1200 print '</td>';
1201 }
1202 print '</tr>'."\n";
1203
1204 // Description (must be a textarea and not html must be allowed (used in list view)
1205 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
1206 print '<td>';
1207 print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
1208 print '</td></tr>';
1209
1210 // Project
1211 if (isModEnabled('project')) {
1212 $formproject = new FormProjets($db);
1213
1214 $langs->load("project");
1215
1216 print '<tr><td>'.$langs->trans("Project").'</td><td>';
1217 print img_picto('', 'project', 'class="pictofixedwidth"');
1218 /* 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
1219 if ($societe->fournisseur==1)
1220 $numprojet=select_projects(-1, GETPOST("projectid", 'int'), 'projectid');
1221 else
1222 $numprojet=select_projects($societe->id, GETPOST("projectid", 'int'), 'projectid');
1223 */
1224 $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth500 widthcentpercentminusxx');
1225 if ($numprojet == 0) {
1226 print ' &nbsp; <a href="' . dolBuildUrl(DOL_URL_ROOT . '/projet/card.php', ['socid' => $soc->id, 'action' => 'create', 'status' => 1, 'backtopage' => dolBuildUrl($_SERVER["PHP_SELF"], ['action' => 'create', 'socid' => $soc->id])]) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
1227 }
1228 print '</td></tr>';
1229 }
1230
1231 // Category
1232 if (isModEnabled('category')) {
1233 // Categories
1234 print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
1235 print $form->selectCategories(Categorie::TYPE_FICHINTER, 'categories', $object);
1236 print "</td></tr>";
1237 }
1238
1239 // Contract
1240 if (isModEnabled('contract') && is_object($formcontract)) {
1241 // This feature hang the application on large list of contracts, because the select component is not complete: it does not work like select of thirdparty or product to support large lists
1242 // So we add a hidden option to avoid to have it used and the application locked, until the select_contract is fixed.
1243 if (getDolGlobalString("CONTRACT_CAN_USE_THE_BUGGED_SELECT_COMPONENT")) {
1244 $langs->load("contracts");
1245 print '<tr><td>'.$langs->trans("Contract").'</td><td>';
1246 $numcontrat = $formcontract->select_contract($soc->id, GETPOSTINT('contratid'), 'contratid', 0, 1, 1);
1247 if ($numcontrat == 0) {
1248 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>';
1249 }
1250 print '</td></tr>';
1251 }
1252 }
1253
1254 // Model
1256 if (count($liste) > 0) {
1257 print '<tr>';
1258 print '<td>'.$langs->trans("DefaultModel").'</td>';
1259 print '<td>';
1260 print $form->selectarray('model', $liste, getDolGlobalString('FICHEINTER_ADDON_PDF'));
1261 print "</td></tr>";
1262 }
1263
1264 // Public note
1265 print '<tr>';
1266 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
1267 print '<td>';
1268 $doleditor = new DolEditor('note_public', (string) $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1269 print $doleditor->Create(1);
1270 //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
1271 print '</td></tr>';
1272
1273 // Private note
1274 if (empty($user->socid)) {
1275 print '<tr>';
1276 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
1277 print '<td>';
1278 $doleditor = new DolEditor('note_private', (string) $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1279 print $doleditor->Create(1);
1280 //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
1281 print '</td></tr>';
1282 }
1283
1284 // Other attributes
1285 $parameters = array();
1286 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1287 print $hookmanager->resPrint;
1288 if (empty($reshook)) {
1289 print $object->showOptionals($extrafields, 'create');
1290 }
1291
1292 // Show link to origin object
1293 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1294 $newclassname = $classname;
1295 if ($newclassname == 'Propal') {
1296 $langs->load('propal');
1297 $newclassname = 'CommercialProposal';
1298 }
1299 print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1300
1301 // Amount
1302 /* Hide amount because we only copy services so amount may differ than source
1303 print '<tr><td>' . $langs->trans('AmountHT') . '</td><td>' . price($objectsrc->total_ht) . '</td></tr>';
1304 print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td>' . price($objectsrc->total_tva) . "</td></tr>";
1305 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
1306 {
1307 print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1) . "</td></tr>";
1308 }
1309
1310 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
1311 {
1312 print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2) . "</td></tr>";
1313 }
1314
1315 print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td>' . price($objectsrc->total_ttc) . "</td></tr>";
1316
1317 if (isModEnabled("multicurrency"))
1318 {
1319 print '<tr><td>' . $langs->trans('MulticurrencyAmountHT') . '</td><td>' . price($objectsrc->multicurrency_total_ht) . '</td></tr>';
1320 print '<tr><td>' . $langs->trans('MulticurrencyAmountVAT') . '</td><td>' . price($objectsrc->multicurrency_total_tva) . "</td></tr>";
1321 print '<tr><td>' . $langs->trans('MulticurrencyAmountTTC') . '</td><td>' . price($objectsrc->multicurrency_total_ttc) . "</td></tr>";
1322 }
1323 */
1324 }
1325
1326 print '</table>';
1327
1328 if (is_object($objectsrc)) {
1329 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1330 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1331 } elseif ($origin == 'project' && !empty($projectid)) {
1332 print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1333 }
1334
1335 print dol_get_fiche_end();
1336
1337 print $form->buttonsSaveCancel("CreateDraftIntervention");
1338
1339 // Show origin lines
1340 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !getDolGlobalInt('FICHINTER_DISABLE_DETAILS')) {
1341 $title = $langs->trans('Services');
1342 print load_fiche_titre($title);
1343
1344 print '<div class="div-table-responsive-no-min">';
1345 print '<table class="noborder centpercent">';
1346
1347 $objectsrc->printOriginLinesList(!getDolGlobalString('FICHINTER_PRINT_PRODUCTS') ? 'services' : ''); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
1348
1349 print '</table>';
1350 print '</div>';
1351 }
1352
1353 print '</form>';
1354} elseif ($id > 0 || !empty($ref)) {
1355 // View mode
1356
1357 $object->fetch($id, $ref);
1358 $object->fetch_thirdparty();
1359
1360 $soc = new Societe($db);
1361 $soc->fetch($object->socid);
1362
1363 if ($error > 0) {
1364 dol_htmloutput_errors($mesg);
1365 } else {
1366 dol_htmloutput_mesg($mesg);
1367 }
1368
1369 $head = fichinter_prepare_head($object);
1370
1371 print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, $object->picto, 0, '', '', 0, '', 1);
1372
1373 $formconfirm = '';
1374
1375 // Confirm deletion of intervention
1376 if ($action == 'delete') {
1377 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
1378 }
1379
1380 // Confirm validation
1381 if ($action == 'validate') {
1382 // Verify if the object's number os temporary
1383 $ref = substr($object->ref, 1, 4);
1384 if ($ref == 'PROV') {
1385 $numref = $object->getNextNumRef($soc);
1386 if (empty($numref)) {
1387 $error++;
1388 setEventMessages($object->error, $object->errors, 'errors');
1389 }
1390 } else {
1391 $numref = (string) $object->ref;
1392 }
1393 $text = $langs->trans('ConfirmValidateIntervention', $numref);
1394 if (isModEnabled('notification')) {
1395 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1396 $notify = new Notify($db);
1397 $text .= '<br>';
1398 $text .= $notify->confirmMessage('FICHINTER_VALIDATE', $object->socid, $object);
1399 }
1400
1401 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
1402 }
1403
1404 // Confirm sign
1405 if ($action == 'sign') {
1406 $text = $langs->trans('ConfirmSignIntervention');
1407 if (isModEnabled('notification')) {
1408 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1409 $notify = new Notify($db);
1410 $text .= '<br>';
1411 $text .= $notify->confirmMessage('FICHINTER_MODIFY', $object->socid, $object);
1412 }
1413 $formquestion = [];
1414 $formquestion[] = [
1415 'type' => 'select',
1416 'name' => 'signed_status',
1417 'select_show_empty' => 0,
1418 'label' => '<span class="fieldrequired">'.$langs->trans('SignStatus').'</span>',
1419 'values' => $object->getSignedStatusLocalisedArray()
1420 ];
1421 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SignIntervention'), $text, 'confirm_sign', $formquestion, 0, 1);
1422 }
1423
1424 // Confirm unsign
1425 if ($action == 'unsign') {
1426 $text = $langs->trans('ConfirmUnsignIntervention');
1427 if (isModEnabled('notification')) {
1428 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1429 $notify = new Notify($db);
1430 $text .= '<br>';
1431 $text .= $notify->confirmMessage('FICHINTER_MODIFY', $object->socid, $object);
1432 }
1433 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnsignIntervention'), $text, 'confirm_unsign', '', 0, 1);
1434 }
1435
1436 // Confirm done
1437 if ($action == 'classifydone') {
1438 $text = $langs->trans('ConfirmCloseIntervention');
1439 if (isModEnabled('notification')) {
1440 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1441 $notify = new Notify($db);
1442 $text .= '<br>';
1443 $text .= $notify->confirmMessage('FICHINTER_CLOSE', $object->socid, $object);
1444 }
1445 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseIntervention'), $text, 'confirm_done', '', 0, 1);
1446 }
1447
1448 // Confirm back to draft
1449 if ($action == 'modify') {
1450 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
1451 }
1452
1453 // Confirm back to open
1454 if ($action == 'reopen') {
1455 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
1456 }
1457
1458 // Confirm back to open
1459 if ($action == 'cancel') {
1460 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("Cancel"), $langs->trans('ConfirmCancelIntervention', $object->ref), 'confirm_cancel', '', 0, 1);
1461 }
1462
1463 // Confirm deletion of line
1464 if ($action == 'ask_deleteline') {
1465 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
1466 }
1467
1468 // Confirmation to delete a subtotal / title / text line (subtotals module)
1469 if ($action == 'ask_subtotal_deleteline') {
1470 $langs->load('subtotals');
1471 $subtotaltitle = 'DeleteSubtotalLine';
1472 $subtotalquestion = 'ConfirmDeleteSubtotalLine';
1473 $subtotalformquestion = array();
1474 if (GETPOST('type') == 'title') {
1475 $subtotalformquestion = array(array('type' => 'checkbox', 'name' => 'deletecorrespondingsubtotalline', 'label' => $langs->trans('DeleteCorrespondingSubtotalLine'), 'value' => 0));
1476 $subtotaltitle = 'DeleteTitleLine';
1477 $subtotalquestion = 'ConfirmDeleteTitleLine';
1478 }
1479 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.GETPOSTINT('lineid'), $langs->trans($subtotaltitle), $langs->trans($subtotalquestion), 'confirm_delete_subtotalline', $subtotalformquestion, 'no', 1);
1480 }
1481
1482 // Clone confirmation
1483 if ($action == 'clone') {
1484 // Create an array for form
1485 $formquestion = array(
1486 // 'text' => $langs->trans("ConfirmClone"),
1487 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
1488 array(
1489 'type' => 'other',
1490 'name' => 'socid',
1491 'label' => $langs->trans("SelectThirdParty"),
1492 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', '', '', 0, 0, array(), 0, 'minwidth200')
1493 ),
1494 array(
1495 'type' => 'checkbox',
1496 'name' => 'clone_contacts',
1497 'label' => $langs->trans("CloneContacts"),
1498 'value' => 1
1499 ),
1500 array(
1501 'type' => 'checkbox',
1502 'name' => 'clone_notes',
1503 'label' => $langs->trans("CloneNotes"),
1504 'value' => 1
1505 )
1506 );
1507
1508 // Paiement incomplet. On demande si motif = escompte ou autre
1509 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1510 }
1511
1512 // Subtotal line form
1513 if ($action == 'add_title_line') {
1514 $langs->load('subtotals');
1515 $type = 'title';
1516 $depth_array = $object->getPossibleLevels($langs);
1517 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1518 } elseif ($action == 'add_subtotal_line') {
1519 $langs->load('subtotals');
1520 $type = 'subtotal';
1521 $titles = $object->getPossibleTitles();
1522 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1523 } elseif ($action == 'add_text_line') {
1524 $langs->load('subtotals');
1525 $type = 'text';
1526 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1527 }
1528
1529 if (!$formconfirm) {
1530 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1531 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1532 if (empty($reshook)) {
1533 $formconfirm .= $hookmanager->resPrint;
1534 } elseif ($reshook > 0) {
1535 $formconfirm = $hookmanager->resPrint;
1536 }
1537 }
1538
1539 // Print form confirm
1540 print $formconfirm;
1541
1542
1543 // Intervention card
1544 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1545
1546
1547 $morehtmlref = '<div class="refidno">';
1548 // Ref customer
1549 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $permissiontoadd, 'string', '', 0, 1);
1550 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $permissiontoadd, 'string', '', null, null, '', 1);
1551 // Thirdparty
1552 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
1553 // Project
1554 if (isModEnabled('project')) {
1555 $langs->load("projects");
1556 $morehtmlref .= '<br>';
1557 if ($permissiontoadd) {
1558 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1559 if ($action != 'classify') {
1560 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1561 }
1562 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1563 } else {
1564 if (!empty($object->fk_project)) {
1565 $proj = new Project($db);
1566 $proj->fetch($object->fk_project);
1567 $morehtmlref .= $proj->getNomUrl(1);
1568 if ($proj->title) {
1569 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1570 }
1571 }
1572 }
1573 }
1574 $morehtmlref .= '</div>';
1575
1576 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1577
1578
1579 print '<div class="fichecenter">';
1580 print '<div class="fichehalfleft">';
1581 print '<div class="underbanner clearboth"></div>';
1582
1583 print '<table class="border tableforfield centpercent">';
1584
1585 if (getDolGlobalString('FICHINTER_USE_PLANNED_AND_DONE_DATES')) {
1586 // Date Start
1587 print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
1588 print '<td>';
1589 print $object->dateo ? dol_print_date($object->dateo, 'daytext') : '&nbsp;';
1590 print '</td>';
1591 print '</tr>';
1592
1593 // Date End
1594 print '<tr><td>'.$langs->trans("Datee").'</td>';
1595 print '<td>';
1596 print $object->datee ? dol_print_date($object->datee, 'daytext') : '&nbsp;';
1597 print '</td>';
1598 print '</tr>';
1599
1600 // Date Terminate/close
1601 print '<tr><td>'.$langs->trans("Datet").'</td>';
1602 print '<td>';
1603 print $object->datet ? dol_print_date($object->datet, 'daytext') : '&nbsp;';
1604 print '</td>';
1605 print '</tr>';
1606 }
1607
1608 // Description (must be a textarea and not html must be allowed (used in list view)
1609 print '<tr><td class="titlefield">';
1610 print $form->editfieldkey("Description", 'description', $object->description, $object, $permissiontoadd, 'textarea');
1611 print '</td><td>';
1612 print $form->editfieldval("Description", 'description', $object->description, $object, $permissiontoadd, 'textarea:8');
1613 print '</td>';
1614 print '</tr>';
1615
1616 // Categories
1617 if (isModEnabled('category')) {
1618 print '<tr><td>';
1619 print '<table class="nobordernopadding centpercent"><tr><td>';
1620 print $langs->trans("Categories");
1621 print '<td><td class="right">';
1622 if ($permissiontoadd) {
1623 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/fichinter/card.php?id='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
1624 } else {
1625 print '&nbsp;';
1626 }
1627 print '</td></tr></table>';
1628 print '</td>';
1629 print '<td>';
1630 if ($action == 'edittags') {
1631 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1632 print '<input type="hidden" name="action" value="settags">';
1633 print '<input type="hidden" name="token" value="'.newToken().'">';
1634 print $form->selectCategories(Categorie::TYPE_FICHINTER, 'categories', $object);
1635 print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
1636 print '</form>';
1637 } else {
1638 print $form->showCategories($object->id, Categorie::TYPE_FICHINTER, 1);
1639 }
1640 print "</td></tr>";
1641 }
1642
1643 // Contract
1644 if (isModEnabled('contract')) {
1645 // This feature hang the application on large list of contracts, because the select component is not complete: it does not work like select of thirdparty or product to support large lists
1646 // So we add a hidden option to avoid to have it used and the application locked, until the select_contract is fixed.
1647 if (getDolGlobalString("CONTRACT_CAN_USE_THE_BUGGED_SELECT_COMPONENT")) {
1648 $langs->load('contracts');
1649 print '<tr>';
1650 print '<td>';
1651
1652 print '<table class="nobordernopadding centpercent"><tr><td>';
1653 print $langs->trans('Contract');
1654 print '</td>';
1655 if ($action != 'editcontract') {
1656 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editcontract&id='.$object->id.'">';
1657 print img_edit($langs->trans('SetContract'), 1);
1658 print '</a></td>';
1659 }
1660 print '</tr></table>';
1661 print '</td><td>';
1662 if ($action == 'editcontract') {
1663 $formcontract = new FormContract($db);
1664 $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
1665 } else {
1666 if ($object->fk_contrat) {
1667 $contratstatic = new Contrat($db);
1668 $contratstatic->fetch($object->fk_contrat);
1669 //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1670 print $contratstatic->getNomUrl(0, 0, 1);
1671 } else {
1672 print "&nbsp;";
1673 }
1674 }
1675 print '</td>';
1676 print '</tr>';
1677 }
1678 }
1679
1680 // Other attributes
1681 $cols = 2;
1682 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1683
1684 print '</table>';
1685
1686 print '</div>';
1687 print '<div class="fichehalfright">';
1688 print '<div class="underbanner clearboth"></div>';
1689
1690 print '<table class="border tableforfield centpercent">';
1691
1692 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1693 // Duration in time
1694 print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
1695 print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' ('.convertDurationtoHour($object->duration, "s").' '.$langs->trans("HourShort").')</td>';
1696 print '</tr>';
1697 }
1698
1699 print "</table>";
1700
1701 print '</div>';
1702 print '</div>';
1703
1704 print '<div class="clearboth"></div><br>';
1705
1706
1707 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1708 $blocname = 'contacts';
1709 $title = $langs->trans('ContactsAddresses');
1710 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1711 }
1712
1713 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
1714 $blocname = 'notes';
1715 $title = $langs->trans('Notes');
1716 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1717 }
1718
1719 // Line of interventions
1720 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1721 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
1722 print '<input type="hidden" name="token" value="'.newToken().'">';
1723 print '<input type="hidden" name="id" value="'.$object->id.'">';
1724 if ($action == 'editline') {
1725 print '<input type="hidden" name="action" value="updateline">';
1726 print '<input type="hidden" name="line_id" value="'.GETPOSTINT('line_id').'">';
1727 } else {
1728 print '<input type="hidden" name="action" value="addline">';
1729 }
1730 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1731
1732 // Intervention lines
1733 $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
1734 $sql .= ' ft.special_code, ft.product_type, ft.extraparams,';
1735 $sql .= ' ft.date as date_intervention';
1736 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1737 $sql .= ' WHERE ft.fk_fichinter = '.((int) $object->id);
1738 if (getDolGlobalString('FICHINTER_HIDE_EMPTY_DURATION')) {
1739 $sql .= ' AND ft.duree <> 0';
1740 }
1741 $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
1742
1743 $resql = $db->query($sql);
1744 if ($resql) {
1745 $num = $db->num_rows($resql);
1746 $i = 0;
1747
1748 if ($num) {
1749 print '<br>';
1750 print '<table class="noborder centpercent">';
1751 print '<tr class="liste_titre">';
1752
1753 // No.
1754 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1755 print '<td width="5" class="center linecolnum"></td>';
1756 }
1757
1758 print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
1759 print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
1760 print '<td class="liste_titre right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1761 print '<td class="liste_titre">&nbsp;</td>';
1762 print '<td class="liste_titre">&nbsp;</td>';
1763 print "</tr>\n";
1764 }
1765 while ($i < $num) {
1766 $objp = $db->fetch_object($resql);
1767
1768 // Line in view mode
1769 if ($action != 'editline' || GETPOSTINT('line_id') != $objp->rowid) {
1770 print '<tr class="oddeven">';
1771
1772 // No.
1773 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1774 print '<td class="center linecolnum">'.($i + 1).'</td>';
1775 }
1776 if (!empty($objp->special_code) || $objp->product_type == 9) {
1777 $line_color = $object->getSubtotalColors($objp->duree);
1778 $line_options = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
1779 $line_options = $line_options['subtotal'] ?? array();
1780 print '<td colspan="3" ><strong>'.dol_htmlentitiesbr($objp->description).'</strong>';
1781 if (array_key_exists('titleshowuponpdf', $line_options)) {
1782 echo '&nbsp;' . img_picto($langs->trans("ShowUPOnPDF"), 'invoicing');
1783 }
1784 if (array_key_exists('titleshowtotalexludingvatonpdf', $line_options)) {
1785 echo '&nbsp; <span title="' . $langs->trans("ShowTotalExludingVATOnPDF") . '">%</span>';
1786 }
1787 if (array_key_exists('titleforcepagebreak', $line_options)) {
1788 echo '&nbsp;' . img_picto($langs->trans("ForcePageBreak"), 'file');
1789 }
1790 print "</td>";
1791 } else {
1792 print '<td>';
1793 print '<a name="'.$objp->rowid.'"></a>'; // Anchor to return to the line
1794 print dol_htmlentitiesbr($objp->description);
1795
1796 $objectline = new FichinterLigne($db);
1797 $objectline->fetch($objp->rowid);
1798 $objectline->fetch_optionals();
1799
1800 $extrafields->fetch_name_optionals_label($objectline->table_element);
1801
1802 $temps = $objectline->showOptionals($extrafields, 'view', array(), '', '', '1', 'line');
1803 if (!empty($temps)) {
1804 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$objp->rowid.'" name="extrafield_lines_area_'.$objp->rowid.'">';
1805 print $temps;
1806 print '</div>';
1807 }
1808
1809 print '</td>';
1810
1811 // Date
1812 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>';
1813
1814 // Duration
1815 print '<td class="right" width="150">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? convertSecondToTime($objp->duree) : '').'</td>';
1816
1817 print "</td>\n";
1818 }
1819 // Icon to edit and delete
1820 if ($object->status == 0 && $permissiontoadd) {
1821 print '<td class="center">';
1822 print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&line_id='.$objp->rowid.'#'.$objp->rowid.'">';
1823 print img_edit();
1824 print '</a>';
1825 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&line_id='.$objp->rowid.'">';
1826 print img_delete();
1827 print '</a></td>';
1828 print '<td class="center">';
1829 if ($num > 1) {
1830 if ($i > 0) {
1831 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&line_id='.$objp->rowid.'">';
1832 print img_up();
1833 print '</a>';
1834 }
1835 if ($i < $num - 1) {
1836 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&line_id='.$objp->rowid.'">';
1837 print img_down();
1838 print '</a>';
1839 }
1840 }
1841 print '</td>';
1842 } else {
1843 print '<td colspan="2">&nbsp;</td>';
1844 }
1845
1846 print '</tr>';
1847 }
1848
1849 // Line in update mode
1850 if ($object->status == 0 && $action == 'editline' && $permissiontoadd && GETPOSTINT('line_id') == $objp->rowid) {
1851 print '<tr class="oddeven nohover">';
1852
1853 // No.
1854 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1855 print '<td class="center linecolnum">'.($i + 1).'</td>';
1856 }
1857
1858 print '<td>';
1859 print '<a name="'.$objp->rowid.'"></a>'; // Anchor to return to the line
1860
1861 // Editeur wysiwyg
1862 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1863 $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1864 $doleditor->Create();
1865
1866 $objectline = new FichinterLigne($db);
1867 $objectline->fetch($objp->rowid);
1868 $objectline->fetch_optionals();
1869
1870 $extrafields->fetch_name_optionals_label($objectline->table_element);
1871
1872 $temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', '1', 'line');
1873 if (!empty($temps)) {
1874 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$objectline->id.'" name="extrafield_lines_area_'.$objectline->id.'">';
1875 print $temps;
1876 print '</div>';
1877 }
1878
1879 print '</td>';
1880
1881 // Date d'intervention
1882 print '<td class="center nowrap">';
1883 if (getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR')) {
1884 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
1885 } else {
1886 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
1887 }
1888 print '</td>';
1889
1890 // Duration
1891 print '<td class="right">';
1892 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1893 $selectmode = 'select';
1894 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1895 $selectmode = 'text';
1896 }
1897 $form->select_duration('duration', $objp->duree, 0, $selectmode);
1898 }
1899 print '</td>';
1900
1901 print '<td class="center" colspan="5" valign="center">';
1902 print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
1903 print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
1904 print '</tr>'."\n";
1905 }
1906
1907 $i++;
1908 }
1909
1910 $db->free($resql);
1911
1912 // Add new line
1913 if ($object->status == 0 && $permissiontoadd && $action != 'editline' && (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2')) {
1914 if (!$num) {
1915 print '<br>';
1916 print '<table class="noborder centpercent">';
1917 print '<tr class="liste_titre">';
1918
1919 // No.
1920 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1921 print '<td width="5" class="center linecolnum"></td>';
1922 }
1923
1924 print '<td>';
1925 print '<a name="add"></a>'; // ancre
1926 print $langs->trans('Description').'</td>';
1927 print '<td class="center">'.$langs->trans('Date').'</td>';
1928 print '<td class="right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1929 print '<td colspan="3">&nbsp;</td>';
1930 print "</tr>\n";
1931 }
1932
1933 print '<tr class="oddeven nohover">'."\n";
1934
1935 // No.
1936 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1937 print '<td class="center linecolnum">'.($i + 1).'</td>';
1938 }
1939
1940 print '<td>';
1941 // editeur wysiwyg
1942 if (!getDolGlobalString('FICHINTER_EMPTY_LINE_DESC')) {
1943 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1944 $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1945 $doleditor->Create();
1946 }
1947
1948 $objectline = new FichinterLigne($db);
1949 $extrafields->fetch_name_optionals_label($objectline->table_element);
1950
1951 if (is_object($objectline)) {
1952 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', '1', 'line');
1953
1954 if (!empty($temps)) {
1955 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
1956 print $temps;
1957 print '</div>';
1958 }
1959 }
1960
1961 print '</td>';
1962
1963 // Date intervention
1964 print '<td class="center nowrap">';
1965 $now = dol_now();
1966 $timearray = dol_getdate($now);
1967 if (!GETPOSTINT('diday')) {
1968 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1969 $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1970 } else {
1971 $timewithnohour = dol_mktime($timearray['hours'], $timearray['minutes'], 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1972 }
1973 } else {
1974 $timewithnohour = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
1975 }
1976 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1977 print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
1978 } else {
1979 print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
1980 }
1981 print '</td>';
1982
1983 // Duration
1984 print '<td class="right">';
1985 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1986 $selectmode = 'select';
1987 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1988 $selectmode = 'text';
1989 }
1990 $form->select_duration('duration', (!GETPOSTINT('durationhour') && !GETPOSTINT('durationmin')) ? 3600 : (60 * 60 * GETPOSTINT('durationhour') + 60 * GETPOSTINT('durationmin')), 0, $selectmode);
1991 }
1992 print '</td>';
1993
1994 print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button button-add" value="'.$langs->trans('Add').'" name="addline"></td>';
1995 print '</tr>';
1996
1997 if (!$num) {
1998 print '</table>';
1999 }
2000 }
2001
2002 if ($num) {
2003 print '</table>';
2004 }
2005 } else {
2007 }
2008
2009 print '</form>'."\n";
2010 }
2011
2012 print dol_get_fiche_end();
2013
2014 print "\n";
2015
2016
2017 /*
2018 * Actions buttons
2019 */
2020
2021 print '<div class="tabsAction">';
2022
2023 $parameters = array();
2024 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2025 // modified by hook
2026 if (empty($reshook)) {
2027 $params = array();
2028 if ($user->socid == 0) {
2029 if ($action != 'editdescription' && ($action != 'presend')) {
2030 // Subtotal
2031 if ($object->status == Fichinter::STATUS_DRAFT && isModEnabled('subtotals')
2032 && (getDolGlobalString('SUBTOTAL_TITLE_'.strtoupper($object->element)) || getDolGlobalString('SUBTOTAL_'.strtoupper($object->element)) || getDolGlobalString('SUBTOTAL_TEXT_'.strtoupper($object->element)))) {
2033 $langs->load('subtotals');
2034
2035 $url_button = array();
2036 $url_button[] = array(
2037 'lang' => 'subtotals',
2038 'enabled' => (isModEnabled('intervention') && $object->status == Fichinter::STATUS_DRAFT),
2039 'perm' => (bool) $permissiontoadd,
2040 'label' => $langs->trans('AddTitleLine'),
2041 'url' => '/fichinter/card.php?id='.$object->id.'&action=add_title_line&token='.newToken()
2042 );
2043
2044 $url_button[] = array(
2045 'lang' => 'subtotals',
2046 'enabled' => (isModEnabled('intervention') && $object->status == Fichinter::STATUS_DRAFT),
2047 'perm' => (bool) $permissiontoadd,
2048 'label' => $langs->trans('AddSubtotalLine'),
2049 'url' => '/fichinter/card.php?id='.$object->id.'&action=add_subtotal_line&token='.newToken()
2050 );
2051
2052 $url_button[] = array(
2053 'lang' => 'subtotals',
2054 'enabled' => (isModEnabled('intervention') && $object->status == Fichinter::STATUS_DRAFT),
2055 'perm' => (bool) $permissiontoadd,
2056 'label' => $langs->trans('AddTextLine'),
2057 'url' => '/fichinter/card.php?id='.$object->id.'&action=add_text_line&token='.newToken()
2058 );
2059 print dolGetButtonAction('', $langs->trans('SubTotal'), 'default', $url_button, '', true);
2060 }
2061
2062 // Validate
2063 if ($object->status == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '1')) {
2064 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $permissiontoadd) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'ficheinter_advance', 'validate'))) {
2065 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a></div>';
2066 } else {
2067 print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span></div>';
2068 }
2069 }
2070
2071 // Modify
2072 if ($object->status == Fichinter::STATUS_VALIDATED && ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $permissiontoadd) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'ficheinter_advance', 'unvalidate')))) {
2073 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify&token='.newToken().'">';
2074 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
2075 print $langs->trans("Modify");
2076 } else {
2077 print $langs->trans("SetToDraft");
2078 }
2079 print '</a></div>';
2080 }
2081
2082 // Reopen
2083 if ($object->status >= Fichinter::STATUS_CLOSED) {
2084 if ($permissiontoadd) {
2085 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>';
2086 } else {
2087 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('ReOpen').'</a></div>';
2088 }
2089 }
2090
2091 // Send
2092 if (empty($user->socid)) {
2094 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('ficheinter', 'ficheinter_advance', 'send')) {
2095 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
2096 } else {
2097 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
2098 }
2099 }
2100 }
2101
2102 // Create intervention model
2103 if ($object->status == Fichinter::STATUS_DRAFT && $permissiontoadd && (count($object->lines) > 0)) {
2104 print '<div class="inline-block divButAction">';
2105 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>';
2106 print '</div>';
2107 }
2108
2109 $arrayofcreatebutton = array();
2110 // Proposal
2111 if (isModEnabled("service") && isModEnabled("propal") && $object->status > Fichinter::STATUS_DRAFT) {
2112 $langs->load("propal");
2113 if ($object->status < Fichinter::STATUS_BILLED) {
2114 $arrayofcreatebutton[] = array(
2115 'url' => '/comm/propal/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid,
2116 'label' => $langs->trans('AddProp'),
2117 'lang' => 'propal',
2118 'perm' => $user->hasRight('propal', 'creer'),
2119 'enabled' => true,
2120 );
2121 }
2122 }
2123
2124 // Invoicing
2125 if (isModEnabled('invoice') && $object->status > Fichinter::STATUS_DRAFT) {
2126 $langs->load("bills");
2127 if ($object->status < Fichinter::STATUS_BILLED) {
2128 $arrayofcreatebutton[] = array(
2129 'url' => '/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid,
2130 'label' => $langs->trans('AddBill'),
2131 'lang' => 'bills',
2132 'perm' => $user->hasRight('facture', 'creer') ? true : false,
2133 'enabled' => true,
2134 );
2135 }
2136
2137 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
2138 if ($object->status != Fichinter::STATUS_BILLED) {
2139 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>';
2140 } else {
2141 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>';
2142 }
2143 }
2144 }
2145
2146 if (count($arrayofcreatebutton)) {
2147 print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayofcreatebutton, '', true, $params);
2148 }
2149
2150 // Sign
2152 if ($object->signed_status != Fichinter::$SIGNED_STATUSES['STATUS_SIGNED_ALL']) {
2153 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>';
2154 } else {
2155 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>';
2156 }
2157 }
2158
2159 // Done
2160 if (!getDolGlobalString('FICHINTER_CLASSIFY_BILLED') && $object->status > Fichinter::STATUS_DRAFT && $object->status < Fichinter::STATUS_CLOSED) {
2161 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>';
2162 }
2163
2164 // Clone
2165 if ($permissiontoadd) {
2166 print '<div class="inline-block divButAction"><a class="butAction butActionClone" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object=ficheinter">'.$langs->trans("ToClone").'</a></div>';
2167 }
2168
2169 // Cancel fichinter
2170 if ($object->status == Fichinter::STATUS_VALIDATED) {
2171 if ($user->hasRight('ficheinter', 'supprimer')) {
2172 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("Cancel").'</a></div>';
2173 } else {
2174 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Cancel').'</a></div>';
2175 }
2176 }
2177
2178 // Delete
2179 print '<div class="inline-block divButAction">';
2180 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'delete'], true), 'delete', $permissiontodelete);
2181 print '</div>';
2182 }
2183 }
2184 }
2185
2186 print '</div>';
2187
2188 if ($action != 'presend') {
2189 print '<div class="fichecenter"><div class="fichehalfleft">';
2190
2191 /*
2192 * Built documents
2193 */
2194 $filename = dol_sanitizeFileName($object->ref);
2195 $filedir = getMultidirOutput($object)."/".$filename;
2196 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2197 $genallowed = $permissiontoread;
2198 $delallowed = $permissiontoadd;
2199 print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object);
2200
2201 // Show links to link elements
2202 $tmparray = $form->showLinkToObjectBlock($object, array(), array('fichinter'), 1);
2203 $linktoelem = $tmparray['linktoelem'];
2204 $htmltoenteralink = $tmparray['htmltoenteralink'];
2205 print $htmltoenteralink;
2206
2207 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2208
2209 // Show direct download link
2210 if ($object->status != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_EXTERNAL_DOWNLOAD')) {
2211 print '<br><!-- Link to download main doc -->'."\n";
2212 print showDirectDownloadLink($object).'<br>';
2213 }
2214
2215 // Show online signature link
2216 if ($object->status != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_ONLINE_SIGN')) {
2217 print '<br><!-- Link to sign -->';
2218 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
2219
2220 print showOnlineSignatureUrl('fichinter', $object->ref, $object).'<br>';
2221 }
2222
2223 print '</div><div class="fichehalfright">';
2224
2225 $MAXEVENT = 10;
2226
2227 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/fichinter/agenda.php?id='.$object->id);
2228
2229 // List of actions on element
2230 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2231 $formactions = new FormActions($db);
2232 $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
2233
2234 print '</div></div>';
2235 }
2236
2237
2238 // Select mail models is same action as presend
2239 if (GETPOST('modelselected')) {
2240 $action = 'presend';
2241 }
2242
2243 // Presend form
2244 $modelmail = 'fichinter_send';
2245 $defaulttopic = 'SendInterventionRef';
2246 $diroutput = $conf->ficheinter->multidir_output[$object->entity];
2247 $trackid = 'int'.$object->id;
2248
2249 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2250}
2251
2252
2253llxFooter();
2254
2255$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage a WYSIWYG editor.
const STATUS_BILLED
Billed.
const STATUS_DRAFT
Draft status.
const STATUS_CANCELED
Canceled 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:342
convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
Convert hours and minutes into seconds.
Definition date.lib.php:219
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:248
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
fichinter_prepare_head($object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
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...
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:519
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.
Definition html.lib.php:717
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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).
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
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.