diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 6f712fa6c4d..fdbce981e72 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -733,40 +733,97 @@ class FormTicket print ajax_combobox('select'.$htmlname); } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Clear list of attached files in send mail form (also stored in session) + * + * @return void + */ + public function clear_attached_files() + { + // phpcs:enable + global $conf,$user; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path + if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir); + + $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined + unset($_SESSION["listofpaths".$keytoavoidconflict]); + unset($_SESSION["listofnames".$keytoavoidconflict]); + unset($_SESSION["listofmimes".$keytoavoidconflict]); + } + /** * Show the form to add message on ticket * - * @param string $width Width of form - * @return void + * @param string $width Width of form + * @return void */ public function showMessageForm($width = '40%') { - global $conf, $langs, $user, $mysoc; + global $conf, $langs, $user, $hookmanager, $form, $mysoc; + + $formmail = new FormMail($this->db); + $addfileaction = 'addfile'; + + if (! is_object($form)) $form=new Form($this->db); // Load translation files required by the page $langs->loadLangs(array('other', 'mails')); - $addfileaction = 'addfile'; + // Clear temp files. Must be done at beginning, before call of triggers + if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) + { + $this->clear_attached_files(); + } - $form = new Form($this->db); - $formmail = new FormMail($this->db); + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $this->param['langsmodels']; + if (! empty($newlang)) + { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + $outputlangs->load('other'); + } + // Get message template for $this->param["models"] into c_email_templates + $arraydefaultmessage = -1; + if ($this->param['models'] != 'none') + { + $model_id=0; + if (array_key_exists('models_id', $this->param)) + { + $model_id=$this->param["models_id"]; + } + + $arraydefaultmessage=$formmail->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id); // If $model_id is empty, preselect the first one + } // Define list of attached files $listofpaths = array(); $listofnames = array(); $listofmimes = array(); - if (!empty($_SESSION["listofpaths"])) { - $listofpaths = explode(';', $_SESSION["listofpaths"]); + $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined + + if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) + { + if (! empty($arraydefaultmessage->joinfiles) && is_array($this->param['fileinit'])) + { + foreach($this->param['fileinit'] as $file) + { + $this->add_attached_files($file, basename($file), dol_mimetype($file)); + } + } } - if (!empty($_SESSION["listofnames"])) { - $listofnames = explode(';', $_SESSION["listofnames"]); - } - - if (!empty($_SESSION["listofmimes"])) { - $listofmimes = explode(';', $_SESSION["listofmimes"]); - } + if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); + if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';', $_SESSION["listofnames".$keytoavoidconflict]); + if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); // Define output language $outputlangs = $langs; @@ -808,6 +865,7 @@ class FormTicket print '
'; print ''; print ''; + print ''; foreach ($this->param as $key => $value) { print ''; } diff --git a/htdocs/public/ticket/index.php b/htdocs/public/ticket/index.php index 2e138312102..b7f7bd71088 100644 --- a/htdocs/public/ticket/index.php +++ b/htdocs/public/ticket/index.php @@ -77,7 +77,7 @@ print ''; print ''; // End of page -htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object); +htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix, $object); llxFooter('', 'public'); diff --git a/htdocs/public/ticket/list.php b/htdocs/public/ticket/list.php index 39736c6d857..88b8426fef9 100644 --- a/htdocs/public/ticket/list.php +++ b/htdocs/public/ticket/list.php @@ -706,7 +706,7 @@ if ($action == "view_ticketlist") print ""; // End of page -htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object); +htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix, $object); llxFooter('', 'public'); diff --git a/htdocs/public/ticket/view.php b/htdocs/public/ticket/view.php index be77e50ea28..e7df24c16f3 100644 --- a/htdocs/public/ticket/view.php +++ b/htdocs/public/ticket/view.php @@ -48,8 +48,9 @@ $langs->loadLangs(array("companies","other","ticket")); // Get parameters $track_id = GETPOST('track_id', 'alpha'); -$action = GETPOST('action', 'aZ09'); -$email = GETPOST('email', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); +$action = GETPOST('action', 'aZ09'); +$email = GETPOST('email', 'alpha'); if (GETPOST('btn_view_ticket')) { unset($_SESSION['email_customer']); @@ -65,7 +66,17 @@ $object = new ActionsTicket($db); * Actions */ -if ($action == "view_ticket" || $action == "add_message" || $action == "close" || $action == "confirm_public_close" || $action == "add_public_message") { +if ($cancel) +{ + if (! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + $action='view_ticket'; +} + +if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close" || $action == "add_message") { $error = 0; $display_ticket = false; if (!strlen($track_id)) { @@ -108,12 +119,33 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | } } } - if ($object->dao->fk_soc > 0) { + // Check email of thirdparty of ticket + if ($object->dao->fk_soc > 0 || $object->dao->socid > 0) { $object->dao->fetch_thirdparty(); + if ($email == $object->dao->thirdparty->email) { + $display_ticket = true; + $_SESSION['email_customer'] = $email; + } } - if ($email == $object->dao->origin_email || $email == $object->dao->thirdparty->email) { - $display_ticket = true; - $_SESSION['email_customer'] = $email; + // Check if email is email of creator + if ($object->dao->fk_user_create > 0) + { + $tmpuser = new User($db); + $tmpuser->fetch($object->dao->fk_user_create); + if ($email == $tmpuser->email) { + $display_ticket = true; + $_SESSION['email_customer'] = $email; + } + } + // Check if email is email of creator + if ($object->dao->fk_user_assign > 0 && $object->dao->fk_user_assign != $object->dao->fk_user_create) + { + $tmpuser = new User($db); + $tmpuser->fetch($object->dao->fk_user_assign); + if ($email == $tmpuser->email) { + $display_ticket = true; + $_SESSION['email_customer'] = $email; + } } } else { $error++; @@ -122,9 +154,11 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | } } - if ($action == "add_public_message") + if (! $error && $action == "add_message" && $display_ticket) { // TODO Add message... + $ret = $object->dao->newMessage($user, $action, 0); + @@ -137,9 +171,9 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | if ($error || $errors) { setEventMessages($object->error, $object->errors, 'errors'); - if ($action == "add_public_message") + if ($action == "add_message") { - $action = 'add_message'; + $action = 'presend'; } else { @@ -172,7 +206,7 @@ llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss); print '
'; -if ($action == "view_ticket" || $action == "add_message" || $action == "close" || $action == "confirm_public_close") { +if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close") { if ($display_ticket) { // Confirmation close if ($action == 'close') { @@ -272,22 +306,24 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | print '
'; - if ($action == 'add_message') { + if ($action == 'presend') { print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'messages@ticket'); $formticket = new FormTicket($db); - $formticket->action = "add_public_message"; + $formticket->action = "add_message"; $formticket->track_id = $object->dao->track_id; $formticket->id = $object->dao->id; $formticket->param = array('track_id' => $object->dao->track_id, 'fk_user_create' => '-1', 'returnurl' => DOL_URL_ROOT.'/public/ticket/view.php'); $formticket->withfile = 2; + $formticket->withcancel = 1; + $formticket->showMessageForm('100%'); } - if ($action != 'add_message') { + if ($action != 'presend') { print ''; print ''; print ''; @@ -302,7 +338,7 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | if ($object->dao->fk_statut < 8) { // New message - print ''; + print ''; // Close ticket if ($object->dao->fk_statut > 0 && $object->dao->fk_statut < 8) { @@ -346,7 +382,7 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | print "
"; // End of page -htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object); +htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix, $object); llxFooter('', 'public'); diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index af65fbd2715..ba2d14b06ce 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -75,7 +75,7 @@ if (empty($action) && empty($id) && empty($ref)) $action='view'; //Select mail models is same action as add_message if (GETPOST('modelselected', 'alpha')) { - $action = 'create_message'; + $action = 'presend'; } // Load object @@ -255,17 +255,17 @@ if (GETPOST('add', 'alpha') && $user->rights->ticket->write) { if ($action == 'edit' && $user->rights->ticket->write) { $error = 0; - if ($object->fetch(GETPOST('id')) < 0) { + if ($object->fetch(GETPOST('id', 'int')) < 0) { $error++; array_push($object->errors, $langs->trans("ErrorTicketIsNotValid")); $_GET["action"] = $_POST["action"] = ''; } } -if (GETPOST('update') && GETPOST('id') && $user->rights->ticket->write) { +if (GETPOST('update', 'alpha') && GETPOST('id', 'int') && $user->rights->ticket->write) { $error = 0; - $ret = $object->fetch(GETPOST('id')); + $ret = $object->fetch(GETPOST('id', 'int')); if ($ret < 0) { $error++; array_push($object->errors, $langs->trans("ErrorTicketIsNotValid")); @@ -385,7 +385,7 @@ if ($action == "add_message" && GETPOST('btn_add_message') && $user->rights->tic exit; } else { setEventMessages($object->error, null, 'errors'); - $action = 'create_message'; + $action = 'presend'; } } @@ -477,7 +477,6 @@ if ($action == 'setsubject') { } } - 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 @@ -601,6 +600,8 @@ $autocopy='MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to $trackid='tic'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; +// Set $action to correct value for the case we used presend action to add a message +if (GETPOSTISSET('actionbis') && $action == 'presend') $action = 'presend_addmessage'; /* @@ -640,7 +641,7 @@ if ($action == 'create' || $action == 'presend') $formticket->showForm(1); } -if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'create_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' +if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { if ($res > 0) @@ -1155,7 +1156,7 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd // Buttons for actions - if ($action != 'presend' && $action != 'editline') { + if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'editline') { print '
'."\n"; $parameters=array(); $reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -1164,8 +1165,8 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd if (empty($reshook)) { // Show link to add a message (if read and not closed) - if ($object->fk_statut < Ticket::STATUS_CLOSED && $action != "create_message") { - print ''; + if ($object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") { + print ''; } // Link to create an intervention @@ -1200,8 +1201,10 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd if (GETPOST('modelselected')) { $action = 'presend'; } + // Set $action to correct value for the case we used presend action to add a message + if (GETPOSTISSET('actionbis') && $action == 'presend') $action = 'presend_addmessage'; - if ($action != 'create_message') + if ($action != 'presend' && $action != 'presend_addmessage') { print '
'; print ''; // ancre @@ -1233,23 +1236,23 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd $substitutionarray['__THIRDPARTY_NAME__'] = $object->thirdparty->name; } $substitutionarray['__SIGNATURE__'] = $user->signature; - $substitutionarray['__TICKETSUP_TRACKID__'] = $object->track_id; - $substitutionarray['__TICKETSUP_REF__'] = $object->ref; - $substitutionarray['__TICKETSUP_SUBJECT__'] = $object->subject; - $substitutionarray['__TICKETSUP_TYPE__'] = $object->type_code; - $substitutionarray['__TICKETSUP_SEVERITY__'] = $object->severity_code; - $substitutionarray['__TICKETSUP_CATEGORY__'] = $object->category_code; // For backward compatibility - $substitutionarray['__TICKETSUP_ANALYTIC_CODE__'] = $object->category_code; - $substitutionarray['__TICKETSUP_MESSAGE__'] = $object->message; - $substitutionarray['__TICKETSUP_PROGRESSION__'] = $object->progress; + $substitutionarray['__TICKET_TRACKID__'] = $object->track_id; + $substitutionarray['__TICKET_REF__'] = $object->ref; + $substitutionarray['__TICKET_SUBJECT__'] = $object->subject; + $substitutionarray['__TICKET_TYPE__'] = $object->type_code; + $substitutionarray['__TICKET_SEVERITY__'] = $object->severity_code; + $substitutionarray['__TICKET_CATEGORY__'] = $object->category_code; // For backward compatibility + $substitutionarray['__TICKET_ANALYTIC_CODE__'] = $object->category_code; + $substitutionarray['__TICKET_MESSAGE__'] = $object->message; + $substitutionarray['__TICKET_PROGRESSION__'] = $object->progress; if ($object->fk_user_assign > 0) { $userstat->fetch($object->fk_user_assign); - $substitutionarray['__TICKETSUP_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + $substitutionarray['__TICKET_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); } if ($object->fk_user_create > 0) { $userstat->fetch($object->fk_user_create); - $substitutionarray['__TICKETSUP_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + $substitutionarray['__TICKET_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); } foreach ($substitutionarray as $key => $val) { $help.=$key.' -> '.$langs->trans($val).'
';