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();
430 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
433 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ticket(";
437 $sql .=
"fk_project,";
438 $sql .=
"origin_email,";
439 $sql .=
"fk_user_create,";
440 $sql .=
"fk_user_assign,";
441 $sql .=
"email_msgid,";
444 $sql .=
"fk_statut,";
445 $sql .=
"resolution,";
448 $sql .=
"type_code,";
449 $sql .=
"category_code,";
450 $sql .=
"severity_code,";
452 $sql .=
"date_read,";
453 $sql .=
"date_close,";
455 $sql .=
"notify_tiers_at_create";
456 $sql .=
") VALUES (";
457 $sql .=
" ".(!isset($this->
ref) ?
'' :
"'".$this->db->escape($this->
ref).
"'").
",";
458 $sql .=
" ".(!isset($this->track_id) ?
'NULL' :
"'".$this->db->escape($this->track_id).
"'").
",";
459 $sql .=
" ".($this->fk_soc > 0 ? $this->
db->escape($this->fk_soc) :
"null").
",";
460 $sql .=
" ".($this->fk_project > 0 ? $this->
db->escape($this->fk_project) :
"null").
",";
461 $sql .=
" ".(!isset($this->origin_email) ?
'NULL' :
"'".$this->db->escape($this->origin_email).
"'").
",";
462 $sql .=
" ".($this->fk_user_create > 0 ? $this->fk_user_create : ($user->id > 0 ? $user->id :
'NULL')).
",";
463 $sql .=
" ".($this->fk_user_assign > 0 ? $this->fk_user_assign :
'NULL').
",";
464 $sql .=
" ".(empty($this->email_msgid) ?
'NULL' :
"'".$this->db->escape($this->email_msgid).
"'").
",";
465 $sql .=
" ".(!isset($this->subject) ?
'NULL' :
"'".$this->db->escape($this->subject).
"'").
",";
466 $sql .=
" ".(!isset($this->message) ?
'NULL' :
"'".$this->db->escape($this->message).
"'").
",";
467 $sql .=
" ".(!isset($this->fk_statut) ?
'0' :
"'".$this->db->escape($this->fk_statut).
"'").
",";
468 $sql .=
" ".(!isset($this->resolution) ?
'NULL' :
"'".$this->db->escape($this->resolution).
"'").
",";
469 $sql .=
" ".(!isset($this->progress) ?
'0' :
"'".$this->db->escape($this->progress).
"'").
",";
470 $sql .=
" ".(!isset($this->timing) ?
'NULL' :
"'".$this->db->escape($this->timing).
"'").
",";
471 $sql .=
" ".(!isset($this->type_code) ?
'NULL' :
"'".$this->db->escape($this->type_code).
"'").
",";
472 $sql .=
" ".(empty($this->category_code) || $this->category_code ==
'-1' ?
'NULL' :
"'".$this->db->escape($this->category_code).
"'").
",";
473 $sql .=
" ".(!isset($this->severity_code) ?
'NULL' :
"'".$this->db->escape($this->severity_code).
"'").
",";
474 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
475 $sql .=
" ".(!isset($this->date_read) ||
dol_strlen($this->date_read) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_read).
"'").
",";
476 $sql .=
" ".(!isset($this->date_close) ||
dol_strlen($this->date_close) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_close).
"'").
"";
477 $sql .=
", ".((int) $this->entity);
478 $sql .=
", ".(!isset($this->notify_tiers_at_create) ?
'1' :
"'".$this->db->escape($this->notify_tiers_at_create).
"'");
483 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
487 $this->errors[] =
"Error ".$this->db->lasterror();
491 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"ticket");
494 if (!$error && ! empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) {
496 if ($this->
add_contact($user->id,
'CONTRIBUTOR',
'internal') < 0) {
501 if (!$error && $this->fk_user_assign > 0) {
502 if ($this->
add_contact($this->fk_user_assign,
'SUPPORTTEC',
'internal') < 0) {
516 if (!$error && !$notrigger) {
527 foreach ($this->errors as $errmsg) {
528 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
529 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
531 $this->
db->rollback();
538 $this->
db->rollback();
539 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
553 public function fetch($id =
'', $ref =
'', $track_id =
'', $email_msgid =
'')
558 if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
559 $this->error =
'ErrorWrongParameters';
566 $sql .=
" t.entity,";
568 $sql .=
" t.track_id,";
569 $sql .=
" t.fk_soc,";
570 $sql .=
" t.fk_project,";
571 $sql .=
" t.origin_email,";
572 $sql .=
" t.fk_user_create,";
573 $sql .=
" t.fk_user_assign,";
574 $sql .=
" t.email_msgid,";
575 $sql .=
" t.subject,";
576 $sql .=
" t.message,";
577 $sql .=
" t.fk_statut as status,";
578 $sql .=
" t.resolution,";
579 $sql .=
" t.progress,";
580 $sql .=
" t.timing,";
581 $sql .=
" t.type_code,";
582 $sql .=
" t.category_code,";
583 $sql .=
" t.severity_code,";
585 $sql .=
" t.date_read,";
586 $sql .=
" t.date_last_msg_sent,";
587 $sql .=
" t.date_close,";
589 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
590 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
591 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
592 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
593 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
596 $sql .=
" WHERE t.rowid = ".((int) $id);
598 $sql .=
" WHERE t.entity IN (".getEntity($this->element, 1).
")";
600 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
601 } elseif ($track_id) {
602 $sql .=
" AND t.track_id = '".$this->db->escape($track_id).
"'";
604 $sql .=
" AND t.email_msgid = '".$this->db->escape($email_msgid).
"'";
608 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
612 $obj = $this->
db->fetch_object(
$resql);
614 $this->
id = $obj->rowid;
615 $this->entity = $obj->entity;
616 $this->
ref = $obj->ref;
617 $this->track_id = $obj->track_id;
618 $this->fk_soc = $obj->fk_soc;
619 $this->socid = $obj->fk_soc;
620 $this->fk_project = $obj->fk_project;
621 $this->origin_email = $obj->origin_email;
622 $this->fk_user_create = $obj->fk_user_create;
623 $this->fk_user_assign = $obj->fk_user_assign;
624 $this->email_msgid = $obj->email_msgid;
625 $this->subject = $obj->subject;
626 $this->message = $obj->message;
628 $this->status = $obj->status;
629 $this->fk_statut = $this->status;
631 $this->resolution = $obj->resolution;
632 $this->progress = $obj->progress;
633 $this->timing = $obj->timing;
635 $this->type_code = $obj->type_code;
637 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
638 $this->type_label = $label_type;
640 $this->category_code = $obj->category_code;
642 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
643 $this->category_label = $label_category;
645 $this->severity_code = $obj->severity_code;
647 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
648 $this->severity_label = $label_severity;
650 $this->datec = $this->
db->jdate($obj->datec);
651 $this->date_creation = $this->
db->jdate($obj->datec);
652 $this->date_read = $this->
db->jdate($obj->date_read);
653 $this->date_validation = $this->
db->jdate($obj->date_read);
654 $this->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
655 $this->date_close = $this->
db->jdate($obj->date_close);
656 $this->tms = $this->
db->jdate($obj->tms);
657 $this->date_modification = $this->
db->jdate($obj->tms);
667 $this->error =
"Error ".$this->db->lasterror();
668 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
686 public function fetchAll($user, $sortorder =
'ASC', $sortfield =
't.datec', $limit =
'', $offset = 0, $arch =
'', $filter =
'')
693 $extrafields->fetch_name_optionals_label($this->table_element);
698 $sql .=
" t.track_id,";
699 $sql .=
" t.fk_soc,";
700 $sql .=
" t.fk_project,";
701 $sql .=
" t.origin_email,";
702 $sql .=
" t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
703 $sql .=
" t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
704 $sql .=
" t.subject,";
705 $sql .=
" t.message,";
706 $sql .=
" t.fk_statut,";
707 $sql .=
" t.resolution,";
708 $sql .=
" t.progress,";
709 $sql .=
" t.timing,";
710 $sql .=
" t.type_code,";
711 $sql .=
" t.category_code,";
712 $sql .=
" t.severity_code,";
714 $sql .=
" t.date_read,";
715 $sql .=
" t.date_last_msg_sent,";
716 $sql .=
" t.date_close,";
718 $sql .=
", type.label as type_label, category.label as category_label, severity.label as severity_label";
720 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
721 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
",ef.".$key.
" as options_".$key :
'');
723 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
724 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
725 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
726 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
727 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid=t.fk_soc";
728 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as uc ON uc.rowid=t.fk_user_create";
729 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as ua ON ua.rowid=t.fk_user_assign";
730 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
731 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ticket_extrafields as ef on (t.rowid = ef.fk_object)";
733 if (empty($user->rights->societe->client->voir) && !$user->socid) {
734 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
737 $sql .=
" WHERE t.entity IN (".getEntity(
'ticket').
")";
740 if (!empty($filter)) {
741 foreach ($filter as $key => $value) {
742 if (strpos($key,
'date')) {
743 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
744 } elseif (($key ==
't.fk_user_assign') || ($key ==
't.type_code') || ($key ==
't.category_code') || ($key ==
't.severity_code') || ($key ==
't.fk_soc')) {
745 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
746 } elseif ($key ==
't.fk_statut') {
747 if (is_array($value) && count($value) > 0) {
748 $sql .=
" AND ".$key.
" IN (".$this->
db->sanitize(implode(
',', $value)).
")";
750 $sql .=
" AND ".$key.
' = '.((int) $value);
753 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
757 if (empty($user->rights->societe->client->voir) && !$user->socid) {
758 $sql .=
" AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
759 } elseif ($user->socid) {
760 $sql .=
" AND t.fk_soc = ".((int) $user->socid);
763 $sql .= $this->
db->order($sortfield, $sortorder);
764 if (!empty($limit)) {
765 $sql .= $this->
db->plimit($limit + 1, $offset);
768 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
772 $this->lines = array();
779 $obj = $this->
db->fetch_object(
$resql);
783 $line->id = $obj->rowid;
784 $line->rowid = $obj->rowid;
785 $line->ref = $obj->ref;
786 $line->track_id = $obj->track_id;
787 $line->fk_soc = $obj->fk_soc;
788 $line->fk_project = $obj->fk_project;
789 $line->origin_email = $obj->origin_email;
791 $line->fk_user_create = $obj->fk_user_create;
792 $line->user_create_lastname = $obj->user_create_lastname;
793 $line->user_create_firstname = $obj->user_create_firstname;
795 $line->fk_user_assign = $obj->fk_user_assign;
796 $line->user_assign_lastname = $obj->user_assign_lastname;
797 $line->user_assign_firstname = $obj->user_assign_firstname;
799 $line->subject = $obj->subject;
800 $line->message = $obj->message;
801 $line->fk_statut = $obj->fk_statut;
802 $line->resolution = $obj->resolution;
803 $line->progress = $obj->progress;
804 $line->timing = $obj->timing;
807 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
808 $line->type_label = $label_type;
810 $this->category_code = $obj->category_code;
812 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
813 $line->category_label = $label_category;
815 $this->severity_code = $obj->severity_code;
817 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
818 $line->severity_label = $label_severity;
820 $line->datec = $this->
db->jdate($obj->datec);
821 $line->date_read = $this->
db->jdate($obj->date_read);
822 $line->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
823 $line->date_close = $this->
db->jdate($obj->date_close);
826 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
827 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
828 $tmpkey =
'options_'.$key;
829 $line->{$tmpkey} = $obj->$tmpkey;
833 $this->lines[$i] = $line;
840 $this->error =
"Error ".$this->db->lasterror();
841 dol_syslog(get_class($this).
"::fetchAll ".$this->error, LOG_ERR);
853 public function update($user = 0, $notrigger = 0)
855 global $conf, $langs, $hookmanager;
859 if (isset($this->
ref)) {
860 $this->
ref = trim($this->
ref);
863 if (isset($this->track_id)) {
864 $this->track_id = trim($this->track_id);
867 if (isset($this->fk_soc)) {
868 $this->fk_soc = (int) $this->fk_soc;
871 if (isset($this->fk_project)) {
872 $this->fk_project = (int) $this->fk_project;
875 if (isset($this->origin_email)) {
876 $this->origin_email = trim($this->origin_email);
879 if (isset($this->fk_user_create)) {
880 $this->fk_user_create = (int) $this->fk_user_create;
883 if (isset($this->fk_user_assign)) {
884 $this->fk_user_assign = (int) $this->fk_user_assign;
887 if (isset($this->subject)) {
888 $this->subject = trim($this->subject);
891 if (isset($this->message)) {
892 $this->message = trim($this->message);
895 if (isset($this->fk_statut)) {
896 $this->fk_statut = (int) $this->fk_statut;
899 if (isset($this->resolution)) {
900 $this->resolution = trim($this->resolution);
903 if (isset($this->progress)) {
904 $this->progress = trim($this->progress);
907 if (isset($this->timing)) {
908 $this->timing = trim($this->timing);
911 if (isset($this->type_code)) {
912 $this->timing = trim($this->type_code);
915 if (isset($this->category_code)) {
916 $this->timing = trim($this->category_code);
919 if (isset($this->severity_code)) {
920 $this->timing = trim($this->severity_code);
926 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket SET";
927 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"").
",";
928 $sql .=
" track_id=".(isset($this->track_id) ?
"'".$this->db->escape($this->track_id).
"'" :
"null").
",";
929 $sql .=
" fk_soc=".(isset($this->fk_soc) ?
"'".$this->db->escape($this->fk_soc).
"'" :
"null").
",";
930 $sql .=
" fk_project=".(isset($this->fk_project) ?
"'".$this->db->escape($this->fk_project).
"'" :
"null").
",";
931 $sql .=
" origin_email=".(isset($this->origin_email) ?
"'".$this->db->escape($this->origin_email).
"'" :
"null").
",";
932 $sql .=
" fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create :
"null").
",";
933 $sql .=
" fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign :
"null").
",";
934 $sql .=
" subject=".(isset($this->subject) ?
"'".$this->db->escape($this->subject).
"'" :
"null").
",";
935 $sql .=
" message=".(isset($this->message) ?
"'".$this->db->escape($this->message).
"'" :
"null").
",";
936 $sql .=
" fk_statut=".(isset($this->fk_statut) ? $this->fk_statut :
"null").
",";
937 $sql .=
" resolution=".(isset($this->resolution) ? $this->resolution :
"null").
",";
938 $sql .=
" progress=".(isset($this->progress) ?
"'".$this->db->escape($this->progress).
"'" :
"null").
",";
939 $sql .=
" timing=".(isset($this->timing) ?
"'".$this->db->escape($this->timing).
"'" :
"null").
",";
940 $sql .=
" type_code=".(isset($this->type_code) ?
"'".$this->db->escape($this->type_code).
"'" :
"null").
",";
941 $sql .=
" category_code=".(isset($this->category_code) ?
"'".$this->db->escape($this->category_code).
"'" :
"null").
",";
942 $sql .=
" severity_code=".(isset($this->severity_code) ?
"'".$this->db->escape($this->severity_code).
"'" :
"null").
",";
943 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
944 $sql .=
" date_read=".(dol_strlen($this->date_read) != 0 ?
"'".$this->db->idate($this->date_read).
"'" :
'null').
",";
945 $sql .=
" date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ?
"'".$this->db->idate($this->date_last_msg_sent).
"'" :
'null').
",";
946 $sql .=
" date_close=".(dol_strlen($this->date_close) != 0 ?
"'".$this->db->idate($this->date_close).
"'" :
'null').
"";
947 $sql .=
" WHERE rowid=".((int) $this->
id);
954 $this->errors[] =
"Error ".$this->db->lasterror();
959 $result = $this->insertExtraFields();
965 if (!$error && !$notrigger) {
967 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
976 foreach ($this->errors as $errmsg) {
977 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
978 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
980 $this->
db->rollback();
995 public function delete($user, $notrigger = 0)
997 global $conf, $langs;
1005 $result = $this->call_trigger(
'TICKET_DELETE', $user);
1015 $res = $this->delete_linked_contact();
1017 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1024 $res = $this->deleteObjectLinked();
1032 $result = $this->deleteExtraFields();
1035 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1042 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_ticket";
1043 $sql .=
" WHERE fk_ticket = ".(int) $this->
id;
1045 $result = $this->
db->query($sql);
1048 $this->errors[] = $this->
db->lasterror();
1053 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ticket";
1054 $sql .=
" WHERE rowid=".((int) $this->
id);
1056 dol_syslog(get_class($this).
"::delete sql=".$sql);
1060 $this->errors[] =
"Error ".$this->db->lasterror();
1066 foreach ($this->errors as $errmsg) {
1067 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1068 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1070 $this->
db->rollback();
1073 $this->
db->commit();
1094 $object->fetch($fromid);
1096 $object->statut = 0;
1101 $object->context[
'createfromclone'] =
'createfromclone';
1102 $result = $object->create($user);
1106 $this->error = $object->error;
1113 unset($object->context[
'createfromclone']);
1117 $this->
db->commit();
1120 $this->
db->rollback();
1135 $this->
ref =
'TI0501-001';
1136 $this->track_id =
'XXXXaaaa';
1137 $this->origin_email =
'email@email.com';
1138 $this->fk_project = 1;
1139 $this->fk_user_create = 1;
1140 $this->fk_user_assign = 1;
1141 $this->subject =
'Subject of ticket';
1142 $this->message =
'Message of ticket';
1144 $this->resolution =
'1';
1145 $this->progress =
'10';
1147 $this->type_code =
'TYPECODE';
1148 $this->category_code =
'CATEGORYCODE';
1149 $this->severity_code =
'SEVERITYCODE';
1151 $this->date_read =
'';
1152 $this->date_last_msg_sent =
'';
1153 $this->date_close =
'';
1166 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 =
'');
1179 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1184 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1185 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type";
1186 $sql .=
" WHERE active > 0";
1187 $sql .=
" ORDER BY pos";
1188 dol_syslog(get_class($this).
"::load_cache_type_tickets", LOG_DEBUG);
1191 $num = $this->
db->num_rows(
$resql);
1194 $obj = $this->
db->fetch_object(
$resql);
1196 $label = ($langs->trans(
"TicketTypeShort".$obj->code) != (
"TicketTypeShort".$obj->code) ? $langs->trans(
"TicketTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1197 $this->cache_types_tickets[$obj->rowid][
'code'] = $obj->code;
1198 $this->cache_types_tickets[$obj->rowid][
'label'] = $label;
1199 $this->cache_types_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1200 $this->cache_types_tickets[$obj->rowid][
'pos'] = $obj->pos;
1217 global $conf, $langs;
1219 if (!empty($this->cache_category_ticket) && count($this->cache_category_tickets)) {
1224 $sql =
"SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category";
1226 $sql .=
" WHERE active > 0 AND entity = ".((int) $conf->entity);
1227 $sql .=
" ORDER BY pos";
1228 dol_syslog(get_class($this).
"::load_cache_categories_tickets", LOG_DEBUG);
1231 $num = $this->
db->num_rows(
$resql);
1234 $obj = $this->
db->fetch_object(
$resql);
1235 $this->cache_category_tickets[$obj->rowid][
'code'] = $obj->code;
1236 $this->cache_category_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1237 $this->cache_category_tickets[$obj->rowid][
'pos'] = $obj->pos;
1238 $this->cache_category_tickets[$obj->rowid][
'public'] = $obj->public;
1239 $this->cache_category_tickets[$obj->rowid][
'active'] = $obj->active;
1240 $this->cache_category_tickets[$obj->rowid][
'force_severity'] = $obj->force_severity;
1241 $this->cache_category_tickets[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1245 $label = ($langs->trans(
"TicketCategoryShort".$obj->code) != (
"TicketCategoryShort".$obj->code) ? $langs->trans(
"TicketCategoryShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1246 $this->cache_category_tickets[$obj->rowid][
'label'] = $label;
1266 if (!empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) {
1271 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity";
1273 $sql .=
" WHERE active > 0";
1274 $sql .=
" ORDER BY pos";
1275 dol_syslog(get_class($this).
"::loadCacheSeveritiesTickets", LOG_DEBUG);
1278 $num = $this->
db->num_rows(
$resql);
1281 $obj = $this->
db->fetch_object(
$resql);
1283 $this->cache_severity_tickets[$obj->rowid][
'code'] = $obj->code;
1285 $label = ($langs->trans(
"TicketSeverityShort".$obj->code) != (
"TicketSeverityShort".$obj->code) ? $langs->trans(
"TicketSeverityShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1286 $this->cache_severity_tickets[$obj->rowid][
'label'] = $label;
1287 $this->cache_severity_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1288 $this->cache_severity_tickets[$obj->rowid][
'pos'] = $obj->pos;
1307 return $this->libStatut($this->fk_statut, $mode, 0, $this->progress);
1321 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1324 global $langs, $hookmanager;
1326 $labelStatus = $this->statuts[$status];
1327 $labelStatusShort = $this->statuts_short[$status];
1329 if ($status == self::STATUS_NOT_READ) {
1330 $statusType =
'status0';
1331 } elseif ($status == self::STATUS_READ) {
1332 $statusType =
'status1';
1333 } elseif ($status == self::STATUS_ASSIGNED) {
1334 $statusType =
'status2';
1335 } elseif ($status == self::STATUS_IN_PROGRESS) {
1336 $statusType =
'status4';
1337 } elseif ($status == self::STATUS_WAITING) {
1338 $statusType =
'status7';
1339 } elseif ($status == self::STATUS_NEED_MORE_INFO) {
1340 $statusType =
'status3';
1341 } elseif ($status == self::STATUS_CANCELED) {
1342 $statusType =
'status9';
1343 } elseif ($status == self::STATUS_CLOSED) {
1344 $statusType =
'status6';
1346 $labelStatus =
'Unknown';
1347 $labelStatusShort =
'Unknown';
1348 $statusType =
'status0';
1352 $parameters = array(
1353 'status' => $status,
1358 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1361 return $hookmanager->resPrint;
1366 $params = array(
'tooltip' =>
'no');
1369 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1370 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1372 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1373 $labelStatus .=
' ('.round($progress).
'%)';
1374 $labelStatusShort .=
' ('.round($progress).
'%)';
1377 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1391 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1393 global $db, $conf, $langs;
1394 global $dolibarr_main_authentication, $dolibarr_main_demo;
1395 global $menumanager;
1397 if (!empty($conf->dol_no_mouse_hover)) {
1403 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1404 $label .=
' '.$this->getLibStatut(4);
1406 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
1407 $label .=
'<b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id.
'<br>';
1408 $label .=
'<b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1409 if ($this->date_creation) {
1410 $label .=
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.$this->date_creation;
1412 if ($this->date_modification) {
1413 $label .=
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.$this->date_modification;
1415 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.$this->id;
1417 if ($option !=
'nolink') {
1419 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1420 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1421 $add_save_lastsearch_values = 1;
1423 if ($add_save_lastsearch_values) {
1424 $url .=
'&save_lastsearch_values=1';
1429 if (empty($notooltip)) {
1430 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1431 $label = $langs->trans(
"ShowTicket");
1432 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1434 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1435 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1437 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1440 $linkstart =
'<a href="'.$url.
'"';
1441 $linkstart .= $linkclose.
'>';
1444 $result .= $linkstart;
1446 $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);
1448 if ($withpicto != 2) {
1449 $result .= $this->ref;
1451 $result .= $linkend;
1467 global $conf, $langs;
1471 if ($this->statut != self::STATUS_CANCELED) {
1474 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1475 $sql .=
" SET fk_statut = ".Ticket::STATUS_READ.
", date_read='".$this->
db->idate(
dol_now()).
"'";
1476 $sql .=
" WHERE rowid = ".((int) $this->
id);
1481 $this->actionmsg = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1482 $this->actionmsg2 = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1484 if (!$error && !$notrigger) {
1486 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1494 $this->
db->commit();
1497 $this->
db->rollback();
1498 $this->error = join(
',', $this->errors);
1499 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1503 $this->
db->rollback();
1504 $this->error = $this->
db->lasterror();
1505 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1519 public function assignUser($user, $id_assign_user, $notrigger = 0)
1521 global $conf, $langs;
1528 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1529 if ($id_assign_user > 0) {
1530 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1532 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1534 $sql .=
" WHERE rowid = ".((int) $this->
id);
1536 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1539 $this->fk_user_assign = $id_assign_user;
1543 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1551 $this->
db->commit();
1554 $this->
db->rollback();
1555 $this->error = join(
',', $this->errors);
1556 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1560 $this->
db->rollback();
1561 $this->error = $this->
db->lasterror();
1562 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1577 global $conf, $langs;
1581 $langs->load(
'ticket');
1584 $contacts = $this->listeContact(-1,
'internal');
1585 $contacts = array_merge($contacts, $this->listeContact(-1,
'external'));
1588 if (!empty($this->origin_email) && empty($this->fk_soc)) {
1589 $array_ext = array(array(
'firstname' =>
'',
'lastname' =>
'',
'email' => $this->origin_email,
'libelle' => $langs->transnoentities(
'TicketEmailOriginIssuer'),
'socid' =>
"-1"));
1590 $contacts = array_merge($contacts, $array_ext);
1593 if (!empty($this->fk_soc)) {
1594 $this->fetch_thirdparty($this->fk_soc);
1595 $array_company = array(array(
'firstname' =>
'',
'lastname' => $this->client->name,
'email' => $this->client->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $this->client->id));
1596 $contacts = array_merge($contacts, $array_company);
1600 if (count($contacts) > 0) {
1601 foreach ($contacts as $key => $info_sendto) {
1603 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNotificationEmailSubject', $this->track_id);
1604 $message .= $langs->transnoentities(
'TicketNotificationEmailBody', $this->track_id).
"\n\n";
1605 $message .= $langs->transnoentities(
'Title').
' : '.$this->subject.
"\n";
1607 $recipient_name =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1');
1608 $recipient = (!empty($recipient_name) ? $recipient_name : $info_sendto[
'email']).
' ('.strtolower($info_sendto[
'libelle']).
')';
1609 $message .= $langs->transnoentities(
'TicketNotificationRecipient').
' : '.$recipient.
"\n";
1611 $message .=
'* '.$langs->transnoentities(
'TicketNotificationLogMessage').
' *'.
"\n";
1614 if ($info_sendto[
'source'] ==
'internal') {
1615 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$this->track_id;
1616 $message .=
"\n".$langs->transnoentities(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$this->track_id.
'</a>'.
"\n";
1618 $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;
1619 $message .=
"\n".$langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$this->track_id.
'</a>'.
"\n";
1623 $message .= $langs->transnoentities(
'TicketEmailPleaseDoNotReplyToThisEmail').
"\n";
1625 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
1629 $filepath = array();
1630 $filename = array();
1631 $mimetype = array();
1635 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1636 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
1637 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
1639 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1641 $deliveryreceipt = 0;
1642 $mailfile =
new CMailFile($subject, $info_sendto[
'email'], $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, 0);
1643 if ($mailfile->error || $mailfile->errors) {
1646 $result = $mailfile->sendfile();
1651 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1652 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
1656 setEventMessages($langs->trans(
'TicketNotificationNumberEmailSent', $nb_sent),
null,
'mesgs');
1671 if (is_array($this->cache_logs_ticket) && count($this->cache_logs_ticket)) {
1715 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
1717 global $conf, $langs;
1723 if (isset($this->fk_track_id)) {
1724 $this->fk_track_id = trim($this->fk_track_id);
1727 if (isset($this->message)) {
1728 $this->message = trim($this->message);
1734 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1736 $actioncomm->type_code =
'AC_OTH';
1737 $actioncomm->code =
'TICKET_MSG';
1738 if ($this->
private) {
1739 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1741 $actioncomm->socid = $this->socid;
1742 $actioncomm->label = $this->subject;
1743 $actioncomm->note_private = $this->message;
1744 $actioncomm->userassigned = array($user->id);
1745 $actioncomm->userownerid = $user->id;
1746 $actioncomm->datep = $now;
1747 $actioncomm->percentage = -1;
1748 $actioncomm->elementtype =
'ticket';
1749 $actioncomm->fk_element = $this->id;
1751 $attachedfiles = array();
1752 $attachedfiles[
'paths'] = $filename_list;
1753 $attachedfiles[
'names'] = $mimefilename_list;
1754 $attachedfiles[
'mimes'] = $mimetype_list;
1755 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1756 $actioncomm->attachedfiles = $attachedfiles;
1759 if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1760 $actioncomm->note_private =
dol_concatdesc($actioncomm->note_private,
"\n".$langs->transnoentities(
"AttachedFiles").
': '.join(
';', $mimefilename_list));
1763 $actionid = $actioncomm->create($user);
1764 if ($actionid <= 0) {
1766 $this->error = $actioncomm->error;
1767 $this->errors = $actioncomm->errors;
1772 $this->
db->rollback();
1775 $this->
db->commit();
1787 if (is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1793 $sql =
"SELECT id as rowid, fk_user_author, datec, datep, label, note as message, code";
1794 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1795 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1796 $sql .=
" AND elementtype = 'ticket'";
1797 $sql .=
" ORDER BY datep DESC";
1799 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1802 $num = $this->
db->num_rows(
$resql);
1805 $obj = $this->
db->fetch_object(
$resql);
1806 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1807 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1808 $this->cache_msgs_ticket[$i][
'datec'] = $this->
db->jdate($obj->datec);
1809 $this->cache_msgs_ticket[$i][
'datep'] = $this->
db->jdate($obj->datep);
1810 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1811 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1812 $this->cache_msgs_ticket[$i][
'private'] = ($obj->code ==
'TICKET_MSG_PRIVATE' ? 1 : 0);
1817 $this->error =
"Error ".$this->db->lasterror();
1818 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1832 global $conf, $langs;
1834 if ($this->fk_statut != Ticket::STATUS_CLOSED && $this->fk_statut != Ticket::STATUS_CANCELED) {
1837 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1838 $sql .=
" SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).
", progress=100, date_close='".$this->
db->idate(
dol_now()).
"'";
1839 $sql .=
" WHERE rowid = ".((int) $this->
id);
1841 dol_syslog(get_class($this).
"::close mode=".$mode);
1847 if (
isModEnabled(
'ficheinter') && !empty($conf->global->WORKFLOW_TICKET_CLOSE_INTERVENTION)) {
1848 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
1849 $this->fetchObjectLinked($this->
id, $this->element,
null,
'fichinter');
1850 if ($this->linkedObjectsIds) {
1851 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
1853 $fichinter->fetch($fichinter_id);
1854 if ($fichinter->statut == 0) {
1855 $result = $fichinter->setValid($user);
1857 $this->errors[] = $fichinter->error;
1861 if ($fichinter->statut < 3) {
1862 $result = $fichinter->setStatut(3);
1864 $this->errors[] = $fichinter->error;
1873 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
1880 $this->
db->commit();
1883 $this->
db->rollback();
1884 $this->error = join(
',', $this->errors);
1885 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1889 $this->
db->rollback();
1890 $this->error = $this->
db->lasterror();
1891 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1908 $thirdparties = array();
1912 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
1913 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
1914 if (!empty($type)) {
1915 if ($type == 1 || $type == 2) {
1916 $sql .=
" AND client = ".((int) $type);
1917 } elseif ($type == 3) {
1918 $sql .=
" AND fournisseur = 1";
1921 if (!empty($email)) {
1922 if (empty($exact)) {
1924 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1925 $email = str_replace(
'*',
'%', $email);
1927 $email =
'%'.$email.
'%';
1931 if (is_array($filters) && !empty($filters)) {
1935 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1937 if (is_array($filters) && !empty($filters)) {
1938 foreach ($filters as $field => $value) {
1939 $sql .=
" ".$clause.
" ".$field.
" LIKE '".$this->
db->escape($value).
"'";
1941 if (!empty($email)) {
1946 $res = $this->
db->query($sql);
1948 while ($rec = $this->
db->fetch_array($res)) {
1950 $soc->fetch($rec[
'rowid']);
1951 $thirdparties[] = $soc;
1954 return $thirdparties;
1956 $this->error = $this->
db->error().
' sql='.$sql;
1957 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
1972 $contacts = array();
1975 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
1976 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
1977 if (!empty($socid)) {
1978 $sql .=
" AND fk_soc='".$this->db->escape($socid).
"'";
1981 if (!empty($email)) {
1985 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1987 $sql .=
"email LIKE BINARY '".$this->db->escape($email).
"'";
1991 $res = $this->
db->query($sql);
1993 while ($rec = $this->
db->fetch_array($res)) {
1994 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1995 $contactstatic =
new Contact($this->
db);
1996 $contactstatic->fetch($rec[
'rowid']);
1997 $contacts[] = $contactstatic;
2002 $this->error = $this->
db->error().
' sql='.$sql;
2003 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
2017 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2018 $sql .=
" SET fk_soc = ".($id > 0 ? $id :
"null");
2019 $sql .=
" WHERE rowid = ".((int) $this->
id);
2020 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
2041 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2042 $sql .=
" SET progress = ".($percent > 0 ? $percent :
"null");
2043 $sql .=
" WHERE rowid = ".((int) $this->
id);
2044 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
2064 if (!$this->table_element) {
2065 dol_syslog(get_class($this).
"::setContract was called on objet with property table_element not defined", LOG_ERR);
2069 $result = $this->add_object_linked(
'contrat', $contractid);
2071 $this->fk_contract = $contractid;
2088 return $this->getIdContact(
'internal',
'SUPPORTTEC');
2098 return $this->listeContact(-1,
'internal');
2108 return $this->getIdContact(
'external',
'SUPPORTCLI');
2118 return $this->listeContact(-1,
'external');
2128 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2138 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2148 $array_contact = array();
2150 $array_contact = $this->getIdTicketInternalContact($exclude_self);
2152 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2154 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact($exclude_self));
2155 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2157 return $array_contact;
2167 $array_contact = array();
2169 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2170 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2172 return $array_contact;
2186 public function listeContact($status = -1, $source =
'external', $list = 0, $code =
'')
2192 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2193 if ($source ==
'internal') {
2194 $sql .=
", '-1' as socid, t.statut as statuscontact";
2197 if ($source ==
'external' || $source ==
'thirdparty') {
2198 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2201 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2202 if ($source ==
'internal') {
2203 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2206 if ($source ==
'external') {
2207 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2210 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2211 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2212 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2213 if ($source ==
'internal') {
2214 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2217 if ($source ==
'external' || $source ==
'thirdparty') {
2218 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2221 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2222 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2223 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2224 if ($source ==
'internal') {
2225 $sql .=
" AND tc.source = 'internal'";
2228 if ($source ==
'external' || $source ==
'thirdparty') {
2229 $sql .=
" AND tc.source = 'external'";
2232 if (!empty($code)) {
2233 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2236 $sql .=
" AND tc.active=1";
2238 $sql .=
" AND ec.statut = ".((int) $status);
2241 $sql .=
" ORDER BY t.lastname ASC";
2245 $num = $this->
db->num_rows(
$resql);
2248 $obj = $this->
db->fetch_object(
$resql);
2251 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2252 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2254 'source' => $obj->source,
2255 'socid' => $obj->socid,
2257 'nom' => $obj->lastname,
2258 'civility' => $obj->civility,
2259 'lastname' => $obj->lastname,
2260 'firstname' => $obj->firstname,
2261 'email' => $obj->email,
2262 'rowid' => $obj->rowid,
2263 'code' => $obj->code,
2264 'libelle' => $libelle_type,
2265 'status' => $obj->statuslink,
2266 'statuscontact'=>$obj->statuscontact,
2267 'fk_c_type_contact' => $obj->fk_c_type_contact,
2268 'phone' => $obj->phone,
2269 'phone_mobile' => $obj->phone_mobile);
2271 $tab[$i] = $obj->id;
2279 $this->error = $this->
db->error();
2296 $modele = empty($conf->global->TICKET_ADDON) ?
'mod_ticket_simple' : $conf->global->TICKET_ADDON;
2302 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2303 foreach ($dirmodels as $reldir) {
2304 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2305 if (file_exists($file)) {
2307 $classname = $modele;
2314 $modTicket =
new $classname;
2316 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2319 if (is_numeric($defaultref) && $defaultref <= 0) {
2337 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2345 if (file_exists($dir_osencoded)) {
2346 $handle = opendir($dir_osencoded);
2347 if (is_resource($handle)) {
2348 while (($file = readdir($handle)) !==
false) {
2350 $file = utf8_encode($file);
2375 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2376 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2377 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2379 $maxwidthsmall = 270;
2380 $maxheightsmall = 150;
2381 $maxwidthmini = 128;
2382 $maxheightmini = 72;
2385 $formmail->trackid = (is_null($forcetrackid) ?
'tic'.$this->id :
'');
2386 $attachedfiles = $formmail->get_attached_files();
2388 $filepath = $attachedfiles[
'paths'];
2389 $filename = $attachedfiles[
'names'];
2390 $mimetype = $attachedfiles[
'mimes'];
2393 $destdir = $conf->ticket->dir_output.
'/'.$this->ref;
2399 $listofpaths = array();
2400 $listofnames = array();
2401 foreach ($filename as $i => $val) {
2402 $destfile = $destdir.
'/'.$filename[$i];
2404 if (is_file($destfile)) {
2405 $pathinfo = pathinfo($filename[$i]);
2407 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2410 $res =
dol_move($filepath[$i], $destfile, 0, 1);
2415 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2418 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2421 $formmail->remove_attached_files($i);
2424 $listofpaths[$i] = $destfile;
2425 $listofnames[$i] = basename($destfile);
2428 return array(
'listofpaths'=>$listofpaths,
'listofnames'=>$listofnames,
'listofmimes'=>$mimetype);
2444 if (!is_array($categories)) {
2445 $categories = array($categories);
2449 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2451 $existing = $c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2454 if (is_array($existing)) {
2455 $to_del = array_diff($existing, $categories);
2456 $to_add = array_diff($categories, $existing);
2459 $to_add = $categories;
2463 foreach ($to_del as $del) {
2464 if ($c->fetch($del) > 0) {
2465 $c->del_type($this, Categorie::TYPE_TICKET);
2468 foreach ($to_add as $add) {
2469 if ($c->fetch($add) > 0) {
2470 $c->add_type($this, Categorie::TYPE_TICKET);
2486 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2488 global $mysoc, $conf, $langs;
2494 $ret = $object->fetch(
'',
'',
GETPOST(
'track_id',
'alpha'));
2496 $object->socid = $object->fk_soc;
2497 $object->fetch_thirdparty();
2501 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2507 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
2508 $action =
'add_message';
2512 $object->subject =
GETPOST(
'subject',
'alphanohtml');
2513 $object->message =
GETPOST(
"message",
"restricthtml");
2514 $object->private =
GETPOST(
"private_message",
"alpha");
2516 $send_email =
GETPOST(
'send_email',
'int');
2519 $resarray = $object->copyFilesForTicket();
2521 $listofpaths = $resarray[
'listofpaths'];
2522 $listofnames = $resarray[
'listofnames'];
2523 $listofmimes = $resarray[
'listofmimes'];
2525 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames);
2528 $this->error = $object->error;
2529 $this->errors = $object->errors;
2530 $action =
'add_message';
2533 if (!$error && $id > 0) {
2534 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'),
null,
'mesgs');
2542 if (!empty($public_area)) {
2546 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
2547 $assigned_user_dont_have_email =
'';
2549 if ($this->fk_user_assign > 0) {
2550 $assigned_user =
new User($this->
db);
2551 $assigned_user->fetch($this->fk_user_assign);
2552 if (!empty($assigned_user->email)) {
2553 $sendto[$assigned_user->email] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2555 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2558 if (empty($sendto)) {
2559 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
2560 $sendto[$conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
2561 } elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2562 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2567 if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
2568 !empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
2570 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2573 if (!empty($sendto)) {
2574 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2575 $subject =
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2578 $message = $langs->trans(
'TicketMessageMailIntroText');
2579 $message .=
'<br><br>';
2580 $messagePost =
GETPOST(
'message',
'restricthtml');
2584 $message .= $messagePost;
2587 $message .=
'<br><br>';
2588 $message .=
"==============================================";
2589 $message .= !empty($object->thirdparty->name) ?
'<br>'.$langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2590 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2591 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2594 $message .=
'<br><br>';
2595 if (!empty($assigned_user_dont_have_email)) {
2596 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2598 foreach ($sendto as $val) {
2599 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2603 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2604 $message .=
'<br><br>';
2605 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a>';
2607 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2617 if ($send_email > 0) {
2619 $internal_contacts = $object->getInfosTicketInternalContact();
2622 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2624 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2625 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2627 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".$object->id);
2628 $message_signature =
GETPOST(
'mail_signature') ?
GETPOST(
'mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2630 $message = $langs->trans(
'TicketMessageMailIntroText');
2631 $message .=
'<br><br>';
2632 $messagePost =
GETPOST(
'message',
'restricthtml');
2636 $message .= $messagePost;
2639 $message .=
'<br><br>';
2640 $message .=
"==============================================<br>";
2641 $message .= !empty($object->thirdparty->name) ? $langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2642 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2643 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2646 foreach ($internal_contacts as $key => $info_sendto) {
2648 if ($info_sendto[
'id'] == $user->id) {
2652 if ($info_sendto[
'email'] !=
'') {
2653 if (!empty($info_sendto[
'email'])) {
2654 $sendto[$info_sendto[
'email']] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2658 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2659 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2664 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2667 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a><br>';
2670 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2671 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2672 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2677 if (!empty($sendto)) {
2678 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2685 if (empty($object->private)) {
2687 $external_contacts = $object->getInfosTicketExternalContact();
2690 if (is_array($external_contacts) && count($external_contacts) === 0) {
2691 if (!empty($object->fk_soc)) {
2692 $object->fetch_thirdparty($object->fk_soc);
2693 $array_company = array(array(
'firstname' =>
'',
'lastname' => $object->thirdparty->name,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2694 $external_contacts = array_merge($external_contacts, $array_company);
2695 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2696 $array_external = array(array(
'firstname' =>
'',
'lastname' => $object->origin_email,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2697 $external_contacts = array_merge($external_contacts, $array_external);
2702 if (is_array($external_contacts) && count($external_contacts) > 0) {
2704 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2705 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2707 $message_intro =
GETPOST(
'mail_intro') ?
GETPOST(
'mail_intro',
'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
2708 $message_signature =
GETPOST(
'mail_signature') ?
GETPOST(
'mail_signature',
'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2710 $message_intro =
dol_nl2br($message_intro);
2713 $message_signature =
dol_nl2br($message_signature);
2717 $messagePost =
GETPOST(
'message',
'restricthtml');
2721 $message = $messagePost;
2722 $message .=
'<br><br>';
2724 foreach ($external_contacts as $key => $info_sendto) {
2726 if ($info_sendto[
'id'] == $user->contact_id) {
2730 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] != $object->origin_email) {
2731 if (!empty($info_sendto[
'email'])) {
2732 $sendto[$info_sendto[
'email']] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2735 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2736 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2741 $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
2742 (!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;
2743 $message .=
'<br>'.$langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$object->track_id.
'</a><br>';
2746 $message = $message_intro.
'<br><br>'.$message;
2749 $message .=
'<br>'.$message_signature;
2751 if (!empty($object->origin_email)) {
2752 $sendto[$object->origin_email] = $object->origin_email;
2755 if ($object->fk_soc > 0 && !array_key_exists($object->origin_email, $sendto)) {
2756 $object->socid = $object->fk_soc;
2757 $object->fetch_thirdparty();
2758 if (!empty($object->thirdparty->email)) {
2759 $sendto[$object->thirdparty->email] = $object->thirdparty->email;
2764 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2765 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2766 $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2771 if (!empty($sendto)) {
2772 $result = $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2775 $this->date_last_msg_sent =
dol_now();
2776 $this->update($user);
2785 if ($object->status < 3 && !$user->socid) {
2786 $object->setStatut(3);
2812 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2814 global $conf, $langs;
2816 if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
2817 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2821 $langs->load(
"mails");
2823 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2827 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2828 $array_receiver = $this->getInfosTicketInternalContact();
2829 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact());
2832 if ($send_internal_cc) {
2833 $sendtocc = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2836 $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2838 if (is_array($array_receiver) && count($array_receiver) > 0) {
2839 foreach ($array_receiver as $key => $receiver) {
2840 $deliveryreceipt = 0;
2841 $filepath = $filename_list;
2842 $filename = $mimefilename_list;
2843 $mimetype = $mimetype_list;
2846 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2847 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
2848 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
2850 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2851 $trackid =
"tic".$this->id;
2852 $mailfile =
new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid,
'',
'ticket');
2853 if ($mailfile->error) {
2856 $result = $mailfile->sendfile();
2858 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)),
null,
'mesgs');
2861 $langs->load(
"other");
2862 if ($mailfile->error) {
2863 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver),
null,
'errors');
2864 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
2866 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'errors');
2870 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2871 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2875 $langs->load(
"other");
2876 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'),
null,
'warnings');
2892 global $conf, $user, $langs;
2897 $this->nbtodo = $this->nbtodolate = 0;
2900 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
2901 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2902 if (
isModEnabled(
'societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2903 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2904 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2907 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2908 if ($mode ==
'opened') {
2909 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
2912 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2917 $label = $labelShort =
'';
2919 if ($mode ==
'opened') {
2920 $status =
'openall';
2923 $label = $langs->trans(
"MenuListNonClosed");
2924 $labelShort = $langs->trans(
"MenuListNonClosed");
2929 $response->label = $label;
2930 $response->labelShort = $labelShort;
2931 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
2935 while ($obj = $this->
db->fetch_object(
$resql)) {
2936 $response->nbtodo++;
2937 if ($mode ==
'opened') {
2938 $datelimit = $this->
db->jdate($obj->datec) + $delay_warning;
2939 if ($datelimit < $now) {
2946 $this->error = $this->
db->lasterror();
2960 global $conf, $user;
2962 $this->nb = array();
2965 $sql =
"SELECT count(p.rowid) as nb";
2966 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2967 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2968 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2969 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2970 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2973 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2978 while ($obj = $this->
db->fetch_object(
$resql)) {
2979 $this->nb[
"ticket"] = $obj->nb;
2985 $this->error = $this->
db->lasterror();
3000 $tables = array(
'ticket');
3131 public $date_last_msg_sent =
'';