* Copyright (C) 2016 Christophe Battarel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file ticket/class/html.ticket.class.php * \ingroup ticket * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire */ require_once DOL_DOCUMENT_ROOT . "/core/class/html.form.class.php"; require_once DOL_DOCUMENT_ROOT . "/core/class/html.formmail.class.php"; if (!class_exists('FormCompany')) { include DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; } /** * Classe permettant la generation du formulaire d'un nouveau ticket. * * @package Ticket * \remarks Utilisation: $formticket = new FormTicket($db) * \remarks $formticket->proprietes=1 ou chaine ou tableau de valeurs * \remarks $formticket->show_form() affiche le formulaire */ class FormTicket { /** * @var DoliDB Database handler. */ public $db; public $track_id; /** * @var int ID */ public $fk_user_create; public $message; public $topic_title; public $action; public $withtopic; public $withemail; /** * * @var int $withsubstit Show substitution array */ public $withsubstit; public $withfile; public $ispublic; // To show information or not into public form public $withtitletopic; public $withcompany; // affiche liste déroulante company public $withfromsocid; public $withfromcontactid; public $withnotnotifytiersatcreate; public $withusercreate; // Show name of creating user in form public $withcreatereadonly; public $withref; // Show ref field public $withcancel; /** * * @var array $substit Substitutions */ public $substit = array(); public $param = array(); /** * @var string Error code (or message) */ public $error; /** * Constructor * * @param DoliDB $db Database handler */ public function __construct($db) { $this->db = $db; $this->action = 'add_ticket'; $this->withcompany = 1; $this->withfromsocid = 0; $this->withfromcontactid = 0; //$this->withthreadid=0; //$this->withtitletopic=''; $this->withnotnotifytiersatcreate = 0; $this->withusercreate = 1; $this->withcreatereadonly = 1; $this->withemail = 0; $this->withref = 0; $this->withextrafields = 0; // Show extrafields or not //$this->withtopicreadonly=0; } /** * Show the form to input ticket * * @param int $withdolfichehead With dol_fiche_head * @return void */ public function showForm($withdolfichehead=0) { global $conf, $langs, $user, $hookmanager; // Load translation files required by the page $langs->loadLangs(array('other', 'mails', 'ticket')); $form = new Form($this->db); $formcompany = new FormCompany($this->db); $ticketstatic = new Ticket($this->db); $soc = new Societe($this->db); if (!empty($this->withfromsocid) && $this->withfromsocid > 0) { $soc->fetch($this->withfromsocid); } $ticketstat = new Ticket($this->db); $extrafields = new ExtraFields($this->db); $extralabels = $extrafields->fetch_name_optionals_label($ticketstat->table_element); print "\n\n"; if ($withdolfichehead) dol_fiche_head(null, 'card', '', 0, ''); print '
'; print ''; print ''; foreach ($this->param as $key => $value) { print ''; } print ''; print ''; if ($this->withref) { // Ref $defaultref = $ticketstat->getDefaultRef(); print ''; } // FK_USER_CREATE if ($this->withusercreate > 0 && $this->fk_user_create) { print '\n"; } // Customer or supplier if ($this->withcompany) { // altairis: force company and contact id for external user if (empty($user->socid)) { // Company print ''; if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) { $htmlname = 'socid'; print ''; } // Contact and type print ''; } else { print ''; print ''; 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 ''; // Category print ''; // Severity print ''; // Notify thirdparty at creation if (empty($this->ispublic)) { print ''; } // TITLE if ($this->withtitletopic) { print ''; } else { if ($this->withthreadid > 0) { $subject = $langs->trans('SubjectAnswerToTicket') . ' ' . $this->withthreadid . ' : ' . $this->topic_title . ''; } print ''; print ''; } } // MESSAGE $msg = GETPOST('message', 'alpha') ? GETPOST('message', 'alpha') : ''; print ''; // Attached files if (!empty($this->withfile)) { // Define list of attached files $listofpaths = array(); $listofnames = array(); $listofmimes = array(); if (!empty($_SESSION["listofpaths"])) { $listofpaths = explode(';', $_SESSION["listofpaths"]); } if (!empty($_SESSION["listofnames"])) { $listofnames = explode(';', $_SESSION["listofnames"]); } if (!empty($_SESSION["listofmimes"])) { $listofmimes = explode(';', $_SESSION["listofmimes"]); } $out .= ''; $out .= ''; $out .= '\n"; print $out; } // Other attributes $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $ticketstat, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { print $ticketstat->showOptionals($extrafields, 'edit'); } print '
' . $langs->trans("Ref") . '
' . $langs->trans("CreatedBy") . ''; $langs->load("users"); $fuser = new User($this->db); if ($this->withcreatereadonly) { if ($res = $fuser->fetch($this->fk_user_create)) { print $fuser->getNomUrl(1); } } print '   '; print "
' . $langs->trans("ThirdParty") . ''; $events = array(); $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); print $form->select_company($this->withfromsocid, 'socid', '', 1, 1, '', $events, 0, 'minwidth200'); print '
' . $langs->trans("Contact") . ''; // If no socid, set to -1 to avoid full contacts list $selectedCompany = ($this->withfromsocid > 0) ? $this->withfromsocid : -1; $nbofcontacts = $form->select_contacts($selectedCompany, $this->withfromcontactid, 'contactid', 3, '', '', 0, 'minwidth200'); $formcompany->selectTypeContact($ticketstatic, '', 'type', 'external', '', 0, 'maginleftonly'); print '
'; print ''; print '
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
'; print $this->selectTypesTickets((GETPOST('type_code') ? GETPOST('type_code') : $this->type_code), 'type_code', '', '2'); print '
'; print $this->selectCategoriesTickets((GETPOST('category_code') ? GETPOST('category_code') : $this->category_code), 'category_code', '', '2'); print '
'; print $this->selectSeveritiesTickets((GETPOST('severity_code') ? GETPOST('severity_code') : $this->severity_code), 'severity_code', '', '2'); print '
'; print 'withnotifytiersatcreate?' checked="checked"':'').'>'; 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 if ($this->ispublic) { 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', GETPOST('message', 'alpha'), '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser); $doleditor->Create(); print '
' . $langs->trans("MailFile") . ''; // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript $out .= '' . "\n"; $out .= '' . "\n"; if (count($listofpaths)) { foreach ($listofpaths as $key => $val) { $out .= '
'; $out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key]; if (!$this->withfilereadonly) { $out .= ' '; } $out .= '
'; } } else { $out .= $langs->trans("NoAttachedFiles") . '
'; } if ($this->withfile == 2) { // Can add other files $out .= ''; $out .= ' '; $out .= ''; } $out .= "
'; if ($withdolfichehead) dol_fiche_end(); print '
'; print ''; if ($this->withcancel) { print "     "; print "trans("Cancel") . "\">"; } print "
\n"; print "
\n"; print "\n"; } /** * Return html list of tickets type * * @param string $selected Id du type pre-selectionne * @param string $htmlname Nom de la zone select * @param string $filtertype To filter on field type in llx_c_ticket_type (array('code'=>xx,'label'=>zz)) * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param int $empty 1=peut etre vide, 0 sinon * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label * @param string $morecss More CSS * @return void */ public function selectTypesTickets($selected = '', $htmlname = 'tickettype', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='') { global $langs, $user; $ticketstat = new Ticket($this->db); dol_syslog(get_class($this) . "::select_types_tickets " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG); $filterarray = array(); if ($filtertype != '' && $filtertype != '-1') { $filterarray = explode(',', $filtertype); } $ticketstat->loadCacheTypesTickets(); print ''; if ($user->admin && !$noadmininfo) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } print ajax_combobox('select'.$htmlname); } /** * Return html list of ticket categories * * @param string $selected Id categorie pre-selectionnée * @param string $htmlname Nom de la zone select * @param string $filtertype To filter on field type in llx_c_ticket_category (array('code'=>xx,'label'=>zz)) * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param int $empty 1=peut etre vide, 0 sinon * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label * @param string $morecss More CSS * @return void */ public function selectCategoriesTickets($selected = '', $htmlname = 'ticketcategory', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='') { global $langs, $user; $ticketstat = new Ticket($this->db); dol_syslog(get_class($this) . "::selectCategoryTickets " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG); $filterarray = array(); if ($filtertype != '' && $filtertype != '-1') { $filterarray = explode(',', $filtertype); } $ticketstat->loadCacheCategoriesTickets(); print ''; if ($user->admin && !$noadmininfo) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } print ajax_combobox('select'.$htmlname); } /** * Return html list of ticket severitys * * @param string $selected Id severity pre-selectionnée * @param string $htmlname Nom de la zone select * @param string $filtertype To filter on field type in llx_c_ticket_severity (array('code'=>xx,'label'=>zz)) * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param int $empty 1=peut etre vide, 0 sinon * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label * @param string $morecss More CSS * @return void */ public function selectSeveritiesTickets($selected = '', $htmlname = 'ticketseverity', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='') { global $langs, $user; $ticketstat = new Ticket($this->db); dol_syslog(get_class($this) . "::selectSeveritiesTickets " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG); $filterarray = array(); if ($filtertype != '' && $filtertype != '-1') { $filterarray = explode(',', $filtertype); } $ticketstat->loadCacheSeveritiesTickets(); print ''; if ($user->admin && !$noadmininfo) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } print ajax_combobox('select'.$htmlname); } /** * Show the form to add message on ticket * * @param string $width Width of form * @return void */ public function showMessageForm($width = '40%') { global $conf, $langs, $user, $mysoc; // Load translation files required by the page $langs->loadLangs(array('other', 'mails')); $addfileaction = 'addfile'; $form = new Form($this->db); $formmail = new FormMail($this->db); // Define list of attached files $listofpaths = array(); $listofnames = array(); $listofmimes = array(); if (!empty($_SESSION["listofpaths"])) { $listofpaths = explode(';', $_SESSION["listofpaths"]); } if (!empty($_SESSION["listofnames"])) { $listofnames = explode(';', $_SESSION["listofnames"]); } if (!empty($_SESSION["listofmimes"])) { $listofmimes = explode(';', $_SESSION["listofmimes"]); } // 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'); } print "\n\n"; $send_email = GETPOST('send_email', 'int') ? GETPOST('send_email', 'int') : 0; // Example 1 : Adding jquery code print ''; print '
'; print ''; print ''; foreach ($this->param as $key => $value) { print ''; } // Get message template $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); } $result = $formmail->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); if ($result<0) { setEventMessages($this->error, $this->errors, 'errors'); } $modelmail_array=array(); foreach ($formmail->lines_model as $line) { $modelmail_array[$line->id]=$line->label; } print ''; // External users can't send message email if ($user->rights->ticket->write && !$user->socid) { print ''; // Zone to select its email template if (count($modelmail_array)>0) { print ''; } // Substitution array if ($this->withsubstit) { print '"; } if (! $user->socid) { print ''; } print ''; $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE; print ''; // Destinataires print ''; } // Intro // External users can't send message email if ($user->rights->ticket->write && !$user->socid) { $mail_intro = GETPOST('mail_intro') ? GETPOST('mail_intro') : $conf->global->TICKET_MESSAGE_MAIL_INTRO; print ''; } // MESSAGE $defaultmessage=""; if (is_array($arraydefaultmessage) && count($arraydefaultmessage) > 0 && $arraydefaultmessage->content) { $defaultmessage=$arraydefaultmessage->content; } $defaultmessage=str_replace('\n', "\n", $defaultmessage); // Deal with format differences between message and signature (text / HTML) if (dol_textishtml($defaultmessage) && !dol_textishtml($this->substit['__SIGNATURE__'])) { $this->substit['__SIGNATURE__'] = dol_nl2br($this->substit['__SIGNATURE__']); } elseif (!dol_textishtml($defaultmessage) && dol_textishtml($this->substit['__SIGNATURE__'])) { $defaultmessage = dol_nl2br($defaultmessage); } if (isset($_POST["message"]) && ! $_POST['modelselected']) { $defaultmessage=GETPOST('message'); } else { $defaultmessage=make_substitutions($defaultmessage, $this->substit); // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) $defaultmessage=preg_replace("/^(
)+/", "", $defaultmessage); $defaultmessage=preg_replace("/^\n+/", "", $defaultmessage); } print ''; // Signature // External users can't send message email if ($user->rights->ticket->write && !$user->socid) { $mail_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE; print ''; } // Attached files if (!empty($this->withfile)) { $out .= ''; $out .= ''; $out .= '\n"; print $out; } print ''; print '
'; $checkbox_selected = ( GETPOST('send_email') == "1" ? ' checked' : ''); print ' '; print ''; print '
'; $checkbox_selected = ( GETPOST('private_message') == "1" ? ' checked' : ''); print ' '; print ''; print ''; print $form->textwithpicto('', $langs->trans("TicketMessagePrivateHelp"), 1, 'help'); print '
'; include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $doleditor = new DolEditor('message', $defaultmessage, '100%', 350, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_2, 70); $doleditor->Create(); print ''; if ($user->rights->ticket->write && !$user->socid) { print $form->textwithpicto('', $langs->trans("TicketMessageHelp"), 1, 'help'); } print '
' . $langs->trans("MailFile") . ''; // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript $out .= '' . "\n"; $out .= '' . "\n"; if (count($listofpaths)) { foreach ($listofpaths as $key => $val) { $out .= '
'; $out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key]; if (!$this->withfilereadonly) { $out .= ' '; } $out .= '
'; } } else { $out .= $langs->trans("NoAttachedFiles") . '
'; } if ($this->withfile == 2) { // Can add other files $out .= ''; $out .= ' '; $out .= ''; } $out .= "
'; print '
'; print ''; if ($this->withcancel) { print "     "; print "trans("Cancel") . "\">"; } print "
\n"; print '
'; print "
\n"; print "\n"; } }