dolibarr 20.0.2
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 print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300');
1089 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>';
1090 print '</td></tr>';
1091 print '</table>';
1092
1093 print dol_get_fiche_end();
1094
1095 print $form->buttonsSaveCancel("CreateDraftIntervention");
1096
1097 print '</form>';
1098 }
1099} elseif ($id > 0 || !empty($ref)) {
1100 // View mode
1101
1102 $object->fetch($id, $ref);
1103 $object->fetch_thirdparty();
1104
1105 $soc = new Societe($db);
1106 $soc->fetch($object->socid);
1107
1108 if ($error > 0) {
1109 dol_htmloutput_errors($mesg);
1110 } else {
1111 dol_htmloutput_mesg($mesg);
1112 }
1113
1115
1116 print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, 'intervention');
1117
1118 $formconfirm = '';
1119
1120 // Confirm deletion of intervention
1121 if ($action == 'delete') {
1122 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
1123 }
1124
1125 // Confirm validation
1126 if ($action == 'validate') {
1127 // Verify if the object's number os temporary
1128 $ref = substr($object->ref, 1, 4);
1129 if ($ref == 'PROV') {
1130 $numref = $object->getNextNumRef($soc);
1131 if (empty($numref)) {
1132 $error++;
1133 setEventMessages($object->error, $object->errors, 'errors');
1134 }
1135 } else {
1136 $numref = $object->ref;
1137 }
1138 $text = $langs->trans('ConfirmValidateIntervention', $numref);
1139 if (isModEnabled('notification')) {
1140 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1141 $notify = new Notify($db);
1142 $text .= '<br>';
1143 $text .= $notify->confirmMessage('FICHINTER_VALIDATE', $object->socid, $object);
1144 }
1145
1146 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
1147 }
1148
1149 // Confirm done
1150 if ($action == 'classifydone') {
1151 $text = $langs->trans('ConfirmCloseIntervention');
1152 if (isModEnabled('notification')) {
1153 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1154 $notify = new Notify($db);
1155 $text .= '<br>';
1156 $text .= $notify->confirmMessage('FICHINTER_CLOSE', $object->socid, $object);
1157 }
1158 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseIntervention'), $text, 'confirm_done', '', 0, 1);
1159 }
1160
1161 // Confirm back to draft
1162 if ($action == 'modify') {
1163 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
1164 }
1165
1166 // Confirm back to open
1167 if ($action == 'reopen') {
1168 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
1169 }
1170
1171 // Confirm deletion of line
1172 if ($action == 'ask_deleteline') {
1173 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
1174 }
1175
1176 // Clone confirmation
1177 if ($action == 'clone') {
1178 // Create an array for form
1179 $formquestion = array(
1180 // 'text' => $langs->trans("ConfirmClone"),
1181 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
1182 // 1),
1183 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
1184 // => 1),
1185 array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', '', '', 0, 0, null, 0, 'minwidth200')));
1186 // Paiement incomplet. On demande si motif = escompte ou autre
1187 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1188 }
1189
1190 if (!$formconfirm) {
1191 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1192 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1193 if (empty($reshook)) {
1194 $formconfirm .= $hookmanager->resPrint;
1195 } elseif ($reshook > 0) {
1196 $formconfirm = $hookmanager->resPrint;
1197 }
1198 }
1199
1200 // Print form confirm
1201 print $formconfirm;
1202
1203
1204 // Intervention card
1205 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1206
1207
1208 $morehtmlref = '<div class="refidno">';
1209 // Ref customer
1210 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->hasRight('ficheinter', 'creer'), 'string', '', 0, 1);
1211 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->hasRight('ficheinter', 'creer'), 'string', '', null, null, '', 1);
1212 // Thirdparty
1213 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
1214 // Project
1215 if (isModEnabled('project')) {
1216 $langs->load("projects");
1217 $morehtmlref .= '<br>';
1218 if ($usercancreate) {
1219 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1220 if ($action != 'classify') {
1221 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1222 }
1223 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1224 } else {
1225 if (!empty($object->fk_project)) {
1226 $proj = new Project($db);
1227 $proj->fetch($object->fk_project);
1228 $morehtmlref .= $proj->getNomUrl(1);
1229 if ($proj->title) {
1230 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1231 }
1232 }
1233 }
1234 }
1235 $morehtmlref .= '</div>';
1236
1237 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1238
1239
1240 print '<div class="fichecenter">';
1241 print '<div class="fichehalfleft">';
1242 print '<div class="underbanner clearboth"></div>';
1243
1244 print '<table class="border tableforfield centpercent">';
1245
1246 if (getDolGlobalString('FICHINTER_USE_PLANNED_AND_DONE_DATES')) {
1247 // Date Start
1248 print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
1249 print '<td>';
1250 print $object->dateo ? dol_print_date($object->dateo, 'daytext') : '&nbsp;';
1251 print '</td>';
1252 print '</tr>';
1253
1254 // Date End
1255 print '<tr><td>'.$langs->trans("Datee").'</td>';
1256 print '<td>';
1257 print $object->datee ? dol_print_date($object->datee, 'daytext') : '&nbsp;';
1258 print '</td>';
1259 print '</tr>';
1260
1261 // Date Terminate/close
1262 print '<tr><td>'.$langs->trans("Datet").'</td>';
1263 print '<td>';
1264 print $object->datet ? dol_print_date($object->datet, 'daytext') : '&nbsp;';
1265 print '</td>';
1266 print '</tr>';
1267 }
1268
1269 // Description (must be a textarea and not html must be allowed (used in list view)
1270 print '<tr><td class="titlefield">';
1271 print $form->editfieldkey("Description", 'description', $object->description, $object, $user->hasRight('ficheinter', 'creer'), 'textarea');
1272 print '</td><td>';
1273 print $form->editfieldval("Description", 'description', $object->description, $object, $user->hasRight('ficheinter', 'creer'), 'textarea:8');
1274 print '</td>';
1275 print '</tr>';
1276
1277 // Contract
1278 if (isModEnabled('contract')) {
1279 $langs->load('contracts');
1280 print '<tr>';
1281 print '<td>';
1282
1283 print '<table class="nobordernopadding centpercent"><tr><td>';
1284 print $langs->trans('Contract');
1285 print '</td>';
1286 if ($action != 'editcontract') {
1287 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editcontract&id='.$object->id.'">';
1288 print img_edit($langs->trans('SetContract'), 1);
1289 print '</a></td>';
1290 }
1291 print '</tr></table>';
1292 print '</td><td>';
1293 if ($action == 'editcontract') {
1294 $formcontract = new FormContract($db);
1295 $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
1296 } else {
1297 if ($object->fk_contrat) {
1298 $contratstatic = new Contrat($db);
1299 $contratstatic->fetch($object->fk_contrat);
1300 //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1301 print $contratstatic->getNomUrl(0, '', 1);
1302 } else {
1303 print "&nbsp;";
1304 }
1305 }
1306 print '</td>';
1307 print '</tr>';
1308 }
1309
1310 // Other attributes
1311 $cols = 2;
1312 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1313
1314 print '</table>';
1315
1316 print '</div>';
1317 print '<div class="fichehalfright">';
1318 print '<div class="underbanner clearboth"></div>';
1319
1320 print '<table class="border tableforfield centpercent">';
1321
1322 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS')) {
1323 // Duration in time
1324 print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
1325 print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' ('.convertDurationtoHour($object->duration, "s").' '.$langs->trans("h").')</td>';
1326 print '</tr>';
1327 }
1328
1329 print "</table>";
1330
1331 print '</div>';
1332 print '</div>';
1333
1334 print '<div class="clearboth"></div><br>';
1335
1336
1337 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1338 $blocname = 'contacts';
1339 $title = $langs->trans('ContactsAddresses');
1340 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1341 }
1342
1343 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
1344 $blocname = 'notes';
1345 $title = $langs->trans('Notes');
1346 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1347 }
1348
1349 // Line of interventions
1350 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS')) {
1351 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
1352 print '<input type="hidden" name="token" value="'.newToken().'">';
1353 print '<input type="hidden" name="id" value="'.$object->id.'">';
1354 if ($action == 'editline') {
1355 print '<input type="hidden" name="action" value="updateline">';
1356 print '<input type="hidden" name="line_id" value="'.GETPOSTINT('line_id').'">';
1357 } else {
1358 print '<input type="hidden" name="action" value="addline">';
1359 }
1360 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1361
1362 // Intervention lines
1363 $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
1364 $sql .= ' ft.date as date_intervention';
1365 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1366 $sql .= ' WHERE ft.fk_fichinter = '.((int) $object->id);
1367 if (getDolGlobalString('FICHINTER_HIDE_EMPTY_DURATION')) {
1368 $sql .= ' AND ft.duree <> 0';
1369 }
1370 $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
1371
1372 $resql = $db->query($sql);
1373 if ($resql) {
1374 $num = $db->num_rows($resql);
1375 $i = 0;
1376
1377 if ($num) {
1378 print '<br>';
1379 print '<table class="noborder centpercent">';
1380 print '<tr class="liste_titre">';
1381
1382 // No.
1383 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1384 print '<td width="5" class="center linecolnum"></td>';
1385 }
1386
1387 print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
1388 print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
1389 print '<td class="liste_titre right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1390 print '<td class="liste_titre">&nbsp;</td>';
1391 print '<td class="liste_titre">&nbsp;</td>';
1392 print "</tr>\n";
1393 }
1394 while ($i < $num) {
1395 $objp = $db->fetch_object($resql);
1396
1397 // Ligne en mode visu
1398 if ($action != 'editline' || GETPOSTINT('line_id') != $objp->rowid) {
1399 print '<tr class="oddeven">';
1400
1401 // No.
1402 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1403 print '<td class="center linecolnum">'.($i + 1).'</td>';
1404 }
1405
1406 print '<td>';
1407 print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1408 print dol_htmlentitiesbr($objp->description);
1409
1410 $objectline = new FichinterLigne($db);
1411 $objectline->fetch($objp->rowid);
1412 $objectline->fetch_optionals();
1413
1414 $extrafields->fetch_name_optionals_label($objectline->table_element);
1415
1416 if (!empty($extrafields)) {
1417 $temps = $objectline->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
1418 if (!empty($temps)) {
1419 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
1420 print $temps;
1421 print '</div>';
1422 }
1423 }
1424
1425 print '</td>';
1426
1427 // Date
1428 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>';
1429
1430 // Duration
1431 print '<td class="right" width="150">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? convertSecondToTime($objp->duree) : '').'</td>';
1432
1433 print "</td>\n";
1434
1435 // Icon to edit and delete
1436 if ($object->statut == 0 && $user->hasRight('ficheinter', 'creer')) {
1437 print '<td class="center">';
1438 print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&line_id='.$objp->rowid.'#'.$objp->rowid.'">';
1439 print img_edit();
1440 print '</a>';
1441 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&line_id='.$objp->rowid.'">';
1442 print img_delete();
1443 print '</a></td>';
1444 print '<td class="center">';
1445 if ($num > 1) {
1446 if ($i > 0) {
1447 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&line_id='.$objp->rowid.'">';
1448 print img_up();
1449 print '</a>';
1450 }
1451 if ($i < $num - 1) {
1452 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&line_id='.$objp->rowid.'">';
1453 print img_down();
1454 print '</a>';
1455 }
1456 }
1457 print '</td>';
1458 } else {
1459 print '<td colspan="2">&nbsp;</td>';
1460 }
1461
1462 print '</tr>';
1463 }
1464
1465 // Line in update mode
1466 if ($object->statut == 0 && $action == 'editline' && $user->hasRight('ficheinter', 'creer') && GETPOSTINT('line_id') == $objp->rowid) {
1467 print '<tr class="oddeven nohover">';
1468
1469 // No.
1470 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1471 print '<td class="center linecolnum">'.($i + 1).'</td>';
1472 }
1473
1474 print '<td>';
1475 print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1476
1477 // Editeur wysiwyg
1478 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1479 $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1480 $doleditor->Create();
1481
1482 $objectline = new FichinterLigne($db);
1483 $objectline->fetch($objp->rowid);
1484 $objectline->fetch_optionals();
1485
1486 $extrafields->fetch_name_optionals_label($objectline->table_element);
1487
1488 if (!empty($extrafields)) {
1489 $temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', 1, 'line');
1490 if (!empty($temps)) {
1491 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
1492 print $temps;
1493 print '</div>';
1494 }
1495 }
1496
1497 print '</td>';
1498
1499 // Date d'intervention
1500 print '<td class="center nowrap">';
1501 if (getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR')) {
1502 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
1503 } else {
1504 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
1505 }
1506 print '</td>';
1507
1508 // Duration
1509 print '<td class="right">';
1510 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1511 $selectmode = 'select';
1512 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1513 $selectmode = 'text';
1514 }
1515 $form->select_duration('duration', $objp->duree, 0, $selectmode);
1516 }
1517 print '</td>';
1518
1519 print '<td class="center" colspan="5" valign="center">';
1520 print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
1521 print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
1522 print '</tr>'."\n";
1523 }
1524
1525 $i++;
1526 }
1527
1528 $db->free($resql);
1529
1530 // Add new line
1531 if ($object->statut == 0 && $user->hasRight('ficheinter', 'creer') && $action != 'editline' && !getDolGlobalString('FICHINTER_DISABLE_DETAILS')) {
1532 if (!$num) {
1533 print '<br>';
1534 print '<table class="noborder centpercent">';
1535 print '<tr class="liste_titre">';
1536
1537 // No.
1538 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1539 print '<td width="5" class="center linecolnum"></td>';
1540 }
1541
1542 print '<td>';
1543 print '<a name="add"></a>'; // ancre
1544 print $langs->trans('Description').'</td>';
1545 print '<td class="center">'.$langs->trans('Date').'</td>';
1546 print '<td class="right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1547 print '<td colspan="3">&nbsp;</td>';
1548 print "</tr>\n";
1549 }
1550
1551 print '<tr class="oddeven nohover">'."\n";
1552
1553 // No.
1554 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1555 print '<td class="center linecolnum">'.($i + 1).'</td>';
1556 }
1557
1558 print '<td>';
1559 // editeur wysiwyg
1560 if (!getDolGlobalString('FICHINTER_EMPTY_LINE_DESC')) {
1561 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1562 $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1563 $doleditor->Create();
1564 }
1565
1566 $objectline = new FichinterLigne($db);
1567 $extrafields->fetch_name_optionals_label($objectline->table_element);
1568
1569 if (is_object($objectline)) {
1570 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
1571
1572 if (!empty($temps)) {
1573 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
1574 print $temps;
1575 print '</div>';
1576 }
1577 }
1578
1579 print '</td>';
1580
1581 // Date intervention
1582 print '<td class="center nowrap">';
1583 $now = dol_now();
1584 $timearray = dol_getdate($now);
1585 if (!GETPOSTINT('diday')) {
1586 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1587 $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1588 } else {
1589 $timewithnohour = dol_mktime($timearray['hours'], $timearray['minutes'], 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1590 }
1591 } else {
1592 $timewithnohour = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
1593 }
1594 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1595 print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
1596 } else {
1597 print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
1598 }
1599 print '</td>';
1600
1601 // Duration
1602 print '<td class="right">';
1603 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1604 $selectmode = 'select';
1605 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1606 $selectmode = 'text';
1607 }
1608 $form->select_duration('duration', (!GETPOSTINT('durationhour') && !GETPOSTINT('durationmin')) ? 3600 : (60 * 60 * GETPOSTINT('durationhour') + 60 * GETPOSTINT('durationmin')), 0, $selectmode);
1609 }
1610 print '</td>';
1611
1612 print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button button-add" value="'.$langs->trans('Add').'" name="addline"></td>';
1613 print '</tr>';
1614
1615 if (!$num) {
1616 print '</table>';
1617 }
1618 }
1619
1620 if ($num) {
1621 print '</table>';
1622 }
1623 } else {
1624 dol_print_error($db);
1625 }
1626
1627 print '</form>'."\n";
1628 }
1629
1630 print dol_get_fiche_end();
1631
1632 print "\n";
1633
1634
1635 /*
1636 * Actions buttons
1637 */
1638
1639 print '<div class="tabsAction">';
1640
1641 $parameters = array();
1642 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1643 // modified by hook
1644 if (empty($reshook)) {
1645 if ($user->socid == 0) {
1646 if ($action != 'editdescription' && ($action != 'presend')) {
1647 // Validate
1648 if ($object->statut == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || getDolGlobalString('FICHINTER_DISABLE_DETAILS'))) {
1649 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'ficheinter_advance', 'validate'))) {
1650 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a></div>';
1651 } else {
1652 print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span></div>';
1653 }
1654 }
1655
1656 // Modify
1657 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')))) {
1658 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify">';
1659 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS')) {
1660 print $langs->trans("Modify");
1661 } else {
1662 print $langs->trans("SetToDraft");
1663 }
1664 print '</a></div>';
1665 }
1666
1667 // Reopen
1668 if ($object->statut >= Fichinter::STATUS_CLOSED) {
1669 if ($user->hasRight('ficheinter', 'creer')) {
1670 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>';
1671 } else {
1672 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('ReOpen').'</a></div>';
1673 }
1674 }
1675
1676 // Send
1677 if (empty($user->socid)) {
1678 if ($object->statut > Fichinter::STATUS_DRAFT) {
1679 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('ficheinter', 'ficheinter_advance', 'send')) {
1680 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>';
1681 } else {
1682 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
1683 }
1684 }
1685 }
1686
1687 // Create intervention model
1688 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 && $object->statut == Fichinter::STATUS_DRAFT && $user->hasRight('ficheinter', 'creer') && (count($object->lines) > 0)) {
1689 print '<div class="inline-block divButAction">';
1690 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>';
1691 print '</div>';
1692 }
1693
1694 // Proposal
1695 if (isModEnabled("service") && isModEnabled("propal") && $object->statut > Fichinter::STATUS_DRAFT) {
1696 $langs->load("propal");
1697 if ($object->statut < Fichinter::STATUS_BILLED) {
1698 if ($user->hasRight('propal', 'creer')) {
1699 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>';
1700 } else {
1701 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddProp").'</a></div>';
1702 }
1703 }
1704 }
1705
1706 // Invoicing
1707 if (isModEnabled('invoice') && $object->statut > Fichinter::STATUS_DRAFT) {
1708 $langs->load("bills");
1709 if ($object->statut < Fichinter::STATUS_BILLED) {
1710 if ($user->hasRight('facture', 'creer')) {
1711 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>';
1712 } else {
1713 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddBill").'</a></div>';
1714 }
1715 }
1716
1717 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
1718 if ($object->statut != Fichinter::STATUS_BILLED) {
1719 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>';
1720 } else {
1721 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>';
1722 }
1723 }
1724 }
1725
1726 // Done
1727 if (!getDolGlobalString('FICHINTER_CLASSIFY_BILLED') && $object->statut > Fichinter::STATUS_DRAFT && $object->statut < Fichinter::STATUS_CLOSED) {
1728 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>';
1729 }
1730
1731 // Clone
1732 if ($user->hasRight('ficheinter', 'creer')) {
1733 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>';
1734 }
1735
1736 // Delete
1737 print '<div class="inline-block divButAction">';
1738 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
1739 print '</div>';
1740 }
1741 }
1742 }
1743
1744 print '</div>';
1745
1746 if ($action != 'presend') {
1747 print '<div class="fichecenter"><div class="fichehalfleft">';
1748
1749 /*
1750 * Built documents
1751 */
1752 $filename = dol_sanitizeFileName($object->ref);
1753 $filedir = $conf->ficheinter->dir_output."/".$filename;
1754 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1755 $genallowed = $user->hasRight('ficheinter', 'lire');
1756 $delallowed = $user->hasRight('ficheinter', 'creer');
1757 print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
1758
1759 // Show links to link elements
1760 $linktoelem = $form->showLinkToObjectBlock($object, null, array('fichinter'));
1761 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1762
1763 // Show direct download link
1764 if ($object->statut != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_EXTERNAL_DOWNLOAD')) {
1765 print '<br><!-- Link to download main doc -->'."\n";
1766 print showDirectDownloadLink($object).'<br>';
1767 }
1768
1769 // Show online signature link
1770 if ($object->statut != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_ONLINE_SIGN')) {
1771 print '<br><!-- Link to sign -->';
1772 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
1773
1774 print showOnlineSignatureUrl('fichinter', $object->ref, $object).'<br>';
1775 }
1776
1777 print '</div><div class="fichehalfright">';
1778
1779 $MAXEVENT = 10;
1780
1781 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/fichinter/agenda.php?id='.$object->id);
1782
1783 // List of actions on element
1784 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1785 $formactions = new FormActions($db);
1786 $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
1787
1788 print '</div></div>';
1789 }
1790
1791
1792 // Select mail models is same action as presend
1793 if (GETPOST('modelselected')) {
1794 $action = 'presend';
1795 }
1796
1797 // Presend form
1798 $modelmail = 'fichinter_send';
1799 $defaulttopic = 'SendInterventionRef';
1800 $diroutput = $conf->ficheinter->dir_output;
1801 $trackid = 'int'.$object->id;
1802
1803 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1804}
1805
1806
1807llxFooter();
1808
1809$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...)
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.