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