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.

1111 lines
54KB

  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('MFH_PAGE_LAYOUT', 'TOP_ONLY');
  16. define('WYSIWYG', 1);
  17. define('VALIDATOR', 1);
  18. // Auto-focus first empty or error field
  19. define('AUTOFOCUS', true);
  20. /* Get all the required files and functions */
  21. require(HESK_PATH . 'hesk_settings.inc.php');
  22. require(HESK_PATH . 'inc/common.inc.php');
  23. require(HESK_PATH . 'inc/admin_functions.inc.php');
  24. require(HESK_PATH . 'inc/view_attachment_functions.inc.php');
  25. require(HESK_PATH . 'inc/mail_functions.inc.php');
  26. hesk_load_database_functions();
  27. hesk_session_start();
  28. hesk_dbConnect();
  29. hesk_isLoggedIn();
  30. // Load custom fields
  31. require_once(HESK_PATH . 'inc/custom_fields.inc.php');
  32. // Pre-populate fields
  33. // Customer name
  34. if (isset($_REQUEST['name'])) {
  35. $_SESSION['as_name'] = $_REQUEST['name'];
  36. }
  37. // Customer email address
  38. if (isset($_REQUEST['email'])) {
  39. $_SESSION['as_email'] = $_REQUEST['email'];
  40. $_SESSION['as_email2'] = $_REQUEST['email'];
  41. }
  42. // Category ID
  43. if (isset($_REQUEST['catid'])) {
  44. $_SESSION['as_category'] = intval($_REQUEST['catid']);
  45. }
  46. if (isset($_REQUEST['category'])) {
  47. $_SESSION['as_category'] = intval($_REQUEST['category']);
  48. }
  49. // Priority
  50. if (isset($_REQUEST['priority'])) {
  51. $_SESSION['as_priority'] = intval($_REQUEST['priority']);
  52. }
  53. // Subject
  54. if (isset($_REQUEST['subject'])) {
  55. $_SESSION['as_subject'] = $_REQUEST['subject'];
  56. }
  57. // Message
  58. if (isset($_REQUEST['message'])) {
  59. $_SESSION['as_message'] = $_REQUEST['message'];
  60. }
  61. // Custom fields
  62. foreach ($hesk_settings['custom_fields'] as $k => $v) {
  63. if ($v['use'] && isset($_REQUEST[$k])) {
  64. $_SESSION['as_' . $k] = $_REQUEST[$k];
  65. }
  66. }
  67. /* Varibles for coloring the fields in case of errors */
  68. if (!isset($_SESSION['iserror'])) {
  69. $_SESSION['iserror'] = array();
  70. }
  71. if (!isset($_SESSION['isnotice'])) {
  72. $_SESSION['isnotice'] = array();
  73. }
  74. /* List of users */
  75. $admins = array();
  76. $result = hesk_dbQuery("SELECT `id`,`name`,`isadmin`,`categories`,`heskprivileges` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `active` = '1' ORDER BY `name` ASC");
  77. while ($row = hesk_dbFetchAssoc($result)) {
  78. /* Is this an administrator? */
  79. if ($row['isadmin']) {
  80. $admins[$row['id']] = $row['name'];
  81. continue;
  82. }
  83. /* Not admin, is user allowed to view tickets? */
  84. if (strpos($row['heskprivileges'], 'can_view_tickets') !== false) {
  85. $admins[$row['id']] = $row['name'];
  86. continue;
  87. }
  88. }
  89. /* Print header */
  90. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  91. /* Print admin navigation */
  92. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  93. // Get categories
  94. $hesk_settings['categories'] = array();
  95. if (hesk_checkPermission('can_submit_any_cat', 0)) {
  96. $res = hesk_dbQuery("SELECT `id`, `name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` ORDER BY `cat_order` ASC");
  97. } else {
  98. $res = hesk_dbQuery("SELECT `id`, `name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` WHERE ".hesk_myCategories('id')." ORDER BY `cat_order` ASC");
  99. }
  100. while ($row = hesk_dbFetchAssoc($res)) {
  101. $hesk_settings['categories'][$row['id']] = $row['name'];
  102. }
  103. $number_of_categories = count($hesk_settings['categories']);
  104. if ($number_of_categories == 0) {
  105. $category = 1;
  106. } elseif ($number_of_categories == 1) {
  107. $category = current(array_keys($hesk_settings['categories']));
  108. } else {
  109. $category = isset($_GET['catid']) ? hesk_REQUEST('catid'): hesk_REQUEST('category');
  110. // Force the customer to select a category?
  111. if (!isset($hesk_settings['categories'][$category])) {
  112. return print_select_category($number_of_categories);
  113. }
  114. }
  115. $showRs = hesk_dbQuery("SELECT `show` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "quick_help_sections` WHERE `id` = 5");
  116. $show = hesk_dbFetchAssoc($showRs);
  117. $show_quick_help = $show['show'];
  118. ?>
  119. <div class="content-wrapper">
  120. <ol class="breadcrumb">
  121. <li><a href="admin_main.php"><?php echo $hesk_settings['hesk_title']; ?></a></li>
  122. <?php if ($number_of_categories > 1): ?>
  123. <li><a href="new_ticket.php"><?php echo $hesklang['nti2']; ?></a></li>
  124. <li class="active"><?php echo $hesk_settings['categories'][$category]; ?></li>
  125. <?php else: ?>
  126. <li class="active"><?php echo $hesklang['nti2']; ?></li>
  127. <?php endif; ?>
  128. </ol>
  129. <section class="content">
  130. <?php
  131. /* This will handle error, success and notice messages */
  132. hesk_handle_messages();
  133. if ($show_quick_help): ?>
  134. <div class="box">
  135. <div class="box-header with-border">
  136. <h1 class="box-title">
  137. <?php echo $hesklang['quick_help']; ?>
  138. </h1>
  139. <div class="box-tools pull-right">
  140. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  141. <i class="fa fa-minus"></i>
  142. </button>
  143. </div>
  144. </div>
  145. <div class="box-body">
  146. <p><?php echo $hesklang['nti3']; ?></p>
  147. <br>
  148. <p><?php echo $hesklang['req_marked_with']; ?> <span class="important">*</span></p>
  149. </div>
  150. </div>
  151. <?php endif; ?>
  152. <div class="box">
  153. <div class="box-header with-border">
  154. <h1 class="box-title">
  155. <?php echo $hesklang['nti2']; ?>
  156. </h1>
  157. <div class="box-tools pull-right">
  158. <button type="button" class="btn btn-box-tool" data-widget="collapse">
  159. <i class="fa fa-minus"></i>
  160. </button>
  161. </div>
  162. </div>
  163. <div class="box-body">
  164. <!-- START FORM -->
  165. <?php if ($modsForHesk_settings['rich_text_for_tickets']): ?>
  166. <script type="text/javascript">
  167. /* <![CDATA[ */
  168. tinyMCE.init({
  169. mode: "textareas",
  170. editor_selector: "htmlEditor",
  171. elements: "content",
  172. theme: "advanced",
  173. convert_urls: false,
  174. plugins: "autolink",
  175. theme_advanced_buttons1: "cut,copy,paste,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
  176. theme_advanced_buttons2: "sub,sup,|,charmap,|,bullist,numlist,|,outdent,indent,insertdate,inserttime,preview,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,link,unlink,anchor,image,cleanup,code",
  177. theme_advanced_buttons3: "",
  178. theme_advanced_toolbar_location: "top",
  179. theme_advanced_toolbar_align: "left",
  180. theme_advanced_statusbar_location: "bottom",
  181. theme_advanced_resizing: true
  182. });
  183. /* ]]> */
  184. </script>
  185. <?php endif;
  186. $onsubmit = '';
  187. if ($modsForHesk_settings['rich_text_for_tickets']) {
  188. $onsubmit = 'onsubmit="return validateRichText(\'message-help-block\', \'message-group\', \'message\', \''.htmlspecialchars($hesklang['this_field_is_required']).'\')"';
  189. }
  190. ?>
  191. <form role="form" class="form-horizontal" method="post" action="admin_submit_ticket.php" name="form1"
  192. enctype="multipart/form-data" <?php echo $onsubmit; ?>>
  193. <?php if ($hesk_settings['can_sel_lang']) { ?>
  194. <div class="form-group">
  195. <label for="customerLanguage" class="col-sm-3 control-label"><?php echo $hesklang['chol']; ?>:&nbsp;<span
  196. class="important">*</span></label>
  197. <div class="col-sm-9">
  198. <select name="customerLanguage" id="customerLanguage" class="form-control">
  199. <?php hesk_listLanguages(); ?>
  200. </select>
  201. </div>
  202. </div>
  203. <?php } ?>
  204. <!-- Contact info -->
  205. <?php
  206. $has_error = '';
  207. if (in_array('name', $_SESSION['iserror'])) {
  208. $has_error = 'has-error';
  209. }?>
  210. <div class="form-group <?php echo $has_error; ?>">
  211. <label for="name" class="col-sm-3 control-label"><?php echo $hesklang['name']; ?><span
  212. class="important">*</span></label>
  213. <div class="col-sm-9">
  214. <input type="text" class="form-control" name="name" size="40" maxlength="30"
  215. value="<?php if (isset($_SESSION['as_name'])) {
  216. echo stripslashes(hesk_input($_SESSION['as_name']));
  217. } else if (isset($_GET['name'])) {
  218. echo hesk_GET('name');
  219. } ?>"
  220. data-error="<?php echo htmlspecialchars($hesklang['enter_your_name']); ?>"
  221. placeholder="<?php echo htmlspecialchars($hesklang['name']); ?>" required>
  222. <div class="help-block with-errors"></div>
  223. </div>
  224. </div>
  225. <div class="form-group">
  226. <label for="email" class="col-sm-3 control-label">
  227. <?php
  228. echo $hesklang['email'];
  229. if ($hesk_settings['require_email']) {
  230. echo '<span class="important">*</span>';
  231. }
  232. ?>
  233. </label>
  234. <div class="col-sm-9">
  235. <input type="text" class="form-control" name="email" size="40" maxlength="1000" id="email"
  236. value="<?php if (isset($_SESSION['as_email'])) {
  237. echo stripslashes(hesk_input($_SESSION['as_email']));
  238. } else if (isset($_GET['email'])) {
  239. echo hesk_GET('email');
  240. } ?>" <?php if ($hesk_settings['detect_typos']) {
  241. echo ' onblur="Javascript:Javascript:hesk_suggestEmail(\'email\', \'email_suggestions\', 1, 1)"';
  242. } ?>
  243. placeholder="<?php echo htmlspecialchars($hesklang['email']); ?>"
  244. onkeyup="disableIfEmpty('email','notify-email')"
  245. <?php if ($hesk_settings['require_email']) {echo 'data-error="'.htmlspecialchars($hesklang['enter_valid_email']).'" required';} ?>>
  246. <div class="help-block with-errors"></div>
  247. </div>
  248. </div>
  249. <div id="email_suggestions"></div>
  250. <!-- Priority -->
  251. <?php
  252. $has_error = '';
  253. if (in_array('priority', $_SESSION['iserror'])) {
  254. $has_error = 'has-error';
  255. } ?>
  256. <div class="form-group <?php echo $has_error; ?>">
  257. <label for="priority" class="col-sm-3 control-label"><?php echo $hesklang['priority']; ?><span
  258. class="important">*</span></label>
  259. <div class="col-sm-9">
  260. <select name="priority" class="form-control"
  261. pattern="[0-9]+"
  262. data-error="<?php echo htmlspecialchars($hesklang['sel_app_priority']); ?>"
  263. required>
  264. <?php
  265. // Show the "Click to select"?
  266. if ($hesk_settings['select_pri']) {
  267. echo '<option value="">' . $hesklang['select'] . '</option>';
  268. }
  269. ?>
  270. <option value="3" <?php
  271. if ((isset($_SESSION['as_priority']) && $_SESSION['as_priority'] == 3)
  272. || (isset($_GET['priority']) && $_GET['priority'] == 3)
  273. ) {
  274. echo 'selected="selected"';
  275. } ?>><?php echo $hesklang['low']; ?></option>
  276. <option value="2" <?php
  277. if ((isset($_SESSION['as_priority']) && $_SESSION['as_priority'] == 2)
  278. || (isset($_GET['priority']) && $_GET['priority'] == 2)
  279. ) {
  280. echo 'selected="selected"';
  281. } ?>><?php echo $hesklang['medium']; ?></option>
  282. <option value="1" <?php
  283. if ((isset($_SESSION['as_priority']) && $_SESSION['as_priority'] == 1)
  284. || (isset($_GET['priority']) && $_GET['priority'] == 1)
  285. ) {
  286. echo 'selected="selected"';
  287. } ?>><?php echo $hesklang['high']; ?></option>
  288. <option value="0" <?php
  289. if ((isset($_SESSION['as_priority']) && $_SESSION['as_priority'] == 0)
  290. || (isset($_GET['priority']) && $_GET['priority'] == 0)
  291. ) {
  292. echo 'selected="selected"';
  293. } ?>><?php echo $hesklang['critical']; ?></option>
  294. </select>
  295. <div class="help-block with-errors"></div>
  296. </div>
  297. </div>
  298. <?php
  299. /* custom fields BEFORE comments */
  300. foreach ($hesk_settings['custom_fields'] as $k => $v) {
  301. if ($v['use'] && $v['place'] == 0 && hesk_is_custom_field_in_category($k, $category)) {
  302. if ($v['req'] == 2) {
  303. $v['req']= '<span class="important">*</span>';
  304. $required_attribute = 'data-error="' . $hesklang['this_field_is_required'] . '" required';
  305. } else {
  306. $v['req'] = '';
  307. $required_attribute = '';
  308. }
  309. if ($v['type'] == 'checkbox') {
  310. $k_value = array();
  311. if (isset($_SESSION["as_$k"]) && is_array($_SESSION["as_$k"])) {
  312. foreach ($_SESSION["as_$k"] as $myCB) {
  313. $k_value[] = stripslashes(hesk_input($myCB));
  314. }
  315. }
  316. } elseif (isset($_SESSION["as_$k"])) {
  317. $k_value = stripslashes(hesk_input($_SESSION["as_$k"]));
  318. } else {
  319. $k_value = '';
  320. }
  321. switch ($v['type']) {
  322. /* Radio box */
  323. case 'radio':
  324. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  325. echo '<div class="form-group' . $cls . '"><label class="col-sm-3 control-label">' . $v['name'] . ' ' . $v['req'] .'</label><div align="left" class="col-sm-9">';
  326. foreach ($v['value']['radio_options'] as $option) {
  327. if (strlen($k_value) == 0) {
  328. $k_value = $option;
  329. $checked = empty($v['value']['no_default']) ? 'checked' : '';
  330. } elseif ($k_value == $option) {
  331. $k_value = $option;
  332. $checked = 'checked';
  333. } else {
  334. $checked = '';
  335. }
  336. echo '<div class="radio">
  337. <label>
  338. <input type="radio" name="' . $k . '" value="' . $option . '" ' . $checked . $required_attribute . '>
  339. ' . $option . '
  340. </label>
  341. </div>';
  342. }
  343. echo '
  344. <div class="help-block with-errors"></div>
  345. </div>
  346. </div>';
  347. break;
  348. /* Select drop-down box */
  349. case 'select':
  350. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  351. echo '<div class="form-group' . $cls . '"><label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'] . ' ' . $v['req'] . '</label>
  352. <div class="col-sm-9"><select class="form-control" name="' . $k . '" ' . $required_attribute . '>';
  353. // Show "Click to select"?
  354. if (!empty($v['value']['show_select'])) {
  355. echo '<option value="">' . $hesklang['select'] . '</option>';
  356. }
  357. foreach ($v['value']['select_options'] as $option) {
  358. if ($k_value == $option) {
  359. $k_value = $option;
  360. $selected = 'selected';
  361. } else {
  362. $selected = '';
  363. }
  364. echo '<option ' . $selected . '>' . $option . '</option>';
  365. }
  366. echo '</select>
  367. <div class="help-block with-errors"></div></div></div>';
  368. break;
  369. /* Checkbox */
  370. case 'checkbox':
  371. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  372. $validator = $v['req'] == '<span class="important">*</span>' ? 'data-checkbox="' . $k . '"' : '';
  373. $required_attribute = $validator == '' ? '' : ' data-error="' . $hesklang['this_field_is_required'] . '"';
  374. echo '<div class="form-group' . $cls . '"><label class="col-sm-3 control-label">' . $v['name'] . ' ' . $v['req'] . '</label><div align="left" class="col-sm-9">';
  375. foreach ($v['value']['checkbox_options'] as $option) {
  376. if (in_array($option, $k_value)) {
  377. $checked = 'checked';
  378. } else {
  379. $checked = '';
  380. }
  381. echo '<div class="checkbox"><label><input ' . $validator . ' type="checkbox" name="' . $k . '[]" value="' . $option . '" ' . $checked . $required_attribute . '> ' . $option . '</label></div>';
  382. }
  383. echo '
  384. <div class="help-block with-errors"></div></div></div>';
  385. break;
  386. /* Large text box */
  387. case 'textarea':
  388. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  389. echo '<div class="form-group' . $cls . '">
  390. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'] . ' ' . $v['req'] . '</label>
  391. <div class="col-sm-9"><textarea class="form-control" placeholder="' . $v['name'] . '" name="' . $k . '" rows="' . intval($v['value']['rows']) . '" cols="' . intval($v['value']['cols']) . '" ' . $required_attribute . '>' . $k_value . '</textarea>
  392. <div class="help-block with-errors"></div></div></div>';
  393. break;
  394. case 'date':
  395. if ($required_attribute != '') {
  396. $required_attribute .= ' pattern="[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])"';
  397. }
  398. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  399. echo '
  400. <div class="form-group' . $cls . '">
  401. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  402. <div class="col-sm-9">
  403. <input type="text" class="datepicker form-control" placeholder="' . $v['name'] . '" name="' . $k . '" size="40"
  404. value="' . $k_value . '" ' . $required_attribute . '>
  405. <div class="help-block with-errors"></div>
  406. </div>
  407. </div>';
  408. break;
  409. case 'email':
  410. $suggest = $hesk_settings['detect_typos'] ? 'onblur="Javascript:hesk_suggestEmail(\''.$k.'\', \''.$k.'_suggestions\', 0, 1'.($v['value']['multiple'] ? ',1' : '').')"' : '';
  411. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  412. echo '<div class="form-group' . $cls . '">
  413. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  414. <div class="col-sm-9">
  415. <input type="text" class="form-control" placeholder="' . $v['name'] . '" name="' . $k . '" size="40" value="' . $k_value . '" '.$suggest.$required_attribute.'>
  416. <div class="help-block with-errors"></div>
  417. </div>
  418. </div><div id="'.$k.'_suggestions"></div>';
  419. break;
  420. // Hidden and read-only should work the same as text
  421. case 'hidden':
  422. case 'readonly':
  423. default:
  424. if (strlen($k_value) != 0 || isset($_SESSION["as_$k"])) {
  425. $v['value']['default_value'] = $k_value;
  426. }
  427. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  428. echo '<div class="form-group' . $cls . '">
  429. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  430. <div class="col-sm-9">
  431. <input type="text" class="form-control" placeholder="' . $v['name'] . '" name="' . $k . '" size="40" maxlength="' . intval($v['value']['max_length']) . '" value="' . $v['value']['default_value'] . '" ' . $cls . $required_attribute . '>
  432. <div class="help-block with-errors"></div>
  433. </div>
  434. </div>';
  435. }
  436. }
  437. }
  438. // Lets handle ticket templates
  439. $can_options = '';
  440. // Get ticket templates from the database
  441. $res = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` ORDER BY `tpl_order` ASC");
  442. // If we have any templates print them out
  443. if (hesk_dbNumRows($res)) {
  444. ?>
  445. <script language="javascript" type="text/javascript"><!--
  446. // -->
  447. var myMsgTxt = new Array();
  448. var mySubjectTxt = new Array();
  449. myMsgTxt[0] = '';
  450. mySubjectTxt[0] = '';
  451. <?php
  452. while ($mysaved = hesk_dbFetchRow($res))
  453. {
  454. $can_options .= '<option value="' . $mysaved[0] . '">' . $mysaved[1]. "</option>\n";
  455. if ($modsForHesk_settings['rich_text_for_tickets']) {
  456. $theMessage = hesk_html_entity_decode($mysaved[2]);
  457. $theMessage = addslashes($theMessage);
  458. echo 'myMsgTxt['.$mysaved[0].']=\''.str_replace("\r\n","\\r\\n' + \r\n'", $theMessage)."';\n";
  459. } else {
  460. echo 'myMsgTxt['.$mysaved[0].']=\''.str_replace("\r\n","\\r\\n' + \r\n'", addslashes($mysaved[2]))."';\n";
  461. }
  462. echo 'mySubjectTxt['.$mysaved[0].']=\''.str_replace("\r\n","\\r\\n' + \r\n'", addslashes($mysaved[1]))."';\n";
  463. }
  464. ?>
  465. function setMessage(msgid) {
  466. var useHtmlEditor = <?php echo $modsForHesk_settings['rich_text_for_tickets']; ?>;
  467. var myMsg = myMsgTxt[msgid];
  468. var mySubject = mySubjectTxt[msgid];
  469. if (myMsg == '') {
  470. if (document.form1.mode[1].checked) {
  471. if (useHtmlEditor) {
  472. tinymce.get("message").setContent('');
  473. tinymce.get("message").execCommand('mceInsertRawHTML', false, '');
  474. }
  475. else {
  476. $('#message').val('');
  477. }
  478. $('#subject').val('');
  479. }
  480. return true;
  481. }
  482. if (document.getElementById) {
  483. if (document.getElementById('moderep').checked) {
  484. if (useHtmlEditor) {
  485. tinymce.get("message").setContent('');
  486. tinymce.get("message").execCommand('mceInsertRawHTML', false, myMsg);
  487. } else {
  488. myMsg = $('<textarea />').html(myMsg).text();
  489. $('#message').val(myMsg).trigger('input');
  490. }
  491. mySubject = $('<textarea />').html(mySubject).text();
  492. $('#subject').val(mySubject).trigger('input');
  493. }
  494. else {
  495. if (useHtmlEditor) {
  496. var oldMsg = tinymce.get("message").getContent();
  497. tinymce.get("message").setContent('');
  498. tinymce.get("message").execCommand('mceInsertRawHTML', false, oldMsg + myMsg);
  499. } else {
  500. var oldMsg = document.getElementById('message').value;
  501. var theMsg = $('<textarea />').html(oldMsg + myMsg).text();
  502. $('#message').val(theMsg).trigger('input');
  503. }
  504. if (document.getElementById('subject').value == '') {
  505. mySubject = $('<textarea />').html(mySubject).text();
  506. $('#subject').val(mySubject).trigger('input');
  507. }
  508. }
  509. }
  510. else {
  511. if (document.form1.mode[0].checked) {
  512. document.form1.message.value = myMsg;
  513. document.form1.subject.value = mySubject;
  514. }
  515. else {
  516. var oldMsg = document.form1.message.value;
  517. document.form1.message.value = oldMsg + myMsg;
  518. if (document.form1.subject.value == '') {
  519. document.form1.subject.value = mySubject;
  520. }
  521. }
  522. }
  523. }
  524. //-->
  525. </script>
  526. <?php
  527. } // END fetchrows
  528. // Print templates
  529. if (strlen($can_options)) {
  530. ?>
  531. <div class="form-group">
  532. <label for="modeadd" class="col-sm-3 control-label"><?php echo $hesklang['ticket_tpl']; ?></label>
  533. <div class="col-sm-9">
  534. <div class="radio">
  535. <label><input type="radio" name="mode" id="modeadd" value="1"
  536. checked="checked"> <?php echo $hesklang['madd']; ?></label>
  537. </div>
  538. <div class="radio">
  539. <label><input type="radio" name="mode" id="moderep" value="0"/> <?php echo $hesklang['mrep']; ?></label>
  540. </div>
  541. <?php echo hesk_checkPermission('can_man_ticket_tpl', 0) ? '(<a href="manage_ticket_templates.php">' . $hesklang['ticket_tpl_man'] . '</a>)' : ''; ?>
  542. </div>
  543. </div>
  544. <div class="form-group">
  545. <label for="saved_replies" class="col-sm-3 control-label"><?php echo $hesklang['select_ticket_tpl']; ?></label>
  546. <div class="col-sm-9">
  547. <select class="form-control" name="saved_replies" onchange="setMessage(this.value)">
  548. <option value="0"> - <?php echo $hesklang['select_empty']; ?> -</option>
  549. <?php echo $can_options; ?>
  550. </select>
  551. </div>
  552. </div>
  553. <?php
  554. } // END printing templates
  555. elseif (hesk_checkPermission('can_man_ticket_tpl', 0)) {
  556. ?>
  557. <div class="form-group">
  558. <div class="col-sm-9 col-sm-offset-3">
  559. <a href="manage_ticket_templates.php"><?php echo $hesklang['ticket_tpl_man']; ?></a>
  560. </div>
  561. </div>
  562. <?php
  563. }
  564. ?>
  565. <div class="form-group">
  566. <label for="due-date" class="col-sm-3 control-label"><?php echo $hesklang['due_date']; ?></label>
  567. <div class="col-sm-9">
  568. <input class="form-control datepicker" name="due-date" placeholder="<?php echo htmlspecialchars($hesklang['due_date']); ?>"
  569. value="<?php if (isset($_GET['due_date'])) { echo $_GET['due_date']; } ?>">
  570. <span class="help-block"><?php echo $hesklang['date_format']; ?></span>
  571. </div>
  572. </div>
  573. <?php
  574. $has_error = '';
  575. if (in_array('subject', $_SESSION['iserror'])) {
  576. $has_error = 'has-error';
  577. }
  578. $red_star = '';
  579. $validator = '';
  580. if ($hesk_settings['require_subject'] == 1) {
  581. $red_star = '<span class="important">*</span>';
  582. $validator = 'data-error="' . htmlspecialchars($hesklang['enter_subject']) . '"" required';
  583. }
  584. ?>
  585. <div class="form-group <?php echo $has_error; ?>">
  586. <label for="subject" class="col-sm-3 control-label">
  587. <?php
  588. echo $hesklang['subject'];
  589. echo $red_star;
  590. ?>
  591. </label>
  592. <div class="col-sm-9">
  593. <span id="HeskSub"><input class="form-control" type="text" name="subject" id="subject" size="40" maxlength="40"
  594. value="<?php if (isset($_SESSION['as_subject']) || isset($_GET['subject'])) {
  595. echo stripslashes(hesk_input($_SESSION['as_subject']));
  596. } ?>" placeholder="<?php echo htmlspecialchars($hesklang['subject']); ?>"
  597. <?php echo $validator; ?>></span>
  598. <div class="help-block with-errors"></div>
  599. </div>
  600. </div>
  601. <?php
  602. $has_error = '';
  603. if (in_array('message', $_SESSION['iserror'])) {
  604. $has_error = 'has-error';
  605. }
  606. $red_star = '';
  607. $validator = '';
  608. if ($hesk_settings['require_message'] == 1) {
  609. $red_star = '<span class="important">*</span>';
  610. $validator = 'data-error="' . htmlspecialchars($hesklang['enter_message']) . '"" required';
  611. }
  612. ?>
  613. <div class="form-group <?php echo $has_error; ?>" id="message-group">
  614. <label for="subject" class="col-sm-3 control-label">
  615. <?php
  616. echo $hesklang['message'];
  617. echo $red_star;
  618. ?>
  619. </label>
  620. <div class="col-sm-9">
  621. <span id="HeskMsg">
  622. <textarea class="form-control htmlEditor" name="message" id="message" rows="12" cols="60"
  623. placeholder="<?php echo htmlspecialchars($hesklang['message']); ?>"
  624. <?php echo $validator; ?>><?php if (isset($_SESSION['as_message'])) {
  625. echo stripslashes(hesk_input($_SESSION['as_message']));
  626. } ?></textarea>
  627. </span>
  628. <div class="help-block with-errors" id="message-help-block"></div>
  629. </div>
  630. </div>
  631. <?php
  632. /* custom fields AFTER comments */
  633. foreach ($hesk_settings['custom_fields'] as $k => $v) {
  634. if ($v['use'] && $v['place'] == 1 && hesk_is_custom_field_in_category($k, $category)) {
  635. if ($v['req'] == 2) {
  636. $v['req']= '<span class="important">*</span>';
  637. $required_attribute = 'data-error="' . $hesklang['this_field_is_required'] . '" required';
  638. } else {
  639. $v['req'] = '';
  640. $required_attribute = '';
  641. }
  642. if ($v['type'] == 'checkbox') {
  643. $k_value = array();
  644. if (isset($_SESSION["as_$k"]) && is_array($_SESSION["as_$k"])) {
  645. foreach ($_SESSION["as_$k"] as $myCB) {
  646. $k_value[] = stripslashes(hesk_input($myCB));
  647. }
  648. }
  649. } elseif (isset($_SESSION["as_$k"])) {
  650. $k_value = stripslashes(hesk_input($_SESSION["as_$k"]));
  651. } else {
  652. $k_value = '';
  653. }
  654. switch ($v['type']) {
  655. /* Radio box */
  656. case 'radio':
  657. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  658. echo '<div class="form-group' . $cls . '"><label class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label><div align="left" class="col-sm-9">';
  659. foreach ($v['value']['radio_options'] as $option) {
  660. if (strlen($k_value) == 0) {
  661. $k_value = $option;
  662. $checked = empty($v['value']['no_default']) ? 'checked' : '';
  663. } elseif ($k_value == $option) {
  664. $k_value = $option;
  665. $checked = 'checked';
  666. } else {
  667. $checked = '';
  668. }
  669. echo '<div class="radio"><label><input type="radio" name="' . $k . '" value="' . $option . '" ' . $checked . ' ' . $required_attribute . '> ' . $option . '</label></div>';
  670. }
  671. echo '<div class="help-block with-errors"></div></div></div>';
  672. break;
  673. /* Select drop-down box */
  674. case 'select':
  675. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  676. echo '<div class="form-group' . $cls . '"><label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  677. <div class="col-sm-9"><select class="form-control" name="' . $k . '" ' . $required_attribute . '>';
  678. // Show "Click to select"?
  679. if (!empty($v['value']['show_select'])) {
  680. echo '<option value="">' . $hesklang['select'] . '</option>';
  681. }
  682. foreach ($v['value']['select_options'] as $option) {
  683. if ($k_value == $option) {
  684. $k_value = $option;
  685. $selected = 'selected';
  686. } else {
  687. $selected = '';
  688. }
  689. echo '<option ' . $selected . '>' . $option . '</option>';
  690. }
  691. echo '</select><div class="help-block with-errors"></div></div></div>';
  692. break;
  693. /* Checkbox */
  694. case 'checkbox':
  695. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  696. $validator = $v['req'] == '<span class="important">*</span>' ? 'data-checkbox="' . $k . '"' : '';
  697. $required_attribute = $validator == '' ? '' : ' data-error="' . $hesklang['this_field_is_required'] . '"';
  698. echo '<div class="form-group' . $cls . '"><label class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label><div align="left" class="col-sm-9">';
  699. foreach ($v['value']['checkbox_options'] as $option) {
  700. if (in_array($option, $k_value)) {
  701. $checked = 'checked';
  702. } else {
  703. $checked = '';
  704. }
  705. echo '<div class="checkbox"><label><input ' . $validator . ' type="checkbox" name="' . $k . '[]" value="' . $option . '" ' . $checked . $required_attribute .'> ' . $option . '</label></div>';
  706. }
  707. echo '<div class="help-block with-errors"></div></div></div>';
  708. break;
  709. /* Large text box */
  710. case 'textarea':
  711. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  712. echo '<div class="form-group' . $cls . '">
  713. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  714. <div class="col-sm-9"><textarea class="form-control" placeholder="' . $v['name'] . '" name="' . $k . '" rows="' . intval($v['value']['rows']) . '" cols="' . intval($v['value']['cols']) . '" ' . $required_attribute . '>' . $k_value . '</textarea>
  715. <div class="help-block with-errors"></div></div>
  716. </div>';
  717. break;
  718. case 'date':
  719. if ($required_attribute != '') {
  720. $required_attribute .= ' pattern="[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])"';
  721. }
  722. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  723. echo '
  724. <div class="form-group' . $cls . '">
  725. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  726. <div class="col-sm-9">
  727. <input type="text" class="datepicker form-control" placeholder="' . $v['name'] . '" name="' . $k . '" size="40"
  728. value="' . $k_value . '" ' . $required_attribute . '>
  729. <div class="help-block with-errors"></div>
  730. </div>
  731. </div>';
  732. break;
  733. case 'email':
  734. $suggest = $hesk_settings['detect_typos'] ? 'onblur="Javascript:hesk_suggestEmail(\''.$k.'\', \''.$k.'_suggestions\', 0, 1'.($v['value']['multiple'] ? ',1' : '').')"' : '';
  735. $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : '';
  736. echo '<div class="form-group">
  737. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  738. <div class="col-sm-9">
  739. <input type="text" class="form-control" placeholder="' . $v['name'] . '" name="' . $k . '" size="40" value="' . $k_value . '" '.$suggest.' ' . $required_attribute . '>
  740. <div class="help-block with-errors"></div>
  741. </div>
  742. </div><div id="'.$k.'_suggestions"></div>';
  743. break;
  744. case 'hidden':
  745. case 'readonly':
  746. default:
  747. if (strlen($k_value) != 0 || isset($_SESSION["as_$k"])) {
  748. $v['value']['default_value'] = $k_value;
  749. }
  750. $cls = in_array($k, $_SESSION['iserror']) ? ' class="isError" ' : '';
  751. echo '<div class="form-group">
  752. <label for="' . $v['name'] . '" class="col-sm-3 control-label">' . $v['name'].' '.$v['req'] . '</label>
  753. <div class="col-sm-9">
  754. <input type="text" class="form-control" placeholder="' . $v['name'] . '" name="' . $k . '" size="40" maxlength="' . intval($v['value']['max_length']) . '" value="' . $v['value']['default_value'] . '" ' . $required_attribute . '>
  755. <div class="help-block with-errors"></div>
  756. </div>
  757. </div>';
  758. }
  759. }
  760. }
  761. /* end custom after */
  762. /* attachments */
  763. if ($hesk_settings['attachments']['use']) {
  764. ?>
  765. <div class="form-group">
  766. <label for="attachments" class="control-label col-sm-3"><?php echo $hesklang['attachments']; ?>:</label>
  767. <div class="col-sm-9">
  768. <?php build_dropzone_markup(true); ?>
  769. </div>
  770. </div>
  771. <?php
  772. display_dropzone_field(HESK_PATH . 'internal-api/ticket/upload-attachment.php');
  773. }
  774. if (!isset($_SESSION['as_notify'])) {
  775. $_SESSION['as_notify'] = $_SESSION['notify_customer_new'] ? 1 : 0;
  776. }
  777. ?>
  778. <div class="form-group">
  779. <label class="col-sm-3 control-label"><?php echo $hesklang['addop']; ?>:</label>
  780. <div class="col-sm-9">
  781. <label><input type="checkbox" id="notify-email" name="notify"
  782. value="1" <?php echo empty($_SESSION['as_notify']) ? '' : 'checked="checked"'; ?> /> <?php echo $hesklang['seno']; ?>
  783. </label><br>
  784. <label><input type="checkbox" name="show"
  785. value="1" <?php echo (!isset($_SESSION['as_show']) || !empty($_SESSION['as_show'])) ? 'checked="checked"' : ''; ?> /> <?php echo $hesklang['otas']; ?>
  786. </label>
  787. </div>
  788. </div>
  789. <?php
  790. if (hesk_checkPermission('can_assign_others',0))
  791. {
  792. $has_error = '';
  793. if (in_array('owner',$_SESSION['iserror'])) {
  794. $has_error = 'has-error';
  795. }
  796. ?>
  797. <div class="form-group <?php echo $has_error; ?>">
  798. <label for="owner" class="col-sm-3 control-label"><?php echo $hesklang['asst2']; ?>:</label>
  799. <div class="col-sm-9">
  800. <select class="form-control" name="owner" >
  801. <option value="-1"> &gt; <?php echo $hesklang['unas']; ?> &lt; </option>
  802. <?php
  803. if ($hesk_settings['autoassign'])
  804. {
  805. echo '<option value="-2"> &gt; ' . $hesklang['aass'] . ' &lt; </option>';
  806. }
  807. $owner = isset($_SESSION['as_owner']) ? intval($_SESSION['as_owner']) : 0;
  808. foreach ($admins as $k=>$v)
  809. {
  810. if ($k == $owner)
  811. {
  812. echo '<option value="'.$k.'" selected="selected">'.$v.'</option>';
  813. }
  814. else
  815. {
  816. echo '<option value="'.$k.'">'.$v.'</option>';
  817. }
  818. }
  819. ?>
  820. </select>
  821. </div>
  822. </div>
  823. <?php
  824. }
  825. elseif (hesk_checkPermission('can_assign_self',0))
  826. {
  827. $checked = (!isset($_SESSION['as_owner']) || !empty($_SESSION['as_owner'])) ? 'checked="checked"' : '';
  828. ?>
  829. <div class="form-group">
  830. <div class="col-sm-9 col-sm-offset-3">
  831. <label><input type="checkbox" name="assing_to_self" value="1" <?php echo $checked; ?> /> <?php echo $hesklang['asss2']; ?></label>
  832. </div>
  833. </div>
  834. <?php
  835. }
  836. if ($modsForHesk_settings['request_location']):
  837. ?>
  838. <div class="form-group">
  839. <label for="location" class="col-md-3 control-label"><?php echo $hesklang['location_colon']; ?></label>
  840. <div class="col-sm-9">
  841. <p id="console"><?php echo $hesklang['requesting_location_ellipsis']; ?></p>
  842. <div id="map" style="height: 300px; display:none">
  843. </div>
  844. </div>
  845. </div>
  846. <?php endif; ?>
  847. <!-- Submit -->
  848. <div class="form-group">
  849. <div class="col-sm-9 col-sm-offset-3">
  850. <input type="hidden" id="latitude" name="latitude" value="E-0">
  851. <input type="hidden" id="longitude" name="longitude" value="E-0">
  852. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>">
  853. <input type="hidden" name="category" value="<?php echo $category; ?>">
  854. <input type="submit" value="<?php echo $hesklang['sub_ticket']; ?>" class="btn btn-default">
  855. </div>
  856. </div>
  857. </form>
  858. </div>
  859. </div>
  860. </section>
  861. </div>
  862. <script>
  863. buildValidatorForTicketSubmission("form1",
  864. "<?php echo addslashes($hesklang['select_at_least_one_value']); ?>");
  865. </script>
  866. <?php
  867. // Request for the users location if enabled
  868. if ($modsForHesk_settings['request_location']) {
  869. echo '
  870. <script>
  871. requestUserLocation("' . $hesklang['your_current_location'] . '", "' . $hesklang['unable_to_determine_location'] . '");
  872. </script>
  873. ';
  874. }
  875. // Set the message in the actual text box if rich text is enabled
  876. if ($modsForHesk_settings['rich_text_for_tickets']) {
  877. $message = hesk_SESSION('as_message', '');
  878. echo "
  879. <script>
  880. tinymce.get('message').setContent('');
  881. tinymce.get('message').execCommand('mceInsertRawHTML', false, '".$message."');
  882. </script>
  883. ";
  884. }
  885. hesk_cleanSessionVars('iserror');
  886. hesk_cleanSessionVars('isnotice');
  887. require_once(HESK_PATH . 'inc/footer.inc.php');
  888. exit();
  889. /*** START FUNCTIONS ***/
  890. function print_select_category($number_of_categories) {
  891. global $hesk_settings, $hesklang;
  892. // A category needs to be selected
  893. if (isset($_GET['category']) && empty($_GET['category'])) {
  894. hesk_process_messages($hesklang['sel_app_cat'],'NOREDIRECT','NOTICE');
  895. }
  896. /* This will handle error, success and notice messages */
  897. hesk_handle_messages();
  898. ?>
  899. <div class="content-wrapper">
  900. <section class="content">
  901. <div class="box">
  902. <div class="box-header with-border">
  903. <h1 class="box-title">
  904. <?php echo $hesklang['select_category_staff']; ?>
  905. </h1>
  906. </div>
  907. <div class="box-body">
  908. <div class="select_category">
  909. <?php
  910. // Print a select box if number of categories is large
  911. if ($number_of_categories > $hesk_settings['cat_show_select'])
  912. {
  913. ?>
  914. <form action="new_ticket.php" method="get">
  915. <select name="category" id="select_category" class="form-control">
  916. <?php
  917. if ($hesk_settings['select_cat'])
  918. {
  919. echo '<option value="">'.$hesklang['select'].'</option>';
  920. }
  921. foreach ($hesk_settings['categories'] as $k=>$v)
  922. {
  923. echo '<option value="'.$k.'">'.$v.'</option>';
  924. }
  925. ?>
  926. </select>
  927. &nbsp;<br />
  928. <div style="text-align:center">
  929. <input type="submit" value="<?php echo $hesklang['c2c']; ?>" class="btn btn-default">
  930. </div>
  931. </form>
  932. <?php
  933. }
  934. // Otherwise print quick links
  935. else
  936. {
  937. // echo '<li><a href="new_ticket.php?a=add&amp;category='.$k.'">&raquo; '.$v.'</a></li>';
  938. $new_row = 1;
  939. foreach ($hesk_settings['categories'] as $k=>$v):
  940. if ($new_row == 1) {
  941. echo '<div class="row">';
  942. $new_row = -1;
  943. }
  944. ?>
  945. <div class="col-md-5 col-sm-12 <?php if ($new_row == -1) {echo 'col-md-offset-1';} ?>">
  946. <a href="new_ticket.php?a=add&category=<?php echo $k; ?>" class="button-link">
  947. <div class="panel panel-default">
  948. <div class="panel-body">
  949. <div class="row">
  950. <div class="col-xs-12">
  951. <?php echo $v; ?>
  952. </div>
  953. </div>
  954. </div>
  955. </div>
  956. </a>
  957. </div>
  958. <?php
  959. $new_row++;
  960. if ($new_row == 1) {
  961. echo '</div>';
  962. }
  963. endforeach;
  964. }
  965. ?>
  966. </div>
  967. </div>
  968. </div>
  969. </section>
  970. </div>
  971. <?php
  972. hesk_cleanSessionVars('iserror');
  973. hesk_cleanSessionVars('isnotice');
  974. require_once(HESK_PATH . 'inc/footer.inc.php');
  975. exit();
  976. } // END print_select_category()