html.formticket.class.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. <?php
  2. /* Copyright (C) - 2013-2015 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file ticket/class/html.ticket.class.php
  20. * \ingroup ticket
  21. * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire
  22. */
  23. require_once DOL_DOCUMENT_ROOT . "/core/class/html.form.class.php";
  24. require_once DOL_DOCUMENT_ROOT . "/core/class/html.formmail.class.php";
  25. if (!class_exists('FormCompany')) {
  26. include DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  27. }
  28. /**
  29. * Classe permettant la generation du formulaire d'un nouveau ticket.
  30. *
  31. * @package Ticket
  32. * \remarks Utilisation: $formticket = new FormTicket($db)
  33. * \remarks $formticket->proprietes=1 ou chaine ou tableau de valeurs
  34. * \remarks $formticket->show_form() affiche le formulaire
  35. */
  36. class FormTicket
  37. {
  38. /**
  39. * @var DoliDB Database handler.
  40. */
  41. public $db;
  42. public $track_id;
  43. /**
  44. * @var int ID
  45. */
  46. public $fk_user_create;
  47. public $message;
  48. public $topic_title;
  49. public $action;
  50. public $withtopic;
  51. public $withemail;
  52. /**
  53. *
  54. * @var int $withsubstit Show substitution array
  55. */
  56. public $withsubstit;
  57. public $withfile;
  58. public $ispublic; // To show information or not into public form
  59. public $withtitletopic;
  60. public $withcompany; // affiche liste déroulante company
  61. public $withfromsocid;
  62. public $withfromcontactid;
  63. public $withnotnotifytiersatcreate;
  64. public $withusercreate; // Show name of creating user in form
  65. public $withcreatereadonly;
  66. public $withref; // Show ref field
  67. public $withcancel;
  68. /**
  69. *
  70. * @var array $substit Substitutions
  71. */
  72. public $substit = array();
  73. public $param = array();
  74. /**
  75. * @var string Error code (or message)
  76. */
  77. public $error;
  78. /**
  79. * Constructor
  80. *
  81. * @param DoliDB $db Database handler
  82. */
  83. public function __construct($db)
  84. {
  85. $this->db = $db;
  86. $this->action = 'add_ticket';
  87. $this->withcompany = 1;
  88. $this->withfromsocid = 0;
  89. $this->withfromcontactid = 0;
  90. //$this->withthreadid=0;
  91. //$this->withtitletopic='';
  92. $this->withnotnotifytiersatcreate = 0;
  93. $this->withusercreate = 1;
  94. $this->withcreatereadonly = 1;
  95. $this->withemail = 0;
  96. $this->withref = 0;
  97. $this->withextrafields = 0; // Show extrafields or not
  98. //$this->withtopicreadonly=0;
  99. }
  100. /**
  101. * Show the form to input ticket
  102. *
  103. * @param int $withdolfichehead With dol_fiche_head
  104. * @return void
  105. */
  106. public function showForm($withdolfichehead=0)
  107. {
  108. global $conf, $langs, $user, $hookmanager;
  109. // Load translation files required by the page
  110. $langs->loadLangs(array('other', 'mails', 'ticket'));
  111. $form = new Form($this->db);
  112. $formcompany = new FormCompany($this->db);
  113. $ticketstatic = new Ticket($this->db);
  114. $soc = new Societe($this->db);
  115. if (!empty($this->withfromsocid) && $this->withfromsocid > 0) {
  116. $soc->fetch($this->withfromsocid);
  117. }
  118. $ticketstat = new Ticket($this->db);
  119. $extrafields = new ExtraFields($this->db);
  120. $extralabels = $extrafields->fetch_name_optionals_label($ticketstat->table_element);
  121. print "\n<!-- Begin form TICKETSUP -->\n";
  122. if ($withdolfichehead) dol_fiche_head(null, 'card', '', 0, '');
  123. print '<form method="POST" '.($withdolfichehead?'':'style="margin-bottom: 30px;" ').'name="ticket" id="form_create_ticket" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">';
  124. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  125. print '<input type="hidden" name="action" value="' . $this->action . '">';
  126. foreach ($this->param as $key => $value) {
  127. print '<input type="hidden" name="' . $key . '" value="' . $value . '">';
  128. }
  129. print '<input type="hidden" name="fk_user_create" value="' . $this->fk_user_create . '">';
  130. print '<table class="border">';
  131. if ($this->withref) {
  132. // Ref
  133. $defaultref = $ticketstat->getDefaultRef();
  134. print '<tr><td class="titlefield"><span class="fieldrequired">' . $langs->trans("Ref") . '</span></td><td><input size="18" type="text" name="ref" value="' . (GETPOST("ref", 'alpha') ? GETPOST("ref", 'alpha') : $defaultref) . '"></td></tr>';
  135. }
  136. // FK_USER_CREATE
  137. if ($this->withusercreate > 0 && $this->fk_user_create) {
  138. print '<tr><td class="titlefield">' . $langs->trans("CreatedBy") . '</td><td>';
  139. $langs->load("users");
  140. $fuser = new User($this->db);
  141. if ($this->withcreatereadonly) {
  142. if ($res = $fuser->fetch($this->fk_user_create)) {
  143. print $fuser->getNomUrl(1);
  144. }
  145. }
  146. print ' &nbsp; ';
  147. print "</td></tr>\n";
  148. }
  149. // Customer or supplier
  150. if ($this->withcompany) {
  151. // altairis: force company and contact id for external user
  152. if (empty($user->socid)) {
  153. // Company
  154. print '<tr><td class="titlefield">' . $langs->trans("ThirdParty") . '</td><td>';
  155. $events = array();
  156. $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
  157. print $form->select_company($this->withfromsocid, 'socid', '', 1, 1, '', $events, 0, 'minwidth200');
  158. print '</td></tr>';
  159. if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
  160. $htmlname = 'socid';
  161. print '<script type="text/javascript">
  162. $(document).ready(function () {
  163. jQuery("#'.$htmlname.'").change(function () {
  164. var obj = '.json_encode($events).';
  165. $.each(obj, function(key,values) {
  166. if (values.method.length) {
  167. runJsCodeForEvent'.$htmlname.'(values);
  168. }
  169. });
  170. });
  171. function runJsCodeForEvent'.$htmlname.'(obj) {
  172. console.log("Run runJsCodeForEvent'.$htmlname.'");
  173. var id = $("#'.$htmlname.'").val();
  174. var method = obj.method;
  175. var url = obj.url;
  176. var htmlname = obj.htmlname;
  177. var showempty = obj.showempty;
  178. $.getJSON(url,
  179. {
  180. action: method,
  181. id: id,
  182. htmlname: htmlname,
  183. showempty: showempty
  184. },
  185. function(response) {
  186. $.each(obj.params, function(key,action) {
  187. if (key.length) {
  188. var num = response.num;
  189. if (num > 0) {
  190. $("#" + key).removeAttr(action);
  191. } else {
  192. $("#" + key).attr(action, action);
  193. }
  194. }
  195. });
  196. $("select#" + htmlname).html(response.value);
  197. if (response.num) {
  198. var selecthtml_str = response.value;
  199. var selecthtml_dom=$.parseHTML(selecthtml_str);
  200. $("#inputautocomplete"+htmlname).val(selecthtml_dom[0][0].innerHTML);
  201. } else {
  202. $("#inputautocomplete"+htmlname).val("");
  203. }
  204. $("select#" + htmlname).change(); /* Trigger event change */
  205. }
  206. );
  207. }
  208. });
  209. </script>';
  210. }
  211. // Contact and type
  212. print '<tr><td>' . $langs->trans("Contact") . '</td><td>';
  213. // If no socid, set to -1 to avoid full contacts list
  214. $selectedCompany = ($this->withfromsocid > 0) ? $this->withfromsocid : -1;
  215. $nbofcontacts = $form->select_contacts($selectedCompany, $this->withfromcontactid, 'contactid', 3, '', '', 0, 'minwidth200');
  216. $formcompany->selectTypeContact($ticketstatic, '', 'type', 'external', '', 0, 'maginleftonly');
  217. print '</td></tr>';
  218. } else {
  219. print '<tr><td class="titlefield"><input type="hidden" name="socid" value="' . $user->socid . '"/></td>';
  220. print '<td><input type="hidden" name="contactid" value="' . $user->contactid . '"/></td>';
  221. print '<td><input type="hidden" name="type" value="Z"/></td></tr>';
  222. }
  223. }
  224. // TITLE
  225. if ($this->withemail) {
  226. print '<tr><td class="titlefield"><label for="email"><span class="fieldrequired">' . $langs->trans("Email") . '</span></label></td><td>';
  227. print '<input class="text minwidth200" id="email" name="email" value="' . (GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $subject) . '" />';
  228. print '</td></tr>';
  229. }
  230. // Si origin du ticket
  231. if (isset($this->param['origin']) && $this->param['originid'] > 0) {
  232. // Parse element/subelement (ex: project_task)
  233. $element = $subelement = $this->param['origin'];
  234. if (preg_match('/^([^_]+)_([^_]+)/i', $this->param['origin'], $regs)) {
  235. $element = $regs[1];
  236. $subelement = $regs[2];
  237. }
  238. dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
  239. $classname = ucfirst($subelement);
  240. $objectsrc = new $classname($this->db);
  241. $objectsrc->fetch(GETPOST('originid','int'));
  242. if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
  243. $objectsrc->fetch_lines();
  244. }
  245. $objectsrc->fetch_thirdparty();
  246. $newclassname = $classname;
  247. print '<tr><td>' . $langs->trans($newclassname) . '</td><td colspan="2"><input name="' . $subelement . 'id" value="' . GETPOST('originid') . '" type="hidden" />' . $objectsrc->getNomUrl(1) . '</td></tr>';
  248. }
  249. // Type
  250. print '<tr><td class="titlefield"><span class="fieldrequired"><label for="selecttype_code">' . $langs->trans("TicketTypeRequest") . '</span></label></td><td>';
  251. print $this->selectTypesTickets((GETPOST('type_code') ? GETPOST('type_code') : $this->type_code), 'type_code', '', '2');
  252. print '</td></tr>';
  253. // Category
  254. print '<tr><td><span class="fieldrequired"><label for="selectcategory_code">' . $langs->trans("TicketCategory") . '</span></label></td><td>';
  255. print $this->selectCategoriesTickets((GETPOST('category_code') ? GETPOST('category_code') : $this->category_code), 'category_code', '', '2');
  256. print '</td></tr>';
  257. // Severity
  258. print '<tr><td><span class="fieldrequired"><label for="selectseverity_code">' . $langs->trans("TicketSeverity") . '</span></label></td><td>';
  259. print $this->selectSeveritiesTickets((GETPOST('severity_code') ? GETPOST('severity_code') : $this->severity_code), 'severity_code', '', '2');
  260. print '</td></tr>';
  261. // Notify thirdparty at creation
  262. if (empty($this->ispublic))
  263. {
  264. print '<tr><td><label for="notify_tiers_at_create">' . $langs->trans("TicketNotifyTiersAtCreation") . '</label></td><td>';
  265. print '<input type="checkbox" id="notify_tiers_at_create" name="notify_tiers_at_create"'.($this->withnotifytiersatcreate?' checked="checked"':'').'>';
  266. print '</td></tr>';
  267. }
  268. // TITLE
  269. if ($this->withtitletopic) {
  270. print '<tr><td><label for="subject"><span class="fieldrequired">' . $langs->trans("Subject") . '</span></label></td><td>';
  271. // Réponse à un ticket : affichage du titre du thread en readonly
  272. if ($this->withtopicreadonly) {
  273. print $langs->trans('SubjectAnswerToTicket') . ' ' . $this->topic_title;
  274. print '</td></tr>';
  275. } else {
  276. if ($this->withthreadid > 0) {
  277. $subject = $langs->trans('SubjectAnswerToTicket') . ' ' . $this->withthreadid . ' : ' . $this->topic_title . '';
  278. }
  279. print '<input class="text" size="50" id="subject" name="subject" value="' . (GETPOST('subject', 'alpha') ? GETPOST('subject', 'alpha') : $subject) . '" />';
  280. print '</td></tr>';
  281. }
  282. }
  283. // MESSAGE
  284. $msg = GETPOST('message', 'alpha') ? GETPOST('message', 'alpha') : '';
  285. print '<tr><td><label for="message"><span class="fieldrequired">' . $langs->trans("Message") . '</span></label></td><td>';
  286. // If public form, display more information
  287. if ($this->ispublic) {
  288. print '<div class="warning">' . ($conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE ? $conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE : $langs->trans('TicketPublicPleaseBeAccuratelyDescribe')) . '</div>';
  289. }
  290. include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  291. $uselocalbrowser = true;
  292. $doleditor = new DolEditor('message', GETPOST('message', 'alpha'), '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser);
  293. $doleditor->Create();
  294. print '</td></tr>';
  295. // Attached files
  296. if (!empty($this->withfile)) {
  297. // Define list of attached files
  298. $listofpaths = array();
  299. $listofnames = array();
  300. $listofmimes = array();
  301. if (!empty($_SESSION["listofpaths"])) {
  302. $listofpaths = explode(';', $_SESSION["listofpaths"]);
  303. }
  304. if (!empty($_SESSION["listofnames"])) {
  305. $listofnames = explode(';', $_SESSION["listofnames"]);
  306. }
  307. if (!empty($_SESSION["listofmimes"])) {
  308. $listofmimes = explode(';', $_SESSION["listofmimes"]);
  309. }
  310. $out .= '<tr>';
  311. $out .= '<td width="180">' . $langs->trans("MailFile") . '</td>';
  312. $out .= '<td colspan="2">';
  313. // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
  314. $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . "\n";
  315. $out .= '<script type="text/javascript" language="javascript">';
  316. $out .= 'jQuery(document).ready(function () {';
  317. $out .= ' jQuery(".removedfile").click(function() {';
  318. $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
  319. $out .= ' });';
  320. $out .= '})';
  321. $out .= '</script>' . "\n";
  322. if (count($listofpaths)) {
  323. foreach ($listofpaths as $key => $val) {
  324. $out .= '<div id="attachfile_' . $key . '">';
  325. $out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key];
  326. if (!$this->withfilereadonly) {
  327. $out .= ' <input type="image" style="border: 0px;" src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/delete.png" value="' . ($key + 1) . '" class="removedfile" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />';
  328. }
  329. $out .= '<br></div>';
  330. }
  331. } else {
  332. $out .= $langs->trans("NoAttachedFiles") . '<br>';
  333. }
  334. if ($this->withfile == 2) { // Can add other files
  335. $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs->trans("Upload") . '" />';
  336. $out .= ' ';
  337. $out .= '<input type="submit" class="button" id="addfile" name="addfile" value="' . $langs->trans("MailingAddFile") . '" />';
  338. }
  339. $out .= "</td></tr>\n";
  340. print $out;
  341. }
  342. // Other attributes
  343. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $ticketstat, $action); // Note that $action and $object may have been modified by hook
  344. if (empty($reshook))
  345. {
  346. print $ticketstat->showOptionals($extrafields, 'edit');
  347. }
  348. print '</table>';
  349. if ($withdolfichehead) dol_fiche_end();
  350. print '<center>';
  351. print '<input class="button" type="submit" name="add_ticket" value="' . $langs->trans(($this->withthreadid > 0 ? "SendResponse" : "NewTicket")) . '" />';
  352. if ($this->withcancel) {
  353. print " &nbsp; &nbsp; ";
  354. print "<input class=\"button\" type=\"submit\" name=\"cancel\" value=\"" . $langs->trans("Cancel") . "\">";
  355. }
  356. print "</center>\n";
  357. print "</form>\n";
  358. print "<!-- End form TICKET -->\n";
  359. }
  360. /**
  361. * Return html list of tickets type
  362. *
  363. * @param string $selected Id du type pre-selectionne
  364. * @param string $htmlname Nom de la zone select
  365. * @param string $filtertype To filter on field type in llx_c_ticket_type (array('code'=>xx,'label'=>zz))
  366. * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code
  367. * @param int $empty 1=peut etre vide, 0 sinon
  368. * @param int $noadmininfo 0=Add admin info, 1=Disable admin info
  369. * @param int $maxlength Max length of label
  370. * @param string $morecss More CSS
  371. * @return void
  372. */
  373. public function selectTypesTickets($selected = '', $htmlname = 'tickettype', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='')
  374. {
  375. global $langs, $user;
  376. $ticketstat = new Ticket($this->db);
  377. dol_syslog(get_class($this) . "::select_types_tickets " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG);
  378. $filterarray = array();
  379. if ($filtertype != '' && $filtertype != '-1') {
  380. $filterarray = explode(',', $filtertype);
  381. }
  382. $ticketstat->loadCacheTypesTickets();
  383. print '<select id="select' . $htmlname . '" class="flat minwidth100'.($morecss?' '.$morecss:'').'" name="' . $htmlname . '">';
  384. if ($empty) {
  385. print '<option value="">&nbsp;</option>';
  386. }
  387. if (is_array($ticketstat->cache_types_tickets) && count($ticketstat->cache_types_tickets)) {
  388. foreach ($ticketstat->cache_types_tickets as $id => $arraytypes) {
  389. // On passe si on a demande de filtrer sur des modes de paiments particuliers
  390. if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) {
  391. continue;
  392. }
  393. // We discard empty line if showempty is on because an empty line has already been output.
  394. if ($empty && empty($arraytypes['code'])) {
  395. continue;
  396. }
  397. if ($format == 0) {
  398. print '<option value="' . $id . '"';
  399. }
  400. if ($format == 1) {
  401. print '<option value="' . $arraytypes['code'] . '"';
  402. }
  403. if ($format == 2) {
  404. print '<option value="' . $arraytypes['code'] . '"';
  405. }
  406. if ($format == 3) {
  407. print '<option value="' . $id . '"';
  408. }
  409. // Si selected est text, on compare avec code, sinon avec id
  410. if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) {
  411. print ' selected="selected"';
  412. } elseif ($selected == $id) {
  413. print ' selected="selected"';
  414. } elseif ($arraytypes['use_default'] == "1" && !$empty) {
  415. print ' selected="selected"';
  416. }
  417. print '>';
  418. if ($format == 0) {
  419. $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
  420. }
  421. if ($format == 1) {
  422. $value = $arraytypes['code'];
  423. }
  424. if ($format == 2) {
  425. $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
  426. }
  427. if ($format == 3) {
  428. $value = $arraytypes['code'];
  429. }
  430. print $value ? $value : '&nbsp;';
  431. print '</option>';
  432. }
  433. }
  434. print '</select>';
  435. if ($user->admin && !$noadmininfo) {
  436. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  437. }
  438. print ajax_combobox('select'.$htmlname);
  439. }
  440. /**
  441. * Return html list of ticket categories
  442. *
  443. * @param string $selected Id categorie pre-selectionnée
  444. * @param string $htmlname Nom de la zone select
  445. * @param string $filtertype To filter on field type in llx_c_ticket_category (array('code'=>xx,'label'=>zz))
  446. * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code
  447. * @param int $empty 1=peut etre vide, 0 sinon
  448. * @param int $noadmininfo 0=Add admin info, 1=Disable admin info
  449. * @param int $maxlength Max length of label
  450. * @param string $morecss More CSS
  451. * @return void
  452. */
  453. public function selectCategoriesTickets($selected = '', $htmlname = 'ticketcategory', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='')
  454. {
  455. global $langs, $user;
  456. $ticketstat = new Ticket($this->db);
  457. dol_syslog(get_class($this) . "::selectCategoryTickets " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG);
  458. $filterarray = array();
  459. if ($filtertype != '' && $filtertype != '-1') {
  460. $filterarray = explode(',', $filtertype);
  461. }
  462. $ticketstat->loadCacheCategoriesTickets();
  463. print '<select id="select' . $htmlname . '" class="flat minwidth100'.($morecss?' '.$morecss:'').'" name="' . $htmlname . '">';
  464. if ($empty) {
  465. print '<option value="">&nbsp;</option>';
  466. }
  467. if (is_array($ticketstat->cache_category_tickets) && count($ticketstat->cache_category_tickets)) {
  468. foreach ($ticketstat->cache_category_tickets as $id => $arraycategories) {
  469. // On passe si on a demande de filtrer sur des modes de paiments particuliers
  470. if (count($filterarray) && !in_array($arraycategories['type'], $filterarray)) {
  471. continue;
  472. }
  473. // We discard empty line if showempty is on because an empty line has already been output.
  474. if ($empty && empty($arraycategories['code'])) {
  475. continue;
  476. }
  477. if ($format == 0) {
  478. print '<option value="' . $id . '"';
  479. }
  480. if ($format == 1) {
  481. print '<option value="' . $arraycategories['code'] . '"';
  482. }
  483. if ($format == 2) {
  484. print '<option value="' . $arraycategories['code'] . '"';
  485. }
  486. if ($format == 3) {
  487. print '<option value="' . $id . '"';
  488. }
  489. // Si selected est text, on compare avec code, sinon avec id
  490. if (preg_match('/[a-z]/i', $selected) && $selected == $arraycategories['code']) {
  491. print ' selected="selected"';
  492. } elseif ($selected == $id) {
  493. print ' selected="selected"';
  494. } elseif ($arraycategories['use_default'] == "1" && !$empty) {
  495. print ' selected="selected"';
  496. }
  497. print '>';
  498. if ($format == 0) {
  499. $value = ($maxlength ? dol_trunc($arraycategories['label'], $maxlength) : $arraycategories['label']);
  500. }
  501. if ($format == 1) {
  502. $value = $arraycategories['code'];
  503. }
  504. if ($format == 2) {
  505. $value = ($maxlength ? dol_trunc($arraycategories['label'], $maxlength) : $arraycategories['label']);
  506. }
  507. if ($format == 3) {
  508. $value = $arraycategories['code'];
  509. }
  510. print $value ? $value : '&nbsp;';
  511. print '</option>';
  512. }
  513. }
  514. print '</select>';
  515. if ($user->admin && !$noadmininfo) {
  516. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  517. }
  518. print ajax_combobox('select'.$htmlname);
  519. }
  520. /**
  521. * Return html list of ticket severitys
  522. *
  523. * @param string $selected Id severity pre-selectionnée
  524. * @param string $htmlname Nom de la zone select
  525. * @param string $filtertype To filter on field type in llx_c_ticket_severity (array('code'=>xx,'label'=>zz))
  526. * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code
  527. * @param int $empty 1=peut etre vide, 0 sinon
  528. * @param int $noadmininfo 0=Add admin info, 1=Disable admin info
  529. * @param int $maxlength Max length of label
  530. * @param string $morecss More CSS
  531. * @return void
  532. */
  533. public function selectSeveritiesTickets($selected = '', $htmlname = 'ticketseverity', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='')
  534. {
  535. global $langs, $user;
  536. $ticketstat = new Ticket($this->db);
  537. dol_syslog(get_class($this) . "::selectSeveritiesTickets " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG);
  538. $filterarray = array();
  539. if ($filtertype != '' && $filtertype != '-1') {
  540. $filterarray = explode(',', $filtertype);
  541. }
  542. $ticketstat->loadCacheSeveritiesTickets();
  543. print '<select id="select' . $htmlname . '" class="flat minwidth150'.($morecss?' '.$morecss:'').'" name="' . $htmlname . '">';
  544. if ($empty) {
  545. print '<option value="">&nbsp;</option>';
  546. }
  547. if (is_array($ticketstat->cache_severity_tickets) && count($ticketstat->cache_severity_tickets)) {
  548. foreach ($ticketstat->cache_severity_tickets as $id => $arrayseverities) {
  549. // On passe si on a demande de filtrer sur des modes de paiments particuliers
  550. if (count($filterarray) && !in_array($arrayseverities['type'], $filterarray)) {
  551. continue;
  552. }
  553. // We discard empty line if showempty is on because an empty line has already been output.
  554. if ($empty && empty($arrayseverities['code'])) {
  555. continue;
  556. }
  557. if ($format == 0) {
  558. print '<option value="' . $id . '"';
  559. }
  560. if ($format == 1) {
  561. print '<option value="' . $arrayseverities['code'] . '"';
  562. }
  563. if ($format == 2) {
  564. print '<option value="' . $arrayseverities['code'] . '"';
  565. }
  566. if ($format == 3) {
  567. print '<option value="' . $id . '"';
  568. }
  569. // Si selected est text, on compare avec code, sinon avec id
  570. if (preg_match('/[a-z]/i', $selected) && $selected == $arrayseverities['code']) {
  571. print ' selected="selected"';
  572. } elseif ($selected == $id) {
  573. print ' selected="selected"';
  574. } elseif ($arrayseverities['use_default'] == "1" && !$empty) {
  575. print ' selected="selected"';
  576. }
  577. print '>';
  578. if ($format == 0) {
  579. $value = ($maxlength ? dol_trunc($arrayseverities['label'], $maxlength) : $arrayseverities['label']);
  580. }
  581. if ($format == 1) {
  582. $value = $arrayseverities['code'];
  583. }
  584. if ($format == 2) {
  585. $value = ($maxlength ? dol_trunc($arrayseverities['label'], $maxlength) : $arrayseverities['label']);
  586. }
  587. if ($format == 3) {
  588. $value = $arrayseverities['code'];
  589. }
  590. print $value ? $value : '&nbsp;';
  591. print '</option>';
  592. }
  593. }
  594. print '</select>';
  595. if ($user->admin && !$noadmininfo) {
  596. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  597. }
  598. print ajax_combobox('select'.$htmlname);
  599. }
  600. /**
  601. * Show the form to add message on ticket
  602. *
  603. * @param string $width Width of form
  604. * @return void
  605. */
  606. public function showMessageForm($width = '40%')
  607. {
  608. global $conf, $langs, $user, $mysoc;
  609. // Load translation files required by the page
  610. $langs->loadLangs(array('other', 'mails'));
  611. $addfileaction = 'addfile';
  612. $form = new Form($this->db);
  613. $formmail = new FormMail($this->db);
  614. // Define list of attached files
  615. $listofpaths = array();
  616. $listofnames = array();
  617. $listofmimes = array();
  618. if (!empty($_SESSION["listofpaths"])) {
  619. $listofpaths = explode(';', $_SESSION["listofpaths"]);
  620. }
  621. if (!empty($_SESSION["listofnames"])) {
  622. $listofnames = explode(';', $_SESSION["listofnames"]);
  623. }
  624. if (!empty($_SESSION["listofmimes"])) {
  625. $listofmimes = explode(';', $_SESSION["listofmimes"]);
  626. }
  627. // Define output language
  628. $outputlangs = $langs;
  629. $newlang = '';
  630. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  631. $newlang = $this->param['langsmodels'];
  632. }
  633. if (! empty($newlang)) {
  634. $outputlangs = new Translate("", $conf);
  635. $outputlangs->setDefaultLang($newlang);
  636. $outputlangs->load('other');
  637. }
  638. print "\n<!-- Begin message_form TICKETSUP -->\n";
  639. $send_email = GETPOST('send_email', 'int') ? GETPOST('send_email', 'int') : 0;
  640. // Example 1 : Adding jquery code
  641. print '<script type="text/javascript" language="javascript">
  642. jQuery(document).ready(function() {
  643. send_email=' . $send_email . ';
  644. if (send_email) {
  645. jQuery(".email_line").show();
  646. } else {
  647. jQuery(".email_line").hide();
  648. }
  649. jQuery("#send_msg_email").click(function() {
  650. if(jQuery(this).is(":checked")) {
  651. jQuery(".email_line").show();
  652. }
  653. else {
  654. jQuery(".email_line").hide();
  655. }
  656. });';
  657. print '});
  658. </script>';
  659. print '<form method="post" name="ticket" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">';
  660. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  661. print '<input type="hidden" name="action" value="' . $this->action . '">';
  662. foreach ($this->param as $key => $value) {
  663. print '<input type="hidden" name="' . $key . '" value="' . $value . '">';
  664. }
  665. // Get message template
  666. $model_id=0;
  667. if (array_key_exists('models_id', $this->param)) {
  668. $model_id=$this->param["models_id"];
  669. $arraydefaultmessage=$formmail->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id);
  670. }
  671. $result = $formmail->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
  672. if ($result<0) {
  673. setEventMessages($this->error, $this->errors, 'errors');
  674. }
  675. $modelmail_array=array();
  676. foreach ($formmail->lines_model as $line) {
  677. $modelmail_array[$line->id]=$line->label;
  678. }
  679. print '<table class="border" width="' . $width . '">';
  680. // External users can't send message email
  681. if ($user->rights->ticket->write && !$user->socid) {
  682. print '<tr><td width="30%"></td><td colspan="2">';
  683. $checkbox_selected = ( GETPOST('send_email') == "1" ? ' checked' : '');
  684. print '<input type="checkbox" name="send_email" value="1" id="send_msg_email" '.$checkbox_selected.'/> ';
  685. print '<label for="send_msg_email">' . $langs->trans('SendMessageByEmail') . '</label>';
  686. print '</td></tr>';
  687. // Zone to select its email template
  688. if (count($modelmail_array)>0) {
  689. print '<tr class="email_line"><td></td><td colspan="2"><div style="padding: 3px 0 3px 0">'."\n";
  690. print $langs->trans('SelectMailModel').': '.$formmail->selectarray('modelmailselected', $modelmail_array, $this->param['models_id'], 1);
  691. if ($user->admin) {
  692. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  693. }
  694. print ' &nbsp; ';
  695. print '<input class="button" type="submit" value="'.$langs->trans('Use').'" name="modelselected" id="modelselected">';
  696. print ' &nbsp; ';
  697. print '</div></td>';
  698. }
  699. // Substitution array
  700. if ($this->withsubstit) {
  701. print '<tr class="email_line"><td></td><td colspan="2">';
  702. $help="";
  703. foreach ($this->substit as $key => $val) {
  704. $help.=$key.' -> '.$langs->trans($val).'<br>';
  705. }
  706. print $form->textwithpicto($langs->trans("TicketMessageSubstitutionReplacedByGenericValues"), $help);
  707. print "</td></tr>";
  708. }
  709. if (! $user->socid) {
  710. print '<tr><td width="30%"></td><td>';
  711. $checkbox_selected = ( GETPOST('private_message') == "1" ? ' checked' : '');
  712. print '<input type="checkbox" name="private_message" value="1" id="private_message" '.$checkbox_selected.'/> ';
  713. print '<label for="private_message">' . $langs->trans('MarkMessageAsPrivate') . '</label>';
  714. print '</td><td align="center">';
  715. print $form->textwithpicto('', $langs->trans("TicketMessagePrivateHelp"), 1, 'help');
  716. print '</td></tr>';
  717. }
  718. print '<tr class="email_line"><td width=20%">' . $langs->trans('Subject') . '</td>';
  719. $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
  720. print '<td colspan="2"><input type="text" class="text" size="80" name="subject" value="[' . $label_title . ' - ticket #' . $this->track_id . '] ' . $langs->trans('TicketNewMessage') . '" />';
  721. print '</td></tr>';
  722. // Destinataires
  723. print '<tr class="email_line"><td>' . $langs->trans('MailRecipients') . '</td><td colspan="2">';
  724. $ticketstat = new Ticket($this->db);
  725. $res = $ticketstat->fetch('', '', $this->track_id);
  726. if ($res) {
  727. // Retrieve email of all contacts (internal and external)
  728. $contacts = $ticketstat->getInfosTicketInternalContact();
  729. $contacts = array_merge($contacts, $ticketstat->getInfosTicketExternalContact());
  730. // Build array to display recipient list
  731. if (is_array($contacts) && count($contacts) > 0) {
  732. foreach ($contacts as $key => $info_sendto) {
  733. if ($info_sendto['email'] != '') {
  734. $sendto[] = dol_escape_htmltag(trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . "> (" . $info_sendto['libelle'] . ")");
  735. }
  736. }
  737. }
  738. if ($ticketstat->origin_email && !in_array($this->dao->origin_email, $sendto)) {
  739. $sendto[] = $ticketstat->origin_email . "(origin)";
  740. }
  741. if ($ticketstat->fk_soc > 0) {
  742. $ticketstat->socid = $ticketstat->fk_soc;
  743. $ticketstat->fetch_thirdparty();
  744. if (is_array($ticketstat->thirdparty->email) && !in_array($ticketstat->thirdparty->email, $sendto)) {
  745. $sendto[] = $ticketstat->thirdparty->email . '(' . $langs->trans('Customer') . ')';
  746. }
  747. }
  748. if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) {
  749. $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO . '(generic email)';
  750. }
  751. // Print recipient list
  752. if (is_array($sendto) && count($sendto) > 0) {
  753. print implode(', ', $sendto);
  754. } else {
  755. print '<div class="warning">' . $langs->trans('WarningNoEMailsAdded') . ' ' . $langs->trans('TicketGoIntoContactTab') . '</div>';
  756. }
  757. }
  758. print '</td></tr>';
  759. }
  760. // Intro
  761. // External users can't send message email
  762. if ($user->rights->ticket->write && !$user->socid) {
  763. $mail_intro = GETPOST('mail_intro') ? GETPOST('mail_intro') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
  764. print '<tr class="email_line"><td><label for="mail_intro">' . $langs->trans("TicketMessageMailIntro") . '</label>';
  765. print '</td><td>';
  766. include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  767. $uselocalbrowser = true;
  768. $doleditor = new DolEditor('mail_intro', $mail_intro, '100%', 140, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_2, 70);
  769. $doleditor->Create();
  770. print '</td><td align="center">';
  771. print $form->textwithpicto('', $langs->trans("TicketMessageMailIntroHelp"), 1, 'help');
  772. print '</td></tr>';
  773. }
  774. // MESSAGE
  775. $defaultmessage="";
  776. if (is_array($arraydefaultmessage) && count($arraydefaultmessage) > 0 && $arraydefaultmessage->content) {
  777. $defaultmessage=$arraydefaultmessage->content;
  778. }
  779. $defaultmessage=str_replace('\n', "\n", $defaultmessage);
  780. // Deal with format differences between message and signature (text / HTML)
  781. if (dol_textishtml($defaultmessage) && !dol_textishtml($this->substit['__SIGNATURE__'])) {
  782. $this->substit['__SIGNATURE__'] = dol_nl2br($this->substit['__SIGNATURE__']);
  783. } elseif (!dol_textishtml($defaultmessage) && dol_textishtml($this->substit['__SIGNATURE__'])) {
  784. $defaultmessage = dol_nl2br($defaultmessage);
  785. }
  786. if (isset($_POST["message"]) && ! $_POST['modelselected']) {
  787. $defaultmessage=GETPOST('message');
  788. } else {
  789. $defaultmessage=make_substitutions($defaultmessage, $this->substit);
  790. // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
  791. $defaultmessage=preg_replace("/^(<br>)+/", "", $defaultmessage);
  792. $defaultmessage=preg_replace("/^\n+/", "", $defaultmessage);
  793. }
  794. print '<tr><td><label for="message"><span class="fieldrequired">' . $langs->trans("Message") . '</span></label></td><td>';
  795. include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  796. $doleditor = new DolEditor('message', $defaultmessage, '100%', 350, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_2, 70);
  797. $doleditor->Create();
  798. print '</td><td align="center">';
  799. if ($user->rights->ticket->write && !$user->socid) {
  800. print $form->textwithpicto('', $langs->trans("TicketMessageHelp"), 1, 'help');
  801. }
  802. print '</td></tr>';
  803. // Signature
  804. // External users can't send message email
  805. if ($user->rights->ticket->write && !$user->socid) {
  806. $mail_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
  807. print '<tr class="email_line"><td><label for="mail_intro">' . $langs->trans("TicketMessageMailSignature") . '</label>';
  808. print '</td><td>';
  809. include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  810. $doleditor = new DolEditor('mail_signature', $mail_signature, '100%', 150, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_2, 70);
  811. $doleditor->Create();
  812. print '</td><td align="center">';
  813. print $form->textwithpicto('', $langs->trans("TicketMessageMailSignatureHelp"), 1, 'help');
  814. print '</td></tr>';
  815. }
  816. // Attached files
  817. if (!empty($this->withfile)) {
  818. $out .= '<tr>';
  819. $out .= '<td width="180">' . $langs->trans("MailFile") . '</td>';
  820. $out .= '<td colspan="2">';
  821. // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
  822. $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . "\n";
  823. $out .= '<script type="text/javascript" language="javascript">';
  824. $out .= 'jQuery(document).ready(function () {';
  825. $out .= ' jQuery(".removedfile").click(function() {';
  826. $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
  827. $out .= ' });';
  828. $out .= '})';
  829. $out .= '</script>' . "\n";
  830. if (count($listofpaths)) {
  831. foreach ($listofpaths as $key => $val) {
  832. $out .= '<div id="attachfile_' . $key . '">';
  833. $out .= img_mime($listofnames[$key]) . ' ' . $listofnames[$key];
  834. if (!$this->withfilereadonly) {
  835. $out .= ' <input type="image" style="border: 0px;" src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/delete.png" value="' . ($key + 1) . '" class="removedfile" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />';
  836. }
  837. $out .= '<br></div>';
  838. }
  839. } else {
  840. $out .= $langs->trans("NoAttachedFiles") . '<br>';
  841. }
  842. if ($this->withfile == 2) { // Can add other files
  843. $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs->trans("Upload") . '" />';
  844. $out .= ' ';
  845. $out .= '<input type="submit" class="button" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs->trans("MailingAddFile") . '" />';
  846. }
  847. $out .= "</td></tr>\n";
  848. print $out;
  849. }
  850. print '<tr><td colspan="3">';
  851. print '<center>';
  852. print '<input class="button" type="submit" name="btn_add_message" value="' . $langs->trans("AddMessage") . '" />';
  853. if ($this->withcancel) {
  854. print " &nbsp; &nbsp; ";
  855. print "<input class=\"button\" type=\"submit\" name=\"cancel\" value=\"" . $langs->trans("Cancel") . "\">";
  856. }
  857. print "</center>\n";
  858. print '</td></tr>';
  859. print '</table>';
  860. print "</form>\n";
  861. print "<!-- End form TICKET -->\n";
  862. }
  863. }