diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 5768a0e5ba6..ccf5c9de6b2 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1139,7 +1139,7 @@ class FormFile } print '
'; - print ''."\n"; + print '
'."\n"; if (! empty($addfilterfields)) { @@ -1156,10 +1156,10 @@ class FormFile print ''; //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder; - print_liste_field_titre('Documents2', $url, "name", "", $param, '', $sortfield, $sortorder, ' left'); - print_liste_field_titre('Size', $url, "size", "", $param, '', $sortfield, $sortorder, ' right'); - print_liste_field_titre('Date', $url, "date", "", $param, '', $sortfield, $sortorder, ' center'); - if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) print_liste_field_titre('', $url, "", "", $param, '', $sortfield, $sortorder, ' center'); // Preview + print_liste_field_titre('Documents2', $url, "name", "", $param, '', $sortfield, $sortorder, 'left '); + print_liste_field_titre('Size', $url, "size", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre('Date', $url, "date", "", $param, '', $sortfield, $sortorder, 'center '); + if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) print_liste_field_titre('', $url, "", "", $param, '', $sortfield, $sortorder, 'center '); // Preview print_liste_field_titre(''); print_liste_field_titre(''); if (! $disablemove) print_liste_field_titre(''); @@ -1734,7 +1734,7 @@ class FormFile print ''; - print '
'; + print '
'; print ''; print_liste_field_titre( $langs->trans("Links"), @@ -1742,9 +1742,10 @@ class FormFile "name", "", $param, - 'class="left"', + '', $sortfield, - $sortorder + $sortorder, + '' ); print_liste_field_titre( "", @@ -1752,7 +1753,10 @@ class FormFile "", "", "", - 'class="right"' + '', + '', + '', + 'right ' ); print_liste_field_titre( $langs->trans("Date"), @@ -1760,9 +1764,10 @@ class FormFile "date", "", $param, - 'class="center"', + '', $sortfield, - $sortorder + $sortorder, + 'center ' ); print_liste_field_titre( '', @@ -1770,7 +1775,10 @@ class FormFile "", "", $param, - 'class="center"' + '', + '', + '', + 'center ' ); print_liste_field_titre('', '', ''); print ''; diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 9e7f18957f7..59996942cd3 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -167,6 +167,85 @@ class FormTicket print ''; } + // TITLE + if ($this->withemail) { + print ''; + } + + // Si origin du ticket + if (isset($this->param['origin']) && $this->param['originid'] > 0) { + // Parse element/subelement (ex: project_task) + $element = $subelement = $this->param['origin']; + if (preg_match('/^([^_]+)_([^_]+)/i', $this->param['origin'], $regs)) { + $element = $regs[1]; + $subelement = $regs[2]; + } + + dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); + $classname = ucfirst($subelement); + $objectsrc = new $classname($this->db); + $objectsrc->fetch(GETPOST('originid', 'int')); + + if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) { + $objectsrc->fetch_lines(); + } + + $objectsrc->fetch_thirdparty(); + $newclassname = $classname; + print ''; + } + + // Type + print ''; + + // Severity + print ''; + + // Group + print ''; + + // Subject + if ($this->withtitletopic) { + print ''; + } else { + if ($this->withthreadid > 0) { + $subject = $langs->trans('SubjectAnswerToTicket') . ' ' . $this->withthreadid . ' : ' . $this->topic_title . ''; + } + print ''; + print ''; + } + } + + // MESSAGE + $msg = GETPOSTISSET('message') ? GETPOST('message', 'none') : ''; + print ''; + // FK_USER_CREATE if ($this->withusercreate > 0 && $this->fk_user_create) { print ''; - } - - // Si origin du ticket - if (isset($this->param['origin']) && $this->param['originid'] > 0) { - // Parse element/subelement (ex: project_task) - $element = $subelement = $this->param['origin']; - if (preg_match('/^([^_]+)_([^_]+)/i', $this->param['origin'], $regs)) { - $element = $regs[1]; - $subelement = $regs[2]; - } - - dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); - $classname = ucfirst($subelement); - $objectsrc = new $classname($this->db); - $objectsrc->fetch(GETPOST('originid', 'int')); - - if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) { - $objectsrc->fetch_lines(); - } - - $objectsrc->fetch_thirdparty(); - $newclassname = $classname; - print ''; - } - - // Type - print ''; - - // Severity - print ''; - - // Group - print ''; - - // TITLE - if ($this->withtitletopic) { - print ''; - } else { - if ($this->withthreadid > 0) { - $subject = $langs->trans('SubjectAnswerToTicket') . ' ' . $this->withthreadid . ' : ' . $this->topic_title . ''; - } - print ''; - print ''; - } - } - - // MESSAGE - $msg = GETPOSTISSET('message') ? GETPOST('message', 'none') : ''; - print ''; - if (! empty($conf->projet->enabled) && ! $this->ispublic) { $formproject=new FormProjets($this->db); @@ -831,7 +831,8 @@ class FormTicket print '
' . $langs->trans("Ref") . '
'; + print ''; + print '
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
'; + $this->selectTypesTickets((GETPOST('type_code') ? GETPOST('type_code') : $this->type_code), 'type_code', '', '2'); + print '
'; + $this->selectSeveritiesTickets((GETPOST('severity_code') ? GETPOST('severity_code') : $this->severity_code), 'severity_code', '', '2'); + print '
'; + $this->selectGroupTickets((GETPOST('category_code') ? GETPOST('category_code') : $this->category_code), 'category_code', '', '2'); + print '
'; + + // Réponse à un ticket : affichage du titre du thread en readonly + if ($this->withtopicreadonly) { + print $langs->trans('SubjectAnswerToTicket') . ' ' . $this->topic_title; + print '
'; + + // If public form, display more information + $toolbarname = 'dolibarr_notes'; + if ($this->ispublic) + { + $toolbarname = 'dolibarr_details'; + print '
' . ($conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE ? $conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE : $langs->trans('TicketPublicPleaseBeAccuratelyDescribe')) . '
'; + } + include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; + $uselocalbrowser = true; + $doleditor = new DolEditor('message', $msg, '100%', 230, $toolbarname, 'In', true, $uselocalbrowser); + $doleditor->Create(); + print '
' . $langs->trans("CreatedBy") . ''; @@ -269,85 +348,6 @@ class FormTicket } } - // TITLE - if ($this->withemail) { - print '
'; - print ''; - print '
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
'; - $this->selectTypesTickets((GETPOST('type_code') ? GETPOST('type_code') : $this->type_code), 'type_code', '', '2'); - print '
'; - $this->selectSeveritiesTickets((GETPOST('severity_code') ? GETPOST('severity_code') : $this->severity_code), 'severity_code', '', '2'); - print '
'; - $this->selectGroupTickets((GETPOST('category_code') ? GETPOST('category_code') : $this->category_code), 'category_code', '', '2'); - print '
'; - - // Réponse à un ticket : affichage du titre du thread en readonly - if ($this->withtopicreadonly) { - print $langs->trans('SubjectAnswerToTicket') . ' ' . $this->topic_title; - print '
'; - - // If public form, display more information - $toolbarname = 'dolibarr_notes'; - if ($this->ispublic) - { - $toolbarname = 'dolibarr_details'; - print '
' . ($conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE ? $conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE : $langs->trans('TicketPublicPleaseBeAccuratelyDescribe')) . '
'; - } - include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; - $uselocalbrowser = true; - $doleditor = new DolEditor('message', $msg, '100%', 230, $toolbarname, 'In', true, $uselocalbrowser); - $doleditor->Create(); - print '
'; // External users can't send message email - if ($user->rights->ticket->write && !$user->socid) { + if ($user->rights->ticket->write && !$user->socid) + { print '
'; $checkbox_selected = ( GETPOST('send_email') == "1" ? ' checked' : ''); print ' '; diff --git a/htdocs/core/lib/ticket.lib.php b/htdocs/core/lib/ticket.lib.php index 406f53c4762..bd449cc91e9 100644 --- a/htdocs/core/lib/ticket.lib.php +++ b/htdocs/core/lib/ticket.lib.php @@ -81,7 +81,6 @@ function ticket_prepare_head($object) $head[$h][2] = 'tabTicket'; $h++; - if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && empty($user->socid)) { $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); @@ -96,9 +95,9 @@ function ticket_prepare_head($object) // Attached files include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $upload_dir = $conf->ticket->dir_output . "/" . $object->track_id; + $upload_dir = $conf->ticket->dir_output . "/" . $object->ref; $nbFiles = count(dol_dir_list($upload_dir, 'files')); - $head[$h][0] = dol_buildpath('/ticket/document.php', 1) . '?track_id=' . $object->track_id; + $head[$h][0] = dol_buildpath('/ticket/document.php', 1) . '?id=' . $object->id; $head[$h][1] = $langs->trans("Documents"); if ($nbFiles > 0) { $head[$h][1] .= ' ' . $nbFiles . ''; diff --git a/htdocs/core/tpl/contacts.tpl.php b/htdocs/core/tpl/contacts.tpl.php index e3060f34bde..316e85a3ac6 100644 --- a/htdocs/core/tpl/contacts.tpl.php +++ b/htdocs/core/tpl/contacts.tpl.php @@ -63,7 +63,7 @@ $userstatic=new User($db);
-
+
); border-top-style: solid; } -/*.liste_titre_create td.nobottom, tr#trlinefordates td { - background-color: rgb() !important; -}*/ tr#trlinefordates td { border-bottom: 0px !important; } @@ -2932,6 +2929,9 @@ form.pair, form.impair { form.tagtr:last-of-type div.tagtd, tr.pair:last-of-type td, tr.impair:last-of-type td { border-bottom: 0px !important; } +div.tableforcontact form.tagtr:last-of-type div.tagtd { + border-bottom: 1px solid #ddd !important; +} tr.pair td .nobordernopadding tr td, tr.impair td .nobordernopadding tr td { border-bottom: 0px !important; } @@ -2939,6 +2939,9 @@ table.nobottomiftotal tr.liste_total td { background-color: #fff; border-bottom: 0px !important; } +table.nobottom { + border-bottom: 0px !important; +} div.liste_titre .tagtd { vertical-align: middle; } diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index fd434ef395f..5aa09bee982 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -123,8 +123,428 @@ if ($cancel) $action='view'; } -// Do action -$actionobject->doActions($action, $object); +if (GETPOST('add', 'alpha') && $user->rights->ticket->write) { + $error = 0; + + if (!GETPOST("subject", 'alpha')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")), null, 'errors'); + $action = 'create'; + } elseif (!GETPOST("message", 'alpha')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors'); + $action = 'create'; + } + + if (!$error) { + $db->begin(); + + $object->ref = GETPOST("ref", 'alpha'); + $object->fk_soc = GETPOST("socid", 'int') > 0 ? GETPOST("socid", 'int') : 0; + $object->subject = GETPOST("subject", 'alpha'); + $object->message = GETPOST("message", 'none'); + + $object->type_code = GETPOST("type_code", 'alpha'); + $object->category_code = GETPOST("category_code", 'alpha'); + $object->severity_code = GETPOST("severity_code", 'alpha'); + $notifyTiers = GETPOST("notify_tiers_at_create", 'alpha'); + $object->notify_tiers_at_create = empty($notifyTiers) ? 0 : 1; + + $object->fk_project = GETPOST('projectid', 'int'); + + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + + $id = $object->create($user); + if ($id <= 0) { + $error++; + setEventMessage($object->error, $object->errors, 'errors'); + $action = 'create'; + } + + if (! $error) + { + // Add contact + $contactid = GETPOST('contactid', 'int'); + $type_contact = GETPOST("type", 'alpha'); + + if ($contactid > 0 && $type_contact) { + $result = $object->add_contact($contactid, GETPOST("type"), 'external'); + } + + // altairis: link ticket to project + if (GETPOST('projectid') > 0) { + $object->setProject(GETPOST('projectid')); + } + + // Auto assign user + if ($conf->global->TICKET_AUTO_ASSIGN_USER_CREATE) { + $result = $object->assignUser($user, $user->id, 1); + $object->add_contact($user->id, "SUPPORTTEC", 'internal'); + } + + // Auto assign contrat + $contractid = 0; + if ($conf->global->TICKET_AUTO_ASSIGN_CONTRACT_CREATE) { + $contrat = new Contrat($db); + $contrat->socid = $object->fk_soc; + $list = $contrat->getListOfContracts(); + + if (is_array($list) && !empty($list)) { + if (count($list) == 1) { + $contractid = $list[0]->id; + $object->setContract($contractid); + } else { + } + } + } + + // Auto create fiche intervention + if ($conf->global->TICKET_AUTO_CREATE_FICHINTER_CREATE) + { + $fichinter = new Fichinter($db); + $fichinter->socid = $object->fk_soc; + $fichinter->fk_project = GETPOST('projectid', 'int'); + $fichinter->fk_contrat = $contractid; + $fichinter->author = $user->id; + $fichinter->modelpdf = 'soleil'; + $fichinter->origin = $object->element; + $fichinter->origin_id = $object->id; + + // Extrafields + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($fichinter->table_element); + $array_options = $extrafields->getOptionalsFromPost($fichinter->table_element); + $fichinter->array_options = $array_options; + + $id = $fichinter->create($user); + if ($id <= 0) { + setEventMessages($fichinter->error, null, 'errors'); + } + } + } + + if (! $error) + { + // File transfer + $object->copyFilesForTicket(); + } + + if (! $error) + { + $db->commit(); + + if (!empty($backtopage)) { + $url = $backtopage; + } else { + $url = 'card.php?track_id=' . $object->track_id; + } + + header("Location: " . $url); + exit; + } else { + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +if ($action == 'edit' && $user->rights->ticket->write) { + $error = 0; + + if ($object->fetch(GETPOST('id')) < 0) { + $error++; + array_push($object->errors, $langs->trans("ErrorTicketIsNotValid")); + $_GET["action"] = $_POST["action"] = ''; + } +} + +if (GETPOST('update') && GETPOST('id') && $user->rights->ticket->write) { + $error = 0; + + $ret = $object->fetch(GETPOST('id')); + if ($ret < 0) { + $error++; + array_push($object->errors, $langs->trans("ErrorTicketIsNotValid")); + $action = ''; + } elseif (!GETPOST("label")) { + $error++; + array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"))); + $action = 'edit'; + } elseif (!GETPOST("subject")) { + $error++; + array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject"))); + $action = 'edit'; + } + + if (!$error) { + $db->begin(); + + $object->label = GETPOST("label"); + $object->description = GETPOST("description"); + + //... + $ret = $object->update($user); + if ($ret <= 0) { + $error++; + setEventMessage($object->error, $object->errors, 'errors'); + $action = 'edit'; + } + + if (!$error && $ret > 0) { + $db->commit(); + } else { + $db->rollback(); + } + } +} + +if ($action == "mark_ticket_read" && $user->rights->ticket->write) { + $object->fetch('', '', GETPOST("track_id", 'alpha')); + + if ($object->markAsRead($user) > 0) + { + setEventMessages($langs->trans('TicketMarkedAsRead'), null, 'mesgs'); + + header("Location: card.php?track_id=" . $object->track_id . "&action=view"); + exit; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + $action = 'view'; +} + +if ($action == "assign_user" && GETPOST('btn_assign_user', 'aplha') && $user->rights->ticket->write) { + $object->fetch('', '', GETPOST("track_id", 'alpha')); + $useroriginassign = $object->fk_user_assign; + $usertoassign = GETPOST('fk_user_assign', 'int'); + + /*if (! ($usertoassign > 0)) { + $error++; + array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("AssignedTo"))); + $action = 'view'; + }*/ + + if (!$error) + { + $ret = $object->assignUser($user, $usertoassign); + if ($ret < 0) $error++; + } + + if (! $error) // Update list of contacts + { + // Si déjà un user assigné on le supprime des contacts + if ($useroriginassign > 0) { + $internal_contacts = $object->listeContact(-1, 'internal'); + + foreach ($internal_contacts as $key => $contact) { + if ($contact['code'] == "SUPPORTTEC" && $contact['id'] == $useroriginassign) { + } + { + //print "user à effacer : ".$useroriginassign; + $object->delete_contact($contact['rowid']); + } + } + } + + if ($usertoassign > 0) $object->add_contact($usertoassign, "SUPPORTTEC", 'internal', $notrigger = 0); + } + + if (! $error) + { + // Log action in ticket logs table + $object->fetch_user($usertoassign); + $log_action = $langs->trans('TicketLogAssignedTo', $object->user->getFullName($langs)); + + setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs'); + + header("Location: card.php?track_id=" . $object->track_id . "&action=view"); + exit; + } else { + array_push($object->errors, $object->error); + } + $action = 'view'; +} + +if ($action == "new_message" && GETPOST('btn_add_message') && $user->rights->ticket->read) { + $ret = $object->newMessage($user, $action); + if ($ret) { + if (!empty($backtopage)) { + $url = $backtopage; + } else { + $url = 'card.php?action=view&track_id=' . $object->track_id; + } + + header("Location: " . $url); + exit; + } else { + setEventMessages($object->error, null, 'errors'); + $action = 'add_message'; + } +} + +if ($action == "new_public_message" && GETPOST('btn_add_message')) { + $object->newMessagePublic($user, $action); +} + +if ($action == "confirm_close" && GETPOST('confirm', 'alpha') == 'yes' && $user->rights->ticket->write) { + $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); + if ($object->close()) { + // Log action in ticket logs table + $log_action = $langs->trans('TicketLogClosedBy', $user->getFullName($langs)); + + setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs'); + + $url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha'); + header("Location: " . $url); + } else { + $action = ''; + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes') { + $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); + if (($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) && $object->close()) { + // Log action in ticket logs table + $log_action = $langs->trans('TicketLogClosedBy', $_SESSION['email_customer']); + + setEventMessages('
' . $langs->trans('TicketMarkedAsClosed') . '
', null, 'mesgs'); + + $url = 'view.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha'); + header("Location: " . $url); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } +} + +if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $user->rights->ticket->delete) { + if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { + if ($object->delete($user) > 0) { + setEventMessages('
' . $langs->trans('TicketDeletedSuccess') . '
', null, 'mesgs'); + Header("Location: ".DOL_URL_ROOT."/ticket/list.php"); + exit; + } else { + $langs->load("errors"); + $mesg = '
' . $langs->trans($object->error) . '
'; + $action = ''; + } + } +} + +// Set parent company +if ($action == 'set_thirdparty' && $user->rights->societe->creer) { + if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { + $result = $object->setCustomer(GETPOST('editcustomer', 'int')); + $url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha'); + header("Location: " . $url); + exit(); + } +} + +if ($action == 'set_progression' && $user->rights->ticket->write) { + if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { + $result = $object->setProgression(GETPOST('progress', 'alpha')); + + $url = 'card.php?action=view&track_id=' . $object->track_id; + header("Location: " . $url); + exit(); + } +} + +if ($action == 'setsubject') { + if ($object->fetch(GETPOST('id', 'int'))) { + if ($action == 'setsubject') { + $object->subject = trim(GETPOST('subject', 'alpha')); + } + + if ($action == 'setsubject' && empty($object->subject)) { + $mesg .= ($mesg ? '
' : '') . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")); + } + + if (!$mesg) { + if ($object->update($user) >= 0) { + header("Location: " . $_SERVER['PHP_SELF'] . "?track_id=" . $object->track_id); + exit; + } + $mesg = $object->error; + } + } +} + + +if ($action == 'confirm_reopen' && $user->rights->ticket->manage && !GETPOST('cancel')) { + if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { + // prevent browser refresh from reopening ticket several times + if ($object->fk_statut == Ticket::STATUS_CLOSED) { + $res = $object->setStatut(Ticket::STATUS_ASSIGNED); + if ($res) { + // Log action in ticket logs table + $log_action = $langs->trans('TicketLogReopen'); + + $url = 'card.php?action=view&track_id=' . $object->track_id; + header("Location: " . $url); + exit(); + } + } + } +} // Categorisation dans projet +elseif ($action == 'classin' && $user->rights->ticket->write) { + if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { + $object->setProject(GETPOST('projectid', 'int')); + $url = 'card.php?action=view&track_id=' . $object->track_id; + header("Location: " . $url); + exit(); + } +} // Categorisation dans contrat +elseif ($action == 'setcontract' && $user->rights->ticket->write) { + if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { + $object->setContract(GETPOST('contractid', 'int')); + $url = 'card.php?action=view&track_id=' . $object->track_id; + header("Location: " . $url); + exit(); + } +} elseif ($action == "set_message" && $user->rights->ticket->manage) { + // altairis: manage cancel button + if (!GETPOST('cancel')) { + $object->fetch('', '', GETPOST('track_id', 'alpha')); + $oldvalue_message = $object->message; + $fieldtomodify = GETPOST('message_initial'); + + $object->message = $fieldtomodify; + $ret = $object->update($user); + if ($ret > 0) { + $log_action = $langs->trans('TicketInitialMessageModified') . " \n"; + // include the Diff class + dol_include_once('/ticket/class/utils_diff.class.php'); + // output the result of comparing two files as plain text + $log_action .= Diff::toString(Diff::compare(strip_tags($oldvalue_message), strip_tags($object->message))); + + setEventMessages($langs->trans('TicketMessageSuccesfullyUpdated'), null, 'mesgs'); + } + } + + $action = 'view'; +} // Reopen ticket +elseif ($action == 'confirm_set_status' && $user->rights->ticket->write && !GETPOST('cancel')) { + if ($object->fetch(GETPOST('id', 'int'), GETPOST('track_id', 'alpha')) >= 0) { + $new_status = GETPOST('new_status', 'int'); + $old_status = $object->fk_statut; + $res = $object->setStatut($new_status); + if ($res) { + // Log action in ticket logs table + $log_action = $langs->trans('TicketLogStatusChanged', $langs->transnoentities($object->statuts_short[$old_status]), $langs->transnoentities($object->statuts_short[$new_status])); + + $url = 'card.php?action=view&track_id=' . $object->track_id; + header("Location: " . $url); + exit(); + } + } +} // Action to update one extrafield if ($action == "update_extras" && ! empty($permissiontoadd)) @@ -164,9 +584,21 @@ if ($action == "change_property" && GETPOST('btn_update_ticket_prop', 'alpha') & $action = 'view'; } + $permissiondellink = $user->rights->ticket->write; include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once +// Actions to build doc +$upload_dir = $conf->ticket->dir_output; +$permissioncreate = $user->rights->ticket->write; +include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + +// Actions to send emails +$trigger_name='TICKET_SENTBYMAIL'; +$paramname='id'; +$autocopy='MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add +$trackid='tic'.$object->id; +include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; @@ -184,7 +616,7 @@ $page_title = $actionobject->getTitle($action); llxHeader('', $page_title, $help_url); -if ($action == 'create') +if ($action == 'create' || $action == 'presend') { $formticket = new FormTicket($db); diff --git a/htdocs/ticket/class/actions_ticket.class.php b/htdocs/ticket/class/actions_ticket.class.php index f978642311c..f84426c03f9 100644 --- a/htdocs/ticket/class/actions_ticket.class.php +++ b/htdocs/ticket/class/actions_ticket.class.php @@ -102,849 +102,6 @@ class ActionsTicket } } - /** - * doActions - * - * @param string $action Action type - * @param Ticket $object Object Ticket - * @return int 0 - */ - public function doActions(&$action = '', Ticket $object = null) - { - global $conf, $user, $langs, $mysoc; - - /* - * Add file in email form - */ - if (GETPOST('addfile', 'alpha')) { - // altairis : allow files from public interface - if (GETPOST('track_id', 'alpha')) { - $res = $object->fetch('', '', GETPOST('track_id', 'alpha')); - } - - ////if($res > 0) - ////{ - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - - // Set tmp directory TODO Use a dedicated directory for temp mails files - $vardir = $conf->ticket->dir_output . (!empty($object->track_id) ? '/' . dol_sanitizeFileName($object->track_id) : ''); - $upload_dir_tmp = $vardir . '/temp'; - if (!dol_is_dir($upload_dir_tmp)) { - dol_mkdir($upload_dir_tmp); - } - dol_add_file_process($upload_dir_tmp, 0, 0, 'addedfile', dol_print_date(dol_now(), '%Y%m%d%H%M%S') . '-__file__'); - $action = !empty($object->track_id) ? 'add_message' : 'create'; - ////} - } - - /* - * Remove file in email form - */ - if (GETPOST('removedfile', 'alpha')) { - // altairis : allow files from public interface - if (GETPOST('track_id')) { - $res = $object->fetch('', '', GETPOST('track_id', 'alpha')); - } - - ////if($res > 0) - ////{ - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - - // Set tmp directory - $vardir = $conf->ticket->dir_output . (!empty($object->track_id) ? '/' . dol_sanitizeFileName($object->track_id) : ''); - $upload_dir_tmp = $vardir . '/temp'; - - // TODO Delete only files that was uploaded from email form - dol_remove_file_process($_POST['removedfile'], 0); - $action = !empty($object->track_id) ? 'add_message' : 'create'; - ////} - } - - if (GETPOST('add', 'alpha') && $user->rights->ticket->write) { - $error = 0; - - if (!GETPOST("subject")) { - $error++; - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")); - $action = 'create'; - } elseif (!GETPOST("message")) { - $error++; - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("message")); - $action = 'create'; - } - - if (!$error) { - $this->db->begin(); - - $object->track_id = generate_random_id(16); - - $object->ref = GETPOST("ref", 'alpha'); - $object->fk_soc = GETPOST("socid", 'int') > 0 ? GETPOST("socid", 'int') : 0; - $object->subject = GETPOST("subject", 'alpha'); - $object->message = GETPOST("message"); - - $object->type_code = GETPOST("type_code", 'alpha'); - $object->category_code = GETPOST("category_code", 'alpha'); - $object->severity_code = GETPOST("severity_code", 'alpha'); - $notifyTiers = GETPOST("notify_tiers_at_create", 'alpha'); - $object->notify_tiers_at_create = empty($notifyTiers) ? 0 : 1; - - $object->fk_project = GETPOST('projectid', 'int'); - - $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - - $id = $object->create($user); - if ($id <= 0) { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - $action = 'create'; - } - - if (!$error && $id > 0) - { - $this->db->commit(); - - // File transfer - $this->copyFilesForTicket(); - - // Add contact - $contactid = GETPOST('contactid', 'int'); - $type_contact = GETPOST("type", 'alpha'); - - if ($contactid > 0 && $type_contact) { - $result = $object->add_contact($contactid, GETPOST("type"), 'external'); - } - - // altairis: link ticket to project - if (GETPOST('projectid') > 0) { - $object->setProject(GETPOST('projectid')); - } - - // Auto assign user - if ($conf->global->TICKET_AUTO_ASSIGN_USER_CREATE) { - $result = $object->assignUser($user, $user->id, 1); - $object->add_contact($user->id, "SUPPORTTEC", 'internal'); - } - - // Auto assign contrat - $contractid = 0; - if ($conf->global->TICKET_AUTO_ASSIGN_CONTRACT_CREATE) { - $contrat = new Contrat($this->db); - $contrat->socid = $object->fk_soc; - $list = $contrat->getListOfContracts(); - - if (is_array($list) && !empty($list)) { - if (count($list) == 1) { - $contractid = $list[0]->id; - $object->setContract($contractid); - } else { - } - } - } - - // Auto create fiche intervention - if ($conf->global->TICKET_AUTO_CREATE_FICHINTER_CREATE) - { - $fichinter = new Fichinter($this->db); - $fichinter->socid = $object->fk_soc; - $fichinter->fk_project = GETPOST('projectid', 'int'); - $fichinter->fk_contrat = $contractid; - $fichinter->author = $user->id; - $fichinter->modelpdf = 'soleil'; - $fichinter->origin = $object->element; - $fichinter->origin_id = $object->id; - - // Extrafields - $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($fichinter->table_element); - $array_options = $extrafields->getOptionalsFromPost($fichinter->table_element); - $fichinter->array_options = $array_options; - - $id = $fichinter->create($user); - if ($id <= 0) { - setEventMessages($fichinter->error, null, 'errors'); - } - } - - if (!empty($backtopage)) { - $url = $backtopage; - } else { - $url = 'card.php?track_id=' . $object->track_id; - } - - header("Location: " . $url); - exit; - } else { - $this->db->rollback(); - setEventMessages($this->error, $this->errors, 'errors'); - } - } else { - setEventMessages($this->error, $this->errors, 'errors'); - } - } - - if ($action == 'edit' && $user->rights->ticket->write) { - $error = 0; - - if ($object->fetch(GETPOST('id')) < 0) { - $error++; - array_push($this->errors, $langs->trans("ErrorTicketIsNotValid")); - $_GET["action"] = $_POST["action"] = ''; - } - } - - if (GETPOST('update') && GETPOST('id') && $user->rights->ticket->write) { - $error = 0; - - $ret = $object->fetch(GETPOST('id')); - if ($ret < 0) { - $error++; - array_push($this->errors, $langs->trans("ErrorTicketIsNotValid")); - $action = ''; - } elseif (!GETPOST("label")) { - $error++; - array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"))); - $action = 'edit'; - } elseif (!GETPOST("subject")) { - $error++; - array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject"))); - $action = 'edit'; - } - - if (!$error) { - $this->db->begin(); - - $object->label = GETPOST("label"); - $object->description = GETPOST("description"); - - //... - $ret = $object->update($user); - if ($ret <= 0) { - $error++; - $this->errors = $object->error; - $this->errors = $object->errors; - $action = 'edit'; - } - - if (!$error && $ret > 0) { - $this->db->commit(); - } else { - $this->db->rollback(); - } - } - } - - if ($action == "mark_ticket_read" && $user->rights->ticket->write) { - $object->fetch('', '', GETPOST("track_id", 'alpha')); - - if ($object->markAsRead($user) > 0) - { - setEventMessages($langs->trans('TicketMarkedAsRead'), null, 'mesgs'); - - header("Location: card.php?track_id=" . $object->track_id . "&action=view"); - exit; - } else { - $this->errors = $object->error; - $this->error = $object->error; - } - $action = 'view'; - } - - if ($action == "assign_user" && GETPOST('btn_assign_user', 'aplha') && $user->rights->ticket->write) { - $object->fetch('', '', GETPOST("track_id", 'alpha')); - $useroriginassign = $object->fk_user_assign; - $usertoassign = GETPOST('fk_user_assign', 'int'); - - /*if (! ($usertoassign > 0)) { - $error++; - array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("AssignedTo"))); - $action = 'view'; - }*/ - - if (!$error) - { - $ret = $object->assignUser($user, $usertoassign); - if ($ret < 0) $error++; - } - - if (! $error) // Update list of contacts - { - // Si déjà un user assigné on le supprime des contacts - if ($useroriginassign > 0) { - $internal_contacts = $object->listeContact(-1, 'internal'); - - foreach ($internal_contacts as $key => $contact) { - if ($contact['code'] == "SUPPORTTEC" && $contact['id'] == $useroriginassign) { - } - { - //print "user à effacer : ".$useroriginassign; - $object->delete_contact($contact['rowid']); - } - } - } - - if ($usertoassign > 0) $object->add_contact($usertoassign, "SUPPORTTEC", 'internal', $notrigger = 0); - } - - if (! $error) - { - // Log action in ticket logs table - $object->fetch_user($usertoassign); - $log_action = $langs->trans('TicketLogAssignedTo', $object->user->getFullName($langs)); - - setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs'); - - header("Location: card.php?track_id=" . $object->track_id . "&action=view"); - exit; - } else { - array_push($this->errors, $object->error); - } - $action = 'view'; - } - - if ($action == "new_message" && GETPOST('btn_add_message') && $user->rights->ticket->read) { - $ret = $this->newMessage($user, $action); - if ($ret) { - if (!empty($backtopage)) { - $url = $backtopage; - } else { - $url = 'card.php?action=view&track_id=' . $object->track_id; - } - - header("Location: " . $url); - exit; - } else { - setEventMessages($object->error, null, 'errors'); - $action = 'add_message'; - } - } - - if ($action == "new_public_message" && GETPOST('btn_add_message')) { - $this->newMessagePublic($user, $action); - } - - if ($action == "confirm_close" && GETPOST('confirm', 'alpha') == 'yes' && $user->rights->ticket->write) { - $this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); - if ($object->close()) { - // Log action in ticket logs table - $log_action = $langs->trans('TicketLogClosedBy', $user->getFullName($langs)); - - setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs'); - - $url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha'); - header("Location: " . $url); - } else { - $action = ''; - setEventMessages($this->error, $this->errors, 'errors'); - } - } - - if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes') { - $this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); - if (($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) && $object->close()) { - // Log action in ticket logs table - $log_action = $langs->trans('TicketLogClosedBy', $_SESSION['email_customer']); - - setEventMessages('
' . $langs->trans('TicketMarkedAsClosed') . '
', null, 'mesgs'); - - $url = 'view.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha'); - header("Location: " . $url); - } else { - setEventMessages($this->error, $this->errors, 'errors'); - $action = ''; - } - } - - if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $user->rights->ticket->delete) { - if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { - if ($object->delete($user) > 0) { - setEventMessages('
' . $langs->trans('TicketDeletedSuccess') . '
', null, 'mesgs'); - Header("Location: ".DOL_URL_ROOT."/ticket/list.php"); - exit; - } else { - $langs->load("errors"); - $mesg = '
' . $langs->trans($this->error) . '
'; - $action = ''; - } - } - } - - // Set parent company - if ($action == 'set_thirdparty' && $user->rights->societe->creer) { - if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { - $result = $object->setCustomer(GETPOST('editcustomer', 'int')); - $url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha'); - header("Location: " . $url); - exit(); - } - } - - if ($action == 'set_progression' && $user->rights->ticket->write) { - if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { - $result = $object->setProgression(GETPOST('progress', 'alpha')); - - $url = 'card.php?action=view&track_id=' . $object->track_id; - header("Location: " . $url); - exit(); - } - } - - if ($action == 'setsubject') { - if ($this->fetch(GETPOST('id', 'int'))) { - if ($action == 'setsubject') { - $object->subject = trim(GETPOST('subject', 'alpha')); - } - - if ($action == 'setsubject' && empty($object->subject)) { - $mesg .= ($mesg ? '
' : '') . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")); - } - - if (!$mesg) { - if ($object->update($user) >= 0) { - header("Location: " . $_SERVER['PHP_SELF'] . "?track_id=" . $object->track_id); - exit; - } - $mesg = $object->error; - } - } - } - - - if ($action == 'confirm_reopen' && $user->rights->ticket->manage && !GETPOST('cancel')) { - if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { - // prevent browser refresh from reopening ticket several times - if ($object->fk_statut == Ticket::STATUS_CLOSED) { - $res = $object->setStatut(Ticket::STATUS_ASSIGNED); - if ($res) { - // Log action in ticket logs table - $log_action = $langs->trans('TicketLogReopen'); - - $url = 'card.php?action=view&track_id=' . $object->track_id; - header("Location: " . $url); - exit(); - } - } - } - } // Categorisation dans projet - elseif ($action == 'classin' && $user->rights->ticket->write) { - if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { - $object->setProject(GETPOST('projectid', 'int')); - $url = 'card.php?action=view&track_id=' . $object->track_id; - header("Location: " . $url); - exit(); - } - } // Categorisation dans contrat - elseif ($action == 'setcontract' && $user->rights->ticket->write) { - if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { - $object->setContract(GETPOST('contractid', 'int')); - $url = 'card.php?action=view&track_id=' . $object->track_id; - header("Location: " . $url); - exit(); - } - } elseif ($action == "set_message" && $user->rights->ticket->manage) { - // altairis: manage cancel button - if (!GETPOST('cancel')) { - $this->fetch('', '', GETPOST('track_id', 'alpha')); - $oldvalue_message = $object->message; - $fieldtomodify = GETPOST('message_initial'); - - $object->message = $fieldtomodify; - $ret = $object->update($user); - if ($ret > 0) { - $log_action = $langs->trans('TicketInitialMessageModified') . " \n"; - // include the Diff class - dol_include_once('/ticket/class/utils_diff.class.php'); - // output the result of comparing two files as plain text - $log_action .= Diff::toString(Diff::compare(strip_tags($oldvalue_message), strip_tags($object->message))); - - setEventMessages($langs->trans('TicketMessageSuccesfullyUpdated'), null, 'mesgs'); - } - } - - $action = 'view'; - } // Reopen ticket - elseif ($action == 'confirm_set_status' && $user->rights->ticket->write && !GETPOST('cancel')) { - if ($this->fetch(GETPOST('id', 'int'), GETPOST('track_id', 'alpha')) >= 0) { - $new_status = GETPOST('new_status', 'int'); - $old_status = $object->fk_statut; - $res = $object->setStatut($new_status); - if ($res) { - // Log action in ticket logs table - $log_action = $langs->trans('TicketLogStatusChanged', $langs->transnoentities($object->statuts_short[$old_status]), $langs->transnoentities($object->statuts_short[$new_status])); - - $url = 'card.php?action=view&track_id=' . $object->track_id; - header("Location: " . $url); - exit(); - } - } - } - - return 0; - } - - /** - * Add new message on a ticket (private area) - * - * @param User $user User for action - * @param string $action Action string - * @return int - */ - private function newMessage($user, &$action) - { - global $mysoc, $conf, $langs; - - if (!class_exists('Contact')) { - include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; - } - - $contactstatic = new Contact($this->db); - - $error = 0; - - $object = new Ticket($this->db); - $ret = $object->fetch('', '', GETPOST('track_id', 'alpha')); - $object->socid = $object->fk_soc; - $object->fetch_thirdparty(); - if ($ret < 0) { - $error++; - array_push($this->errors, $langs->trans("ErrorTicketIsNotValid")); - $action = ''; - } - - if (!GETPOST("message")) { - $error++; - array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"))); - $action = 'add_message'; - } - - if (!$error) { - $object->message = GETPOST("message"); - $object->private = GETPOST("private_message"); - $send_email = GETPOST('send_email', 'int'); - - $id = $object->createTicketMessage($user); - if ($id <= 0) { - $error++; - $this->errors = $object->error; - $this->errors = $object->errors; - $action = 'add_message'; - } - - if (!$error && $id > 0) { - setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs'); - - /* - * Send email to linked contacts - */ - if ($send_email > 0) { - // Retrieve internal contact datas - $internal_contacts = $object->getInfosTicketInternalContact(); - $sendto = array(); - if (is_array($internal_contacts) && count($internal_contacts) > 0) { - // altairis: set default subject - $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE; - $subject = GETPOST('subject') ? GETPOST('subject') : '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); - - $message_intro = $langs->trans('TicketNotificationEmailBody', "#" . $object->id); - $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; - - $message = $langs->trans('TicketMessageMailIntroText'); - $message .= "\n\n"; - $message .= GETPOST('message'); - - // Coordonnées client - $message .= "\n\n"; - $message .= "==============================================\n"; - $message .= !empty($object->thirdparty->name) ? $langs->trans('Thirdparty') . " : " . $object->thirdparty->name : ''; - $message .= !empty($object->thirdparty->town) ? "\n" . $langs->trans('Town') . " : " . $object->thirdparty->town : ''; - $message .= !empty($object->thirdparty->phone) ? "\n" . $langs->trans('Phone') . " : " . $object->thirdparty->phone : ''; - - // Build array to display recipient list - foreach ($internal_contacts as $key => $info_sendto) { - // altairis: avoid duplicate notifications - if ($info_sendto['id'] == $user->id) { - continue; - } - - if ($info_sendto['email'] != '') { - if(!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; - - //Contact type - $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; - $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); - } - } - $message .= "\n"; - // URL ticket - $url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id; - - // altairis: make html link on url - $message .= "\n" . $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : ' . '' . $object->track_id . '' . "\n"; - - // Add global email address recipient - // altairis: use new TICKET_NOTIFICATION_EMAIL_TO configuration variable - if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) { - if(!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; - } - - // altairis: dont try to send email if no recipient - if (!empty($sendto)) { - $this->sendTicketMessageByEmail($subject, $message, '', $sendto); - } - } - - /* - * Email for externals users if not private - */ - if (empty($object->private)) { - // Retrieve email of all contacts (external) - $external_contacts = $object->getInfosTicketExternalContact(); - - // If no contact, get email from thirdparty - if (is_array($external_contacts) && count($external_contacts) === 0) { - if (!empty($object->fk_soc)) { - $object->fetch_thirdparty($object->fk_soc); - $array_company = array(array('firstname' => '', 'lastname' => $object->thirdparty->name, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id)); - $external_contacts = array_merge($external_contacts, $array_company); - } elseif (empty($object->fk_soc) && !empty($object->origin_email)) { - $array_external = array(array('firstname' => '', 'lastname' => $object->origin_email, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id)); - $external_contacts = array_merge($external_contacts, $array_external); - } - } - - $sendto = array(); - if (is_array($external_contacts) && count($external_contacts) > 0) { - // altairis: get default subject for email to external contacts - $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE; - $subject = GETPOST('subject') ? GETPOST('subject') : '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); - - $message_intro = GETPOST('mail_intro') ? GETPOST('mail_intro') : $conf->global->TICKET_MESSAGE_MAIL_INTRO; - $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; - - // We put intro after - $message = GETPOST('message'); - $message .= "\n\n"; - - foreach ($external_contacts as $key => $info_sendto) { - // altairis: avoid duplicate emails to external contacts - if ($info_sendto['id'] == $user->contactid) { - continue; - } - - if ($info_sendto['email'] != '' && $info_sendto['email'] != $object->origin_email) { - if(!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; - - $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; - $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); - } - } - - // If public interface is not enable, use link to internal page into mail - $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ? - (!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; - $message .= "\n" . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : ' . '' . $object->track_id . '' . "\n"; - - // Build final message - $message = $message_intro . $message; - - // Add signature - $message .= '
' . $message_signature; - - if (!empty($object->origin_email)) { - $sendto[] = $object->origin_email; - } - - if ($object->fk_soc > 0 && ! in_array($object->origin_email, $sendto)) { - $object->socid = $object->fk_soc; - $object->fetch_thirdparty(); - if(!empty($object->thirdparty->email)) $sendto[] = $object->thirdparty->email; - } - - // altairis: Add global email address reciepient - if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) { - if(!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; - } - - // altairis: dont try to send email when no recipient - if (!empty($sendto)) { - $this->sendTicketMessageByEmail($subject, $message, '', $sendto); - } - } - } - } - - $this->copyFilesForTicket(); - - // Set status to "answered" if not set yet, only for internal users - if ($object->fk_statut < 3 && !$user->societe_id) { - $object->setStatut(3); - } - - return 1; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - return -1; - } - } else { - setEventMessages($this->error, $this->errors, 'errors'); - return -1; - } - } - - /** - * Add new message on a ticket (public area) - * - * @param User $user User for action - * @param string $action Action string - * @return void - */ - private function newMessagePublic($user, &$action) - { - - global $mysoc, $conf, $langs; - - $object = new Ticket($this->db); - $error = 0; - $ret = $object->fetch('', '', GETPOST('track_id', 'alpha')); - $object->socid = $object->fk_soc; - $object->fetch_thirdparty(); - if ($ret < 0) { - $error++; - array_push($this->errors, $langs->trans("ErrorTicketIsNotValid")); - $action = ''; - } - - if (!GETPOST("message")) { - $error++; - array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"))); - $action = 'add_message'; - } - - if (!$error) { - $object->message = (string) GETPOST("message"); - $id = $object->createTicketMessage($user); - if ($id <= 0) { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - $action = 'add_message'; - } - - if (!$error && $id > 0) { - setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs'); - - // Retrieve internal contact datas - $internal_contacts = $object->getInfosTicketInternalContact(); - $sendto = array(); - if (is_array($internal_contacts) && count($internal_contacts) > 0) { - $subject = '[' . $mysoc->name . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); - - $message = $langs->trans('TicketMessageMailIntroAutoNewPublicMessage', $object->subject); - $message .= "\n"; - $message .= GETPOST('message'); - $message .= "\n"; - - // Coordonnées client - if ($object->thirdparty->id > 0) { - $message .= "\n\n"; - $message .= "==============================================\n"; - $message .= $langs->trans('Thirparty') . " : " . $object->thirdparty->name; - $message .= !empty($object->thirdparty->town) ? $langs->trans('Town') . " : " . $object->thirdparty->town : ''; - $message .= "\n"; - $message .= !empty($object->thirdparty->phone) ? $langs->trans('Phone') . " : " . $object->thirdparty->phone : ''; - $message .= "\n"; - } - - // Build array to display recipient list - foreach ($internal_contacts as $key => $info_sendto) { - if ($info_sendto['email'] != '') { - $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; - } - - // Contact type - $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; - $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); - $message .= "\n"; - } - - // URL ticket - $url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id; - $message .= "\n" . $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : ' . $url_internal_ticket . "\n"; - - $message .= "\n\n"; - - $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; - - // Add global email address reciepient - if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_FROM, $sendto)) { - $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM; - } - - $this->sendTicketMessageByEmail($subject, $message, '', $sendto); - } - - /* - * Email for externals users if not private - */ - - // Retrieve email of all contacts external - $external_contacts = $object->getInfosTicketExternalContact(); - $sendto = array(); - if (is_array($external_contacts) && count($external_contacts) > 0) { - $subject = '[' . $mysoc->name . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); - - $message = $langs->trans('TicketMessageMailIntroAutoNewPublicMessage', $object->subject); - $message .= "\n"; - - $message .= GETPOST('message'); - $message .= "\n\n"; - - $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; - foreach ($external_contacts as $key => $info_sendto) { - if ($info_sendto['email'] != '') { - $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; - } - $recipient = ''; - $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; - $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); - } - - $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=' . $object->track_id; - $message .= "\n\n" . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : ' . $url_public_ticket . "\n"; - - // Add signature - $message .= '\n\n' . $message_signature; - - if (!empty($object->origin_email) && !in_array($object->origin_email, $sendto)) { - $sendto[] = $object->origin_email; - } - if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) { - $sendto[] = $object->thirdparty->email; - } - $this->sendTicketMessageByEmail($subject, $message, '', $sendto); - } - - $this->copyFilesForTicket(); - - $url = 'view.php?action=view_ticket&track_id=' . $object->track_id; - header("Location: " . $url); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($this->error, $this->errors, 'errors'); - } - } - /** * Fetch object * @@ -1405,53 +562,6 @@ class ActionsTicket } } - /** - * Copy files into ticket directory - * Used for files linked into messages - * - * @return void - */ - public function copyFilesForTicket() - { - global $conf, $object; - - // Create form object - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; - - $maxwidthsmall = 270; - $maxheightsmall = 150; - $maxwidthmini = 128; - $maxheightmini = 72; - - $formmail = new FormMail($this->db); - - $attachedfiles = $formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; - - // Copy files into ticket directory - $destdir = $conf->ticket->dir_output . '/' . $object->track_id; - - if (!dol_is_dir($destdir)) { - dol_mkdir($destdir); - } - foreach ($filename as $i => $val) { - $res = dol_move($filepath[$i], $destdir . '/' . $filename[$i]); - if (image_format_supported($destdir . '/' . $filename[$i]) == 1) { - // Create small thumbs for image (Ratio is near 16/9) - // Used on logon for example - $imgThumbSmall = vignette($destdir . '/' . $filename[$i], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); - // Create mini thumbs for image (Ratio is near 16/9) - // Used on menu or for setup page for example - $imgThumbMini = vignette($destdir . '/' . $filename[$i], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); - } - $formmail->remove_attached_files($i); - } - } - /** * Print html navbar with link to set ticket status * @@ -1490,7 +600,7 @@ class ActionsTicket $urlforbutton = $_SERVER['PHP_SELF'] . '?track_id=' . $object->track_id . '&action=set_status&new_status=' . $status; } - print ''; + print ''; print img_picto($langs->trans($object->statuts_short[$status]), 'statut' . $status . '.png@ticket') . ' ' . $langs->trans($object->statuts_short[$status]); print ''; print '
'; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 759360a8e84..0d0c6f2cb0d 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -25,8 +25,7 @@ // Put here all includes required by your class file require_once DOL_DOCUMENT_ROOT . "/core/class/commonobject.class.php"; require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php'; -//require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"; -//require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php"; +require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php'; /** @@ -66,7 +65,7 @@ class Ticket extends CommonObject /** - * @var string Hash to identify ticket + * @var string Hash to identify ticket publically */ public $track_id; @@ -327,11 +326,14 @@ class Ticket extends CommonObject global $conf, $langs; $error = 0; + // Clean parameters $this->datec = dol_now(); + if (empty($this->track_id)) $this->track_id = generate_random_id(16); // Check more parameters // If error, this->errors[] is filled $result = $this->verify(); + if ($result >= 0) { // Insert request $sql = "INSERT INTO " . MAIN_DB_PREFIX . "ticket("; @@ -2430,6 +2432,416 @@ class Ticket extends CommonObject } return false; } + + + /** + * Copy files into ticket directory + * Used for files linked into messages + * + * @return void + */ + public function copyFilesForTicket() + { + global $conf; + + // Create form object + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; + include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; + + $maxwidthsmall = 270; + $maxheightsmall = 150; + $maxwidthmini = 128; + $maxheightmini = 72; + + $formmail = new FormMail($this->db); + + $attachedfiles = $formmail->get_attached_files(); + + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + + // Copy files into ticket directory + $destdir = $conf->ticket->dir_output . '/' . $this->ref; + + if (!dol_is_dir($destdir)) { + dol_mkdir($destdir); + } + foreach ($filename as $i => $val) { + $res = dol_move($filepath[$i], $destdir . '/' . $filename[$i]); + if (image_format_supported($destdir . '/' . $filename[$i]) == 1) { + // Create small thumbs for image (Ratio is near 16/9) + // Used on logon for example + $imgThumbSmall = vignette($destdir . '/' . $filename[$i], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); + // Create mini thumbs for image (Ratio is near 16/9) + // Used on menu or for setup page for example + $imgThumbMini = vignette($destdir . '/' . $filename[$i], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); + } + $formmail->remove_attached_files($i); + } + } + + + /** + * Add new message on a ticket (private area) + * + * @param User $user User for action + * @param string $action Action string + * @return int + */ + public function newMessage($user, &$action) + { + global $mysoc, $conf, $langs; + + if (!class_exists('Contact')) { + include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; + } + + $contactstatic = new Contact($this->db); + $object = new Ticket($this->db); + + $error = 0; + + $ret = $object->fetch('', '', GETPOST('track_id', 'alpha')); + $object->socid = $object->fk_soc; + $object->fetch_thirdparty(); + if ($ret < 0) { + $error++; + array_push($this->errors, $langs->trans("ErrorTicketIsNotValid")); + $action = ''; + } + + if (!GETPOST("message")) { + $error++; + array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"))); + $action = 'add_message'; + } + + if (!$error) { + $object->message = GETPOST("message"); + $object->private = GETPOST("private_message"); + $send_email = GETPOST('send_email', 'int'); + + $id = $object->createTicketMessage($user); + if ($id <= 0) { + $error++; + $this->errors = $object->error; + $this->errors = $object->errors; + $action = 'add_message'; + } + + if (!$error && $id > 0) { + setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs'); + + /* + * Send email to linked contacts + */ + if ($send_email > 0) { + // Retrieve internal contact datas + $internal_contacts = $object->getInfosTicketInternalContact(); + $sendto = array(); + if (is_array($internal_contacts) && count($internal_contacts) > 0) { + // altairis: set default subject + $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE; + $subject = GETPOST('subject') ? GETPOST('subject') : '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); + + $message_intro = $langs->trans('TicketNotificationEmailBody', "#" . $object->id); + $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; + + $message = $langs->trans('TicketMessageMailIntroText'); + $message .= "\n\n"; + $message .= GETPOST('message'); + + // Coordonnées client + $message .= "\n\n"; + $message .= "==============================================\n"; + $message .= !empty($object->thirdparty->name) ? $langs->trans('Thirdparty') . " : " . $object->thirdparty->name : ''; + $message .= !empty($object->thirdparty->town) ? "\n" . $langs->trans('Town') . " : " . $object->thirdparty->town : ''; + $message .= !empty($object->thirdparty->phone) ? "\n" . $langs->trans('Phone') . " : " . $object->thirdparty->phone : ''; + + // Build array to display recipient list + foreach ($internal_contacts as $key => $info_sendto) { + // altairis: avoid duplicate notifications + if ($info_sendto['id'] == $user->id) { + continue; + } + + if ($info_sendto['email'] != '') { + if(!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; + + //Contact type + $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; + $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); + } + } + $message .= "\n"; + // URL ticket + $url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id; + + // altairis: make html link on url + $message .= "\n" . $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : ' . '' . $object->track_id . '' . "\n"; + + // Add global email address recipient + // altairis: use new TICKET_NOTIFICATION_EMAIL_TO configuration variable + if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) { + if(!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; + } + + // altairis: dont try to send email if no recipient + if (!empty($sendto)) { + $this->sendTicketMessageByEmail($subject, $message, '', $sendto); + } + } + + /* + * Email for externals users if not private + */ + if (empty($object->private)) { + // Retrieve email of all contacts (external) + $external_contacts = $object->getInfosTicketExternalContact(); + + // If no contact, get email from thirdparty + if (is_array($external_contacts) && count($external_contacts) === 0) { + if (!empty($object->fk_soc)) { + $object->fetch_thirdparty($object->fk_soc); + $array_company = array(array('firstname' => '', 'lastname' => $object->thirdparty->name, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id)); + $external_contacts = array_merge($external_contacts, $array_company); + } elseif (empty($object->fk_soc) && !empty($object->origin_email)) { + $array_external = array(array('firstname' => '', 'lastname' => $object->origin_email, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id)); + $external_contacts = array_merge($external_contacts, $array_external); + } + } + + $sendto = array(); + if (is_array($external_contacts) && count($external_contacts) > 0) { + // altairis: get default subject for email to external contacts + $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE; + $subject = GETPOST('subject') ? GETPOST('subject') : '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); + + $message_intro = GETPOST('mail_intro') ? GETPOST('mail_intro') : $conf->global->TICKET_MESSAGE_MAIL_INTRO; + $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; + + // We put intro after + $message = GETPOST('message'); + $message .= "\n\n"; + + foreach ($external_contacts as $key => $info_sendto) { + // altairis: avoid duplicate emails to external contacts + if ($info_sendto['id'] == $user->contactid) { + continue; + } + + if ($info_sendto['email'] != '' && $info_sendto['email'] != $object->origin_email) { + if(!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; + + $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; + $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); + } + } + + // If public interface is not enable, use link to internal page into mail + $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ? + (!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; + $message .= "\n" . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : ' . '' . $object->track_id . '' . "\n"; + + // Build final message + $message = $message_intro . $message; + + // Add signature + $message .= '
' . $message_signature; + + if (!empty($object->origin_email)) { + $sendto[] = $object->origin_email; + } + + if ($object->fk_soc > 0 && ! in_array($object->origin_email, $sendto)) { + $object->socid = $object->fk_soc; + $object->fetch_thirdparty(); + if(!empty($object->thirdparty->email)) $sendto[] = $object->thirdparty->email; + } + + // altairis: Add global email address reciepient + if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) { + if(!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; + } + + // altairis: dont try to send email when no recipient + if (!empty($sendto)) { + $this->sendTicketMessageByEmail($subject, $message, '', $sendto); + } + } + } + } + + $object->copyFilesForTicket(); + + // Set status to "answered" if not set yet, only for internal users + if ($object->fk_statut < 3 && !$user->societe_id) { + $object->setStatut(3); + } + + return 1; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + return -1; + } + } else { + setEventMessages($this->error, $this->errors, 'errors'); + return -1; + } + } + + /** + * Add new message on a ticket (public area) + * + * @param User $user User for action + * @param string $action Action string + * @return void + */ + public function newMessagePublic($user, &$action) + { + global $mysoc, $conf, $langs; + + $object = new Ticket($this->db); + + $error = 0; + $ret = $object->fetch('', '', GETPOST('track_id', 'alpha')); + $object->socid = $object->fk_soc; + $object->fetch_thirdparty(); + if ($ret < 0) { + $error++; + array_push($this->errors, $langs->trans("ErrorTicketIsNotValid")); + $action = ''; + } + + if (!GETPOST("message")) { + $error++; + array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"))); + $action = 'add_message'; + } + + if (!$error) { + $object->message = (string) GETPOST("message"); + $id = $object->createTicketMessage($user); + if ($id <= 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + $action = 'add_message'; + } + + if (!$error && $id > 0) { + setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs'); + + // Retrieve internal contact datas + $internal_contacts = $object->getInfosTicketInternalContact(); + $sendto = array(); + if (is_array($internal_contacts) && count($internal_contacts) > 0) { + $subject = '[' . $mysoc->name . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); + + $message = $langs->trans('TicketMessageMailIntroAutoNewPublicMessage', $object->subject); + $message .= "\n"; + $message .= GETPOST('message'); + $message .= "\n"; + + // Coordonnées client + if ($object->thirdparty->id > 0) { + $message .= "\n\n"; + $message .= "==============================================\n"; + $message .= $langs->trans('Thirparty') . " : " . $object->thirdparty->name; + $message .= !empty($object->thirdparty->town) ? $langs->trans('Town') . " : " . $object->thirdparty->town : ''; + $message .= "\n"; + $message .= !empty($object->thirdparty->phone) ? $langs->trans('Phone') . " : " . $object->thirdparty->phone : ''; + $message .= "\n"; + } + + // Build array to display recipient list + foreach ($internal_contacts as $key => $info_sendto) { + if ($info_sendto['email'] != '') { + $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; + } + + // Contact type + $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; + $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); + $message .= "\n"; + } + + // URL ticket + $url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id; + $message .= "\n" . $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : ' . $url_internal_ticket . "\n"; + + $message .= "\n\n"; + + $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; + + // Add global email address reciepient + if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_FROM, $sendto)) { + $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM; + } + + $this->sendTicketMessageByEmail($subject, $message, '', $sendto); + } + + /* + * Email for externals users if not private + */ + + // Retrieve email of all contacts external + $external_contacts = $object->getInfosTicketExternalContact(); + $sendto = array(); + if (is_array($external_contacts) && count($external_contacts) > 0) { + $subject = '[' . $mysoc->name . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage'); + + $message = $langs->trans('TicketMessageMailIntroAutoNewPublicMessage', $object->subject); + $message .= "\n"; + + $message .= GETPOST('message'); + $message .= "\n\n"; + + $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; + foreach ($external_contacts as $key => $info_sendto) { + if ($info_sendto['email'] != '') { + $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">"; + } + $recipient = ''; + $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')'; + $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : ''); + } + + $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=' . $object->track_id; + $message .= "\n\n" . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : ' . $url_public_ticket . "\n"; + + // Add signature + $message .= '\n\n' . $message_signature; + + if (!empty($object->origin_email) && !in_array($object->origin_email, $sendto)) { + $sendto[] = $object->origin_email; + } + if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) { + $sendto[] = $object->thirdparty->email; + } + $this->sendTicketMessageByEmail($subject, $message, '', $sendto); + } + + $object->copyFilesForTicket(); + + $url = 'view.php?action=view_ticket&track_id=' . $object->track_id; + header("Location: " . $url); + exit; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + setEventMessages($this->error, $this->errors, 'errors'); + } + } } diff --git a/htdocs/ticket/contact.php b/htdocs/ticket/contact.php index 21c1087f276..f38a5abd910 100644 --- a/htdocs/ticket/contact.php +++ b/htdocs/ticket/contact.php @@ -50,9 +50,6 @@ $source = GETPOST('source', 'alpha'); $ligne = GETPOST('ligne', 'int'); $lineid = GETPOST('lineid', 'int'); - - - // Protection if external user if ($user->societe_id > 0) { $socid = $user->societe_id; @@ -64,8 +61,9 @@ $url_page_current = dol_buildpath('/ticket/contact.php', 1); $object = new Ticket($db); + /* - * Ajout d'un nouveau contact + * Actions */ if ($action == 'addcontact' && $user->rights->ticket->write) { @@ -110,9 +108,12 @@ if ($action == 'deletecontact' && $user->rights->ticket->write) { } } + + /* * View */ + $help_url = 'FR:DocumentationModuleTicket'; llxHeader('', $langs->trans("TicketContacts"), $help_url); @@ -121,12 +122,6 @@ $formcompany = new FormCompany($db); $contactstatic = new Contact($db); $userstatic = new User($db); -/* *************************************************************************** */ -/* */ -/* Mode vue et edition */ -/* */ -/* *************************************************************************** */ - if ($id > 0 || !empty($track_id) || !empty($ref)) { if ($object->fetch($id, $ref, $track_id) > 0) { @@ -146,7 +141,7 @@ if ($id > 0 || !empty($track_id) || !empty($ref)) { $head = ticket_prepare_head($object); - dol_fiche_head($head, 'contact', $langs->trans("Ticket"), 0, 'ticket'); + dol_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket'); $morehtmlref ='
'; $morehtmlref.= $object->subject; diff --git a/htdocs/ticket/document.php b/htdocs/ticket/document.php index b02b6ee07a7..16fabc6943c 100644 --- a/htdocs/ticket/document.php +++ b/htdocs/ticket/document.php @@ -61,15 +61,10 @@ if (! $sortfield) $sortfield="position_name"; $object = new Ticket($db); $result = $object->fetch($id, $ref, $track_id); -// to match document rules and compatibility -$old_ref = $object->ref; -$object->ref = $object->track_id; - - if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { - $upload_dir = $conf->ticket->dir_output . "/" . dol_sanitizeFileName($object->track_id); + $upload_dir = $conf->ticket->dir_output . "/" . dol_sanitizeFileName($object->ref); } @@ -79,8 +74,6 @@ if ($result < 0) { include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; -$object->ref = $old_ref; - /* @@ -193,7 +186,7 @@ if ($object->id) $totalsize += $file['size']; } - $object->ref = $object->track_id; // For compatibility we use track ID for directory + //$object->ref = $object->track_id; // For compatibility we use track ID for directory $modulepart = 'ticket'; $permission = $user->rights->ticket->write; $permtoedit = $user->rights->ticket->write;