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