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