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 dol_print_error($db);
701 exit;
702 }
703
704 // Define output language
705 $outputlangs = $langs;
706 $newlang = '';
707 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
708 $newlang = GETPOST('lang_id', 'aZ09');
709 }
710 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
711 $newlang = $object->thirdparty->default_lang;
712 }
713 if (!empty($newlang)) {
714 $outputlangs = new Translate("", $conf);
715 $outputlangs->setDefaultLang($newlang);
716 }
717 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
718 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
719 }
720
721 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
722 exit;
723 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoadd) {
724 // Supprime une ligne d'intervention AVEC confirmation
725 $objectline = new FichinterLigne($db);
726 if ($objectline->fetch($lineid) <= 0) {
727 dol_print_error($db);
728 exit;
729 }
730 $result = $objectline->deleteLine($user);
731
732 if ($object->fetch($objectline->fk_fichinter) <= 0) {
733 dol_print_error($db);
734 exit;
735 }
736
737 // Define output language
738 $outputlangs = $langs;
739 $newlang = '';
740 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
741 $newlang = GETPOST('lang_id', 'aZ09');
742 }
743 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
744 $newlang = $object->thirdparty->default_lang;
745 }
746 if (!empty($newlang)) {
747 $outputlangs = new Translate("", $conf);
748 $outputlangs->setDefaultLang($newlang);
749 }
750 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
751 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
752 }
753 } elseif ($action == 'up' && $permissiontoadd) {
754 // Set position of lines
755 $object->line_up($lineid);
756
757 // Define output language
758 $outputlangs = $langs;
759 $newlang = '';
760 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
761 $newlang = GETPOST('lang_id', 'aZ09');
762 }
763 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
764 $newlang = $object->thirdparty->default_lang;
765 }
766 if (!empty($newlang)) {
767 $outputlangs = new Translate("", $conf);
768 $outputlangs->setDefaultLang($newlang);
769 }
770 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
771 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
772 }
773
774 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
775 exit;
776 } elseif ($action == 'down' && $permissiontoadd) {
777 $object->line_down($lineid);
778
779 // Define output language
780 $outputlangs = $langs;
781 $newlang = '';
782 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
783 $newlang = GETPOST('lang_id', 'aZ09');
784 }
785 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
786 $newlang = $object->thirdparty->default_lang;
787 }
788 if (!empty($newlang)) {
789 $outputlangs = new Translate("", $conf);
790 $outputlangs->setDefaultLang($newlang);
791 }
792 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
793 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
794 }
795
796 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
797 exit;
798 }
799
800 // Actions when printing a doc from card
801 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
802
803 // Actions to send emails
804 $triggersendname = 'FICHINTER_SENTBYMAIL';
805 $autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
806 $trackid = 'int'.$object->id;
807 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
808
809 // Actions to build doc
810 $upload_dir = $conf->ficheinter->dir_output;
811 $permissiontoadd = $user->hasRight('ficheinter', 'creer');
812 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
813
814 if ($action == 'update_extras' && $permissiontoadd) {
815 $object->oldcopy = dol_clone($object, 2);
816 $attribute_name = GETPOST('attribute', 'restricthtml');
817
818 // Fill array 'array_options' with data from update form
819 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
820 if ($ret < 0) {
821 $error++;
822 }
823
824 if (!$error) {
825 // Actions on extra fields
826 $result = $object->updateExtraField($attribute_name, 'INTERVENTION_MODIFY');
827 if ($result < 0) {
828 setEventMessages($object->error, $object->errors, 'errors');
829 $error++;
830 }
831 }
832
833 if ($error) {
834 $action = 'edit_extras';
835 }
836 }
837
838 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
839 if ($action == 'addcontact' && $permissiontoadd) {
840 if ($result > 0 && $id > 0) {
841 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
842 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
843 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
844 }
845
846 if ($result >= 0) {
847 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
848 exit;
849 } else {
850 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
851 $langs->load("errors");
852 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
853 } else {
854 $mesg = $object->error;
855 }
856 }
857 } elseif ($action == 'swapstatut' && $permissiontoadd) {
858 // bascule du statut d'un contact
859 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
860 } elseif ($action == 'deletecontact' && $permissiontoadd) {
861 // Efface un contact
862 $result = $object->delete_contact(GETPOSTINT('lineid'));
863
864 if ($result >= 0) {
865 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
866 exit;
867 } else {
868 dol_print_error($db);
869 }
870 }
871 }
872}
873
874
875/*
876 * View
877 */
878
879$form = new Form($db);
880$formfile = new FormFile($db);
881$formcontract = null;
882$formproject = null;
883if (isModEnabled('contract')) {
884 $formcontract = new FormContract($db);
885}
886if (isModEnabled('project')) {
887 $formproject = new FormProjets($db);
888}
889
890
891$help_url = 'EN:Module_Interventions';
892
893llxHeader('', $langs->trans("Intervention"), $help_url, '', 0, 0, '', '', '', 'mod-fichinter page-card');
894
895if ($action == 'create') {
896 // Create new intervention
897
898 $soc = new Societe($db);
899
900 print load_fiche_titre($langs->trans("AddIntervention"), '', 'intervention');
901
902 if ($error > 0) {
904 } else {
905 dol_htmloutput_mesg($mesg);
906 }
907
908 if ($socid) {
909 $res = $soc->fetch($socid);
910 }
911
912 if (GETPOST('origin', 'alphanohtml') && GETPOSTINT('originid')) {
913 // Parse element/subelement (ex: project_task)
914 $regs = array();
915 $element = $subelement = GETPOST('origin', 'alphanohtml');
916 if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
917 $element = $regs[1];
918 $subelement = $regs[2];
919 }
920
921 if ($element == 'project') {
922 $projectid = GETPOSTINT('originid');
923 } else {
924 // For compatibility
925 if ($element == 'order' || $element == 'commande') {
926 $element = $subelement = 'commande';
927 }
928 if ($element == 'propal') {
929 $element = 'comm/propal';
930 $subelement = 'propal';
931 }
932 if ($element == 'contract') {
933 $element = $subelement = 'contrat';
934 }
935
936 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
937
938 $classname = ucfirst($subelement);
939 $objectsrc = new $classname($db);
940 '@phan-var-force Commande|Propal|Contrat $objectsrc';
941 $objectsrc->fetch(GETPOST('originid'));
942 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
943 $objectsrc->fetch_lines();
944 $lines = $objectsrc->lines;
945 }
946 $objectsrc->fetch_thirdparty();
947
948 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
949
950 $soc = $objectsrc->thirdparty;
951
952 $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private', 'restricthtml')));
953 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public', 'restricthtml'));
954
955 // Replicate extrafields
956 $objectsrc->fetch_optionals();
957 $object->array_options = $objectsrc->array_options;
958
959 // Object source contacts list
960 $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
961 }
962 } else {
963 $projectid = GETPOSTINT('projectid');
964 }
965
966 if (!$conf->global->FICHEINTER_ADDON) {
967 dol_print_error($db, $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
968 exit;
969 }
970
971 $object->datec = dol_now();
972
973 $obj = getDolGlobalString('FICHEINTER_ADDON');
974 $obj = "mod_".$obj;
975
976 //$modFicheinter = new $obj;
977 //$numpr = $modFicheinter->getNextValue($soc, $object);
978
979 if ($socid > 0) {
980 $soc = new Societe($db);
981 $soc->fetch($socid);
982
983 print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
984 print '<input type="hidden" name="token" value="'.newToken().'">';
985 print '<input type="hidden" name="socid" value='.$soc->id.'>';
986 print '<input type="hidden" name="action" value="add">';
987 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
988
989 print dol_get_fiche_head([]);
990
991 print '<table class="border centpercent">';
992
993 print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
994
995 // Ref
996 print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
997
998 // Ref customer
999 print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
1000 print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
1001 print '</tr>';
1002
1003 // Description (must be a textarea and not html must be allowed (used in list view)
1004 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
1005 print '<td>';
1006 print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
1007 print '</td></tr>';
1008
1009 // Project
1010 if (isModEnabled('project')) {
1011 $formproject = new FormProjets($db);
1012
1013 $langs->load("project");
1014
1015 print '<tr><td>'.$langs->trans("Project").'</td><td>';
1016 /* 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
1017 if ($societe->fournisseur==1)
1018 $numprojet=select_projects(-1, GETPOST("projectid", 'int'), 'projectid');
1019 else
1020 $numprojet=select_projects($societe->id, GETPOST("projectid", 'int'), 'projectid');
1021 */
1022 $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid');
1023 if ($numprojet == 0) {
1024 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>';
1025 }
1026 print '</td></tr>';
1027 }
1028
1029 // Contract
1030 if (isModEnabled('contract') && is_object($formcontract)) {
1031 $langs->load("contracts");
1032 print '<tr><td>'.$langs->trans("Contract").'</td><td>';
1033 $numcontrat = $formcontract->select_contract($soc->id, GETPOSTINT('contratid'), 'contratid', 0, 1, 1);
1034 if ($numcontrat == 0) {
1035 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>';
1036 }
1037 print '</td></tr>';
1038 }
1039
1040 // Model
1041 print '<tr>';
1042 print '<td>'.$langs->trans("DefaultModel").'</td>';
1043 print '<td>';
1045 print $form->selectarray('model', $liste, $conf->global->FICHEINTER_ADDON_PDF);
1046 print "</td></tr>";
1047
1048 // Public note
1049 print '<tr>';
1050 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
1051 print '<td>';
1052 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1053 print $doleditor->Create(1);
1054 //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
1055 print '</td></tr>';
1056
1057 // Private note
1058 if (empty($user->socid)) {
1059 print '<tr>';
1060 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
1061 print '<td>';
1062 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1063 print $doleditor->Create(1);
1064 //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
1065 print '</td></tr>';
1066 }
1067
1068 // Other attributes
1069 $parameters = array();
1070 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1071 print $hookmanager->resPrint;
1072 if (empty($reshook)) {
1073 print $object->showOptionals($extrafields, 'create');
1074 }
1075
1076 // Show link to origin object
1077 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1078 $newclassname = $classname;
1079 if ($newclassname == 'Propal') {
1080 $langs->load('propal');
1081 $newclassname = 'CommercialProposal';
1082 }
1083 print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1084
1085 // Amount
1086 /* Hide amount because we only copy services so amount may differ than source
1087 print '<tr><td>' . $langs->trans('AmountHT') . '</td><td>' . price($objectsrc->total_ht) . '</td></tr>';
1088 print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td>' . price($objectsrc->total_tva) . "</td></tr>";
1089 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
1090 {
1091 print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1) . "</td></tr>";
1092 }
1093
1094 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
1095 {
1096 print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2) . "</td></tr>";
1097 }
1098
1099 print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td>' . price($objectsrc->total_ttc) . "</td></tr>";
1100
1101 if (isModEnabled("multicurrency"))
1102 {
1103 print '<tr><td>' . $langs->trans('MulticurrencyAmountHT') . '</td><td>' . price($objectsrc->multicurrency_total_ht) . '</td></tr>';
1104 print '<tr><td>' . $langs->trans('MulticurrencyAmountVAT') . '</td><td>' . price($objectsrc->multicurrency_total_tva) . "</td></tr>";
1105 print '<tr><td>' . $langs->trans('MulticurrencyAmountTTC') . '</td><td>' . price($objectsrc->multicurrency_total_ttc) . "</td></tr>";
1106 }
1107 */
1108 }
1109
1110 print '</table>';
1111
1112 if (is_object($objectsrc)) {
1113 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1114 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1115 } elseif ($origin == 'project' && !empty($projectid)) {
1116 print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1117 }
1118
1119 print dol_get_fiche_end();
1120
1121 print $form->buttonsSaveCancel("CreateDraftIntervention");
1122
1123 // Show origin lines
1124 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !getDolGlobalInt('FICHINTER_DISABLE_DETAILS')) {
1125 $title = $langs->trans('Services');
1126 print load_fiche_titre($title);
1127
1128 print '<div class="div-table-responsive-no-min">';
1129 print '<table class="noborder centpercent">';
1130
1131 $objectsrc->printOriginLinesList(!getDolGlobalString('FICHINTER_PRINT_PRODUCTS') ? 'services' : ''); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
1132
1133 print '</table>';
1134 print '</div>';
1135 }
1136
1137 print '</form>';
1138 } else {
1139 print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
1140 print '<input type="hidden" name="token" value="'.newToken().'">';
1141 print '<input type="hidden" name="action" value="create">'; // We go back to create action
1142 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1143
1144 print dol_get_fiche_head([]);
1145
1146 if (is_object($objectsrc)) {
1147 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1148 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1149 } elseif ($origin == 'project' && !empty($projectid)) {
1150 print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1151 }
1152 print '<table class="border centpercent">';
1153 print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
1154 print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, array(), 0, 'minwidth300');
1155 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>';
1156 print '</td></tr>';
1157 print '</table>';
1158
1159 print dol_get_fiche_end();
1160
1161 print $form->buttonsSaveCancel("CreateDraftIntervention");
1162
1163 print '</form>';
1164 }
1165} elseif ($id > 0 || !empty($ref)) {
1166 // View mode
1167
1168 $object->fetch($id, $ref);
1169 $object->fetch_thirdparty();
1170
1171 $soc = new Societe($db);
1172 $soc->fetch($object->socid);
1173
1174 if ($error > 0) {
1175 dol_htmloutput_errors($mesg);
1176 } else {
1177 dol_htmloutput_mesg($mesg);
1178 }
1179
1181
1182 print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, 'intervention');
1183
1184 $formconfirm = '';
1185
1186 // Confirm deletion of intervention
1187 if ($action == 'delete') {
1188 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
1189 }
1190
1191 // Confirm validation
1192 if ($action == 'validate') {
1193 // Verify if the object's number os temporary
1194 $ref = substr($object->ref, 1, 4);
1195 if ($ref == 'PROV') {
1196 $numref = $object->getNextNumRef($soc);
1197 if (empty($numref)) {
1198 $error++;
1199 setEventMessages($object->error, $object->errors, 'errors');
1200 }
1201 } else {
1202 $numref = $object->ref;
1203 }
1204 $text = $langs->trans('ConfirmValidateIntervention', $numref);
1205 if (isModEnabled('notification')) {
1206 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1207 $notify = new Notify($db);
1208 $text .= '<br>';
1209 $text .= $notify->confirmMessage('FICHINTER_VALIDATE', $object->socid, $object);
1210 }
1211
1212 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
1213 }
1214
1215 // Confirm sign
1216 if ($action == 'sign') {
1217 $text = $langs->trans('ConfirmSignIntervention');
1218 if (isModEnabled('notification')) {
1219 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1220 $notify = new Notify($db);
1221 $text .= '<br>';
1222 $text .= $notify->confirmMessage('FICHINTER_MODIFY', $object->socid, $object);
1223 }
1224 $formquestion = [];
1225 $formquestion[] = [
1226 'type' => 'select',
1227 'name' => 'signed_status',
1228 'select_show_empty' => 0,
1229 'label' => '<span class="fieldrequired">'.$langs->trans('SignStatus').'</span>',
1230 'values' => $object->getSignedStatusLocalisedArray()
1231 ];
1232 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SignIntervention'), $text, 'confirm_sign', $formquestion, 0, 1);
1233 }
1234
1235 // Confirm unsign
1236 if ($action == 'unsign') {
1237 $text = $langs->trans('ConfirmUnsignIntervention');
1238 if (isModEnabled('notification')) {
1239 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1240 $notify = new Notify($db);
1241 $text .= '<br>';
1242 $text .= $notify->confirmMessage('FICHINTER_MODIFY', $object->socid, $object);
1243 }
1244 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnsignIntervention'), $text, 'confirm_unsign', '', 0, 1);
1245 }
1246
1247 // Confirm done
1248 if ($action == 'classifydone') {
1249 $text = $langs->trans('ConfirmCloseIntervention');
1250 if (isModEnabled('notification')) {
1251 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1252 $notify = new Notify($db);
1253 $text .= '<br>';
1254 $text .= $notify->confirmMessage('FICHINTER_CLOSE', $object->socid, $object);
1255 }
1256 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseIntervention'), $text, 'confirm_done', '', 0, 1);
1257 }
1258
1259 // Confirm back to draft
1260 if ($action == 'modify') {
1261 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
1262 }
1263
1264 // Confirm back to open
1265 if ($action == 'reopen') {
1266 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
1267 }
1268
1269 // Confirm deletion of line
1270 if ($action == 'ask_deleteline') {
1271 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
1272 }
1273
1274 // Clone confirmation
1275 if ($action == 'clone') {
1276 // Create an array for form
1277 $formquestion = array(
1278 // 'text' => $langs->trans("ConfirmClone"),
1279 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
1280 // 1),
1281 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
1282 // => 1),
1283 array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', '', '', 0, 0, array(), 0, 'minwidth200')));
1284 // Paiement incomplet. On demande si motif = escompte ou autre
1285 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1286 }
1287
1288 if (!$formconfirm) {
1289 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1290 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1291 if (empty($reshook)) {
1292 $formconfirm .= $hookmanager->resPrint;
1293 } elseif ($reshook > 0) {
1294 $formconfirm = $hookmanager->resPrint;
1295 }
1296 }
1297
1298 // Print form confirm
1299 print $formconfirm;
1300
1301
1302 // Intervention card
1303 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1304
1305
1306 $morehtmlref = '<div class="refidno">';
1307 // Ref customer
1308 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->hasRight('ficheinter', 'creer'), 'string', '', 0, 1);
1309 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->hasRight('ficheinter', 'creer'), 'string', '', null, null, '', 1);
1310 // Thirdparty
1311 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
1312 // Project
1313 if (isModEnabled('project')) {
1314 $langs->load("projects");
1315 $morehtmlref .= '<br>';
1316 if ($usercancreate) {
1317 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1318 if ($action != 'classify') {
1319 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1320 }
1321 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1322 } else {
1323 if (!empty($object->fk_project)) {
1324 $proj = new Project($db);
1325 $proj->fetch($object->fk_project);
1326 $morehtmlref .= $proj->getNomUrl(1);
1327 if ($proj->title) {
1328 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1329 }
1330 }
1331 }
1332 }
1333 $morehtmlref .= '</div>';
1334
1335 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1336
1337
1338 print '<div class="fichecenter">';
1339 print '<div class="fichehalfleft">';
1340 print '<div class="underbanner clearboth"></div>';
1341
1342 print '<table class="border tableforfield centpercent">';
1343
1344 if (getDolGlobalString('FICHINTER_USE_PLANNED_AND_DONE_DATES')) {
1345 // Date Start
1346 print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
1347 print '<td>';
1348 print $object->dateo ? dol_print_date($object->dateo, 'daytext') : '&nbsp;';
1349 print '</td>';
1350 print '</tr>';
1351
1352 // Date End
1353 print '<tr><td>'.$langs->trans("Datee").'</td>';
1354 print '<td>';
1355 print $object->datee ? dol_print_date($object->datee, 'daytext') : '&nbsp;';
1356 print '</td>';
1357 print '</tr>';
1358
1359 // Date Terminate/close
1360 print '<tr><td>'.$langs->trans("Datet").'</td>';
1361 print '<td>';
1362 print $object->datet ? dol_print_date($object->datet, 'daytext') : '&nbsp;';
1363 print '</td>';
1364 print '</tr>';
1365 }
1366
1367 // Description (must be a textarea and not html must be allowed (used in list view)
1368 print '<tr><td class="titlefield">';
1369 print $form->editfieldkey("Description", 'description', $object->description, $object, $user->hasRight('ficheinter', 'creer'), 'textarea');
1370 print '</td><td>';
1371 print $form->editfieldval("Description", 'description', $object->description, $object, $user->hasRight('ficheinter', 'creer'), 'textarea:8');
1372 print '</td>';
1373 print '</tr>';
1374
1375 // Contract
1376 if (isModEnabled('contract')) {
1377 $langs->load('contracts');
1378 print '<tr>';
1379 print '<td>';
1380
1381 print '<table class="nobordernopadding centpercent"><tr><td>';
1382 print $langs->trans('Contract');
1383 print '</td>';
1384 if ($action != 'editcontract') {
1385 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editcontract&id='.$object->id.'">';
1386 print img_edit($langs->trans('SetContract'), 1);
1387 print '</a></td>';
1388 }
1389 print '</tr></table>';
1390 print '</td><td>';
1391 if ($action == 'editcontract') {
1392 $formcontract = new FormContract($db);
1393 $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
1394 } else {
1395 if ($object->fk_contrat) {
1396 $contratstatic = new Contrat($db);
1397 $contratstatic->fetch($object->fk_contrat);
1398 //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1399 print $contratstatic->getNomUrl(0, 0, 1);
1400 } else {
1401 print "&nbsp;";
1402 }
1403 }
1404 print '</td>';
1405 print '</tr>';
1406 }
1407
1408 // Other attributes
1409 $cols = 2;
1410 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1411
1412 print '</table>';
1413
1414 print '</div>';
1415 print '<div class="fichehalfright">';
1416 print '<div class="underbanner clearboth"></div>';
1417
1418 print '<table class="border tableforfield centpercent">';
1419
1420 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1421 // Duration in time
1422 print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
1423 print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' ('.convertDurationtoHour($object->duration, "s").' '.$langs->trans("h").')</td>';
1424 print '</tr>';
1425 }
1426
1427 print "</table>";
1428
1429 print '</div>';
1430 print '</div>';
1431
1432 print '<div class="clearboth"></div><br>';
1433
1434
1435 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1436 $blocname = 'contacts';
1437 $title = $langs->trans('ContactsAddresses');
1438 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1439 }
1440
1441 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
1442 $blocname = 'notes';
1443 $title = $langs->trans('Notes');
1444 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1445 }
1446
1447 // Line of interventions
1448 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1449 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
1450 print '<input type="hidden" name="token" value="'.newToken().'">';
1451 print '<input type="hidden" name="id" value="'.$object->id.'">';
1452 if ($action == 'editline') {
1453 print '<input type="hidden" name="action" value="updateline">';
1454 print '<input type="hidden" name="line_id" value="'.GETPOSTINT('line_id').'">';
1455 } else {
1456 print '<input type="hidden" name="action" value="addline">';
1457 }
1458 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1459
1460 // Intervention lines
1461 $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
1462 $sql .= ' ft.date as date_intervention';
1463 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1464 $sql .= ' WHERE ft.fk_fichinter = '.((int) $object->id);
1465 if (getDolGlobalString('FICHINTER_HIDE_EMPTY_DURATION')) {
1466 $sql .= ' AND ft.duree <> 0';
1467 }
1468 $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
1469
1470 $resql = $db->query($sql);
1471 if ($resql) {
1472 $num = $db->num_rows($resql);
1473 $i = 0;
1474
1475 if ($num) {
1476 print '<br>';
1477 print '<table class="noborder centpercent">';
1478 print '<tr class="liste_titre">';
1479
1480 // No.
1481 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1482 print '<td width="5" class="center linecolnum"></td>';
1483 }
1484
1485 print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
1486 print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
1487 print '<td class="liste_titre right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1488 print '<td class="liste_titre">&nbsp;</td>';
1489 print '<td class="liste_titre">&nbsp;</td>';
1490 print "</tr>\n";
1491 }
1492 while ($i < $num) {
1493 $objp = $db->fetch_object($resql);
1494
1495 // Ligne en mode visu
1496 if ($action != 'editline' || GETPOSTINT('line_id') != $objp->rowid) {
1497 print '<tr class="oddeven">';
1498
1499 // No.
1500 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1501 print '<td class="center linecolnum">'.($i + 1).'</td>';
1502 }
1503
1504 print '<td>';
1505 print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1506 print dol_htmlentitiesbr($objp->description);
1507
1508 $objectline = new FichinterLigne($db);
1509 $objectline->fetch($objp->rowid);
1510 $objectline->fetch_optionals();
1511
1512 $extrafields->fetch_name_optionals_label($objectline->table_element);
1513
1514 if (!empty($extrafields)) {
1515 $temps = $objectline->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
1516 if (!empty($temps)) {
1517 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
1518 print $temps;
1519 print '</div>';
1520 }
1521 }
1522
1523 print '</td>';
1524
1525 // Date
1526 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>';
1527
1528 // Duration
1529 print '<td class="right" width="150">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? convertSecondToTime($objp->duree) : '').'</td>';
1530
1531 print "</td>\n";
1532
1533 // Icon to edit and delete
1534 if ($object->statut == 0 && $user->hasRight('ficheinter', 'creer')) {
1535 print '<td class="center">';
1536 print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&line_id='.$objp->rowid.'#'.$objp->rowid.'">';
1537 print img_edit();
1538 print '</a>';
1539 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&line_id='.$objp->rowid.'">';
1540 print img_delete();
1541 print '</a></td>';
1542 print '<td class="center">';
1543 if ($num > 1) {
1544 if ($i > 0) {
1545 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&line_id='.$objp->rowid.'">';
1546 print img_up();
1547 print '</a>';
1548 }
1549 if ($i < $num - 1) {
1550 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&line_id='.$objp->rowid.'">';
1551 print img_down();
1552 print '</a>';
1553 }
1554 }
1555 print '</td>';
1556 } else {
1557 print '<td colspan="2">&nbsp;</td>';
1558 }
1559
1560 print '</tr>';
1561 }
1562
1563 // Line in update mode
1564 if ($object->statut == 0 && $action == 'editline' && $user->hasRight('ficheinter', 'creer') && GETPOSTINT('line_id') == $objp->rowid) {
1565 print '<tr class="oddeven nohover">';
1566
1567 // No.
1568 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1569 print '<td class="center linecolnum">'.($i + 1).'</td>';
1570 }
1571
1572 print '<td>';
1573 print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1574
1575 // Editeur wysiwyg
1576 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1577 $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1578 $doleditor->Create();
1579
1580 $objectline = new FichinterLigne($db);
1581 $objectline->fetch($objp->rowid);
1582 $objectline->fetch_optionals();
1583
1584 $extrafields->fetch_name_optionals_label($objectline->table_element);
1585
1586 if (!empty($extrafields)) {
1587 $temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', 1, 'line');
1588 if (!empty($temps)) {
1589 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
1590 print $temps;
1591 print '</div>';
1592 }
1593 }
1594
1595 print '</td>';
1596
1597 // Date d'intervention
1598 print '<td class="center nowrap">';
1599 if (getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR')) {
1600 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
1601 } else {
1602 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
1603 }
1604 print '</td>';
1605
1606 // Duration
1607 print '<td class="right">';
1608 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1609 $selectmode = 'select';
1610 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1611 $selectmode = 'text';
1612 }
1613 $form->select_duration('duration', $objp->duree, 0, $selectmode);
1614 }
1615 print '</td>';
1616
1617 print '<td class="center" colspan="5" valign="center">';
1618 print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
1619 print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
1620 print '</tr>'."\n";
1621 }
1622
1623 $i++;
1624 }
1625
1626 $db->free($resql);
1627
1628 // Add new line
1629 if ($object->statut == 0 && $user->hasRight('ficheinter', 'creer') && $action != 'editline' && (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2')) {
1630 if (!$num) {
1631 print '<br>';
1632 print '<table class="noborder centpercent">';
1633 print '<tr class="liste_titre">';
1634
1635 // No.
1636 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1637 print '<td width="5" class="center linecolnum"></td>';
1638 }
1639
1640 print '<td>';
1641 print '<a name="add"></a>'; // ancre
1642 print $langs->trans('Description').'</td>';
1643 print '<td class="center">'.$langs->trans('Date').'</td>';
1644 print '<td class="right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1645 print '<td colspan="3">&nbsp;</td>';
1646 print "</tr>\n";
1647 }
1648
1649 print '<tr class="oddeven nohover">'."\n";
1650
1651 // No.
1652 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1653 print '<td class="center linecolnum">'.($i + 1).'</td>';
1654 }
1655
1656 print '<td>';
1657 // editeur wysiwyg
1658 if (!getDolGlobalString('FICHINTER_EMPTY_LINE_DESC')) {
1659 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1660 $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1661 $doleditor->Create();
1662 }
1663
1664 $objectline = new FichinterLigne($db);
1665 $extrafields->fetch_name_optionals_label($objectline->table_element);
1666
1667 if (is_object($objectline)) {
1668 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
1669
1670 if (!empty($temps)) {
1671 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
1672 print $temps;
1673 print '</div>';
1674 }
1675 }
1676
1677 print '</td>';
1678
1679 // Date intervention
1680 print '<td class="center nowrap">';
1681 $now = dol_now();
1682 $timearray = dol_getdate($now);
1683 if (!GETPOSTINT('diday')) {
1684 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1685 $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1686 } else {
1687 $timewithnohour = dol_mktime($timearray['hours'], $timearray['minutes'], 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1688 }
1689 } else {
1690 $timewithnohour = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
1691 }
1692 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1693 print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
1694 } else {
1695 print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
1696 }
1697 print '</td>';
1698
1699 // Duration
1700 print '<td class="right">';
1701 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1702 $selectmode = 'select';
1703 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1704 $selectmode = 'text';
1705 }
1706 $form->select_duration('duration', (!GETPOSTINT('durationhour') && !GETPOSTINT('durationmin')) ? 3600 : (60 * 60 * GETPOSTINT('durationhour') + 60 * GETPOSTINT('durationmin')), 0, $selectmode);
1707 }
1708 print '</td>';
1709
1710 print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button button-add" value="'.$langs->trans('Add').'" name="addline"></td>';
1711 print '</tr>';
1712
1713 if (!$num) {
1714 print '</table>';
1715 }
1716 }
1717
1718 if ($num) {
1719 print '</table>';
1720 }
1721 } else {
1722 dol_print_error($db);
1723 }
1724
1725 print '</form>'."\n";
1726 }
1727
1728 print dol_get_fiche_end();
1729
1730 print "\n";
1731
1732
1733 /*
1734 * Actions buttons
1735 */
1736
1737 print '<div class="tabsAction">';
1738
1739 $parameters = array();
1740 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1741 // modified by hook
1742 if (empty($reshook)) {
1743 $params = array();
1744 if ($user->socid == 0) {
1745 if ($action != 'editdescription' && ($action != 'presend')) {
1746 // Validate
1747 if ($object->statut == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '1')) {
1748 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'ficheinter_advance', 'validate'))) {
1749 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a></div>';
1750 } else {
1751 print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span></div>';
1752 }
1753 }
1754
1755 // Modify
1756 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')))) {
1757 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify&token='.newToken().'">';
1758 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1759 print $langs->trans("Modify");
1760 } else {
1761 print $langs->trans("SetToDraft");
1762 }
1763 print '</a></div>';
1764 }
1765
1766 // Reopen
1767 if ($object->statut >= Fichinter::STATUS_CLOSED) {
1768 if ($user->hasRight('ficheinter', 'creer')) {
1769 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>';
1770 } else {
1771 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('ReOpen').'</a></div>';
1772 }
1773 }
1774
1775 // Send
1776 if (empty($user->socid)) {
1777 if ($object->statut > Fichinter::STATUS_DRAFT) {
1778 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('ficheinter', 'ficheinter_advance', 'send')) {
1779 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>';
1780 } else {
1781 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
1782 }
1783 }
1784 }
1785
1786 // Create intervention model
1787 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 && $object->statut == Fichinter::STATUS_DRAFT && $user->hasRight('ficheinter', 'creer') && (count($object->lines) > 0)) {
1788 print '<div class="inline-block divButAction">';
1789 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>';
1790 print '</div>';
1791 }
1792
1793 $arrayofcreatebutton = array();
1794 // Proposal
1795 if (isModEnabled("service") && isModEnabled("propal") && $object->statut > Fichinter::STATUS_DRAFT) {
1796 $langs->load("propal");
1797 if ($object->statut < Fichinter::STATUS_BILLED) {
1798 $arrayofcreatebutton[] = array(
1799 'url' => '/comm/propal/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid,
1800 'label' => $langs->trans('AddProp'),
1801 'lang' => 'propal',
1802 'perm' => $user->hasRight('propal', 'creer'),
1803 'enabled' => true,
1804 );
1805 }
1806 }
1807
1808 // Invoicing
1809 if (isModEnabled('invoice') && $object->statut > Fichinter::STATUS_DRAFT) {
1810 $langs->load("bills");
1811 if ($object->statut < Fichinter::STATUS_BILLED) {
1812 $arrayofcreatebutton[] = array(
1813 'url' => '/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid,
1814 'label' => $langs->trans('AddBill'),
1815 'lang' => 'bills',
1816 'perm' => $user->hasRight('facture', 'creer') ? true : false,
1817 'enabled' => true,
1818 );
1819 }
1820
1821 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
1822 if ($object->statut != Fichinter::STATUS_BILLED) {
1823 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>';
1824 } else {
1825 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>';
1826 }
1827 }
1828 }
1829
1830 if (count($arrayofcreatebutton)) {
1831 print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayofcreatebutton, '', true, $params);
1832 }
1833
1834 // Sign
1835 if ($object->statut > Fichinter::STATUS_DRAFT) {
1836 if ($object->signed_status != Fichinter::$SIGNED_STATUSES['STATUS_SIGNED_ALL']) {
1837 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>';
1838 } else {
1839 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>';
1840 }
1841 }
1842
1843 // Done
1844 if (!getDolGlobalString('FICHINTER_CLASSIFY_BILLED') && $object->statut > Fichinter::STATUS_DRAFT && $object->statut < Fichinter::STATUS_CLOSED) {
1845 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>';
1846 }
1847
1848 // Clone
1849 if ($user->hasRight('ficheinter', 'creer')) {
1850 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>';
1851 }
1852
1853 // Delete
1854 print '<div class="inline-block divButAction">';
1855 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
1856 print '</div>';
1857 }
1858 }
1859 }
1860
1861 print '</div>';
1862
1863 if ($action != 'presend') {
1864 print '<div class="fichecenter"><div class="fichehalfleft">';
1865
1866 /*
1867 * Built documents
1868 */
1869 $filename = dol_sanitizeFileName($object->ref);
1870 $filedir = $conf->ficheinter->dir_output."/".$filename;
1871 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1872 $genallowed = $user->hasRight('ficheinter', 'lire');
1873 $delallowed = $user->hasRight('ficheinter', 'creer');
1874 print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
1875
1876 // Show links to link elements
1877 $tmparray = $form->showLinkToObjectBlock($object, array(), array('fichinter'), 1);
1878 $linktoelem = $tmparray['linktoelem'];
1879 $htmltoenteralink = $tmparray['htmltoenteralink'];
1880 print $htmltoenteralink;
1881
1882 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1883
1884 // Show direct download link
1885 if ($object->statut != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_EXTERNAL_DOWNLOAD')) {
1886 print '<br><!-- Link to download main doc -->'."\n";
1887 print showDirectDownloadLink($object).'<br>';
1888 }
1889
1890 // Show online signature link
1891 if ($object->statut != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_ONLINE_SIGN')) {
1892 print '<br><!-- Link to sign -->';
1893 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
1894
1895 print showOnlineSignatureUrl('fichinter', $object->ref, $object).'<br>';
1896 }
1897
1898 print '</div><div class="fichehalfright">';
1899
1900 $MAXEVENT = 10;
1901
1902 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/fichinter/agenda.php?id='.$object->id);
1903
1904 // List of actions on element
1905 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1906 $formactions = new FormActions($db);
1907 $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
1908
1909 print '</div></div>';
1910 }
1911
1912
1913 // Select mail models is same action as presend
1914 if (GETPOST('modelselected')) {
1915 $action = 'presend';
1916 }
1917
1918 // Presend form
1919 $modelmail = 'fichinter_send';
1920 $defaulttopic = 'SendInterventionRef';
1921 $diroutput = $conf->ficheinter->dir_output;
1922 $trackid = 'int'.$object->id;
1923
1924 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1925}
1926
1927
1928llxFooter();
1929
1930$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.