dolibarr 24.0.3
ticket.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2018 Jean-François Ferry <hello@librethic.io>
3 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2023-2025 Charlene Benke <charlene@patas-monkey.com>
7 * Copyright (C) 2023-2024 Benjamin Falière <benjamin.faliere@altairis.fr>
8 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2026 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
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// Put here all includes required by your class file
33require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
34require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
36
37
41class Ticket extends CommonObject
42{
46 public $db;
47
51 public $element = 'ticket';
52
56 public $table_element = 'ticket';
57
61 public $fk_element = 'fk_ticket';
62
66 public $picto = 'ticket';
67
71 public $track_id;
72
76 public $fk_soc;
77
81 public $socid;
82
86 public $fk_contract;
87
91 public $origin_email;
92
96 public $fk_user_create;
97
101 public $fk_user_assign;
102
106 public $subject;
107
111 public $message;
112
116 public $private;
117
123 public $fk_statut;
124
128 public $status;
129
133 public $resolution;
134
138 public $progress;
139
143 public $timing;
144
148 public $type_code;
149
153 public $category_code;
154
158 public $severity_code;
159
163 public $type_label;
164
168 public $category_label;
169
173 public $severity_label;
174
178 public $email_from;
179
183 public $origin_replyto;
184
188 public $origin_references;
189
193 public $datec;
194
198 public $date_read;
199
203 public $date_last_msg_sent;
204
208 public $date_close;
209
213 public $cache_types_tickets;
214
218 public $cache_msgs_ticket;
219
223 public $notify_tiers_at_create;
224
228 public $email_msgid;
229
233 public $email_date;
234
238 public $ip;
239
243 public $lines;
244
248 public $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into images.lib.php
249
253 const STATUS_NOT_READ = 0; // Draft. Not take into account yet.
254 const STATUS_READ = 1; // Ticket was read.
255 const STATUS_ASSIGNED = 2; // Ticket was just assigned to someone. Not in progress yet.
256 const STATUS_IN_PROGRESS = 3; // In progress
257 const STATUS_NEED_MORE_INFO = 5; // Waiting requester feedback
258 const STATUS_WAITING = 7; // On hold
259 const STATUS_CLOSED = 8; // Closed - Solved
260 const STATUS_CANCELED = 9; // Closed - Not solved
261
262
289 // BEGIN MODULEBUILDER PROPERTIES
290 public $fields = array(
291 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -2, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id"),
292 'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 5, 'notnull' => 1, 'index' => 1),
293 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'visible' => 1, 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'index' => 1, 'searchall' => 1, 'comment' => "Reference of object", 'css' => '', 'showoncombobox' => 1),
294 'track_id' => array('type' => 'varchar(255)', 'label' => 'TicketTrackId', 'visible' => -2, 'enabled' => 1, 'position' => 11, 'notnull' => -1, 'searchall' => 1, 'help' => "Help text"),
295 'fk_user_create' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Author', 'visible' => 1, 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'csslist' => 'tdoverflowmax100 maxwidth150onsmartphone'),
296 'origin_email' => array('type' => 'mail', 'label' => 'OriginEmail', 'visible' => -2, 'enabled' => 1, 'position' => 16, 'notnull' => 1, 'index' => 1, 'searchall' => 1, 'comment' => "Reference of object", 'csslist' => 'tdoverflowmax150'),
297 'origin_replyto' => array('type' => 'mail', 'label' => 'EmailReplyto', 'visible' => -2, 'enabled' => 1, 'position' => 17, 'notnull' => 1, 'index' => 1, 'searchall' => 1, 'comment' => "Email to reply to", 'csslist' => 'tdoverflowmax150'),
298 'origin_references' => array('type' => 'text', 'label' => 'EmailReferences', 'visible' => -2, 'enabled' => 1, 'position' => 18, 'notnull' => 1, 'index' => 1, 'searchall' => 1, 'comment' => "References from origin email", 'csslist' => 'tdoverflowmax150'),
299 'subject' => array('type' => 'varchar(255)', 'label' => 'Subject', 'visible' => 1, 'enabled' => 1, 'position' => 19, 'notnull' => -1, 'searchall' => 1, 'help' => "", 'css' => 'maxwidth200 tdoverflowmax200', 'csslist' => 'tdoverflowmax250', 'autofocusoncreate' => 1),
300 'type_code' => array('type' => 'varchar(32)', 'label' => 'Type', 'visible' => 1, 'enabled' => 1, 'position' => 20, 'notnull' => -1, 'help' => "", 'csslist' => 'tdoverflowmax100'),
301 'category_code' => array('type' => 'varchar(32)', 'label' => 'TicketCategory', 'visible' => -1, 'enabled' => 1, 'position' => 21, 'notnull' => -1, 'help' => "", 'css' => 'maxwidth100 tdoverflowmax200'),
302 'severity_code' => array('type' => 'varchar(32)', 'label' => 'Severity', 'visible' => 1, 'enabled' => 1, 'position' => 22, 'notnull' => -1, 'help' => "", 'css' => 'maxwidth100 tdoverflowmax100'),
303 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'visible' => 1, 'enabled' => 'isModEnabled("societe")', 'position' => 50, 'notnull' => -1, 'index' => 1, 'searchall' => 1, 'help' => "OrganizationEventLinkToThirdParty", 'css' => 'tdoverflowmax150 maxwidth150onsmartphone'),
304 'notify_tiers_at_create' => array('type' => 'integer', 'label' => 'NotifyThirdparty', 'visible' => -1, 'enabled' => 0, 'position' => 51, 'notnull' => 1, 'index' => 1),
305 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php', 'label' => 'Project', 'visible' => -1, 'enabled' => 'isModEnabled("project")', 'position' => 52, 'notnull' => -1, 'index' => 1, 'help' => "LinkToProject"),
306 'fk_contract' => array('type' => 'integer:Contrat:contrat/class/contrat.class.php', 'label' => 'Contract', 'visible' => -1, 'enabled' => 'isModEnabled("contract")', 'position' => 53, 'notnull' => -1, 'index' => 1, 'help' => "LinkToContract"),
307 //'timing' => array('type'=>'varchar(20)', 'label'=>'Timing', 'visible'=>-1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'help'=>""), // what is this ?
308 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => 1, 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'csslist' => 'nowraponall'),
309 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -1, 'enabled' => 1, 'position' => 501, 'notnull' => 1),
310 'date_read' => array('type' => 'datetime', 'label' => 'DateReading', 'visible' => -1, 'enabled' => 1, 'position' => 505, 'notnull' => 1, 'csslist' => 'nowraponall'),
311 'date_last_msg_sent' => array('type' => 'datetime', 'label' => 'TicketLastMessageDate', 'visible' => 0, 'enabled' => 1, 'position' => 506, 'notnull' => -1),
312 'fk_user_assign' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'AssignedTo', 'visible' => 1, 'enabled' => 1, 'position' => 507, 'notnull' => 1, 'csslist' => 'tdoverflowmax100 maxwidth150onsmartphone'),
313 'date_close' => array('type' => 'datetime', 'label' => 'TicketCloseOn', 'visible' => -1, 'enabled' => 1, 'position' => 510, 'notnull' => 1),
314 'message' => array('type' => 'html', 'label' => 'Message', 'visible' => -2, 'enabled' => 1, 'position' => 540, 'notnull' => -1,),
315 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 110),
316 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 115),
317 'email_msgid' => array('type' => 'varchar(255)', 'label' => 'EmailMsgID', 'visible' => -2, 'enabled' => 1, 'position' => 540, 'notnull' => -1, 'help' => 'EmailMsgIDDesc', 'csslist' => 'tdoverflowmax100'),
318 'email_date' => array('type' => 'datetime', 'label' => 'EmailDate', 'visible' => -2, 'enabled' => 1, 'position' => 541),
319 'progress' => array('type' => 'integer', 'label' => 'Progression', 'visible' => -1, 'enabled' => 1, 'position' => 540, 'notnull' => -1, 'css' => 'right', 'help' => "", 'isameasure' => 1, 'csslist' => 'width50'),
320 'resolution' => array('type' => 'integer', 'label' => 'Resolution', 'visible' => -1, 'enabled' => 'getDolGlobalString("TICKET_ENABLE_RESOLUTION")', 'position' => 550, 'notnull' => 1),
321 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'PDFTemplate', 'enabled' => 1, 'visible' => 0, 'position' => 560),
322 'extraparams' => array('type' => 'varchar(255)', 'label' => 'Extraparams', 'enabled' => 1, 'visible' => 0, 'position' => 570),
323 'fk_statut' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'position' => 600, 'notnull' => 1, 'index' => 1, 'arrayofkeyval' => array(0 => 'Unread', 1 => 'Read', 2 => 'Assigned', 3 => 'InProgress', 5 => 'NeedMoreInformation', 7 => 'OnHold', 8 => 'SolvedClosed', 9 => 'Deleted')),
324 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 900),
325 );
326 // END MODULEBUILDER PROPERTIES
327
328
334 public function __construct(DoliDB $db)
335 {
336 $this->db = $db;
337
338 $this->ismultientitymanaged = 1;
339 $this->isextrafieldmanaged = 1;
340
341 $this->labelStatusShort = array(
342 self::STATUS_NOT_READ => 'Unread',
343 self::STATUS_READ => 'Read',
344 self::STATUS_ASSIGNED => 'Assigned',
345 self::STATUS_IN_PROGRESS => 'InProgress',
346 self::STATUS_NEED_MORE_INFO => 'NeedMoreInformationShort',
347 self::STATUS_WAITING => 'OnHold',
348 self::STATUS_CLOSED => 'SolvedClosed',
349 self::STATUS_CANCELED => 'Canceled'
350 );
351 $this->labelStatus = array(
352 self::STATUS_NOT_READ => 'Unread',
353 self::STATUS_READ => 'Read',
354 self::STATUS_ASSIGNED => 'Assigned',
355 self::STATUS_IN_PROGRESS => 'InProgress',
356 self::STATUS_NEED_MORE_INFO => 'NeedMoreInformation',
357 self::STATUS_WAITING => 'OnHold',
358 self::STATUS_CLOSED => 'SolvedClosed',
359 self::STATUS_CANCELED => 'Canceled'
360 );
361
362 if (!getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
363 unset($this->fields['fk_statut']['arrayofkeyval'][self::STATUS_WAITING]);
364 unset($this->labelStatusShort[self::STATUS_WAITING]);
365 unset($this->labelStatus[self::STATUS_WAITING]);
366 }
367 }
368
375 private function verify()
376 {
377 $this->errors = array();
378
379 $result = 0;
380
381 // Clean parameters
382 if (isset($this->ref)) {
383 $this->ref = trim($this->ref);
384 }
385
386 if (isset($this->track_id)) {
387 $this->track_id = trim($this->track_id);
388 }
389
390 if (isset($this->fk_soc)) {
391 $this->fk_soc = (int) $this->fk_soc;
392 }
393
394 if (isset($this->fk_project)) {
395 $this->fk_project = (int) $this->fk_project;
396 }
397
398 if (isset($this->origin_email)) {
399 $this->origin_email = trim($this->origin_email);
400 }
401
402 if (isset($this->fk_user_create)) {
403 $this->fk_user_create = (int) $this->fk_user_create;
404 }
405
406 if (isset($this->fk_user_assign)) {
407 $this->fk_user_assign = (int) $this->fk_user_assign;
408 }
409
410 if (isset($this->subject)) {
411 $this->subject = trim($this->subject);
412 }
413
414 if (isset($this->message)) {
415 $this->message = trim($this->message);
416 if (dol_strlen($this->message) > 65000) {
417 global $langs;
418 $langs->loadLangs(array('errors', 'ticket'));
419 $this->errors[] = $langs->trans('ErrorFieldTooLong', $langs->transnoentitiesnoconv('InitialMessage'));
420 dol_syslog(get_class($this).'::create error -1 message too long', LOG_ERR);
421 $result = -1;
422 }
423 }
424
425 if (isset($this->status)) {
426 $this->status = (int) $this->status;
427 }
428
429 if (isset($this->resolution)) {
430 $this->resolution = (int) $this->resolution;
431 }
432
433 if (isset($this->progress)) {
434 $this->progress = (int) $this->progress;
435 }
436
437 if (isset($this->timing)) {
438 $this->timing = trim($this->timing);
439 }
440
441 if (isset($this->type_code)) {
442 $this->type_code = trim($this->type_code);
443 }
444
445 if (isset($this->category_code)) {
446 $this->category_code = trim($this->category_code);
447 }
448
449 if (isset($this->severity_code)) {
450 $this->severity_code = trim($this->severity_code);
451 }
452
453 if (empty($this->ref)) {
454 $this->errors[] = 'ErrorTicketRefRequired';
455 dol_syslog(get_class($this)."::create error -1 ref null", LOG_ERR);
456 $result = -1;
457 }
458
459 return $result;
460 }
461
469 public function checkExistingRef(string $action, string $getRef)
470 {
471 $test = new self($this->db);
472
473 if ($test->fetch(0, $getRef) > 0) {
474 if (($action == 'add') || ($action == 'update' && $this->ref != $getRef)) {
475 return true;
476 }
477 }
478
479 $this->ref = $getRef;
480 return false;
481 }
482
490 public function create($user, $notrigger = 0)
491 {
492 global $conf;
493
494 $error = 0;
495
496 // Clean parameters
497 if (empty($this->datec)) {
498 $this->datec = dol_now();
499 }
500 if (empty($this->track_id)) {
501 $this->track_id = generate_random_id(16);
502 }
503
504 // Check more parameters
505 // If error, this->errors[] is filled
506 $result = $this->verify();
507
508 if ($result >= 0) {
509 // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active
510 $this->entity = setEntity($this);
511
512 // Insert request
513 $sql = "INSERT INTO ".MAIN_DB_PREFIX."ticket(";
514 $sql .= "ref,";
515 $sql .= "track_id,";
516 $sql .= "fk_soc,";
517 $sql .= "fk_project,";
518 $sql .= "fk_contract,";
519 $sql .= "origin_email,";
520 $sql .= "origin_replyto,";
521 $sql .= "origin_references,";
522 $sql .= "fk_user_create,";
523 $sql .= "fk_user_assign,";
524 $sql .= "email_msgid,";
525 $sql .= "email_date,";
526 $sql .= "subject,";
527 $sql .= "message,";
528 $sql .= "note_private,";
529 $sql .= "note_public,";
530 $sql .= "fk_statut,";
531 $sql .= "resolution,";
532 $sql .= "progress,";
533 $sql .= "timing,";
534 $sql .= "type_code,";
535 $sql .= "category_code,";
536 $sql .= "severity_code,";
537 $sql .= "datec,";
538 $sql .= "date_read,";
539 $sql .= "date_close,";
540 $sql .= "entity,";
541 $sql .= "notify_tiers_at_create,";
542 $sql .= "model_pdf,";
543 $sql .= "ip";
544 $sql .= ") VALUES (";
545 $sql .= " ".(!isset($this->ref) ? '' : "'".$this->db->escape($this->ref)."'").",";
546 $sql .= " ".(!isset($this->track_id) ? 'NULL' : "'".$this->db->escape($this->track_id)."'").",";
547 $sql .= " ".($this->fk_soc > 0 ? ((int) $this->fk_soc) : "null").",";
548 $sql .= " ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null").",";
549 $sql .= " ".($this->fk_contract > 0 ? ((int) $this->fk_contract) : "null").",";
550 $sql .= " ".(!isset($this->origin_email) ? 'NULL' : "'".$this->db->escape($this->origin_email)."'").",";
551 $sql .= " ".(!isset($this->origin_replyto) ? 'NULL' : "'".$this->db->escape($this->origin_replyto)."'").",";
552 $sql .= " ".(!isset($this->origin_references) ? 'NULL' : "'".$this->db->escape($this->origin_references)."'").",";
553 $sql .= " ".(!isset($this->fk_user_create) ? ($user->id > 0 ? ((int) $user->id) : 'NULL') : ($this->fk_user_create > 0 ? ((int) $this->fk_user_create) : 'NULL')).",";
554 $sql .= " ".($this->fk_user_assign > 0 ? ((int) $this->fk_user_assign) : 'NULL').",";
555 $sql .= " ".(empty($this->email_msgid) ? 'NULL' : "'".$this->db->escape($this->email_msgid)."'").",";
556 $sql .= " ".(!isDolTms($this->email_date) ? 'NULL' : "'".$this->db->idate($this->email_date)."'").",";
557 $sql .= " ".(!isset($this->subject) ? 'NULL' : "'".$this->db->escape($this->subject)."'").",";
558 $sql .= " ".(!isset($this->message) ? 'NULL' : "'".$this->db->escape($this->message)."'").",";
559 $sql .= " ".(!isset($this->note_private) ? 'NULL' : "'".$this->db->escape($this->note_private)."'").",";
560 $sql .= " ".(!isset($this->note_public) ? 'NULL' : "'".$this->db->escape($this->note_public)."'").",";
561 $sql .= " ".(!isset($this->status) ? '0' : ((int) $this->status)).",";
562 $sql .= " ".(!isset($this->resolution) ? 'NULL' : ((int) $this->resolution)).",";
563 $sql .= " ".(!isset($this->progress) ? '0' : ((int) $this->progress)).",";
564 $sql .= " ".(!isset($this->timing) ? 'NULL' : "'".$this->db->escape($this->timing)."'").",";
565 $sql .= " ".(!isset($this->type_code) ? 'NULL' : "'".$this->db->escape($this->type_code)."'").",";
566 $sql .= " ".(empty($this->category_code) || $this->category_code == '-1' ? 'NULL' : "'".$this->db->escape($this->category_code)."'").",";
567 $sql .= " ".(!isset($this->severity_code) ? 'NULL' : "'".$this->db->escape($this->severity_code)."'").",";
568 $sql .= " ".(!isDolTms($this->datec) ? 'NULL' : "'".$this->db->idate($this->datec)."'").",";
569 $sql .= " ".(!isset($this->date_read) || dol_strlen((string) $this->date_read) == 0 ? 'NULL' : "'".$this->db->idate($this->date_read)."'").",";
570 $sql .= " ".(!isset($this->date_close) || dol_strlen((string) $this->date_close) == 0 ? 'NULL' : "'".$this->db->idate($this->date_close)."'");
571 $sql .= ", ".((int) $this->entity);
572 $sql .= ", ".(!isset($this->notify_tiers_at_create) ? 1 : ((int) $this->notify_tiers_at_create));
573 $sql .= ", '".$this->db->escape($this->model_pdf)."'";
574 $sql .= ", ".(!isset($this->ip) ? 'NULL' : "'".$this->db->escape($this->ip)."'");
575 $sql .= ")";
576
577 $this->db->begin();
578
579 dol_syslog(get_class($this)."::create", LOG_DEBUG);
580 $resql = $this->db->query($sql);
581 if (!$resql) {
582 $error++;
583 $this->errors[] = "Error ".$this->db->lasterror();
584 }
585
586 if (!$error) {
587 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ticket");
588 }
589
590 if (!$error && getDolGlobalString('TICKET_ADD_AUTHOR_AS_CONTACT') && empty($this->context["createdfrompublicinterface"])) {
591 // add creator as contributor
592
593 // We first check the type of contact (internal or external)
594 if (!empty($user->socid) && !empty($user->contact_id) && getDolGlobalInt('TICKET_ADD_AUTHOR_AS_CONTACT') == 2) {
595 $contact_type = 'external';
596 $contributor_id = $user->contact_id;
597 } else {
598 $contact_type = 'internal';
599 $contributor_id = $user->id;
600 }
601
602 // We add the creator as contributor
603 if ($this->add_contact($contributor_id, 'CONTRIBUTOR', $contact_type) < 0) {
604 $error++;
605 }
606 }
607
608 if (!$error && $this->fk_user_assign > 0) {
609 if ($this->add_contact($this->fk_user_assign, 'SUPPORTTEC', 'internal') < 0) {
610 $error++;
611 }
612 }
613
614
615 //Update extrafield
616 if (!$error) {
617 $result = $this->insertExtraFields();
618 if ($result < 0) {
619 $error++;
620 }
621 }
622
623 if (!$error && !$notrigger) {
624 // Call trigger
625 $result = $this->call_trigger('TICKET_CREATE', $user);
626 if ($result < 0) {
627 $error++;
628 }
629 // End call triggers
630 }
631
632 // Commit or rollback
633 if ($error) {
634 foreach ($this->errors as $errmsg) {
635 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
636 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
637 }
638 $this->db->rollback();
639 return -1 * $error;
640 } else {
641 $this->db->commit();
642 return $this->id;
643 }
644 } else {
645 dol_syslog(get_class($this)."::Create fails verify ".implode(',', $this->errors), LOG_WARNING);
646 return -3;
647 }
648 }
649
659 public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '')
660 {
661 global $langs;
662
663 // Check parameters
664 if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
665 $this->error = 'ErrorWrongParameters';
666 dol_print_error(null, get_class($this)."::fetch ".$this->error);
667 return -1;
668 }
669
670 $sql = "SELECT";
671 $sql .= " t.rowid,";
672 $sql .= " t.entity,";
673 $sql .= " t.ref,";
674 $sql .= " t.track_id,";
675 $sql .= " t.fk_soc,";
676 $sql .= " t.fk_project,";
677 $sql .= " t.fk_contract,";
678 $sql .= " t.origin_email,";
679 $sql .= " t.origin_replyto,";
680 $sql .= " t.origin_references,";
681 $sql .= " t.fk_user_create,";
682 $sql .= " t.fk_user_assign,";
683 $sql .= " t.email_msgid,";
684 $sql .= " t.email_date,";
685 $sql .= " t.subject,";
686 $sql .= " t.message,";
687 $sql .= " t.note_private,";
688 $sql .= " t.note_public,";
689 $sql .= " t.fk_statut as status,";
690 $sql .= " t.resolution,";
691 $sql .= " t.progress,";
692 $sql .= " t.timing,";
693 $sql .= " t.type_code,";
694 $sql .= " t.category_code,";
695 $sql .= " t.severity_code,";
696 $sql .= " t.datec,";
697 $sql .= " t.date_read,";
698 $sql .= " t.date_last_msg_sent,";
699 $sql .= " t.date_close,";
700 $sql .= " t.tms,";
701 $sql .= " t.model_pdf,";
702 $sql .= " t.extraparams,";
703 $sql .= " t.ip,";
704 $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
705 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
706 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
707 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
708 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
709
710 if ($id) {
711 $sql .= " WHERE t.rowid = ".((int) $id);
712 } else {
713 $sql .= " WHERE t.entity IN (".getEntity($this->element, 1).")";
714 if (!empty($ref)) {
715 $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
716 } elseif ($track_id) {
717 $sql .= " AND t.track_id = '".$this->db->escape($track_id)."'";
718 } else {
719 $sql .= " AND t.email_msgid = '".$this->db->escape($email_msgid)."'";
720 }
721 }
722
723 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
724 $resql = $this->db->query($sql);
725 if ($resql) {
726 if ($this->db->num_rows($resql)) {
727 $obj = $this->db->fetch_object($resql);
728
729 $this->id = $obj->rowid;
730 $this->entity = $obj->entity;
731 $this->ref = $obj->ref;
732 $this->track_id = $obj->track_id;
733 $this->fk_soc = $obj->fk_soc;
734 $this->socid = $obj->fk_soc; // for fetch_thirdparty() method
735 $this->fk_project = $obj->fk_project;
736 $this->fk_contract = $obj->fk_contract;
737 $this->origin_email = $obj->origin_email;
738 $this->origin_replyto = $obj->origin_replyto;
739 $this->origin_references = $obj->origin_references;
740 $this->fk_user_create = $obj->fk_user_create;
741 $this->fk_user_assign = $obj->fk_user_assign;
742 $this->email_msgid = $obj->email_msgid;
743 $this->email_date = $this->db->jdate($obj->email_date);
744 $this->subject = $obj->subject;
745 $this->message = $obj->message;
746 $this->note_private = $obj->note_private;
747 $this->note_public = $obj->note_public;
748 $this->model_pdf = $obj->model_pdf;
749 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array();
750 $this->ip = $obj->ip;
751
752 $this->status = $obj->status;
753 $this->fk_statut = $this->status; // For backward compatibility
754
755 $this->resolution = $obj->resolution;
756 $this->progress = $obj->progress;
757 $this->timing = $obj->timing;
758
759 $this->type_code = $obj->type_code;
760 $label_type = ($langs->trans("TicketTypeShort".$obj->type_code) != "TicketTypeShort".$obj->type_code ? $langs->trans("TicketTypeShort".$obj->type_code) : ($obj->type_label != '-' ? $obj->type_label : ''));
761 $this->type_label = $label_type;
762
763 $this->category_code = $obj->category_code;
764 $label_category = ($langs->trans("TicketCategoryShort".$obj->category_code) != "TicketCategoryShort".$obj->category_code ? $langs->trans("TicketCategoryShort".$obj->category_code) : ($obj->category_label != '-' ? $obj->category_label : ''));
765 $this->category_label = $label_category;
766
767 $this->severity_code = $obj->severity_code;
768 $label_severity = ($langs->trans("TicketSeverityShort".$obj->severity_code) != "TicketSeverityShort".$obj->severity_code ? $langs->trans("TicketSeverityShort".$obj->severity_code) : ($obj->severity_label != '-' ? $obj->severity_label : ''));
769 $this->severity_label = $label_severity;
770
771 $this->datec = $this->db->jdate($obj->datec);
772 $this->date_creation = $this->db->jdate($obj->datec);
773 $this->date_read = $this->db->jdate($obj->date_read);
774 $this->date_validation = $this->db->jdate($obj->date_read);
775 $this->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
776 $this->date_close = $this->db->jdate($obj->date_close);
777 $this->tms = $this->db->jdate($obj->tms);
778 $this->date_modification = $this->db->jdate($obj->tms);
779
780 $this->fetch_optionals();
781
782 $this->db->free($resql);
783 return 1;
784 } else {
785 return 0;
786 }
787 } else {
788 $this->error = "Error ".$this->db->lasterror();
789 dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
790 return -1;
791 }
792 }
793
806 public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $limit = 0, $offset = 0, $arch = 0, $filter = '')
807 {
808 global $langs, $extrafields;
809
810 // fetch optionals attributes and labels
811 $extrafields->fetch_name_optionals_label($this->table_element);
812
813 $sql = "SELECT";
814 $sql .= " t.rowid,";
815 $sql .= " t.ref,";
816 $sql .= " t.track_id,";
817 $sql .= " t.fk_soc,";
818 $sql .= " t.fk_project,";
819 $sql .= " t.fk_contract,";
820 $sql .= " t.origin_email,";
821 $sql .= " t.origin_replyto,";
822 $sql .= " t.origin_references,";
823 $sql .= " t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
824 $sql .= " t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
825 $sql .= " t.subject,";
826 $sql .= " t.message,";
827 $sql .= " t.note_private,";
828 $sql .= " t.note_public,";
829 $sql .= " t.fk_statut as status,";
830 $sql .= " t.resolution,";
831 $sql .= " t.progress,";
832 $sql .= " t.timing,";
833 $sql .= " t.type_code,";
834 $sql .= " t.category_code,";
835 $sql .= " t.severity_code,";
836 $sql .= " t.datec,";
837 $sql .= " t.date_read,";
838 $sql .= " t.date_last_msg_sent,";
839 $sql .= " t.date_close,";
840 $sql .= " t.tms,";
841 $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
842 // Add fields for extrafields
843 if ($extrafields->attributes[$this->table_element]['count'] > 0) {
844 foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
845 $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? ",ef.".$key." as options_".$key : '');
846 }
847 }
848 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
849 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code = t.type_code";
850 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code = t.category_code";
851 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code = t.severity_code";
852 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc";
853 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid = t.fk_user_create";
854 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON ua.rowid = t.fk_user_assign";
855 if ($extrafields->attributes[$this->table_element]['count'] > 0) {
856 if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
857 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ticket_extrafields as ef on (t.rowid = ef.fk_object)";
858 }
859 }
860 $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
861
862 // Manage filter
863 if (is_array($filter)) {
864 foreach ($filter as $key => $value) {
865 if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
866 $sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape((string) $value)."'";
867 } elseif (($key == 't.fk_user_assign') || ($key == 't.type_code') || ($key == 't.category_code') || ($key == 't.severity_code') || ($key == 't.fk_soc')) {
868 $sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape((string) $value)."'";
869 } elseif ($key == 't.fk_statut') {
870 if (is_array($value) && count($value) > 0) {
871 $sql .= " AND ".$this->db->sanitize($key)." IN (".$this->db->sanitize(implode(',', $value)).")";
872 } else {
873 $sql .= " AND ".$this->db->sanitize($key).' = '.((int) $value);
874 }
875 } elseif ($key == 't.fk_contract') {
876 $sql .= " AND ".$this->db->sanitize($key).' = '.((int) $value);
877 } else {
878 $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike((string) $value))."%'";
879 }
880 }
881
882 $filter = '';
883 }
884
885 // Manage filter
886 $errormessage = '';
887 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
888 if ($errormessage) {
889 $this->errors[] = $errormessage;
890 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
891 return -1;
892 }
893
894 // Case of external user
895 $socid = $user->socid ?: 0;
896 // If the internal user must only see his customers, force searching by him
897 $search_sale = 0;
898 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
899 $search_sale = $user->id;
900 }
901 // Search on sale representative
902 if ($search_sale && $search_sale != '-1') {
903 if ($search_sale == -2) {
904 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
905 } elseif ($search_sale > 0) {
906 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
907 }
908 }
909 // Search on socid
910 if ($socid) {
911 $sql .= " AND t.fk_soc = ".((int) $socid);
912 }
913
914 $sql .= $this->db->order($sortfield, $sortorder);
915 if (!empty($limit)) {
916 $sql .= $this->db->plimit($limit + 1, $offset);
917 }
918
919 dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
920 $resql = $this->db->query($sql);
921
922 if ($resql) {
923 $this->lines = array();
924
925 $num = $this->db->num_rows($resql);
926 $i = 0;
927
928 if ($num) {
929 while ($i < $num) {
930 $obj = $this->db->fetch_object($resql);
931
932 $line = new self($this->db);
933
934 $line->id = $obj->rowid;
935 //$line->rowid = $obj->rowid;
936 $line->ref = $obj->ref;
937 $line->track_id = $obj->track_id;
938 $line->fk_soc = $obj->fk_soc;
939 $line->fk_project = $obj->fk_project;
940 $line->fk_contract = $obj->fk_contract;
941 $line->origin_email = $obj->origin_email;
942 $line->origin_replyto = $obj->origin_replyto;
943 $line->origin_references = $obj->origin_references;
944
945 $line->fk_user_create = $obj->fk_user_create;
946 $line->fk_user_assign = $obj->fk_user_assign;
947
948 $line->subject = $obj->subject;
949 $line->message = $obj->message;
950 $line->note_private = $obj->note_private;
951 $line->note_public = $obj->note_public;
952 $line->fk_statut = $obj->status;
953 $line->status = $obj->status;
954 $line->resolution = $obj->resolution;
955 $line->progress = $obj->progress;
956 $line->timing = $obj->timing;
957
958 $label_type = ($langs->trans("TicketTypeShort".$obj->type_code) != "TicketTypeShort".$obj->type_code ? $langs->trans("TicketTypeShort".$obj->type_code) : ($obj->type_label != '-' ? $obj->type_label : ''));
959 $line->type_label = $label_type;
960
961 $this->category_code = $obj->category_code;
962 $label_category = ($langs->trans("TicketCategoryShort".$obj->category_code) != "TicketCategoryShort".$obj->category_code ? $langs->trans("TicketCategoryShort".$obj->category_code) : ($obj->category_label != '-' ? $obj->category_label : ''));
963 $line->category_label = $label_category;
964
965 $this->severity_code = $obj->severity_code;
966 $label_severity = ($langs->trans("TicketSeverityShort".$obj->severity_code) != "TicketSeverityShort".$obj->severity_code ? $langs->trans("TicketSeverityShort".$obj->severity_code) : ($obj->severity_label != '-' ? $obj->severity_label : ''));
967 $line->severity_label = $label_severity;
968
969 $line->datec = $this->db->jdate($obj->datec);
970 $line->date_read = $this->db->jdate($obj->date_read);
971 $line->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
972 $line->date_close = $this->db->jdate($obj->date_close);
973
974 // Extra fields
975 if ($extrafields->attributes[$this->table_element]['count'] > 0) {
976 if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
977 foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
978 $tmpkey = 'options_'.$key;
979 $line->{$tmpkey} = $obj->$tmpkey;
980 }
981 }
982 }
983 $this->lines[$i] = $line;
984 $i++;
985 }
986 }
987 $this->db->free($resql);
988 return $num;
989 } else {
990 $this->error = "Error ".$this->db->lasterror();
991 dol_syslog(get_class($this)."::fetchAll ".$this->error, LOG_ERR);
992 return -1;
993 }
994 }
995
1003 public function update($user, $notrigger = 0)
1004 {
1005 $error = 0;
1006
1007 // $this->oldcopy should have been set by the caller of update
1008 //if (empty($this->oldcopy)) {
1009 // dol_syslog("this->oldcopy should have been set by the caller of update (here properties were already modified)", LOG_WARNING);
1010 // $this->oldcopy = dol_clone($this, 2);
1011 //}
1012
1013 // Clean parameters
1014 if (isset($this->ref)) {
1015 $this->ref = trim($this->ref);
1016 }
1017
1018 if (isset($this->track_id)) {
1019 $this->track_id = trim($this->track_id);
1020 }
1021
1022 if (isset($this->fk_soc)) {
1023 $this->fk_soc = (int) $this->fk_soc;
1024 }
1025
1026 if (isset($this->fk_project)) {
1027 $this->fk_project = (int) $this->fk_project;
1028 }
1029
1030 if (isset($this->fk_contract)) {
1031 $this->fk_contract = (int) $this->fk_contract;
1032 }
1033
1034 if (isset($this->origin_email)) {
1035 $this->origin_email = trim($this->origin_email);
1036 }
1037
1038 if (isset($this->fk_user_create)) {
1039 $this->fk_user_create = (int) $this->fk_user_create;
1040 }
1041
1042 if (isset($this->fk_user_assign)) {
1043 $this->fk_user_assign = (int) $this->fk_user_assign;
1044 }
1045
1046 if (isset($this->subject)) {
1047 $this->subject = trim($this->subject);
1048 }
1049
1050 if (isset($this->message)) {
1051 $this->message = trim($this->message);
1052 if (dol_strlen($this->message) > 65000) {
1053 global $langs;
1054 $langs->loadLangs(array('errors', 'ticket'));
1055 $this->errors[] = $langs->trans('ErrorFieldTooLong', $langs->transnoentitiesnoconv('InitialMessage'));
1056 dol_syslog(get_class($this).'::update error -1 message too long', LOG_ERR);
1057 return -1;
1058 }
1059 }
1060
1061 if (isset($this->status)) {
1062 $this->status = (int) $this->status;
1063 }
1064
1065 if (isset($this->resolution)) {
1066 $this->resolution = (int) $this->resolution;
1067 }
1068
1069 if (isset($this->progress)) {
1070 $this->progress = (int) $this->progress;
1071 }
1072
1073 if (isset($this->timing)) {
1074 $this->timing = trim($this->timing);
1075 }
1076
1077 if (isset($this->type_code)) {
1078 $this->type_code = trim($this->type_code);
1079 }
1080
1081 if (isset($this->category_code)) {
1082 $this->category_code = trim($this->category_code);
1083 }
1084
1085 if (isset($this->severity_code)) {
1086 $this->severity_code = trim($this->severity_code);
1087 }
1088 if (isset($this->model_pdf)) {
1089 $this->model_pdf = trim($this->model_pdf);
1090 }
1091 // Check parameters
1092 // Put here code to add a control on parameters values
1093 // Update request
1094 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket SET";
1095 $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "").",";
1096 $sql .= " track_id=".(isset($this->track_id) ? "'".$this->db->escape($this->track_id)."'" : "null").",";
1097 $sql .= " fk_soc=".(isset($this->fk_soc) ? (int) $this->fk_soc : "null").",";
1098 $sql .= " fk_project=".(isset($this->fk_project) ? (int) $this->fk_project : "null").",";
1099 $sql .= " fk_contract=".(isset($this->fk_contract) ? (int) $this->fk_contract : "null").",";
1100 $sql .= " origin_email=".(isset($this->origin_email) ? "'".$this->db->escape($this->origin_email)."'" : "null").",";
1101 $sql .= " origin_replyto=".(isset($this->origin_replyto) ? "'".$this->db->escape($this->origin_replyto)."'" : "null").",";
1102 $sql .= " origin_references=".(isset($this->origin_references) ? "'".$this->db->escape($this->origin_references)."'" : "null").",";
1103 $sql .= " fk_user_create=".(isset($this->fk_user_create) ? (int) $this->fk_user_create : "null").",";
1104 $sql .= " fk_user_assign=".(isset($this->fk_user_assign) ? (int) $this->fk_user_assign : "null").",";
1105 $sql .= " subject=".(isset($this->subject) ? "'".$this->db->escape($this->subject)."'" : "null").",";
1106 $sql .= " message=".(isset($this->message) ? "'".$this->db->escape($this->message)."'" : "null").",";
1107 $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
1108 $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
1109 $sql .= " fk_statut=".(isset($this->status) ? (int) $this->status : "0").",";
1110 $sql .= " resolution=".(isset($this->resolution) ? (int) $this->resolution : "null").",";
1111 $sql .= " progress=".(isset($this->progress) ? "'".$this->db->escape((string) $this->progress)."'" : "null").",";
1112 $sql .= " timing=".(isset($this->timing) ? "'".$this->db->escape($this->timing)."'" : "null").",";
1113 $sql .= " type_code=".(isset($this->type_code) ? "'".$this->db->escape($this->type_code)."'" : "null").",";
1114 $sql .= " category_code=".(isset($this->category_code) ? "'".$this->db->escape($this->category_code)."'" : "null").",";
1115 $sql .= " severity_code=".(isset($this->severity_code) ? "'".$this->db->escape($this->severity_code)."'" : "null").",";
1116 $sql .= " datec=".(isDolTms($this->datec) ? "'".$this->db->idate($this->datec)."'" : 'null').",";
1117 $sql .= " date_read=".(dol_strlen((string) $this->date_read) != 0 ? "'".$this->db->idate($this->date_read)."'" : 'null').",";
1118 $sql .= " date_last_msg_sent=".(dol_strlen((string) $this->date_last_msg_sent) != 0 ? "'".$this->db->idate($this->date_last_msg_sent)."'" : 'null').",";
1119 $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").",";
1120 $sql .= " date_close=".(dol_strlen((string) $this->date_close) != 0 ? "'".$this->db->idate($this->date_close)."'" : 'null');
1121 $sql .= " WHERE rowid=".((int) $this->id);
1122
1123 $this->db->begin();
1124
1125 $resql = $this->db->query($sql);
1126 if (!$resql) {
1127 $error++;
1128 $this->errors[] = "Error ".$this->db->lasterror();
1129 }
1130
1131 if (!$error) {
1132 // Update extrafields
1133 $result = $this->insertExtraFields();
1134 if ($result < 0) {
1135 $error++;
1136 }
1137 }
1138
1139 if (!$error && !$notrigger) {
1140 // Call trigger
1141 $result = $this->call_trigger('TICKET_MODIFY', $user);
1142 if ($result < 0) {
1143 $error++;
1144 }
1145 // End call triggers
1146 }
1147
1148 // Commit or rollback
1149 if ($error) {
1150 foreach ($this->errors as $errmsg) {
1151 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1152 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1153 }
1154 $this->db->rollback();
1155 return -1 * $error;
1156 } else {
1157 $this->db->commit();
1158 return 1;
1159 }
1160 }
1161
1169 public function delete($user, $notrigger = 0)
1170 {
1171 $error = 0;
1172
1173 $this->db->begin();
1174
1175 if (!$notrigger) {
1176 // Call trigger
1177 $result = $this->call_trigger('TICKET_DELETE', $user);
1178 if ($result < 0) {
1179 $error++;
1180 }
1181 // End call triggers
1182 }
1183
1184 if (!$error) {
1185 // Delete linked contacts
1186 $res = $this->delete_linked_contact();
1187 if ($res < 0) {
1188 dol_syslog(get_class($this)."::delete error", LOG_ERR);
1189 $error++;
1190 }
1191 }
1192
1193 if (!$error) {
1194 // Delete linked object
1195 $res = $this->deleteObjectLinked();
1196 if ($res < 0) {
1197 $error++;
1198 }
1199 }
1200
1201 // Removed extrafields
1202 if (!$error) {
1203 $result = $this->deleteExtraFields();
1204 if ($result < 0) {
1205 $error++;
1206 dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1207 }
1208 }
1209
1210 // Delete all child tables
1211
1212 if (!$error) {
1213 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_ticket";
1214 $sql .= " WHERE fk_ticket = ".(int) $this->id;
1215
1216 $result = $this->db->query($sql);
1217 if (!$result) {
1218 $error++;
1219 $this->errors[] = $this->db->lasterror();
1220 }
1221 }
1222
1223 if (!$error) {
1224 $sql = "DELETE FROM ".MAIN_DB_PREFIX."ticket";
1225 $sql .= " WHERE rowid=".((int) $this->id);
1226
1227 dol_syslog(get_class($this)."::delete sql=".$sql);
1228 $resql = $this->db->query($sql);
1229 if (!$resql) {
1230 $error++;
1231 $this->errors[] = "Error ".$this->db->lasterror();
1232 } else {
1233 // we delete file with dol_delete_dir_recursive
1234 $this->deleteEcmFiles(1);
1235
1236 $dir = DOL_DATA_ROOT.'/'.$this->element.'/'.$this->ref;
1237 // For remove dir
1238 if (dol_is_dir($dir)) {
1239 if (!dol_delete_dir_recursive($dir)) {
1240 $this->errors[] = $this->error;
1241 }
1242 }
1243 }
1244 }
1245
1246 // Commit or rollback
1247 if ($error) {
1248 foreach ($this->errors as $errmsg) {
1249 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1250 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1251 }
1252 $this->db->rollback();
1253 return -1 * $error;
1254 } else {
1255 $this->db->commit();
1256 return 1;
1257 }
1258 }
1259
1267 public function createFromClone(User $user, $fromid)
1268 {
1269 $error = 0;
1270
1271 $object = new Ticket($this->db);
1272
1273 $this->db->begin();
1274
1275 // Load source object
1276 $object->fetch($fromid);
1277
1278 // Clear fields
1279 $object->id = 0;
1280 $object->statut = 0;
1281 $object->status = 0;
1282 $object->ref = $object->getDefaultRef();
1283 $object->track_id = generate_random_id(16);
1284 $object->progress = 0;
1285 // Reset lifecycle timestamps so the clone starts fresh: datec is filled by
1286 // create() with dol_now() when empty, date_read and date_close stay null
1287 // because the new ticket has not been read or closed yet (see issue #38559).
1288 // Reset lifecycle timestamps and resolution so the clone starts fresh.
1289 // datec stays at 0 so Ticket::create()'s `if (empty($this->datec))` guard
1290 // fills it with dol_now(). date_read / date_close / resolution are unset
1291 // so the SQL writers' `!isset` checks emit NULL. We use these forms
1292 // rather than `= null` so phpstan stays happy with the int-typed
1293 // property declarations.
1294 $object->datec = 0;
1295 unset($object->date_read);
1296 unset($object->date_close);
1297 unset($object->resolution);
1298
1299 // Create clone
1300 $object->context['createfromclone'] = 'createfromclone';
1301 $result = $object->create($user);
1302
1303 // Other options
1304 if ($result < 0) {
1305 $this->error = $object->error;
1306 $error++;
1307 }
1308
1309 unset($object->context['createfromclone']);
1310
1311 // End
1312 if (!$error) {
1313 $this->db->commit();
1314 return $object->id;
1315 } else {
1316 $this->db->rollback();
1317 return -1;
1318 }
1319 }
1320
1327 public function initAsSpecimen()
1328 {
1329 $this->id = 0;
1330 $this->entity = 1;
1331 $this->ref = 'TI0501-001';
1332 $this->track_id = 'XXXXaaaa';
1333 $this->origin_email = 'email@email.com';
1334 $this->fk_project = 1;
1335 $this->fk_user_create = 1;
1336 $this->fk_user_assign = 1;
1337 $this->subject = 'Subject of ticket';
1338 $this->message = 'Message of ticket';
1339 $this->status = 0;
1340 $this->resolution = 1;
1341 $this->progress = 10;
1342 // $this->timing = '30';
1343 $this->type_code = 'TYPECODE';
1344 $this->category_code = 'CATEGORYCODE';
1345 $this->severity_code = 'SEVERITYCODE';
1346 $this->datec = dol_now();
1347 $this->date_read = dol_now();
1348 $this->date_last_msg_sent = dol_now();
1349 $this->date_close = dol_now();
1350 $this->tms = dol_now();
1351
1352 return 1;
1353 }
1354
1361 public function printSelectStatus($selected = "")
1362 {
1363 print Form::selectarray('search_fk_statut', $this->labelStatusShort, $selected, $show_empty = 1, $key_in_label = 0, $value_as_key = 0, $option = '', $translate = 1, $maxlen = 0, $disabled = 0, $sort = '', $morecss = '');
1364 }
1365
1366
1372 public function loadCacheTypesTickets()
1373 {
1374 global $langs;
1375
1376 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1377 return 0;
1378 }
1379 // Cache deja charge
1380
1381 $sql = "SELECT rowid, code, label, use_default, pos, description";
1382 $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type";
1383 $sql .= " WHERE entity IN (".getEntity('c_ticket_type').")";
1384 $sql .= " AND active > 0";
1385 $sql .= " ORDER BY pos";
1386 dol_syslog(get_class($this)."::load_cache_type_tickets", LOG_DEBUG);
1387 $resql = $this->db->query($sql);
1388 if ($resql) {
1389 $num = $this->db->num_rows($resql);
1390 $i = 0;
1391 while ($i < $num) {
1392 $obj = $this->db->fetch_object($resql);
1393 $label = ($langs->trans("TicketTypeShort".$obj->code) != "TicketTypeShort".$obj->code ? $langs->trans("TicketTypeShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
1394 $this->cache_types_tickets[$obj->rowid]['code'] = $obj->code;
1395 $this->cache_types_tickets[$obj->rowid]['label'] = $label;
1396 $this->cache_types_tickets[$obj->rowid]['use_default'] = $obj->use_default;
1397 $this->cache_types_tickets[$obj->rowid]['pos'] = $obj->pos;
1398 $i++;
1399 }
1400 return $num;
1401 } else {
1402 dol_print_error($this->db);
1403 return -1;
1404 }
1405 }
1406
1413 public function loadCacheCategoriesTickets($publicgroup = -1)
1414 {
1415 global $conf, $langs;
1416
1417 if ($publicgroup == -1 && !empty($conf->cache['category_tickets']) && count($conf->cache['category_tickets'])) {
1418 // Cache already loaded
1419 return 0;
1420 }
1421
1422 $sql = "SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1423 $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category";
1424 $sql .= " WHERE entity IN (".getEntity('c_ticket_category').")";
1425 $sql .= " AND active > 0";
1426 if ($publicgroup > -1) {
1427 $sql .= " AND public = ".((int) $publicgroup);
1428 }
1429 $sql .= " ORDER BY pos";
1430
1431 dol_syslog(get_class($this)."::load_cache_categories_tickets", LOG_DEBUG);
1432
1433 $resql = $this->db->query($sql);
1434 if ($resql) {
1435 $num = $this->db->num_rows($resql);
1436 $i = 0;
1437 $categorytickets = array();
1438 '@phan-var-force array<int,array{code:string,label:string,use_default:int,pos:int,public:int,active:int,force_severity:?string,fk_parent:int}> $categorytickets';
1439 while ($i < $num) {
1440 $obj = $this->db->fetch_object($resql);
1441 $categorytickets[$obj->rowid]['code'] = $obj->code;
1442 $categorytickets[$obj->rowid]['use_default'] = $obj->use_default;
1443 $categorytickets[$obj->rowid]['pos'] = $obj->pos;
1444 $categorytickets[$obj->rowid]['public'] = $obj->public;
1445 $categorytickets[$obj->rowid]['active'] = $obj->active;
1446 $categorytickets[$obj->rowid]['force_severity'] = $obj->force_severity;
1447 $categorytickets[$obj->rowid]['fk_parent'] = $obj->fk_parent;
1448
1449 // If translation exists, we use it to store already translated string.
1450 // Warning: You should not use this and recompute the translated string into caller code to get the value into expected language
1451 $label = ($langs->trans("TicketCategoryShort".$obj->code) != "TicketCategoryShort".$obj->code ? $langs->trans("TicketCategoryShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
1452 $categorytickets[$obj->rowid]['label'] = $label;
1453
1454 $i++;
1455 }
1456 $conf->cache['category_tickets'] = $categorytickets;
1457 return $num;
1458 } else {
1459 dol_print_error($this->db);
1460 return -1;
1461 }
1462 }
1463
1470 {
1471 global $conf, $langs;
1472
1473 if (!empty($conf->cache['severity_tickets']) && count($conf->cache['severity_tickets'])) {
1474 // Cache already loaded
1475 return 0;
1476 }
1477
1478 $sql = "SELECT rowid, code, label, use_default, pos, description";
1479 $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity";
1480 $sql .= " WHERE entity IN (".getEntity('c_ticket_severity').")";
1481 $sql .= " AND active > 0";
1482 $sql .= " ORDER BY pos";
1483 dol_syslog(get_class($this)."::loadCacheSeveritiesTickets", LOG_DEBUG);
1484 $resql = $this->db->query($sql);
1485 if ($resql) {
1486 $num = $this->db->num_rows($resql);
1487 $i = 0;
1488 $severitytickets = array();
1489 '@phan-var-force array<int,array{code:string,label:string,use_default:int,pos:int}> $severitytickets';
1490 while ($i < $num) {
1491 $obj = $this->db->fetch_object($resql);
1492
1493 $severitytickets[$obj->rowid]['code'] = $obj->code;
1494 $label = ($langs->trans("TicketSeverityShort".$obj->code) != "TicketSeverityShort".$obj->code ? $langs->trans("TicketSeverityShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
1495 $severitytickets[$obj->rowid]['label'] = $label;
1496 $severitytickets[$obj->rowid]['use_default'] = $obj->use_default;
1497 $severitytickets[$obj->rowid]['pos'] = $obj->pos;
1498 $i++;
1499 }
1500 $conf->cache['severity_tickets'] = $severitytickets;
1501 return $num;
1502 } else {
1503 dol_print_error($this->db);
1504 return -1;
1505 }
1506 }
1507
1508
1515 public function getLibStatut($mode = 0)
1516 {
1517 return $this->LibStatut($this->status, $mode, 0, $this->progress);
1518 }
1519
1520
1521 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1531 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1532 {
1533 // phpcs:enable
1534 global $langs, $hookmanager;
1535
1536 $labelStatus = (isset($status) && !empty($this->labelStatus[$status])) ? $this->labelStatus[$status] : '';
1537 $labelStatusShort = (isset($status) && !empty($this->labelStatusShort[$status])) ? $this->labelStatusShort[$status] : '';
1538 $statusType = '';
1539
1540 $isUnknown = false;
1541 switch ($status) {
1542 case self::STATUS_NOT_READ: // Not read
1543 $statusType = 'status0';
1544 break;
1545 case self::STATUS_READ: // Read
1546 $statusType = 'status1';
1547 break;
1548 case self::STATUS_ASSIGNED: // Assigned
1549 $statusType = 'status2';
1550 break;
1551 case self::STATUS_IN_PROGRESS: // In progress
1552 $statusType = 'status4';
1553 break;
1554 case self::STATUS_WAITING: // Waiting/pending/suspended
1555 $statusType = 'status7';
1556 break;
1557 case self::STATUS_NEED_MORE_INFO: // Waiting more information from the requester
1558 $statusType = 'status3';
1559 break;
1560 case self::STATUS_CANCELED: // Canceled
1561 $statusType = 'status9';
1562 break;
1563 case self::STATUS_CLOSED: // Closed
1564 $statusType = 'status6';
1565 break;
1566 default:
1567 $isUnknown = true;
1568 break;
1569 }
1570
1571 $parameters = array(
1572 'status' => $status,
1573 'mode' => $mode,
1574 );
1575
1576 // Note that $action and $object may have been modified by hook
1577 $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this);
1578
1579 if ($reshook > 0) {
1580 return $hookmanager->resPrint;
1581 }
1582
1583 if ($isUnknown) {
1584 $labelStatus = 'Unknown';
1585 $labelStatusShort = 'Unknown';
1586 $statusType = 'status0';
1587 $mode = 0;
1588 }
1589
1590 $params = array();
1591 if ($notooltip) {
1592 $params = array('tooltip' => 'no');
1593 }
1594
1595 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1596 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1597
1598 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1599 $labelStatus .= ' ('.round($progress).'%)';
1600 $labelStatusShort .= ' ('.round($progress).'%)';
1601 }
1602
1603 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode, '', $params);
1604 }
1605
1612 public function getTooltipContentArray($params)
1613 {
1614 global $langs;
1615
1616 $langs->load('ticket');
1617 $nofetch = !empty($params['nofetch']);
1618
1619 $datas = array();
1620 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Ticket").'</u>';
1621 $datas['picto'] .= ' '.$this->getLibStatut(4);
1622 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1623 $datas['track_id'] = '<br><b>'.$langs->trans('TicketTrackId').':</b> '.$this->track_id;
1624 $datas['subject'] = '<br><b>'.$langs->trans('Subject').':</b> '.$this->subject;
1625 if ($this->date_creation) {
1626 $datas['date_creation'] = '<br><b>'.$langs->trans('DateCreation').':</b> '.dol_print_date($this->date_creation, 'dayhour');
1627 }
1628 if ($this->date_modification) {
1629 $datas['date_modification'] = '<br><b>'.$langs->trans('DateModification').':</b> '.dol_print_date($this->date_modification, 'dayhour');
1630 }
1631 // show categories for this record only in ajax to not overload lists
1632 if (isModEnabled('category') && !$nofetch) {
1633 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1634 $form = new Form($this->db);
1635 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_TICKET, 1);
1636 }
1637
1638 return $datas;
1639 }
1640
1651 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1652 {
1653 global $action, $conf, $hookmanager, $langs;
1654
1655 if (!empty($conf->dol_no_mouse_hover)) {
1656 $notooltip = 1; // Force disable tooltips
1657 }
1658
1659 $result = '';
1660
1661 $params = [
1662 'id' => $this->id,
1663 'objecttype' => $this->element,
1664 'option' => $option,
1665 'nofetch' => 1,
1666 ];
1667 $classfortooltip = 'classfortooltip';
1668 $dataparams = '';
1669 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1670 $classfortooltip = 'classforajaxtooltip';
1671 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1672 $label = '';
1673 } else {
1674 $label = implode($this->getTooltipContentArray($params));
1675 }
1676
1677 $url = DOL_URL_ROOT.'/ticket/card.php?id='.$this->id;
1678
1679 if ($option != 'nolink') {
1680 // Add param to save lastsearch_values or not
1681 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1682 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1683 $add_save_lastsearch_values = 1;
1684 }
1685 if ($add_save_lastsearch_values) {
1686 $url .= '&save_lastsearch_values=1';
1687 }
1688 }
1689
1690 $linkclose = '';
1691 if (empty($notooltip)) {
1692 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1693 $label = $langs->trans("ShowTicket");
1694 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1695 }
1696 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1697 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1698 } else {
1699 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1700 }
1701
1702 $linkstart = '<a href="'.$url.'"';
1703 $linkstart .= $linkclose.'>';
1704 $linkend = '</a>';
1705
1706 $result .= $linkstart;
1707 if ($withpicto) {
1708 $result .= img_object(($notooltip ? '' : $label), ($this->picto ?: 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
1709 }
1710 if ($withpicto != 2) {
1711 $result .= $this->ref;
1712 }
1713 $result .= $linkend;
1714 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1715
1716 $hookmanager->initHooks(array('ticketdao'));
1717 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1718 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1719 if ($reshook > 0) {
1720 $result = $hookmanager->resPrint;
1721 } else {
1722 $result .= $hookmanager->resPrint;
1723 }
1724
1725 return $result;
1726 }
1727
1728
1736 public function markAsRead($user, $notrigger = 0)
1737 {
1738 global $langs;
1739
1740 $error = 0;
1741
1742 if ($this->status != self::STATUS_CANCELED) { // no closed
1743 $this->oldcopy = dol_clone($this, 2);
1744
1745 $this->db->begin();
1746
1747 $this->status = Ticket::STATUS_READ;
1748
1749 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
1750 $sql .= " SET fk_statut = ".((int) $this->status) .", date_read = '".$this->db->idate(dol_now())."'";
1751 $sql .= " WHERE rowid = ".((int) $this->id);
1752
1753 dol_syslog(get_class($this)."::markAsRead");
1754 $resql = $this->db->query($sql);
1755 if ($resql) {
1756 $this->context['actionmsg'] = $langs->trans('TicketLogMesgReadBy', $this->ref, $user->getFullName($langs));
1757 $this->context['actionmsg2'] = $langs->trans('TicketLogMesgReadBy', $this->ref, $user->getFullName($langs));
1758
1759 if (!$notrigger) {
1760 // Call trigger
1761 $result = $this->call_trigger('TICKET_MODIFY', $user);
1762 if ($result < 0) {
1763 $error++;
1764 }
1765 // End call triggers
1766 }
1767
1768 if (!$error) {
1769 $this->db->commit();
1770 return 1;
1771 } else {
1772 $this->status = $this->oldcopy->status;
1773
1774 $this->db->rollback();
1775
1776 $this->error = implode(',', $this->errors);
1777
1778 dol_syslog(get_class($this)."::markAsRead ".$this->error, LOG_ERR);
1779 return -1;
1780 }
1781 } else {
1782 $this->status = $this->oldcopy->status;
1783
1784 $this->db->rollback();
1785 $this->error = $this->db->lasterror();
1786 dol_syslog(get_class($this)."::markAsRead ".$this->error, LOG_ERR);
1787 return -1;
1788 }
1789 }
1790
1791 return 0;
1792 }
1793
1801 public function setReadDate($user, $notrigger = 0)
1802 {
1803 global $langs;
1804
1805 if (!empty($this->date_read)) {
1806 return 0;
1807 }
1808
1809 $this->oldcopy = dol_clone($this, 2);
1810
1811 $this->db->begin();
1812
1813 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
1814 $sql .= " SET date_read = '".$this->db->idate(dol_now())."'";
1815 $sql .= ", fk_user_modif = ".((int) $user->id);
1816 $sql .= " WHERE rowid = ".((int) $this->id);
1817
1818 dol_syslog(get_class($this)."::setReadDate");
1819
1820 $resql = $this->db->query($sql);
1821
1822 if (!$resql) {
1823 $this->db->rollback();
1824 $this->date_read = $this->oldcopy->date_read;
1825 $this->error = $this->db->lasterror();
1826
1827 dol_syslog(get_class($this)."::setReadDate ".$this->error, LOG_ERR);
1828 return -1;
1829 }
1830
1831 if (!$notrigger) {
1832 $result = $this->call_trigger('TICKET_MODIFY', $user);
1833 if ($result < 0) {
1834 $this->db->rollback();
1835 $this->date_read = $this->oldcopy->date_read;
1836 $this->error = implode(',', $this->errors);
1837
1838 dol_syslog(get_class($this)."::setReadDate ".$this->error, LOG_ERR);
1839 return -1;
1840 }
1841 }
1842
1843 $this->db->commit();
1844
1845 $this->date_read = dol_now();
1846 $this->fk_user_modif = $user->id;
1847 $this->user_modification_id = $user->id;
1848
1849 return 1;
1850 }
1851
1860 public function assignUser($user, $id_assign_user, $notrigger = 0)
1861 {
1862 $error = 0;
1863
1864 $this->oldcopy = dol_clone($this, 2);
1865
1866 $this->db->begin();
1867
1868 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
1869 if ($id_assign_user > 0) {
1870 $newstatus = Ticket::STATUS_ASSIGNED;
1871 if (getDolGlobalString('TICKET_AUTO_READ_WHEN_ASSIGN')) {
1872 $newstatus = Ticket::STATUS_READ;
1873 }
1874 $sql .= " SET fk_user_assign=".((int) $id_assign_user).", fk_statut = ".((int) $newstatus);
1875 } else {
1876 $sql .= " SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1877 }
1878 $sql .= " WHERE rowid = ".((int) $this->id);
1879
1880 dol_syslog(get_class($this)."::assignUser sql=".$sql);
1881 $resql = $this->db->query($sql);
1882 if ($resql) {
1883 $this->fk_user_assign = $id_assign_user; // May be used by trigger
1884
1885 if (!$notrigger) {
1886 // Call trigger
1887 $result = $this->call_trigger('TICKET_ASSIGNED', $user);
1888 if ($result < 0) {
1889 $error++;
1890 }
1891 // End call triggers
1892 }
1893
1894 if (!$error) {
1895 $this->db->commit();
1896 return 1;
1897 } else {
1898 $this->db->rollback();
1899 $this->error = implode(',', $this->errors);
1900 dol_syslog(get_class($this)."::assignUser ".$this->error, LOG_ERR);
1901 return -1;
1902 }
1903 } else {
1904 $this->db->rollback();
1905 $this->error = $this->db->lasterror();
1906 dol_syslog(get_class($this)."::assignUser ".$this->error, LOG_ERR);
1907 return -1;
1908 }
1909 }
1910
1925 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email = false, $public_area = 0, $summary = '', $external_contacts = [])
1926 {
1927 global $conf, $langs, $hookmanager;
1928 $error = 0;
1929
1930 $now = dol_now();
1931
1932 // Clean parameters
1933 if (isset($this->track_id)) {
1934 $this->track_id = trim($this->track_id);
1935 }
1936
1937 if (isset($this->message)) {
1938 $this->message = trim($this->message);
1939 }
1940
1941 $this->db->begin();
1942
1943 // Insert entry into agenda with code 'TICKET_MSG'
1944 include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1945 $actioncomm = new ActionComm($this->db);
1946 $actioncomm->type_code = 'AC_OTH_AUTO'; // This is not an entry that must appears into manual calendar but only into CRM calendar
1947 $actioncomm->code = 'TICKET_MSG';
1948 if ($this->private) {
1949 $actioncomm->code = 'TICKET_MSG_PRIVATE';
1950 }
1951 if ($send_email) {
1952 $actioncomm->code .= '_SENTBYMAIL';
1953 }
1954 if ((empty($user->id) || $user->id == 0) && isset($_SESSION['email_customer'])) {
1955 $actioncomm->email_from = $_SESSION['email_customer'];
1956 }
1957 $actioncomm->socid = $this->socid;
1958 $actioncomm->label = $this->subject;
1959 if ($summary) {
1960 $actioncomm->label = preg_replace('/(\[[^\]]*\]).*$/', '\1', $actioncomm->label);
1961 if ($actioncomm->label) {
1962 $actioncomm->label .= ' ';
1963 }
1964 $actioncomm->label .= (string) $summary;
1965 }
1966
1967 $actioncomm->note_private = $this->message;
1968 $actioncomm->userassigned = array($user->id => array('id' => $user->id,'transparency' => 0));
1969
1970 $parameters = array();
1971 $reshook = $hookmanager->executeHooks('createTicketMessageExternalContacts', $parameters, $actioncomm);
1972 if ($reshook < 0) {
1973 $actioncomm->socpeopleassigned = $external_contacts;
1974 } elseif ($reshook == 0) {
1975 $actioncomm->socpeopleassigned += $external_contacts;
1976 }
1977
1978 $actioncomm->userownerid = $user->id;
1979 $actioncomm->datep = $now;
1980 $actioncomm->percentage = -1; // percentage is not relevant for punctual events
1981 $actioncomm->elementtype = 'ticket';
1982 $actioncomm->fk_element = $this->id;
1983 $actioncomm->elementid = $this->id;
1984 $actioncomm->elementtype = 'ticket';
1985 $actioncomm->fk_project = $this->fk_project;
1986
1987 // Add first contact id found in database from submitter email entered into public interface
1988 // Feature disabled by default: This has a security trouble. The public interface is a no login interface, so being able to show the contact info from an
1989 // email decided by the submiter allows anybody to get information on any contact (customer or supplier) in Dolibarr database.
1990 // He can even check if contact exists by trying any email if this feature is enabled.
1991 if ($public_area && !empty($this->origin_email) && getDolGlobalString('TICKET_ASSIGN_CONTACT_TO_MESSAGE')) {
1992 $contacts = $this->searchContactByEmail($this->origin_email);
1993 if (!empty($contacts)) {
1994 // Ensure that contact is active and select first active contact
1995 foreach ($contacts as $contact) {
1996 if ((int) $contact->status == 1) {
1997 $actioncomm->contact_id = $contact->id;
1998 break;
1999 }
2000 }
2001 }
2002 }
2003
2004 $attachedfiles = array();
2005 $attachedfiles['paths'] = $filename_list;
2006 $attachedfiles['names'] = $mimefilename_list;
2007 $attachedfiles['mimes'] = $mimetype_list;
2008 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
2009 $actioncomm->attachedfiles = $attachedfiles;
2010 }
2011
2012 //if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
2013 // $actioncomm->note_private = dol_concatdesc($actioncomm->note_private, "\n".$langs->transnoentities("AttachedFiles").': '.implode(';', $mimefilename_list));
2014 //}
2015 $actionid = $actioncomm->create($user);
2016 if ($actionid <= 0) {
2017 $error++;
2018 $this->error = $actioncomm->error;
2019 $this->errors = $actioncomm->errors;
2020 }
2021
2022 if ($actionid > 0) {
2023 if (is_array($attachedfiles) && array_key_exists('paths', $attachedfiles) && count($attachedfiles['paths']) > 0) {
2024 // If there is some files, we must now link them to the event, so we can show them per event.
2025 foreach ($attachedfiles['paths'] as $key => $filespath) {
2026 // Disabled the move into another directory, Files for a ticket should be stored into ticket directory. It generates too much troubles.
2027 $destdir = $conf->ticket->dir_output.'/'.$this->ref;
2028 //$destfile = $destdir.'/'.$attachedfiles['names'][$key];
2029 //if (dol_mkdir($destdir) >= 0) {
2030 //require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2031 //dol_move($filespath, $destfile); // Disabled, a file for a ticket should be stored into ticket directory. It generates big trouble.
2032 if (in_array($actioncomm->code, array('TICKET_MSG', 'TICKET_MSG_SENTBYMAIL', 'TICKET_MSG_PRIVATE'))) {
2033 $ecmfile = new EcmFiles($this->db);
2034 $destdir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $destdir);
2035 $destdir = preg_replace('/[\\/]$/', '', $destdir);
2036 $destdir = preg_replace('/^[\\/]/', '', $destdir);
2037
2038 $result = $ecmfile->fetch(0, '', $destdir.'/'.$attachedfiles['names'][$key]);
2039
2040 // We also store the ID of event.
2041 $ecmfile->agenda_id = $actionid;
2042
2043 if ($result > 0) {
2044 $result = $ecmfile->update($user);
2045 if ($result < 0) {
2046 setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
2047 }
2048 }
2049 }
2050 //}
2051 }
2052 }
2053 }
2054
2055 // Commit or rollback
2056 if ($error) {
2057 $this->db->rollback();
2058 return -1 * $error;
2059 } else {
2060 $this->db->commit();
2061 return $actionid;
2062 }
2063 }
2064
2070 public function loadCacheMsgsTicket()
2071 {
2072 if (!empty($this->cache_msgs_ticket) && is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
2073 return 0;
2074 }
2075
2076 // Cache already loaded
2077
2078 $sql = "SELECT id as rowid, fk_user_author, fk_user_action, email_from, datec, datep, label, note as message, code";
2079 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
2080 $sql .= " WHERE fk_element = ".(int) $this->id;
2081 $sql .= " AND elementtype = 'ticket'";
2082 $sql .= " ORDER BY datep DESC";
2083
2084 dol_syslog(get_class($this)."::load_cache_actions_ticket", LOG_DEBUG);
2085 $resql = $this->db->query($sql);
2086 if ($resql) {
2087 $num = $this->db->num_rows($resql);
2088 $i = 0;
2089 while ($i < $num) {
2090 $obj = $this->db->fetch_object($resql);
2091 $this->cache_msgs_ticket[$i]['id'] = $obj->rowid;
2092 $this->cache_msgs_ticket[$i]['fk_user_author'] = $obj->fk_user_author;
2093 $this->cache_msgs_ticket[$i]['fk_user_action'] = $obj->fk_user_action; // owner of the action
2094 if (in_array($obj->code, array('TICKET_MSG', 'AC_TICKET_CREATE')) && empty($obj->fk_user_author)) {
2095 $this->cache_msgs_ticket[$i]['fk_contact_author'] = $obj->email_from;
2096 }
2097 $this->cache_msgs_ticket[$i]['datec'] = $this->db->jdate($obj->datec);
2098 $this->cache_msgs_ticket[$i]['datep'] = $this->db->jdate($obj->datep);
2099 $this->cache_msgs_ticket[$i]['subject'] = $obj->label;
2100 $this->cache_msgs_ticket[$i]['message'] = $obj->message;
2101 $this->cache_msgs_ticket[$i]['private'] = (preg_match('/^TICKET_MSG_PRIVATE/', $obj->code) ? 1 : 0);
2102 $i++;
2103 }
2104 return $num;
2105 } else {
2106 $this->error = "Error ".$this->db->lasterror();
2107 dol_syslog(get_class($this)."::load_cache_actions_ticket ".$this->error, LOG_ERR);
2108 return -1;
2109 }
2110 }
2111
2119 public function close(User $user, $mode = 0)
2120 {
2121
2122 if ($this->status != Ticket::STATUS_CLOSED && $this->status != Ticket::STATUS_CANCELED) { // not closed
2123 $this->db->begin();
2124
2125 $this->oldcopy = dol_clone($this);
2126 $this->status = ($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED);
2127
2128 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
2129 $sql .= " SET fk_statut = ".((int) $this->status).", progress=100, date_close='".$this->db->idate(dol_now())."'";
2130 $sql .= " WHERE rowid = ".((int) $this->id);
2131
2132 dol_syslog(get_class($this)."::close mode=".$mode);
2133 $resql = $this->db->query($sql);
2134 if ($resql) {
2135 $error = 0;
2136
2137 // Valid and close fichinter linked
2138 if (isModEnabled('intervention') && getDolGlobalString('WORKFLOW_TICKET_CLOSE_INTERVENTION')) {
2139 dol_syslog("We have closed the ticket, so we close all linked interventions");
2140 $this->fetchObjectLinked($this->id, $this->element, null, 'fichinter');
2141 if ($this->linkedObjectsIds) {
2142 foreach ($this->linkedObjectsIds['fichinter'] as $fichinter_id) {
2143 $fichinter = new Fichinter($this->db);
2144 $fichinter->fetch($fichinter_id);
2145 if ($fichinter->statut == 0) {
2146 $result = $fichinter->setValid($user);
2147 if (!$result) {
2148 $this->errors[] = $fichinter->error;
2149 $error++;
2150 }
2151 }
2152 if ($fichinter->statut < 3) {
2153 $result = $fichinter->setStatut(3);
2154 if (!$result) {
2155 $this->errors[] = $fichinter->error;
2156 $error++;
2157 }
2158 }
2159 }
2160 }
2161 }
2162
2163 // Call trigger
2164 $result = $this->call_trigger('TICKET_CLOSE', $user);
2165 if ($result < 0) {
2166 $error++;
2167 }
2168 // End call triggers
2169
2170 if (!$error) {
2171 $this->db->commit();
2172 return 1;
2173 } else {
2174 $this->db->rollback();
2175 $this->error = implode(',', $this->errors);
2176 dol_syslog(get_class($this)."::close ".$this->error, LOG_ERR);
2177 return -1;
2178 }
2179 } else {
2180 $this->db->rollback();
2181 $this->error = $this->db->lasterror();
2182 dol_syslog(get_class($this)."::close ".$this->error, LOG_ERR);
2183 return -1;
2184 }
2185 }
2186
2187 return 0;
2188 }
2189
2199 public function searchSocidByEmail($email, $type = 0, $filters = array(), $clause = 'AND')
2200 {
2201 $thirdparties = array();
2202 $exact = 0;
2203
2204 // Generation requete recherche
2205 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
2206 $sql .= " WHERE entity IN (".getEntity('ticket', 1).")";
2207 if (!empty($type)) {
2208 if ($type == 1 || $type == 2) {
2209 $sql .= " AND client = ".((int) $type);
2210 } elseif ($type == 3) {
2211 $sql .= " AND fournisseur = 1";
2212 }
2213 }
2214 if (!empty($email)) {
2215 if (empty($exact)) {
2216 $regs = array();
2217 if (preg_match('/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
2218 $email = str_replace('*', '%', $email);
2219 } else {
2220 $email = '%'.$email.'%';
2221 }
2222 }
2223 $sql .= " AND ";
2224 if (is_array($filters) && !empty($filters)) {
2225 $sql .= "(";
2226 }
2227
2228 $sql .= "email LIKE '".$this->db->escape($email)."'";
2229 }
2230 if (is_array($filters) && !empty($filters)) {
2231 foreach ($filters as $field => $value) {
2232 $sql .= " ".$clause." ".$this->db->sanitize($field)." LIKE '".$this->db->escape($value)."'";
2233 }
2234 if (!empty($email)) {
2235 $sql .= ")";
2236 }
2237 }
2238
2239 $res = $this->db->query($sql);
2240 if ($res) {
2241 while ($rec = $this->db->fetch_array($res)) {
2242 $soc = new Societe($this->db);
2243 $soc->fetch($rec['rowid']);
2244 $thirdparties[] = $soc;
2245 }
2246
2247 return $thirdparties;
2248 } else {
2249 $this->error = $this->db->error().' sql='.$sql;
2250 dol_syslog(get_class($this)."::searchSocidByEmail ".$this->error, LOG_ERR);
2251 return -1;
2252 }
2253 }
2254
2263 public function searchContactByEmail($email, $socid = 0, $case = '')
2264 {
2265 $contacts = array();
2266
2267 // Forge the search SQL
2268 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople";
2269 $sql .= " WHERE entity IN (".getEntity('contact').")";
2270 if (!empty($socid)) {
2271 $sql .= " AND fk_soc = ".((int) $socid);
2272 }
2273 if (!empty($email)) {
2274 $sql .= " AND ";
2275 if (!$case) {
2276 $sql .= "email = '".$this->db->escape($email)."'";
2277 } else {
2278 $sql .= "email LIKE BINARY '".$this->db->escape($this->db->escapeforlike($email))."'";
2279 }
2280 }
2281
2282 $res = $this->db->query($sql);
2283 if ($res) {
2284 while ($rec = $this->db->fetch_object($res)) {
2285 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2286 $contactstatic = new Contact($this->db);
2287 $contactstatic->fetch($rec->rowid);
2288 $contacts[] = $contactstatic;
2289 }
2290
2291 return $contacts;
2292 } else {
2293 $this->error = $this->db->error().' sql='.$sql;
2294 dol_syslog(get_class($this)."::searchContactByEmail ".$this->error, LOG_ERR);
2295 return -1;
2296 }
2297 }
2298
2305 public function setCustomer($id)
2306 {
2307 if ($this->id) {
2308 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
2309 $sql .= " SET fk_soc = ".($id > 0 ? (int) $id : "null");
2310 $sql .= " WHERE rowid = ".((int) $this->id);
2311 dol_syslog(get_class($this).'::setCustomer sql='.$sql);
2312 $resql = $this->db->query($sql);
2313 if ($resql) {
2314 return 1;
2315 } else {
2316 return -1;
2317 }
2318 } else {
2319 return -1;
2320 }
2321 }
2322
2329 public function setProgression($percent)
2330 {
2331 if ($this->id) {
2332 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
2333 $sql .= " SET progress = ".($percent > 0 ? (float) $percent : "null");
2334 $sql .= " WHERE rowid = ".((int) $this->id);
2335 dol_syslog(get_class($this).'::set_progression sql='.$sql);
2336 $resql = $this->db->query($sql);
2337 if ($resql) {
2338 return 1;
2339 } else {
2340 return -1;
2341 }
2342 } else {
2343 return -1;
2344 }
2345 }
2346
2353 public function setContract($contractid)
2354 {
2355 if ($this->id) {
2356 $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
2357 $sql .= " SET fk_contract = ".($contractid > 0 ? (int) $contractid : "null");
2358 $sql .= " WHERE rowid = ".((int) $this->id);
2359 dol_syslog(get_class($this).'::setContract sql='.$sql);
2360 $resql = $this->db->query($sql);
2361 if ($resql) {
2362 return 1;
2363 } else {
2364 return -1;
2365 }
2366 } else {
2367 return -1;
2368 }
2369 }
2370
2371 /* gestion des contacts d'un ticket */
2372
2379 {
2380 return $this->getIdContact('internal', 'SUPPORTTEC');
2381 }
2382
2389 public function getInfosTicketInternalContact($status = -1)
2390 {
2391 return $this->listeContact(-1, 'internal', 0, '', $status);
2392 }
2393
2400 {
2401 return $this->getIdContact('external', 'SUPPORTCLI');
2402 }
2403
2410 public function getInfosTicketExternalContact($status = -1)
2411 {
2412 return $this->listeContact(-1, 'external', 0, '', $status);
2413 }
2414
2421 {
2422 return $this->getIdContact('internal', 'CONTRIBUTOR');
2423 }
2424
2431 {
2432 return $this->getIdContact('external', 'CONTRIBUTOR');
2433 }
2434
2440 public function getTicketAllContacts()
2441 {
2442 $array_contact = $this->getIdTicketInternalContact();
2443
2444 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2445
2446 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact());
2447
2448 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2449
2450 return $array_contact;
2451 }
2452
2459 {
2460 $array_contact = array();
2461
2462 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2463
2464 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2465
2466 return $array_contact;
2467 }
2468
2469
2481 public function listeContact($statusoflink = -1, $source = 'external', $list = 0, $code = '', $status = -1)
2482 {
2483 global $langs;
2484
2485 $tab = array();
2486
2487 $sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user
2488 if ($source == 'internal') {
2489 $sql .= ", '-1' as socid, t.statut as statuscontact";
2490 }
2491
2492 if ($source == 'external' || $source == 'thirdparty') {
2493 $sql .= ", t.fk_soc as socid, t.statut as statuscontact";
2494 }
2495
2496 $sql .= ", t.civility, t.lastname as lastname, t.firstname, t.email";
2497 if ($source == 'internal') {
2498 $sql .= ", t.office_phone as phone, t.user_mobile as phone_mobile";
2499 }
2500
2501 if ($source == 'external' || $source == 'thirdparty') {
2502 $sql .= ", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2503 }
2504
2505 $sql .= ", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2506 $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
2507 $sql .= ", ".MAIN_DB_PREFIX."element_contact ec";
2508 if ($source == 'internal') {
2509 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
2510 }
2511
2512 if ($source == 'external' || $source == 'thirdparty') {
2513 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
2514 }
2515
2516 $sql .= " WHERE ec.element_id = ".((int) $this->id);
2517 $sql .= " AND ec.fk_c_type_contact=tc.rowid";
2518 $sql .= " AND tc.element='".$this->db->escape($this->element)."'";
2519 if ($source == 'internal') {
2520 $sql .= " AND tc.source = 'internal'";
2521 if ($status >= 0) {
2522 $sql .= " AND t.statut = ".((int) $status);
2523 }
2524 }
2525
2526 if ($source == 'external' || $source == 'thirdparty') {
2527 $sql .= " AND tc.source = 'external'";
2528 if ($status >= 0) {
2529 $sql .= " AND t.statut = ".((int) $status);
2530 }
2531 }
2532
2533 if (!empty($code)) {
2534 $sql .= " AND tc.code = '".$this->db->escape($code)."'";
2535 }
2536
2537 $sql .= " AND tc.active=1";
2538 if ($statusoflink >= 0) {
2539 $sql .= " AND ec.statut = ".((int) $statusoflink);
2540 }
2541
2542 $sql .= " ORDER BY t.lastname ASC";
2543
2544 $resql = $this->db->query($sql);
2545 if ($resql) {
2546 $num = $this->db->num_rows($resql);
2547 $i = 0;
2548 while ($i < $num) {
2549 $obj = $this->db->fetch_object($resql);
2550
2551 if (!$list) {
2552 $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code;
2553 $labelType = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2554 $tab[$i] = array(
2555 'source' => $obj->source,
2556 'socid' => (int) $obj->socid,
2557 'id' => (int) $obj->id,
2558 'nom' => $obj->lastname, // For backward compatibility
2559 'civility' => $obj->civility,
2560 'lastname' => $obj->lastname,
2561 'firstname' => $obj->firstname,
2562 'email' => $obj->email,
2563 'rowid' => (int) $obj->rowid,
2564 'code' => $obj->code,
2565 'libelle' => $labelType, // deprecated, replaced with labeltype
2566 'labeltype' => $labelType,
2567 'status' => $obj->statuslink,
2568 'statuscontact' => (int) $obj->statuscontact,
2569 'fk_c_type_contact' => (int) $obj->fk_c_type_contact,
2570 'phone' => $obj->phone,
2571 'phone_mobile' => $obj->phone_mobile);
2572 if ($source == 'external') {
2573 $tab[$i]['phone_perso'] = $obj->phone_perso;
2574 }
2575 } else {
2576 $tab[$i] = $obj->id;
2577 }
2578
2579 $i++;
2580 }
2581
2582 return $tab;
2583 } else {
2584 $this->error = $this->db->error();
2585 dol_print_error($this->db);
2586 return -1;
2587 }
2588 }
2589
2596 public function getDefaultRef($thirdparty = null)
2597 {
2598 global $conf;
2599
2600 $defaultref = '';
2601 $modele = getDolGlobalString('TICKET_ADDON', 'mod_ticket_simple');
2602
2603 // Search template files
2604 $file = '';
2605 $classname = '';
2606 $reldir = '';
2607 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
2608 foreach ($dirmodels as $reldir) {
2609 $file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
2610 if (file_exists($file)) {
2611 $classname = $modele;
2612 break;
2613 }
2614 }
2615
2616 if ($classname !== '') {
2617 $result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
2618 $modTicket = new $classname();
2619 '@phan-var-force ModeleNumRefTicket $modTicket';
2620
2621 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2622 }
2623
2624 if (is_numeric($defaultref) && $defaultref <= 0) {
2625 $defaultref = '';
2626 }
2627
2628 return $defaultref;
2629 }
2630
2631
2632 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2639 public function is_photo_available($sdir)
2640 {
2641 // phpcs:enable
2642 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2643
2644 $dir = $sdir.'/';
2645
2646 $dir_osencoded = dol_osencode($dir);
2647 if (file_exists($dir_osencoded)) {
2648 $handle = opendir($dir_osencoded);
2649 if (is_resource($handle)) {
2650 while (($file = readdir($handle)) !== false) {
2651 if (!utf8_check($file)) {
2652 $file = mb_convert_encoding($file, 'UTF-8', 'ISO-8859-1'); // To be sure data is stored in UTF8 in memory
2653 }
2654 if (dol_is_file($dir.$file)) {
2655 return true;
2656 }
2657 }
2658 }
2659 }
2660 return false;
2661 }
2662
2663
2672 public function copyFilesForTicket($forcetrackid = null)
2673 {
2674 global $conf;
2675
2676 // Create form object
2677 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2678 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2679 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2680
2681 $maxwidthsmall = 270;
2682 $maxheightsmall = 150;
2683 $maxwidthmini = 128;
2684 $maxheightmini = 72;
2685
2686 $formmail = new FormMail($this->db);
2687 $formmail->trackid = (is_null($forcetrackid) ? 'tic'.$this->id : '');
2688 $attachedfiles = $formmail->get_attached_files();
2689
2690 $filepath = $attachedfiles['paths']; // path is for example user->dir_temp.'/'.$user->id.'/'...
2691 $filename = $attachedfiles['names'];
2692 $mimetype = $attachedfiles['mimes'];
2693
2694 // Copy files into ticket directory
2695 $destdir = $conf->ticket->dir_output.'/'.$this->ref;
2696
2697 if (!dol_is_dir($destdir)) {
2698 dol_mkdir($destdir);
2699 }
2700
2701 $listofpaths = array();
2702 $listofnames = array();
2703 foreach ($filename as $i => $val) {
2704 $destfile = $destdir.'/'.$filename[$i];
2705 // If destination file already exists, we add a suffix to avoid to overwrite
2706 if (is_file($destfile)) {
2707 $pathinfo = pathinfo($filename[$i]);
2708 $now = dol_now();
2709 $destfile = $destdir.'/'.$pathinfo['filename'].' - '.dol_print_date($now, 'dayhourlog').'.'.$pathinfo['extension'];
2710 }
2711
2712 $moreinfo = array(
2713 'description' => 'File saved by copyFilesForTicket',
2714 'src_object_type' => $this->element,
2715 'src_object_id' => $this->id,
2716 'gen_or_uploaded' => 'uploaded'
2717 );
2718
2719 $res = dol_move($filepath[$i], $destfile, '0', 1, 0, 1, $moreinfo);
2720
2721 if (!$res) {
2722 // Move has failed
2723 $this->error = "Failed to move file ".dirbasename($filepath[$i])." into ".dirbasename($destfile);
2724 return -1;
2725 } else {
2726 // If file is an image, we create thumbs
2727 if (image_format_supported($destfile) == 1) {
2728 // Create small thumbs for image (Ratio is near 16/9)
2729 // Used on logon for example
2730 $imgThumbSmall = vignette($destfile, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
2731 // Create mini thumbs for image (Ratio is near 16/9)
2732 // Used on menu or for setup page for example
2733 $imgThumbMini = vignette($destfile, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
2734 }
2735 }
2736
2737 // Clear variables into session
2738 $formmail->remove_attached_files($i);
2739
2740 // Fill array with new names
2741 $listofpaths[$i] = $destfile;
2742 $listofnames[$i] = basename($destfile);
2743 }
2744
2745 return array('listofpaths' => $listofpaths, 'listofnames' => $listofnames, 'listofmimes' => $mimetype);
2746 }
2747
2758 public function setCategories($categories)
2759 {
2760 // Handle single category
2761 if (!is_array($categories)) {
2762 $categories = array($categories);
2763 }
2764
2765 // Get current categories
2766 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2767 $c = new Categorie($this->db);
2768 $existing = $c->containing($this->id, Categorie::TYPE_TICKET, 'id');
2769
2770 // Diff
2771 if (is_array($existing)) {
2772 $to_del = array_diff($existing, $categories);
2773 $to_add = array_diff($categories, $existing);
2774 } else {
2775 $to_del = array(); // Nothing to delete
2776 $to_add = $categories;
2777 }
2778
2779 // Process
2780 foreach ($to_del as $del) {
2781 if ($c->fetch($del) > 0) {
2782 $c->del_type($this, Categorie::TYPE_TICKET);
2783 }
2784 }
2785 foreach ($to_add as $add) {
2786 if ($c->fetch($add) > 0) {
2787 $c->add_type($this, Categorie::TYPE_TICKET);
2788 }
2789 }
2790
2791 return 1;
2792 }
2793
2806 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2807 {
2808 global $mysoc, $langs, $hookmanager;
2809
2810 $error = 0;
2811
2812 $object = new Ticket($this->db);
2813
2814 $ret = $object->fetch(0, '', GETPOST('track_id', 'alpha'));
2815
2816 $object->socid = $object->fk_soc;
2817 $object->fetch_thirdparty();
2818 $object->fetchProject();
2819
2820 if ($ret < 0) {
2821 $error++;
2822 array_push($this->errors, $langs->trans("ErrorTicketIsNotValid"));
2823 $action = '';
2824 }
2825
2826 if (!GETPOST("message")) {
2827 $error++;
2828 array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")));
2829 $action = 'add_message';
2830 }
2831
2832 if (!$error) {
2833 $summary = mb_strcut(GETPOST('summary', 'alphanohtml'), 0, 42, 'UTF-8');
2834 $object->subject = GETPOST('subject', 'alphanohtml');
2835 $object->message = GETPOST("message", "restricthtml");
2836 $object->private = GETPOST("private_message", "alpha");
2837
2838 $send_email = (bool) GETPOSTINT('send_email');
2839
2840 // Copy attached files (saved into $_SESSION) as linked files to ticket. Return array with final name used.
2841 $resarray = $object->copyFilesForTicket();
2842 if (is_numeric($resarray) && $resarray == -1) {
2843 setEventMessages($object->error, $object->errors, 'errors');
2844 return -1;
2845 }
2846
2847 $listofpaths = $resarray['listofpaths'];
2848 $listofnames = $resarray['listofnames'];
2849 $listofmimes = $resarray['listofmimes'];
2850
2851 // Retrieve email of all contacts (external)
2852 $external_contacts = $object->getInfosTicketExternalContact(1);
2853 $external_resources = [];
2854 if (!empty($external_contacts)) {
2855 foreach ($external_contacts as $eContact) {
2856 $external_resources[$eContact['id']] = $eContact;
2857 }
2858 }
2859
2860 // Add the ticket message in database (even if email is requested, we store a simple record
2861 // like a simple private message, with no information about emails) because
2862 // information about emails sent will be fill later after email sending.
2863 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email, $public_area, $summary, $external_resources);
2864
2865 if ($id <= 0) {
2866 $error++;
2867 $this->error = $object->error;
2868 $this->errors = $object->errors;
2869 $action = 'add_message';
2870 }
2871
2872 if (!$error && $id > 0) {
2873 setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs');
2874
2875 // Now send emails
2876 if (!empty($public_area)) {
2877 /*
2878 * Message created from the Public interface
2879 *
2880 * Send emails to assigned users (public area notification)
2881 */
2882 if (getDolGlobalString('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED')) {
2883 // Retrieve internal contact datas
2884 $internal_contacts = $object->getInfosTicketInternalContact(1);
2885
2886 $assigned_user_dont_have_email = '';
2887
2888 $sendto = array();
2889
2890 if ($this->fk_user_assign > 0) {
2891 $assigned_user = new User($this->db);
2892 $assigned_user->fetch($this->fk_user_assign);
2893 if (!empty($assigned_user->email)) {
2894 $sendto[$assigned_user->email] = $assigned_user->getFullName($langs)." <".$assigned_user->email.">";
2895 } else {
2896 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2897 }
2898 } else {
2899 $assigned_user = null;
2900 }
2901
2902 // Build array to display recipient list
2903 foreach ($internal_contacts as $key => $info_sendto) {
2904 // Avoid duplicate notifications
2905 if ($info_sendto['id'] == $user->id) {
2906 continue;
2907 }
2908
2909 // We check if the email address is not the assignee's address to prevent notification from being sent twice
2910 if (!empty($info_sendto['email']) && ($assigned_user === null || $assigned_user->email != $info_sendto['email'])) {
2911 $sendto[] = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'])." <".$info_sendto['email'].">";
2912 }
2913 }
2914
2915 if (empty($sendto)) {
2916 if (getDolGlobalString('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL')) {
2917 $sendto[getDolGlobalString('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL')] = getDolGlobalString('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL');
2918 } elseif (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')) {
2919 $sendto[getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')] = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO');
2920 }
2921 }
2922
2923 // Add global email address recipient
2924 if (getDolGlobalString('TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS') && !array_key_exists(getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO'), $sendto)) {
2925 if (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')) {
2926 $sendto[getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')] = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO');
2927 }
2928 }
2929
2930 $parameters = array('sendto' => $sendto);
2931 $reshook = $hookmanager->executeHooks('updateSendtoTicketMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2932 if (empty($reshook)) {
2933 $sendto = array_merge($sendto, $hookmanager->resArray);
2934 } elseif ($reshook > 0) {
2935 $sendto = $hookmanager->resArray;
2936 }
2937
2938 if (!empty($sendto)) {
2939 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE', $mysoc->name);
2940
2941 $subject = '['.$appli.'- ticket #'.$object->track_id.'] '.$this->subject;
2942
2943 // Message send
2944 $message = getDolGlobalString('TICKET_MESSAGE_MAIL_INTRO', $langs->trans('TicketMessageMailIntroText'));
2945 $message .= '<br><br>';
2946 $messagePost = GETPOST('message', 'restricthtml');
2947 if (!dol_textishtml($messagePost)) {
2948 $messagePost = dol_nl2br($messagePost);
2949 }
2950 $message .= $messagePost;
2951
2952 // Customer company infos
2953 $message .= '<br><br>';
2954 $message .= "==============================================";
2955 $message .= !empty($object->thirdparty->name) ? '<br>'.$langs->trans('ThirdParty')." : ".$object->thirdparty->name : '';
2956 $message .= !empty($object->thirdparty->town) ? '<br>'.$langs->trans('Town')." : ".$object->thirdparty->town : '';
2957 $message .= !empty($object->thirdparty->phone) ? '<br>'.$langs->trans('Phone')." : ".$object->thirdparty->phone : '';
2958
2959 // Email send to
2960 $message .= '<br><br>';
2961 if (!empty($assigned_user_dont_have_email)) {
2962 $message .= '<br>'.$langs->trans('NoEMail').' : '.$assigned_user_dont_have_email;
2963 }
2964 foreach ($sendto as $val) {
2965 $message .= '<br>'.$langs->trans('TicketNotificationRecipient').' : '.$val;
2966 }
2967
2968 // URL ticket
2969 $url_internal_ticket = dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id;
2970 $message .= '<br><br>';
2971 $message .= $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal').' : <a href="'.$url_internal_ticket.'">'.$object->track_id.'</a>';
2972
2973 $email_from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
2974
2975 $replyto = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_REPLYTO');
2976
2977 // don't try to send email if no recipient
2978 $this->sendTicketMessageByEmail($subject, $message, 0, $sendto, $listofpaths, $listofmimes, $listofnames, array(), $email_from, $replyto);
2979 }
2980 }
2981 } else {
2982 /*
2983 * Message created from the Backoffice / Private area
2984 *
2985 * Send emails to internal users (linked contacts) then, if private is not set, to external users (linked contacts or thirdparty email if no contact set)
2986 */
2987 if ((int) $send_email > 0) {
2988 // Retrieve internal contact datas
2989 $internal_contacts = $object->getInfosTicketInternalContact(1);
2990
2991 $sendto = array();
2992 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2993 // Set default subject
2994 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE', $mysoc->name);
2995
2996 $subject = GETPOST('subject', 'alphanohtml') ? GETPOST('subject', 'alphanohtml') : '['.$appli.' - '.$langs->trans("Ticket").' #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
2997
2998 $message_intro = $langs->trans('TicketNotificationEmailBody', "#".$object->id);
2999 $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : getDolGlobalString('TICKET_MESSAGE_MAIL_SIGNATURE');
3000
3001 $message = getDolGlobalString('TICKET_MESSAGE_MAIL_INTRO', $langs->trans('TicketMessageMailIntroText'));
3002 $message .= '<br><br>';
3003 $messagePost = GETPOST('message', 'restricthtml');
3004 if (!dol_textishtml($messagePost)) {
3005 $messagePost = dol_nl2br($messagePost);
3006 }
3007 $message .= $messagePost;
3008
3009 // Data about customer
3010 $message .= '<br><br>';
3011 $message .= "==============================================<br>";
3012 $message .= !empty($object->thirdparty->name) ? $langs->trans('ThirdParty')." : ".$object->thirdparty->name : '';
3013 $message .= !empty($object->thirdparty->town) ? '<br>'.$langs->trans('Town')." : ".$object->thirdparty->town : '';
3014 $message .= !empty($object->thirdparty->phone) ? '<br>'.$langs->trans('Phone')." : ".$object->thirdparty->phone : '';
3015
3016 // Build array to display recipient list
3017 foreach ($internal_contacts as $key => $info_sendto) {
3018 // Check if recipient email is current user, if yes, we avoid to send email to him.
3019 if ($info_sendto['id'] == $user->id) {
3020 dol_syslog("We cancel sending email to internal user ".$info_sendto['email']." because it is current user", LOG_DEBUG);
3021 continue;
3022 }
3023
3024 if ($info_sendto['email'] != '') {
3025 $email = $info_sendto['email'];
3026 if ($email != null) {
3027 $sendto[$email] = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'])." <".$info_sendto['email'].">";
3028 }
3029
3030 // Contact type
3031 $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], -1).' ('.strtolower((string) $info_sendto['libelle']).')';
3032 $message .= (!empty($recipient) ? '<br>'.$langs->trans('TicketNotificationRecipient').' : '.$recipient.'<br>' : '');
3033 }
3034 }
3035 $message .= '<br>';
3036 // URL ticket
3037 $url_internal_ticket = dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id;
3038
3039 // Add html link on url
3040 $message .= '<br>'.$langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal').' : <a href="'.$url_internal_ticket.'">'.$object->track_id.'</a><br>';
3041
3042 // Add global email address recipient
3043 if (getDolGlobalString('TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS') && !array_key_exists(getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO'), $sendto)) {
3044 if (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')) {
3045 $sendto[getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')] = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO');
3046 }
3047 }
3048
3049 $parameters = array('sendto' => $sendto);
3050 $reshook = $hookmanager->executeHooks('updateSendtoTicketMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3051 if (empty($reshook)) {
3052 $sendto = array_merge($sendto, $hookmanager->resArray);
3053 } elseif ($reshook > 0) {
3054 $sendto = $hookmanager->resArray;
3055 }
3056
3057 $sendtocc = array();
3058 if (getDolGlobalString("TICKET_SEND_INTERNAL_CC")) {
3059 $sendtocc = explode(',', getDolGlobalString("TICKET_SEND_INTERNAL_CC"));
3060 }
3061
3062 $email_from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
3063
3064 $replyto = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_REPLYTO');
3065
3066 // don't try to send email if no recipient
3067 if (!empty($sendto)) {
3068 $this->sendTicketMessageByEmail($subject, $message, 0, $sendto, $listofpaths, $listofmimes, $listofnames, $sendtocc, $email_from, $replyto);
3069 }
3070 }
3071
3072 /*
3073 * Send emails for externals users if not private (linked contacts)
3074 */
3075 if (empty($object->private)) {
3076 // If no contact, get email from thirdparty
3077 if (is_array($external_contacts) && count($external_contacts) === 0) {
3078 if (!empty($object->fk_soc)) {
3079 $object->fetch_thirdparty($object->fk_soc);
3080 $array_company = array(array('id' => -1, 'firstname' => '', 'lastname' => $object->thirdparty->name, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
3081 $external_contacts = array_merge($external_contacts, $array_company);
3082 } elseif (empty($object->fk_soc) && !empty($object->origin_replyto)) {
3083 $array_external = array(array('id' => -1, 'firstname' => '', 'lastname' => $object->origin_replyto, 'email' => $object->origin_replyto, 'libelle' => $langs->transnoentities('Customer'), 'socid' => 0));
3084 $external_contacts = array_merge($external_contacts, $array_external);
3085 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
3086 $array_external = array(array('id' => -1, 'firstname' => '', 'lastname' => $object->origin_email, 'email' => $object->origin_email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => 0)); // no fk_soc here, so $object->thirdparty was never fetched (mirrors the origin_replyto branch above)
3087 $external_contacts = array_merge($external_contacts, $array_external);
3088 }
3089 }
3090
3091 $sendto = array();
3092 if (is_array($external_contacts) && count($external_contacts) > 0) {
3093 // Get default subject for email to external contacts
3094 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE', $mysoc->name);
3095
3096 $subject = GETPOST('subject') ? GETPOST('subject') : '['.$appli.' - '.$langs->trans("Ticket").' #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
3097
3098 $message_intro = GETPOST('mail_intro') ? GETPOST('mail_intro', 'restricthtml') : getDolGlobalString('TICKET_MESSAGE_MAIL_INTRO');
3099 $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature', 'restricthtml') : getDolGlobalString('TICKET_MESSAGE_MAIL_SIGNATURE');
3100 if (!dol_textishtml($message_intro)) {
3101 $message_intro = dol_nl2br($message_intro);
3102 }
3103 if (!dol_textishtml($message_signature)) {
3104 $message_signature = dol_nl2br($message_signature);
3105 }
3106
3107 // We put intro after
3108 $messagePost = GETPOST('message', 'restricthtml');
3109 if (!dol_textishtml($messagePost)) {
3110 $messagePost = dol_nl2br($messagePost);
3111 }
3112 $message = $messagePost;
3113 $message .= '<br><br>';
3114
3115 foreach ($external_contacts as $key => $info_sendto) {
3116 // Check if recipient email is current user, if yes, we avoid to send email to him.
3117 if ($info_sendto['id'] == $user->contact_id) {
3118 continue;
3119 }
3120
3121 if ($info_sendto['email'] != '' && $info_sendto['email'] != $object->origin_email) {
3122 $email = $info_sendto['email'];
3123 if ($email != null) {
3124 $sendto[$email] = trim($info_sendto['firstname']." ".$info_sendto['lastname'])." <".$info_sendto['email'].">";
3125 }
3126
3127 $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], -1).' ('.strtolower((string) $info_sendto['libelle']).')';
3128 $message .= (!empty($recipient) ? '<br>'.$langs->trans('TicketNotificationRecipient').' : '.$recipient.'<br>' : '');
3129 }
3130 }
3131
3132 // If public interface is not enable, use link to internal page into mail
3133 $url_public_ticket = (getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE') ?
3134 (getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') . '/view.php' : dol_buildpath('/public/ticket/view.php', 2)) : dol_buildpath('/ticket/card.php', 2)).'?track_id='.urlencode($object->track_id);
3135
3136 if (getDolGlobalInt('TICKET_INCLUDE_LINK_TO_PUBLIC_INTERFACE_IN_MESSAGE')) {
3137 $message .= '<br>' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="' . $url_public_ticket . '">' . $object->track_id . '</a><br>';
3138 }
3139
3140 // Build final message
3141 $message = $message_intro.'<br><br>'.$message;
3142
3143 // Add signature
3144 $message .= '<br>'.$message_signature;
3145
3146 if (!empty($object->origin_replyto)) {
3147 $sendto[$object->origin_replyto] = $object->origin_replyto;
3148 } elseif (!empty($object->origin_email)) {
3149 $sendto[$object->origin_email] = $object->origin_email;
3150 }
3151
3152 if ($object->fk_soc > 0 && !array_key_exists($object->origin_replyto, $sendto) && !array_key_exists($object->origin_email, $sendto)) {
3153 $object->socid = $object->fk_soc;
3154 $object->fetch_thirdparty();
3155 if (!empty($object->thirdparty->email)) {
3156 $sendto[$object->thirdparty->email] = $object->thirdparty->email;
3157 }
3158 }
3159
3160 // Add global email address recipient
3161 if (getDolGlobalString('TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS') && !array_key_exists(getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO'), $sendto)) {
3162 if (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')) {
3163 $sendto[getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO')] = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO');
3164 }
3165 }
3166
3167 $parameters = array('sendto' => $sendto);
3168 $reshook = $hookmanager->executeHooks('updateSendtoTicketMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3169 if (empty($reshook)) {
3170 $sendto = array_merge($sendto, $hookmanager->resArray);
3171 } elseif ($reshook > 0) {
3172 $sendto = $hookmanager->resArray;
3173 }
3174
3175 $sendtocc = array();
3176 if (getDolGlobalString("TICKET_SEND_INTERNAL_CC")) {
3177 $sendtocc = explode(',', getDolGlobalString("TICKET_SEND_INTERNAL_CC"));
3178 }
3179
3180 // Don't try to send email when no recipient
3181 if (!empty($sendto)) {
3182 $email_from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
3183
3184 $replyto = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_REPLYTO');
3185
3186 $result = $this->sendTicketMessageByEmail($subject, $message, 0, $sendto, $listofpaths, $listofmimes, $listofnames, $sendtocc, $email_from, $replyto);
3187 if ($result) {
3188 // update last_msg_sent date of ticket (for last message sent to external users)
3189 $this->date_last_msg_sent = dol_now();
3190 $this->update($user, 1); // disable trigger when updating date_last_msg_sent. sendTicketMessageByEmail already create an event in actioncomm table.
3191
3192 // update event actioncomm $id
3193 //print 'update actioncomm id='.$id.' with sendto='.json_encode($sendto)." sendtocc=".json_encode($sendtocc)." email_msgid=".json_encode($this->email_msgid);
3194 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm";
3195 $sql .= " SET email_msgid = '".$this->db->escape($this->email_msgid)."',";
3196 $sql .= " email_subject = '".$this->db->escape($subject)."',";
3197 $sql .= " email_from = '".$this->db->escape($email_from)."',";
3198 $sql .= " email_to = '".$this->db->escape(implode(',', $sendto))."',";
3199 $sql .= " email_tocc = '".$this->db->escape(implode(',', $sendtocc))."',";
3200 $sql .= " reply_to = '".$this->db->escape($replyto)."'";
3201 $sql .= " WHERE id = ".((int) $id);
3202
3203 $resql = $this->db->query($sql);
3204 }
3205 }
3206 }
3207 }
3208 }
3209 }
3210
3211 // Set status back to "In progress" if not set yet, but only if internal user and not a private message
3212 // Or set status to "In progress" if the client has answered and if the ticket has started
3213 // So we are sure to leave the STATUS_DRAFT, STATUS_NEED_INFO.
3214 // Except if TICKET_SET_STATUS_ON_ANSWER has been defined
3215 if ((getDolGlobalInt('TICKET_SET_STATUS_ON_ANSWER', -1) < 0
3216 && ($object->status < self::STATUS_IN_PROGRESS && !$user->socid && !$private))
3217 || ($object->status > self::STATUS_IN_PROGRESS && $public_area)) {
3218 // Set status
3219 $object->setStatut($object::STATUS_IN_PROGRESS, null, '', 'TICKET_MODIFY');
3220 } elseif (getDolGlobalInt('TICKET_SET_STATUS_ON_ANSWER', -1) >= 0 && empty($user->socid) && empty($private)) {
3221 // Set status
3222 $object->setStatut(getDolGlobalInt('TICKET_SET_STATUS_ON_ANSWER'), null, '', 'TICKET_MODIFY');
3223 }
3224
3225 return 1;
3226 } else {
3227 setEventMessages($object->error, $object->errors, 'errors');
3228 return -1;
3229 }
3230 } else {
3231 setEventMessages($this->error, $this->errors, 'errors');
3232 return -1;
3233 }
3234 }
3235
3236
3252 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $array_receiver_cc = array(), $email_from = '', $replyto = '')
3253 {
3254 global $conf, $langs, $user, $hookmanager;
3255
3256 if (getDolGlobalString('TICKET_DISABLE_ALL_MAILS')) {
3257 dol_syslog(get_class($this).'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
3258 return false;
3259 }
3260
3261 $langs->load("mails");
3262
3263 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
3264 //$contactstatic = new Contact($this->db);
3265
3266 // If no receiver defined, load all ticket linked contacts
3267 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
3268 $array_receiver = $this->getInfosTicketInternalContact(1);
3269 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact(1));
3270 }
3271
3272 dol_syslog("sendTicketMessageByEmail array_receiver=".json_encode($array_receiver), LOG_DEBUG);
3273 dol_syslog("sendTicketMessageByEmail array_receiver_cc=".json_encode($array_receiver_cc), LOG_DEBUG);
3274
3275 $sendtocc = '';
3276 if ($send_internal_cc) {
3277 $sendtocc = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
3278 }
3279 if (!empty($array_receiver_cc) && is_array($array_receiver_cc)) {
3280 $sendtocc .= ($sendtocc ? ',' : '').implode(',', $array_receiver_cc);
3281 }
3282
3283 if (empty($email_from)) {
3284 $email_from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
3285 }
3286
3287 $parameters = array('from' => $email_from);
3288 $action = '';
3289 $reshook = $hookmanager->executeHooks('getTicketMessageEmailFrom', $parameters, $this, $action);
3290 if ($reshook && !empty($hookmanager->resArray['from'])) {
3291 $email_from = $hookmanager->resArray['from'];
3292 }
3293
3294 $is_sent = false;
3295 $this->email_msgids = array();
3296
3297 if (is_array($array_receiver) && count($array_receiver) > 0) {
3298 //foreach ($array_receiver as $key => $receiver) {
3299 $deliveryreceipt = 0;
3300 $filepath = $filename_list;
3301 $filename = $mimefilename_list;
3302 $mimetype = $mimetype_list;
3303
3304 // Send email
3305
3306 $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO');
3307 if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) {
3308 $conf->global->MAIN_MAIL_AUTOCOPY_TO = '';
3309 }
3310
3311 $upload_dir_tmp = $conf->user->dir_output."/".$user->id.'/temp';
3312
3313 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3314 $trackid = "tic".$this->id;
3315
3316 $moreinheader = 'X-Dolibarr-Info: sendTicketMessageByEmail'."\r\n";
3317 if (!empty($this->email_msgid)) {
3318 // We must also add 1 entry In-Reply-To: <$this->email_msgid> with Message-ID we respond from (See RFC5322).
3319 $moreinheader .= 'In-Reply-To: <'.$this->email_msgid.'>'."\r\n";
3320 // TODO We should now be able to give the in_reply_to as a dedicated parameter of new CMailFile() instead of into $moreinheader.
3321 }
3322
3323 // We should add here also a header 'References:'
3324 // According to RFC5322, we should add here all the References fields of the initial message concatenated with
3325 // the Message-ID of the message we respond from (but each ID must be once).
3326 $references = '';
3327 if (!empty($this->origin_references)) { // $this->origin_references should be '<'.$this->origin_references.'>'
3328 $references .= (empty($references) ? '' : ' ').$this->origin_references;
3329 }
3330 if (!empty($this->email_msgid) && !preg_match('/'.preg_quote($this->email_msgid, '/').'/', $references)) {
3331 $references .= (empty($references) ? '' : ' ').'<'.$this->email_msgid.'>';
3332 }
3333 if ($references) {
3334 $moreinheader .= 'References: '.$references."\r\n";
3335 // TODO We should now be able to give the references as a dedicated parameter of new CMailFile() instead of into $moreinheader.
3336 }
3337
3338 $receiverstring = '';
3339 foreach ($array_receiver as $key => $receiver) {
3340 $receiverstring .= ($receiverstring ? ',' : '').$receiver;
3341 }
3342
3343 $sendcontext = 'ticket';
3344
3345 // Send email
3346 $mailfile = new CMailFile($subject, $receiverstring, $email_from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1, '', '', $trackid, $moreinheader, $sendcontext, $replyto, $upload_dir_tmp);
3347
3348
3349 if ($mailfile->error) {
3350 setEventMessages($mailfile->error, null, 'errors');
3351 } else {
3352 $result = $mailfile->sendfile();
3353
3354 if ($result) {
3355 setEventMessages($langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($email_from, 2), $mailfile->getValidAddress($receiverstring, 2)), null, 'mesgs');
3356 $is_sent = true;
3357
3358 $this->email_msgid = $mailfile->msgid;
3359 } else {
3360 $langs->load("other");
3361 if ($mailfile->error) {
3362 setEventMessages($langs->trans('ErrorFailedToSendMail', $email_from, $receiverstring), null, 'errors');
3363 dol_syslog('ErrorFailedToSendMail from='.$email_from.' to='.$receiverstring.' : '.$mailfile->error);
3364 } elseif (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
3365 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'errors');
3366 } else {
3367 setEventMessages($langs->trans('ErrorFailedToSendMail', $email_from, $receiverstring), null, 'errors');
3368 dol_syslog('ErrorFailedToSendMail from='.$email_from.' to='.$receiverstring.' : (no error details)', LOG_WARNING);
3369 }
3370 }
3371 }
3372
3373 if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) {
3374 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
3375 }
3376 //}
3377 } else {
3378 $langs->load("other");
3379 setEventMessages($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage'), null, 'warnings');
3380 }
3381
3382 return $is_sent;
3383 }
3384
3385 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3393 public function load_board($user, $mode)
3394 {
3395 // phpcs:enable
3396 global $user, $langs;
3397
3398 $now = dol_now();
3399 $delay_warning = 0;
3400
3401 $clause = " WHERE";
3402
3403 $sql = "SELECT p.rowid, p.ref, p.datec as datec";
3404 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as p";
3405 if (empty($user->socid) && isModEnabled('societe') && !$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
3406 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
3407 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
3408 $clause = " AND";
3409 }
3410 $sql .= $clause." p.entity IN (".getEntity('ticket').")";
3411 if ($mode == 'opened') {
3412 $sql .= " AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.", ".Ticket::STATUS_CANCELED.")";
3413 }
3414 if ($user->socid) {
3415 $sql .= " AND p.fk_soc = ".((int) $user->socid);
3416 }
3417
3418 $resql = $this->db->query($sql);
3419 if ($resql) {
3420 $label = $labelShort = '';
3421 $status = '';
3422 if ($mode == 'opened') {
3423 $status = 'openall';
3424 //$delay_warning = $conf->ticket->warning_delay;
3425 $delay_warning = 0;
3426 $label = $langs->trans("MenuListNonClosed");
3427 $labelShort = $langs->trans("MenuListNonClosed");
3428 }
3429
3430 $response = new WorkboardResponse();
3431 //$response->warning_delay = $delay_warning / 60 / 60 / 24;
3432 $response->label = $label;
3433 $response->labelShort = $labelShort;
3434 $response->url = DOL_URL_ROOT.'/ticket/list.php?search_fk_statut[]='.$status;
3435 $response->img = img_object('', "ticket");
3436
3437 // This assignment in condition is not a bug. It allows walking the results.
3438 while ($obj = $this->db->fetch_object($resql)) {
3439 $response->nbtodo++;
3440 if ($mode == 'opened') {
3441 $datelimit = (int) $this->db->jdate($obj->datec) + (int) $delay_warning;
3442 if ($datelimit < $now) {
3443 //$response->nbtodolate++;
3444 }
3445 }
3446 }
3447 return $response;
3448 } else {
3449 $this->error = $this->db->lasterror();
3450 return -1;
3451 }
3452 }
3453
3459 public function loadStateBoard()
3460 {
3461 global $user;
3462
3463 $this->nb = array();
3464 $clause = "WHERE";
3465
3466 $sql = "SELECT count(p.rowid) as nb";
3467 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as p";
3468 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
3469 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
3470 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3471 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
3472 $clause = "AND";
3473 }
3474 $sql .= " ".$clause." p.entity IN (".getEntity('ticket').")";
3475
3476 $resql = $this->db->query($sql);
3477 if ($resql) {
3478 // This assignment in condition is not a bug. It allows walking the results.
3479 while ($obj = $this->db->fetch_object($resql)) {
3480 $this->nb["ticket"] = $obj->nb;
3481 }
3482 $this->db->free($resql);
3483 return 1;
3484 } else {
3485 dol_print_error($this->db);
3486 $this->error = $this->db->lasterror();
3487 return -1;
3488 }
3489 }
3490
3499 public static function replaceThirdparty($db, $origin_id, $dest_id)
3500 {
3501 $tables = array('ticket');
3502
3503 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
3504 }
3505
3513 public function getKanbanView($option = '', $arraydata = null)
3514 {
3515 global $langs;
3516
3517 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3518
3519 $return = '<div class="box-flex-item box-flex-grow-zero">';
3520 $return .= '<div class="info-box info-box-sm">';
3521 $return .= '<span class="info-box-icon bg-infobox-action">';
3522 $return .= img_picto('', $this->picto);
3523 $return .= '</span>';
3524 $return .= '<div class="info-box-content">';
3525 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
3526 if ($selected >= 0) {
3527 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
3528 }
3529 if (!empty($arraydata['user_assignment'])) {
3530 $return .= '<br><span class="info-box-label" title="'.dol_escape_htmltag($langs->trans("AssignedTo")).'">'.$arraydata['user_assignment'].'</span>';
3531 }
3532 if (property_exists($this, 'type_code') && !empty($this->type_code)) {
3533 $return .= '<br>';
3534 $return .= '<div class="tdoverflowmax125 inline-block">'.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$this->type_code, 'c_ticket_type', 'code', 'label', $this->type_code).'</div>';
3535 }
3536 if (method_exists($this, 'getLibStatut')) {
3537 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
3538 }
3539 $return .= '</div>';
3540 $return .= '</div>';
3541 $return .= '</div>';
3542
3543 return $return;
3544 }
3545
3557 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3558 {
3559 global $langs;
3560
3561 $langs->load("ticket");
3562 $outputlangs->load("ticket");
3563
3564 if (!dol_strlen($modele)) {
3565 $modele = 'generic_ticket_odt';
3566
3567 if (!empty($this->model_pdf)) {
3568 $modele = $this->model_pdf;
3569 } elseif (getDolGlobalString('TICKET_ADDON_PDF')) {
3570 $modele = getDolGlobalString('TICKET_ADDON_PDF');
3571 }
3572 }
3573
3574 $modelpath = "core/modules/ticket/doc/";
3575
3576 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3577 }
3578}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$c
Definition line.php:334
$object ref
Definition info.php:90
Class to manage agenda events (actions)
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage contact/addresses.
Class to manage Dolibarr database access.
Class to manage ECM files.
Class to manage generation of HTML components Only common components must be here.
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage third parties objects (customers, suppliers, prospects...)
fetch($id=0, $ref='', $track_id='', $email_msgid='')
Load object in memory from the database.
fetchAll($user, $sortorder='ASC', $sortfield='t.datec', $limit=0, $offset=0, $arch=0, $filter='')
Load all objects in memory from database.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
createTicketMessage($user, $notrigger=0, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $send_email=false, $public_area=0, $summary='', $external_contacts=[])
Add message into database.
listeContact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1)
Get array of all contacts for a ticket Override method of file commonobject.class....
loadCacheMsgsTicket()
Load the list of event on ticket into ->cache_msgs_ticket.
setProgression($percent)
Define progression of current ticket.
searchSocidByEmail($email, $type=0, $filters=array(), $clause='AND')
Search and fetch thirparties by email.
loadCacheSeveritiesTickets()
Load into cache the list of ticket severities (configurable in the dictionary)
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]',...
getInfosTicketExternalContact($status=-1)
Retrieve information about external contacts.
searchContactByEmail($email, $socid=0, $case='')
Search and fetch contacts by email.
getIdTicketCustomerInvolvedContact()
Return id des contacts clients des intervenants.
LibStatut($status, $mode=0, $notooltip=0, $progress=0)
Return status label of object.
setContract($contractid)
Link element with a contract.
setReadDate($user, $notrigger=0)
Set read date if not already set.
getTicketAllContacts()
Return id of all contacts for ticket.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
assignUser($user, $id_assign_user, $notrigger=0)
Set an assigned user to a ticket.
loadStateBoard()
Load indicator this->nb of global stats widget.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
printSelectStatus($selected="")
Print selected status.
is_photo_available($sdir)
Return if at least one photo is available.
getIdTicketInternalContact()
Return id des contacts interne de suivi.
update($user, $notrigger=0)
Update object into database.
loadCacheCategoriesTickets($publicgroup=-1)
Load into a cache array, the list of ticket categories (setup done into dictionary)
setCustomer($id)
Define parent commany of current ticket.
markAsRead($user, $notrigger=0)
Mark a message as read.
getDefaultRef($thirdparty=null)
Get a default reference.
const STATUS_NOT_READ
Status.
sendTicketMessageByEmail($subject, $message, $send_internal_cc=0, $array_receiver=array(), $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $array_receiver_cc=array(), $email_from='', $replyto='')
Send ticket by email to linked contacts.
getTicketAllCustomerContacts()
Return id of all contacts for ticket.
verify()
Check properties of ticket are ok (like ref, track_id, ...).
setCategories($categories)
Sets object to supplied categories.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
newMessage($user, &$action, $private=1, $public_area=0)
Add new message on a ticket (private/public area).
getIdTicketCustomerContact()
Return id des contacts clients pour le suivi ticket.
checkExistingRef(string $action, string $getRef)
Check if ref exists or not.
__construct(DoliDB $db)
Constructor.
loadCacheTypesTickets()
Load into a cache the types of tickets (setup done into dictionaries)
getLibStatut($mode=0)
Return status label of object.
close(User $user, $mode=0)
Close a ticket.
getIdTicketInternalInvolvedContact()
Return id des contacts clients des intervenants.
copyFilesForTicket($forcetrackid=null)
Copy files defined into $_SESSION array into the ticket directory of attached files.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getInfosTicketInternalContact($status=-1)
Retrieve information about internal contacts.
create($user, $notrigger=0)
Create object into database.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dirbasename($pathfile)
Return the relative dirname (relative to DOL_DATA_ROOT) of a full path string.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
Class to generate the form for creating a new ticket.
generate_random_id($car=16)
Generate a random id.