28require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
29require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
41 public $element =
'ticket';
46 public $table_element =
'ticket';
51 public $fk_element =
'fk_ticket';
56 public $ismultientitymanaged = 1;
61 public $isextrafieldmanaged = 1;
66 public $picto =
'ticket';
92 public $fk_user_create;
97 public $fk_user_assign;
144 public $category_code;
149 public $severity_code;
179 public $date_read =
'';
184 public $date_last_msg_sent =
'';
189 public $date_close =
'';
194 public $cache_types_tickets;
199 public $cache_category_tickets;
204 public $cache_severity_tickets;
209 public $cache_msgs_ticket;
219 public $statuts_short;
224 public $notify_tiers_at_create;
255 public $regeximgext =
'\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm';
261 const STATUS_READ = 1;
262 const STATUS_ASSIGNED = 2;
263 const STATUS_IN_PROGRESS = 3;
264 const STATUS_NEED_MORE_INFO = 5;
265 const STATUS_WAITING = 7;
266 const STATUS_CLOSED = 8;
267 const STATUS_CANCELED = 9;
298 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-2,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id"),
299 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>5,
'notnull'=>1,
'index'=>1),
300 '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),
301 'track_id' => array(
'type'=>
'varchar(255)',
'label'=>
'TicketTrackId',
'visible'=>-2,
'enabled'=>1,
'position'=>11,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"Help text"),
302 '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'),
303 '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'),
304 'subject' => array(
'type'=>
'varchar(255)',
'label'=>
'Subject',
'visible'=>1,
'enabled'=>1,
'position'=>18,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"",
'css'=>
'maxwidth200 tdoverflowmax200',
'autofocusoncreate'=>1),
305 'type_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Type',
'visible'=>1,
'enabled'=>1,
'position'=>20,
'notnull'=>-1,
'help'=>
"",
'csslist'=>
'maxwidth125 tdoverflowmax50'),
306 'category_code' => array(
'type'=>
'varchar(32)',
'label'=>
'TicketCategory',
'visible'=>-1,
'enabled'=>1,
'position'=>21,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100 tdoverflowmax200'),
307 'severity_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Severity',
'visible'=>1,
'enabled'=>1,
'position'=>22,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100'),
308 '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'),
309 'notify_tiers_at_create' => array(
'type'=>
'integer',
'label'=>
'NotifyThirdparty',
'visible'=>-1,
'enabled'=>0,
'position'=>51,
'notnull'=>1,
'index'=>1),
310 'fk_project' => array(
'type'=>
'integer:Project:projet/class/project.class.php',
'label'=>
'Project',
'visible'=>-1,
'enabled'=>
'$conf->project->enabled',
'position'=>52,
'notnull'=>-1,
'index'=>1,
'help'=>
"LinkToProject"),
312 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'visible'=>1,
'enabled'=>1,
'position'=>500,
'notnull'=>1,
'csslist'=>
'nowraponall'),
313 'date_read' => array(
'type'=>
'datetime',
'label'=>
'TicketReadOn',
'visible'=>-1,
'enabled'=>1,
'position'=>501,
'notnull'=>1),
314 'date_last_msg_sent' => array(
'type'=>
'datetime',
'label'=>
'TicketLastMessageDate',
'visible'=>0,
'enabled'=>1,
'position'=>502,
'notnull'=>-1),
315 'fk_user_assign' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'AssignedTo',
'visible'=>1,
'enabled'=>1,
'position'=>505,
'notnull'=>1,
'csslist'=>
'tdoverflowmax100 maxwidth150onsmartphone'),
316 'date_close' => array(
'type'=>
'datetime',
'label'=>
'TicketCloseOn',
'visible'=>-1,
'enabled'=>1,
'position'=>510,
'notnull'=>1),
317 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'visible'=>-1,
'enabled'=>1,
'position'=>520,
'notnull'=>1),
318 'message' => array(
'type'=>
'html',
'label'=>
'Message',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,),
319 'email_msgid' => array(
'type'=>
'varchar(255)',
'label'=>
'EmailMsgID',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'help'=>
'EmailMsgIDDesc',
'csslist'=>
'tdoverflowmax100'),
320 'email_date' => array(
'type'=>
'datetime',
'label'=>
'EmailDate',
'visible'=>-2,
'enabled'=>1,
'position'=>541),
321 'progress' => array(
'type'=>
'integer',
'label'=>
'Progression',
'visible'=>-1,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'css'=>
'right',
'help'=>
"",
'isameasure'=>2,
'csslist'=>
'width50'),
322 'resolution' => array(
'type'=>
'integer',
'label'=>
'Resolution',
'visible'=>-1,
'enabled'=>
'getDolGlobalString("TICKET_ENABLE_RESOLUTION")',
'position'=>550,
'notnull'=>1),
323 'fk_statut' => array(
'type'=>
'integer',
'label'=>
'Status',
'visible'=>1,
'enabled'=>1,
'position'=>600,
'notnull'=>1,
'index'=>1,
'arrayofkeyval'=>array(0 =>
'Unread', 1 =>
'Read', 3 =>
'Answered', 4 =>
'Assigned', 5 =>
'InProgress', 6 =>
'Waiting', 8 =>
'SolvedClosed', 9 =>
'Deleted')),
324 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
340 $this->statuts_short = array(
341 self::STATUS_NOT_READ =>
'Unread',
342 self::STATUS_READ =>
'Read',
343 self::STATUS_ASSIGNED =>
'Assigned',
344 self::STATUS_IN_PROGRESS =>
'InProgress',
345 self::STATUS_WAITING =>
'OnHold',
346 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformationShort',
347 self::STATUS_CLOSED =>
'SolvedClosed',
348 self::STATUS_CANCELED =>
'Canceled'
350 $this->statuts = array(
351 self::STATUS_NOT_READ =>
'Unread',
352 self::STATUS_READ =>
'Read',
353 self::STATUS_ASSIGNED =>
'Assigned',
354 self::STATUS_IN_PROGRESS =>
'InProgress',
355 self::STATUS_WAITING =>
'OnHold',
356 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformation',
357 self::STATUS_CLOSED =>
'SolvedClosed',
358 self::STATUS_CANCELED =>
'Canceled'
370 $this->errors = array();
375 if (isset($this->
ref)) {
376 $this->
ref = trim($this->
ref);
379 if (isset($this->track_id)) {
380 $this->track_id = trim($this->track_id);
383 if (isset($this->fk_soc)) {
384 $this->fk_soc = (int) $this->fk_soc;
387 if (isset($this->fk_project)) {
388 $this->fk_project = (int) $this->fk_project;
391 if (isset($this->origin_email)) {
392 $this->origin_email = trim($this->origin_email);
395 if (isset($this->fk_user_create)) {
396 $this->fk_user_create = (int) $this->fk_user_create;
399 if (isset($this->fk_user_assign)) {
400 $this->fk_user_assign = (int) $this->fk_user_assign;
403 if (isset($this->subject)) {
404 $this->subject = trim($this->subject);
407 if (isset($this->message)) {
408 $this->message = trim($this->message);
410 $this->errors[] =
'ErrorFieldTooLong';
411 dol_syslog(get_class($this).
'::create error -1 message too long', LOG_ERR);
416 if (isset($this->fk_statut)) {
417 $this->fk_statut = (int) $this->fk_statut;
420 if (isset($this->resolution)) {
421 $this->resolution = trim($this->resolution);
424 if (isset($this->progress)) {
425 $this->progress = trim($this->progress);
428 if (isset($this->timing)) {
429 $this->timing = trim($this->timing);
432 if (isset($this->type_code)) {
433 $this->type_code = trim($this->type_code);
436 if (isset($this->category_code)) {
437 $this->category_code = trim($this->category_code);
440 if (isset($this->severity_code)) {
441 $this->severity_code = trim($this->severity_code);
444 if (empty($this->
ref)) {
445 $this->errors[] =
'ErrorTicketRefRequired';
446 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
460 public function create($user, $notrigger = 0)
468 if (empty($this->track_id)) {
474 $result = $this->
verify();
477 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
480 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ticket(";
484 $sql .=
"fk_project,";
485 $sql .=
"origin_email,";
486 $sql .=
"fk_user_create,";
487 $sql .=
"fk_user_assign,";
488 $sql .=
"email_msgid,";
489 $sql .=
"email_date,";
492 $sql .=
"fk_statut,";
493 $sql .=
"resolution,";
496 $sql .=
"type_code,";
497 $sql .=
"category_code,";
498 $sql .=
"severity_code,";
500 $sql .=
"date_read,";
501 $sql .=
"date_close,";
503 $sql .=
"notify_tiers_at_create,";
505 $sql .=
") VALUES (";
506 $sql .=
" ".(!isset($this->
ref) ?
'' :
"'".$this->db->escape($this->
ref).
"'").
",";
507 $sql .=
" ".(!isset($this->track_id) ?
'NULL' :
"'".$this->db->escape($this->track_id).
"'").
",";
508 $sql .=
" ".($this->fk_soc > 0 ? $this->db->escape($this->fk_soc) :
"null").
",";
509 $sql .=
" ".($this->fk_project > 0 ? $this->db->escape($this->fk_project) :
"null").
",";
510 $sql .=
" ".(!isset($this->origin_email) ?
'NULL' :
"'".$this->db->escape($this->origin_email).
"'").
",";
511 $sql .=
" ".(!isset($this->fk_user_create) ? ($user->id > 0 ? $user->id :
'NULL') : ($this->fk_user_create > 0 ? $this->fk_user_create :
'NULL')).
",";
512 $sql .=
" ".($this->fk_user_assign > 0 ? $this->fk_user_assign :
'NULL').
",";
513 $sql .=
" ".(empty($this->email_msgid) ?
'NULL' :
"'".$this->db->escape($this->email_msgid).
"'").
",";
514 $sql .=
" ".(empty($this->email_date) ?
'NULL' :
"'".$this->db->idate($this->email_date).
"'").
",";
515 $sql .=
" ".(!isset($this->subject) ?
'NULL' :
"'".$this->db->escape($this->subject).
"'").
",";
516 $sql .=
" ".(!isset($this->message) ?
'NULL' :
"'".$this->db->escape($this->message).
"'").
",";
517 $sql .=
" ".(!isset($this->fk_statut) ?
'0' :
"'".$this->db->escape($this->fk_statut).
"'").
",";
518 $sql .=
" ".(!isset($this->resolution) ?
'NULL' :
"'".$this->db->escape($this->resolution).
"'").
",";
519 $sql .=
" ".(!isset($this->progress) ?
'0' :
"'".$this->db->escape($this->progress).
"'").
",";
520 $sql .=
" ".(!isset($this->timing) ?
'NULL' :
"'".$this->db->escape($this->timing).
"'").
",";
521 $sql .=
" ".(!isset($this->type_code) ?
'NULL' :
"'".$this->db->escape($this->type_code).
"'").
",";
522 $sql .=
" ".(empty($this->category_code) || $this->category_code ==
'-1' ?
'NULL' :
"'".$this->db->escape($this->category_code).
"'").
",";
523 $sql .=
" ".(!isset($this->severity_code) ?
'NULL' :
"'".$this->db->escape($this->severity_code).
"'").
",";
524 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
525 $sql .=
" ".(!isset($this->date_read) ||
dol_strlen($this->date_read) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_read).
"'").
",";
526 $sql .=
" ".(!isset($this->date_close) ||
dol_strlen($this->date_close) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_close).
"'");
527 $sql .=
", ".((int) $this->entity);
528 $sql .=
", ".(!isset($this->notify_tiers_at_create) ?
'1' :
"'".$this->db->escape($this->notify_tiers_at_create).
"'");
529 $sql .=
", ".(!isset($this->ip) ?
'NULL' :
"'".$this->db->escape($this->ip).
"'");
534 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
535 $resql = $this->db->query($sql);
538 $this->errors[] =
"Error ".$this->db->lasterror();
542 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"ticket");
547 if ($this->
add_contact($user->id,
'CONTRIBUTOR',
'internal') < 0) {
552 if (!$error && $this->fk_user_assign > 0) {
553 if ($this->
add_contact($this->fk_user_assign,
'SUPPORTTEC',
'internal') < 0) {
567 if (!$error && !$notrigger) {
578 foreach ($this->errors as $errmsg) {
579 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
580 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
582 $this->db->rollback();
589 $this->db->rollback();
590 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
604 public function fetch($id =
'', $ref =
'', $track_id =
'', $email_msgid =
'')
609 if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
610 $this->error =
'ErrorWrongParameters';
617 $sql .=
" t.entity,";
619 $sql .=
" t.track_id,";
620 $sql .=
" t.fk_soc,";
621 $sql .=
" t.fk_project,";
622 $sql .=
" t.origin_email,";
623 $sql .=
" t.fk_user_create,";
624 $sql .=
" t.fk_user_assign,";
625 $sql .=
" t.email_msgid,";
626 $sql .=
" t.email_date,";
627 $sql .=
" t.subject,";
628 $sql .=
" t.message,";
629 $sql .=
" t.fk_statut as status,";
630 $sql .=
" t.resolution,";
631 $sql .=
" t.progress,";
632 $sql .=
" t.timing,";
633 $sql .=
" t.type_code,";
634 $sql .=
" t.category_code,";
635 $sql .=
" t.severity_code,";
637 $sql .=
" t.date_read,";
638 $sql .=
" t.date_last_msg_sent,";
639 $sql .=
" t.date_close,";
642 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
643 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
644 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
645 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
646 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
649 $sql .=
" WHERE t.rowid = ".((int) $id);
651 $sql .=
" WHERE t.entity IN (".getEntity($this->element, 1).
")";
653 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
654 } elseif ($track_id) {
655 $sql .=
" AND t.track_id = '".$this->db->escape($track_id).
"'";
657 $sql .=
" AND t.email_msgid = '".$this->db->escape($email_msgid).
"'";
661 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
662 $resql = $this->db->query($sql);
664 if ($this->db->num_rows($resql)) {
665 $obj = $this->db->fetch_object($resql);
667 $this->
id = $obj->rowid;
668 $this->entity = $obj->entity;
669 $this->
ref = $obj->ref;
670 $this->track_id = $obj->track_id;
671 $this->fk_soc = $obj->fk_soc;
672 $this->socid = $obj->fk_soc;
673 $this->fk_project = $obj->fk_project;
674 $this->origin_email = $obj->origin_email;
675 $this->fk_user_create = $obj->fk_user_create;
676 $this->fk_user_assign = $obj->fk_user_assign;
677 $this->email_msgid = $obj->email_msgid;
678 $this->email_date = $this->db->jdate($obj->email_date);
679 $this->subject = $obj->subject;
680 $this->message = $obj->message;
681 $this->ip = $obj->ip;
683 $this->status = $obj->status;
684 $this->fk_statut = $this->status;
686 $this->resolution = $obj->resolution;
687 $this->progress = $obj->progress;
688 $this->timing = $obj->timing;
690 $this->type_code = $obj->type_code;
691 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
692 $this->type_label = $label_type;
694 $this->category_code = $obj->category_code;
695 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
696 $this->category_label = $label_category;
698 $this->severity_code = $obj->severity_code;
699 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
700 $this->severity_label = $label_severity;
702 $this->datec = $this->db->jdate($obj->datec);
703 $this->date_creation = $this->db->jdate($obj->datec);
704 $this->date_read = $this->db->jdate($obj->date_read);
705 $this->date_validation = $this->db->jdate($obj->date_read);
706 $this->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
707 $this->date_close = $this->db->jdate($obj->date_close);
708 $this->tms = $this->db->jdate($obj->tms);
709 $this->date_modification = $this->db->jdate($obj->tms);
713 $this->db->free($resql);
719 $this->error =
"Error ".$this->db->lasterror();
720 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
738 public function fetchAll($user, $sortorder =
'ASC', $sortfield =
't.datec', $limit =
'', $offset = 0, $arch =
'', $filter =
'')
745 $extrafields->fetch_name_optionals_label($this->table_element);
750 $sql .=
" t.track_id,";
751 $sql .=
" t.fk_soc,";
752 $sql .=
" t.fk_project,";
753 $sql .=
" t.origin_email,";
754 $sql .=
" t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
755 $sql .=
" t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
756 $sql .=
" t.subject,";
757 $sql .=
" t.message,";
758 $sql .=
" t.fk_statut,";
759 $sql .=
" t.resolution,";
760 $sql .=
" t.progress,";
761 $sql .=
" t.timing,";
762 $sql .=
" t.type_code,";
763 $sql .=
" t.category_code,";
764 $sql .=
" t.severity_code,";
766 $sql .=
" t.date_read,";
767 $sql .=
" t.date_last_msg_sent,";
768 $sql .=
" t.date_close,";
770 $sql .=
", type.label as type_label, category.label as category_label, severity.label as severity_label";
772 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
773 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
",ef.".$key.
" as options_".$key :
'');
775 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
776 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
777 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
778 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
779 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid=t.fk_soc";
780 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as uc ON uc.rowid=t.fk_user_create";
781 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as ua ON ua.rowid=t.fk_user_assign";
782 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
783 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ticket_extrafields as ef on (t.rowid = ef.fk_object)";
785 if (empty($user->rights->societe->client->voir) && !$user->socid) {
786 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
789 $sql .=
" WHERE t.entity IN (".getEntity(
'ticket').
")";
792 if (!empty($filter)) {
793 foreach ($filter as $key => $value) {
794 if (strpos($key,
'date')) {
795 $sql .=
" AND ".$key.
" = '".$this->db->escape($value).
"'";
796 } elseif (($key ==
't.fk_user_assign') || ($key ==
't.type_code') || ($key ==
't.category_code') || ($key ==
't.severity_code') || ($key ==
't.fk_soc')) {
797 $sql .=
" AND ".$key.
" = '".$this->db->escape($value).
"'";
798 } elseif ($key ==
't.fk_statut') {
799 if (is_array($value) && count($value) > 0) {
800 $sql .=
" AND ".$key.
" IN (".$this->db->sanitize(implode(
',', $value)).
")";
802 $sql .=
" AND ".$key.
' = '.((int) $value);
805 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
809 if (empty($user->rights->societe->client->voir) && !$user->socid) {
810 $sql .=
" AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
811 } elseif ($user->socid) {
812 $sql .=
" AND t.fk_soc = ".((int) $user->socid);
815 $sql .= $this->db->order($sortfield, $sortorder);
816 if (!empty($limit)) {
817 $sql .= $this->db->plimit($limit + 1, $offset);
820 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
821 $resql = $this->db->query($sql);
824 $this->lines = array();
826 $num = $this->db->num_rows($resql);
831 $obj = $this->db->fetch_object($resql);
835 $line->id = $obj->rowid;
836 $line->rowid = $obj->rowid;
837 $line->ref = $obj->ref;
838 $line->track_id = $obj->track_id;
839 $line->fk_soc = $obj->fk_soc;
840 $line->fk_project = $obj->fk_project;
841 $line->origin_email = $obj->origin_email;
843 $line->fk_user_create = $obj->fk_user_create;
844 $line->user_create_lastname = $obj->user_create_lastname;
845 $line->user_create_firstname = $obj->user_create_firstname;
847 $line->fk_user_assign = $obj->fk_user_assign;
848 $line->user_assign_lastname = $obj->user_assign_lastname;
849 $line->user_assign_firstname = $obj->user_assign_firstname;
851 $line->subject = $obj->subject;
852 $line->message = $obj->message;
853 $line->fk_statut = $obj->fk_statut;
854 $line->resolution = $obj->resolution;
855 $line->progress = $obj->progress;
856 $line->timing = $obj->timing;
858 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
859 $line->type_label = $label_type;
861 $this->category_code = $obj->category_code;
862 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
863 $line->category_label = $label_category;
865 $this->severity_code = $obj->severity_code;
866 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
867 $line->severity_label = $label_severity;
869 $line->datec = $this->db->jdate($obj->datec);
870 $line->date_read = $this->db->jdate($obj->date_read);
871 $line->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
872 $line->date_close = $this->db->jdate($obj->date_close);
875 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
876 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
877 $tmpkey =
'options_'.$key;
878 $line->{$tmpkey} = $obj->$tmpkey;
882 $this->lines[$i] = $line;
886 $this->db->free($resql);
889 $this->error =
"Error ".$this->db->lasterror();
890 dol_syslog(get_class($this).
"::fetchAll ".$this->error, LOG_ERR);
902 public function update($user = 0, $notrigger = 0)
904 global $conf, $langs, $hookmanager;
913 if (isset($this->
ref)) {
914 $this->
ref = trim($this->
ref);
917 if (isset($this->track_id)) {
918 $this->track_id = trim($this->track_id);
921 if (isset($this->fk_soc)) {
922 $this->fk_soc = (int) $this->fk_soc;
925 if (isset($this->fk_project)) {
926 $this->fk_project = (int) $this->fk_project;
929 if (isset($this->origin_email)) {
930 $this->origin_email = trim($this->origin_email);
933 if (isset($this->fk_user_create)) {
934 $this->fk_user_create = (int) $this->fk_user_create;
937 if (isset($this->fk_user_assign)) {
938 $this->fk_user_assign = (int) $this->fk_user_assign;
941 if (isset($this->subject)) {
942 $this->subject = trim($this->subject);
945 if (isset($this->message)) {
946 $this->message = trim($this->message);
948 $this->errors[] =
'ErrorFieldTooLong';
949 dol_syslog(get_class($this).
'::update error -1 message too long', LOG_ERR);
954 if (isset($this->fk_statut)) {
955 $this->fk_statut = (int) $this->fk_statut;
958 if (isset($this->resolution)) {
959 $this->resolution = trim($this->resolution);
962 if (isset($this->progress)) {
963 $this->progress = trim($this->progress);
966 if (isset($this->timing)) {
967 $this->timing = trim($this->timing);
970 if (isset($this->type_code)) {
971 $this->timing = trim($this->type_code);
974 if (isset($this->category_code)) {
975 $this->timing = trim($this->category_code);
978 if (isset($this->severity_code)) {
979 $this->timing = trim($this->severity_code);
985 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket SET";
986 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"").
",";
987 $sql .=
" track_id=".(isset($this->track_id) ?
"'".$this->db->escape($this->track_id).
"'" :
"null").
",";
988 $sql .=
" fk_soc=".(isset($this->fk_soc) ?
"'".$this->db->escape($this->fk_soc).
"'" :
"null").
",";
989 $sql .=
" fk_project=".(isset($this->fk_project) ?
"'".$this->db->escape($this->fk_project).
"'" :
"null").
",";
990 $sql .=
" origin_email=".(isset($this->origin_email) ?
"'".$this->db->escape($this->origin_email).
"'" :
"null").
",";
991 $sql .=
" fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create :
"null").
",";
992 $sql .=
" fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign :
"null").
",";
993 $sql .=
" subject=".(isset($this->subject) ?
"'".$this->db->escape($this->subject).
"'" :
"null").
",";
994 $sql .=
" message=".(isset($this->message) ?
"'".$this->db->escape($this->message).
"'" :
"null").
",";
995 $sql .=
" fk_statut=".(isset($this->fk_statut) ? $this->fk_statut :
"0").
",";
996 $sql .=
" resolution=".(isset($this->resolution) ? $this->resolution :
"null").
",";
997 $sql .=
" progress=".(isset($this->progress) ?
"'".$this->db->escape($this->progress).
"'" :
"null").
",";
998 $sql .=
" timing=".(isset($this->timing) ?
"'".$this->db->escape($this->timing).
"'" :
"null").
",";
999 $sql .=
" type_code=".(isset($this->type_code) ?
"'".$this->db->escape($this->type_code).
"'" :
"null").
",";
1000 $sql .=
" category_code=".(isset($this->category_code) ?
"'".$this->db->escape($this->category_code).
"'" :
"null").
",";
1001 $sql .=
" severity_code=".(isset($this->severity_code) ?
"'".$this->db->escape($this->severity_code).
"'" :
"null").
",";
1002 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
1003 $sql .=
" date_read=".(dol_strlen($this->date_read) != 0 ?
"'".$this->db->idate($this->date_read).
"'" :
'null').
",";
1004 $sql .=
" date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ?
"'".$this->db->idate($this->date_last_msg_sent).
"'" :
'null').
",";
1005 $sql .=
" date_close=".(dol_strlen($this->date_close) != 0 ?
"'".$this->db->idate($this->date_close).
"'" :
'null');
1006 $sql .=
" WHERE rowid=".((int) $this->
id);
1010 $resql = $this->db->query($sql);
1013 $this->errors[] =
"Error ".$this->db->lasterror();
1018 $result = $this->insertExtraFields();
1024 if (!$error && !$notrigger) {
1026 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1035 foreach ($this->errors as $errmsg) {
1036 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1037 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1039 $this->db->rollback();
1042 $this->db->commit();
1054 public function delete($user, $notrigger = 0)
1056 global $conf, $langs;
1064 $result = $this->call_trigger(
'TICKET_DELETE', $user);
1074 $res = $this->delete_linked_contact();
1076 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1083 $res = $this->deleteObjectLinked();
1091 $result = $this->deleteExtraFields();
1094 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1101 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_ticket";
1102 $sql .=
" WHERE fk_ticket = ".(int) $this->
id;
1104 $result = $this->db->query($sql);
1107 $this->errors[] = $this->db->lasterror();
1112 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ticket";
1113 $sql .=
" WHERE rowid=".((int) $this->
id);
1115 dol_syslog(get_class($this).
"::delete sql=".$sql);
1116 $resql = $this->db->query($sql);
1119 $this->errors[] =
"Error ".$this->db->lasterror();
1125 foreach ($this->errors as $errmsg) {
1126 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1127 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1129 $this->db->rollback();
1132 $this->db->commit();
1148 $object =
new Ticket($this->db);
1153 $object->fetch($fromid);
1155 $object->statut = 0;
1160 $object->context[
'createfromclone'] =
'createfromclone';
1161 $result = $object->create($user);
1165 $this->error = $object->error;
1172 unset($object->context[
'createfromclone']);
1176 $this->db->commit();
1179 $this->db->rollback();
1194 $this->
ref =
'TI0501-001';
1195 $this->track_id =
'XXXXaaaa';
1196 $this->origin_email =
'email@email.com';
1197 $this->fk_project = 1;
1198 $this->fk_user_create = 1;
1199 $this->fk_user_assign = 1;
1200 $this->subject =
'Subject of ticket';
1201 $this->message =
'Message of ticket';
1203 $this->resolution =
'1';
1204 $this->progress =
'10';
1206 $this->type_code =
'TYPECODE';
1207 $this->category_code =
'CATEGORYCODE';
1208 $this->severity_code =
'SEVERITYCODE';
1210 $this->date_read =
'';
1211 $this->date_last_msg_sent =
'';
1212 $this->date_close =
'';
1225 print
Form::selectarray(
'search_fk_statut', $this->statuts_short, $selected, $show_empty = 1, $key_in_label = 0, $value_as_key = 0, $option =
'', $translate = 1, $maxlen = 0, $disabled = 0, $sort =
'', $morecss =
'');
1238 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1243 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1244 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type";
1245 $sql .=
" WHERE entity IN (".getEntity(
'c_ticket_type').
")";
1246 $sql .=
" AND active > 0";
1247 $sql .=
" ORDER BY pos";
1248 dol_syslog(get_class($this).
"::load_cache_type_tickets", LOG_DEBUG);
1249 $resql = $this->db->query($sql);
1251 $num = $this->db->num_rows($resql);
1254 $obj = $this->db->fetch_object($resql);
1255 $label = ($langs->trans(
"TicketTypeShort".$obj->code) != (
"TicketTypeShort".$obj->code) ? $langs->trans(
"TicketTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1256 $this->cache_types_tickets[$obj->rowid][
'code'] = $obj->code;
1257 $this->cache_types_tickets[$obj->rowid][
'label'] = $label;
1258 $this->cache_types_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1259 $this->cache_types_tickets[$obj->rowid][
'pos'] = $obj->pos;
1277 global $conf, $langs;
1279 if ($publicgroup == -1 && !empty($this->cache_category_ticket) && count($this->cache_category_tickets)) {
1284 $sql =
"SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1285 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category";
1286 $sql .=
" WHERE entity IN (".getEntity(
'c_ticket_category').
")";
1287 $sql .=
" AND active > 0";
1288 if ($publicgroup > -1) {
1289 $sql .=
" AND public = ".((int) $publicgroup);
1291 $sql .=
" ORDER BY pos";
1293 dol_syslog(get_class($this).
"::load_cache_categories_tickets", LOG_DEBUG);
1295 $resql = $this->db->query($sql);
1297 $num = $this->db->num_rows($resql);
1300 $obj = $this->db->fetch_object($resql);
1301 $this->cache_category_tickets[$obj->rowid][
'code'] = $obj->code;
1302 $this->cache_category_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1303 $this->cache_category_tickets[$obj->rowid][
'pos'] = $obj->pos;
1304 $this->cache_category_tickets[$obj->rowid][
'public'] = $obj->public;
1305 $this->cache_category_tickets[$obj->rowid][
'active'] = $obj->active;
1306 $this->cache_category_tickets[$obj->rowid][
'force_severity'] = $obj->force_severity;
1307 $this->cache_category_tickets[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1311 $label = ($langs->trans(
"TicketCategoryShort".$obj->code) != (
"TicketCategoryShort".$obj->code) ? $langs->trans(
"TicketCategoryShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1312 $this->cache_category_tickets[$obj->rowid][
'label'] = $label;
1332 if (!empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) {
1337 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1338 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity";
1339 $sql .=
" WHERE entity IN (".getEntity(
'c_ticket_severity').
")";
1340 $sql .=
" AND active > 0";
1341 $sql .=
" ORDER BY pos";
1342 dol_syslog(get_class($this).
"::loadCacheSeveritiesTickets", LOG_DEBUG);
1343 $resql = $this->db->query($sql);
1345 $num = $this->db->num_rows($resql);
1348 $obj = $this->db->fetch_object($resql);
1350 $this->cache_severity_tickets[$obj->rowid][
'code'] = $obj->code;
1351 $label = ($langs->trans(
"TicketSeverityShort".$obj->code) != (
"TicketSeverityShort".$obj->code) ? $langs->trans(
"TicketSeverityShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1352 $this->cache_severity_tickets[$obj->rowid][
'label'] = $label;
1353 $this->cache_severity_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1354 $this->cache_severity_tickets[$obj->rowid][
'pos'] = $obj->pos;
1373 return $this->libStatut($this->fk_statut, $mode, 0, $this->progress);
1387 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1390 global $langs, $hookmanager;
1392 $labelStatus = $this->statuts[$status];
1393 $labelStatusShort = $this->statuts_short[$status];
1395 if ($status == self::STATUS_NOT_READ) {
1396 $statusType =
'status0';
1397 } elseif ($status == self::STATUS_READ) {
1398 $statusType =
'status1';
1399 } elseif ($status == self::STATUS_ASSIGNED) {
1400 $statusType =
'status2';
1401 } elseif ($status == self::STATUS_IN_PROGRESS) {
1402 $statusType =
'status4';
1403 } elseif ($status == self::STATUS_WAITING) {
1404 $statusType =
'status7';
1405 } elseif ($status == self::STATUS_NEED_MORE_INFO) {
1406 $statusType =
'status3';
1407 } elseif ($status == self::STATUS_CANCELED) {
1408 $statusType =
'status9';
1409 } elseif ($status == self::STATUS_CLOSED) {
1410 $statusType =
'status6';
1412 $labelStatus =
'Unknown';
1413 $labelStatusShort =
'Unknown';
1414 $statusType =
'status0';
1418 $parameters = array(
1419 'status' => $status,
1424 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1427 return $hookmanager->resPrint;
1432 $params = array(
'tooltip' =>
'no');
1435 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1436 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1438 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1439 $labelStatus .=
' ('.round($progress).
'%)';
1440 $labelStatusShort .=
' ('.round($progress).
'%)';
1443 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1457 $langs->load(
'ticket');
1458 $nofetch = !empty($params[
'nofetch']);
1461 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1462 $datas[
'picto'] .=
' '.$this->getLibStatut(4);
1463 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1464 $datas[
'track_id'] =
'<br><b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id;
1465 $datas[
'subject'] =
'<br><b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1466 if ($this->date_creation) {
1467 $datas[
'date_creation'] =
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.
dol_print_date($this->date_creation,
'dayhour');
1469 if ($this->date_modification) {
1470 $datas[
'date_modification'] =
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.
dol_print_date($this->date_modification,
'dayhour');
1473 if (isModEnabled(
'categorie') && !$nofetch) {
1474 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1475 $form =
new Form($this->db);
1476 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_TICKET, 1);
1492 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1494 global $conf, $langs;
1496 if (!empty($conf->dol_no_mouse_hover)) {
1504 'objecttype' => $this->element,
1505 'option' => $option,
1508 $classfortooltip =
'classfortooltip';
1511 $classfortooltip =
'classforajaxtooltip';
1512 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1515 $label = implode($this->getTooltipContentArray($params));
1518 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.$this->id;
1520 if ($option !=
'nolink') {
1522 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1523 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1524 $add_save_lastsearch_values = 1;
1526 if ($add_save_lastsearch_values) {
1527 $url .=
'&save_lastsearch_values=1';
1532 if (empty($notooltip)) {
1534 $label = $langs->trans(
"ShowTicket");
1535 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1537 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1538 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1540 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1543 $linkstart =
'<a href="'.$url.
'"';
1544 $linkstart .= $linkclose.
'>';
1547 $result .= $linkstart;
1549 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1551 if ($withpicto != 2) {
1552 $result .= $this->ref;
1554 $result .= $linkend;
1574 if ($this->
statut != self::STATUS_CANCELED) {
1579 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1580 $sql .=
" SET fk_statut = ".Ticket::STATUS_READ.
", date_read = '".$this->db->idate(
dol_now()).
"'";
1581 $sql .=
" WHERE rowid = ".((int) $this->
id);
1584 $resql = $this->db->query($sql);
1586 $this->actionmsg = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1587 $this->actionmsg2 = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1589 if (!$error && !$notrigger) {
1591 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1599 $this->db->commit();
1602 $this->db->rollback();
1603 $this->error = join(
',', $this->errors);
1604 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1608 $this->db->rollback();
1609 $this->error = $this->db->lasterror();
1610 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1626 public function assignUser($user, $id_assign_user, $notrigger = 0)
1628 global $conf, $langs;
1636 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1637 if ($id_assign_user > 0) {
1638 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1640 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1642 $sql .=
" WHERE rowid = ".((int) $this->
id);
1644 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1645 $resql = $this->db->query($sql);
1647 $this->fk_user_assign = $id_assign_user;
1651 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1659 $this->db->commit();
1662 $this->db->rollback();
1663 $this->error = join(
',', $this->errors);
1664 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1668 $this->db->rollback();
1669 $this->error = $this->db->lasterror();
1670 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1686 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email =
false)
1688 global $conf, $langs;
1694 if (isset($this->fk_track_id)) {
1695 $this->fk_track_id = trim($this->fk_track_id);
1698 if (isset($this->message)) {
1699 $this->message = trim($this->message);
1705 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1707 $actioncomm->type_code =
'AC_OTH_AUTO';
1708 $actioncomm->code =
'TICKET_MSG';
1709 if ($this->
private) {
1710 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1713 $actioncomm->code .=
'_SENTBYMAIL';
1715 if ((empty($user->id) || $user->id == 0) && isset($_SESSION[
'email_customer'])) {
1716 $actioncomm->email_from = $_SESSION[
'email_customer'];
1718 $actioncomm->socid = $this->socid;
1719 $actioncomm->label = $this->subject;
1720 $actioncomm->note_private = $this->message;
1721 $actioncomm->userassigned = array($user->id);
1722 $actioncomm->userownerid = $user->id;
1723 $actioncomm->datep = $now;
1724 $actioncomm->percentage = -1;
1725 $actioncomm->elementtype =
'ticket';
1726 $actioncomm->fk_element = $this->id;
1727 $actioncomm->fk_project = $this->fk_project;
1729 $attachedfiles = array();
1730 $attachedfiles[
'paths'] = $filename_list;
1731 $attachedfiles[
'names'] = $mimefilename_list;
1732 $attachedfiles[
'mimes'] = $mimetype_list;
1733 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1734 $actioncomm->attachedfiles = $attachedfiles;
1737 if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1738 $actioncomm->note_private =
dol_concatdesc($actioncomm->note_private,
"\n".$langs->transnoentities(
"AttachedFiles").
': '.join(
';', $mimefilename_list));
1741 $actionid = $actioncomm->create($user);
1742 if ($actionid <= 0) {
1744 $this->error = $actioncomm->error;
1745 $this->errors = $actioncomm->errors;
1750 $this->db->rollback();
1753 $this->db->commit();
1765 if (!empty($this->cache_msgs_ticket) && is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1771 $sql =
"SELECT id as rowid, fk_user_author, email_from, datec, datep, label, note as message, code";
1772 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1773 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1774 $sql .=
" AND elementtype = 'ticket'";
1775 $sql .=
" ORDER BY datep DESC";
1777 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1778 $resql = $this->db->query($sql);
1780 $num = $this->db->num_rows($resql);
1783 $obj = $this->db->fetch_object($resql);
1784 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1785 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1786 if ($obj->code ==
'TICKET_MSG' && empty($obj->fk_user_author)) {
1787 $this->cache_msgs_ticket[$i][
'fk_contact_author'] = $obj->email_from;
1789 $this->cache_msgs_ticket[$i][
'datec'] = $this->db->jdate($obj->datec);
1790 $this->cache_msgs_ticket[$i][
'datep'] = $this->db->jdate($obj->datep);
1791 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1792 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1793 $this->cache_msgs_ticket[$i][
'private'] = (preg_match(
'/^TICKET_MSG_PRIVATE/', $obj->code) ? 1 : 0);
1798 $this->error =
"Error ".$this->db->lasterror();
1799 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1815 if ($this->status != Ticket::STATUS_CLOSED && $this->status != Ticket::STATUS_CANCELED) {
1818 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1819 $sql .=
" SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).
", progress=100, date_close='".$this->db->idate(
dol_now()).
"'";
1820 $sql .=
" WHERE rowid = ".((int) $this->
id);
1822 dol_syslog(get_class($this).
"::close mode=".$mode);
1823 $resql = $this->db->query($sql);
1828 if (isModEnabled(
'ficheinter') &&
getDolGlobalString(
'WORKFLOW_TICKET_CLOSE_INTERVENTION')) {
1829 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
1830 $this->fetchObjectLinked($this->
id, $this->element,
null,
'fichinter');
1831 if ($this->linkedObjectsIds) {
1832 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
1834 $fichinter->fetch($fichinter_id);
1835 if ($fichinter->statut == 0) {
1836 $result = $fichinter->setValid($user);
1838 $this->errors[] = $fichinter->error;
1842 if ($fichinter->statut < 3) {
1843 $result = $fichinter->setStatut(3);
1845 $this->errors[] = $fichinter->error;
1854 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
1861 $this->db->commit();
1864 $this->db->rollback();
1865 $this->error = join(
',', $this->errors);
1866 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1870 $this->db->rollback();
1871 $this->error = $this->db->lasterror();
1872 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1891 $thirdparties = array();
1895 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
1896 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
1897 if (!empty($type)) {
1898 if ($type == 1 || $type == 2) {
1899 $sql .=
" AND client = ".((int) $type);
1900 } elseif ($type == 3) {
1901 $sql .=
" AND fournisseur = 1";
1904 if (!empty($email)) {
1905 if (empty($exact)) {
1907 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1908 $email = str_replace(
'*',
'%', $email);
1910 $email =
'%'.$email.
'%';
1914 if (is_array($filters) && !empty($filters)) {
1918 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1920 if (is_array($filters) && !empty($filters)) {
1921 foreach ($filters as $field => $value) {
1922 $sql .=
" ".$clause.
" ".$field.
" LIKE '".$this->db->escape($value).
"'";
1924 if (!empty($email)) {
1929 $res = $this->db->query($sql);
1931 while ($rec = $this->db->fetch_array($res)) {
1932 $soc =
new Societe($this->db);
1933 $soc->fetch($rec[
'rowid']);
1934 $thirdparties[] = $soc;
1937 return $thirdparties;
1939 $this->error = $this->db->error().
' sql='.$sql;
1940 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
1955 $contacts = array();
1958 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
1959 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
1960 if (!empty($socid)) {
1961 $sql .=
" AND fk_soc = ".((int) $socid);
1963 if (!empty($email)) {
1966 $sql .=
"email = '".$this->db->escape($email).
"'";
1968 $sql .=
"email LIKE BINARY '".$this->db->escape($this->db->escapeforlike($email)).
"'";
1972 $res = $this->db->query($sql);
1974 while ($rec = $this->db->fetch_object($res)) {
1975 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1976 $contactstatic =
new Contact($this->db);
1977 $contactstatic->fetch($rec->rowid);
1978 $contacts[] = $contactstatic;
1983 $this->error = $this->db->error().
' sql='.$sql;
1984 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
1998 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1999 $sql .=
" SET fk_soc = ".($id > 0 ? $id :
"null");
2000 $sql .=
" WHERE rowid = ".((int) $this->
id);
2001 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
2002 $resql = $this->db->query($sql);
2022 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2023 $sql .=
" SET progress = ".($percent > 0 ? $percent :
"null");
2024 $sql .=
" WHERE rowid = ".((int) $this->
id);
2025 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
2026 $resql = $this->db->query($sql);
2045 if (!$this->table_element) {
2046 dol_syslog(get_class($this).
"::setContract was called on objet with property table_element not defined", LOG_ERR);
2050 $result = $this->add_object_linked(
'contrat', $contractid);
2052 $this->fk_contract = $contractid;
2069 return $this->getIdContact(
'internal',
'SUPPORTTEC');
2080 return $this->listeContact(-1,
'internal', 0,
'', $status);
2090 return $this->getIdContact(
'external',
'SUPPORTCLI');
2101 return $this->listeContact(-1,
'external', 0,
'', $status);
2111 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2121 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2131 $array_contact = array();
2133 $array_contact = $this->getIdTicketInternalContact();
2135 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2137 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact());
2139 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2141 return $array_contact;
2151 $array_contact = array();
2153 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2155 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2157 return $array_contact;
2172 public function listeContact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1)
2178 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2179 if ($source ==
'internal') {
2180 $sql .=
", '-1' as socid, t.statut as statuscontact";
2183 if ($source ==
'external' || $source ==
'thirdparty') {
2184 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2187 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2188 if ($source ==
'internal') {
2189 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2192 if ($source ==
'external') {
2193 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2196 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2198 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2199 if ($source ==
'internal') {
2200 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2203 if ($source ==
'external' || $source ==
'thirdparty') {
2204 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2207 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2208 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2209 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2210 if ($source ==
'internal') {
2211 $sql .=
" AND tc.source = 'internal'";
2213 $sql .=
" AND t.statut = ".((int) $status);
2217 if ($source ==
'external' || $source ==
'thirdparty') {
2218 $sql .=
" AND tc.source = 'external'";
2220 $sql .=
" AND t.statut = ".((int) $status);
2224 if (!empty($code)) {
2225 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2228 $sql .=
" AND tc.active=1";
2229 if ($statusoflink >= 0) {
2230 $sql .=
" AND ec.statut = ".((int) $statusoflink);
2233 $sql .=
" ORDER BY t.lastname ASC";
2235 $resql = $this->db->query($sql);
2237 $num = $this->db->num_rows($resql);
2240 $obj = $this->db->fetch_object($resql);
2243 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2244 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2246 'source' => $obj->source,
2247 'socid' => $obj->socid,
2249 'nom' => $obj->lastname,
2250 'civility' => $obj->civility,
2251 'lastname' => $obj->lastname,
2252 'firstname' => $obj->firstname,
2253 'email' => $obj->email,
2254 'rowid' => $obj->rowid,
2255 'code' => $obj->code,
2256 'libelle' => $libelle_type,
2257 'status' => $obj->statuslink,
2258 'statuscontact'=>$obj->statuscontact,
2259 'fk_c_type_contact' => $obj->fk_c_type_contact,
2260 'phone' => $obj->phone,
2261 'phone_mobile' => $obj->phone_mobile);
2263 $tab[$i] = $obj->id;
2271 $this->error = $this->db->error();
2294 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2295 foreach ($dirmodels as $reldir) {
2296 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2297 if (file_exists($file)) {
2299 $classname = $modele;
2306 $modTicket =
new $classname;
2308 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2311 if (is_numeric($defaultref) && $defaultref <= 0) {
2329 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2337 if (file_exists($dir_osencoded)) {
2338 $handle = opendir($dir_osencoded);
2339 if (is_resource($handle)) {
2340 while (($file = readdir($handle)) !==
false) {
2342 $file = utf8_encode($file);
2367 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2368 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2369 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2371 $maxwidthsmall = 270;
2372 $maxheightsmall = 150;
2373 $maxwidthmini = 128;
2374 $maxheightmini = 72;
2376 $formmail =
new FormMail($this->db);
2377 $formmail->trackid = (is_null($forcetrackid) ?
'tic'.$this->id :
'');
2378 $attachedfiles = $formmail->get_attached_files();
2380 $filepath = $attachedfiles[
'paths'];
2381 $filename = $attachedfiles[
'names'];
2382 $mimetype = $attachedfiles[
'mimes'];
2385 $destdir = $conf->ticket->dir_output.
'/'.$this->ref;
2391 $listofpaths = array();
2392 $listofnames = array();
2393 foreach ($filename as $i => $val) {
2394 $destfile = $destdir.
'/'.$filename[$i];
2396 if (is_file($destfile)) {
2397 $pathinfo = pathinfo($filename[$i]);
2399 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2402 $res =
dol_move($filepath[$i], $destfile, 0, 1, 0, 1);
2405 $this->error =
"Failed to move file ".dirbasename($filepath[$i]).
" into ".
dirbasename($destfile);
2412 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2415 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2420 $formmail->remove_attached_files($i);
2423 $listofpaths[$i] = $destfile;
2424 $listofnames[$i] = basename($destfile);
2427 return array(
'listofpaths'=>$listofpaths,
'listofnames'=>$listofnames,
'listofmimes'=>$mimetype);
2443 if (!is_array($categories)) {
2444 $categories = array($categories);
2448 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2450 $existing = $c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2453 if (is_array($existing)) {
2454 $to_del = array_diff($existing, $categories);
2455 $to_add = array_diff($categories, $existing);
2458 $to_add = $categories;
2462 foreach ($to_del as $del) {
2463 if ($c->fetch($del) > 0) {
2464 $c->del_type($this, Categorie::TYPE_TICKET);
2467 foreach ($to_add as $add) {
2468 if ($c->fetch($add) > 0) {
2469 $c->add_type($this, Categorie::TYPE_TICKET);
2486 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2488 global $mysoc, $conf, $langs;
2492 $object =
new Ticket($this->db);
2494 $ret = $object->fetch(
'',
'',
GETPOST(
'track_id',
'alpha'));
2496 $object->socid = $object->fk_soc;
2497 $object->fetch_thirdparty();
2498 $object->fetch_project();
2502 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2508 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
2509 $action =
'add_message';
2513 $object->subject =
GETPOST(
'subject',
'alphanohtml');
2514 $object->message =
GETPOST(
"message",
"restricthtml");
2515 $object->private =
GETPOST(
"private_message",
"alpha");
2517 $send_email =
GETPOST(
'send_email',
'int');
2520 $resarray = $object->copyFilesForTicket();
2521 if (is_numeric($resarray) && $resarray == -1) {
2526 $listofpaths = $resarray[
'listofpaths'];
2527 $listofnames = $resarray[
'listofnames'];
2528 $listofmimes = $resarray[
'listofmimes'];
2530 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email);
2533 $this->error = $object->error;
2534 $this->errors = $object->errors;
2535 $action =
'add_message';
2538 if (!$error && $id > 0) {
2539 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'),
null,
'mesgs');
2544 if (!empty($public_area)) {
2552 $internal_contacts = $object->getInfosTicketInternalContact(1);
2554 $assigned_user_dont_have_email =
'';
2558 if ($this->fk_user_assign > 0) {
2559 $assigned_user =
new User($this->db);
2560 $assigned_user->fetch($this->fk_user_assign);
2561 if (!empty($assigned_user->email)) {
2562 $sendto[$assigned_user->email] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2564 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2569 foreach ($internal_contacts as $key => $info_sendto) {
2571 if ($info_sendto[
'id'] == $user->id) {
2576 if (!empty($info_sendto[
'email']) && $assigned_user->email != $info_sendto[
'email']) {
2577 $sendto[] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2581 if (empty($sendto)) {
2596 if (!empty($sendto)) {
2598 $subject =
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2601 $message =
getDolGlobalString(
'TICKET_MESSAGE_MAIL_INTRO', $langs->trans(
'TicketMessageMailIntroText'));
2602 $message .=
'<br><br>';
2603 $messagePost =
GETPOST(
'message',
'restricthtml');
2607 $message .= $messagePost;
2610 $message .=
'<br><br>';
2611 $message .=
"==============================================";
2612 $message .= !empty($object->thirdparty->name) ?
'<br>'.$langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2613 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2614 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2617 $message .=
'<br><br>';
2618 if (!empty($assigned_user_dont_have_email)) {
2619 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2621 foreach ($sendto as $val) {
2622 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2626 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2627 $message .=
'<br><br>';
2628 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a>';
2630 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2639 if ($send_email > 0) {
2641 $internal_contacts = $object->getInfosTicketInternalContact(1);
2644 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2647 $appli = $label_title;
2648 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2650 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".$object->id);
2653 $message =
getDolGlobalString(
'TICKET_MESSAGE_MAIL_INTRO', $langs->trans(
'TicketMessageMailIntroText'));
2654 $message .=
'<br><br>';
2655 $messagePost =
GETPOST(
'message',
'restricthtml');
2659 $message .= $messagePost;
2662 $message .=
'<br><br>';
2663 $message .=
"==============================================<br>";
2664 $message .= !empty($object->thirdparty->name) ? $langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2665 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2666 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2669 foreach ($internal_contacts as $key => $info_sendto) {
2671 if ($info_sendto[
'id'] == $user->id) {
2675 if ($info_sendto[
'email'] !=
'') {
2676 if (!empty($info_sendto[
'email'])) {
2677 $sendto[$info_sendto[
'email']] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2681 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2682 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2687 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2690 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a><br>';
2700 if (!empty($sendto)) {
2701 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2708 if (empty($object->private)) {
2710 $external_contacts = $object->getInfosTicketExternalContact(1);
2713 if (is_array($external_contacts) && count($external_contacts) === 0) {
2714 if (!empty($object->fk_soc)) {
2715 $object->fetch_thirdparty($object->fk_soc);
2716 $array_company = array(array(
'firstname' =>
'',
'lastname' => $object->thirdparty->name,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2717 $external_contacts = array_merge($external_contacts, $array_company);
2718 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2719 $array_external = array(array(
'firstname' =>
'',
'lastname' => $object->origin_email,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2720 $external_contacts = array_merge($external_contacts, $array_external);
2725 if (is_array($external_contacts) && count($external_contacts) > 0) {
2728 $appli = $mysoc->name;
2729 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2734 $message_intro =
dol_nl2br($message_intro);
2737 $message_signature =
dol_nl2br($message_signature);
2741 $messagePost =
GETPOST(
'message',
'restricthtml');
2745 $message = $messagePost;
2746 $message .=
'<br><br>';
2748 foreach ($external_contacts as $key => $info_sendto) {
2750 if ($info_sendto[
'id'] == $user->contact_id) {
2754 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] != $object->origin_email) {
2755 if (!empty($info_sendto[
'email'])) {
2756 $sendto[$info_sendto[
'email']] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2759 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2760 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2765 $url_public_ticket =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
dol_buildpath(
'/public/ticket/view.php', 2)) .
'/view.php?track_id='.$object->track_id;
2766 $message .=
'<br>'.$langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$object->track_id.
'</a><br>';
2769 $message = $message_intro.
'<br><br>'.$message;
2772 $message .=
'<br>'.$message_signature;
2774 if (!empty($object->origin_email)) {
2775 $sendto[$object->origin_email] = $object->origin_email;
2778 if ($object->fk_soc > 0 && !array_key_exists($object->origin_email, $sendto)) {
2779 $object->socid = $object->fk_soc;
2780 $object->fetch_thirdparty();
2781 if (!empty($object->thirdparty->email)) {
2782 $sendto[$object->thirdparty->email] = $object->thirdparty->email;
2794 if (!empty($sendto)) {
2795 $result = $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2798 $this->date_last_msg_sent =
dol_now();
2799 $this->update($user, 1);
2809 if (($object->status < self::STATUS_IN_PROGRESS && !$user->socid && !$private) ||
2810 ($object->status > self::STATUS_IN_PROGRESS && $public_area)
2812 $object->setStatut(3);
2838 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2840 global $conf, $langs;
2843 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2847 $langs->load(
"mails");
2849 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2853 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2854 $array_receiver = $this->getInfosTicketInternalContact(1);
2855 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact(1));
2859 if ($send_internal_cc) {
2865 if (is_array($array_receiver) && count($array_receiver) > 0) {
2866 foreach ($array_receiver as $key => $receiver) {
2867 $deliveryreceipt = 0;
2868 $filepath = $filename_list;
2869 $filename = $mimefilename_list;
2870 $mimetype = $mimetype_list;
2877 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
2880 $upload_dir_tmp = $conf->user->dir_output.
"/".$user->id.
'/temp';
2882 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2883 $trackid =
"tic".$this->id;
2885 $moreinheader =
'X-Dolibarr-Info: sendTicketMessageByEmail'.
"\r\n";
2886 if (!empty($this->email_msgid)) {
2888 $moreinheader .=
'In-Reply-To: <'.$this->email_msgid.
'>'.
"\r\n";
2891 $mailfile =
new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid, $moreinheader,
'ticket',
'', $upload_dir_tmp);
2893 if ($mailfile->error) {
2896 $result = $mailfile->sendfile();
2898 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)),
null,
'mesgs');
2901 $langs->load(
"other");
2902 if ($mailfile->error) {
2903 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver),
null,
'errors');
2904 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
2906 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'errors');
2912 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2916 $langs->load(
"other");
2917 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'),
null,
'warnings');
2934 global $conf, $user, $langs;
2939 $this->nbtodo = $this->nbtodolate = 0;
2942 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
2943 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2944 if (isModEnabled(
'societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2945 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2946 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2949 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2950 if ($mode ==
'opened') {
2951 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
2954 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2957 $resql = $this->db->query($sql);
2959 $label = $labelShort =
'';
2961 if ($mode ==
'opened') {
2962 $status =
'openall';
2965 $label = $langs->trans(
"MenuListNonClosed");
2966 $labelShort = $langs->trans(
"MenuListNonClosed");
2971 $response->label = $label;
2972 $response->labelShort = $labelShort;
2973 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
2977 while ($obj = $this->db->fetch_object($resql)) {
2978 $response->nbtodo++;
2979 if ($mode ==
'opened') {
2980 $datelimit = $this->db->jdate($obj->datec) + $delay_warning;
2981 if ($datelimit < $now) {
2988 $this->error = $this->db->lasterror();
3002 global $conf, $user;
3004 $this->nb = array();
3007 $sql =
"SELECT count(p.rowid) as nb";
3008 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
3009 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3010 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3011 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3012 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3015 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
3017 $resql = $this->db->query($sql);
3020 while ($obj = $this->db->fetch_object($resql)) {
3021 $this->nb[
"ticket"] = $obj->nb;
3023 $this->db->free($resql);
3027 $this->error = $this->db->lasterror();
3042 $tables = array(
'ticket');
3058 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3060 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3061 $return .=
'<div class="info-box info-box-sm">';
3062 $return .=
'<span class="info-box-icon bg-infobox-action">';
3064 $return .=
'</span>';
3065 $return .=
'<div class="info-box-content">';
3066 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->getNomUrl(1) : $this->ref).
'</span>';
3067 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3068 if (!empty($arraydata[
'user_assignment'])) {
3069 $return .=
'<br><span class="info-box-label" title="'.dol_escape_htmltag($langs->trans(
"AssignedTo")).
'">'.$arraydata[
'user_assignment'].
'</span>';
3071 if (property_exists($this,
'type_code') && !empty($this->type_code)) {
3073 $return .=
'<div class="tdoverflowmax125 inline-block">'.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$this->type_code,
'c_ticket_type',
'code',
'label', $this->type_code).
'</div>';
3075 if (method_exists($this,
'getLibStatut')) {
3076 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
3078 $return .=
'</div>';
3079 $return .=
'</div>';
3080 $return .=
'</div>';
3210 public $date_last_msg_sent =
'';
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage interventions.
Class to manage third parties objects (customers, suppliers, prospects...)
update($user=0, $notrigger=0)
Update object into database.
$email_from
Email from user.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
fetch($id='', $ref='', $track_id='', $email_msgid='')
Load object in memory from the 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.
loadCacheSeveritiesTickets()
Charge dans cache la liste des sévérité de tickets (paramétrable dans dictionnaire)
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]',...
getInfosTicketExternalContact($status=-1)
Retrieve informations about external contacts.
searchContactByEmail($email, $socid='', $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.
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)
Mark a message as read.
getTooltipContentArray($params)
getTooltipContentArray
load_state_board()
Load indicator this->nb of global stats widget.
getKanbanView($option='', $arraydata=null)
Return clicable 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.
fetchAll($user, $sortorder='ASC', $sortfield='t.datec', $limit='', $offset=0, $arch='', $filter='')
Load all objects in memory from 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='')
Get a default reference.
sendTicketMessageByEmail($subject, $message, $send_internal_cc=0, $array_receiver=array(), $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
Send ticket by email to linked contacts.
const STATUS_NOT_READ
Status.
__construct($db)
Constructor.
getTicketAllCustomerContacts()
Return id of all contacts for ticket.
$category_label
Category label.
searchSocidByEmail($email, $type='0', $filters=array(), $clause='AND')
Search and fetch thirparties by email.
$severity_label
Severity label.
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).
$subject
var string Ticket subject
getIdTicketCustomerContact()
Return id des contacts clients pour le suivi ticket.
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.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getInfosTicketInternalContact($status=-1)
Retrieve informations about internal contacts.
createTicketMessage($user, $notrigger=0, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $send_email=false)
Add message into database.
create($user, $notrigger=0)
Create object into database.
$category_code
Category code.
$fk_user_assign
User id who have ticket assigned.
$timing
Duration for ticket.
$category_label
Category label.
$severity_code
Severity code.
$track_id
Hash to identify ticket.
$progress
Progress in percent.
$date_close
Close ticket date.
$severity_label
Severity label.
$origin_email
Person email who have create ticket.
$resolution
State resolution.
$fk_user_create
User id who have create ticket.
Class to manage Dolibarr users.
print $langs trans("Ref").' m m m statut
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())
Move a file into another name.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
Class to generate the form for creating a new ticket.
generate_random_id($car=16)
Generate a random id.