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;
143 public $category_code;
148 public $severity_code;
178 public $date_read =
'';
183 public $date_last_msg_sent =
'';
188 public $date_close =
'';
193 public $cache_types_tickets;
198 public $cache_category_tickets;
203 public $notify_tiers_at_create;
215 public $regeximgext =
'\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff';
221 const STATUS_READ = 1;
222 const STATUS_ASSIGNED = 2;
223 const STATUS_IN_PROGRESS = 3;
224 const STATUS_NEED_MORE_INFO = 5;
225 const STATUS_WAITING = 7;
226 const STATUS_CLOSED = 8;
227 const STATUS_CANCELED = 9;
258 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'position'=>1,
'visible'=>-2,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id"),
259 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>5,
'notnull'=>1,
'index'=>1),
260 '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),
261 'track_id' => array(
'type'=>
'varchar(255)',
'label'=>
'TicketTrackId',
'visible'=>-2,
'enabled'=>1,
'position'=>11,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"Help text"),
262 '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'),
263 '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'),
264 'subject' => array(
'type'=>
'varchar(255)',
'label'=>
'Subject',
'visible'=>1,
'enabled'=>1,
'position'=>18,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"",
'css'=>
'maxwidth200 tdoverflowmax200',
'autofocusoncreate'=>1),
265 'type_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Type',
'visible'=>1,
'enabled'=>1,
'position'=>20,
'notnull'=>-1,
'help'=>
"",
'csslist'=>
'maxwidth125 tdoverflowmax50'),
266 'category_code' => array(
'type'=>
'varchar(32)',
'label'=>
'TicketCategory',
'visible'=>-1,
'enabled'=>1,
'position'=>21,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100 tdoverflowmax200'),
267 'severity_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Severity',
'visible'=>1,
'enabled'=>1,
'position'=>22,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100'),
268 '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'),
269 'notify_tiers_at_create' => array(
'type'=>
'integer',
'label'=>
'NotifyThirdparty',
'visible'=>-1,
'enabled'=>0,
'position'=>51,
'notnull'=>1,
'index'=>1),
270 '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"),
272 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'visible'=>1,
'enabled'=>1,
'position'=>500,
'notnull'=>1,
'csslist'=>
'nowraponall'),
273 'date_read' => array(
'type'=>
'datetime',
'label'=>
'TicketReadOn',
'visible'=>-1,
'enabled'=>1,
'position'=>501,
'notnull'=>1),
274 'date_last_msg_sent' => array(
'type'=>
'datetime',
'label'=>
'TicketLastMessageDate',
'visible'=>0,
'enabled'=>1,
'position'=>502,
'notnull'=>-1),
275 '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'),
276 'date_close' => array(
'type'=>
'datetime',
'label'=>
'TicketCloseOn',
'visible'=>-1,
'enabled'=>1,
'position'=>510,
'notnull'=>1),
277 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'visible'=>-1,
'enabled'=>1,
'position'=>520,
'notnull'=>1),
278 'message' => array(
'type'=>
'text',
'label'=>
'Message',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,),
279 'email_msgid' => array(
'type'=>
'varchar(255)',
'label'=>
'EmailMsgID',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'help'=>
'EmailMsgIDDesc'),
280 'progress' => array(
'type'=>
'integer',
'label'=>
'Progression',
'visible'=>-1,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'css'=>
'right',
'help'=>
"",
'isameasure'=>2,
'csslist'=>
'width50'),
281 'resolution' => array(
'type'=>
'integer',
'label'=>
'Resolution',
'visible'=>-1,
'enabled'=>
'$conf->global->TICKET_ENABLE_RESOLUTION',
'position'=>550,
'notnull'=>1),
282 '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')),
283 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
299 $this->statuts_short = array(
300 self::STATUS_NOT_READ =>
'Unread',
301 self::STATUS_READ =>
'Read',
302 self::STATUS_ASSIGNED =>
'Assigned',
303 self::STATUS_IN_PROGRESS =>
'InProgress',
304 self::STATUS_WAITING =>
'OnHold',
305 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformationShort',
306 self::STATUS_CLOSED =>
'SolvedClosed',
307 self::STATUS_CANCELED =>
'Canceled'
309 $this->statuts = array(
310 self::STATUS_NOT_READ =>
'Unread',
311 self::STATUS_READ =>
'Read',
312 self::STATUS_ASSIGNED =>
'Assigned',
313 self::STATUS_IN_PROGRESS =>
'InProgress',
314 self::STATUS_WAITING =>
'OnHold',
315 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformation',
316 self::STATUS_CLOSED =>
'SolvedClosed',
317 self::STATUS_CANCELED =>
'Canceled'
329 $this->errors = array();
334 if (isset($this->
ref)) {
335 $this->
ref = trim($this->
ref);
338 if (isset($this->track_id)) {
339 $this->track_id = trim($this->track_id);
342 if (isset($this->fk_soc)) {
343 $this->fk_soc = (int) $this->fk_soc;
346 if (isset($this->fk_project)) {
347 $this->fk_project = (int) $this->fk_project;
350 if (isset($this->origin_email)) {
351 $this->origin_email = trim($this->origin_email);
354 if (isset($this->fk_user_create)) {
355 $this->fk_user_create = (int) $this->fk_user_create;
358 if (isset($this->fk_user_assign)) {
359 $this->fk_user_assign = (int) $this->fk_user_assign;
362 if (isset($this->subject)) {
363 $this->subject = trim($this->subject);
366 if (isset($this->message)) {
367 $this->message = trim($this->message);
370 if (isset($this->fk_statut)) {
371 $this->fk_statut = (int) $this->fk_statut;
374 if (isset($this->resolution)) {
375 $this->resolution = trim($this->resolution);
378 if (isset($this->progress)) {
379 $this->progress = trim($this->progress);
382 if (isset($this->timing)) {
383 $this->timing = trim($this->timing);
386 if (isset($this->type_code)) {
387 $this->type_code = trim($this->type_code);
390 if (isset($this->category_code)) {
391 $this->category_code = trim($this->category_code);
394 if (isset($this->severity_code)) {
395 $this->severity_code = trim($this->severity_code);
398 if (empty($this->
ref)) {
399 $this->errors[] =
'ErrorTicketRefRequired';
400 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
414 public function create($user, $notrigger = 0)
416 global $conf, $langs;
421 if (empty($this->track_id)) {
427 $result = $this->
verify();
431 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ticket(";
435 $sql .=
"fk_project,";
436 $sql .=
"origin_email,";
437 $sql .=
"fk_user_create,";
438 $sql .=
"fk_user_assign,";
439 $sql .=
"email_msgid,";
442 $sql .=
"fk_statut,";
443 $sql .=
"resolution,";
446 $sql .=
"type_code,";
447 $sql .=
"category_code,";
448 $sql .=
"severity_code,";
450 $sql .=
"date_read,";
451 $sql .=
"date_close,";
453 $sql .=
"notify_tiers_at_create";
454 $sql .=
") VALUES (";
455 $sql .=
" ".(!isset($this->
ref) ?
'' :
"'".$this->db->escape($this->
ref).
"'").
",";
456 $sql .=
" ".(!isset($this->track_id) ?
'NULL' :
"'".$this->db->escape($this->track_id).
"'").
",";
457 $sql .=
" ".($this->fk_soc > 0 ? $this->
db->escape($this->fk_soc) :
"null").
",";
458 $sql .=
" ".($this->fk_project > 0 ? $this->
db->escape($this->fk_project) :
"null").
",";
459 $sql .=
" ".(!isset($this->origin_email) ?
'NULL' :
"'".$this->db->escape($this->origin_email).
"'").
",";
460 $sql .=
" ".($this->fk_user_create > 0 ? $this->fk_user_create : ($user->id > 0 ? $user->id :
'NULL')).
",";
461 $sql .=
" ".($this->fk_user_assign > 0 ? $this->fk_user_assign :
'NULL').
",";
462 $sql .=
" ".(empty($this->email_msgid) ?
'NULL' :
"'".$this->db->escape($this->email_msgid).
"'").
",";
463 $sql .=
" ".(!isset($this->subject) ?
'NULL' :
"'".$this->db->escape($this->subject).
"'").
",";
464 $sql .=
" ".(!isset($this->message) ?
'NULL' :
"'".$this->db->escape($this->message).
"'").
",";
465 $sql .=
" ".(!isset($this->fk_statut) ?
'0' :
"'".$this->db->escape($this->fk_statut).
"'").
",";
466 $sql .=
" ".(!isset($this->resolution) ?
'NULL' :
"'".$this->db->escape($this->resolution).
"'").
",";
467 $sql .=
" ".(!isset($this->progress) ?
'0' :
"'".$this->db->escape($this->progress).
"'").
",";
468 $sql .=
" ".(!isset($this->timing) ?
'NULL' :
"'".$this->db->escape($this->timing).
"'").
",";
469 $sql .=
" ".(!isset($this->type_code) ?
'NULL' :
"'".$this->db->escape($this->type_code).
"'").
",";
470 $sql .=
" ".(empty($this->category_code) || $this->category_code ==
'-1' ?
'NULL' :
"'".$this->db->escape($this->category_code).
"'").
",";
471 $sql .=
" ".(!isset($this->severity_code) ?
'NULL' :
"'".$this->db->escape($this->severity_code).
"'").
",";
472 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
473 $sql .=
" ".(!isset($this->date_read) ||
dol_strlen($this->date_read) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_read).
"'").
",";
474 $sql .=
" ".(!isset($this->date_close) ||
dol_strlen($this->date_close) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_close).
"'").
"";
475 $sql .=
", ".((int) $conf->entity);
476 $sql .=
", ".(!isset($this->notify_tiers_at_create) ?
'1' :
"'".$this->db->escape($this->notify_tiers_at_create).
"'");
481 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
485 $this->errors[] =
"Error ".$this->db->lasterror();
489 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"ticket");
492 if (!$error && ! empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) {
494 if ($this->
add_contact($user->id,
'CONTRIBUTOR',
'internal') < 0) {
499 if (!$error && $this->fk_user_assign > 0) {
500 if ($this->
add_contact($this->fk_user_assign,
'SUPPORTTEC',
'internal') < 0) {
514 if (!$error && !$notrigger) {
525 foreach ($this->errors as $errmsg) {
526 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
527 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
529 $this->
db->rollback();
536 $this->
db->rollback();
537 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
551 public function fetch($id =
'', $ref =
'', $track_id =
'', $email_msgid =
'')
556 if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
557 $this->error =
'ErrorWrongParameters';
564 $sql .=
" t.entity,";
566 $sql .=
" t.track_id,";
567 $sql .=
" t.fk_soc,";
568 $sql .=
" t.fk_project,";
569 $sql .=
" t.origin_email,";
570 $sql .=
" t.fk_user_create,";
571 $sql .=
" t.fk_user_assign,";
572 $sql .=
" t.email_msgid,";
573 $sql .=
" t.subject,";
574 $sql .=
" t.message,";
575 $sql .=
" t.fk_statut as status,";
576 $sql .=
" t.resolution,";
577 $sql .=
" t.progress,";
578 $sql .=
" t.timing,";
579 $sql .=
" t.type_code,";
580 $sql .=
" t.category_code,";
581 $sql .=
" t.severity_code,";
583 $sql .=
" t.date_read,";
584 $sql .=
" t.date_last_msg_sent,";
585 $sql .=
" t.date_close,";
587 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
588 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
589 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
590 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
591 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
594 $sql .=
" WHERE t.rowid = ".((int) $id);
596 $sql .=
" WHERE t.entity IN (".getEntity($this->element, 1).
")";
598 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
599 } elseif ($track_id) {
600 $sql .=
" AND t.track_id = '".$this->db->escape($track_id).
"'";
602 $sql .=
" AND t.email_msgid = '".$this->db->escape($email_msgid).
"'";
606 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
610 $obj = $this->
db->fetch_object(
$resql);
612 $this->
id = $obj->rowid;
613 $this->entity = $obj->entity;
614 $this->
ref = $obj->ref;
615 $this->track_id = $obj->track_id;
616 $this->fk_soc = $obj->fk_soc;
617 $this->socid = $obj->fk_soc;
618 $this->fk_project = $obj->fk_project;
619 $this->origin_email = $obj->origin_email;
620 $this->fk_user_create = $obj->fk_user_create;
621 $this->fk_user_assign = $obj->fk_user_assign;
622 $this->email_msgid = $obj->email_msgid;
623 $this->subject = $obj->subject;
624 $this->message = $obj->message;
626 $this->status = $obj->status;
627 $this->fk_statut = $this->status;
629 $this->resolution = $obj->resolution;
630 $this->progress = $obj->progress;
631 $this->timing = $obj->timing;
633 $this->type_code = $obj->type_code;
635 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
636 $this->type_label = $label_type;
638 $this->category_code = $obj->category_code;
640 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
641 $this->category_label = $label_category;
643 $this->severity_code = $obj->severity_code;
645 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
646 $this->severity_label = $label_severity;
648 $this->datec = $this->
db->jdate($obj->datec);
649 $this->date_creation = $this->
db->jdate($obj->datec);
650 $this->date_read = $this->
db->jdate($obj->date_read);
651 $this->date_validation = $this->
db->jdate($obj->date_read);
652 $this->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
653 $this->date_close = $this->
db->jdate($obj->date_close);
654 $this->tms = $this->
db->jdate($obj->tms);
655 $this->date_modification = $this->
db->jdate($obj->tms);
665 $this->error =
"Error ".$this->db->lasterror();
666 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
684 public function fetchAll($user, $sortorder =
'ASC', $sortfield =
't.datec', $limit =
'', $offset = 0, $arch =
'', $filter =
'')
691 $extrafields->fetch_name_optionals_label($this->table_element);
696 $sql .=
" t.track_id,";
697 $sql .=
" t.fk_soc,";
698 $sql .=
" t.fk_project,";
699 $sql .=
" t.origin_email,";
700 $sql .=
" t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
701 $sql .=
" t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
702 $sql .=
" t.subject,";
703 $sql .=
" t.message,";
704 $sql .=
" t.fk_statut,";
705 $sql .=
" t.resolution,";
706 $sql .=
" t.progress,";
707 $sql .=
" t.timing,";
708 $sql .=
" t.type_code,";
709 $sql .=
" t.category_code,";
710 $sql .=
" t.severity_code,";
712 $sql .=
" t.date_read,";
713 $sql .=
" t.date_last_msg_sent,";
714 $sql .=
" t.date_close,";
716 $sql .=
", type.label as type_label, category.label as category_label, severity.label as severity_label";
718 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
719 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
",ef.".$key.
" as options_".$key :
'');
721 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
722 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
723 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
724 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
725 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid=t.fk_soc";
726 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as uc ON uc.rowid=t.fk_user_create";
727 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as ua ON ua.rowid=t.fk_user_assign";
728 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
729 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ticket_extrafields as ef on (t.rowid = ef.fk_object)";
731 if (empty($user->rights->societe->client->voir) && !$user->socid) {
732 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
735 $sql .=
" WHERE t.entity IN (".getEntity(
'ticket').
")";
738 if (!empty($filter)) {
739 foreach ($filter as $key => $value) {
740 if (strpos($key,
'date')) {
741 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
742 } elseif (($key ==
't.fk_user_assign') || ($key ==
't.type_code') || ($key ==
't.category_code') || ($key ==
't.severity_code') || ($key ==
't.fk_soc')) {
743 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
744 } elseif ($key ==
't.fk_statut') {
745 if (is_array($value) && count($value) > 0) {
746 $sql .=
" AND ".$key.
" IN (".$this->
db->sanitize(implode(
',', $value)).
")";
748 $sql .=
" AND ".$key.
' = '.((int) $value);
751 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
755 if (empty($user->rights->societe->client->voir) && !$user->socid) {
756 $sql .=
" AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
757 } elseif ($user->socid) {
758 $sql .=
" AND t.fk_soc = ".((int) $user->socid);
761 $sql .= $this->
db->order($sortfield, $sortorder);
762 if (!empty($limit)) {
763 $sql .= $this->
db->plimit($limit + 1, $offset);
766 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
770 $this->lines = array();
777 $obj = $this->
db->fetch_object(
$resql);
781 $line->id = $obj->rowid;
782 $line->rowid = $obj->rowid;
783 $line->ref = $obj->ref;
784 $line->track_id = $obj->track_id;
785 $line->fk_soc = $obj->fk_soc;
786 $line->fk_project = $obj->fk_project;
787 $line->origin_email = $obj->origin_email;
789 $line->fk_user_create = $obj->fk_user_create;
790 $line->user_create_lastname = $obj->user_create_lastname;
791 $line->user_create_firstname = $obj->user_create_firstname;
793 $line->fk_user_assign = $obj->fk_user_assign;
794 $line->user_assign_lastname = $obj->user_assign_lastname;
795 $line->user_assign_firstname = $obj->user_assign_firstname;
797 $line->subject = $obj->subject;
798 $line->message = $obj->message;
799 $line->fk_statut = $obj->fk_statut;
800 $line->resolution = $obj->resolution;
801 $line->progress = $obj->progress;
802 $line->timing = $obj->timing;
805 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
806 $line->type_label = $label_type;
808 $this->category_code = $obj->category_code;
810 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
811 $line->category_label = $label_category;
813 $this->severity_code = $obj->severity_code;
815 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
816 $line->severity_label = $label_severity;
818 $line->datec = $this->
db->jdate($obj->datec);
819 $line->date_read = $this->
db->jdate($obj->date_read);
820 $line->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
821 $line->date_close = $this->
db->jdate($obj->date_close);
824 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
825 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
826 $tmpkey =
'options_'.$key;
827 $line->{$tmpkey} = $obj->$tmpkey;
831 $this->lines[$i] = $line;
838 $this->error =
"Error ".$this->db->lasterror();
839 dol_syslog(get_class($this).
"::fetchAll ".$this->error, LOG_ERR);
851 public function update($user = 0, $notrigger = 0)
853 global $conf, $langs, $hookmanager;
857 if (isset($this->
ref)) {
858 $this->
ref = trim($this->
ref);
861 if (isset($this->track_id)) {
862 $this->track_id = trim($this->track_id);
865 if (isset($this->fk_soc)) {
866 $this->fk_soc = (int) $this->fk_soc;
869 if (isset($this->fk_project)) {
870 $this->fk_project = (int) $this->fk_project;
873 if (isset($this->origin_email)) {
874 $this->origin_email = trim($this->origin_email);
877 if (isset($this->fk_user_create)) {
878 $this->fk_user_create = (int) $this->fk_user_create;
881 if (isset($this->fk_user_assign)) {
882 $this->fk_user_assign = (int) $this->fk_user_assign;
885 if (isset($this->subject)) {
886 $this->subject = trim($this->subject);
889 if (isset($this->message)) {
890 $this->message = trim($this->message);
893 if (isset($this->fk_statut)) {
894 $this->fk_statut = (int) $this->fk_statut;
897 if (isset($this->resolution)) {
898 $this->resolution = trim($this->resolution);
901 if (isset($this->progress)) {
902 $this->progress = trim($this->progress);
905 if (isset($this->timing)) {
906 $this->timing = trim($this->timing);
909 if (isset($this->type_code)) {
910 $this->timing = trim($this->type_code);
913 if (isset($this->category_code)) {
914 $this->timing = trim($this->category_code);
917 if (isset($this->severity_code)) {
918 $this->timing = trim($this->severity_code);
924 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket SET";
925 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"").
",";
926 $sql .=
" track_id=".(isset($this->track_id) ?
"'".$this->db->escape($this->track_id).
"'" :
"null").
",";
927 $sql .=
" fk_soc=".(isset($this->fk_soc) ?
"'".$this->db->escape($this->fk_soc).
"'" :
"null").
",";
928 $sql .=
" fk_project=".(isset($this->fk_project) ?
"'".$this->db->escape($this->fk_project).
"'" :
"null").
",";
929 $sql .=
" origin_email=".(isset($this->origin_email) ?
"'".$this->db->escape($this->origin_email).
"'" :
"null").
",";
930 $sql .=
" fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create :
"null").
",";
931 $sql .=
" fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign :
"null").
",";
932 $sql .=
" subject=".(isset($this->subject) ?
"'".$this->db->escape($this->subject).
"'" :
"null").
",";
933 $sql .=
" message=".(isset($this->message) ?
"'".$this->db->escape($this->message).
"'" :
"null").
",";
934 $sql .=
" fk_statut=".(isset($this->fk_statut) ? $this->fk_statut :
"null").
",";
935 $sql .=
" resolution=".(isset($this->resolution) ? $this->resolution :
"null").
",";
936 $sql .=
" progress=".(isset($this->progress) ?
"'".$this->db->escape($this->progress).
"'" :
"null").
",";
937 $sql .=
" timing=".(isset($this->timing) ?
"'".$this->db->escape($this->timing).
"'" :
"null").
",";
938 $sql .=
" type_code=".(isset($this->type_code) ?
"'".$this->db->escape($this->type_code).
"'" :
"null").
",";
939 $sql .=
" category_code=".(isset($this->category_code) ?
"'".$this->db->escape($this->category_code).
"'" :
"null").
",";
940 $sql .=
" severity_code=".(isset($this->severity_code) ?
"'".$this->db->escape($this->severity_code).
"'" :
"null").
",";
941 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
942 $sql .=
" date_read=".(dol_strlen($this->date_read) != 0 ?
"'".$this->db->idate($this->date_read).
"'" :
'null').
",";
943 $sql .=
" date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ?
"'".$this->db->idate($this->date_last_msg_sent).
"'" :
'null').
",";
944 $sql .=
" date_close=".(dol_strlen($this->date_close) != 0 ?
"'".$this->db->idate($this->date_close).
"'" :
'null').
"";
945 $sql .=
" WHERE rowid=".((int) $this->
id);
952 $this->errors[] =
"Error ".$this->db->lasterror();
957 $result = $this->insertExtraFields();
963 if (!$error && !$notrigger) {
965 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
974 foreach ($this->errors as $errmsg) {
975 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
976 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
978 $this->
db->rollback();
993 public function delete($user, $notrigger = 0)
995 global $conf, $langs;
1003 $result = $this->call_trigger(
'TICKET_DELETE', $user);
1013 $res = $this->delete_linked_contact();
1015 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1022 $res = $this->deleteObjectLinked();
1030 $result = $this->deleteExtraFields();
1033 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1040 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_ticket";
1041 $sql .=
" WHERE fk_ticket = ".(int) $this->
id;
1043 $result = $this->
db->query($sql);
1046 $this->errors[] = $this->
db->lasterror();
1051 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ticket";
1052 $sql .=
" WHERE rowid=".((int) $this->
id);
1054 dol_syslog(get_class($this).
"::delete sql=".$sql);
1058 $this->errors[] =
"Error ".$this->db->lasterror();
1064 foreach ($this->errors as $errmsg) {
1065 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1066 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1068 $this->
db->rollback();
1071 $this->
db->commit();
1092 $object->fetch($fromid);
1094 $object->statut = 0;
1099 $object->context[
'createfromclone'] =
'createfromclone';
1100 $result = $object->create($user);
1104 $this->error = $object->error;
1111 unset($object->context[
'createfromclone']);
1115 $this->
db->commit();
1118 $this->
db->rollback();
1133 $this->
ref =
'TI0501-001';
1134 $this->track_id =
'XXXXaaaa';
1135 $this->origin_email =
'email@email.com';
1136 $this->fk_project = 1;
1137 $this->fk_user_create = 1;
1138 $this->fk_user_assign = 1;
1139 $this->subject =
'Subject of ticket';
1140 $this->message =
'Message of ticket';
1142 $this->resolution =
'1';
1143 $this->progress =
'10';
1145 $this->type_code =
'TYPECODE';
1146 $this->category_code =
'CATEGORYCODE';
1147 $this->severity_code =
'SEVERITYCODE';
1149 $this->date_read =
'';
1150 $this->date_last_msg_sent =
'';
1151 $this->date_close =
'';
1164 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 =
'');
1177 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1182 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1183 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type";
1184 $sql .=
" WHERE active > 0";
1185 $sql .=
" ORDER BY pos";
1186 dol_syslog(get_class($this).
"::load_cache_type_tickets", LOG_DEBUG);
1189 $num = $this->
db->num_rows(
$resql);
1192 $obj = $this->
db->fetch_object(
$resql);
1194 $label = ($langs->trans(
"TicketTypeShort".$obj->code) != (
"TicketTypeShort".$obj->code) ? $langs->trans(
"TicketTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1195 $this->cache_types_tickets[$obj->rowid][
'code'] = $obj->code;
1196 $this->cache_types_tickets[$obj->rowid][
'label'] = $label;
1197 $this->cache_types_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1198 $this->cache_types_tickets[$obj->rowid][
'pos'] = $obj->pos;
1215 global $conf, $langs;
1217 if (!empty($this->cache_category_ticket) && count($this->cache_category_tickets)) {
1222 $sql =
"SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category";
1224 $sql .=
" WHERE active > 0 AND entity = ".((int) $conf->entity);
1225 $sql .=
" ORDER BY pos";
1226 dol_syslog(get_class($this).
"::load_cache_categories_tickets", LOG_DEBUG);
1229 $num = $this->
db->num_rows(
$resql);
1232 $obj = $this->
db->fetch_object(
$resql);
1233 $this->cache_category_tickets[$obj->rowid][
'code'] = $obj->code;
1234 $this->cache_category_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1235 $this->cache_category_tickets[$obj->rowid][
'pos'] = $obj->pos;
1236 $this->cache_category_tickets[$obj->rowid][
'public'] = $obj->public;
1237 $this->cache_category_tickets[$obj->rowid][
'active'] = $obj->active;
1238 $this->cache_category_tickets[$obj->rowid][
'force_severity'] = $obj->force_severity;
1239 $this->cache_category_tickets[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1243 $label = ($langs->trans(
"TicketCategoryShort".$obj->code) != (
"TicketCategoryShort".$obj->code) ? $langs->trans(
"TicketCategoryShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1244 $this->cache_category_tickets[$obj->rowid][
'label'] = $label;
1264 if (!empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) {
1269 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1270 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity";
1271 $sql .=
" WHERE active > 0";
1272 $sql .=
" ORDER BY pos";
1273 dol_syslog(get_class($this).
"::loadCacheSeveritiesTickets", LOG_DEBUG);
1276 $num = $this->
db->num_rows(
$resql);
1279 $obj = $this->
db->fetch_object(
$resql);
1281 $this->cache_severity_tickets[$obj->rowid][
'code'] = $obj->code;
1283 $label = ($langs->trans(
"TicketSeverityShort".$obj->code) != (
"TicketSeverityShort".$obj->code) ? $langs->trans(
"TicketSeverityShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1284 $this->cache_severity_tickets[$obj->rowid][
'label'] = $label;
1285 $this->cache_severity_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1286 $this->cache_severity_tickets[$obj->rowid][
'pos'] = $obj->pos;
1305 return $this->libStatut($this->fk_statut, $mode, 0, $this->progress);
1319 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1324 $labelStatus = $this->statuts[$status];
1325 $labelStatusShort = $this->statuts_short[$status];
1327 if ($status == self::STATUS_NOT_READ) {
1328 $statusType =
'status0';
1329 } elseif ($status == self::STATUS_READ) {
1330 $statusType =
'status1';
1331 } elseif ($status == self::STATUS_ASSIGNED) {
1332 $statusType =
'status2';
1333 } elseif ($status == self::STATUS_IN_PROGRESS) {
1334 $statusType =
'status4';
1335 } elseif ($status == self::STATUS_WAITING) {
1336 $statusType =
'status7';
1337 } elseif ($status == self::STATUS_NEED_MORE_INFO) {
1338 $statusType =
'status3';
1339 } elseif ($status == self::STATUS_CANCELED) {
1340 $statusType =
'status9';
1341 } elseif ($status == self::STATUS_CLOSED) {
1342 $statusType =
'status6';
1344 $labelStatus =
'Unknown';
1345 $labelStatusShort =
'Unknown';
1346 $statusType =
'status0';
1352 $params = array(
'tooltip' =>
'no');
1355 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1356 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1358 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1359 $labelStatus .=
' ('.round($progress).
'%)';
1360 $labelStatusShort .=
' ('.round($progress).
'%)';
1363 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1377 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1379 global $db, $conf, $langs;
1380 global $dolibarr_main_authentication, $dolibarr_main_demo;
1381 global $menumanager;
1383 if (!empty($conf->dol_no_mouse_hover)) {
1389 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1390 $label .=
' '.$this->getLibStatut(4);
1392 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
1393 $label .=
'<b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id.
'<br>';
1394 $label .=
'<b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1395 if ($this->date_creation) {
1396 $label .=
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.$this->date_creation;
1398 if ($this->date_modification) {
1399 $label .=
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.$this->date_modification;
1401 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.$this->id;
1403 if ($option !=
'nolink') {
1405 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1406 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1407 $add_save_lastsearch_values = 1;
1409 if ($add_save_lastsearch_values) {
1410 $url .=
'&save_lastsearch_values=1';
1415 if (empty($notooltip)) {
1416 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1417 $label = $langs->trans(
"ShowTicket");
1418 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1420 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1421 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1423 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1426 $linkstart =
'<a href="'.$url.
'"';
1427 $linkstart .= $linkclose.
'>';
1430 $result .= $linkstart;
1432 $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);
1434 if ($withpicto != 2) {
1435 $result .= $this->ref;
1437 $result .= $linkend;
1453 global $conf, $langs;
1457 if ($this->statut != self::STATUS_CANCELED) {
1460 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1461 $sql .=
" SET fk_statut = ".Ticket::STATUS_READ.
", date_read='".$this->
db->idate(
dol_now()).
"'";
1462 $sql .=
" WHERE rowid = ".((int) $this->
id);
1467 $this->actionmsg = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1468 $this->actionmsg2 = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1470 if (!$error && !$notrigger) {
1472 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1480 $this->
db->commit();
1483 $this->
db->rollback();
1484 $this->error = join(
',', $this->errors);
1485 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1489 $this->
db->rollback();
1490 $this->error = $this->
db->lasterror();
1491 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1505 public function assignUser($user, $id_assign_user, $notrigger = 0)
1507 global $conf, $langs;
1514 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1515 if ($id_assign_user > 0) {
1516 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1518 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1520 $sql .=
" WHERE rowid = ".((int) $this->
id);
1522 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1525 $this->fk_user_assign = $id_assign_user;
1529 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1537 $this->
db->commit();
1540 $this->
db->rollback();
1541 $this->error = join(
',', $this->errors);
1542 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1546 $this->
db->rollback();
1547 $this->error = $this->
db->lasterror();
1548 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1563 global $conf, $langs;
1567 $langs->load(
'ticket');
1570 $contacts = $this->listeContact(-1,
'internal');
1571 $contacts = array_merge($contacts, $this->listeContact(-1,
'external'));
1574 if (!empty($this->origin_email) && empty($this->fk_soc)) {
1575 $array_ext = array(array(
'firstname' =>
'',
'lastname' =>
'',
'email' => $this->origin_email,
'libelle' => $langs->transnoentities(
'TicketEmailOriginIssuer'),
'socid' =>
"-1"));
1576 $contacts = array_merge($contacts, $array_ext);
1579 if (!empty($this->fk_soc)) {
1580 $this->fetch_thirdparty($this->fk_soc);
1581 $array_company = array(array(
'firstname' =>
'',
'lastname' => $this->client->name,
'email' => $this->client->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $this->client->id));
1582 $contacts = array_merge($contacts, $array_company);
1586 if (count($contacts) > 0) {
1587 foreach ($contacts as $key => $info_sendto) {
1589 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNotificationEmailSubject', $this->track_id);
1590 $message .= $langs->transnoentities(
'TicketNotificationEmailBody', $this->track_id).
"\n\n";
1591 $message .= $langs->transnoentities(
'Title').
' : '.$this->subject.
"\n";
1593 $recipient_name =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1');
1594 $recipient = (!empty($recipient_name) ? $recipient_name : $info_sendto[
'email']).
' ('.strtolower($info_sendto[
'libelle']).
')';
1595 $message .= $langs->transnoentities(
'TicketNotificationRecipient').
' : '.$recipient.
"\n";
1597 $message .=
'* '.$langs->transnoentities(
'TicketNotificationLogMessage').
' *'.
"\n";
1600 if ($info_sendto[
'source'] ==
'internal') {
1601 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$this->track_id;
1602 $message .=
"\n".$langs->transnoentities(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$this->track_id.
'</a>'.
"\n";
1604 $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.
'/view.php' :
dol_buildpath(
'/public/ticket/view.php', 2)).
'?track_id='.$this->track_id;
1605 $message .=
"\n".$langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$this->track_id.
'</a>'.
"\n";
1609 $message .= $langs->transnoentities(
'TicketEmailPleaseDoNotReplyToThisEmail').
"\n";
1611 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
1615 $filepath = array();
1616 $filename = array();
1617 $mimetype = array();
1621 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1622 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
1623 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
1625 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1627 $deliveryreceipt = 0;
1628 $mailfile =
new CMailFile($subject, $info_sendto[
'email'], $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, 0);
1629 if ($mailfile->error || $mailfile->errors) {
1632 $result = $mailfile->sendfile();
1637 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1638 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
1642 setEventMessages($langs->trans(
'TicketNotificationNumberEmailSent', $nb_sent), null,
'mesgs');
1657 if (is_array($this->cache_logs_ticket) && count($this->cache_logs_ticket)) {
1701 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
1703 global $conf, $langs;
1709 if (isset($this->fk_track_id)) {
1710 $this->fk_track_id = trim($this->fk_track_id);
1713 if (isset($this->message)) {
1714 $this->message = trim($this->message);
1720 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1722 $actioncomm->type_code =
'AC_OTH';
1723 $actioncomm->code =
'TICKET_MSG';
1724 if ($this->
private) {
1725 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1727 $actioncomm->socid = $this->socid;
1728 $actioncomm->label = $this->subject;
1729 $actioncomm->note_private = $this->message;
1730 $actioncomm->userassigned = array($user->id);
1731 $actioncomm->userownerid = $user->id;
1732 $actioncomm->datep = $now;
1733 $actioncomm->percentage = -1;
1734 $actioncomm->elementtype =
'ticket';
1735 $actioncomm->fk_element = $this->id;
1737 $attachedfiles = array();
1738 $attachedfiles[
'paths'] = $filename_list;
1739 $attachedfiles[
'names'] = $mimefilename_list;
1740 $attachedfiles[
'mimes'] = $mimetype_list;
1741 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1742 $actioncomm->attachedfiles = $attachedfiles;
1745 if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1746 $actioncomm->note_private =
dol_concatdesc($actioncomm->note_private,
"\n".$langs->transnoentities(
"AttachedFiles").
': '.join(
';', $mimefilename_list));
1749 $actionid = $actioncomm->create($user);
1750 if ($actionid <= 0) {
1752 $this->error = $actioncomm->error;
1753 $this->errors = $actioncomm->errors;
1758 $this->
db->rollback();
1761 $this->
db->commit();
1773 if (is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1779 $sql =
"SELECT id as rowid, fk_user_author, datec, label, note as message, code";
1780 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1781 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1782 $sql .=
" AND elementtype = 'ticket'";
1783 $sql .=
" ORDER BY datec DESC";
1785 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1788 $num = $this->
db->num_rows(
$resql);
1791 $obj = $this->
db->fetch_object(
$resql);
1792 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1793 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1794 $this->cache_msgs_ticket[$i][
'datec'] = $this->
db->jdate($obj->datec);
1795 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1796 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1797 $this->cache_msgs_ticket[$i][
'private'] = ($obj->code ==
'TICKET_MSG_PRIVATE' ? 1 : 0);
1802 $this->error =
"Error ".$this->db->lasterror();
1803 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1817 global $conf, $langs;
1819 if ($this->fk_statut != Ticket::STATUS_CLOSED && $this->fk_statut != Ticket::STATUS_CANCELED) {
1822 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1823 $sql .=
" SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).
", progress=100, date_close='".$this->
db->idate(
dol_now()).
"'";
1824 $sql .=
" WHERE rowid = ".((int) $this->
id);
1826 dol_syslog(get_class($this).
"::close mode=".$mode);
1832 if (
isModEnabled(
'ficheinter') && !empty($conf->global->WORKFLOW_TICKET_CLOSE_INTERVENTION)) {
1833 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
1834 $this->fetchObjectLinked($this->
id, $this->element, null,
'fichinter');
1835 if ($this->linkedObjectsIds) {
1836 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
1838 $fichinter->fetch($fichinter_id);
1839 if ($fichinter->statut == 0) {
1840 $result = $fichinter->setValid($user);
1842 $this->errors[] = $fichinter->error;
1846 if ($fichinter->statut < 3) {
1847 $result = $fichinter->setStatut(3);
1849 $this->errors[] = $fichinter->error;
1858 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
1865 $this->
db->commit();
1868 $this->
db->rollback();
1869 $this->error = join(
',', $this->errors);
1870 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1874 $this->
db->rollback();
1875 $this->error = $this->
db->lasterror();
1876 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1893 $thirdparties = array();
1897 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
1898 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
1899 if (!empty($type)) {
1900 if ($type == 1 || $type == 2) {
1901 $sql .=
" AND client = ".((int) $type);
1902 } elseif ($type == 3) {
1903 $sql .=
" AND fournisseur = 1";
1906 if (!empty($email)) {
1907 if (empty($exact)) {
1909 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1910 $email = str_replace(
'*',
'%', $email);
1912 $email =
'%'.$email.
'%';
1916 if (is_array($filters) && !empty($filters)) {
1920 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1922 if (is_array($filters) && !empty($filters)) {
1923 foreach ($filters as $field => $value) {
1924 $sql .=
" ".$clause.
" ".$field.
" LIKE '".$this->
db->escape($value).
"'";
1926 if (!empty($email)) {
1931 $res = $this->
db->query($sql);
1933 while ($rec = $this->
db->fetch_array($res)) {
1935 $soc->fetch($rec[
'rowid']);
1936 $thirdparties[] = $soc;
1939 return $thirdparties;
1941 $this->error = $this->
db->error().
' sql='.$sql;
1942 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
1957 $contacts = array();
1960 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
1961 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
1962 if (!empty($socid)) {
1963 $sql .=
" AND fk_soc='".$this->db->escape($socid).
"'";
1966 if (!empty($email)) {
1970 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1972 $sql .=
"email LIKE BINARY '".$this->db->escape($email).
"'";
1976 $res = $this->
db->query($sql);
1978 while ($rec = $this->
db->fetch_array($res)) {
1979 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1980 $contactstatic =
new Contact($this->
db);
1981 $contactstatic->fetch($rec[
'rowid']);
1982 $contacts[] = $contactstatic;
1987 $this->error = $this->
db->error().
' sql='.$sql;
1988 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
2002 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2003 $sql .=
" SET fk_soc = ".($id > 0 ? $id :
"null");
2004 $sql .=
" WHERE rowid = ".((int) $this->
id);
2005 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
2026 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2027 $sql .=
" SET progress = ".($percent > 0 ? $percent :
"null");
2028 $sql .=
" WHERE rowid = ".((int) $this->
id);
2029 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
2049 if (!$this->table_element) {
2050 dol_syslog(get_class($this).
"::setContract was called on objet with property table_element not defined", LOG_ERR);
2054 $result = $this->add_object_linked(
'contrat', $contractid);
2056 $this->fk_contract = $contractid;
2073 return $this->getIdContact(
'internal',
'SUPPORTTEC');
2083 return $this->listeContact(-1,
'internal');
2093 return $this->getIdContact(
'external',
'SUPPORTCLI');
2103 return $this->listeContact(-1,
'external');
2113 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2123 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2133 $array_contact = array();
2135 $array_contact = $this->getIdTicketInternalContact($exclude_self);
2137 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2139 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact($exclude_self));
2140 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2142 return $array_contact;
2152 $array_contact = array();
2154 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2155 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2157 return $array_contact;
2171 public function listeContact($status = -1, $source =
'external', $list = 0, $code =
'')
2177 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2178 if ($source ==
'internal') {
2179 $sql .=
", '-1' as socid, t.statut as statuscontact";
2182 if ($source ==
'external' || $source ==
'thirdparty') {
2183 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2186 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2187 if ($source ==
'internal') {
2188 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2191 if ($source ==
'external') {
2192 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2195 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2196 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2197 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2198 if ($source ==
'internal') {
2199 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2202 if ($source ==
'external' || $source ==
'thirdparty') {
2203 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2206 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2207 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2208 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2209 if ($source ==
'internal') {
2210 $sql .=
" AND tc.source = 'internal'";
2213 if ($source ==
'external' || $source ==
'thirdparty') {
2214 $sql .=
" AND tc.source = 'external'";
2217 if (!empty($code)) {
2218 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2221 $sql .=
" AND tc.active=1";
2223 $sql .=
" AND ec.statut = ".((int) $status);
2226 $sql .=
" ORDER BY t.lastname ASC";
2230 $num = $this->
db->num_rows(
$resql);
2233 $obj = $this->
db->fetch_object(
$resql);
2236 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2237 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2239 'source' => $obj->source,
2240 'socid' => $obj->socid,
2242 'nom' => $obj->lastname,
2243 'civility' => $obj->civility,
2244 'lastname' => $obj->lastname,
2245 'firstname' => $obj->firstname,
2246 'email' => $obj->email,
2247 'rowid' => $obj->rowid,
2248 'code' => $obj->code,
2249 'libelle' => $libelle_type,
2250 'status' => $obj->statuslink,
2251 'statuscontact'=>$obj->statuscontact,
2252 'fk_c_type_contact' => $obj->fk_c_type_contact,
2253 'phone' => $obj->phone,
2254 'phone_mobile' => $obj->phone_mobile);
2256 $tab[$i] = $obj->id;
2264 $this->error = $this->
db->error();
2281 $modele = empty($conf->global->TICKET_ADDON) ?
'mod_ticket_simple' : $conf->global->TICKET_ADDON;
2287 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2288 foreach ($dirmodels as $reldir) {
2289 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2290 if (file_exists($file)) {
2292 $classname = $modele;
2299 $modTicket =
new $classname;
2301 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2304 if (is_numeric($defaultref) && $defaultref <= 0) {
2322 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2330 if (file_exists($dir_osencoded)) {
2331 $handle = opendir($dir_osencoded);
2332 if (is_resource($handle)) {
2333 while (($file = readdir($handle)) !==
false) {
2335 $file = utf8_encode($file);
2359 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2360 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2361 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2363 $maxwidthsmall = 270;
2364 $maxheightsmall = 150;
2365 $maxwidthmini = 128;
2366 $maxheightmini = 72;
2370 $attachedfiles = $formmail->get_attached_files();
2372 $filepath = $attachedfiles[
'paths'];
2373 $filename = $attachedfiles[
'names'];
2374 $mimetype = $attachedfiles[
'mimes'];
2377 $destdir = $conf->ticket->dir_output.
'/'.$this->ref;
2383 $listofpaths = array();
2384 $listofnames = array();
2385 foreach ($filename as $i => $val) {
2386 $destfile = $destdir.
'/'.$filename[$i];
2388 if (is_file($destfile)) {
2389 $pathinfo = pathinfo($filename[$i]);
2391 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2394 $res =
dol_move($filepath[$i], $destfile, 0, 1);
2399 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2402 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2405 $formmail->remove_attached_files($i);
2408 $listofpaths[$i] = $destfile;
2409 $listofnames[$i] = basename($destfile);
2412 return array(
'listofpaths'=>$listofpaths,
'listofnames'=>$listofnames,
'listofmimes'=>$mimetype);
2428 if (!is_array($categories)) {
2429 $categories = array($categories);
2433 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2435 $existing = $c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2438 if (is_array($existing)) {
2439 $to_del = array_diff($existing, $categories);
2440 $to_add = array_diff($categories, $existing);
2443 $to_add = $categories;
2447 foreach ($to_del as $del) {
2448 if ($c->fetch($del) > 0) {
2449 $c->del_type($this, Categorie::TYPE_TICKET);
2452 foreach ($to_add as $add) {
2453 if ($c->fetch($add) > 0) {
2454 $c->add_type($this, Categorie::TYPE_TICKET);
2470 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2472 global $mysoc, $conf, $langs;
2478 $ret = $object->fetch(
'',
'',
GETPOST(
'track_id',
'alpha'));
2480 $object->socid = $object->fk_soc;
2481 $object->fetch_thirdparty();
2485 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2491 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
2492 $action =
'add_message';
2496 $object->subject =
GETPOST(
'subject',
'alphanohtml');
2497 $object->message =
GETPOST(
"message",
"restricthtml");
2498 $object->private =
GETPOST(
"private_message",
"alpha");
2500 $send_email =
GETPOST(
'send_email',
'int');
2503 $resarray = $object->copyFilesForTicket();
2505 $listofpaths = $resarray[
'listofpaths'];
2506 $listofnames = $resarray[
'listofnames'];
2507 $listofmimes = $resarray[
'listofmimes'];
2509 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames);
2512 $this->error = $object->error;
2513 $this->errors = $object->errors;
2514 $action =
'add_message';
2517 if (!$error && $id > 0) {
2518 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'), null,
'mesgs');
2526 if (!empty($public_area)) {
2530 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
2531 $assigned_user_dont_have_email =
'';
2533 if ($this->fk_user_assign > 0) {
2534 $assigned_user =
new User($this->
db);
2535 $assigned_user->fetch($this->fk_user_assign);
2536 if (!empty($assigned_user->email)) {
2537 $sendto[] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2539 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2542 if (empty($sendto)) {
2543 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
2544 $sendto[] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
2545 } elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2546 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2551 if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
2552 !empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
2554 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2557 if (!empty($sendto)) {
2558 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2559 $subject =
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2562 $message = $langs->trans(
'TicketMessageMailIntroText');
2563 $message .=
'<br><br>';
2564 $messagePost =
GETPOST(
'message',
'restricthtml');
2568 $message .= $messagePost;
2571 $message .=
'<br><br>';
2572 $message .=
"==============================================";
2573 $message .= !empty($object->thirdparty->name) ?
'<br>'.$langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2574 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2575 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2578 $message .=
'<br><br>';
2579 if (!empty($assigned_user_dont_have_email)) {
2580 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2582 foreach ($sendto as $val) {
2583 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2587 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2588 $message .=
'<br><br>';
2589 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a>';
2591 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2601 if ($send_email > 0) {
2603 $internal_contacts = $object->getInfosTicketInternalContact();
2606 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2608 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2609 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2611 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".$object->id);
2612 $message_signature =
GETPOST(
'mail_signature') ?
GETPOST(
'mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2614 $message = $langs->trans(
'TicketMessageMailIntroText');
2615 $message .=
'<br><br>';
2616 $messagePost =
GETPOST(
'message',
'restricthtml');
2620 $message .= $messagePost;
2623 $message .=
'<br><br>';
2624 $message .=
"==============================================<br>";
2625 $message .= !empty($object->thirdparty->name) ? $langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2626 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2627 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2630 foreach ($internal_contacts as $key => $info_sendto) {
2632 if ($info_sendto[
'id'] == $user->id) {
2636 if ($info_sendto[
'email'] !=
'') {
2637 if (!empty($info_sendto[
'email'])) {
2638 $sendto[] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2642 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2643 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2648 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2651 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a><br>';
2654 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2655 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2656 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2661 if (!empty($sendto)) {
2662 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2669 if (empty($object->private)) {
2671 $external_contacts = $object->getInfosTicketExternalContact();
2674 if (is_array($external_contacts) && count($external_contacts) === 0) {
2675 if (!empty($object->fk_soc)) {
2676 $object->fetch_thirdparty($object->fk_soc);
2677 $array_company = array(array(
'firstname' =>
'',
'lastname' => $object->thirdparty->name,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2678 $external_contacts = array_merge($external_contacts, $array_company);
2679 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2680 $array_external = array(array(
'firstname' =>
'',
'lastname' => $object->origin_email,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2681 $external_contacts = array_merge($external_contacts, $array_external);
2686 if (is_array($external_contacts) && count($external_contacts) > 0) {
2688 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2689 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2691 $message_intro =
GETPOST(
'mail_intro') ?
GETPOST(
'mail_intro',
'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
2692 $message_signature =
GETPOST(
'mail_signature') ?
GETPOST(
'mail_signature',
'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2694 $message_intro =
dol_nl2br($message_intro);
2697 $message_signature =
dol_nl2br($message_signature);
2701 $messagePost =
GETPOST(
'message',
'restricthtml');
2705 $message = $messagePost;
2706 $message .=
'<br><br>';
2708 foreach ($external_contacts as $key => $info_sendto) {
2710 if ($info_sendto[
'id'] == $user->contact_id) {
2714 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] != $object->origin_email) {
2715 if (!empty($info_sendto[
'email'])) {
2716 $sendto[] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2719 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2720 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2725 $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
2726 (!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;
2727 $message .=
'<br>'.$langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$object->track_id.
'</a><br>';
2730 $message = $message_intro.
'<br><br>'.$message;
2733 $message .=
'<br>'.$message_signature;
2735 if (!empty($object->origin_email)) {
2736 $sendto[] = $object->origin_email;
2739 if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) {
2740 $object->socid = $object->fk_soc;
2741 $object->fetch_thirdparty();
2742 if (!empty($object->thirdparty->email)) {
2743 $sendto[] = $object->thirdparty->email;
2748 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2749 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2750 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2755 if (!empty($sendto)) {
2756 $result = $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2759 $this->date_last_msg_sent =
dol_now();
2760 $this->update($user);
2769 if ($object->status < 3 && !$user->socid) {
2770 $object->setStatut(3);
2796 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2798 global $conf, $langs;
2800 if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
2801 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2805 $langs->load(
"mails");
2807 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2811 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2812 $array_receiver = $this->getInfosTicketInternalContact();
2813 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact());
2816 if ($send_internal_cc) {
2817 $sendtocc = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2820 $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2822 if (is_array($array_receiver) && count($array_receiver) > 0) {
2823 foreach ($array_receiver as $key => $receiver) {
2824 $deliveryreceipt = 0;
2825 $filepath = $filename_list;
2826 $filename = $mimefilename_list;
2827 $mimetype = $mimetype_list;
2830 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2831 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
2832 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
2834 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2835 $trackid =
"tic".$this->id;
2836 $mailfile =
new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid,
'',
'ticket');
2837 if ($mailfile->error) {
2840 $result = $mailfile->sendfile();
2842 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)), null,
'mesgs');
2845 $langs->load(
"other");
2846 if ($mailfile->error) {
2847 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver), null,
'errors');
2848 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
2850 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'errors');
2854 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2855 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2859 $langs->load(
"other");
2860 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'), null,
'warnings');
2876 global $conf, $user, $langs;
2881 $this->nbtodo = $this->nbtodolate = 0;
2884 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
2885 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2886 if (
isModEnabled(
'societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2887 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2888 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2891 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2892 if ($mode ==
'opened') {
2893 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
2896 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2901 $label = $labelShort =
'';
2903 if ($mode ==
'opened') {
2904 $status =
'openall';
2907 $label = $langs->trans(
"MenuListNonClosed");
2908 $labelShort = $langs->trans(
"MenuListNonClosed");
2913 $response->label = $label;
2914 $response->labelShort = $labelShort;
2915 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
2919 while ($obj = $this->
db->fetch_object(
$resql)) {
2920 $response->nbtodo++;
2921 if ($mode ==
'opened') {
2922 $datelimit = $this->
db->jdate($obj->datec) + $delay_warning;
2923 if ($datelimit < $now) {
2930 $this->error = $this->
db->lasterror();
2944 global $conf, $user;
2946 $this->nb = array();
2949 $sql =
"SELECT count(p.rowid) as nb";
2950 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2951 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2952 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2953 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2954 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2957 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2962 while ($obj = $this->
db->fetch_object(
$resql)) {
2963 $this->nb[
"ticket"] = $obj->nb;
2969 $this->error = $this->
db->lasterror();
2984 $tables = array(
'ticket');
3115 public $date_last_msg_sent =
'';
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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)...
close(User $user, $mode=0)
Close a ticket.
fetchAll($user, $sortorder= 'ASC', $sortfield= 't.datec', $limit= '', $offset=0, $arch= '', $filter= '')
Load all objects in memory from database.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
markAsRead($user, $notrigger=0)
Mark a message as read.
getIdTicketCustomerInvolvedContact()
Return id des contacts clients des intervenants.
Class to manage agenda events (actions)
$email_from
Email from user.
$category_label
Category label.
$conf db
API class for accounts.
setProgression($percent)
Define progression of current ticket.
copyFilesForTicket()
Copy files defined into $_SESSION array into the ticket directory of attached files.
$origin_email
Person email who have create ticket.
dol_html_entity_decode($a, $b, $c= 'UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
$fk_user_create
User id who have create ticket.
getInfosTicketExternalContact()
Retrieve informations about external contacts.
printSelectStatus($selected="")
Print selected status.
Class to manage Dolibarr users.
getInfosTicketInternalContact()
Retrieve informations about internal contacts.
listeContact($status=-1, $source= 'external', $list=0, $code= '')
Get array of all contacts for a ticket Override method of file commonobject.class.php to add phone number.
add_contact($fk_socpeople, $type_contact, $source= 'external', $notrigger=0)
Add a link between element $this->element and a contact.
$severity_code
Severity code.
createTicketMessage($user, $notrigger=0, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
Add message into database.
is_photo_available($sdir)
Return if at least one photo is available.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
update($user=0, $notrigger=0)
Update object into database.
loadCacheCategoriesTickets()
Load into a cache array, the list of ticket categories (setup done into dictionary) ...
create($user, $notrigger=0)
Create object into database.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
$resolution
State resolution.
sendLogByEmail($user, $message)
Send notification of changes by email.
dol_is_dir($folder)
Test if filename is a directory.
__construct($db)
Constructor.
$fk_user_assign
User id who have ticket assigned.
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_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$progress
Progress in percent.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
$date_close
Close ticket date.
$severity_label
Severity label.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
fetch($id= '', $ref= '', $track_id= '', $email_msgid= '')
Load object in memory from the database.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
$category_label
Category label.
loadCacheLogsTicket()
Charge la liste des actions sur le ticket.
Class to manage third parties objects (customers, suppliers, prospects...)
$subject
var string Ticket subject
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to manage categories.
load_state_board()
Load indicator this->nb of global stats widget.
setCustomer($id)
Define parent commany of current ticket.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
getTicketAllCustomerContacts()
Return id of all contacts for ticket.
$timing
Duration for ticket.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
generate_random_id($car=16)
Generate a random id.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" 'label' the translation key.
searchContactByEmail($email, $socid= '', $case= '')
Search and fetch contacts by email.
getIdTicketInternalInvolvedContact()
Return id des contacts clients des intervenants.
utf8_check($str)
Check if a string is in UTF8.
getIdTicketInternalContact()
Return id des contacts interne de suivi.
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...
dol_is_file($pathoffile)
Return if path is a file.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
$track_id
Hash to identify ticket.
verify()
Check properties of ticket are ok (like ref, track_id, ...).
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
$category_code
Category code.
LibStatut($status, $mode=0, $notooltip=0, $progress=0)
Return status label of object.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getIdTicketCustomerContact()
Return id des contacts clients pour le suivi ticket.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setCategories($categories)
Sets object to supplied categories.
isModEnabled($module)
Is Dolibarr module enabled.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
assignUser($user, $id_assign_user, $notrigger=0)
Mark a message as read.
const STATUS_NOT_READ
Status.
loadCacheSeveritiesTickets()
Charge dans cache la liste des sévérité de tickets (paramétrable dans dictionnaire) ...
loadCacheTypesTickets()
Load into a cache the types of tickets (setup done into dictionaries)
getLibStatut($mode=0)
Return status label of object.
loadCacheMsgsTicket()
Load the list of event on ticket into ->cache_msgs_ticket.
getDefaultRef($thirdparty= '')
Get a default reference.
searchSocidByEmail($email, $type= '0', $filters=array(), $clause= 'AND')
Search and fetch thirparties by email.
setContract($contractid)
Link element with a contract.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
getTicketAllContacts()
Return id of all contacts for ticket.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
newMessage($user, &$action, $private=1, $public_area=0)
Add new message on a ticket (private/public area).
$severity_label
Severity label.
dol_textishtml($msg, $option=0)
Return if a text is a html content.