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