dolibarr 23.0.4
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:int');
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)) > 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 if ($object->close($user) > 0) {
483 setEventMessages('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>', null, 'mesgs');
484
485 $url = 'card.php?track_id=' . GETPOST('track_id', 'alpha');
486 header("Location: " . $url);
487 exit;
488 }
489 setEventMessages($object->error, $object->errors, 'errors');
490 $action = '';
491 } else {
492 setEventMessages($object->error, $object->errors, 'errors');
493 $action = '';
494 }
495 }
496
497 if ($action == 'confirm_clone' && GETPOST('confirm', 'alpha') == "yes" && $permissiontoadd) {
498 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
499 $newid = $object->createFromClone($user, $object->id);
500 if ($newid > 0) {
501 header("Location: " . DOL_URL_ROOT . "/ticket/card.php?id=".$newid);
502 exit;
503 } else {
504 setEventMessages($object->error, $object->errors, 'errors');
505 $action = '';
506 }
507 }
508 }
509
510 if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $permissiontodelete) {
511 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
512 if ($object->delete($user) > 0) {
513 setEventMessages('<div class="confirm">' . $langs->trans('TicketDeletedSuccess') . '</div>', null, 'mesgs');
514 header("Location: " . DOL_URL_ROOT . "/ticket/list.php");
515 exit;
516 } else {
517 $langs->load("errors");
518 $mesg = '<div class="error">' . $langs->trans($object->error) . '</div>';
519 $action = '';
520 }
521 }
522 }
523
524 // Set parent company
525 if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
526 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
527 $result = $object->setCustomer(GETPOSTINT('editcustomer'));
528 $url = $_SERVER["PHP_SELF"] . '?track_id=' . GETPOST('track_id', 'alpha');
529 header("Location: " . $url);
530 exit();
531 }
532 }
533
534 // Set progress status
535 if ($action == 'set_progression' && $user->hasRight('ticket', 'write')) {
536 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
537 $result = $object->setProgression(GETPOSTINT('progress'));
538
539 $url = 'card.php?track_id=' . $object->track_id;
540 header("Location: " . $url);
541 exit();
542 }
543 }
544
545 // Set categories
546 if ($action == 'set_categories' && $user->hasRight('ticket', 'write')) {
547 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
548 $result = $object->setCategories(GETPOST('categories', 'array'));
549
550 $url = 'card.php?track_id=' . $object->track_id;
551 header("Location: " . $url);
552 exit();
553 }
554 }
555
556 // Set Subject
557 if ($action == 'setsubject' && $user->hasRight('ticket', 'write')) {
558 if ($object->fetch(GETPOSTINT('id'))) {
559 if ($action == 'setsubject') { // Test on permission already done
560 $object->subject = GETPOST('subject', 'alphanohtml');
561 }
562
563 if ($action == 'setsubject' && empty($object->subject)) { // Test on permission already done
564 $error++;
565 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")), null, 'errors');
566 }
567
568 if (!$error) {
569 if (!$object->update($user) >= 0) {
570 $error++;
571 setEventMessages($object->error, $object->errors, 'errors');
572 }
573 }
574
575 header("Location: " . $_SERVER['PHP_SELF'] . "?track_id=" . $object->track_id);
576 exit;
577 }
578 }
579
580 if ($action == 'confirm_reopen' && $user->hasRight('ticket', 'manage') && !GETPOST('cancel')) {
581 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
582 // prevent browser refresh from reopening ticket several times
583 if ($object->status == Ticket::STATUS_CLOSED || $object->status == Ticket::STATUS_CANCELED) {
584 if ($object->fk_user_assign != null) {
585 $res = $object->setStatut(Ticket::STATUS_ASSIGNED, null, '', $triggermodname);
586 } else {
587 $res = $object->setStatut(Ticket::STATUS_NOT_READ, null, '', $triggermodname);
588 }
589 if ($res) {
590 $url = 'card.php?track_id=' . $object->track_id;
591 header("Location: " . $url);
592 exit();
593 } else {
594 $error++;
595 setEventMessages($object->error, $object->errors, 'errors');
596 }
597 }
598 }
599 } elseif ($action == 'classin' && $permissiontoadd) {
600 // Categorisation dans projet
601 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
602 $object->setProject($projectid);
603 $url = 'card.php?track_id=' . $object->track_id;
604 header("Location: " . $url);
605 exit();
606 }
607 } elseif ($action == 'setcontract' && $permissiontoadd) {
608 // Categorisation dans contrat
609 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
610 $object->setContract(GETPOSTINT('contractid'));
611 $url = 'card.php?track_id=' . $object->track_id;
612 header("Location: " . $url);
613 exit();
614 }
615 } elseif ($action == "set_message" && $user->hasRight('ticket', 'manage')) {
616 if (!GETPOST('cancel')) {
617 $object->fetch(0, '', GETPOST('track_id', 'alpha'));
618 //$oldvalue_message = $object->message;
619 $fieldtomodify = GETPOST('message_initial', 'restricthtml');
620
621 $object->message = $fieldtomodify;
622 $ret = $object->update($user);
623 if ($ret > 0) {
624 //include_once DOL_DOCUMENT_ROOT.'/core/class/utils_diff.class.php';
625 // output the result of comparing two files as plain text
626 //$log_action .= Diff::toString(Diff::compare(strip_tags($oldvalue_message), strip_tags($object->message)));
627
628 setEventMessages($langs->trans('TicketMessageSuccesfullyUpdated'), null, 'mesgs');
629 } else {
630 $error++;
631 setEventMessages($object->error, $object->errors, 'errors');
632 }
633 }
634
635 $action = 'view';
636 } elseif ($action == 'confirm_set_status' && $permissiontoadd && !GETPOST('cancel')) {
637 // Reopen ticket
638 if ($object->fetch(GETPOSTINT('id'), GETPOST('track_id', 'alpha')) >= 0) {
639 $new_status = GETPOSTINT('new_status');
640
641 $res = $object->setStatut($new_status, null, '', 'TICKET_MODIFY');
642
643 if ($res) {
644 $url = 'card.php?track_id=' . $object->track_id;
645 header("Location: " . $url);
646 exit();
647 } else {
648 $error++;
649 setEventMessages($object->error, $object->errors, 'errors');
650 }
651 }
652 }
653
654 // Action to update an extrafield
655 if ($action == "update_extras" && $permissiontoeditextra) {
656 $object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha'));
657
658 $attribute_name = GETPOST('attribute', 'aZ09');
659
660 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
661 if ($ret < 0) {
662 $error++;
663 }
664
665 if (!$error) {
666 $result = $object->updateExtraField($attribute_name, $triggermodname);
667 if ($result < 0) {
668 setEventMessages($object->error, $object->errors, 'errors');
669 $error++;
670 }
671 }
672
673 if ($error) {
674 $action = 'edit_extras';
675 }
676 }
677
678 if ($action == "change_property" && GETPOST('btn_update_ticket_prop', 'alpha') && $permissiontoadd) {
679 $object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha'));
680
681 $object->type_code = GETPOST('update_value_type', 'aZ09');
682 $object->severity_code = GETPOST('update_value_severity', 'aZ09');
683 $object->category_code = GETPOST('update_value_category', 'aZ09');
684
685 $ret = $object->update($user);
686 if ($ret > 0) {
687 setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
688 } else {
689 $error++;
690 setEventMessages($object->error, $object->errors, 'errors');
691 }
692 $action = 'view';
693 }
694
695 // Actions when printing a doc from card
696 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
697
698 $permissiondellink = $user->hasRight('ticket', 'write');
699 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
700
701 // Actions when printing a doc from card
702 include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
703
704 // Actions to build doc
705 include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
706
707 // Actions to send emails
708 $triggersendname = 'TICKET_SENTBYMAIL';
709 $paramname = 'id';
710 $autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
711 $trackid = 'tic' . $object->id;
712 include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
713
714 // Set $action to correct value for the case we used presend action to add a message
715 if (GETPOSTISSET('actionbis') && $action == 'presend') { // Test on permission not required here
716 $action = 'presend_addmessage';
717 }
718}
719
720
721/*
722 * View
723 */
724
725$userstat = new User($db);
726$form = new Form($db);
727$formfile = new FormFile($db);
728$formticket = new FormTicket($db);
729if (isModEnabled('project')) {
730 $formproject = new FormProjets($db);
731}
732
733$help_url = 'EN:Module_Ticket|FR:DocumentationModuleTicket';
734
735$title = $actionobject->getTitle($action, $object);
736
737llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-ticket page-card');
738
739if ($action == 'create' || $action == 'presend') {
740 if (empty($permissiontoadd)) {
741 accessforbidden('NotEnoughPermissions', 0, 1);
742 }
743
744 $formticket = new FormTicket($db);
745
746 print load_fiche_titre($langs->trans('NewTicket'), '', 'ticket');
747
748 $formticket->trackid = ''; // TODO Use a unique key 'tic' to avoid conflict in upload file feature
749
750 if (GETPOST("mode", "aZ09") == 'init' && empty($_POST)) {
751 $formticket->clear_attached_files();
752 }
753
754 $formticket->withfromsocid = $socid ? $socid : $user->socid;
755 $formticket->withfromcontactid = $contactid ? $contactid : '';
756 $formticket->withtitletopic = 1;
757 $formticket->withnotifytiersatcreate = ($notifyTiers ? 1 : (getDolGlobalString('TICKET_CHECK_NOTIFY_THIRDPARTY_AT_CREATION') ? 1 : 0));
758 $formticket->withusercreate = 0;
759 $formticket->withref = 1;
760 $formticket->fk_user_create = $user->id;
761 $formticket->withfile = 2;
762 $formticket->withextrafields = 1;
763 $formticket->param = array('origin' => GETPOST('origin'), 'originid' => GETPOST('originid'));
764
765 $formticket->withcancel = 1;
766
767 // Init list of files
768 if (GETPOST("mode", "aZ09") == 'init') {
769 $formticket->clear_attached_files();
770 }
771
772 $formticket->showForm(1, 'create', 0, null, $action, $object);
773
774 print dol_get_fiche_end();
775} elseif ($action == 'edit' && $user->hasRight('ticket', 'write') && $object->status < Ticket::STATUS_CLOSED) {
776 if (empty($permissiontoadd)) {
777 accessforbidden('NotEnoughPermissions', 0, 1);
778 }
779
780 $formticket = new FormTicket($db);
781
782 $head = ticket_prepare_head($object);
783
784 print dol_get_fiche_head($head, 'tabTicket', $langs->trans('Ticket'), -1, 'ticket');
785
786 $formticket->trackid = $object->track_id; // TODO Use a unique key 'tic' to avoid conflict in upload file feature
787 $formticket->withfromsocid = $object->socid;
788 $formticket->withtitletopic = 1;
789 // $formticket->withnotifytiersatcreate = ($notifyTiers ? 1 : (getDolGlobalString('TICKET_CHECK_NOTIFY_THIRDPARTY_AT_CREATION') ? 1 : 0));
790 $formticket->withnotifytiersatcreate = 0;
791 $formticket->withusercreate = 0;
792 $formticket->withref = 1;
793 $formticket->fk_user_create = $user->id;
794 $formticket->withfile = 0;
795 $formticket->action = 'update';
796 $formticket->withextrafields = 1;
797 $formticket->param = array('origin' => GETPOST('origin'), 'originid' => GETPOST('originid'));
798
799 $formticket->withcancel = 1;
800
801 $formticket->showForm(0, 'edit', 0, null, $action, $object);
802
803 print dol_get_fiche_end();
804} elseif ($object->id) {
805 if (!empty($res) && $res > 0) {
806 // or for unauthorized internals users
807 if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
808 accessforbidden('', 0, 1);
809 }
810
811 $formconfirm = '';
812
813 // Confirmation close
814 if ($action == 'close') {
815 $thirdparty_contacts = $object->getInfosTicketExternalContact(1);
816 $contacts_select = array(
817 '-2' => $langs->trans('TicketNotifyAllTiersAtClose'),
818 '-3' => $langs->trans('TicketNotNotifyTiersAtClose')
819 );
820 foreach ($thirdparty_contacts as $thirdparty_contact) {
821 $contacts_select[$thirdparty_contact['id']] = $thirdparty_contact['civility'] . ' ' . $thirdparty_contact['lastname'] . ' ' . $thirdparty_contact['firstname'];
822 }
823
824 // Default select all or no contact
825 $default = (getDolGlobalString('TICKET_NOTIFY_AT_CLOSING') ? '-2' : '-3');
826 $formquestion = array(
827 array(
828 'name' => 'contactid',
829 'type' => 'select',
830 'label' => $langs->trans('NotifyThirdpartyOnTicketClosing'),
831 'values' => $contacts_select,
832 'default' => $default
833 ),
834 );
835
836 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_close", $formquestion, '', 1);
837 }
838 // Confirmation abandon
839 if ($action == 'abandon') {
840 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("AbandonTicket"), $langs->trans("ConfirmAbandonTicket"), "confirm_abandon", '', '', 1);
841 }
842 // Confirmation delete
843 if ($action == 'delete') {
844 $formconfirm = $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("Delete"), $langs->trans("ConfirmDeleteTicket"), "confirm_delete_ticket", '', '', 1);
845 }
846 // Confirm reopen
847 if ($action == 'reopen') {
848 $formconfirm = $form->formconfirm($url_page_current.'?track_id='.$object->track_id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenTicket'), 'confirm_reopen', '', '', 1);
849 }
850 // Confirmation status change
851 if ($action == 'set_status') {
852 $new_status = GETPOSTINT('new_status');
853 //var_dump($url_page_current . "?track_id=" . $object->track_id);
854 $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);
855 }
856 // Clone confirmation
857 if ($action == 'clone') {
858 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', '', 'yes', 1);
859 }
860
861 // Call Hook formConfirm
862 $parameters = array('formConfirm' => $formconfirm);
863 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
864 if (empty($reshook)) {
865 $formconfirm .= $hookmanager->resPrint;
866 } elseif ($reshook > 0) {
867 $formconfirm = $hookmanager->resPrint;
868 }
869
870 // Print form confirm
871 print $formconfirm;
872
873 // project info
874 if ($projectid > 0) {
875 $projectstat = new Project($db);
876 if ($projectstat->fetch($projectid) > 0) {
877 $projectstat->fetch_thirdparty();
878
879 // To verify role of users
880 //$userAccess = $object->restrictedProjectArea($user,'read');
881 $userWrite = $projectstat->restrictedProjectArea($user, 'write');
882 //$userDelete = $object->restrictedProjectArea($user,'delete');
883 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
884
885 $head = project_prepare_head($projectstat);
886
887 print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), 0, ($projectstat->public ? 'projectpub' : 'project'));
888
889 print '<table class="border centpercent">';
890
891 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
892
893 // Ref
894 print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="3">';
895 // Define a complementary filter for search of next/prev ref.
896 if (!$user->hasRight('projet', 'all', 'lire')) {
897 $objectsListId = $projectstat->getProjectsAuthorizedForUser($user, $mine, 0);
898 $projectstat->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
899 }
900 print $form->showrefnav($projectstat, 'ref', $linkback, 1, 'ref', 'ref', '');
901 print '</td></tr>';
902
903 // Label
904 print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projectstat->title.'</td></tr>';
905
906 // Customer
907 print "<tr><td>".$langs->trans("ThirdParty")."</td>";
908 print '<td colspan="3">';
909 if ($projectstat->thirdparty->id > 0) {
910 print $projectstat->thirdparty->getNomUrl(1);
911 } else {
912 print '&nbsp;';
913 }
914
915 print '</td></tr>';
916
917 // Visibility
918 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
919 if ($projectstat->public) {
920 print $langs->trans('SharedProject');
921 } else {
922 print $langs->trans('PrivateProject');
923 }
924
925 print '</td></tr>';
926
927 // Status
928 print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projectstat->getLibStatut(4).'</td></tr>';
929
930 print "</table>";
931
932 print dol_get_fiche_end();
933 } else {
934 print "ErrorRecordNotFound";
935 }
936 } elseif ($socid > 0) {
937 $object->fetch_thirdparty();
938 $head = societe_prepare_head($object->thirdparty);
939
940 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
941
942 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
943
944 print dol_get_fiche_end();
945 }
946
947 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
948 $object->next_prev_filter = "te.fk_user_assign:=:".((int) $user->id);
949 } elseif ($user->socid > 0) {
950 $object->next_prev_filter = "te.fk_soc:=:".((int) $user->socid);
951 }
952
953 $head = ticket_prepare_head($object);
954
955 print dol_get_fiche_head($head, 'tabTicket', $langs->trans("Ticket"), -1, 'ticket', 0, '', '', 0, '', 1);
956
957 $morehtmlref = '<div class="refidno">';
958
959 if ($user->hasRight('ticket', 'write') && !$user->socid) {
960 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editsubject&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetTitle'), 0).'</a> ';
961 }
962 if ($action != 'editsubject') {
963 $morehtmlref .= dolPrintLabel($object->subject);
964 } else {
965 $morehtmlref .= '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
966 $morehtmlref .= '<input type="hidden" name="action" value="setsubject">';
967 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
968 $morehtmlref .= '<input type="hidden" name="id" value="'.$object->id.'">';
969 $morehtmlref .= '<input type="text" class="minwidth300" id="subject" name="subject" value="'.$object->subject.'" autofocus="">';
970 $morehtmlref .= '<input type="submit" class="smallpaddingimp button valignmiddle" name="modify" value="'.$langs->trans("Modify").'">';
971 $morehtmlref .= '<input type="submit" class="smallpaddingimp button button-cancel valignmiddle" name="cancel" value="'.$langs->trans("Cancel").'">';
972 $morehtmlref .= '</form>';
973 }
974
975 // Author
976 $createdbyshown = 0;
977 if ($object->fk_user_create > 0) {
978 $morehtmlref .= '<br>';
979 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
980
981 $fuser = new User($db);
982 $fuser->fetch($object->fk_user_create);
983 $morehtmlref .= $fuser->getNomUrl(-1);
984 $createdbyshown++;
985 }
986
987 $createdfrompublicticket = 0;
988 $createdfromemailcollector = 0;
989 if (!empty($object->origin_email) && (empty($object->email_msgid) || preg_match('/dolibarr\-tic\d+/', $object->email_msgid))) {
990 // If ticket create from public interface - TODO Add a more robust test to know if created by public interface
991 $createdfrompublicticket = 1;
992 } elseif (!empty($object->email_msgid)) {
993 // If ticket create by emailcollector - TODO Add a more robust test to know if created by email collector (using import key ?)
994 $createdfromemailcollector = 1;
995 }
996
997 //var_dump($object);
998 $htmltooltip = '';
999 if ($createdfrompublicticket) {
1000 $htmltooltip .= $langs->trans("OriginEmail").': '.$object->origin_email;
1001 $htmltooltip .= '<br>'.$langs->trans("IP").': '.dol_print_ip($object->ip);
1002 $morehtmlref .= ($createdbyshown ? ' - ' : '<br>');
1003 //$morehtmlref .= ($createdbyshown ? '' : '<span class="opacitymedium">'.$langs->trans("CreatedBy").' </span> ');
1004 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
1005 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">- '.$form->textwithpicto($langs->trans("CreatedByPublicPortal"), $htmltooltip, 1, 'help', '', 0, 3, 'tooltipcreatedbyportal').'</small>';
1006 } elseif ($createdfromemailcollector) {
1007 $langs->load("mails");
1008
1009 $htmltooltip .= '<b>'.$langs->trans("EmailMsgID").':</b> '.$object->email_msgid;
1010 $htmltooltip .= '<br><b>'.$langs->trans("EmailDate").':</b> '.dol_print_date($object->email_date, 'dayhour');
1011 $htmltooltip .= '<br><b>'.$langs->trans("MailFrom").':</b> '.$object->origin_email;
1012 $htmltooltip .= '<br><b>'.$langs->trans("MailReply").':</b> '.$object->origin_replyto;
1013 $htmltooltip .= '<br><b>'.$langs->trans("MailReferences").':</b> '.$object->origin_references;
1014 $morehtmlref .= ($createdbyshown ? ' - ' : '<br>');
1015 //$morehtmlref .= ($createdbyshown ? '' : '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ');
1016 $morehtmlref .= img_picto('From', 'email', 'class="paddingrightonly"');
1017 $morehtmlref .= dol_escape_htmltag($object->origin_email);
1018 if ($object->origin_replyto) {
1019 $morehtmlref .= ' - '.img_picto('ReplyTo', 'email', 'class="paddingrightonly"');
1020 $morehtmlref .= dol_escape_htmltag($object->origin_replyto);
1021 }
1022 $morehtmlref .= ' <small class="hideonsmartphone opacitymedium">- '.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $htmltooltip, 1, 'help', '', 0, 3, 'tooltipcreatedbyemailcollector').'</small>';
1023 }
1024
1025 $permissiontoedit = $object->status < 8 && !$user->socid && $user->hasRight('ticket', 'write');
1026 //$permissiontoedit = 0;
1027
1028 // Thirdparty
1029 if (isModEnabled("societe")) {
1030 $morehtmlref .= '<br>';
1031 if ($action != 'editcustomer' && $permissiontoedit) {
1032 $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
1033 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
1034 }
1035 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, (string) $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
1036 if (!empty($object->socid)) {
1037 $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>';
1038 }
1039 }
1040
1041 // Project
1042 if (isModEnabled('project')) {
1043 $langs->load("projects");
1044 $morehtmlref .= '<br>';
1045 if ($permissiontoedit) {
1046 $object->fetchProject();
1047 $morehtmlref .= img_picto($langs->trans("Project"), 'project'.((is_object($object->project) && $object->project->public) ? 'pub' : ''), 'class="pictofixedwidth"');
1048 if ($action != 'classify') {
1049 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1050 }
1051 $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');
1052 } else {
1053 if (!empty($object->fk_project)) {
1054 $object->fetchProject();
1055 $morehtmlref .= $object->project->getNomUrl(1);
1056 if ($object->project->title) {
1057 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($object->project->title).'</span>';
1058 }
1059 }
1060 }
1061 }
1062
1063 // Contract
1064 if (getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
1065 // Deprecated. Duplicate feature. Ticket can already be linked to contract with the generic "Link to" feature.
1066 if (isModEnabled('contract')) {
1067 $langs->load('contracts');
1068 $morehtmlref .= '<br>';
1069 if ($permissiontoedit) {
1070 $morehtmlref .= img_picto($langs->trans("Contract"), 'contract', 'class="pictofixedwidth"');
1071 if ($action == 'edit_contrat') {
1072 $formcontract = new FormContract($db);
1073 $morehtmlref .= $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contract, 'contratid', 0, 1, 1, 1);
1074 } else {
1075 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_contrat&token='.newToken().'&id='.$object->id.'">';
1076 $morehtmlref .= img_edit($langs->trans('SetContract'));
1077 $morehtmlref .= '</a>';
1078 }
1079 } else {
1080 if (!empty($object->fk_contract)) {
1081 $contratstatic = new Contrat($db);
1082 $contratstatic->fetch($object->fk_contract);
1083 //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1084 $morehtmlref .= $contratstatic->getNomUrl(0, 0, 1);
1085 }
1086 }
1087 }
1088 }
1089
1090 $morehtmlref .= '</div>';
1091
1092 $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php?restore_lastsearch_values=1"><strong>'.$langs->trans("BackToList").'</strong></a> ';
1093
1094 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref);
1095
1096 print '<div class="fichecenter">';
1097 print '<div class="fichehalfleft">';
1098 print '<div class="underbanner clearboth"></div>';
1099
1100 print '<table class="border tableforfield centpercent">';
1101
1102 // Track ID
1103 print '<tr><td class="titlefieldmiddle">'.$langs->trans("TicketTrackId").'</td><td>';
1104 if (!empty($object->track_id)) {
1105 if (empty($object->ref)) {
1106 $object->ref = (string) $object->id;
1107 print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'track_id');
1108 } else {
1109 print dolPrintLabel($object->track_id);
1110 }
1111 } else {
1112 print $langs->trans('None');
1113 }
1114 print '</td></tr>';
1115
1116 // Subject
1117 /*
1118 print '<tr><td>';
1119 print $form->editfieldkey("Subject", 'subject', $object->subject, $object, $user->hasRight('ticket', 'write') && !$user->socid, 'string');
1120 print '</td><td>';
1121 print $form->editfieldval("Subject", 'subject', $object->subject, $object, $user->hasRight('ticket', 'write') && !$user->socid, 'string');
1122 print '</td></tr>';
1123 */
1124
1125 // Creation date
1126 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
1127 print dol_print_date($object->datec, 'dayhour', 'tzuser');
1128 print '<span class="opacitymedium"><span class="small"> - '.$langs->trans("TimeElapsedSince").': <b><i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->datec, 60)).'</i></b></span></span>';
1129 print '</td></tr>';
1130
1131 // Origin
1132 /*
1133 if ($object->email_msgid) {
1134 $texttoshow = $langs->trans("CreatedByEmailCollector");
1135 } elseif ($object->origin_email) {
1136 $texttoshow = $langs->trans("FromPublicEmail");
1137 }
1138 if ($texttoshow) {
1139 print '<tr><td class="titlefield fieldname_email_origin">';
1140 print $langs->trans("Origin");
1141 print '</td>';
1142 print '<td class="valuefield fieldname_email_origin">';
1143 print $texttoshow;
1144 print '</td></tr>';
1145 }
1146 */
1147
1148 // Read date
1149 print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
1150 if (!empty($object->date_read)) {
1151 print dol_print_date($object->date_read, 'dayhour', 'tzuser');
1152 print '<span class="opacitymedium"><span class="small"> - '.$langs->trans("TimeElapsedSince").': ';
1153 //print '<b><i>'.convertSecondToTime(roundUpToNextMultiple($object->date_read - $object->datec, 60)).'</i></b>';
1154 //print ' / ';
1155 print '<b><i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->date_read, 60)).'</i></b></span></span>';
1156 }
1157 print '</td></tr>';
1158
1159 // Close date
1160 print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
1161 if (!empty($object->date_close)) {
1162 print dol_print_date($object->date_close, 'dayhour', 'tzuser');
1163 }
1164 print '</td></tr>';
1165
1166 // User assigned
1167 print '<tr><td>';
1168 print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
1169 print $langs->trans("AssignedTo");
1170 if (isset($object->status) && $object->status < $object::STATUS_CLOSED && GETPOST('set', 'alpha') != "assign_ticket" && $user->hasRight('ticket', 'manage')) {
1171 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>';
1172 }
1173 print '</td></tr></table>';
1174 print '</td><td>';
1175 if (GETPOST('set', 'alpha') != "assign_ticket" && $object->fk_user_assign > 0) {
1176 $userstat->fetch($object->fk_user_assign);
1177 print $userstat->getNomUrl(-1);
1178 }
1179
1180 // Show user list to assignate one if status is "read"
1181 if (GETPOST('set', 'alpha') == "assign_ticket" && $object->status < 8 && !$user->socid && $user->hasRight('ticket', 'write')) {
1182 print '<form method="post" name="ticket" enctype="multipart/form-data" action="'.$url_page_current.'">';
1183 print '<input type="hidden" name="token" value="'.newToken().'">';
1184 print '<input type="hidden" name="action" value="assign_user">';
1185 print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
1186 //print '<label for="fk_user_assign">'.$langs->trans("AssignUser").'</label> ';
1187 print $form->select_dolusers(empty($object->fk_user_assign) ? $user->id : $object->fk_user_assign, 'fk_user_assign', 1);
1188 print ' <input type="submit" class="button smallpaddingimp" name="btn_assign_user" value="'.$langs->trans("Validate").'" />';
1189 print '</form>';
1190 }
1191 print '</td></tr>';
1192
1193 // Progression
1194 print '<tr><td>';
1195 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
1196 print $langs->trans('Progression').'</td><td class="left">';
1197 print '</td>';
1198 if ($action != 'progression' && isset($object->status) && $object->status < $object::STATUS_CLOSED && !$user->socid) {
1199 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>';
1200 }
1201 print '</tr></table>';
1202 print '</td><td>';
1203 if ($user->hasRight('ticket', 'write') && $action == 'progression') {
1204 print '<form action="'.$url_page_current.'" method="post">';
1205 print '<input type="hidden" name="token" value="'.newToken().'">';
1206 print '<input type="hidden" name="track_id" value="'.$track_id.'">';
1207 print '<input type="hidden" name="action" value="set_progression">';
1208 print '<input type="text" class="flat width75" name="progress" value="'.$object->progress.'">';
1209 print ' <input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
1210 print '</form>';
1211 } else {
1212 print($object->progress > 0 ? $object->progress : '0').'%';
1213 }
1214 print '</td>';
1215 print '</tr>';
1216
1217 // Timing (Duration sum of linked fichinter)
1218 if (isModEnabled('intervention')) {
1219 $object->fetchObjectLinked();
1220 $num = count($object->linkedObjects);
1221 $timing = 0;
1222 $foundinter = 0;
1223 if ($num) {
1224 foreach ($object->linkedObjects as $objecttype => $objects) {
1225 if ($objecttype == "fichinter") {
1226 '@phan-var-force Fichinter[] $objects';
1227 foreach ($objects as $fichinter) {
1228 $foundinter++;
1230 $timing += $fichinter->duration;
1231 }
1232 }
1233 }
1234 }
1235 print '<tr><td>';
1236 print $form->textwithpicto($langs->trans("TicketDurationAuto"), $langs->trans("TicketDurationAutoInfos"), 1);
1237 print '</td><td>';
1238 print $foundinter ? convertSecondToTime($timing, 'all', getDolGlobalInt('MAIN_DURATION_OF_WORKDAY')) : '';
1239 print '</td></tr>';
1240 }
1241
1242 // Other attributes
1243 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1244
1245 print '</table>';
1246
1247
1248 // End of left column and beginning of right column
1249 print '</div><div class="fichehalfright">';
1250
1251
1252 print '<form method="post" name="formticketproperties" action="'.$url_page_current.'">';
1253 print '<input type="hidden" name="token" value="'.newToken().'">';
1254 print '<input type="hidden" name="action" value="change_property">';
1255 print '<input type="hidden" name="track_id" value="'.$track_id.'">';
1256 print '<input type="hidden" name="trackid" value="'.$trackid.'">';
1257
1258 // Classification of ticket
1259 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
1260 print '<table class="border tableforfield centpercent margintable bordertopimp">';
1261 print '<tr class="liste_titre">';
1262 print '<td>';
1263 print $langs->trans('TicketProperties');
1264 print '</td>';
1265 print '<td>';
1266 if (GETPOST('set', 'alpha') == 'properties' && $user->hasRight('ticket', 'write')) {
1267 print '<input type="submit" class="button smallpaddingimp" name="btn_update_ticket_prop" value="'.$langs->trans("Modify").'" />';
1268 } else {
1269 // Button to edit Properties
1270 if (isset($object->status) && ($object->status < $object::STATUS_NEED_MORE_INFO || !getDolGlobalInt('TICKET_DISALLOW_CLASSIFICATION_MODIFICATION_EVEN_IF_CLOSED')) && $user->hasRight('ticket', 'write')) {
1271 print ' <a class="editfielda" href="card.php?track_id='.$object->track_id.'&set=properties">'.img_edit($langs->trans('Modify')).'</a>';
1272 }
1273 }
1274 print '</td>';
1275 print '</tr>';
1276
1277 if (GETPOST('set', 'alpha') == 'properties' && $user->hasRight('ticket', 'write')) {
1278 print '<tr>';
1279 // Type
1280 print '<td class="titlefield">';
1281 print $langs->trans('Type');
1282 print '</td><td>';
1283 $formticket->selectTypesTickets($object->type_code, 'update_value_type', '', 2);
1284 print '</td>';
1285 print '</tr>';
1286 // Group
1287 print '<tr>';
1288 print '<td>';
1289 print $langs->trans('TicketCategory');
1290 print '</td><td>';
1291 $formticket->selectGroupTickets($object->category_code, 'update_value_category', '', 2, 0, 0, 0, 'maxwidth500 widthcentpercentminusxx');
1292 print '</td>';
1293 print '</tr>';
1294 // Severity
1295 print '<tr>';
1296 print '<td>';
1297 print $langs->trans('TicketSeverity');
1298 print '</td><td>';
1299 $formticket->selectSeveritiesTickets($object->severity_code, 'update_value_severity', '', 2);
1300 print '</td>';
1301 print '</tr>';
1302 } else {
1303 // Type
1304 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
1305 if (!empty($object->type_code)) {
1306 print $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
1307 }
1308 print '</td></tr>';
1309 // Group
1310 $s = '';
1311 if (!empty($object->category_code)) {
1312 $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
1313 }
1314 print '<tr><td>'.$langs->trans("TicketCategory").'</td><td class="tdoverflowmax200" title="'.dol_escape_htmltag($s).'">';
1315 print dol_escape_htmltag($s);
1316 print '</td></tr>';
1317 // Severity
1318 print '<tr><td>'.$langs->trans("TicketSeverity").'</td><td>';
1319 if (!empty($object->severity_code)) {
1320 print $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
1321 }
1322 print '</td></tr>';
1323 }
1324 print '</table>'; // End table actions
1325 print '</div>';
1326
1327 print '</form>';
1328
1329 // Tags/Categories
1330 if (isModEnabled('category')) {
1331 print '<!-- tag/categories -->'."\n";
1332 print '<table class="border centpercent tableforfield">';
1333 print '<tr>';
1334 print '<td class="valignmiddle titlefield">';
1335 print '<table class="nobordernopadding centpercent"><tr><td class="none">';
1336 print $langs->trans("Categories");
1337 if ($action != 'categories' && !$user->socid) {
1338 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>';
1339 }
1340 print '</td>';
1341 print '</table>';
1342 print '</td>';
1343
1344 if ($user->hasRight('ticket', 'write') && $action == 'categories') {
1345 print '<td colspan="3">';
1346 print '<form action="'.$url_page_current.'" method="POST">';
1347 print '<input type="hidden" name="token" value="'.newToken().'">';
1348 print '<input type="hidden" name="track_id" value="'.$track_id.'">';
1349 print '<input type="hidden" name="action" value="set_categories">';
1350 print $form->selectCategories(Categorie::TYPE_TICKET, 'categories', $object);
1351 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Save').'">';
1352 print '</form>';
1353 print "</td>";
1354 } else {
1355 print '<td colspan="3">';
1356 print $form->showCategories($object->id, Categorie::TYPE_TICKET, 1);
1357 print "</td></tr>";
1358 }
1359
1360 print '</table>';
1361 }
1362
1363 // View Original message
1364 $actionobject->viewTicketOriginalMessage($user, $action, $object);
1365
1366
1367 // Display navbar with links to change ticket status
1368 print '<!-- navbar with status -->';
1369 if (!$user->socid && $user->hasRight('ticket', 'write') && isset($object->status) && $object->status < $object::STATUS_CLOSED) {
1370 $actionobject->viewStatusActions($object);
1371 }
1372
1373
1374 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1375 print load_fiche_titre($langs->trans('Contacts'), '', 'title_companies.png');
1376
1377 print '<div class="div-table-responsive-no-min">';
1378 print '<div class="tagtable centpercent noborder allwidth">';
1379
1380 print '<div class="tagtr liste_titre">';
1381 print '<div class="tagtd">'.$langs->trans("Source").'</div>
1382 <div class="tagtd">' . $langs->trans("Company").'</div>
1383 <div class="tagtd">' . $langs->trans("Contacts").'</div>
1384 <div class="tagtd">' . $langs->trans("ContactType").'</div>
1385 <div class="tagtd">' . $langs->trans("Phone").'</div>
1386 <div class="tagtd center">' . $langs->trans("Status").'</div>';
1387 print '</div><!-- tagtr -->';
1388
1389 // Contact list
1390 $companystatic = new Societe($db);
1391 $contactstatic = new Contact($db);
1392 $userstatic = new User($db);
1393 $var = false;
1394 foreach (array('internal', 'external') as $source) {
1395 $tmpobject = $object;
1396 $tab = $tmpobject->listeContact(-1, $source);
1397 // '@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';
1398 $num = is_array($tab) ? count($tab) : 0;
1399 $i = 0;
1400 foreach (array_keys($tab) as $i) {
1401 $tab_i = &$tab[$i];
1402 $var = !$var;
1403 print '<div class="tagtr '.($var ? 'pair' : 'impair').'">';
1404
1405 print '<div class="tagtd left">';
1406 if ($tab_i['source'] == 'internal') {
1407 echo $langs->trans("User");
1408 }
1409
1410 if ($tab_i['source'] == 'external') {
1411 echo $langs->trans("ThirdPartyContact");
1412 }
1413
1414 print '</div>';
1415 print '<div class="tagtd left">';
1416
1417 if ($tab_i['socid'] > 0) {
1418 $companystatic->fetch($tab_i['socid']);
1419 echo $companystatic->getNomUrl(-1);
1420 }
1421 if ($tab_i['socid'] < 0) {
1422 echo getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
1423 }
1424 if (!$tab_i['socid']) {
1425 echo '&nbsp;';
1426 }
1427 print '</div>';
1428
1429 print '<div class="tagtd">';
1430 if ($tab_i['source'] == 'internal') {
1431 if ($userstatic->fetch($tab_i['id'])) {
1432 print $userstatic->getNomUrl(-1);
1433 }
1434 }
1435 if ($tab_i['source'] == 'external') {
1436 if ($contactstatic->fetch($tab_i['id'])) {
1437 print $contactstatic->getNomUrl(-1);
1438 }
1439 }
1440 print ' </div>
1441 <div class="tagtd">' . $tab_i['libelle'].'</div>';
1442
1443 print '<div class="tagtd">';
1444
1445 print dol_print_phone($tab_i['phone'], '', 0, 0, 'AC_TEL').'<br>';
1446
1447 if (array_key_exists('phone_perso', $tab_i) && !empty($tab_i['phone_perso'])) {
1448 //print img_picto($langs->trans('PhonePerso'),'object_phoning.png','',0,0,0).' ';
1449 print '<br>'.dol_print_phone((string) $tab_i['phone_perso'], '', 0, 0, 'AC_TEL').'<br>';
1450 }
1451 if (!empty($tab_i['phone_mobile'])) {
1452 //print img_picto($langs->trans('PhoneMobile'),'object_phoning.png','',0,0,0).' ';
1453 print dol_print_phone($tab_i['phone_mobile'], '', 0, 0, 'AC_TEL').'<br>';
1454 }
1455 print '</div>';
1456
1457 print '<div class="tagtd center">';
1458 if ($object->status >= 0) {
1459 echo '<a href="contact.php?track_id='.$object->track_id.'&amp;action=swapstatut&amp;ligne='.$tab_i['rowid'].'">';
1460 }
1461
1462 if ($tab_i['source'] == 'internal') {
1463 $userstatic->id = $tab_i['id'];
1464 $userstatic->lastname = $tab_i['lastname'];
1465 $userstatic->firstname = $tab_i['firstname'];
1466 echo $userstatic->LibStatut($tab_i['statuscontact'], 3);
1467 }
1468 if ($tab_i['source'] == 'external') {
1469 $contactstatic->id = $tab_i['id'];
1470 $contactstatic->lastname = $tab_i['lastname'];
1471 $contactstatic->firstname = $tab_i['firstname'];
1472 echo $contactstatic->LibStatut($tab_i['statuscontact'], 3);
1473 }
1474 if ($object->status >= 0) {
1475 echo '</a>';
1476 }
1477
1478 print '</div>';
1479
1480 print '</div><!-- tagtr -->';
1481
1482 $i++;
1483 }
1484 }
1485
1486 print '</div><!-- contact list -->';
1487 print '</div>';
1488 }
1489
1490 print '</div></div>';
1491 print '<div class="clearboth"></div>';
1492
1493 print dol_get_fiche_end();
1494
1495
1496 // Buttons for actions
1497 if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'editline') {
1498 print '<div class="tabsAction">'."\n";
1499 $parameters = array();
1500 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1501 if ($reshook < 0) {
1502 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1503 }
1504
1505 if (empty($reshook)) {
1506 // Email
1507 if (isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") {
1508 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', '');
1509 }
1510
1511 // Show link to add a message (if read and not closed)
1512 if (isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") {
1513 print dolGetButtonAction('', $langs->trans('TicketAddPrivateMessage'), 'default', $_SERVER["PHP_SELF"].'?action=presend_addmessage&mode=init&token='.newToken().'&track_id='.$object->track_id.'#formmailbeforetitle', '');
1514 }
1515
1516 // Link to create an intervention
1517 // socid is needed otherwise fichinter ask it and forgot origin after form submit :\
1518 if (!$object->fk_soc && $user->hasRight("ficheinter", "creer")) {
1519 print dolGetButtonAction($langs->trans('UnableToCreateInterIfNoSocid'), $langs->trans('TicketAddIntervention'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
1520 }
1521 if ($object->fk_soc > 0 && isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ficheinter', 'creer')) {
1522 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, '');
1523 }
1524
1525 // Close ticket if status is read
1526 if (isset($object->status) && $object->status >= 0 && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ticket', 'write')) {
1527 print dolGetButtonAction('', $langs->trans('CloseTicket'), 'default', $_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&track_id='.$object->track_id, '');
1528 }
1529
1530 // Abandon ticket if status is read
1531 if (isset($object->status) && $object->status > 0 && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ticket', 'write')) {
1532 print dolGetButtonAction('', $langs->trans('AbandonTicket'), 'default', $_SERVER["PHP_SELF"].'?action=abandon&token='.newToken().'&track_id='.$object->track_id, '');
1533 }
1534
1535 // Re-open ticket
1536 if (!$user->socid && (isset($object->status) && ($object->status == Ticket::STATUS_CLOSED || $object->status == Ticket::STATUS_CANCELED)) && !$user->socid) {
1537 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&track_id='.$object->track_id, '');
1538 }
1539
1540 // Edit ticket
1541 if ($permissiontoedit) {
1542 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoedit);
1543 }
1544
1545 // Clone
1546 if ($permissiontoadd) {
1547 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken(), '', $permissiontoadd);
1548 }
1549
1550 // Delete ticket
1551 if ($user->hasRight('ticket', 'delete') && !$user->socid) {
1552 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&track_id='.$object->track_id, '');
1553 }
1554 }
1555 print '</div>'."\n";
1556 }
1557
1558 // Select mail models is same action as presend
1559 if (GETPOST('modelselected')) {
1560 $action = 'presend';
1561 }
1562 // Set $action to correct value for the case we used presend action to add a message
1563 if (GETPOSTISSET('actionbis') && $action == 'presend') {
1564 $action = 'presend_addmessage';
1565 }
1566
1567 // add a message
1568 if ($action == 'presend' || $action == 'presend_addmessage') {
1569 if ($object->fk_soc > 0) {
1570 $object->fetch_thirdparty();
1571 }
1572
1573 $outputlangs = $langs;
1574 $newlang = '';
1575 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1576 $newlang = GETPOST('lang_id', 'aZ09');
1577 } elseif (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && is_object($object->thirdparty)) {
1578 $newlang = $object->thirdparty->default_lang;
1579 }
1580 if (!empty($newlang)) {
1581 $outputlangs = new Translate("", $conf);
1582 $outputlangs->setDefaultLang($newlang);
1583 }
1584
1585 $arrayoffamiliestoexclude = array('objectamount');
1586
1587 $action = 'add_message'; // action to use to post the message
1588 $modelmail = 'ticket_send';
1589
1590 // Substitution array
1591 $morehtmlright = '';
1592 $help = "";
1593 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude, $object);
1594 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1595 $morehtmlright .= $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("TicketMessageSubstitutionReplacedByGenericValues").'</span>', $help, 1, 'helpclickable', '', 0, 3, 'helpsubstitution');
1596
1597 print '<div>';
1598
1599 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1600
1601 print load_fiche_titre($langs->trans('TicketAddMessage'), $morehtmlright, 'messages@ticket');
1602
1603 print '<hr>';
1604
1605 $formticket = new FormTicket($db);
1606
1607 $formticket->action = $action;
1608 $formticket->track_id = $object->track_id;
1609 $formticket->ref = $object->ref;
1610 $formticket->id = $object->id;
1611 $formticket->trackid = 'tic'.$object->id;
1612
1613 $formticket->withfile = 2;
1614 $formticket->withcancel = 1;
1615 $formticket->param = array('fk_user_create' => $user->id);
1616 $formticket->param['langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
1617
1618 // Table of additional post parameters
1619 $formticket->param['models'] = $modelmail;
1620 $formticket->param['models_id'] = GETPOSTINT('modelmailselected');
1621 //$formticket->param['socid']=$object->fk_soc;
1622 $formticket->param['returnurl'] = $_SERVER["PHP_SELF"].'?track_id='.urldecode($object->track_id);
1623
1624 $formticket->withsubstit = 1;
1625 $formticket->substit = $substitutionarray;
1626 $formticket->backtopage = $backtopage;
1627
1628 $formticket->showMessageForm('100%');
1629 print '</div>';
1630 }
1631
1632 // Show messages on card (Note: this is a duplicate of the view Events/Agenda but on the main tab)
1633 if (getDolGlobalString('TICKET_SHOW_MESSAGES_ON_CARD')) {
1634 $param = '&id='.$object->id;
1635 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1636 $param .= '&contextpage='.$contextpage;
1637 }
1638 if ($limit > 0 && $limit != $conf->liste_limit) {
1639 $param .= '&limit='.$limit;
1640 }
1641 if ($actioncode) {
1642 $param .= '&actioncode='.urlencode($actioncode);
1643 }
1644 if ($search_agenda_label) {
1645 $param .= '&search_agenda_label='.urlencode($search_agenda_label);
1646 }
1647
1648 $morehtmlright = '';
1649
1650 $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
1651 $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
1652
1653 // Show link to add a message (if read and not closed)
1654 $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage" && $action != "add_message";
1655 $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init';
1656 $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', (int) $btnstatus);
1657
1658 // Show link to add event (if read and not closed)
1659 $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage" && $action != "add_message";
1660 $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);
1661 $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', (int) $btnstatus);
1662
1663 print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
1664
1665 // List of all actions
1666 $filters = array();
1667 $filters['search_agenda_label'] = $search_agenda_label;
1668 $filters['search_rowid'] = $search_rowid;
1669
1670 show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
1671 }
1672
1673 if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'add_message') {
1674 print '<div class="fichecenter"><div class="fichehalfleft">';
1675 print '<a name="builddoc"></a>'; // ancre
1676 /*
1677 * Generated documents
1678 */
1679 $filename = dol_sanitizeFileName($object->ref);
1680 $filedir = $upload_dir."/".dol_sanitizeFileName($object->ref);
1681 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1682 $genallowed = $permissiontoadd;
1683 $delallowed = $permissiontodelete;
1684 $codelang = '';
1685 if ($object->fk_soc > 0) {
1686 $object->fetch_thirdparty();
1687 $codelang = $object->thirdparty->default_lang;
1688 }
1689
1690 print $formfile->showdocuments('ticket', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $codelang);
1691
1692 // Show links to link elements
1693 $tmparray = $form->showLinkToObjectBlock($object, array(), array('ticket'), 1);
1694 $linktoelem = $tmparray['linktoelem'];
1695 $htmltoenteralink = $tmparray['htmltoenteralink'];
1696 print $htmltoenteralink;
1697
1698 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1699
1700 // Show direct link to public interface
1701 print '<br><!-- Link to public interface -->'."\n";
1702 print showDirectPublicLink($object).'<br>';
1703 print '</div>';
1704
1705 if (!getDolGlobalString('MAIN_HIDE_MESSAGES_ON_CARD')) {
1706 print '<div class="fichehalfright">';
1707
1708 $MAXEVENT = 10;
1709
1710 $morehtmlcenter = '<div class="nowraponall">';
1711 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/ticket/messaging.php?id='.$object->id);
1712 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/ticket/agenda.php?id='.$object->id);
1713 $morehtmlcenter .= '</div>';
1714
1715 // List of actions on element
1716 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1717 $formactions = new FormActions($db);
1718 $somethingshown = $formactions->showactions($object, 'ticket', $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
1719
1720 print '</div>';
1721 }
1722
1723 print '</div>';
1724 }
1725 }
1726}
1727
1728// End of page
1729llxFooter();
1730$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 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:262
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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $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'.
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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:469
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.