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)
1322 global $langs, $hookmanager;
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';
1350 $parameters = array(
1351 'status' => $status,
1356 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1359 return $hookmanager->resPrint;
1364 $params = array(
'tooltip' =>
'no');
1367 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1368 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1370 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1371 $labelStatus .=
' ('.round($progress).
'%)';
1372 $labelStatusShort .=
' ('.round($progress).
'%)';
1375 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1389 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1391 global $db, $conf, $langs;
1392 global $dolibarr_main_authentication, $dolibarr_main_demo;
1393 global $menumanager;
1395 if (!empty($conf->dol_no_mouse_hover)) {
1401 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1402 $label .=
' '.$this->getLibStatut(4);
1404 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
1405 $label .=
'<b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id.
'<br>';
1406 $label .=
'<b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1407 if ($this->date_creation) {
1408 $label .=
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.$this->date_creation;
1410 if ($this->date_modification) {
1411 $label .=
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.$this->date_modification;
1413 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.$this->id;
1415 if ($option !=
'nolink') {
1417 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1418 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1419 $add_save_lastsearch_values = 1;
1421 if ($add_save_lastsearch_values) {
1422 $url .=
'&save_lastsearch_values=1';
1427 if (empty($notooltip)) {
1428 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1429 $label = $langs->trans(
"ShowTicket");
1430 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1432 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1433 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1435 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1438 $linkstart =
'<a href="'.$url.
'"';
1439 $linkstart .= $linkclose.
'>';
1442 $result .= $linkstart;
1444 $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);
1446 if ($withpicto != 2) {
1447 $result .= $this->ref;
1449 $result .= $linkend;
1465 global $conf, $langs;
1469 if ($this->statut != self::STATUS_CANCELED) {
1472 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1473 $sql .=
" SET fk_statut = ".Ticket::STATUS_READ.
", date_read='".$this->
db->idate(
dol_now()).
"'";
1474 $sql .=
" WHERE rowid = ".((int) $this->
id);
1479 $this->actionmsg = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1480 $this->actionmsg2 = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1482 if (!$error && !$notrigger) {
1484 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1492 $this->
db->commit();
1495 $this->
db->rollback();
1496 $this->error = join(
',', $this->errors);
1497 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1501 $this->
db->rollback();
1502 $this->error = $this->
db->lasterror();
1503 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1517 public function assignUser($user, $id_assign_user, $notrigger = 0)
1519 global $conf, $langs;
1526 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1527 if ($id_assign_user > 0) {
1528 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1530 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1532 $sql .=
" WHERE rowid = ".((int) $this->
id);
1534 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1537 $this->fk_user_assign = $id_assign_user;
1541 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1549 $this->
db->commit();
1552 $this->
db->rollback();
1553 $this->error = join(
',', $this->errors);
1554 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1558 $this->
db->rollback();
1559 $this->error = $this->
db->lasterror();
1560 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1575 global $conf, $langs;
1579 $langs->load(
'ticket');
1582 $contacts = $this->listeContact(-1,
'internal');
1583 $contacts = array_merge($contacts, $this->listeContact(-1,
'external'));
1586 if (!empty($this->origin_email) && empty($this->fk_soc)) {
1587 $array_ext = array(array(
'firstname' =>
'',
'lastname' =>
'',
'email' => $this->origin_email,
'libelle' => $langs->transnoentities(
'TicketEmailOriginIssuer'),
'socid' =>
"-1"));
1588 $contacts = array_merge($contacts, $array_ext);
1591 if (!empty($this->fk_soc)) {
1592 $this->fetch_thirdparty($this->fk_soc);
1593 $array_company = array(array(
'firstname' =>
'',
'lastname' => $this->client->name,
'email' => $this->client->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $this->client->id));
1594 $contacts = array_merge($contacts, $array_company);
1598 if (count($contacts) > 0) {
1599 foreach ($contacts as $key => $info_sendto) {
1601 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNotificationEmailSubject', $this->track_id);
1602 $message .= $langs->transnoentities(
'TicketNotificationEmailBody', $this->track_id).
"\n\n";
1603 $message .= $langs->transnoentities(
'Title').
' : '.$this->subject.
"\n";
1605 $recipient_name =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1');
1606 $recipient = (!empty($recipient_name) ? $recipient_name : $info_sendto[
'email']).
' ('.strtolower($info_sendto[
'libelle']).
')';
1607 $message .= $langs->transnoentities(
'TicketNotificationRecipient').
' : '.$recipient.
"\n";
1609 $message .=
'* '.$langs->transnoentities(
'TicketNotificationLogMessage').
' *'.
"\n";
1612 if ($info_sendto[
'source'] ==
'internal') {
1613 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$this->track_id;
1614 $message .=
"\n".$langs->transnoentities(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$this->track_id.
'</a>'.
"\n";
1616 $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;
1617 $message .=
"\n".$langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$this->track_id.
'</a>'.
"\n";
1621 $message .= $langs->transnoentities(
'TicketEmailPleaseDoNotReplyToThisEmail').
"\n";
1623 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
1627 $filepath = array();
1628 $filename = array();
1629 $mimetype = array();
1633 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1634 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
1635 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
1637 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1639 $deliveryreceipt = 0;
1640 $mailfile =
new CMailFile($subject, $info_sendto[
'email'], $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, 0);
1641 if ($mailfile->error || $mailfile->errors) {
1644 $result = $mailfile->sendfile();
1649 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1650 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
1654 setEventMessages($langs->trans(
'TicketNotificationNumberEmailSent', $nb_sent),
null,
'mesgs');
1669 if (is_array($this->cache_logs_ticket) && count($this->cache_logs_ticket)) {
1713 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
1715 global $conf, $langs;
1721 if (isset($this->fk_track_id)) {
1722 $this->fk_track_id = trim($this->fk_track_id);
1725 if (isset($this->message)) {
1726 $this->message = trim($this->message);
1732 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1734 $actioncomm->type_code =
'AC_OTH';
1735 $actioncomm->code =
'TICKET_MSG';
1736 if ($this->
private) {
1737 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1739 $actioncomm->socid = $this->socid;
1740 $actioncomm->label = $this->subject;
1741 $actioncomm->note_private = $this->message;
1742 $actioncomm->userassigned = array($user->id);
1743 $actioncomm->userownerid = $user->id;
1744 $actioncomm->datep = $now;
1745 $actioncomm->percentage = -1;
1746 $actioncomm->elementtype =
'ticket';
1747 $actioncomm->fk_element = $this->id;
1749 $attachedfiles = array();
1750 $attachedfiles[
'paths'] = $filename_list;
1751 $attachedfiles[
'names'] = $mimefilename_list;
1752 $attachedfiles[
'mimes'] = $mimetype_list;
1753 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1754 $actioncomm->attachedfiles = $attachedfiles;
1757 if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1758 $actioncomm->note_private =
dol_concatdesc($actioncomm->note_private,
"\n".$langs->transnoentities(
"AttachedFiles").
': '.join(
';', $mimefilename_list));
1761 $actionid = $actioncomm->create($user);
1762 if ($actionid <= 0) {
1764 $this->error = $actioncomm->error;
1765 $this->errors = $actioncomm->errors;
1770 $this->
db->rollback();
1773 $this->
db->commit();
1785 if (is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1791 $sql =
"SELECT id as rowid, fk_user_author, datec, label, note as message, code";
1792 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1793 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1794 $sql .=
" AND elementtype = 'ticket'";
1795 $sql .=
" ORDER BY datec DESC";
1797 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1800 $num = $this->
db->num_rows(
$resql);
1803 $obj = $this->
db->fetch_object(
$resql);
1804 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1805 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1806 $this->cache_msgs_ticket[$i][
'datec'] = $this->
db->jdate($obj->datec);
1807 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1808 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1809 $this->cache_msgs_ticket[$i][
'private'] = ($obj->code ==
'TICKET_MSG_PRIVATE' ? 1 : 0);
1814 $this->error =
"Error ".$this->db->lasterror();
1815 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1829 global $conf, $langs;
1831 if ($this->fk_statut != Ticket::STATUS_CLOSED && $this->fk_statut != Ticket::STATUS_CANCELED) {
1834 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1835 $sql .=
" SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).
", progress=100, date_close='".$this->
db->idate(
dol_now()).
"'";
1836 $sql .=
" WHERE rowid = ".((int) $this->
id);
1838 dol_syslog(get_class($this).
"::close mode=".$mode);
1844 if (
isModEnabled(
'ficheinter') && !empty($conf->global->WORKFLOW_TICKET_CLOSE_INTERVENTION)) {
1845 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
1846 $this->fetchObjectLinked($this->
id, $this->element,
null,
'fichinter');
1847 if ($this->linkedObjectsIds) {
1848 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
1850 $fichinter->fetch($fichinter_id);
1851 if ($fichinter->statut == 0) {
1852 $result = $fichinter->setValid($user);
1854 $this->errors[] = $fichinter->error;
1858 if ($fichinter->statut < 3) {
1859 $result = $fichinter->setStatut(3);
1861 $this->errors[] = $fichinter->error;
1870 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
1877 $this->
db->commit();
1880 $this->
db->rollback();
1881 $this->error = join(
',', $this->errors);
1882 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1886 $this->
db->rollback();
1887 $this->error = $this->
db->lasterror();
1888 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1905 $thirdparties = array();
1909 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
1910 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
1911 if (!empty($type)) {
1912 if ($type == 1 || $type == 2) {
1913 $sql .=
" AND client = ".((int) $type);
1914 } elseif ($type == 3) {
1915 $sql .=
" AND fournisseur = 1";
1918 if (!empty($email)) {
1919 if (empty($exact)) {
1921 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1922 $email = str_replace(
'*',
'%', $email);
1924 $email =
'%'.$email.
'%';
1928 if (is_array($filters) && !empty($filters)) {
1932 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1934 if (is_array($filters) && !empty($filters)) {
1935 foreach ($filters as $field => $value) {
1936 $sql .=
" ".$clause.
" ".$field.
" LIKE '".$this->
db->escape($value).
"'";
1938 if (!empty($email)) {
1943 $res = $this->
db->query($sql);
1945 while ($rec = $this->
db->fetch_array($res)) {
1947 $soc->fetch($rec[
'rowid']);
1948 $thirdparties[] = $soc;
1951 return $thirdparties;
1953 $this->error = $this->
db->error().
' sql='.$sql;
1954 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
1969 $contacts = array();
1972 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
1973 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
1974 if (!empty($socid)) {
1975 $sql .=
" AND fk_soc='".$this->db->escape($socid).
"'";
1978 if (!empty($email)) {
1982 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1984 $sql .=
"email LIKE BINARY '".$this->db->escape($email).
"'";
1988 $res = $this->
db->query($sql);
1990 while ($rec = $this->
db->fetch_array($res)) {
1991 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1992 $contactstatic =
new Contact($this->
db);
1993 $contactstatic->fetch($rec[
'rowid']);
1994 $contacts[] = $contactstatic;
1999 $this->error = $this->
db->error().
' sql='.$sql;
2000 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
2014 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2015 $sql .=
" SET fk_soc = ".($id > 0 ? $id :
"null");
2016 $sql .=
" WHERE rowid = ".((int) $this->
id);
2017 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
2038 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2039 $sql .=
" SET progress = ".($percent > 0 ? $percent :
"null");
2040 $sql .=
" WHERE rowid = ".((int) $this->
id);
2041 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
2061 if (!$this->table_element) {
2062 dol_syslog(get_class($this).
"::setContract was called on objet with property table_element not defined", LOG_ERR);
2066 $result = $this->add_object_linked(
'contrat', $contractid);
2068 $this->fk_contract = $contractid;
2085 return $this->getIdContact(
'internal',
'SUPPORTTEC');
2095 return $this->listeContact(-1,
'internal');
2105 return $this->getIdContact(
'external',
'SUPPORTCLI');
2115 return $this->listeContact(-1,
'external');
2125 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2135 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2145 $array_contact = array();
2147 $array_contact = $this->getIdTicketInternalContact($exclude_self);
2149 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2151 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact($exclude_self));
2152 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2154 return $array_contact;
2164 $array_contact = array();
2166 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2167 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2169 return $array_contact;
2183 public function listeContact($status = -1, $source =
'external', $list = 0, $code =
'')
2189 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2190 if ($source ==
'internal') {
2191 $sql .=
", '-1' as socid, t.statut as statuscontact";
2194 if ($source ==
'external' || $source ==
'thirdparty') {
2195 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2198 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2199 if ($source ==
'internal') {
2200 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2203 if ($source ==
'external') {
2204 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2207 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2208 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2209 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2210 if ($source ==
'internal') {
2211 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2214 if ($source ==
'external' || $source ==
'thirdparty') {
2215 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2218 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2219 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2220 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2221 if ($source ==
'internal') {
2222 $sql .=
" AND tc.source = 'internal'";
2225 if ($source ==
'external' || $source ==
'thirdparty') {
2226 $sql .=
" AND tc.source = 'external'";
2229 if (!empty($code)) {
2230 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2233 $sql .=
" AND tc.active=1";
2235 $sql .=
" AND ec.statut = ".((int) $status);
2238 $sql .=
" ORDER BY t.lastname ASC";
2242 $num = $this->
db->num_rows(
$resql);
2245 $obj = $this->
db->fetch_object(
$resql);
2248 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2249 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2251 'source' => $obj->source,
2252 'socid' => $obj->socid,
2254 'nom' => $obj->lastname,
2255 'civility' => $obj->civility,
2256 'lastname' => $obj->lastname,
2257 'firstname' => $obj->firstname,
2258 'email' => $obj->email,
2259 'rowid' => $obj->rowid,
2260 'code' => $obj->code,
2261 'libelle' => $libelle_type,
2262 'status' => $obj->statuslink,
2263 'statuscontact'=>$obj->statuscontact,
2264 'fk_c_type_contact' => $obj->fk_c_type_contact,
2265 'phone' => $obj->phone,
2266 'phone_mobile' => $obj->phone_mobile);
2268 $tab[$i] = $obj->id;
2276 $this->error = $this->
db->error();
2293 $modele = empty($conf->global->TICKET_ADDON) ?
'mod_ticket_simple' : $conf->global->TICKET_ADDON;
2299 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2300 foreach ($dirmodels as $reldir) {
2301 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2302 if (file_exists($file)) {
2304 $classname = $modele;
2311 $modTicket =
new $classname;
2313 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2316 if (is_numeric($defaultref) && $defaultref <= 0) {
2334 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2342 if (file_exists($dir_osencoded)) {
2343 $handle = opendir($dir_osencoded);
2344 if (is_resource($handle)) {
2345 while (($file = readdir($handle)) !==
false) {
2347 $file = utf8_encode($file);
2372 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2373 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2374 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2376 $maxwidthsmall = 270;
2377 $maxheightsmall = 150;
2378 $maxwidthmini = 128;
2379 $maxheightmini = 72;
2382 $formmail->trackid = (is_null($forcetrackid) ?
'tic'.$this->id :
'');
2383 $attachedfiles = $formmail->get_attached_files();
2385 $filepath = $attachedfiles[
'paths'];
2386 $filename = $attachedfiles[
'names'];
2387 $mimetype = $attachedfiles[
'mimes'];
2390 $destdir = $conf->ticket->dir_output.
'/'.$this->ref;
2396 $listofpaths = array();
2397 $listofnames = array();
2398 foreach ($filename as $i => $val) {
2399 $destfile = $destdir.
'/'.$filename[$i];
2401 if (is_file($destfile)) {
2402 $pathinfo = pathinfo($filename[$i]);
2404 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2407 $res =
dol_move($filepath[$i], $destfile, 0, 1);
2412 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2415 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2418 $formmail->remove_attached_files($i);
2421 $listofpaths[$i] = $destfile;
2422 $listofnames[$i] = basename($destfile);
2425 return array(
'listofpaths'=>$listofpaths,
'listofnames'=>$listofnames,
'listofmimes'=>$mimetype);
2441 if (!is_array($categories)) {
2442 $categories = array($categories);
2446 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2448 $existing = $c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2451 if (is_array($existing)) {
2452 $to_del = array_diff($existing, $categories);
2453 $to_add = array_diff($categories, $existing);
2456 $to_add = $categories;
2460 foreach ($to_del as $del) {
2461 if ($c->fetch($del) > 0) {
2462 $c->del_type($this, Categorie::TYPE_TICKET);
2465 foreach ($to_add as $add) {
2466 if ($c->fetch($add) > 0) {
2467 $c->add_type($this, Categorie::TYPE_TICKET);
2483 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2485 global $mysoc, $conf, $langs;
2491 $ret = $object->fetch(
'',
'',
GETPOST(
'track_id',
'alpha'));
2493 $object->socid = $object->fk_soc;
2494 $object->fetch_thirdparty();
2498 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2504 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
2505 $action =
'add_message';
2509 $object->subject =
GETPOST(
'subject',
'alphanohtml');
2510 $object->message =
GETPOST(
"message",
"restricthtml");
2511 $object->private =
GETPOST(
"private_message",
"alpha");
2513 $send_email =
GETPOST(
'send_email',
'int');
2516 $resarray = $object->copyFilesForTicket();
2518 $listofpaths = $resarray[
'listofpaths'];
2519 $listofnames = $resarray[
'listofnames'];
2520 $listofmimes = $resarray[
'listofmimes'];
2522 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames);
2525 $this->error = $object->error;
2526 $this->errors = $object->errors;
2527 $action =
'add_message';
2530 if (!$error && $id > 0) {
2531 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'),
null,
'mesgs');
2539 if (!empty($public_area)) {
2543 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
2544 $assigned_user_dont_have_email =
'';
2546 if ($this->fk_user_assign > 0) {
2547 $assigned_user =
new User($this->
db);
2548 $assigned_user->fetch($this->fk_user_assign);
2549 if (!empty($assigned_user->email)) {
2550 $sendto[$assigned_user->email] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2552 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2555 if (empty($sendto)) {
2556 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
2557 $sendto[$conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
2558 } elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2559 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2564 if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
2565 !empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
2567 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2570 if (!empty($sendto)) {
2571 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2572 $subject =
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2575 $message = $langs->trans(
'TicketMessageMailIntroText');
2576 $message .=
'<br><br>';
2577 $messagePost =
GETPOST(
'message',
'restricthtml');
2581 $message .= $messagePost;
2584 $message .=
'<br><br>';
2585 $message .=
"==============================================";
2586 $message .= !empty($object->thirdparty->name) ?
'<br>'.$langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2587 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2588 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2591 $message .=
'<br><br>';
2592 if (!empty($assigned_user_dont_have_email)) {
2593 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2595 foreach ($sendto as $val) {
2596 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2600 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2601 $message .=
'<br><br>';
2602 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a>';
2604 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2614 if ($send_email > 0) {
2616 $internal_contacts = $object->getInfosTicketInternalContact();
2619 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2621 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2622 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2624 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".$object->id);
2625 $message_signature =
GETPOST(
'mail_signature') ?
GETPOST(
'mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2627 $message = $langs->trans(
'TicketMessageMailIntroText');
2628 $message .=
'<br><br>';
2629 $messagePost =
GETPOST(
'message',
'restricthtml');
2633 $message .= $messagePost;
2636 $message .=
'<br><br>';
2637 $message .=
"==============================================<br>";
2638 $message .= !empty($object->thirdparty->name) ? $langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2639 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2640 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2643 foreach ($internal_contacts as $key => $info_sendto) {
2645 if ($info_sendto[
'id'] == $user->id) {
2649 if ($info_sendto[
'email'] !=
'') {
2650 if (!empty($info_sendto[
'email'])) {
2651 $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_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2664 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a><br>';
2667 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2668 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2669 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2674 if (!empty($sendto)) {
2675 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2682 if (empty($object->private)) {
2684 $external_contacts = $object->getInfosTicketExternalContact();
2687 if (is_array($external_contacts) && count($external_contacts) === 0) {
2688 if (!empty($object->fk_soc)) {
2689 $object->fetch_thirdparty($object->fk_soc);
2690 $array_company = array(array(
'firstname' =>
'',
'lastname' => $object->thirdparty->name,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2691 $external_contacts = array_merge($external_contacts, $array_company);
2692 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2693 $array_external = array(array(
'firstname' =>
'',
'lastname' => $object->origin_email,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2694 $external_contacts = array_merge($external_contacts, $array_external);
2699 if (is_array($external_contacts) && count($external_contacts) > 0) {
2701 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2702 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2704 $message_intro =
GETPOST(
'mail_intro') ?
GETPOST(
'mail_intro',
'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
2705 $message_signature =
GETPOST(
'mail_signature') ?
GETPOST(
'mail_signature',
'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2707 $message_intro =
dol_nl2br($message_intro);
2710 $message_signature =
dol_nl2br($message_signature);
2714 $messagePost =
GETPOST(
'message',
'restricthtml');
2718 $message = $messagePost;
2719 $message .=
'<br><br>';
2721 foreach ($external_contacts as $key => $info_sendto) {
2723 if ($info_sendto[
'id'] == $user->contact_id) {
2727 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] != $object->origin_email) {
2728 if (!empty($info_sendto[
'email'])) {
2729 $sendto[$info_sendto[
'email']] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2732 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2733 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2738 $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
2739 (!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;
2740 $message .=
'<br>'.$langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$object->track_id.
'</a><br>';
2743 $message = $message_intro.
'<br><br>'.$message;
2746 $message .=
'<br>'.$message_signature;
2748 if (!empty($object->origin_email)) {
2749 $sendto[$object->origin_email] = $object->origin_email;
2752 if ($object->fk_soc > 0 && !array_key_exists($object->origin_email, $sendto)) {
2753 $object->socid = $object->fk_soc;
2754 $object->fetch_thirdparty();
2755 if (!empty($object->thirdparty->email)) {
2756 $sendto[$object->thirdparty->email] = $object->thirdparty->email;
2761 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2762 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2763 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2768 if (!empty($sendto)) {
2769 $result = $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2772 $this->date_last_msg_sent =
dol_now();
2773 $this->update($user);
2782 if ($object->status < 3 && !$user->socid) {
2783 $object->setStatut(3);
2809 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2811 global $conf, $langs;
2813 if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
2814 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2818 $langs->load(
"mails");
2820 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2824 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2825 $array_receiver = $this->getInfosTicketInternalContact();
2826 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact());
2829 if ($send_internal_cc) {
2830 $sendtocc = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2833 $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2835 if (is_array($array_receiver) && count($array_receiver) > 0) {
2836 foreach ($array_receiver as $key => $receiver) {
2837 $deliveryreceipt = 0;
2838 $filepath = $filename_list;
2839 $filename = $mimefilename_list;
2840 $mimetype = $mimetype_list;
2843 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2844 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
2845 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
2847 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2848 $trackid =
"tic".$this->id;
2849 $mailfile =
new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid,
'',
'ticket');
2850 if ($mailfile->error) {
2853 $result = $mailfile->sendfile();
2855 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)),
null,
'mesgs');
2858 $langs->load(
"other");
2859 if ($mailfile->error) {
2860 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver),
null,
'errors');
2861 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
2863 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'errors');
2867 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2868 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2872 $langs->load(
"other");
2873 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'),
null,
'warnings');
2889 global $conf, $user, $langs;
2894 $this->nbtodo = $this->nbtodolate = 0;
2897 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
2898 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2899 if (
isModEnabled(
'societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2900 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2901 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2904 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2905 if ($mode ==
'opened') {
2906 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
2909 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2914 $label = $labelShort =
'';
2916 if ($mode ==
'opened') {
2917 $status =
'openall';
2920 $label = $langs->trans(
"MenuListNonClosed");
2921 $labelShort = $langs->trans(
"MenuListNonClosed");
2926 $response->label = $label;
2927 $response->labelShort = $labelShort;
2928 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
2932 while ($obj = $this->
db->fetch_object(
$resql)) {
2933 $response->nbtodo++;
2934 if ($mode ==
'opened') {
2935 $datelimit = $this->
db->jdate($obj->datec) + $delay_warning;
2936 if ($datelimit < $now) {
2943 $this->error = $this->
db->lasterror();
2957 global $conf, $user;
2959 $this->nb = array();
2962 $sql =
"SELECT count(p.rowid) as nb";
2963 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2964 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2965 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2966 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2967 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2970 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2975 while ($obj = $this->
db->fetch_object(
$resql)) {
2976 $this->nb[
"ticket"] = $obj->nb;
2982 $this->error = $this->
db->lasterror();
2997 $tables = array(
'ticket');
3128 public $date_last_msg_sent =
'';