Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

manage_ticket_templates.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <?php
  2. /**
  3. *
  4. * This file is part of HESK - PHP Help Desk Software.
  5. *
  6. * (c) Copyright Klemen Stirn. All rights reserved.
  7. * https://www.hesk.com
  8. *
  9. * For the full copyright and license agreement information visit
  10. * https://www.hesk.com/eula.php
  11. *
  12. */
  13. define('IN_SCRIPT', 1);
  14. define('HESK_PATH', '../');
  15. define('VALIDATOR', 1);
  16. define('PAGE_TITLE', 'ADMIN_TICKET_TPL');
  17. define('MFH_PAGE_LAYOUT', 'TOP_ONLY');
  18. /* Get all the required files and functions */
  19. require(HESK_PATH . 'hesk_settings.inc.php');
  20. require(HESK_PATH . 'inc/common.inc.php');
  21. require(HESK_PATH . 'inc/admin_functions.inc.php');
  22. require(HESK_PATH . 'inc/mail_functions.inc.php');
  23. hesk_load_database_functions();
  24. hesk_session_start();
  25. hesk_dbConnect();
  26. hesk_isLoggedIn();
  27. $modsForHesk_settings = mfh_getSettings();
  28. /* Check permissions for this feature */
  29. hesk_checkPermission('can_man_ticket_tpl');
  30. // Define required constants
  31. define('LOAD_TABS', 1);
  32. if ($modsForHesk_settings['rich_text_for_tickets']) {
  33. define('WYSIWYG', 1);
  34. }
  35. /* What should we do? */
  36. if ($action = hesk_REQUEST('a')) {
  37. if (defined('HESK_DEMO')) {
  38. hesk_process_messages($hesklang['ddemo'], 'manage_ticket_templates.php', 'NOTICE');
  39. } elseif ($action == 'new') {
  40. new_saved();
  41. } elseif ($action == 'edit') {
  42. edit_saved();
  43. } elseif ($action == 'remove') {
  44. remove();
  45. } elseif ($action == 'order') {
  46. order_saved();
  47. }
  48. }
  49. /* Print header */
  50. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  51. /* Print main manage users page */
  52. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  53. ?>
  54. <script language="javascript" type="text/javascript"><!--
  55. function confirm_delete() {
  56. if (confirm('<?php echo hesk_makeJsString($hesklang['delete_tpl']); ?>')) {
  57. return true;
  58. }
  59. else {
  60. return false;
  61. }
  62. }
  63. //-->
  64. </script>
  65. <?php
  66. // Get canned responses from database
  67. $result = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'ticket_templates` ORDER BY `tpl_order` ASC');
  68. $options = '';
  69. $javascript_messages = '';
  70. $javascript_titles = '';
  71. $i = 1;
  72. $j = 0;
  73. $num = hesk_dbNumRows($result);
  74. ?>
  75. <div class="content-wrapper">
  76. <section class="content">
  77. <div class="box">
  78. <div class="box-header with-border">
  79. <h1 class="box-title">
  80. <?php echo $hesklang['saved_ticket_tpl']; ?>
  81. </h1>
  82. <div class="box-tools pull-right">
  83. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  84. <i class="fa fa-minus"></i>
  85. </button>
  86. </div>
  87. </div>
  88. <div class="box-body">
  89. <?php if ($num < 1) {
  90. echo '<p>' . $hesklang['no_ticket_tpl'] . '</p>';
  91. } else {
  92. ?>
  93. <table class="table table-hover">
  94. <thead>
  95. <tr>
  96. <th><?php echo $hesklang['ticket_tpl_title']; ?></th>
  97. <th><?php echo $hesklang['opt']; ?></th>
  98. </tr>
  99. </thead>
  100. <tbody>
  101. <?php
  102. while ($mysaved = hesk_dbFetchAssoc($result)) {
  103. $j++;
  104. $color = '';
  105. if (isset($_SESSION['canned']['selcat2']) && $mysaved['id'] == $_SESSION['canned']['selcat2']) {
  106. $color = 'success';
  107. unset($_SESSION['canned']['selcat2']);
  108. }
  109. $options .= '<option class="form-control" value="' . $mysaved['id'] . '"';
  110. $options .= (isset($_SESSION['canned']['id']) && $_SESSION['canned']['id'] == $mysaved['id']) ? ' selected="selected" ' : '';
  111. $options .= '>' . $mysaved['title'] . '</option>';
  112. if ($modsForHesk_settings['rich_text_for_tickets']) {
  113. $theMessage = html_entity_decode($mysaved['message']);
  114. $theMessage = addslashes($theMessage);
  115. $javascript_messages .= 'myMsgTxt[' . $mysaved['id'] . ']=\'' . str_replace("\r\n", "\\r\\n' + \r\n'", $theMessage) . "';\n";
  116. } else {
  117. $javascript_messages .= 'myMsgTxt[' . $mysaved['id'] . ']=\'' . str_replace("\r\n", "\\r\\n' + \r\n'", addslashes($mysaved['message'])) . "';\n";
  118. }
  119. $javascript_titles .= 'myTitle[' . $mysaved['id'] . ']=\'' . addslashes($mysaved['title']) . "';\n";
  120. echo '
  121. <tr>
  122. <td>' . $mysaved['title'] . '</td>
  123. <td class="text-left">
  124. ';
  125. if ($num > 1) {
  126. if ($j == 1) {
  127. echo '<img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />
  128. <a href="manage_ticket_templates.php?a=order&amp;replyid=' . $mysaved['id'] . '&amp;move=15&amp;token=' . hesk_token_echo(0) . '">
  129. <i class="fa fa-arrow-down icon-link green" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['move_dn'] . '"></i></a>';
  130. } elseif ($j == $num) {
  131. echo '<a href="manage_ticket_templates.php?a=order&amp;replyid=' . $mysaved['id'] . '&amp;move=-15&amp;token=' . hesk_token_echo(0) . '"><i class="fa fa-arrow-up icon-link green" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['move_up'] . '"></i></a> <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />';
  132. } else {
  133. echo '
  134. <a href="manage_ticket_templates.php?a=order&amp;replyid=' . $mysaved['id'] . '&amp;move=-15&amp;token=' . hesk_token_echo(0) . '"><i class="fa fa-arrow-up icon-link green" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['move_up'] . '"></i></a>
  135. <a href="manage_ticket_templates.php?a=order&amp;replyid=' . $mysaved['id'] . '&amp;move=15&amp;token=' . hesk_token_echo(0) . '"><i class="fa fa-arrow-down icon-link green" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['move_dn'] . '"></i></a>
  136. ';
  137. }
  138. } else {
  139. echo '';
  140. }
  141. echo '
  142. <a name="'.$mysaved['title'].'" href="manage_ticket_templates.php?a=remove&amp;id=' . $mysaved['id'] . '&amp;token=' . hesk_token_echo(0) . '" onclick="return confirm_delete();"><i class="fa fa-times icon-link red" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['delete'] . '"></i></a></td>
  143. </tr>
  144. ';
  145. } // End while
  146. ?>
  147. </tbody>
  148. </table>
  149. <?php
  150. }
  151. ?>
  152. </div>
  153. </div>
  154. <div class="box">
  155. <div class="box-header with-border">
  156. <h1 class="box-title">
  157. <?php echo $hesklang['new_ticket_tpl']; ?>
  158. <a href="javascript:void(0)"
  159. onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['ticket_tpl_intro']); ?>')"><i
  160. class="fa fa-question-circle settingsquestionmark"></i></a>
  161. </h1>
  162. <div class="box-tools pull-right">
  163. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  164. <i class="fa fa-minus"></i>
  165. </button>
  166. </div>
  167. </div>
  168. <div class="box-body">
  169. <?php
  170. /* This will handle error, success and notice messages */
  171. hesk_handle_messages();
  172. $onsubmit = '';
  173. if ($modsForHesk_settings['rich_text_for_tickets']) {
  174. $onsubmit = 'onsubmit="return validateRichText(\'message-help-block\', \'message-group\', \'message\', \''.htmlspecialchars($hesklang['this_field_is_required']).'\')"';
  175. }
  176. ?>
  177. <form class="form-horizontal" action="manage_ticket_templates.php" method="post" name="form1" role="form" data-toggle="validator" <?php echo $onsubmit; ?>>
  178. <?php
  179. if ($num > 0) {
  180. ?>
  181. <div class="form-group">
  182. <div class="col-sm-12">
  183. <div class="row">
  184. <div class="col-sm-12">
  185. <div class="radio">
  186. <label>
  187. <input type="radio" name="a"
  188. value="new" <?php echo (!isset($_SESSION['canned']['what']) || $_SESSION['canned']['what'] != 'EDIT') ? 'checked=' : ''; ?>>
  189. <?php echo $hesklang['ticket_tpl_add']; ?>
  190. </label>
  191. </div>
  192. </div>
  193. </div>
  194. <div class="row">
  195. <div class="col-sm-6">
  196. <div class="radio">
  197. <label>
  198. <input type="radio" name="a"
  199. value="edit" <?php echo (isset($_SESSION['canned']['what']) && $_SESSION['canned']['what'] == 'EDIT') ? 'checked' : ''; ?>>
  200. <?php echo $hesklang['ticket_tpl_edit']; ?>
  201. </label>
  202. </div>
  203. </div>
  204. <div class="col-sm-6">
  205. <select class="form-control" name="saved_replies" onchange="setMessage(this.value)">
  206. <option value="0"> - <?php echo $hesklang['select_empty']; ?>-
  207. </option><?php echo $options; ?></select>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. <?php
  213. } else {
  214. echo '<p><input type="hidden" name="a" value="new" /> ' . $hesklang['ticket_tpl_add'] . '</label></p>';
  215. }
  216. ?>
  217. <div class="form-group">
  218. <label for="name" class="col-sm-2 control-label"><?php echo $hesklang['ticket_tpl_title']; ?></label>
  219. <div class="col-sm-10">
  220. <span id="HeskTitle">
  221. <input id="subject" class="form-control" type="text" name="name" size="40" maxlength="50"
  222. data-error="<?php echo htmlspecialchars($hesklang['this_field_is_required']); ?>"
  223. placeholder="<?php echo htmlspecialchars($hesklang['ticket_tpl_title']); ?>"
  224. <?php if (isset($_SESSION['canned']['name'])) {
  225. echo ' value="' . stripslashes($_SESSION['canned']['name']) . '" ';
  226. } ?> required>
  227. </span>
  228. <div class="help-block with-errors"></div>
  229. </div>
  230. </div>
  231. <div class="form-group" id="message-group">
  232. <label for="msg" class="col-sm-2 control-label"><?php echo $hesklang['message']; ?></label>
  233. <div class="col-sm-10">
  234. <span id="HeskMsg">
  235. <textarea id="message" class="form-control htmlEditor"
  236. data-error="<?php echo htmlspecialchars($hesklang['this_field_is_required']); ?>"
  237. placeholder="<?php echo htmlspecialchars($hesklang['message']); ?>" name="msg"
  238. rows="15" cols="70" required><?php
  239. if (isset($_SESSION['canned']['msg'])) {
  240. if ($modsForHesk_settings['rich_text_for_tickets']) {
  241. echo $_SESSION['canned']['msg'];
  242. } else {
  243. echo stripslashes($_SESSION['canned']['msg']);
  244. }
  245. }
  246. ?></textarea>
  247. </span>
  248. <div class="help-block with-errors" id="message-help-block"></div>
  249. </div>
  250. </div>
  251. <div class="form-group">
  252. <div class="col-sm-10 col-sm-offset-2">
  253. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>"/>
  254. <input type="submit" value="<?php echo $hesklang['save_ticket_tpl']; ?>" class="btn btn-default">
  255. </div>
  256. </div>
  257. </form>
  258. </div>
  259. </div>
  260. </section>
  261. </div>
  262. <?php if ($modsForHesk_settings['rich_text_for_tickets']): ?>
  263. <script type="text/javascript">
  264. /* <![CDATA[ */
  265. $(document).ready(function() {
  266. $('.htmlEditor').summernote({
  267. height: 200,
  268. toolbar: [
  269. ['style', ['bold', 'italic', 'underline', 'clear']],
  270. ['font', ['strikethrough', 'superscript', 'subscript']],
  271. ['para', ['ul', 'ol']]
  272. ]
  273. });
  274. });
  275. /* ]]> */
  276. </script>
  277. <?php endif; ?>
  278. <script language="javascript" type="text/javascript"><!--
  279. // -->
  280. var myMsgTxt = new Array();
  281. var myTitle = new Array();
  282. myMsgTxt[0] = '';
  283. myTitle[0] = '';
  284. <?php
  285. echo $javascript_titles;
  286. echo $javascript_messages;
  287. ?>
  288. function setMessage(msgid) {
  289. var useHtmlEditor = <?php echo $modsForHesk_settings['rich_text_for_tickets']; ?>;
  290. var myMsg = myMsgTxt[msgid];
  291. var mySubject = myTitle[msgid];
  292. if (myMsg == '') {
  293. if (useHtmlEditor) {
  294. $("#message").summernote('reset');
  295. }
  296. else {
  297. $('#message').val('');
  298. }
  299. $('#subject').val('');
  300. return true;
  301. }
  302. if (document.getElementById) {
  303. if (useHtmlEditor) {
  304. $("#message").summernote('reset');
  305. $("#message").summernote('editor.insertText', myMsg));
  306. } else {
  307. myMsg = $('<textarea />').html(myMsg).text();
  308. $('#message').val(myMsg).trigger('input');
  309. }
  310. mySubject = $('<textarea />').html(mySubject).text();
  311. $('#subject').val(mySubject).trigger('input');
  312. }
  313. else {
  314. document.form1.message.value = myMsg;
  315. document.form1.subject.value = mySubject;
  316. }
  317. if (msgid == 0) {
  318. document.form1.a[0].checked = true;
  319. } else {
  320. document.form1.a[1].checked = true;
  321. }
  322. }
  323. //-->
  324. </script>
  325. <?php
  326. require_once(HESK_PATH . 'inc/footer.inc.php');
  327. exit();
  328. /*** START FUNCTIONS ***/
  329. function edit_saved()
  330. {
  331. global $hesk_settings, $hesklang;
  332. /* A security check */
  333. hesk_token_check('POST');
  334. $hesk_error_buffer = '';
  335. $id = intval(hesk_POST('saved_replies')) or $hesk_error_buffer .= '<li>' . $hesklang['sel_ticket_tpl'] . '</li>';
  336. $savename = hesk_input(hesk_POST('name')) or $hesk_error_buffer .= '<li>' . $hesklang['ent_ticket_tpl_title'] . '</li>';
  337. $msg = hesk_input(hesk_POST('msg')) or $hesk_error_buffer .= '<li>' . $hesklang['ent_ticket_tpl_msg'] . '</li>';
  338. // Avoid problems with utf-8 newline chars in Javascript code, detect and remove them
  339. $msg = preg_replace('/\R/u', "\r\n", $msg);
  340. $_SESSION['canned']['what'] = 'EDIT';
  341. $_SESSION['canned']['id'] = $id;
  342. $_SESSION['canned']['name'] = $savename;
  343. $_SESSION['canned']['msg'] = $msg;
  344. /* Any errors? */
  345. if (strlen($hesk_error_buffer)) {
  346. $hesk_error_buffer = $hesklang['rfm'] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>';
  347. hesk_process_messages($hesk_error_buffer, 'manage_ticket_templates.php?saved_replies=' . $id);
  348. }
  349. $result = hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `title`='" . hesk_dbEscape($savename) . "',`message`='" . hesk_dbEscape($msg) . "' WHERE `id`='" . intval($id) . "'");
  350. unset($_SESSION['canned']['what']);
  351. unset($_SESSION['canned']['id']);
  352. unset($_SESSION['canned']['name']);
  353. unset($_SESSION['canned']['msg']);
  354. hesk_process_messages($hesklang['ticket_tpl_saved'], 'manage_ticket_templates.php?saved_replies=' . $id, 'SUCCESS');
  355. } // End edit_saved()
  356. function new_saved()
  357. {
  358. global $hesk_settings, $hesklang;
  359. /* A security check */
  360. hesk_token_check('POST');
  361. $hesk_error_buffer = '';
  362. $savename = hesk_input(hesk_POST('name')) or $hesk_error_buffer .= '<li>' . $hesklang['ent_ticket_tpl_title'] . '</li>';
  363. $msg = hesk_input(hesk_POST('msg')) or $hesk_error_buffer .= '<li>' . $hesklang['ent_ticket_tpl_msg'] . '</li>';
  364. // Avoid problems with utf-8 newline chars in Javascript code, detect and remove them
  365. $msg = preg_replace('/\R/u', "\r\n", $msg);
  366. $_SESSION['canned']['what'] = 'NEW';
  367. $_SESSION['canned']['name'] = $savename;
  368. $_SESSION['canned']['msg'] = $msg;
  369. /* Any errors? */
  370. if (strlen($hesk_error_buffer)) {
  371. $hesk_error_buffer = $hesklang['rfm'] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>';
  372. hesk_process_messages($hesk_error_buffer, 'manage_ticket_templates.php');
  373. }
  374. /* Get the latest tpl_order */
  375. $result = hesk_dbQuery('SELECT `tpl_order` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'ticket_templates` ORDER BY `tpl_order` DESC LIMIT 1');
  376. $row = hesk_dbFetchRow($result);
  377. $my_order = $row[0] + 10;
  378. hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` (`title`,`message`,`tpl_order`) VALUES ('" . hesk_dbEscape($savename) . "','" . hesk_dbEscape($msg) . "','" . intval($my_order) . "')");
  379. unset($_SESSION['canned']['what']);
  380. unset($_SESSION['canned']['name']);
  381. unset($_SESSION['canned']['msg']);
  382. hesk_process_messages($hesklang['ticket_tpl_saved'], 'manage_ticket_templates.php', 'SUCCESS');
  383. } // End new_saved()
  384. function remove()
  385. {
  386. global $hesk_settings, $hesklang;
  387. /* A security check */
  388. hesk_token_check();
  389. $mysaved = intval(hesk_GET('id')) or hesk_error($hesklang['id_not_valid']);
  390. hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` WHERE `id`='" . intval($mysaved) . "'");
  391. if (hesk_dbAffectedRows() != 1) {
  392. hesk_error("$hesklang[int_error]: $hesklang[ticket_tpl_not_found].");
  393. }
  394. hesk_process_messages($hesklang['ticket_tpl_removed'], 'manage_ticket_templates.php', 'SUCCESS');
  395. } // End remove()
  396. function order_saved()
  397. {
  398. global $hesk_settings, $hesklang;
  399. /* A security check */
  400. hesk_token_check();
  401. $tplid = intval(hesk_GET('replyid')) or hesk_error($hesklang['ticket_tpl_id']);
  402. $_SESSION['canned']['selcat2'] = $tplid;
  403. $tpl_move = intval(hesk_GET('move'));
  404. hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `tpl_order`=`tpl_order`+" . intval($tpl_move) . " WHERE `id`='" . intval($tplid) . "'");
  405. if (hesk_dbAffectedRows() != 1) {
  406. hesk_error("$hesklang[int_error]: $hesklang[ticket_tpl_not_found].");
  407. }
  408. /* Update all category fields with new order */
  409. $result = hesk_dbQuery('SELECT `id` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'ticket_templates` ORDER BY `tpl_order` ASC');
  410. $i = 10;
  411. while ($mytpl = hesk_dbFetchAssoc($result)) {
  412. hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `tpl_order`=" . intval($i) . " WHERE `id`='" . intval($mytpl['id']) . "'");
  413. $i += 10;
  414. }
  415. header('Location: manage_ticket_templates.php');
  416. exit();
  417. } // End order_saved()
  418. ?>