dolibarr 24.0.3
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
3 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4 * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2021-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 * Copyright (C) 2022-2023 Charlene Benke <charlene@patas-monkey.com>
8 * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
9 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Irvine FLEITH <irvine.fleith@atm-consulting.fr>
11 * Copyright (C) 2026 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
50require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
51
52if (isModEnabled('project')) {
53 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
54 include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
55 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
56}
57if (isModEnabled('contract')) {
58 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcontract.class.php';
59 include_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
60 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
61}
62
63// Load translation files required by the page
64$langs->loadLangs(array("companies", "other", "ticket"));
65
66// Get parameters
67$id = GETPOSTINT('id');
68$ref = GETPOST('ref', 'alpha');
69$track_id = GETPOST('track_id', 'alpha', 3);
70$socid = GETPOSTINT('socid');
71$contactid = GETPOSTINT('contactid');
72$projectid = GETPOSTINT('projectid');
73$notifyTiers = GETPOST("notify_tiers_at_create", 'alpha');
74$mine = GETPOSTINT('mine');
75
76$action = GETPOST('action', 'aZ09');
77$cancel = GETPOST('cancel', 'alpha');
78$backtopage = GETPOST('backtopage', 'alpha');
79$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
80$contextpage = GETPOST('contextpage', 'aZ');
81
82$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
83$sortfield = GETPOST('sortfield', 'aZ09comma') ? GETPOST('sortfield', 'aZ09comma') : "a.datep";
84$sortorder = GETPOST('sortorder', 'aZ09comma') ? GETPOST('sortorder', 'aZ09comma') : "desc";
85$search_rowid = GETPOST('search_rowid');
86$search_agenda_label = GETPOST('search_agenda_label');
87
88if (GETPOST('actioncode', 'array')) {
89 $actioncode = GETPOST('actioncode', 'array', 3);
90 if (!count($actioncode)) {
91 $actioncode = '0';
92 }
93} else {
94 $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
95}
96
97
98// Initialize a technical object to manage hooks of ticket. Note that conf->hooks_modules contains array array
99$hookmanager->initHooks(array('ticketcard', 'globalcard'));
100
101$object = new Ticket($db);
102
103// Fetch optionals attributes and labels
104$extrafields->fetch_name_optionals_label($object->table_element);
105
106$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
107
108// Initialize array of search criteria
109$search_all = GETPOST("search_all", 'alpha');
110$search = array();
111foreach ($object->fields as $key => $val) {
112 if (GETPOST('search_'.$key, 'alpha')) {
113 $search[$key] = GETPOST('search_'.$key, 'alpha');
114 }
115}
116
117if (empty($action) && empty($id) && empty($ref)) {
118 $action = 'view';
119}
120
121// Select mail models is same action as add_message
122if (GETPOST('modelselected', 'alpha')) {
123 $action = 'presend';
124}
125
126// Load object
127//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
128$res = 0;
129// Must not load on add: the posted ref may now belong to another ticket.
130if (($id || $track_id || $ref) && $action != 'add') {
131 $res = $object->fetch($id, $ref, $track_id);
132 if ($res >= 0) {
133 $id = $object->id;
134 $track_id = $object->track_id;
135 }
136}
137
138$now = dol_now();
139
140$actionobject = new ActionsTicket($db);
141
142// Store current page url
143$url_page_current = DOL_URL_ROOT.'/ticket/card.php';
144
145// Security check - Protection if external user
146if ($user->socid > 0) {
147 $socid = $user->socid;
148}
149$result = restrictedArea($user, 'ticket', $object->id);
150
151$triggermodname = 'TICKET_MODIFY';
152
153// Permissions
154$permissiontoread = $user->hasRight('ticket', 'read');
155$permissiontoadd = $user->hasRight('ticket', 'write');
156$permissiontodelete = $user->hasRight('ticket', 'delete');
157// Permission allowing the management of all ticket status modifications (status change buttons, Close/Resolve, Cancel, the assignee selection menu, and re-open)
158$permissiontomanage = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ticket', 'write')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ticket', 'manage_advance')));
159$permissiontoeditextra = $permissiontoadd;
160if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
161 // For action 'update_extras', is there a specific permission set for the attribute to update
162 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
163}
164
165$upload_dir = $conf->ticket->dir_output;
166
167
168/*
169 * Actions
170 */
171
172$parameters = array();
173$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
174if ($reshook < 0) {
175 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
176}
177
178$error = 0;
179if (empty($reshook)) {
180 // Purge search criteria
181 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers{
182 $actioncode = '';
183 $search_agenda_label = '';
184 }
185
186 $backurlforlist = DOL_URL_ROOT . '/ticket/list.php';
187
188 if (empty($backtopage) || ($cancel && empty($id))) {
189 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
190 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
191 $backtopage = $backurlforlist;
192 } else {
193 $backtopage = DOL_URL_ROOT . '/ticket/card.php?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__');
194 }
195 }
196 }
197
198 if ($cancel) {
199 if (!empty($backtopageforcancel)) {
200 header("Location: " . $backtopageforcancel);
201 exit;
202 } elseif (!empty($backtopage)) {
203 header("Location: " . $backtopage);
204 exit;
205 }
206 $action = 'view';
207 }
208
209 if ((($action == 'add' && GETPOST('save', 'alpha')) || ($action == 'update' && $object->status < Ticket::STATUS_CLOSED)) && $permissiontoadd) {
210 $ifErrorAction = ($action == 'add' ? 'create' : 'edit'); // Test on permission not required here
211 if ($action == 'add') { // Test on permission already done
212 $object->track_id = null;
213 }
214 $error = 0;
215
216 $fieldsToCheck = [
217 'ref' => ['check' => 'alpha', 'langs' => 'Ref'],
218 'type_code' => ['check' => 'alpha', 'langs' => 'TicketTypeRequest'],
219 'category_code' => ['check' => 'alpha', 'langs' => 'TicketCategory'],
220 'severity_code' => ['check' => 'alpha', 'langs' => 'TicketSeverity'],
221 'subject' => ['check' => 'alphanohtml', 'langs' => 'Subject'],
222 'message' => ['check' => 'restricthtml', 'langs' => 'Message']
223 ];
224
225 FormTicket::checkRequiredFields($fieldsToCheck, $error);
226
227 if (!empty($error)) {
228 $action = $ifErrorAction;
229 }
230
231 $ret = $extrafields->setOptionalsFromPost(null, $object);
232 if ($ret < 0) {
233 $error++;
234 }
235 $getRef = GETPOST('ref', 'alpha');
236
237 if (!empty($getRef)) {
238 $isExistingRef = $object->checkExistingRef($action, $getRef);
239 } else {
240 $isExistingRef = true;
241 }
242
243 $style = '';
244
245 if ($isExistingRef) {
246 if ($action == 'update') { // Test on permission already done
247 $error++;
248 $action = 'edit';
249 $style = 'errors';
250 } elseif ($action == 'add') { // Test on permission already done
251 $object->ref = $object->getDefaultRef();
252 $object->track_id = null;
253 $style = 'warnings';
254 }
255 if (!empty($getRef)) {
256 setEventMessage($langs->trans('TicketRefAlreadyUsed', $getRef, $object->ref), $style);
257 }
258 }
259 if (!$error) {
260 $db->begin();
261
262 $object->type_code = GETPOST('type_code', 'alpha');
263 $object->category_code = GETPOST('category_code', 'alpha');
264 $object->severity_code = GETPOST('severity_code', 'alpha');
265 $object->subject = GETPOST('subject', 'alpha');
266 $object->message = GETPOST('message', 'restricthtml');
267 $object->fk_soc = GETPOSTINT('socid');
268 $fk_user_assign = GETPOSTINT('fk_user_assign');
269 $object->fk_project = GETPOSTINT('projectid');
270 $object->fk_contract = GETPOSTISSET('contractid') ? GETPOSTINT('contractid') : GETPOSTINT('contratid');
271
272 if ($fk_user_assign > 0) {
273 $object->fk_user_assign = $fk_user_assign;
274 $object->status = $object::STATUS_ASSIGNED;
275 }
276
277 if ($action == 'add') { // Test on permission already done
278 $object->type_code = GETPOST("type_code", 'alpha');
279 $object->type_label = $langs->trans($langs->getLabelFromKey($db, $object->type_code, 'c_ticket_type', 'code', 'label'));
280 $object->category_label = $langs->trans($langs->getLabelFromKey($db, $object->category_code, 'c_ticket_category', 'code', 'label'));
281 $object->severity_label = $langs->trans($langs->getLabelFromKey($db, $object->severity_code, 'c_ticket_severity', 'code', 'label'));
282 $object->fk_user_create = $user->id;
283 $object->email_from = $user->email;
284 $object->origin_email = null;
285 $notifyTiers = GETPOST("notify_tiers_at_create", 'alpha');
286 $object->notify_tiers_at_create = empty($notifyTiers) ? 0 : 1;
287 $object->context['contact_id'] = GETPOSTINT('contactid');
288 $id = $object->create($user);
289 } else {
290 $id = $object->update($user);
291 }
292
293 if ($id <= 0) {
294 $error++;
295 setEventMessages($object->error, $object->errors, 'errors');
296 $action = $ifErrorAction;
297 }
298
299 if (!$error) {
300 // Category association
301 $categories = GETPOST('categories', 'array:int');
302 $object->setCategories($categories);
303 }
304
305 if ($action == 'add') { // Test on permission already done
306 if (!$error) {
307 // Add contact
308 $contactid = GETPOSTINT('contactid');
309 $type_contact = GETPOST("type", 'alpha');
310
311 if ($contactid > 0 && $type_contact) {
312 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
313 $result = $object->add_contact($contactid, $typeid, 'external');
314 }
315
316 // Link ticket to project
317 if (GETPOST('origin', 'alpha') == 'projet') {
318 $projectid = GETPOSTINT('originid');
319 } else {
320 $projectid = GETPOSTINT('projectid');
321 }
322
323 if ($projectid > 0) {
324 $object->setProject($projectid);
325 }
326
327 // Auto mark as read if created from backend
328 if (getDolGlobalString('TICKET_AUTO_READ_WHEN_CREATED_FROM_BACKEND') && $permissiontomanage) {
329 if (!$object->markAsRead($user) > 0) {
330 setEventMessages($object->error, $object->errors, 'errors');
331 }
332 }
333
334 // Auto assign user
335 if ((empty($fk_user_assign) && getDolGlobalInt('TICKET_AUTO_ASSIGN_USER_CREATE') == 1) || (getDolGlobalInt('TICKET_AUTO_ASSIGN_USER_CREATE') == 2)) {
336 $result = $object->assignUser($user, $user->id, 1);
337 $object->add_contact($user->id, "SUPPORTTEC", 'internal');
338 }
339 }
340
341 if (!$error) {
342 // File transfer
343 $object->copyFilesForTicket(''); // trackid is forced to '' because files were uploaded when no id for ticket exists yet and trackid was ''
344 }
345 }
346 if (!$error) {
347 $db->commit();
348
349 if (!empty($backtopage)) {
350 if (empty($id)) {
351 $url = $backtopage;
352 } else {
353 $url = 'card.php?track_id=' . urlencode($object->track_id);
354 }
355 } else {
356 $url = 'card.php?track_id=' . urlencode($object->track_id);
357 }
358
359 header("Location: " . $url);
360 exit;
361 } else {
362 $db->rollback();
363 setEventMessages($object->error, $object->errors, 'errors');
364 }
365 } else {
366 $action = $ifErrorAction;
367 }
368 }
369
370 // Mark as Read
371 if ($action == "set_read" && $permissiontomanage) {
372 $object->fetch(0, '', GETPOST("track_id", 'alpha'));
373
374 if ($object->markAsRead($user) > 0) {
375 setEventMessages($langs->trans('TicketMarkedAsRead'), null, 'mesgs');
376
377 header("Location: card.php?track_id=" . $object->track_id);
378 exit;
379 } else {
380 setEventMessages($object->error, $object->errors, 'errors');
381 }
382 $action = 'view';
383 }
384
385 // Assign to someone
386 if ($action == "assign_user" && GETPOST('btn_assign_user', 'alpha') && $permissiontomanage) {
387 $object->fetch(0, '', GETPOST("track_id", 'alpha'));
388 $useroriginassign = $object->fk_user_assign;
389 $usertoassign = GETPOSTINT('fk_user_assign');
390
391 /*if (! ($usertoassign > 0)) {
392 $error++;
393 array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("AssignedTo")));
394 $action = 'view';
395 }*/
396
397 if (!$error) {
398 $ret = $object->assignUser($user, $usertoassign);
399 if ($ret < 0) {
400 $error++;
401 }
402 }
403
404 if (!$error) { // Update list of contacts
405 // If a user has already been assigned, we delete him from the contacts.
406 if ($useroriginassign > 0) {
407 $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
408 foreach ($internal_contacts as $key => $contact) {
409 if ($contact['id'] !== $usertoassign) {
410 $result = $object->delete_contact($contact['rowid']);
411 if ($result < 0) {
412 $error++;
413 setEventMessages($object->error, $object->errors, 'errors');
414 }
415 }
416 }
417 }
418
419 if ($usertoassign > 0 && $usertoassign !== $useroriginassign) {
420 $result = $object->add_contact($usertoassign, "SUPPORTTEC", 'internal', $notrigger = 0);
421 if ($result < 0) {
422 $error++;
423 setEventMessages($object->error, $object->errors, 'errors');
424 }
425 }
426 }
427
428 if (!$error) {
429 // Log action in ticket logs table
430 $object->fetch_user($usertoassign);
431
432 setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs');
433 header("Location: card.php?track_id=" . $object->track_id);
434 exit;
435 } else {
436 array_push($object->errors, $object->error);
437 }
438 $action = 'view';
439 }
440
441 // Action to add a message (private or not, with email or not).
442 // This may also send an email (concatenated with email_intro and email footer if checkbox was selected)
443 if ($action == 'add_message' && GETPOSTISSET('btn_add_message') && $permissiontoread) {
444 $ret = $object->newMessage($user, $action, GETPOSTINT('private_message'), 0);
445
446 if ($ret > 0) {
447 if (!empty($backtopage)) {
448 $url = $backtopage;
449 } else {
450 $url = 'card.php?track_id=' . urlencode($object->track_id);
451 }
452
453 header("Location: " . $url);
454 exit;
455 } else {
456 setEventMessages($object->error, $object->errors, 'errors');
457 $action = 'presend';
458 }
459 }
460
461 if (($action == "confirm_close" || $action == "confirm_abandon") && GETPOST('confirm', 'alpha') == 'yes' && $permissiontomanage) {
462 $object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha'));
463 if (GETPOSTISSET('contactid')) {
464 $object->context['contact_id'] = GETPOSTINT('contactid');
465 }
466
467 if ($object->close($user, ($action == "confirm_abandon" ? 1 : 0)) > 0) { // Test on pemrission already done
468 setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
469
470 $url = 'card.php?track_id=' . GETPOST('track_id', 'alpha');
471 header("Location: " . $url);
472 exit;
473 } else {
474 $action = '';
475 setEventMessages($object->error, $object->errors, 'errors');
476 }
477 }
478
479 if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) {
480 $object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha'));
481 if ($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) {
482 $object->context['contact_id'] = GETPOSTINT('contactid');
483
484 if ($object->close($user) > 0) {
485 setEventMessages('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>', null, 'mesgs');
486
487 $url = 'card.php?track_id=' . GETPOST('track_id', 'alpha');
488 header("Location: " . $url);
489 exit;
490 }
491 setEventMessages($object->error, $object->errors, 'errors');
492 $action = '';
493 } else {
494 setEventMessages($object->error, $object->errors, 'errors');
495 $action = '';
496 }
497 }
498
499 if ($action == 'confirm_clone' && GETPOST('confirm', 'alpha') == "yes" && $permissiontomanage) {
500 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
501 $newid = $object->createFromClone($user, $object->id);
502 if ($newid > 0) {
503 header("Location: " . DOL_URL_ROOT . "/ticket/card.php?id=".$newid);
504 exit;
505 } else {
506 setEventMessages($object->error, $object->errors, 'errors');
507 $action = '';
508 }
509 }
510 }
511
512 if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $permissiontodelete) {
513 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
514 if ($object->delete($user) > 0) {
515 setEventMessages('<div class="confirm">' . $langs->trans('TicketDeletedSuccess') . '</div>', null, 'mesgs');
516 header("Location: " . DOL_URL_ROOT . "/ticket/list.php");
517 exit;
518 } else {
519 $langs->load("errors");
520 $mesg = '<div class="error">' . $langs->trans($object->error) . '</div>';
521 $action = '';
522 }
523 }
524 }
525
526 // Set parent company
527 if ($action == 'set_thirdparty' && $permissiontoadd) {
528 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
529 $result = $object->setCustomer(GETPOSTINT('editcustomer'));
530 $url = $_SERVER["PHP_SELF"] . '?track_id=' . GETPOST('track_id', 'alpha');
531 header("Location: " . $url);
532 exit();
533 }
534 }
535
536 // Set progress status
537 if ($action == 'set_progression' && $permissiontoadd) {
538 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
539 $result = $object->setProgression(GETPOSTINT('progress'));
540
541 $url = 'card.php?track_id=' . $object->track_id;
542 header("Location: " . $url);
543 exit();
544 }
545 }
546
547 // Set categories
548 if ($action == 'set_categories' && $permissiontoadd) {
549 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
550 $result = $object->setCategories(GETPOST('categories', 'array'));
551
552 $url = 'card.php?track_id=' . $object->track_id;
553 header("Location: " . $url);
554 exit();
555 }
556 }
557
558 // Set Subject
559 if ($action == 'setsubject' && $permissiontoadd) {
560 if ($object->fetch(GETPOSTINT('id'))) {
561 if ($action == 'setsubject') { // Test on permission already done
562 $object->subject = GETPOST('subject', 'alphanohtml');
563 }
564
565 if ($action == 'setsubject' && empty($object->subject)) { // Test on permission already done
566 $error++;
567 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")), null, 'errors');
568 }
569
570 if (!$error) {
571 if (!$object->update($user) >= 0) {
572 $error++;
573 setEventMessages($object->error, $object->errors, 'errors');
574 }
575 }
576
577 header("Location: " . $_SERVER['PHP_SELF'] . "?track_id=" . $object->track_id);
578 exit;
579 }
580 }
581
582 if ($action == 'confirm_reopen' && $permissiontomanage && !GETPOST('cancel')) {
583 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
584 // prevent browser refresh from reopening ticket several times
585 if ($object->status == Ticket::STATUS_CLOSED || $object->status == Ticket::STATUS_CANCELED) {
586 if ($object->fk_user_assign != null) {
587 $res = $object->setStatut(Ticket::STATUS_ASSIGNED, null, '', $triggermodname);
588 } else {
589 $res = $object->setStatut(Ticket::STATUS_NOT_READ, null, '', $triggermodname);
590 }
591 if ($res) {
592 $url = 'card.php?track_id=' . $object->track_id;
593 header("Location: " . $url);
594 exit();
595 } else {
596 $error++;
597 setEventMessages($object->error, $object->errors, 'errors');
598 }
599 }
600 }
601 } elseif ($action == 'classin' && $permissiontoadd) {
602 // Categorisation dans projet
603 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
604 $object->setProject($projectid);
605 $url = 'card.php?track_id=' . $object->track_id;
606 header("Location: " . $url);
607 exit();
608 }
609 } elseif ($action == 'setcontract' && $permissiontoadd) {
610 // Categorisation dans contrat
611 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
612 $object->setContract(GETPOSTINT('contractid'));
613 $url = 'card.php?track_id=' . $object->track_id;
614 header("Location: " . $url);
615 exit();
616 }
617 } elseif ($action == "set_message" && $permissiontoadd) {
618 if (!GETPOST('cancel')) {
619 $object->fetch(0, '', GETPOST('track_id', 'alpha'));
620 //$oldvalue_message = $object->message;
621 $fieldtomodify = GETPOST('message_initial', 'restricthtml');
622
623 $object->message = $fieldtomodify;
624 $ret = $object->update($user);
625 if ($ret > 0) {
626 //include_once DOL_DOCUMENT_ROOT.'/core/class/utils_diff.class.php';
627 // output the result of comparing two files as plain text
628 //$log_action .= Diff::toString(Diff::compare(strip_tags($oldvalue_message), strip_tags($object->message)));
629
630 setEventMessages($langs->trans('TicketMessageSuccesfullyUpdated'), null, 'mesgs');
631 } else {
632 $error++;
633 setEventMessages($object->error, $object->errors, 'errors');
634 }
635 }
636
637 $action = 'view';
638 } elseif ($action == 'confirm_set_status' && $permissiontomanage && !GETPOST('cancel')) {
639 // Reopen ticket
640 if ($object->fetch(GETPOSTINT('id'), GETPOST('track_id', 'alpha')) >= 0) {
641 $new_status = GETPOSTINT('new_status');
642
643 $res = $object->setStatut($new_status, null, '', $triggermodname);
644 if ($res) {
645 if ($new_status != Ticket::STATUS_NOT_READ) {
646 $res = $object->setReadDate($user, 1); // Update date read if necessary, without trigger because we already run trigger in setStatut()
647 if ($res < 0) {
648 $error++;
649 setEventMessages($object->error, $object->errors, 'errors');
650 }
651 } else {
652 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket SET date_read = null WHERE rowid = ".((int) $object->id);
653 $resql = $db->query($sql);
654 if (!$resql) {
656 }
657 }
658 $url = 'card.php?track_id=' . $object->track_id;
659 header("Location: " . $url);
660 exit();
661 } else {
662 $error++;
663 setEventMessages($object->error, $object->errors, 'errors');
664 }
665 }
666 }
667
668 // Action to update an extrafield
669 if ($action == "update_extras" && $permissiontoeditextra) {
670 $object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha'));
671
672 $attribute_name = GETPOST('attribute', 'aZ09');
673
674 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
675 if ($ret < 0) {
676 $error++;
677 }
678
679 if (!$error) {
680 $result = $object->updateExtraField($attribute_name, $triggermodname);
681 if ($result < 0) {
682 setEventMessages($object->error, $object->errors, 'errors');
683 $error++;
684 }
685 }
686
687 if ($error) {
688 $action = 'edit_extras';
689 }
690 }
691
692 if ($action == "change_property" && GETPOST('btn_update_ticket_prop', 'alpha') && $permissiontoadd) {
693 $object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha'));
694
695 $object->type_code = GETPOST('update_value_type', 'aZ09');
696 $object->severity_code = GETPOST('update_value_severity', 'aZ09');
697 $object->category_code = GETPOST('update_value_category', 'aZ09');
698
699 $ret = $object->update($user);
700 if ($ret > 0) {
701 setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
702 } else {
703 $error++;
704 setEventMessages($object->error, $object->errors, 'errors');
705 }
706 $action = 'view';
707 }
708
709 // Actions when printing a doc from card
710 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
711
712 $permissiondellink = $permissiontoadd;
713 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
714
715 // Actions when printing a doc from card
716 include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
717
718 // Actions to build doc
719 include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
720
721 // Actions to send emails
722 $triggersendname = 'TICKET_SENTBYMAIL';
723 $paramname = 'id';
724 $autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
725 $trackid = 'tic' . $object->id;
726 include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
727
728 // Set $action to correct value for the case we used presend action to add a message
729 if (GETPOSTISSET('actionbis') && $action == 'presend') { // Test on permission not required here
730 $action = 'presend_addmessage';
731 }
732}
733
734
735/*
736 * View
737 */
738
739$userstat = new User($db);
740$form = new Form($db);
741$formfile = new FormFile($db);
742$formticket = new FormTicket($db);
743
744$help_url = 'EN:Module_Ticket|FR:DocumentationModuleTicket';
745
746$title = $actionobject->getTitle($action, $object);
747
748llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-ticket page-card');
749
750if ($action == 'create' || $action == 'presend') {
751 if (empty($permissiontoadd)) {
752 accessforbidden('NotEnoughPermissions', 0, 1);
753 }
754
755 $formticket = new FormTicket($db);
756
757 print load_fiche_titre($langs->trans('NewTicket'), '', 'ticket');
758
759 $formticket->trackid = ''; // TODO Use a unique key 'tic' to avoid conflict in upload file feature
760
761 if (GETPOST("mode", "aZ09") == 'init' && empty($_POST)) {
762 $formticket->clear_attached_files();
763 }
764
765 $formticket->withfromsocid = $socid ? $socid : $user->socid;
766 $formticket->withfromcontactid = $contactid ? $contactid : '';
767 $formticket->withtitletopic = 1;
768 $formticket->withnotifytiersatcreate = ($notifyTiers ? 1 : (getDolGlobalString('TICKET_CHECK_NOTIFY_THIRDPARTY_AT_CREATION') ? 1 : 0));
769 $formticket->withusercreate = 0;
770 $formticket->withref = 1;
771 $formticket->fk_user_create = $user->id;
772 $formticket->withfile = 2;
773 $formticket->withextrafields = 1;
774 $formticket->param = array('origin' => GETPOST('origin'), 'originid' => GETPOST('originid'));
775
776 $formticket->withcancel = 1;
777
778 // Init list of files
779 if (GETPOST("mode", "aZ09") == 'init') {
780 $formticket->clear_attached_files();
781 }
782
783 $formticket->showForm(1, 'create', 0, null, $action, $object);
784
785 print dol_get_fiche_end();
786} elseif ($action == 'edit' && $permissiontoadd && $object->status < Ticket::STATUS_CLOSED) {
787 if (empty($permissiontoadd)) {
788 accessforbidden('NotEnoughPermissions', 0, 1);
789 }
790
791 $formticket = new FormTicket($db);
792
793 $head = ticket_prepare_head($object);
794
795 print dol_get_fiche_head($head, 'tabTicket', $langs->trans('Ticket'), -1, 'ticket');
796
797 $formticket->trackid = 'tic'.$object->id;
798 $formticket->withfromsocid = $object->socid;
799 $formticket->withtitletopic = 1;
800 // $formticket->withnotifytiersatcreate = ($notifyTiers ? 1 : (getDolGlobalString('TICKET_CHECK_NOTIFY_THIRDPARTY_AT_CREATION') ? 1 : 0));
801 $formticket->withnotifytiersatcreate = 0;
802 $formticket->withusercreate = 0;
803 $formticket->withref = 1;
804 $formticket->fk_user_create = $user->id;
805 $formticket->withfile = 0;
806 $formticket->action = 'update';
807 $formticket->withextrafields = 1;
808 $formticket->param = array('origin' => GETPOST('origin'), 'originid' => GETPOST('originid'));
809
810 $formticket->withcancel = 1;
811
812 $formticket->showForm(0, 'edit', 0, null, $action, $object);
813
814 print dol_get_fiche_end();
815} elseif ($object->id) {
816 if (!empty($res) && $res > 0) {
817 // or for unauthorized internals users
818 if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$permissiontomanage) {
819 accessforbidden('', 0, 1);
820 }
821
822 $trackid = 'tic'.$object->id;
823
824 $formconfirm = '';
825
826 // Confirmation close
827 if ($action == 'close' && $permissiontomanage) {
828 $thirdparty_contacts = $object->getInfosTicketExternalContact(1);
829 $contacts_select = array(
830 '-2' => $langs->trans('TicketNotifyAllTiersAtClose'),
831 '-3' => $langs->trans('TicketNotNotifyTiersAtClose')
832 );
833 foreach ($thirdparty_contacts as $thirdparty_contact) {
834 $contacts_select[$thirdparty_contact['id']] = $thirdparty_contact['civility'] . ' ' . $thirdparty_contact['lastname'] . ' ' . $thirdparty_contact['firstname'];
835 }
836
837 // Default select all or no contact
838 $default = (getDolGlobalString('TICKET_NOTIFY_AT_CLOSING') ? '-2' : '-3');
839 $formquestion = array(
840 array(
841 'name' => 'contactid',
842 'type' => 'select',
843 'label' => $langs->trans('NotifyThirdpartyOnTicketClosing'),
844 'values' => $contacts_select,
845 'default' => $default
846 ),
847 );
848
849 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_close", $formquestion, '', 1);
850 }
851 // Confirmation abandon
852 if ($action == 'abandon' && $permissiontomanage) {
853 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("AbandonTicket"), $langs->trans("ConfirmAbandonTicket"), "confirm_abandon", '', '', 1);
854 }
855 // Confirmation delete
856 if ($action == 'delete' && $permissiontodelete) {
857 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("Delete"), $langs->trans("ConfirmDeleteTicket"), "confirm_delete_ticket", '', '', 1);
858 }
859 // Confirm reopen
860 if ($action == 'reopen' && $permissiontomanage) {
861 $formconfirm = $form->formconfirm($url_page_current.'?track_id='.$object->track_id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenTicket'), 'confirm_reopen', '', '', 1);
862 }
863 // Confirmation status change
864 if ($action == 'set_status' && $permissiontomanage) {
865 $new_status = GETPOSTINT('new_status');
866 //var_dump($url_page_current . "?track_id=" . $object->track_id);
867 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id."&new_status=".$new_status, $langs->trans("TicketChangeStatus"), $langs->trans("TicketConfirmChangeStatus", $langs->transnoentities($object->labelStatusShort[$new_status])), "confirm_set_status", '', '', 1);
868 }
869 // Clone confirmation
870 if ($action == 'clone') {
871 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', '', 'yes', 1);
872 }
873
874 // Call Hook formConfirm
875 $parameters = array('formConfirm' => $formconfirm);
876 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
877 if (empty($reshook)) {
878 $formconfirm .= $hookmanager->resPrint;
879 } elseif ($reshook > 0) {
880 $formconfirm = $hookmanager->resPrint;
881 }
882
883 // Print form confirm
884 print $formconfirm;
885
886 // project info
887 if ($projectid > 0) {
888 $projectstat = new Project($db);
889 if ($projectstat->fetch($projectid) > 0) {
890 $projectstat->fetch_thirdparty();
891
892 // To verify role of users
893 //$userAccess = $object->restrictedProjectArea($user,'read');
894 $userWrite = $projectstat->restrictedProjectArea($user, 'write');
895 //$userDelete = $object->restrictedProjectArea($user,'delete');
896 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
897
898 $head = project_prepare_head($projectstat);
899
900 print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), 0, ($projectstat->public ? 'projectpub' : 'project'));
901
902 print '<table class="border centpercent">';
903
904 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
905
906 // Ref
907 print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="3">';
908 // Define a complementary filter for search of next/prev ref.
909 if (!$user->hasRight('projet', 'all', 'lire')) {
910 $objectsListId = $projectstat->getProjectsAuthorizedForUser($user, $mine, 0);
911 $projectstat->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
912 }
913 print $form->showrefnav($projectstat, 'ref', $linkback, 1, 'ref', 'ref', '');
914 print '</td></tr>';
915
916 // Label
917 print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projectstat->title.'</td></tr>';
918
919 // Customer
920 print "<tr><td>".$langs->trans("ThirdParty")."</td>";
921 print '<td colspan="3">';
922 if ($projectstat->thirdparty->id > 0) {
923 print $projectstat->thirdparty->getNomUrl(1);
924 } else {
925 print '&nbsp;';
926 }
927
928 print '</td></tr>';
929
930 // Visibility
931 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
932 if ($projectstat->public) {
933 print $langs->trans('SharedProject');
934 } else {
935 print $langs->trans('PrivateProject');
936 }
937
938 print '</td></tr>';
939
940 // Status
941 print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projectstat->getLibStatut(4).'</td></tr>';
942
943 print "</table>";
944
945 print dol_get_fiche_end();
946 } else {
947 print "ErrorRecordNotFound";
948 }
949 } elseif ($socid > 0) {
950 $object->fetch_thirdparty();
951 $head = societe_prepare_head($object->thirdparty);
952
953 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
954
955 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
956
957 print dol_get_fiche_end();
958 }
959
960 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
961 $object->next_prev_filter = "te.fk_user_assign:=:".((int) $user->id);
962 } elseif ($user->socid > 0) {
963 $object->next_prev_filter = "te.fk_soc:=:".((int) $user->socid);
964 }
965
966 $head = ticket_prepare_head($object);
967
968 print dol_get_fiche_head($head, 'tabTicket', $langs->trans("Ticket"), -1, 'ticket', 0, '', '', 0, '', 1);
969
970 $morehtmlref = '<div class="refidno">';
971
972 if ($permissiontoadd && !$user->socid) {
973 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editsubject&token='.newToken().'&track_id='.urlencode($object->track_id).'">'.img_edit($langs->transnoentitiesnoconv('SetTitle'), 0).'</a> ';
974 }
975 if ($action != 'editsubject') {
976 $morehtmlref .= '<span class="smallonsmartphone">'.dolPrintLabel($object->subject).'</span>';
977 } else {
978 $morehtmlref .= '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
979 $morehtmlref .= '<input type="hidden" name="action" value="setsubject">';
980 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
981 $morehtmlref .= '<input type="hidden" name="id" value="'.$object->id.'">';
982 $morehtmlref .= '<input type="text" class="minwidth300" id="subject" name="subject" value="'.$object->subject.'" autofocus="" spellcheck="false">';
983 $morehtmlref .= '<input type="submit" class="smallpaddingimp button valignmiddle" name="modify" value="'.$langs->trans("Modify").'">';
984 $morehtmlref .= '<input type="submit" class="smallpaddingimp button button-cancel valignmiddle" name="cancel" value="'.$langs->trans("Cancel").'">';
985 $morehtmlref .= '</form>';
986 }
987
988 // Author
989 $createdbyshown = 0;
990 if ($object->fk_user_create > 0) {
991 $morehtmlref .= '<br>';
992 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
993
994 $fuser = new User($db);
995 $fuser->fetch($object->fk_user_create);
996 $morehtmlref .= $fuser->getNomUrl(-4);
997 $createdbyshown++;
998 }
999
1000 $createdfrompublicticket = 0;
1001 $createdfromemailcollector = 0;
1002 if (!empty($object->origin_email) && (empty($object->email_msgid) || preg_match('/dolibarr\-tic\d+/', $object->email_msgid))) {
1003 // If ticket create from public interface - TODO Add a more robust test to know if created by public interface
1004 $createdfrompublicticket = 1;
1005 } elseif (!empty($object->email_msgid)) {
1006 // If ticket create by emailcollector - TODO Add a more robust test to know if created by email collector (using import key ?)
1007 $createdfromemailcollector = 1;
1008 }
1009
1010 //var_dump($object);
1011 $htmltooltip = '';
1012 if ($createdfrompublicticket) {
1013 $htmltooltip .= $langs->trans("OriginEmail").': '.$object->origin_email;
1014 $htmltooltip .= '<br>'.$langs->trans("IP").': '.dol_print_ip($object->ip);
1015 $morehtmlref .= ($createdbyshown ? ' - ' : '<br>');
1016 //$morehtmlref .= ($createdbyshown ? '' : '<span class="opacitymedium">'.$langs->trans("CreatedBy").' </span> ');
1017 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
1018 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">- '.$form->textwithpicto($langs->trans("CreatedByPublicPortal"), $htmltooltip, 1, 'help', '', 0, 3, 'tooltipcreatedbyportal').'</small>';
1019 } elseif ($createdfromemailcollector) {
1020 $langs->load("mails");
1021
1022 $htmltooltip .= '<b>'.$langs->trans("EmailMsgID").':</b> '.$object->email_msgid;
1023 $htmltooltip .= '<br><b>'.$langs->trans("EmailDate").':</b> '.dol_print_date($object->email_date, 'dayhour');
1024 $htmltooltip .= '<br><b>'.$langs->trans("MailFrom").':</b> '.$object->origin_email;
1025 $htmltooltip .= '<br><b>'.$langs->trans("MailReply").':</b> '.$object->origin_replyto;
1026 $htmltooltip .= '<br><b>'.$langs->trans("MailReferences").':</b> '.$object->origin_references;
1027 $morehtmlref .= ($createdbyshown ? ' - ' : '<br>');
1028 //$morehtmlref .= ($createdbyshown ? '' : '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ');
1029 $morehtmlref .= img_picto('From', 'email', 'class="paddingrightonly"');
1030 $morehtmlref .= dol_escape_htmltag($object->origin_email);
1031 if ($object->origin_replyto) {
1032 $morehtmlref .= ' - '.img_picto('ReplyTo', 'email', 'class="paddingrightonly"');
1033 $morehtmlref .= dol_escape_htmltag($object->origin_replyto);
1034 }
1035 $morehtmlref .= ' <small class="hideonsmartphone opacitymedium">- '.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $htmltooltip, 1, 'help', '', 0, 3, 'tooltipcreatedbyemailcollector').'</small>';
1036 }
1037
1038 $permissiontoedit = $object->status < 8 && !$user->socid && $permissiontoadd;
1039 //$permissiontoedit = 0;
1040
1041 // Thirdparty
1042 if (isModEnabled("societe")) {
1043 $morehtmlref .= '<br>';
1044 if ($action != 'editcustomer' && $permissiontoedit) {
1045 $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
1046 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
1047 }
1048 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, (string) $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
1049 if (!empty($object->socid)) {
1050 $morehtmlref .= ' - <a href="'.DOL_URL_ROOT.'/ticket/list.php?socid='.$object->socid.'&sortfield=t.datec&sortorder=desc'.(getDolGlobalBool('TICKET_CLIENT_OTHER_TICKET_ONLY_OPEN') ? '&search_fk_statut[]=openall' : '').'">'.img_picto($langs->trans("Tickets"), 'ticket', 'class="pictofixedwidth paddingright"').$langs->trans("TicketHistory").'</a>';
1051 }
1052 }
1053
1054 // Project
1055 if (isModEnabled('project')) {
1056 $langs->load("projects");
1057 $morehtmlref .= '<br>';
1058 if ($permissiontoedit) {
1059 $object->fetchProject();
1060 $morehtmlref .= img_picto($langs->trans("Project"), 'project'.((is_object($object->project) && $object->project->public) ? 'pub' : ''), 'class="pictofixedwidth"');
1061 if ($action != 'classify') {
1062 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1063 }
1064 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1065 } else {
1066 if (!empty($object->fk_project)) {
1067 $object->fetchProject();
1068 $morehtmlref .= $object->project->getNomUrl(1);
1069 if ($object->project->title) {
1070 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($object->project->title).'</span>';
1071 }
1072 }
1073 }
1074 }
1075
1076 // Contract
1077 if (getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
1078 // Deprecated. Duplicate feature. Ticket can already be linked to contract with the generic "Link to" feature.
1079 if (isModEnabled('contract')) {
1080 // This feature hang the application on large list of contracts, because the select component is not complete: it does not work like select of thirdparty or product to support large lists
1081 // So we add a hidden option to avoid to have it used and the application locked, until the select_contract is fixed.
1082 if (getDolGlobalString("CONTRACT_CAN_USE_THE_BUGGED_SELECT_COMPONENT")) {
1083 $langs->load('contracts');
1084 $morehtmlref .= '<br>';
1085 if ($permissiontoedit) {
1086 $morehtmlref .= img_picto($langs->trans("Contract"), 'contract', 'class="pictofixedwidth"');
1087 if ($action == 'edit_contrat') {
1088 $formcontract = new FormContract($db);
1089 $morehtmlref .= $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contract, 'contratid', 0, 1, 1, 1);
1090 } else {
1091 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_contrat&token='.newToken().'&id='.$object->id.'">';
1092 $morehtmlref .= img_edit($langs->trans('SetContract'));
1093 $morehtmlref .= '</a>';
1094 }
1095 } else {
1096 if (!empty($object->fk_contract)) {
1097 $contratstatic = new Contrat($db);
1098 $contratstatic->fetch($object->fk_contract);
1099 //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1100 $morehtmlref .= $contratstatic->getNomUrl(0, 0, 1);
1101 }
1102 }
1103 }
1104 }
1105 }
1106
1107 $morehtmlref .= '</div>';
1108
1109 $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php?restore_lastsearch_values=1"><strong>'.$langs->trans("BackToList").'</strong></a> ';
1110
1111 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref);
1112
1113 print '<div class="fichecenter">';
1114 print '<div class="fichehalfleft">';
1115 print '<div class="underbanner clearboth"></div>';
1116
1117 print '<table class="border tableforfield centpercent">';
1118
1119 // Subject
1120 /*
1121 print '<tr><td>';
1122 print $form->editfieldkey("Subject", 'subject', $object->subject, $object, $permissiontoadd && !$user->socid, 'string');
1123 print '</td><td>';
1124 print $form->editfieldval("Subject", 'subject', $object->subject, $object, $permissiontoadd && !$user->socid, 'string');
1125 print '</td></tr>';
1126 */
1127
1128 // Creation date
1129 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
1130 print dol_print_date($object->datec, 'dayhour', 'tzuser');
1131 print '<span class="opacitymedium"><span class="small"> - '.$langs->trans("TimeElapsedSince").': <b><i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->datec, 60)).'</i></b></span></span>';
1132 print '</td></tr>';
1133
1134 // Read date
1135 print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
1136 if (!empty($object->date_read)) {
1137 print dol_print_date($object->date_read, 'dayhour', 'tzuser');
1138 print '<span class="opacitymedium"><span class="small"> - '.$langs->trans("TimeElapsedSince").': ';
1139 //print '<b><i>'.convertSecondToTime(roundUpToNextMultiple($object->date_read - $object->datec, 60)).'</i></b>';
1140 //print ' / ';
1141 print '<b><i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->date_read, 60)).'</i></b></span></span>';
1142 }
1143 print '</td></tr>';
1144
1145 // Close date
1146 print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
1147 if (!empty($object->date_close)) {
1148 print dol_print_date($object->date_close, 'dayhour', 'tzuser');
1149 }
1150 print '</td></tr>';
1151
1152 // User assigned
1153 print '<tr><td>';
1154 print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
1155 print $langs->trans("AssignedTo");
1156 if (isset($object->status) && $object->status < $object::STATUS_CLOSED && GETPOST('set', 'alpha') != "assign_ticket" && $permissiontomanage) {
1157 print '</td><td class="right"><a class="editfielda" href="'.$url_page_current.'?track_id='.urlencode($object->track_id).'&set=assign_ticket">'.img_edit($langs->trans('Modify')).'</a>';
1158 }
1159 print '</td></tr></table>';
1160 print '</td><td>';
1161 if (GETPOST('set', 'alpha') != "assign_ticket" && $object->fk_user_assign > 0) {
1162 $userstat->fetch($object->fk_user_assign);
1163 print $userstat->getNomUrl(-1);
1164 }
1165
1166 // Show user list to assignate one if status is "read"
1167 if (GETPOST('set', 'alpha') == "assign_ticket" && $object->status < 8 && !$user->socid && $permissiontomanage) {
1168 print '<form method="post" name="ticket" enctype="multipart/form-data" action="'.$url_page_current.'">';
1169 print '<input type="hidden" name="token" value="'.newToken().'">';
1170 print '<input type="hidden" name="action" value="assign_user">';
1171 print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
1172 print $form->select_dolusers(empty($object->fk_user_assign) ? $user->id : $object->fk_user_assign, 'fk_user_assign', 1, null, 0, '', '', '', 0, 0, '', 0, '', '', 1);
1173 print ' <input type="submit" class="button smallpaddingimp" name="btn_assign_user" value="'.$langs->trans("Validate").'" />';
1174 print ' <input type="submit" class="button smallpaddingimp" name="btn_cancel" value="'.$langs->trans("Cancel").'" />';
1175 print '</form>';
1176 }
1177 print '</td></tr>';
1178
1179 // Progression
1180 print '<tr><td>';
1181 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
1182 print $langs->trans('Progression').'</td><td class="left">';
1183 print '</td>';
1184 if ($permissiontoadd && $action != 'progression' && isset($object->status) && $object->status < $object::STATUS_CLOSED && !$user->socid) {
1185 print '<td class="right"><a class="editfielda" href="'.$url_page_current.'?action=progression&token='.newToken().'&track_id='.urlencode($object->track_id).'">'.img_edit($langs->trans('Modify')).'</a></td>';
1186 }
1187 print '</tr></table>';
1188 print '</td><td>';
1189 if ($permissiontoadd && $action == 'progression') {
1190 print '<form action="'.$url_page_current.'" method="post">';
1191 print '<input type="hidden" name="token" value="'.newToken().'">';
1192 print '<input type="hidden" name="track_id" value="'.$track_id.'">';
1193 print '<input type="hidden" name="action" value="set_progression">';
1194 print '<input type="text" class="flat width75" name="progress" value="'.$object->progress.'">';
1195 print ' <input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
1196 print '</form>';
1197 } else {
1198 print($object->progress > 0 ? $object->progress : '0').'%';
1199 }
1200 print '</td>';
1201 print '</tr>';
1202
1203 // Timing (Duration sum of linked fichinter)
1204 if (isModEnabled('intervention')) {
1205 $object->fetchObjectLinked();
1206 $num = count($object->linkedObjects);
1207 $timing = 0;
1208 $foundinter = 0;
1209 if ($num) {
1210 foreach ($object->linkedObjects as $objecttype => $objects) {
1211 if ($objecttype == "fichinter") {
1212 '@phan-var-force Fichinter[] $objects';
1213 foreach ($objects as $fichinter) {
1214 $foundinter++;
1216 $timing += $fichinter->duration;
1217 }
1218 }
1219 }
1220 }
1221 print '<tr><td>';
1222 print $form->textwithpicto($langs->trans("TicketDurationAuto"), $langs->trans("TicketDurationAutoInfos"), 1);
1223 print '</td><td>';
1224 print $foundinter ? convertSecondToTime($timing, 'all', getDolGlobalInt('MAIN_DURATION_OF_WORKDAY')) : '';
1225 print '</td></tr>';
1226 }
1227
1228 // Other attributes
1229 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1230
1231 print '</table>';
1232
1233
1234 // End of left column and beginning of right column
1235 print '</div><div class="fichehalfright">';
1236
1237
1238 print '<form method="post" name="formticketproperties" action="'.$url_page_current.'">';
1239 print '<input type="hidden" name="token" value="'.newToken().'">';
1240 print '<input type="hidden" name="action" value="change_property">';
1241 print '<input type="hidden" name="track_id" value="'.$track_id.'">';
1242 print '<input type="hidden" name="trackid" value="'.$trackid.'">';
1243
1244 // Classification of ticket
1245 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1246 print '<table class="border tableforfield centpercent margintable bordertopimp">';
1247 print '<tr class="liste_titre">';
1248 print '<td class="valignmiddle titlefield">';
1249 print '<table class="nobordernopadding centpercent"><tr><td class="none" style="border-bottom: none !important;">';
1250 print $langs->trans('TicketProperties');
1251 if (GETPOST('set', 'alpha') != 'properties' && isset($object->status) && ($object->status < $object::STATUS_NEED_MORE_INFO || !getDolGlobalInt('TICKET_DISALLOW_CLASSIFICATION_MODIFICATION_EVEN_IF_CLOSED')) && $permissiontoadd) {
1252 print '</td><td class="right" style="border-bottom: none !important;"><a class="editfielda" href="card.php?track_id='.$object->track_id.'&set=properties">'.img_edit($langs->trans('Modify')).'</a>';
1253 }
1254 print '</td></tr></table>';
1255 print '</td>';
1256 print '<td>';
1257 if (GETPOST('set', 'alpha') == 'properties' && $permissiontoadd) {
1258 print '<input type="submit" class="button smallpaddingimp" name="btn_update_ticket_prop" value="'.$langs->trans("Modify").'" />';
1259 }
1260 print '</td>';
1261 print '</tr>';
1262
1263 if (GETPOST('set', 'alpha') == 'properties' && $permissiontoadd) {
1264 print '<tr>';
1265 // Type
1266 print '<td class="titlefield">';
1267 print $langs->trans('Type');
1268 print '</td><td>';
1269 $formticket->selectTypesTickets($object->type_code, 'update_value_type', '', 2);
1270 print '</td>';
1271 print '</tr>';
1272 // Group
1273 print '<tr>';
1274 print '<td>';
1275 print $langs->trans('TicketCategory');
1276 print '</td><td>';
1277 $formticket->selectGroupTickets($object->category_code, 'update_value_category', '', 2, 0, 0, 0, 'maxwidth500 widthcentpercentminusxx');
1278 print '</td>';
1279 print '</tr>';
1280 // Severity
1281 print '<tr>';
1282 print '<td>';
1283 print $langs->trans('TicketSeverity');
1284 print '</td><td>';
1285 $formticket->selectSeveritiesTickets($object->severity_code, 'update_value_severity', '', 2);
1286 print '</td>';
1287 print '</tr>';
1288 } else {
1289 // Type
1290 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
1291 if (!empty($object->type_code)) {
1292 print $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
1293 }
1294 print '</td></tr>';
1295 // Group
1296 $s = '';
1297 if (!empty($object->category_code)) {
1298 $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
1299 }
1300 print '<tr><td>'.$langs->trans("TicketCategory").'</td><td class="tdoverflowmax200" title="'.dol_escape_htmltag($s).'">';
1301 print dol_escape_htmltag($s);
1302 print '</td></tr>';
1303 // Severity
1304 print '<tr><td>'.$langs->trans("TicketSeverity").'</td><td>';
1305 if (!empty($object->severity_code)) {
1306 print $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
1307 }
1308 print '</td></tr>';
1309 }
1310 print '</table>'; // End table actions
1311 print '</div>';
1312
1313 print '</form>';
1314
1315 // Tags/Categories
1316 if (isModEnabled('category')) {
1317 print '<!-- tag/categories -->'."\n";
1318 print '<table class="border centpercent tableforfield">';
1319 print '<tr>';
1320 print '<td class="valignmiddle titlefield">';
1321 print '<table class="nobordernopadding centpercent"><tr><td class="none">';
1322 print $langs->trans("Categories");
1323 if ($permissiontoadd && !in_array($object->status, [Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED]) && $action != 'categories' && !$user->socid) {
1324 print '</td><td class="right"><a class="editfielda" href="'.$url_page_current.'?action=categories&token='.newToken().'&track_id='.urlencode($object->track_id).'">'.img_edit($langs->trans('Modify')).'</a>';
1325 }
1326 print '</td>';
1327 print '</table>';
1328 print '</td>';
1329
1330 if ($permissiontoadd && $action == 'categories') {
1331 print '<td colspan="3">';
1332 print '<form action="'.$url_page_current.'" method="POST">';
1333 print '<input type="hidden" name="token" value="'.newToken().'">';
1334 print '<input type="hidden" name="track_id" value="'.$track_id.'">';
1335 print '<input type="hidden" name="action" value="set_categories">';
1336 print $form->selectCategories(Categorie::TYPE_TICKET, 'categories', $object);
1337 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Save').'">';
1338 print '</form>';
1339 print "</td>";
1340 } else {
1341 print '<td colspan="3">';
1342 print $form->showCategories($object->id, Categorie::TYPE_TICKET, 1);
1343 print "</td></tr>";
1344 }
1345
1346 print '</table>';
1347 }
1348
1349 // View Original message
1350 $actionobject->viewTicketOriginalMessage($user, $action, $object);
1351
1352
1353 // Display navbar with links to change ticket status
1354 print '<!-- navbar with status -->';
1355 if (!$user->socid && $permissiontomanage && isset($object->status) && $object->status < $object::STATUS_CLOSED) {
1356 $actionobject->viewStatusActions($object);
1357 }
1358
1359
1360 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1361 print load_fiche_titre($langs->trans('Contacts'), '', 'title_companies.png');
1362
1363 print '<div class="div-table-responsive-no-min">';
1364 print '<div class="tagtable centpercent noborder allwidth">';
1365
1366 print '<div class="tagtr liste_titre">';
1367 print '<div class="tagtd">'.$langs->trans("Source").'</div>
1368 <div class="tagtd">' . $langs->trans("Company").'</div>
1369 <div class="tagtd">' . $langs->trans("Contacts").'</div>
1370 <div class="tagtd">' . $langs->trans("ContactType").'</div>
1371 <div class="tagtd">' . $langs->trans("Phone").'</div>
1372 <div class="tagtd center">' . $langs->trans("Status").'</div>';
1373 print '</div><!-- tagtr -->';
1374
1375 // Contact list
1376 $companystatic = new Societe($db);
1377 $contactstatic = new Contact($db);
1378 $userstatic = new User($db);
1379 $var = false;
1380 foreach (array('internal', 'external') as $source) {
1381 $tmpobject = $object;
1382 $tab = $tmpobject->listeContact(-1, $source);
1383 // '@phan-var-force array<array{source:string,id:int,rowid:int,email:string,civility:string,firstname:string,lastname:string,labeltype:string,libelle:string,socid:int,code:string,status:int,statuscontact:int,fk_c_typecontact:string,phone:string,phone_mobile:string,phone_perso?:string,nom:string}> $tab';
1384 $num = is_array($tab) ? count($tab) : 0;
1385 $i = 0;
1386 foreach (array_keys($tab) as $i) {
1387 $tab_i = &$tab[$i];
1388 $var = !$var;
1389 print '<div class="tagtr '.($var ? 'pair' : 'impair').'">';
1390
1391 print '<div class="tagtd left">';
1392 if ($tab_i['source'] == 'internal') {
1393 echo $langs->trans("User");
1394 }
1395
1396 if ($tab_i['source'] == 'external') {
1397 echo $langs->trans("ThirdPartyContact");
1398 }
1399
1400 print '</div>';
1401 print '<div class="tagtd left">';
1402
1403 if ($tab_i['socid'] > 0) {
1404 $companystatic->fetch($tab_i['socid']);
1405 echo $companystatic->getNomUrl(-1);
1406 }
1407 if ($tab_i['socid'] < 0) {
1408 echo getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
1409 }
1410 if (!$tab_i['socid']) {
1411 echo '&nbsp;';
1412 }
1413 print '</div>';
1414
1415 print '<div class="tagtd">';
1416 if ($tab_i['source'] == 'internal') {
1417 if ($userstatic->fetch($tab_i['id'])) {
1418 print $userstatic->getNomUrl(-1);
1419 }
1420 }
1421 if ($tab_i['source'] == 'external') {
1422 if ($contactstatic->fetch($tab_i['id'])) {
1423 print $contactstatic->getNomUrl(-1);
1424 }
1425 }
1426 print ' </div>
1427 <div class="tagtd">' . $tab_i['libelle'].'</div>';
1428
1429 print '<div class="tagtd">';
1430
1431 print dol_print_phone($tab_i['phone'], '', 0, 0, 'AC_TEL').'<br>';
1432
1433 if (array_key_exists('phone_perso', $tab_i) && !empty($tab_i['phone_perso'])) {
1434 //print img_picto($langs->trans('PhonePerso'),'object_phoning.png','',0,0,0).' ';
1435 print '<br>'.dol_print_phone((string) $tab_i['phone_perso'], '', 0, 0, 'AC_TEL').'<br>';
1436 }
1437 if (!empty($tab_i['phone_mobile'])) {
1438 //print img_picto($langs->trans('PhoneMobile'),'object_phoning.png','',0,0,0).' ';
1439 print dol_print_phone($tab_i['phone_mobile'], '', 0, 0, 'AC_TEL').'<br>';
1440 }
1441 print '</div>';
1442
1443 print '<div class="tagtd center">';
1444 if ($object->status >= 0) {
1445 echo '<a href="contact.php?track_id='.$object->track_id.'&amp;action=swapstatut&amp;token='.newToken().'&amp;ligne='.$tab_i['rowid'].'">';
1446 }
1447
1448 if ($tab_i['source'] == 'internal') {
1449 $userstatic->id = $tab_i['id'];
1450 $userstatic->lastname = $tab_i['lastname'];
1451 $userstatic->firstname = $tab_i['firstname'];
1452 echo $userstatic->LibStatut($tab_i['statuscontact'], 3);
1453 }
1454 if ($tab_i['source'] == 'external') {
1455 $contactstatic->id = $tab_i['id'];
1456 $contactstatic->lastname = $tab_i['lastname'];
1457 $contactstatic->firstname = $tab_i['firstname'];
1458 echo $contactstatic->LibStatut($tab_i['statuscontact'], 3);
1459 }
1460 if ($object->status >= 0) {
1461 echo '</a>';
1462 }
1463
1464 print '</div>';
1465
1466 print '</div><!-- tagtr -->';
1467
1468 $i++;
1469 }
1470 }
1471
1472 print '</div><!-- contact list -->';
1473 print '</div>';
1474 }
1475
1476 print '</div></div>';
1477 print '<div class="clearboth"></div>';
1478
1479 print dol_get_fiche_end();
1480
1481
1482 // Buttons for actions
1483 if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'editline') {
1484 print '<div class="tabsAction">'."\n";
1485 $parameters = array();
1486 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1487 if ($reshook < 0) {
1488 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1489 }
1490
1491 if (empty($reshook)) {
1492 // Email
1493 if (isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") {
1494 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?action=presend_addmessage&send_email=1&private_message=0&mode=init&token='.newToken().'&track_id='.$object->track_id.'#formmailbeforetitle', '');
1495 }
1496
1497 // Show link to add a message (if read and not closed)
1498 if (isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") {
1499 print dolGetButtonAction('', $langs->trans('TicketAddPrivateMessage'), 'default', $_SERVER["PHP_SELF"].'?action=presend_addmessage&mode=init&token='.newToken().'&track_id='.$object->track_id.'#formmailbeforetitle', '');
1500 }
1501
1502 // Link to create an intervention
1503 // socid is needed otherwise fichinter ask it and forgot origin after form submit :\
1504 if (!$object->fk_soc && $user->hasRight("ficheinter", "creer")) {
1505 print dolGetButtonAction($langs->trans('UnableToCreateInterIfNoSocid'), $langs->trans('TicketAddIntervention'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
1506 }
1507 if ($object->fk_soc > 0 && isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ficheinter', 'creer')) {
1508 print dolGetButtonAction('', $langs->trans('TicketAddIntervention'), 'default', DOL_URL_ROOT.'/fichinter/card.php?action=create&token='.newToken().'&socid='. $object->fk_soc.'&origin=ticket_ticket&originid='. $object->id, '');
1509 }
1510
1511 // Close ticket if status is read
1512 if (isset($object->status) && $object->status >= 0 && $object->status < Ticket::STATUS_CLOSED && $permissiontomanage) {
1513 print dolGetButtonAction('', $langs->trans('CloseTicket'), 'default', $_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&track_id='.$object->track_id, '');
1514 }
1515
1516 // Abandon ticket if status is read
1517 if (isset($object->status) && $object->status > 0 && $object->status < Ticket::STATUS_CLOSED && $permissiontomanage) {
1518 print dolGetButtonAction('', $langs->trans('AbandonTicket'), 'default', $_SERVER["PHP_SELF"].'?action=abandon&token='.newToken().'&track_id='.$object->track_id, '');
1519 }
1520
1521 // Re-open ticket
1522 if ($permissiontomanage && !$user->socid && (isset($object->status) && ($object->status == Ticket::STATUS_CLOSED || $object->status == Ticket::STATUS_CANCELED)) && !$user->socid) {
1523 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&track_id='.$object->track_id, '');
1524 }
1525
1526 // Edit ticket
1527 if ($permissiontoedit) {
1528 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoedit);
1529 }
1530
1531 // Clone
1532 if ($permissiontoadd) {
1533 print dolGetButtonAction('', $langs->trans('ToClone'), 'clone', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken(), '', $permissiontoadd);
1534 }
1535
1536 // Delete ticket
1537 if ($permissiontodelete && !$user->socid) {
1538 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&track_id='.$object->track_id, '');
1539 }
1540 }
1541 print '</div>'."\n";
1542 }
1543
1544 // Select mail models is same action as presend
1545 if (GETPOST('modelselected')) {
1546 $action = 'presend';
1547 }
1548 // Set $action to correct value for the case we used presend action to add a message
1549 if (GETPOSTISSET('actionbis') && $action == 'presend') {
1550 $action = 'presend_addmessage';
1551 }
1552
1553 // add a message
1554 if ($action == 'presend' || $action == 'presend_addmessage') {
1555 if ($object->fk_soc > 0) {
1556 $object->fetch_thirdparty();
1557 }
1558
1559 $outputlangs = $langs;
1560 $newlang = '';
1561 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1562 $newlang = GETPOST('lang_id', 'aZ09');
1563 } elseif (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && is_object($object->thirdparty)) {
1564 $newlang = $object->thirdparty->default_lang;
1565 }
1566 if (!empty($newlang)) {
1567 $outputlangs = new Translate("", $conf);
1568 $outputlangs->setDefaultLang($newlang);
1569 }
1570
1571 $arrayoffamiliestoexclude = array('objectamount');
1572
1573 $action = 'add_message'; // action to use to post the message
1574 $modelmail = 'ticket_send';
1575
1576 // Substitution array
1577 $morehtmlright = '';
1578 //$help = "";
1579 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude, $object);
1580 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1581 //$morehtmlright .= $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("TicketMessageSubstitutionReplacedByGenericValues").'</span>', $help, 1, 'helpclickable', '', 0, 3, 'helpsubstitution');
1582
1583 print '<div>';
1584
1585 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1586
1587 print load_fiche_titre($langs->trans('TicketAddMessage'), $morehtmlright, 'fa-comment-dots');
1588
1589 print '<hr>';
1590
1591 $formticket = new FormTicket($db);
1592
1593 $formticket->action = $action;
1594 $formticket->track_id = $object->track_id;
1595 $formticket->ref = $object->ref;
1596 $formticket->id = $object->id;
1597 $formticket->trackid = 'tic'.$object->id;
1598
1599 $formticket->withfile = 2;
1600 $formticket->withcancel = 1;
1601 $formticket->param = array('fk_user_create' => $user->id);
1602 $formticket->param['langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
1603
1604 // Table of additional post parameters
1605 $formticket->param['models'] = $modelmail;
1606 $formticket->param['models_id'] = GETPOSTINT('modelmailselected');
1607 //$formticket->param['socid']=$object->fk_soc;
1608 $formticket->param['returnurl'] = $_SERVER["PHP_SELF"].'?track_id='.urldecode($object->track_id);
1609
1610 $formticket->withsubstit = 1;
1611 $formticket->substit = $substitutionarray;
1612 $formticket->backtopage = $backtopage;
1613
1614 $formticket->withtitletopic = 1;
1615
1616 $formticket->showMessageForm('100%', 0);
1617
1618 print '</div>';
1619 }
1620
1621 // Show messages on card (Note: this is a duplicate of the view Events/Agenda but on the main tab)
1622 if (getDolGlobalString('TICKET_SHOW_MESSAGES_ON_CARD')) {
1623 $param = '&id='.$object->id;
1624 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1625 $param .= '&contextpage='.$contextpage;
1626 }
1627 if ($limit > 0 && $limit != $conf->liste_limit) {
1628 $param .= '&limit='.$limit;
1629 }
1630 if ($actioncode) {
1631 $param .= '&actioncode='.urlencode($actioncode);
1632 }
1633 if ($search_agenda_label) {
1634 $param .= '&search_agenda_label='.urlencode($search_agenda_label);
1635 }
1636
1637 $morehtmlright = '';
1638
1639 $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
1640 $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
1641
1642 // Show link to add a message (if read and not closed)
1643 $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage" && $action != "add_message";
1644 $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init';
1645 $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', (int) $btnstatus);
1646
1647 // Show link to add event (if read and not closed)
1648 $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage" && $action != "add_message";
1649 $url = dol_buildpath('/comm/action/card.php', 1).'?action=create&datep='.date('YmdHi').'&origin=ticket&originid='.$object->id.'&projectid='.$object->fk_project.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id);
1650 $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', (int) $btnstatus);
1651
1652 print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
1653
1654 // List of all actions
1655 $filters = array();
1656 $filters['search_agenda_label'] = $search_agenda_label;
1657 $filters['search_rowid'] = $search_rowid;
1658
1659 show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
1660 }
1661
1662 if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'add_message') {
1663 print '<div class="fichecenter"><div class="fichehalfleft">';
1664 print '<a name="builddoc"></a>'; // ancre
1665 /*
1666 * Generated documents
1667 */
1668 $filename = dol_sanitizeFileName($object->ref);
1669 $filedir = $upload_dir."/".dol_sanitizeFileName($object->ref);
1670 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1671 $genallowed = $permissiontoadd;
1672 $delallowed = $permissiontodelete;
1673 $codelang = '';
1674 if ($object->fk_soc > 0) {
1675 $object->fetch_thirdparty();
1676 $codelang = $object->thirdparty->default_lang;
1677 }
1678
1679 print $formfile->showdocuments('ticket', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $codelang);
1680
1681 // Show links to link elements
1682 $tmparray = $form->showLinkToObjectBlock($object, array(), array('ticket'), 1);
1683 $linktoelem = $tmparray['linktoelem'];
1684 $htmltoenteralink = $tmparray['htmltoenteralink'];
1685 print $htmltoenteralink;
1686
1687 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1688
1689 // Show direct link to public interface
1690 print '<br><!-- Link to public interface -->'."\n";
1691 print showDirectPublicLink($object).'<br>';
1692 print '</div>';
1693
1694 if (!getDolGlobalString('MAIN_HIDE_MESSAGES_ON_CARD')) {
1695 print '<div class="fichehalfright">';
1696
1697 $MAXEVENT = 10;
1698
1699 $morehtmlcenter = '<div class="nowraponall">';
1700 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/ticket/messaging.php?id='.$object->id);
1701 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/ticket/agenda.php?id='.$object->id);
1702 $morehtmlcenter .= '</div>';
1703
1704 // List of actions on element
1705 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1706 $formactions = new FormActions($db);
1707 $somethingshown = $formactions->showactions($object, 'ticket', $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
1708
1709 print '</div>';
1710 }
1711
1712 print '</div>';
1713 }
1714 }
1715}
1716
1717// End of page
1718llxFooter();
1719$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class Actions of the module ticket.
Class to manage contact/addresses.
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.
static checkRequiredFields(array $fields, int &$errors)
Check required fields.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
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:263
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
show_actions_messaging($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions in messaging format.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
roundUpToNextMultiple($n, $x=5)
Round to next multiple.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Class to generate the form for creating a new ticket.
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
showDirectPublicLink($object)
Return string with full Url.
ticket_prepare_head($object)
Build tabs for a Ticket object.