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