28 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
29 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
30 require_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 $notify_tiers_at_create;
235 public $regeximgext =
'\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm';
241 const STATUS_READ = 1;
242 const STATUS_ASSIGNED = 2;
243 const STATUS_IN_PROGRESS = 3;
244 const STATUS_NEED_MORE_INFO = 5;
245 const STATUS_WAITING = 7;
246 const STATUS_CLOSED = 8;
247 const STATUS_CANCELED = 9;
278 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-2,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id"),
279 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>5,
'notnull'=>1,
'index'=>1),
280 '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),
281 'track_id' => array(
'type'=>
'varchar(255)',
'label'=>
'TicketTrackId',
'visible'=>-2,
'enabled'=>1,
'position'=>11,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"Help text"),
282 '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'),
283 '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'),
284 'subject' => array(
'type'=>
'varchar(255)',
'label'=>
'Subject',
'visible'=>1,
'enabled'=>1,
'position'=>18,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"",
'css'=>
'maxwidth200 tdoverflowmax200',
'autofocusoncreate'=>1),
285 'type_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Type',
'visible'=>1,
'enabled'=>1,
'position'=>20,
'notnull'=>-1,
'help'=>
"",
'csslist'=>
'maxwidth125 tdoverflowmax50'),
286 'category_code' => array(
'type'=>
'varchar(32)',
'label'=>
'TicketCategory',
'visible'=>-1,
'enabled'=>1,
'position'=>21,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100 tdoverflowmax200'),
287 'severity_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Severity',
'visible'=>1,
'enabled'=>1,
'position'=>22,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100'),
288 'fk_soc' => array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'visible'=>1,
'enabled'=>
'$conf->societe->enabled',
'position'=>50,
'notnull'=>-1,
'index'=>1,
'searchall'=>1,
'help'=>
"OrganizationEventLinkToThirdParty",
'css'=>
'tdoverflowmax150 maxwidth150onsmartphone'),
289 'notify_tiers_at_create' => array(
'type'=>
'integer',
'label'=>
'NotifyThirdparty',
'visible'=>-1,
'enabled'=>0,
'position'=>51,
'notnull'=>1,
'index'=>1),
290 '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"),
292 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'visible'=>1,
'enabled'=>1,
'position'=>500,
'notnull'=>1,
'csslist'=>
'nowraponall'),
293 'date_read' => array(
'type'=>
'datetime',
'label'=>
'TicketReadOn',
'visible'=>-1,
'enabled'=>1,
'position'=>501,
'notnull'=>1),
294 'date_last_msg_sent' => array(
'type'=>
'datetime',
'label'=>
'TicketLastMessageDate',
'visible'=>0,
'enabled'=>1,
'position'=>502,
'notnull'=>-1),
295 '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'),
296 'date_close' => array(
'type'=>
'datetime',
'label'=>
'TicketCloseOn',
'visible'=>-1,
'enabled'=>1,
'position'=>510,
'notnull'=>1),
297 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'visible'=>-1,
'enabled'=>1,
'position'=>520,
'notnull'=>1),
298 'message' => array(
'type'=>
'text',
'label'=>
'Message',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,),
299 'email_msgid' => array(
'type'=>
'varchar(255)',
'label'=>
'EmailMsgID',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'help'=>
'EmailMsgIDDesc'),
300 'email_date' => array(
'type'=>
'datetime',
'label'=>
'EmailDate',
'visible'=>-2,
'enabled'=>1,
'position'=>541),
301 'progress' => array(
'type'=>
'integer',
'label'=>
'Progression',
'visible'=>-1,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'css'=>
'right',
'help'=>
"",
'isameasure'=>2,
'csslist'=>
'width50'),
302 'resolution' => array(
'type'=>
'integer',
'label'=>
'Resolution',
'visible'=>-1,
'enabled'=>
'getDolGlobalString("TICKET_ENABLE_RESOLUTION")',
'position'=>550,
'notnull'=>1),
303 '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')),
304 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
320 $this->statuts_short = array(
321 self::STATUS_NOT_READ =>
'Unread',
322 self::STATUS_READ =>
'Read',
323 self::STATUS_ASSIGNED =>
'Assigned',
324 self::STATUS_IN_PROGRESS =>
'InProgress',
325 self::STATUS_WAITING =>
'OnHold',
326 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformationShort',
327 self::STATUS_CLOSED =>
'SolvedClosed',
328 self::STATUS_CANCELED =>
'Canceled'
330 $this->statuts = array(
331 self::STATUS_NOT_READ =>
'Unread',
332 self::STATUS_READ =>
'Read',
333 self::STATUS_ASSIGNED =>
'Assigned',
334 self::STATUS_IN_PROGRESS =>
'InProgress',
335 self::STATUS_WAITING =>
'OnHold',
336 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformation',
337 self::STATUS_CLOSED =>
'SolvedClosed',
338 self::STATUS_CANCELED =>
'Canceled'
350 $this->errors = array();
355 if (isset($this->
ref)) {
356 $this->
ref = trim($this->
ref);
359 if (isset($this->track_id)) {
360 $this->track_id = trim($this->track_id);
363 if (isset($this->fk_soc)) {
364 $this->fk_soc = (int) $this->fk_soc;
367 if (isset($this->fk_project)) {
368 $this->fk_project = (int) $this->fk_project;
371 if (isset($this->origin_email)) {
372 $this->origin_email = trim($this->origin_email);
375 if (isset($this->fk_user_create)) {
376 $this->fk_user_create = (int) $this->fk_user_create;
379 if (isset($this->fk_user_assign)) {
380 $this->fk_user_assign = (int) $this->fk_user_assign;
383 if (isset($this->subject)) {
384 $this->subject = trim($this->subject);
387 if (isset($this->message)) {
388 $this->message = trim($this->message);
391 if (isset($this->fk_statut)) {
392 $this->fk_statut = (int) $this->fk_statut;
395 if (isset($this->resolution)) {
396 $this->resolution = trim($this->resolution);
399 if (isset($this->progress)) {
400 $this->progress = trim($this->progress);
403 if (isset($this->timing)) {
404 $this->timing = trim($this->timing);
407 if (isset($this->type_code)) {
408 $this->type_code = trim($this->type_code);
411 if (isset($this->category_code)) {
412 $this->category_code = trim($this->category_code);
415 if (isset($this->severity_code)) {
416 $this->severity_code = trim($this->severity_code);
419 if (empty($this->
ref)) {
420 $this->errors[] =
'ErrorTicketRefRequired';
421 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
435 public function create($user, $notrigger = 0)
437 global $conf, $langs;
442 if (empty($this->track_id)) {
448 $result = $this->
verify();
452 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ticket(";
456 $sql .=
"fk_project,";
457 $sql .=
"origin_email,";
458 $sql .=
"fk_user_create,";
459 $sql .=
"fk_user_assign,";
460 $sql .=
"email_msgid,";
461 $sql .=
"email_date,";
464 $sql .=
"fk_statut,";
465 $sql .=
"resolution,";
468 $sql .=
"type_code,";
469 $sql .=
"category_code,";
470 $sql .=
"severity_code,";
472 $sql .=
"date_read,";
473 $sql .=
"date_close,";
475 $sql .=
"notify_tiers_at_create,";
477 $sql .=
") VALUES (";
478 $sql .=
" ".(!isset($this->
ref) ?
'' :
"'".$this->db->escape($this->
ref).
"'").
",";
479 $sql .=
" ".(!isset($this->track_id) ?
'NULL' :
"'".$this->db->escape($this->track_id).
"'").
",";
480 $sql .=
" ".($this->fk_soc > 0 ? $this->
db->escape($this->fk_soc) :
"null").
",";
481 $sql .=
" ".($this->fk_project > 0 ? $this->
db->escape($this->fk_project) :
"null").
",";
482 $sql .=
" ".(!isset($this->origin_email) ?
'NULL' :
"'".$this->db->escape($this->origin_email).
"'").
",";
483 $sql .=
" ".($this->fk_user_create > 0 ? $this->fk_user_create : ($user->id > 0 ? $user->id :
'NULL')).
",";
484 $sql .=
" ".($this->fk_user_assign > 0 ? $this->fk_user_assign :
'NULL').
",";
485 $sql .=
" ".(empty($this->email_msgid) ?
'NULL' :
"'".$this->db->escape($this->email_msgid).
"'").
",";
486 $sql .=
" ".(empty($this->email_date) ?
'NULL' :
"'".$this->db->idate($this->email_date).
"'").
",";
487 $sql .=
" ".(!isset($this->subject) ?
'NULL' :
"'".$this->db->escape($this->subject).
"'").
",";
488 $sql .=
" ".(!isset($this->message) ?
'NULL' :
"'".$this->db->escape($this->message).
"'").
",";
489 $sql .=
" ".(!isset($this->fk_statut) ?
'0' :
"'".$this->db->escape($this->fk_statut).
"'").
",";
490 $sql .=
" ".(!isset($this->resolution) ?
'NULL' :
"'".$this->db->escape($this->resolution).
"'").
",";
491 $sql .=
" ".(!isset($this->progress) ?
'0' :
"'".$this->db->escape($this->progress).
"'").
",";
492 $sql .=
" ".(!isset($this->timing) ?
'NULL' :
"'".$this->db->escape($this->timing).
"'").
",";
493 $sql .=
" ".(!isset($this->type_code) ?
'NULL' :
"'".$this->db->escape($this->type_code).
"'").
",";
494 $sql .=
" ".(empty($this->category_code) || $this->category_code ==
'-1' ?
'NULL' :
"'".$this->db->escape($this->category_code).
"'").
",";
495 $sql .=
" ".(!isset($this->severity_code) ?
'NULL' :
"'".$this->db->escape($this->severity_code).
"'").
",";
496 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
497 $sql .=
" ".(!isset($this->date_read) ||
dol_strlen($this->date_read) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_read).
"'").
",";
498 $sql .=
" ".(!isset($this->date_close) ||
dol_strlen($this->date_close) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_close).
"'").
"";
499 $sql .=
", ".((int) $conf->entity);
500 $sql .=
", ".(!isset($this->notify_tiers_at_create) ?
'1' :
"'".$this->db->escape($this->notify_tiers_at_create).
"'");
501 $sql .=
", ".(!isset($this->ip) ?
'NULL' :
"'".$this->db->escape($this->ip).
"'");
506 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
510 $this->errors[] =
"Error ".$this->db->lasterror();
514 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"ticket");
517 if (!$error && !empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) {
519 if ($this->
add_contact($user->id,
'CONTRIBUTOR',
'internal') < 0) {
524 if (!$error && $this->fk_user_assign > 0) {
525 if ($this->
add_contact($this->fk_user_assign,
'SUPPORTTEC',
'internal') < 0) {
539 if (!$error && !$notrigger) {
550 foreach ($this->errors as $errmsg) {
551 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
552 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
554 $this->
db->rollback();
561 $this->
db->rollback();
562 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
576 public function fetch($id =
'', $ref =
'', $track_id =
'', $email_msgid =
'')
581 if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
582 $this->error =
'ErrorWrongParameters';
589 $sql .=
" t.entity,";
591 $sql .=
" t.track_id,";
592 $sql .=
" t.fk_soc,";
593 $sql .=
" t.fk_project,";
594 $sql .=
" t.origin_email,";
595 $sql .=
" t.fk_user_create,";
596 $sql .=
" t.fk_user_assign,";
597 $sql .=
" t.email_msgid,";
598 $sql .=
" t.email_date,";
599 $sql .=
" t.subject,";
600 $sql .=
" t.message,";
601 $sql .=
" t.fk_statut as status,";
602 $sql .=
" t.resolution,";
603 $sql .=
" t.progress,";
604 $sql .=
" t.timing,";
605 $sql .=
" t.type_code,";
606 $sql .=
" t.category_code,";
607 $sql .=
" t.severity_code,";
609 $sql .=
" t.date_read,";
610 $sql .=
" t.date_last_msg_sent,";
611 $sql .=
" t.date_close,";
614 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
615 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
616 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
617 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
618 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
621 $sql .=
" WHERE t.rowid = ".((int) $id);
623 $sql .=
" WHERE t.entity IN (".getEntity($this->element, 1).
")";
625 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
626 } elseif ($track_id) {
627 $sql .=
" AND t.track_id = '".$this->db->escape($track_id).
"'";
629 $sql .=
" AND t.email_msgid = '".$this->db->escape($email_msgid).
"'";
633 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
637 $obj = $this->
db->fetch_object(
$resql);
639 $this->
id = $obj->rowid;
640 $this->entity = $obj->entity;
641 $this->
ref = $obj->ref;
642 $this->track_id = $obj->track_id;
643 $this->fk_soc = $obj->fk_soc;
644 $this->socid = $obj->fk_soc;
645 $this->fk_project = $obj->fk_project;
646 $this->origin_email = $obj->origin_email;
647 $this->fk_user_create = $obj->fk_user_create;
648 $this->fk_user_assign = $obj->fk_user_assign;
649 $this->email_msgid = $obj->email_msgid;
650 $this->email_date = $this->
db->jdate($obj->email_date);
651 $this->subject = $obj->subject;
652 $this->message = $obj->message;
653 $this->ip = $obj->ip;
655 $this->status = $obj->status;
656 $this->fk_statut = $this->status;
658 $this->resolution = $obj->resolution;
659 $this->progress = $obj->progress;
660 $this->timing = $obj->timing;
662 $this->type_code = $obj->type_code;
664 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
665 $this->type_label = $label_type;
667 $this->category_code = $obj->category_code;
669 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
670 $this->category_label = $label_category;
672 $this->severity_code = $obj->severity_code;
674 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
675 $this->severity_label = $label_severity;
677 $this->datec = $this->
db->jdate($obj->datec);
678 $this->date_creation = $this->
db->jdate($obj->datec);
679 $this->date_read = $this->
db->jdate($obj->date_read);
680 $this->date_validation = $this->
db->jdate($obj->date_read);
681 $this->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
682 $this->date_close = $this->
db->jdate($obj->date_close);
683 $this->tms = $this->
db->jdate($obj->tms);
684 $this->date_modification = $this->
db->jdate($obj->tms);
694 $this->error =
"Error ".$this->db->lasterror();
695 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
713 public function fetchAll($user, $sortorder =
'ASC', $sortfield =
't.datec', $limit =
'', $offset = 0, $arch =
'', $filter =
'')
720 $extrafields->fetch_name_optionals_label($this->table_element);
725 $sql .=
" t.track_id,";
726 $sql .=
" t.fk_soc,";
727 $sql .=
" t.fk_project,";
728 $sql .=
" t.origin_email,";
729 $sql .=
" t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
730 $sql .=
" t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
731 $sql .=
" t.subject,";
732 $sql .=
" t.message,";
733 $sql .=
" t.fk_statut,";
734 $sql .=
" t.resolution,";
735 $sql .=
" t.progress,";
736 $sql .=
" t.timing,";
737 $sql .=
" t.type_code,";
738 $sql .=
" t.category_code,";
739 $sql .=
" t.severity_code,";
741 $sql .=
" t.date_read,";
742 $sql .=
" t.date_last_msg_sent,";
743 $sql .=
" t.date_close,";
745 $sql .=
", type.label as type_label, category.label as category_label, severity.label as severity_label";
747 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
748 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
",ef.".$key.
" as options_".$key :
'');
750 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
751 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
752 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
753 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
754 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid=t.fk_soc";
755 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as uc ON uc.rowid=t.fk_user_create";
756 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as ua ON ua.rowid=t.fk_user_assign";
757 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
758 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ticket_extrafields as ef on (t.rowid = ef.fk_object)";
760 if (empty($user->rights->societe->client->voir) && !$user->socid) {
761 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
764 $sql .=
" WHERE t.entity IN (".getEntity(
'ticket').
")";
767 if (!empty($filter)) {
768 foreach ($filter as $key => $value) {
769 if (strpos($key,
'date')) {
770 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
771 } elseif (($key ==
't.fk_user_assign') || ($key ==
't.type_code') || ($key ==
't.category_code') || ($key ==
't.severity_code') || ($key ==
't.fk_soc')) {
772 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
773 } elseif ($key ==
't.fk_statut') {
774 if (is_array($value) && count($value) > 0) {
775 $sql .=
" AND ".$key.
" IN (".$this->
db->sanitize(implode(
',', $value)).
")";
777 $sql .=
" AND ".$key.
' = '.((int) $value);
780 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
784 if (empty($user->rights->societe->client->voir) && !$user->socid) {
785 $sql .=
" AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
786 } elseif ($user->socid) {
787 $sql .=
" AND t.fk_soc = ".((int) $user->socid);
790 $sql .= $this->
db->order($sortfield, $sortorder);
791 if (!empty($limit)) {
792 $sql .= $this->
db->plimit($limit + 1, $offset);
795 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
799 $this->lines = array();
806 $obj = $this->
db->fetch_object(
$resql);
810 $line->id = $obj->rowid;
811 $line->rowid = $obj->rowid;
812 $line->ref = $obj->ref;
813 $line->track_id = $obj->track_id;
814 $line->fk_soc = $obj->fk_soc;
815 $line->fk_project = $obj->fk_project;
816 $line->origin_email = $obj->origin_email;
818 $line->fk_user_create = $obj->fk_user_create;
819 $line->user_create_lastname = $obj->user_create_lastname;
820 $line->user_create_firstname = $obj->user_create_firstname;
822 $line->fk_user_assign = $obj->fk_user_assign;
823 $line->user_assign_lastname = $obj->user_assign_lastname;
824 $line->user_assign_firstname = $obj->user_assign_firstname;
826 $line->subject = $obj->subject;
827 $line->message = $obj->message;
828 $line->fk_statut = $obj->fk_statut;
829 $line->resolution = $obj->resolution;
830 $line->progress = $obj->progress;
831 $line->timing = $obj->timing;
834 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
835 $line->type_label = $label_type;
837 $this->category_code = $obj->category_code;
839 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
840 $line->category_label = $label_category;
842 $this->severity_code = $obj->severity_code;
844 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
845 $line->severity_label = $label_severity;
847 $line->datec = $this->
db->jdate($obj->datec);
848 $line->date_read = $this->
db->jdate($obj->date_read);
849 $line->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
850 $line->date_close = $this->
db->jdate($obj->date_close);
853 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
854 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
855 $tmpkey =
'options_'.$key;
856 $line->{$tmpkey} = $obj->$tmpkey;
860 $this->lines[$i] = $line;
867 $this->error =
"Error ".$this->db->lasterror();
868 dol_syslog(get_class($this).
"::fetchAll ".$this->error, LOG_ERR);
880 public function update($user = 0, $notrigger = 0)
882 global $conf, $langs, $hookmanager;
891 if (isset($this->
ref)) {
892 $this->
ref = trim($this->
ref);
895 if (isset($this->track_id)) {
896 $this->track_id = trim($this->track_id);
899 if (isset($this->fk_soc)) {
900 $this->fk_soc = (int) $this->fk_soc;
903 if (isset($this->fk_project)) {
904 $this->fk_project = (int) $this->fk_project;
907 if (isset($this->origin_email)) {
908 $this->origin_email = trim($this->origin_email);
911 if (isset($this->fk_user_create)) {
912 $this->fk_user_create = (int) $this->fk_user_create;
915 if (isset($this->fk_user_assign)) {
916 $this->fk_user_assign = (int) $this->fk_user_assign;
919 if (isset($this->subject)) {
920 $this->subject = trim($this->subject);
923 if (isset($this->message)) {
924 $this->message = trim($this->message);
927 if (isset($this->fk_statut)) {
928 $this->fk_statut = (int) $this->fk_statut;
931 if (isset($this->resolution)) {
932 $this->resolution = trim($this->resolution);
935 if (isset($this->progress)) {
936 $this->progress = trim($this->progress);
939 if (isset($this->timing)) {
940 $this->timing = trim($this->timing);
943 if (isset($this->type_code)) {
944 $this->timing = trim($this->type_code);
947 if (isset($this->category_code)) {
948 $this->timing = trim($this->category_code);
951 if (isset($this->severity_code)) {
952 $this->timing = trim($this->severity_code);
958 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket SET";
959 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"").
",";
960 $sql .=
" track_id=".(isset($this->track_id) ?
"'".$this->db->escape($this->track_id).
"'" :
"null").
",";
961 $sql .=
" fk_soc=".(isset($this->fk_soc) ?
"'".$this->db->escape($this->fk_soc).
"'" :
"null").
",";
962 $sql .=
" fk_project=".(isset($this->fk_project) ?
"'".$this->db->escape($this->fk_project).
"'" :
"null").
",";
963 $sql .=
" origin_email=".(isset($this->origin_email) ?
"'".$this->db->escape($this->origin_email).
"'" :
"null").
",";
964 $sql .=
" fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create :
"null").
",";
965 $sql .=
" fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign :
"null").
",";
966 $sql .=
" subject=".(isset($this->subject) ?
"'".$this->db->escape($this->subject).
"'" :
"null").
",";
967 $sql .=
" message=".(isset($this->message) ?
"'".$this->db->escape($this->message).
"'" :
"null").
",";
968 $sql .=
" fk_statut=".(isset($this->fk_statut) ? $this->fk_statut :
"null").
",";
969 $sql .=
" resolution=".(isset($this->resolution) ? $this->resolution :
"null").
",";
970 $sql .=
" progress=".(isset($this->progress) ?
"'".$this->db->escape($this->progress).
"'" :
"null").
",";
971 $sql .=
" timing=".(isset($this->timing) ?
"'".$this->db->escape($this->timing).
"'" :
"null").
",";
972 $sql .=
" type_code=".(isset($this->type_code) ?
"'".$this->db->escape($this->type_code).
"'" :
"null").
",";
973 $sql .=
" category_code=".(isset($this->category_code) ?
"'".$this->db->escape($this->category_code).
"'" :
"null").
",";
974 $sql .=
" severity_code=".(isset($this->severity_code) ?
"'".$this->db->escape($this->severity_code).
"'" :
"null").
",";
975 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
976 $sql .=
" date_read=".(dol_strlen($this->date_read) != 0 ?
"'".$this->db->idate($this->date_read).
"'" :
'null').
",";
977 $sql .=
" date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ?
"'".$this->db->idate($this->date_last_msg_sent).
"'" :
'null').
",";
978 $sql .=
" date_close=".(dol_strlen($this->date_close) != 0 ?
"'".$this->db->idate($this->date_close).
"'" :
'null').
"";
979 $sql .=
" WHERE rowid=".((int) $this->
id);
986 $this->errors[] =
"Error ".$this->db->lasterror();
991 $result = $this->insertExtraFields();
997 if (!$error && !$notrigger) {
999 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1008 foreach ($this->errors as $errmsg) {
1009 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1010 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1012 $this->
db->rollback();
1015 $this->
db->commit();
1027 public function delete($user, $notrigger = 0)
1029 global $conf, $langs;
1037 $result = $this->call_trigger(
'TICKET_DELETE', $user);
1047 $res = $this->delete_linked_contact();
1049 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1056 $res = $this->deleteObjectLinked();
1064 $result = $this->deleteExtraFields();
1067 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1074 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_ticket";
1075 $sql .=
" WHERE fk_ticket = ".(int) $this->
id;
1077 $result = $this->
db->query($sql);
1080 $this->errors[] = $this->
db->lasterror();
1085 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ticket";
1086 $sql .=
" WHERE rowid=".((int) $this->
id);
1088 dol_syslog(get_class($this).
"::delete sql=".$sql);
1092 $this->errors[] =
"Error ".$this->db->lasterror();
1098 foreach ($this->errors as $errmsg) {
1099 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1100 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1102 $this->
db->rollback();
1105 $this->
db->commit();
1126 $object->fetch($fromid);
1128 $object->statut = 0;
1133 $object->context[
'createfromclone'] =
'createfromclone';
1134 $result = $object->create($user);
1138 $this->error = $object->error;
1145 unset($object->context[
'createfromclone']);
1149 $this->
db->commit();
1152 $this->
db->rollback();
1167 $this->
ref =
'TI0501-001';
1168 $this->track_id =
'XXXXaaaa';
1169 $this->origin_email =
'email@email.com';
1170 $this->fk_project = 1;
1171 $this->fk_user_create = 1;
1172 $this->fk_user_assign = 1;
1173 $this->subject =
'Subject of ticket';
1174 $this->message =
'Message of ticket';
1176 $this->resolution =
'1';
1177 $this->progress =
'10';
1179 $this->type_code =
'TYPECODE';
1180 $this->category_code =
'CATEGORYCODE';
1181 $this->severity_code =
'SEVERITYCODE';
1183 $this->date_read =
'';
1184 $this->date_last_msg_sent =
'';
1185 $this->date_close =
'';
1198 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 =
'');
1211 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1216 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type";
1218 $sql .=
" WHERE active > 0";
1219 $sql .=
" ORDER BY pos";
1220 dol_syslog(get_class($this).
"::load_cache_type_tickets", LOG_DEBUG);
1223 $num = $this->
db->num_rows(
$resql);
1226 $obj = $this->
db->fetch_object(
$resql);
1228 $label = ($langs->trans(
"TicketTypeShort".$obj->code) != (
"TicketTypeShort".$obj->code) ? $langs->trans(
"TicketTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1229 $this->cache_types_tickets[$obj->rowid][
'code'] = $obj->code;
1230 $this->cache_types_tickets[$obj->rowid][
'label'] = $label;
1231 $this->cache_types_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1232 $this->cache_types_tickets[$obj->rowid][
'pos'] = $obj->pos;
1250 global $conf, $langs;
1252 if ($publicgroup == -1 && !empty($this->cache_category_ticket) && count($this->cache_category_tickets)) {
1257 $sql =
"SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category";
1259 $sql .=
" WHERE active > 0 AND entity = ".((int) $conf->entity);
1260 if ($publicgroup > -1) {
1261 $sql .=
" AND public = ".((int) $publicgroup);
1263 $sql .=
" ORDER BY pos";
1265 dol_syslog(get_class($this).
"::load_cache_categories_tickets", LOG_DEBUG);
1269 $num = $this->
db->num_rows(
$resql);
1272 $obj = $this->
db->fetch_object(
$resql);
1273 $this->cache_category_tickets[$obj->rowid][
'code'] = $obj->code;
1274 $this->cache_category_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1275 $this->cache_category_tickets[$obj->rowid][
'pos'] = $obj->pos;
1276 $this->cache_category_tickets[$obj->rowid][
'public'] = $obj->public;
1277 $this->cache_category_tickets[$obj->rowid][
'active'] = $obj->active;
1278 $this->cache_category_tickets[$obj->rowid][
'force_severity'] = $obj->force_severity;
1279 $this->cache_category_tickets[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1283 $label = ($langs->trans(
"TicketCategoryShort".$obj->code) != (
"TicketCategoryShort".$obj->code) ? $langs->trans(
"TicketCategoryShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1284 $this->cache_category_tickets[$obj->rowid][
'label'] = $label;
1304 if (!empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) {
1309 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1310 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity";
1311 $sql .=
" WHERE active > 0";
1312 $sql .=
" ORDER BY pos";
1313 dol_syslog(get_class($this).
"::loadCacheSeveritiesTickets", LOG_DEBUG);
1316 $num = $this->
db->num_rows(
$resql);
1319 $obj = $this->
db->fetch_object(
$resql);
1321 $this->cache_severity_tickets[$obj->rowid][
'code'] = $obj->code;
1323 $label = ($langs->trans(
"TicketSeverityShort".$obj->code) != (
"TicketSeverityShort".$obj->code) ? $langs->trans(
"TicketSeverityShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1324 $this->cache_severity_tickets[$obj->rowid][
'label'] = $label;
1325 $this->cache_severity_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1326 $this->cache_severity_tickets[$obj->rowid][
'pos'] = $obj->pos;
1345 return $this->libStatut($this->fk_statut, $mode, 0, $this->progress);
1359 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1362 global $langs, $hookmanager;
1364 $labelStatus = $this->statuts[$status];
1365 $labelStatusShort = $this->statuts_short[$status];
1367 if ($status == self::STATUS_NOT_READ) {
1368 $statusType =
'status0';
1369 } elseif ($status == self::STATUS_READ) {
1370 $statusType =
'status1';
1371 } elseif ($status == self::STATUS_ASSIGNED) {
1372 $statusType =
'status2';
1373 } elseif ($status == self::STATUS_IN_PROGRESS) {
1374 $statusType =
'status4';
1375 } elseif ($status == self::STATUS_WAITING) {
1376 $statusType =
'status7';
1377 } elseif ($status == self::STATUS_NEED_MORE_INFO) {
1378 $statusType =
'status3';
1379 } elseif ($status == self::STATUS_CANCELED) {
1380 $statusType =
'status9';
1381 } elseif ($status == self::STATUS_CLOSED) {
1382 $statusType =
'status6';
1384 $labelStatus =
'Unknown';
1385 $labelStatusShort =
'Unknown';
1386 $statusType =
'status0';
1390 $parameters = array(
1391 'status' => $status,
1396 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1399 return $hookmanager->resPrint;
1404 $params = array(
'tooltip' =>
'no');
1407 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1408 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1410 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1411 $labelStatus .=
' ('.round($progress).
'%)';
1412 $labelStatusShort .=
' ('.round($progress).
'%)';
1415 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1429 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1431 global $db, $conf, $langs;
1432 global $dolibarr_main_authentication, $dolibarr_main_demo;
1433 global $menumanager;
1435 if (!empty($conf->dol_no_mouse_hover)) {
1441 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1442 $label .=
' '.$this->getLibStatut(4);
1444 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
1445 $label .=
'<b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id.
'<br>';
1446 $label .=
'<b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1447 if ($this->date_creation) {
1448 $label .=
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.$this->date_creation;
1450 if ($this->date_modification) {
1451 $label .=
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.$this->date_modification;
1453 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.$this->id;
1455 if ($option !=
'nolink') {
1457 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1458 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1459 $add_save_lastsearch_values = 1;
1461 if ($add_save_lastsearch_values) {
1462 $url .=
'&save_lastsearch_values=1';
1467 if (empty($notooltip)) {
1468 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1469 $label = $langs->trans(
"ShowTicket");
1470 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1472 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1473 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1475 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1478 $linkstart =
'<a href="'.$url.
'"';
1479 $linkstart .= $linkclose.
'>';
1482 $result .= $linkstart;
1484 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1486 if ($withpicto != 2) {
1487 $result .= $this->ref;
1489 $result .= $linkend;
1505 global $conf, $langs;
1509 if ($this->statut != self::STATUS_CANCELED) {
1514 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1515 $sql .=
" SET fk_statut = ".Ticket::STATUS_READ.
", date_read = '".$this->
db->idate(
dol_now()).
"'";
1516 $sql .=
" WHERE rowid = ".((int) $this->
id);
1521 $this->actionmsg = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1522 $this->actionmsg2 = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1524 if (!$error && !$notrigger) {
1526 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1534 $this->
db->commit();
1537 $this->
db->rollback();
1538 $this->error = join(
',', $this->errors);
1539 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1543 $this->
db->rollback();
1544 $this->error = $this->
db->lasterror();
1545 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1559 public function assignUser($user, $id_assign_user, $notrigger = 0)
1561 global $conf, $langs;
1569 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1570 if ($id_assign_user > 0) {
1571 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1573 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1575 $sql .=
" WHERE rowid = ".((int) $this->
id);
1577 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1580 $this->fk_user_assign = $id_assign_user;
1584 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1592 $this->
db->commit();
1595 $this->
db->rollback();
1596 $this->error = join(
',', $this->errors);
1597 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1601 $this->
db->rollback();
1602 $this->error = $this->
db->lasterror();
1603 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1619 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email =
false)
1621 global $conf, $langs;
1627 if (isset($this->fk_track_id)) {
1628 $this->fk_track_id = trim($this->fk_track_id);
1631 if (isset($this->message)) {
1632 $this->message = trim($this->message);
1638 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1640 $actioncomm->type_code =
'AC_OTH_AUTO';
1641 $actioncomm->code =
'TICKET_MSG';
1642 if ($this->
private) {
1643 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1646 $actioncomm->code .=
'_SENTBYMAIL';
1648 $actioncomm->socid = $this->socid;
1649 $actioncomm->label = $this->subject;
1650 $actioncomm->note_private = $this->message;
1651 $actioncomm->userassigned = array($user->id);
1652 $actioncomm->userownerid = $user->id;
1653 $actioncomm->datep = $now;
1654 $actioncomm->percentage = -1;
1655 $actioncomm->elementtype =
'ticket';
1656 $actioncomm->fk_element = $this->id;
1657 $actioncomm->fk_project = $this->fk_project;
1659 $attachedfiles = array();
1660 $attachedfiles[
'paths'] = $filename_list;
1661 $attachedfiles[
'names'] = $mimefilename_list;
1662 $attachedfiles[
'mimes'] = $mimetype_list;
1663 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1664 $actioncomm->attachedfiles = $attachedfiles;
1667 if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1668 $actioncomm->note_private =
dol_concatdesc($actioncomm->note_private,
"\n".$langs->transnoentities(
"AttachedFiles").
': '.join(
';', $mimefilename_list));
1671 $actionid = $actioncomm->create($user);
1672 if ($actionid <= 0) {
1674 $this->error = $actioncomm->error;
1675 $this->errors = $actioncomm->errors;
1680 $this->
db->rollback();
1683 $this->
db->commit();
1695 if (!empty($this->cache_msgs_ticket) && is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1701 $sql =
"SELECT id as rowid, fk_user_author, datec, label, note as message, code";
1702 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1703 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1704 $sql .=
" AND elementtype = 'ticket'";
1705 $sql .=
" ORDER BY datec DESC";
1707 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1710 $num = $this->
db->num_rows(
$resql);
1713 $obj = $this->
db->fetch_object(
$resql);
1714 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1715 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1716 $this->cache_msgs_ticket[$i][
'datec'] = $this->
db->jdate($obj->datec);
1717 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1718 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1719 $this->cache_msgs_ticket[$i][
'private'] = (preg_match(
'/^TICKET_MSG_PRIVATE/', $obj->code) ? 1 : 0);
1724 $this->error =
"Error ".$this->db->lasterror();
1725 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1739 global $conf, $langs;
1741 if ($this->fk_statut != Ticket::STATUS_CLOSED && $this->fk_statut != Ticket::STATUS_CANCELED) {
1744 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1745 $sql .=
" SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).
", progress=100, date_close='".$this->
db->idate(
dol_now()).
"'";
1746 $sql .=
" WHERE rowid = ".((int) $this->
id);
1748 dol_syslog(get_class($this).
"::close mode=".$mode);
1754 if (
isModEnabled(
'ficheinter') && !empty($conf->global->WORKFLOW_TICKET_CLOSE_INTERVENTION)) {
1755 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
1756 $this->fetchObjectLinked($this->
id, $this->element,
null,
'fichinter');
1757 if ($this->linkedObjectsIds) {
1758 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
1760 $fichinter->fetch($fichinter_id);
1761 if ($fichinter->statut == 0) {
1762 $result = $fichinter->setValid($user);
1764 $this->errors[] = $fichinter->error;
1768 if ($fichinter->statut < 3) {
1769 $result = $fichinter->setStatut(3);
1771 $this->errors[] = $fichinter->error;
1780 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
1787 $this->
db->commit();
1790 $this->
db->rollback();
1791 $this->error = join(
',', $this->errors);
1792 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1796 $this->
db->rollback();
1797 $this->error = $this->
db->lasterror();
1798 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1815 $thirdparties = array();
1819 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
1820 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
1821 if (!empty($type)) {
1822 if ($type == 1 || $type == 2) {
1823 $sql .=
" AND client = ".((int) $type);
1824 } elseif ($type == 3) {
1825 $sql .=
" AND fournisseur = 1";
1828 if (!empty($email)) {
1829 if (empty($exact)) {
1831 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1832 $email = str_replace(
'*',
'%', $email);
1834 $email =
'%'.$email.
'%';
1838 if (is_array($filters) && !empty($filters)) {
1842 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1844 if (is_array($filters) && !empty($filters)) {
1845 foreach ($filters as $field => $value) {
1846 $sql .=
" ".$clause.
" ".$field.
" LIKE '".$this->
db->escape($value).
"'";
1848 if (!empty($email)) {
1853 $res = $this->
db->query($sql);
1855 while ($rec = $this->
db->fetch_array($res)) {
1857 $soc->fetch($rec[
'rowid']);
1858 $thirdparties[] = $soc;
1861 return $thirdparties;
1863 $this->error = $this->
db->error().
' sql='.$sql;
1864 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
1879 $contacts = array();
1882 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
1883 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
1884 if (!empty($socid)) {
1885 $sql .=
" AND fk_soc = ".((int) $socid);
1887 if (!empty($email)) {
1890 $sql .=
"email = '".$this->db->escape($email).
"'";
1892 $sql .=
"email LIKE BINARY '".$this->db->escape($this->
db->escapeforlike($email)).
"'";
1896 $res = $this->
db->query($sql);
1898 while ($rec = $this->
db->fetch_object($res)) {
1899 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1900 $contactstatic =
new Contact($this->
db);
1901 $contactstatic->fetch($rec->rowid);
1902 $contacts[] = $contactstatic;
1907 $this->error = $this->
db->error().
' sql='.$sql;
1908 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
1922 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1923 $sql .=
" SET fk_soc = ".($id > 0 ? $id :
"null");
1924 $sql .=
" WHERE rowid = ".((int) $this->
id);
1925 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
1946 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1947 $sql .=
" SET progress = ".($percent > 0 ? $percent :
"null");
1948 $sql .=
" WHERE rowid = ".((int) $this->
id);
1949 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
1969 if (!$this->table_element) {
1970 dol_syslog(get_class($this).
"::setContract was called on objet with property table_element not defined", LOG_ERR);
1974 $result = $this->add_object_linked(
'contrat', $contractid);
1976 $this->fk_contract = $contractid;
1993 return $this->getIdContact(
'internal',
'SUPPORTTEC');
2003 return $this->listeContact(-1,
'internal');
2013 return $this->getIdContact(
'external',
'SUPPORTCLI');
2023 return $this->listeContact(-1,
'external');
2033 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2043 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2053 $array_contact = array();
2055 $array_contact = $this->getIdTicketInternalContact();
2057 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2059 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact());
2061 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2063 return $array_contact;
2073 $array_contact = array();
2075 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2077 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2079 return $array_contact;
2093 public function listeContact($status = -1, $source =
'external', $list = 0, $code =
'')
2099 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2100 if ($source ==
'internal') {
2101 $sql .=
", '-1' as socid, t.statut as statuscontact";
2104 if ($source ==
'external' || $source ==
'thirdparty') {
2105 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2108 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2109 if ($source ==
'internal') {
2110 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2113 if ($source ==
'external') {
2114 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2117 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2118 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2119 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2120 if ($source ==
'internal') {
2121 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2124 if ($source ==
'external' || $source ==
'thirdparty') {
2125 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2128 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2129 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2130 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2131 if ($source ==
'internal') {
2132 $sql .=
" AND tc.source = 'internal'";
2135 if ($source ==
'external' || $source ==
'thirdparty') {
2136 $sql .=
" AND tc.source = 'external'";
2139 if (!empty($code)) {
2140 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2143 $sql .=
" AND tc.active=1";
2145 $sql .=
" AND ec.statut = ".((int) $status);
2148 $sql .=
" ORDER BY t.lastname ASC";
2152 $num = $this->
db->num_rows(
$resql);
2155 $obj = $this->
db->fetch_object(
$resql);
2158 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2159 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2161 'source' => $obj->source,
2162 'socid' => $obj->socid,
2164 'nom' => $obj->lastname,
2165 'civility' => $obj->civility,
2166 'lastname' => $obj->lastname,
2167 'firstname' => $obj->firstname,
2168 'email' => $obj->email,
2169 'rowid' => $obj->rowid,
2170 'code' => $obj->code,
2171 'libelle' => $libelle_type,
2172 'status' => $obj->statuslink,
2173 'statuscontact'=>$obj->statuscontact,
2174 'fk_c_type_contact' => $obj->fk_c_type_contact,
2175 'phone' => $obj->phone,
2176 'phone_mobile' => $obj->phone_mobile);
2178 $tab[$i] = $obj->id;
2186 $this->error = $this->
db->error();
2203 $modele = empty($conf->global->TICKET_ADDON) ?
'mod_ticket_simple' : $conf->global->TICKET_ADDON;
2209 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2210 foreach ($dirmodels as $reldir) {
2211 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2212 if (file_exists($file)) {
2214 $classname = $modele;
2221 $modTicket =
new $classname;
2223 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2226 if (is_numeric($defaultref) && $defaultref <= 0) {
2244 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2252 if (file_exists($dir_osencoded)) {
2253 $handle = opendir($dir_osencoded);
2254 if (is_resource($handle)) {
2255 while (($file = readdir($handle)) !==
false) {
2257 $file = utf8_encode($file);
2282 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2283 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2284 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2286 $maxwidthsmall = 270;
2287 $maxheightsmall = 150;
2288 $maxwidthmini = 128;
2289 $maxheightmini = 72;
2292 $formmail->trackid = (is_null($forcetrackid) ?
'tic'.$this->id :
'');
2293 $attachedfiles = $formmail->get_attached_files();
2295 $filepath = $attachedfiles[
'paths'];
2296 $filename = $attachedfiles[
'names'];
2297 $mimetype = $attachedfiles[
'mimes'];
2300 $destdir = $conf->ticket->dir_output.
'/'.$this->ref;
2306 $listofpaths = array();
2307 $listofnames = array();
2308 foreach ($filename as $i => $val) {
2309 $destfile = $destdir.
'/'.$filename[$i];
2311 if (is_file($destfile)) {
2312 $pathinfo = pathinfo($filename[$i]);
2314 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2317 $res =
dol_move($filepath[$i], $destfile, 0, 1, 0, 1);
2320 $this->error =
"Failed to move file ".dirbasename($filepath[$i]).
" into ".
dirbasename($destfile);
2327 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2330 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2335 $formmail->remove_attached_files($i);
2338 $listofpaths[$i] = $destfile;
2339 $listofnames[$i] = basename($destfile);
2342 return array(
'listofpaths'=>$listofpaths,
'listofnames'=>$listofnames,
'listofmimes'=>$mimetype);
2358 if (!is_array($categories)) {
2359 $categories = array($categories);
2363 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2365 $existing = $c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2368 if (is_array($existing)) {
2369 $to_del = array_diff($existing, $categories);
2370 $to_add = array_diff($categories, $existing);
2373 $to_add = $categories;
2377 foreach ($to_del as $del) {
2378 if ($c->fetch($del) > 0) {
2379 $c->del_type($this, Categorie::TYPE_TICKET);
2382 foreach ($to_add as $add) {
2383 if ($c->fetch($add) > 0) {
2384 $c->add_type($this, Categorie::TYPE_TICKET);
2401 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2403 global $mysoc, $conf, $langs;
2409 $ret = $object->fetch(
'',
'',
GETPOST(
'track_id',
'alpha'));
2411 $object->socid = $object->fk_soc;
2412 $object->fetch_thirdparty();
2413 $object->fetch_project();
2417 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2423 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
2424 $action =
'add_message';
2428 $object->subject =
GETPOST(
'subject',
'alphanohtml');
2429 $object->message =
GETPOST(
"message",
"restricthtml");
2430 $object->private =
GETPOST(
"private_message",
"alpha");
2432 $send_email =
GETPOST(
'send_email',
'int');
2435 $resarray = $object->copyFilesForTicket();
2436 if (is_numeric($resarray) && $resarray == -1) {
2441 $listofpaths = $resarray[
'listofpaths'];
2442 $listofnames = $resarray[
'listofnames'];
2443 $listofmimes = $resarray[
'listofmimes'];
2445 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email);
2448 $this->error = $object->error;
2449 $this->errors = $object->errors;
2450 $action =
'add_message';
2453 if (!$error && $id > 0) {
2454 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'),
null,
'mesgs');
2459 if (!empty($public_area)) {
2465 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
2466 $assigned_user_dont_have_email =
'';
2468 if ($this->fk_user_assign > 0) {
2469 $assigned_user =
new User($this->
db);
2470 $assigned_user->fetch($this->fk_user_assign);
2471 if (!empty($assigned_user->email)) {
2472 $sendto[$assigned_user->email] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2474 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2477 if (empty($sendto)) {
2478 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
2479 $sendto[$conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
2480 } elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2481 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2486 if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
2487 !empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
2489 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2492 if (!empty($sendto)) {
2493 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2494 $subject =
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2497 $message = $langs->trans(
'TicketMessageMailIntroText');
2498 $message .=
'<br><br>';
2499 $messagePost =
GETPOST(
'message',
'restricthtml');
2503 $message .= $messagePost;
2506 $message .=
'<br><br>';
2507 $message .=
"==============================================";
2508 $message .= !empty($object->thirdparty->name) ?
'<br>'.$langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2509 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2510 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2513 $message .=
'<br><br>';
2514 if (!empty($assigned_user_dont_have_email)) {
2515 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2517 foreach ($sendto as $val) {
2518 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2522 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2523 $message .=
'<br><br>';
2524 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a>';
2526 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2535 if ($send_email > 0) {
2537 $internal_contacts = $object->getInfosTicketInternalContact();
2540 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2542 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2543 $appli = $label_title;
2544 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2546 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".$object->id);
2549 $message = $langs->trans(
'TicketMessageMailIntroText');
2550 $message .=
'<br><br>';
2551 $messagePost =
GETPOST(
'message',
'restricthtml');
2555 $message .= $messagePost;
2558 $message .=
'<br><br>';
2559 $message .=
"==============================================<br>";
2560 $message .= !empty($object->thirdparty->name) ? $langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2561 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2562 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2565 foreach ($internal_contacts as $key => $info_sendto) {
2567 if ($info_sendto[
'id'] == $user->id) {
2571 if ($info_sendto[
'email'] !=
'') {
2572 if (!empty($info_sendto[
'email'])) {
2573 $sendto[$info_sendto[
'email']] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2577 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2578 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2583 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2586 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a><br>';
2589 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2590 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2591 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2596 if (!empty($sendto)) {
2597 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2604 if (empty($object->private)) {
2606 $external_contacts = $object->getInfosTicketExternalContact();
2609 if (is_array($external_contacts) && count($external_contacts) === 0) {
2610 if (!empty($object->fk_soc)) {
2611 $object->fetch_thirdparty($object->fk_soc);
2612 $array_company = array(array(
'firstname' =>
'',
'lastname' => $object->thirdparty->name,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2613 $external_contacts = array_merge($external_contacts, $array_company);
2614 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2615 $array_external = array(array(
'firstname' =>
'',
'lastname' => $object->origin_email,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2616 $external_contacts = array_merge($external_contacts, $array_external);
2621 if (is_array($external_contacts) && count($external_contacts) > 0) {
2623 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2624 $appli = $mysoc->name;
2625 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2630 $message_intro =
dol_nl2br($message_intro);
2633 $message_signature =
dol_nl2br($message_signature);
2637 $messagePost =
GETPOST(
'message',
'restricthtml');
2641 $message = $messagePost;
2642 $message .=
'<br><br>';
2644 foreach ($external_contacts as $key => $info_sendto) {
2646 if ($info_sendto[
'id'] == $user->contact_id) {
2650 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] != $object->origin_email) {
2651 if (!empty($info_sendto[
'email'])) {
2652 $sendto[$info_sendto[
'email']] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2655 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2656 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2661 $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
2662 (!empty($conf->global->TICKET_URL_PUBLIC_INTERFACE) ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.
'/view.php' :
dol_buildpath(
'/public/ticket/view.php', 2)) :
dol_buildpath(
'/ticket/card.php', 2)).
'?track_id='.$object->track_id;
2663 $message .=
'<br>'.$langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$object->track_id.
'</a><br>';
2666 $message = $message_intro.
'<br><br>'.$message;
2669 $message .=
'<br>'.$message_signature;
2671 if (!empty($object->origin_email)) {
2672 $sendto[$object->origin_email] = $object->origin_email;
2675 if ($object->fk_soc > 0 && !array_key_exists($object->origin_email, $sendto)) {
2676 $object->socid = $object->fk_soc;
2677 $object->fetch_thirdparty();
2678 if (!empty($object->thirdparty->email)) {
2679 $sendto[$object->thirdparty->email] = $object->thirdparty->email;
2684 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2685 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2686 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2691 if (!empty($sendto)) {
2692 $result = $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2695 $this->date_last_msg_sent =
dol_now();
2696 $this->update($user, 1);
2706 if (($object->status < self::STATUS_IN_PROGRESS && !$user->socid && !$private) ||
2707 ($object->status > self::STATUS_IN_PROGRESS && $public_area)
2709 $object->setStatut(3);
2735 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2737 global $conf, $langs;
2739 if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
2740 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2744 $langs->load(
"mails");
2746 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2750 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2751 $array_receiver = $this->getInfosTicketInternalContact();
2752 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact());
2755 if ($send_internal_cc) {
2756 $sendtocc = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2759 $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2761 if (is_array($array_receiver) && count($array_receiver) > 0) {
2762 foreach ($array_receiver as $key => $receiver) {
2763 $deliveryreceipt = 0;
2764 $filepath = $filename_list;
2765 $filename = $mimefilename_list;
2766 $mimetype = $mimetype_list;
2772 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2773 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
2776 $upload_dir_tmp = $conf->user->dir_output.
"/".$user->id.
'/temp';
2778 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2779 $trackid =
"tic".$this->id;
2781 $moreinheader =
'X-Dolibarr-Info: sendTicketMessageByEmail'.
"\r\n";
2782 if (!empty($this->email_msgid)) {
2783 $moreinheader .=
'References <'.$this->email_msgid.
'>'.
"\r\n";
2786 $mailfile =
new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid, $moreinheader,
'ticket',
'', $upload_dir_tmp);
2787 if ($mailfile->error) {
2790 $result = $mailfile->sendfile();
2792 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)),
null,
'mesgs');
2795 $langs->load(
"other");
2796 if ($mailfile->error) {
2797 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver),
null,
'errors');
2798 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
2800 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'errors');
2805 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2806 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2810 $langs->load(
"other");
2811 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'),
null,
'warnings');
2828 global $conf, $user, $langs;
2833 $this->nbtodo = $this->nbtodolate = 0;
2836 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
2837 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2838 if (
isModEnabled(
'societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2839 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2840 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2843 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2844 if ($mode ==
'opened') {
2845 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
2848 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2853 $label = $labelShort =
'';
2855 if ($mode ==
'opened') {
2856 $status =
'openall';
2859 $label = $langs->trans(
"MenuListNonClosed");
2860 $labelShort = $langs->trans(
"MenuListNonClosed");
2865 $response->label = $label;
2866 $response->labelShort = $labelShort;
2867 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
2871 while ($obj = $this->
db->fetch_object(
$resql)) {
2872 $response->nbtodo++;
2873 if ($mode ==
'opened') {
2874 $datelimit = $this->
db->jdate($obj->datec) + $delay_warning;
2875 if ($datelimit < $now) {
2882 $this->error = $this->
db->lasterror();
2896 global $conf, $user;
2898 $this->nb = array();
2901 $sql =
"SELECT count(p.rowid) as nb";
2902 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2903 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2904 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2905 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2906 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2909 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2914 while ($obj = $this->
db->fetch_object(
$resql)) {
2915 $this->nb[
"ticket"] = $obj->nb;
2921 $this->error = $this->
db->lasterror();
2936 $tables = array(
'ticket');
3067 public $date_last_msg_sent =
'';