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