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.

custom_fields.php 49KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  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('PAGE_TITLE', 'ADMIN_CUSTOM_FIELDS');
  17. define('LOAD_TABS',1);
  18. define('CALENDAR',1);
  19. // Get all the req files and functions
  20. require(HESK_PATH . 'hesk_settings.inc.php');
  21. require(HESK_PATH . 'inc/common.inc.php');
  22. require(HESK_PATH . 'inc/admin_functions.inc.php');
  23. require(HESK_PATH . 'inc/setup_functions.inc.php');
  24. require(HESK_PATH . 'inc/mail_functions.inc.php');
  25. hesk_load_database_functions();
  26. hesk_session_start();
  27. hesk_dbConnect();
  28. hesk_isLoggedIn();
  29. // Check permissions for this feature
  30. hesk_checkPermission('can_man_settings');
  31. // Load custom fields
  32. require_once(HESK_PATH . 'inc/custom_fields.inc.php');
  33. // List of categories
  34. $hesk_settings['categories'] = array();
  35. $res = hesk_dbQuery("SELECT `id`, `name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."categories` ORDER BY `cat_order` ASC");
  36. while ($row=hesk_dbFetchAssoc($res))
  37. {
  38. $hesk_settings['categories'][$row['id']] = $row['name'];
  39. }
  40. // What should we do?
  41. if ( $action = hesk_REQUEST('a') )
  42. {
  43. if ($action == 'edit_cf') {edit_cf();}
  44. elseif ( defined('HESK_DEMO') ) {hesk_process_messages($hesklang['ddemo'], 'custom_fields.php', 'NOTICE');}
  45. elseif ($action == 'new_cf') {new_cf();}
  46. elseif ($action == 'save_cf') {save_cf();}
  47. elseif ($action == 'order_cf') {order_cf();}
  48. elseif ($action == 'remove_cf') {remove_cf();}
  49. }
  50. // Print header
  51. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  52. // Print main manage users page
  53. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  54. ?>
  55. <div class="content-wrapper">
  56. <section class="content">
  57. <?php
  58. /* This will handle error, success and notice messages */
  59. hesk_handle_messages();
  60. ?>
  61. <div class="box">
  62. <div class="box-body">
  63. <div class="nav-tabs-custom">
  64. <ul class="nav nav-tabs" role="tablist">
  65. <?php
  66. // Show a link to banned_emails.php if user has permission to do so
  67. if (hesk_checkPermission('can_ban_emails', 0)) {
  68. echo '
  69. <li role="presentation">
  70. <a title="' . $hesklang['banemail'] . '" href="banned_emails.php">' . $hesklang['banemail'] . '</a>
  71. </li>';
  72. }
  73. // Show a link to banned_ips.php if user has permission to do so
  74. if (hesk_checkPermission('can_ban_ips', 0)) {
  75. echo '
  76. <li role="presentation">
  77. <a title="' . $hesklang['banip'] . '" href="banned_ips.php">' . $hesklang['banip'] . '</a>
  78. </li>';
  79. }
  80. // Show a link to status_message.php if user has permission to do so
  81. if (hesk_checkPermission('can_service_msg', 0)) {
  82. echo '
  83. <li role="presentation">
  84. <a title="' . $hesklang['sm_title'] . '" href="service_messages.php">' . $hesklang['sm_title'] . '</a>
  85. </li>';
  86. }
  87. // Show a link to email tpl management if user has permission to do so
  88. if (hesk_checkPermission('can_man_email_tpl', 0)) {
  89. echo '
  90. <li role="presentation">
  91. <a title="' . $hesklang['email_templates'] . '" href="manage_email_templates.php">' . $hesklang['email_templates'] . '</a>
  92. </li>
  93. ';
  94. }
  95. if (hesk_checkPermission('can_man_ticket_statuses', 0)) {
  96. echo '
  97. <li role="presentation">
  98. <a title="' . $hesklang['statuses'] . '" href="manage_statuses.php">' . $hesklang['statuses'] . '</a>
  99. </li>
  100. ';
  101. }
  102. ?>
  103. <li role="presentation" class="active">
  104. <a title="<?php echo $hesklang['tab_4']; ?>" href="custom_fields.php">
  105. <?php echo $hesklang['tab_4']; ?>
  106. <i class="fa fa-question-circle settingsquestionmark"
  107. onclick="alert('<?php echo hesk_makeJsString($hesklang['cf_intro']); ?>')"></i>
  108. </a>
  109. </li>
  110. </ul>
  111. <div class="tab-content summaryList tabPadding">
  112. <?php
  113. // Did we reach the custom fields limit?
  114. if ($hesk_settings['num_custom_fields'] >= 50 && $action != 'edit_cf')
  115. {
  116. hesk_show_info($hesklang['cf_limit']);
  117. }
  118. // Less than 50 custom fields
  119. else
  120. {
  121. ?>
  122. <div class="panel panel-default">
  123. <div class="panel-heading">
  124. <h4><a name="new_cf"></a><?php echo hesk_SESSION('edit_cf') ? $hesklang['edit_cf'] : $hesklang['new_cf']; ?></h4>
  125. </div>
  126. <div class="panel-body">
  127. <form action="custom_fields.php" method="post" name="form1" class="form-horizontal">
  128. <div class="form-group">
  129. <label for="name[]" class="col-sm-3 control-label">
  130. <?php echo $hesklang['custom_n']; ?>
  131. </label>
  132. <?php
  133. $names = hesk_SESSION(array('new_cf','names'));
  134. if ($hesk_settings['can_sel_lang'] && count($hesk_settings['languages']) > 1)
  135. {
  136. ?>
  137. <table border="0">
  138. <?php foreach ($hesk_settings['languages'] as $lang => $info): ?>
  139. <tr>
  140. <td><?php echo $lang; ?></td>
  141. <td><input type="text" class="form-control" name="name[<?php echo $lang; ?>]" size="30" value="<?php echo (isset($names[$lang]) ? $names[$lang] : ''); ?>"></td>
  142. </tr>
  143. <?php endforeach; ?>
  144. </table>
  145. <?php
  146. }
  147. else
  148. {
  149. ?>
  150. <div class="col-sm-9">
  151. <input type="text" class="form-control" name="name[<?php echo $hesk_settings['language']; ?>]" size="30" value="<?php echo isset($names[$hesk_settings['language']]) ? $names[$hesk_settings['language']] : ''; ?>" />
  152. </div>
  153. <?php
  154. }
  155. ?>
  156. </div>
  157. <div class="form-group">
  158. <label for="name[]" class="col-sm-3 control-label">
  159. <?php echo $hesklang['s_type']; ?>
  160. </label>
  161. <div class="col-sm-9">
  162. <select name="type" class="form-control" onchange="hesk_setType(this.value);">
  163. <?php $type = hesk_SESSION(array('new_cf','type'), 'text'); ?>
  164. <option value="text" <?php if ($type == 'text') {echo 'selected';} ?> ><?php echo $hesklang['stf']; ?></option>
  165. <option value="textarea" <?php if ($type == 'textarea') {echo 'selected';} ?> ><?php echo $hesklang['stb']; ?></option>
  166. <option value="radio" <?php if ($type == 'radio') {echo 'selected';} ?> ><?php echo $hesklang['srb']; ?></option>
  167. <option value="select" <?php if ($type == 'select') {echo 'selected';} ?> ><?php echo $hesklang['ssb']; ?></option>
  168. <option value="checkbox" <?php if ($type == 'checkbox') {echo 'selected';} ?> ><?php echo $hesklang['scb']; ?></option>
  169. <option value="date" <?php if ($type == 'date') {echo 'selected';} ?> ><?php echo $hesklang['date']; ?></option>
  170. <option value="email" <?php if ($type == 'email') {echo 'selected';} ?> ><?php echo $hesklang['email']; ?></option>
  171. <option value="readonly" <?php if ($type == 'readonly') {echo 'selected';} ?> ><?php echo $hesklang['readonly_custom_field']; ?></option>
  172. <option value="hidden" <?php if ($type == 'hidden') {echo 'selected';} ?> ><?php echo $hesklang['sch']; ?></option>
  173. </select><br>
  174. <?php
  175. $value = hesk_SESSION(array('new_cf','value'));
  176. if (is_string($value))
  177. {
  178. $value = json_decode($value, true);
  179. }
  180. ?>
  181. <div id="text" style="display:<?php echo ($type == 'text') ? 'block' : 'none' ?>">
  182. <div class="form-group">
  183. <label class="col-sm-3 control-label" for="max_length">
  184. <?php echo $hesklang['custom_l']; ?>
  185. </label>
  186. <div class="col-sm-3">
  187. <input type="text" class="form-control" name="max_length"
  188. value="<?php echo isset($value['max_length']) ? intval($value['max_length']) : '255'; ?>" size="5">
  189. </div>
  190. </div>
  191. <div class="form-group">
  192. <label class="col-sm-3 control-label" for="default_value">
  193. <?php echo $hesklang['defw']; ?>
  194. </label>
  195. <div class="col-sm-3">
  196. <input type="text" class="form-control" name="default_value"
  197. value="<?php echo isset($value['default_value']) ? $value['default_value'] : ''; ?>" size="30">
  198. </div>
  199. </div>
  200. </div>
  201. <div id="readonly" style="display:<?php echo ($type == 'readonly') ? 'block' : 'none' ?>">
  202. <div class="form-group">
  203. <label class="col-sm-3 control-label" for="max_length">
  204. <?php echo $hesklang['custom_l']; ?>
  205. </label>
  206. <div class="col-sm-3">
  207. <input type="text" class="form-control" name="readonly_max_length"
  208. value="<?php echo isset($value['max_length']) ? intval($value['max_length']) : '255'; ?>" size="5">
  209. </div>
  210. </div>
  211. <div class="form-group">
  212. <label class="col-sm-3 control-label" for="value">
  213. <?php echo $hesklang['defw']; ?>
  214. </label>
  215. <div class="col-sm-3">
  216. <input type="text" class="form-control" name="readonly_default_value"
  217. value="<?php echo isset($value['default_value']) ? $value['default_value'] : ''; ?>" size="30">
  218. </div>
  219. </div>
  220. </div>
  221. <div id="textarea" style="display:<?php echo ($type == 'textarea') ? 'block' : 'none' ?>">
  222. <div class="form-group">
  223. <label class="col-sm-3 control-label" for="rows">
  224. <?php echo $hesklang['rows']; ?>
  225. </label>
  226. <div class="col-sm-3">
  227. <input type="text" class="form-control" name="rows"
  228. value="<?php echo isset($value['rows']) ? intval($value['rows']) : '12'; ?>" size="5">
  229. </div>
  230. </div>
  231. <div class="form-group">
  232. <label class="col-sm-3 control-label" for="cols">
  233. <?php echo $hesklang['cols']; ?>
  234. </label>
  235. <div class="col-sm-3">
  236. <input type="text" class="form-control" name="cols"
  237. value="<?php echo isset($value['cols']) ? intval($value['cols']) : '60'; ?>" size="5">
  238. </div>
  239. </div>
  240. </div>
  241. <div id="radio" style="display:<?php echo ($type == 'radio') ? 'block' : 'none' ?>">
  242. <p><?php echo $hesklang['opt2']; ?></p>
  243. <p><label><input type="checkbox" name="no_default" id="no_default" value="1" <?php if ( ! empty($value['no_default'])) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['rcheck']; ?> </label></p>
  244. <textarea class="form-control" name="radio_options" rows="6" cols="40"><?php echo (isset($value['radio_options']) && is_array($value['radio_options'])) ? implode("\n", $value['radio_options']) : ''; ?></textarea>
  245. </div>
  246. <div id="select" style="display:<?php echo ($type == 'select') ? 'block' : 'none' ?>">
  247. <p><?php echo $hesklang['opt3']; ?></p>
  248. <p><label><input type="checkbox" name="show_select" id="show_select" value="1" <?php if ( ! empty($value['show_select'])) {echo 'checked="checked"';} ?> /> <?php echo $hesklang['show_select']; ?> </label></p>
  249. <textarea class="form-control" name="select_options" rows="6" cols="40"><?php echo isset($value['select_options']) && is_array($value['select_options']) ? implode("\n", $value['select_options']) : ''; ?></textarea>
  250. </div>
  251. <div id="checkbox" style="display:<?php echo ($type == 'checkbox') ? 'block' : 'none' ?>">
  252. <p><?php echo $hesklang['opt4']; ?></p>
  253. <textarea class="form-control" name="checkbox_options" rows="6" cols="40"><?php echo isset($value['checkbox_options']) && is_array($value['checkbox_options']) ? implode("\n", $value['checkbox_options']) : ''; ?></textarea>
  254. </div>
  255. <div id="date" style="display:<?php echo ($type == 'date') ? 'block' : 'none' ?>">
  256. <div class="form-group">
  257. <label class="col-sm-3 control-label">
  258. <?php echo $hesklang['dmin']; ?>
  259. </label>
  260. <div class="col-sm-9">
  261. <?php
  262. $dmin = isset($value['dmin']) ? $value['dmin'] : '';
  263. // Defaults
  264. $dmin_pm = '+';
  265. $dmin_num = 1;
  266. $dmin_type = 'day';
  267. // Minimum date is in "+1 day" format
  268. if (preg_match("/^([+-]{1})(\d+) (day|week|month|year)$/", $dmin, $matches))
  269. {
  270. $dmin = '';
  271. $dmin_rf = 2;
  272. $dmin_pm = $matches[1];
  273. $dmin_num = $matches[2];
  274. $dmin_type = $matches[3];
  275. }
  276. // Minimum date is in "MM/DD/YYYY" format
  277. elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $dmin))
  278. {
  279. $dmin_rf = 1;
  280. }
  281. else
  282. {
  283. $dmin = '';
  284. $dmin_rf = 0;
  285. }
  286. ?>
  287. <div class="form-inline">
  288. <div class="radio">
  289. <label>
  290. <input type="radio" name="dmin_rf" id="dmin_rf0" value="0"
  291. <?php if ($dmin_rf == 0) {echo 'checked';} ?>> <?php echo $hesklang['d_any']; ?>
  292. </label>
  293. </div>
  294. </div>
  295. <div class="form-inline">
  296. <div class="radio">
  297. <label>
  298. <input type="radio" name="dmin_rf" id="dmin_rf1" value="1"
  299. <?php if ($dmin_rf == 1) {echo 'checked';} ?>> <?php echo $hesklang['d_fixed']; ?>
  300. </label>
  301. </div>
  302. <input type="text" name="dmin" value="<?php echo $dmin; ?>" id="dmin" class="form-control datepicker" size="10" onfocus="document.getElementById('dmin_rf1').checked = true">
  303. </div>
  304. <div class="form-inline">
  305. <div class="radio">
  306. <label>
  307. <input type="radio" name="dmin_rf" id="dmin_rf2" value="2"
  308. <?php if ($dmin_rf == 2) {echo 'checked';} ?>> <?php echo $hesklang['d_relative']; ?>
  309. </label>
  310. </div>
  311. <select name="dmin_pm" class="form-control" onclick="document.getElementById('dmin_rf2').checked = true" onchange="document.getElementById('dmin_rf2').checked = true">
  312. <option <?php if ($dmin_pm == '+') {echo 'selected';} ?>>+</option>
  313. <option <?php if ($dmin_pm == '-') {echo 'selected';} ?>>-</option>
  314. </select>
  315. <input type="text" class="form-control" name="dmin_num" value="<?php echo $dmin_num; ?>" size="5" onclick="document.getElementById('dmin_rf2').checked = true" onchange="document.getElementById('dmin_rf2').checked = true">
  316. <select class="form-control" name="dmin_type" onclick="document.getElementById('dmin_rf2').checked = true" onchange="document.getElementById('dmin_rf2').checked = true">
  317. <option value="day" <?php if ($dmin_type == 'day') {echo 'selected';} ?>><?php echo $hesklang['d_day']; ?></option>
  318. <option value="week" <?php if ($dmin_type == 'week') {echo 'selected';} ?>><?php echo $hesklang['d_week']; ?></option>
  319. <option value="month" <?php if ($dmin_type == 'month') {echo 'selected';} ?>><?php echo $hesklang['d_month']; ?></option>
  320. <option value="year" <?php if ($dmin_type == 'year') {echo 'selected';} ?>><?php echo $hesklang['d_year']; ?></option>
  321. </select>
  322. </div>
  323. </div>
  324. </div>
  325. <div class="form-group">
  326. <label class="col-sm-3 control-label">
  327. <?php echo $hesklang['dmax']; ?>
  328. </label>
  329. <div class="col-sm-9">
  330. <?php
  331. $dmax = isset($value['dmax']) ? $value['dmax'] : '';
  332. // Defaults
  333. $dmax_pm = '+';
  334. $dmax_num = 1;
  335. $dmax_type = 'day';
  336. // Minimum date is in "+1 day" format
  337. if (preg_match("/^([+-]{1})(\d+) (day|week|month|year)$/", $dmax, $matches))
  338. {
  339. $dmax = '';
  340. $dmax_rf = 2;
  341. $dmax_pm = $matches[1];
  342. $dmax_num = $matches[2];
  343. $dmax_type = $matches[3];
  344. }
  345. // Minimum date is in "MM/DD/YYYY" format
  346. elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $dmax))
  347. {
  348. $dmax_rf = 1;
  349. }
  350. else
  351. {
  352. $dmax = '';
  353. $dmax_rf = 0;
  354. }
  355. ?>
  356. <div class="form-inline">
  357. <div class="radio">
  358. <label>
  359. <input type="radio" name="dmax_rf" id="dmax_rf0" value="0"
  360. <?php if ($dmax_rf == 0) {echo 'checked';} ?>> <?php echo $hesklang['d_any']; ?>
  361. </label>
  362. </div>
  363. </div>
  364. <div class="form-inline">
  365. <div class="radio">
  366. <label>
  367. <input type="radio" name="dmax_rf" id="dmax_rf1" value="1"
  368. <?php if ($dmax_rf == 1) {echo 'checked';} ?>> <?php echo $hesklang['d_fixed']; ?>
  369. </label>
  370. </div>
  371. <input type="text" class="form-control datepicker" name="dmax" value="<?php echo $dmax; ?>" id="dmax" size="10" onfocus="document.getElementById('dmax_rf1').checked = true">
  372. </div>
  373. <div class="form-inline">
  374. <div class="radio">
  375. <label>
  376. <input type="radio" name="dmax_rf" id="dmax_rf2" value="2"
  377. <?php if ($dmax_rf == 2) {echo 'checked';} ?>> <?php echo $hesklang['d_relative']; ?>
  378. </label>
  379. </div>
  380. <select name="dmax_pm" class="form-control" onclick="document.getElementById('dmax_rf2').checked = true" onchange="document.getElementById('dmax_rf2').checked = true">
  381. <option <?php if ($dmax_pm == '+') {echo 'selected="selected"';} ?>>+</option>
  382. <option <?php if ($dmax_pm == '-') {echo 'selected="selected"';} ?>>-</option>
  383. </select>
  384. <input type="text" name="dmax_num" class="form-control" value="<?php echo $dmax_num; ?>" size="5" onclick="document.getElementById('dmax_rf2').checked = true" onchange="document.getElementById('dmax_rf2').checked = true">
  385. <select name="dmax_type" class="form-control" onclick="document.getElementById('dmax_rf2').checked = true" onchange="document.getElementById('dmax_rf2').checked = true">
  386. <option value="day" <?php if ($dmax_type == 'day') {echo 'selected';} ?>><?php echo $hesklang['d_day']; ?></option>
  387. <option value="week" <?php if ($dmax_type == 'week') {echo 'selected';} ?>><?php echo $hesklang['d_week']; ?></option>
  388. <option value="month" <?php if ($dmax_type == 'month') {echo 'selected';} ?>><?php echo $hesklang['d_month']; ?></option>
  389. <option value="year" <?php if ($dmax_type == 'year') {echo 'selected';} ?>><?php echo $hesklang['d_year']; ?></option>
  390. </select>
  391. </div>
  392. </div>
  393. </div>
  394. <div class="form-group">
  395. <label class="col-sm-3 control-label">
  396. <?php echo $hesklang['d_format']; ?>
  397. </label>
  398. <div class="col-sm-9">
  399. <?php
  400. $date_format = isset($value['date_format']) ? $value['date_format'] : 'F j, Y';
  401. $default_formats = array(
  402. 'm/d/Y',
  403. 'd/m/Y',
  404. 'm-d-Y',
  405. 'd-m-Y',
  406. 'd.m.Y',
  407. 'M j Y',
  408. 'j M Y',
  409. 'j M y',
  410. 'F j, Y',
  411. );
  412. $time = mktime(0, 0, 0, 12, 30, date('Y'));
  413. foreach ($default_formats as $format)
  414. {
  415. echo '<div class="form-inline"><div class="radio"><label><input type="radio" name="date_format" value="'.$format.'" '.($date_format == $format ? 'checked="checked"' : '').' /> '.date($format, $time).'</label></div></div>';
  416. }
  417. ?>
  418. <div class="form-inline">
  419. <div class="radio">
  420. <label>
  421. <input type="radio" name="date_format" value="custom" id="d_custom"
  422. <?php if (!in_array($date_format, $default_formats)) {echo 'checked';} ?>>
  423. <?php echo $hesklang['d_custom']; ?>
  424. </label>
  425. </div>
  426. <input type="text" class="form-control" name="date_format_custom"
  427. value="<?php echo $date_format; ?>" size="10" onclick="document.getElementById('d_custom').checked = true"
  428. onchange="document.getElementById('d_custom').checked = true">
  429. <a href="javascript:;" onclick="alert('<?php echo hesk_makeJsString($hesklang['d_ci']); ?>')">
  430. <i class="fa fa-question-circle settingsquestionmark"></i>
  431. </a>
  432. </div>
  433. </div>
  434. </div>
  435. </div>
  436. <div id="email" style="display:<?php echo ($type == 'email') ? 'block' : 'none' ?>">
  437. <div class="form-group">
  438. <label for="email_multi" class="col-sm-4 control-label">
  439. <?php echo $hesklang['meml3']; ?>
  440. </label>
  441. <div class="col-sm-8">
  442. <?php $email_multi = empty($value['multiple']) ? 0 : 1; ?>
  443. <div class="radio">
  444. <label>
  445. <input type="radio" name="email_multi" id="email_multi0" value="0"
  446. <?php if ($email_multi == 0) {echo 'checked';} ?>>
  447. <?php echo $hesklang['no']; ?>
  448. </label>
  449. </div>
  450. <div class="radio">
  451. <label>
  452. <input type="radio" name="email_multi" id="email_multi1" value="1"
  453. <?php if ($email_multi == 1) {echo 'checked';} ?>>
  454. <?php echo $hesklang['yes']; ?>
  455. </label>
  456. </div>
  457. </div>
  458. </div>
  459. <div class="form-group">
  460. <label for="email_type" class="col-sm-4 control-label">
  461. <?php echo $hesklang['email_custom_field_label']; ?>
  462. </label>
  463. <div class="col-sm-8">
  464. <?php $address_type = empty($value['email_type']) ? 'none' : $value['email_type']; ?>
  465. <div class="radio">
  466. <label>
  467. <input type="radio" name="email_type" value="none"
  468. <?php if ($address_type == 'none') {echo 'checked';} ?>>
  469. <?php echo $hesklang['none']; ?>
  470. </label>
  471. </div>
  472. <div class="radio">
  473. <label>
  474. <input type="radio" name="email_type" value="cc"
  475. <?php if ($address_type == 'cc') {echo 'checked';} ?>>
  476. <?php echo $hesklang['cc']; ?>
  477. </label>
  478. </div>
  479. <div class="radio">
  480. <label>
  481. <input type="radio" name="email_type" value="bcc"
  482. <?php if ($address_type == 'bcc') {echo 'checked';} ?>>
  483. <?php echo $hesklang['bcc']; ?>
  484. </label>
  485. </div>
  486. </div>
  487. </div>
  488. </div>
  489. <div id="hidden" style="display:<?php echo ($type == 'hidden') ? 'block' : 'none' ?>">
  490. <p><?php echo $hesklang['hidf']; ?></p>
  491. <div class="form-group">
  492. <label class="col-sm-3 control-label" for="hidden_max_length">
  493. <?php echo $hesklang['custom_l']; ?>
  494. </label>
  495. <div class="col-sm-3">
  496. <input type="text" class="form-control" name="hidden_max_length"
  497. value="<?php echo isset($value['max_length']) ? intval($value['max_length']) : '255'; ?>" size="5">
  498. </div>
  499. </div>
  500. <div class="form-group">
  501. <label class="col-sm-3 control-label" for="hidden_default_value">
  502. <?php echo $hesklang['defw']; ?>
  503. </label>
  504. <div class="col-sm-3">
  505. <input type="text" class="form-control" name="hidden_default_value"
  506. value="<?php echo isset($value['default_value']) ? $value['default_value'] : ''; ?>" size="30">
  507. </div>
  508. </div>
  509. </div>
  510. </div>
  511. </div>
  512. <div class="form-group">
  513. <label class="col-sm-3 control-label" for="use">
  514. <?php echo $hesklang['visibility']; ?>
  515. </label>
  516. <div class="col-sm-9">
  517. <?php $use = hesk_SESSION(array('new_cf','use'), 1); ?>
  518. <div class="radio">
  519. <label>
  520. <input type="radio" name="use" id="use1" value="1"
  521. onchange="hesk_setRadioOptions();" <?php if ($use == 1) {echo 'checked';} ?>>
  522. <?php echo $hesklang['cf_public']; ?>
  523. </label>
  524. </div>
  525. <div class="radio">
  526. <label>
  527. <input type="radio" name="use" id="use2" value="2"
  528. onchange="hesk_setRadioOptions();" <?php if ($use == 2) {echo 'checked';} ?>>
  529. <?php echo $hesklang['cf_private']; ?>
  530. </label>
  531. </div>
  532. </div>
  533. </div>
  534. <div class="form-group">
  535. <label for="req" class="col-sm-3 control-label">
  536. <?php echo $hesklang['custom_r']; ?>
  537. </label>
  538. <div class="col-sm-9">
  539. <?php $req = hesk_SESSION(array('new_cf','req'), 0); ?>
  540. <div class="radio">
  541. <label>
  542. <input type="radio" name="req" id="req0" value="0"
  543. <?php if ($req == 0) {echo 'checked';} ?>>
  544. <?php echo $hesklang['no']; ?>
  545. </label>
  546. </div>
  547. <div class="radio">
  548. <label>
  549. <input type="radio" name="req" id="req2" value="2"
  550. <?php if ($req == 2) {echo 'checked';} ?>>
  551. <?php echo $hesklang['yes']; ?>
  552. </label>
  553. </div>
  554. <div class="radio">
  555. <label id="req_customers" style="display:<?php echo ($use == 2) ? 'none' : 'inline'; ?>">
  556. <input type="radio" name="req" id="req1" value="1"
  557. <?php if ($req == 1) {echo 'checked';} ?>>
  558. <?php echo $hesklang['cf_cust']; ?>
  559. </label>
  560. </div>
  561. </div>
  562. </div>
  563. <div class="form-group">
  564. <label for="place" class="col-sm-3 control-label">
  565. <?php echo $hesklang['custom_place']; ?>
  566. </label>
  567. <div class="col-sm-9">
  568. <?php $place = hesk_SESSION(array('new_cf','place')) ? 1 : 0; ?>
  569. <div class="radio">
  570. <label>
  571. <input type="radio" name="place" value="0"
  572. <?php if ($place == 0) {echo 'checked';} ?>>
  573. <?php echo $hesklang['place_before']; ?>
  574. </label>
  575. </div>
  576. <div class="radio">
  577. <label>
  578. <input type="radio" name="place" value="1"
  579. <?php if ($place == 1) {echo 'checked';} ?>>
  580. <?php echo $hesklang['place_after']; ?>
  581. </label>
  582. </div>
  583. </div>
  584. </div>
  585. <div class="form-group">
  586. <label for="category" class="col-sm-3 control-label">
  587. <?php echo $hesklang['category']; ?>
  588. </label>
  589. <div class="col-sm-9">
  590. <?php $category = hesk_SESSION(array('new_cf','category')) ? 1 : 0; ?>
  591. <div class="radio">
  592. <label>
  593. <input type="radio" name="category" id="category0" value="0"
  594. onchange="hesk_setRadioOptions();" <?php if ($category == 0) {echo 'checked';} ?>>
  595. <?php echo $hesklang['cf_all']; ?>
  596. </label>
  597. </div>
  598. <div class="radio">
  599. <label>
  600. <input type="radio" name="category" id="category1" value="1"
  601. onchange="hesk_setRadioOptions();" <?php if ($category == 1) {echo 'checked';} ?>>
  602. <?php echo $hesklang['cf_cat']; ?>
  603. </label>
  604. </div>
  605. <div id="selcat" style="display:<?php echo $category ? 'block' : 'none'; ?>">
  606. <select class="form-control" name="categories[]" multiple="multiple" size="10">
  607. <?php
  608. $categories = hesk_SESSION(array('new_cf','categories'));
  609. $categories = is_array($categories) ? $categories : array();
  610. foreach ($hesk_settings['categories'] as $cat_id => $cat_name)
  611. {
  612. echo '<option value="'.$cat_id.'"'.(in_array($cat_id, $categories) ? ' selected' : '').'>'.$cat_name.'</option>';
  613. }
  614. ?>
  615. </select>
  616. <?php echo $hesklang['cf_ctrl']; ?>
  617. </div>
  618. </div>
  619. </div>
  620. <div class="form-group">
  621. <div class="col-sm-9 col-sm-offset-3">
  622. <?php echo isset($_SESSION['edit_cf']) ? '<input type="hidden" name="a" value="save_cf" /><input type="hidden" name="id" value="'.intval($_SESSION['new_cf']['id']).'" />' : '<input type="hidden" name="a" value="new_cf" />'; ?>
  623. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>" />
  624. <input type="submit" value="<?php echo $hesklang['cf_save']; ?>" class="btn btn-default">
  625. </div>
  626. </div>
  627. </form>
  628. </div>
  629. </div>
  630. <?php } ?>
  631. <script language="javascript" type="text/javascript"><!--
  632. function hesk_toggleLayer(nr,setto) {
  633. if (document.all)
  634. document.all[nr].style.display = setto;
  635. else if (document.getElementById)
  636. document.getElementById(nr).style.display = setto;
  637. }
  638. function hesk_setType(myType) {
  639. var divs = ["text", "textarea", "radio", "select", "checkbox", "date", "email", "hidden", "readonly"];
  640. var index;
  641. var setTo;
  642. for (index = 0; index < divs.length; ++index) {
  643. setTo = (myType == divs[index] + "") ? 'block' : 'none';
  644. hesk_toggleLayer(divs[index], setTo);
  645. }
  646. }
  647. function hesk_setRadioOptions() {
  648. if(document.getElementById('use1').checked) {
  649. hesk_toggleLayer('req_customers', 'inline');
  650. } else {
  651. hesk_toggleLayer('req_customers', 'none');
  652. if(document.getElementById('req1').checked) {
  653. document.getElementById('req0').checked = true;
  654. }
  655. }
  656. if(document.getElementById('category1').checked) {
  657. hesk_toggleLayer('selcat', 'block');
  658. } else {
  659. hesk_toggleLayer('selcat', 'none');
  660. }
  661. }
  662. //-->
  663. </script>
  664. <div class="panel panel-default">
  665. <div class="panel-heading">
  666. <h4><?php echo $hesklang['ex_cf']; ?></h4>
  667. </div>
  668. <div class="panel-body">
  669. <?php
  670. // List existing custom fields
  671. if ($hesk_settings['num_custom_fields'] < 1) {
  672. echo $hesklang['no_cf'];
  673. } else {
  674. ?>
  675. <table border="0" cellspacing="1" cellpadding="3" class="table table-striped" width="100%">
  676. <thead>
  677. <tr>
  678. <th><?php echo $hesklang['id']; ?></th>
  679. <th><?php echo $hesklang['custom_n']; ?></th>
  680. <th><?php echo $hesklang['s_type']; ?></th>
  681. <th><?php echo $hesklang['visibility']; ?></th>
  682. <th><?php echo $hesklang['custom_r']; ?></th>
  683. <th><?php echo $hesklang['category']; ?></th>
  684. <th><?php echo $hesklang['opt']; ?></th>
  685. </tr>
  686. </thead>
  687. <tbody>
  688. <?php
  689. $before = true;
  690. $after = true;
  691. $hide_up = false;
  692. $num_before = 0;
  693. $num_after = 0;
  694. foreach ($hesk_settings['custom_fields'] as $tmp_id => $cf) {
  695. if ($cf['place']) {
  696. $num_after++;
  697. } else {
  698. $num_before++;
  699. }
  700. }
  701. $k = 1;
  702. foreach ($hesk_settings['custom_fields'] as $tmp_id => $cf) {
  703. $tmp_id = intval(str_replace('custom', '', $tmp_id));
  704. if ($hide_up) {
  705. $hide_up = false;
  706. }
  707. if ($before && $cf['place'] == 0) {
  708. ?>
  709. <tr>
  710. <td colspan="7"><b><i><?php echo $hesklang['place_before']; ?></i></b></td>
  711. </tr>
  712. <?php
  713. $before = false;
  714. } elseif ($after && $cf['place'] == 1) {
  715. ?>
  716. <tr>
  717. <td colspan="7"><b><i><?php echo $hesklang['place_after']; ?></i></b></td>
  718. </tr>
  719. <?php
  720. $after = false;
  721. $hide_up = true;
  722. }
  723. $cf['type'] = hesk_custom_field_type($cf['type']);
  724. $cf['use'] = ($cf['use'] == 1) ? $hesklang['cf_public'] : $hesklang['cf_private'];
  725. $cf['req'] = ($cf['req'] == 0) ? $hesklang['no'] : ($cf['req'] == 2 ? $hesklang['yes'] : $hesklang['cf_cust']);
  726. $cf['category'] = count($cf['category']) ? $hesklang['cf_cat'] : $hesklang['cf_all'];
  727. ?>
  728. <tr>
  729. <td><?php echo $tmp_id; ?></td>
  730. <td><?php echo $cf['name']; ?></td>
  731. <td><?php echo $cf['type']; ?></td>
  732. <td><?php echo $cf['use']; ?></td>
  733. <td><?php echo $cf['req']; ?></td>
  734. <td><?php echo $cf['category']; ?></td>
  735. <td>
  736. <?php
  737. if ($hesk_settings['num_custom_fields'] == 2 && $num_before == 1) {
  738. // Special case, don't print anything
  739. } elseif ($hesk_settings['num_custom_fields'] > 1) {
  740. if (($num_before == 1 && $cf['place'] == 0) || ($num_after == 1 && $cf['place'] == 1)) {
  741. // Only 1 custom fields in this place, don't print anything
  742. ?>
  743. <i class="fa fa-fw icon-link">&nbsp;</i>
  744. <i class="fa fa-fw icon-link">&nbsp;</i>
  745. <?php
  746. } elseif ($k == 1 || $hide_up) {
  747. ?>
  748. <i class="fa fa-fw icon-link">&nbsp;</i>
  749. <a href="custom_fields.php?a=order_cf&amp;id=<?php echo $tmp_id; ?>&amp;move=15&amp;token=<?php hesk_token_echo(); ?>">
  750. <i class="fa fa-arrow-down fa-fw icon-link green" data-toggle="tooltip" title="<?php echo $hesklang['move_dn']; ?>"></i>
  751. </a>
  752. <?php
  753. } elseif ($k == $hesk_settings['num_custom_fields'] || $k == $num_before) {
  754. ?>
  755. <a href="custom_fields.php?a=order_cf&amp;id=<?php echo $tmp_id; ?>&amp;move=-15&amp;token=<?php hesk_token_echo(); ?>">
  756. <i class="fa fa-arrow-up fa-fw icon-link green" data-toggle="tooltip" title="<?php echo $hesklang['move_up']; ?>"></i>
  757. </a>
  758. <i class="fa fa-fw icon-link">&nbsp;</i>
  759. <?php
  760. } else {
  761. ?>
  762. <a href="custom_fields.php?a=order_cf&amp;id=<?php echo $tmp_id; ?>&amp;move=-15&amp;token=<?php hesk_token_echo(); ?>">
  763. <i class="fa fa-arrow-up fa-fw icon-link green" data-toggle="tooltip" title="<?php echo $hesklang['move_up']; ?>"></i>
  764. </a>
  765. <a href="custom_fields.php?a=order_cf&amp;id=<?php echo $tmp_id; ?>&amp;move=15&amp;token=<?php hesk_token_echo(); ?>">
  766. <i class="fa fa-arrow-down fa-fw icon-link green" data-toggle="tooltip" title="<?php echo $hesklang['move_dn']; ?>"></i>
  767. </a>
  768. <?php
  769. }
  770. }
  771. ?>
  772. <a href="custom_fields.php?a=edit_cf&amp;id=<?php echo $tmp_id; ?>">
  773. <i class="fa fa-pencil fa-fw icon-link orange" data-toggle="tooltip" title="<?php echo $hesklang['edit']; ?>"></i>
  774. </a>
  775. <a href="custom_fields.php?a=remove_cf&amp;id=<?php echo $tmp_id; ?>&amp;token=<?php hesk_token_echo(); ?>"
  776. onclick="return hesk_confirmExecute('<?php echo hesk_makeJsString($hesklang['del_cf']); ?>');">
  777. <i class="fa fa-times fa-fw icon-link red" data-toggle="tooltip" title="<?php echo $hesklang['delete']; ?>"></i>
  778. </a>
  779. </td>
  780. </tr>
  781. <?php
  782. $k++;
  783. } // End while
  784. ?>
  785. </tbody>
  786. </table>
  787. <?php } ?>
  788. </div>
  789. </div>
  790. </div>
  791. </div>
  792. </div>
  793. </div>
  794. </section>
  795. </div>
  796. <?php
  797. hesk_cleanSessionVars( array('new_cf', 'edit_cf') );
  798. require_once(HESK_PATH . 'inc/footer.inc.php');
  799. exit();
  800. /*** START FUNCTIONS ***/
  801. function save_cf()
  802. {
  803. global $hesk_settings, $hesklang;
  804. global $hesk_error_buffer;
  805. // A security check
  806. # hesk_token_check('POST');
  807. // Get custom field ID
  808. $id = intval( hesk_POST('id') ) or hesk_error($hesklang['cf_e_id']);
  809. // Validate inputs
  810. if (($cf = cf_validate()) == false)
  811. {
  812. $_SESSION['edit_cf'] = true;
  813. $_SESSION['new_cf']['id'] = $id;
  814. $tmp = '';
  815. foreach ($hesk_error_buffer as $error)
  816. {
  817. $tmp .= "<li>$error</li>\n";
  818. }
  819. $hesk_error_buffer = $tmp;
  820. $hesk_error_buffer = $hesklang['rfm'].'<br /><br /><ul>'.$hesk_error_buffer.'</ul>';
  821. hesk_process_messages($hesk_error_buffer,'custom_fields.php');
  822. }
  823. // Add custom field data into database
  824. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET
  825. `use` = '{$cf['use']}',
  826. `place` = '{$cf['place']}',
  827. `type` = '{$cf['type']}',
  828. `req` = '{$cf['req']}',
  829. `category` = ".(count($cf['categories']) ? "'".json_encode($cf['categories'])."'" : 'NULL').",
  830. `name` = '".hesk_dbEscape($cf['names'])."',
  831. `value` = ".(strlen($cf['value']) ? "'".hesk_dbEscape($cf['value'])."'" : 'NULL')."
  832. WHERE `id`={$id}");
  833. // Clear cache
  834. hesk_purge_cache('cf');
  835. // Show success
  836. $_SESSION['cford'] = $id;
  837. hesk_process_messages($hesklang['cf_mdf'],'custom_fields.php','SUCCESS');
  838. } // End save_cf()
  839. function edit_cf()
  840. {
  841. global $hesk_settings, $hesklang;
  842. // Get custom field ID
  843. $id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']);
  844. // Get details from the database
  845. $res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `id`={$id} LIMIT 1");
  846. if ( hesk_dbNumRows($res) != 1 )
  847. {
  848. hesk_error($hesklang['cf_not_found']);
  849. }
  850. $cf = hesk_dbFetchAssoc($res);
  851. $cf['names'] = json_decode($cf['name'], true);
  852. unset($cf['name']);
  853. if (strlen($cf['category']))
  854. {
  855. $cf['categories'] = json_decode($cf['category'], true);
  856. $cf['category'] = 1;
  857. }
  858. else
  859. {
  860. $cf['categories'] = array();
  861. $cf['category'] = 0;
  862. }
  863. $_SESSION['new_cf'] = $cf;
  864. $_SESSION['edit_cf'] = true;
  865. } // End edit_cf()
  866. function order_cf()
  867. {
  868. global $hesk_settings, $hesklang;
  869. // A security check
  870. hesk_token_check();
  871. // Get ID and move parameters
  872. $id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']);
  873. $move = intval( hesk_GET('move') );
  874. $_SESSION['cford'] = $id;
  875. // Update article details
  876. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=`order`+".intval($move)." WHERE `id`={$id}");
  877. // Update order of all custom fields
  878. update_cf_order();
  879. // Clear cache
  880. hesk_purge_cache('cf');
  881. // Finish
  882. header('Location: custom_fields.php');
  883. exit();
  884. } // End order_cf()
  885. function update_cf_order()
  886. {
  887. global $hesk_settings, $hesklang;
  888. // Get list of current custom fields
  889. $res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `use` IN ('1','2') ORDER BY `place` ASC, `order` ASC");
  890. // Update database
  891. $i = 10;
  892. while ( $cf = hesk_dbFetchAssoc($res) )
  893. {
  894. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=".intval($i)." WHERE `id`='".intval($cf['id'])."'");
  895. $i += 10;
  896. }
  897. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=1000 WHERE `use`='0'");
  898. return true;
  899. } // END update_cf_order()
  900. function remove_cf()
  901. {
  902. global $hesk_settings, $hesklang;
  903. // A security check
  904. hesk_token_check();
  905. // Get ID
  906. $id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']);
  907. // Reset the custom field
  908. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `use`='0', `place`='0', `type`='text', `req`='0', `category`=NULL, `name`='', `value`=NULL, `order`=1000 WHERE `id`={$id}");
  909. // Were we successful?
  910. if ( hesk_dbAffectedRows() == 1 )
  911. {
  912. // Update order
  913. update_cf_order();
  914. // Clear cache
  915. hesk_purge_cache('cf');
  916. // Delete custom field data from tickets
  917. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `custom{$id}`=''");
  918. // Show success message
  919. hesk_process_messages($hesklang['cf_deleted'],'./custom_fields.php','SUCCESS');
  920. }
  921. else
  922. {
  923. hesk_process_messages($hesklang['cf_not_found'],'./custom_fields.php');
  924. }
  925. } // End remove_cf()
  926. function cf_validate()
  927. {
  928. global $hesk_settings, $hesklang;
  929. global $hesk_error_buffer;
  930. $hesk_error_buffer = array();
  931. // Get names
  932. $cf['names'] = hesk_POST_array('name');
  933. // Make sure only valid names pass
  934. foreach ($cf['names'] as $key => $name)
  935. {
  936. if ( ! isset($hesk_settings['languages'][$key]))
  937. {
  938. unset($cf['names'][$key]);
  939. }
  940. else
  941. {
  942. $name = is_array($name) ? '' : hesk_input($name, 0, 0, HESK_SLASH);
  943. if (strlen($name) < 1)
  944. {
  945. unset($cf['names'][$key]);
  946. }
  947. else
  948. {
  949. $cf['names'][$key] = stripslashes($name);
  950. }
  951. }
  952. }
  953. // No name entered?
  954. if ( ! count($cf['names']))
  955. {
  956. $hesk_error_buffer[] = $hesklang['err_custname'];
  957. }
  958. // Get type and values
  959. $cf['type'] = hesk_POST('type');
  960. switch ($cf['type'])
  961. {
  962. case 'textarea':
  963. $cf['rows'] = hesk_checkMinMax(intval(hesk_POST('rows')), 1, 100, 12);
  964. $cf['cols'] = hesk_checkMinMax(intval(hesk_POST('cols')), 1, 500, 60);
  965. $cf['value'] = array('rows' => $cf['rows'], 'cols' => $cf['cols']);
  966. break;
  967. case 'radio':
  968. $cf['radio_options'] = stripslashes(hesk_input(hesk_POST('radio_options'), 0, 0, HESK_SLASH));
  969. $options = preg_split("/\\r\\n|\\r|\\n/", $cf['radio_options']);
  970. $no_default = hesk_POST('no_default') ? 1 : 0;
  971. $cf['value'] = array('radio_options' => $options, 'no_default' => $no_default);
  972. if (count($options) < 2)
  973. {
  974. $hesk_error_buffer[] = $hesklang['atl2'];
  975. }
  976. break;
  977. case 'select':
  978. $cf['select_options'] = stripslashes(hesk_input(hesk_POST('select_options'), 0, 0, HESK_SLASH));
  979. $options = preg_split("/\\r\\n|\\r|\\n/", $cf['select_options']);
  980. $show_select = hesk_POST('show_select') ? 1 : 0;
  981. $cf['value'] = array('show_select' => $show_select, 'select_options' => $options);
  982. if (count($options) < 2)
  983. {
  984. $hesk_error_buffer[] = $hesklang['atl2'];
  985. }
  986. break;
  987. case 'checkbox':
  988. $cf['checkbox_options'] = stripslashes(hesk_input(hesk_POST('checkbox_options'), 0, 0, HESK_SLASH));
  989. $options = preg_split("/\\r\\n|\\r|\\n/", $cf['checkbox_options']);
  990. $cf['value'] = array('checkbox_options' => $options);
  991. if ( ! isset($options[0]) || strlen($options[0]) < 1)
  992. {
  993. $hesk_error_buffer[] = $hesklang['atl1'];
  994. }
  995. break;
  996. case 'date':
  997. $cf['dmin'] = '';
  998. $cf['dmax'] = '';
  999. // Minimum date
  1000. $dmin_rf = hesk_POST('dmin_rf');
  1001. if ($dmin_rf == 1)
  1002. {
  1003. $dmin = hesk_POST('dmin');
  1004. if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $dmin))
  1005. {
  1006. $cf['dmin'] = $dmin;
  1007. }
  1008. }
  1009. elseif ($dmin_rf == 2)
  1010. {
  1011. $dmin_pm = hesk_POST('dmin_pm') == '+' ? '+' : '-';
  1012. $dmin_num = intval(hesk_POST('dmin_num', 0));
  1013. $dmin_type = hesk_POST('dmin_type');
  1014. if ( ! in_array($dmin_type, array('day', 'week', 'month', 'year')))
  1015. {
  1016. $dmin_type = 'day';
  1017. }
  1018. $cf['dmin'] = $dmin_pm . $dmin_num . ' ' . $dmin_type;
  1019. }
  1020. // Maximum date
  1021. $dmax_rf = hesk_POST('dmax_rf');
  1022. if ($dmax_rf == 1)
  1023. {
  1024. $dmax = hesk_POST('dmax');
  1025. if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $dmax))
  1026. {
  1027. $cf['dmax'] = $dmax;
  1028. }
  1029. }
  1030. elseif ($dmax_rf == 2)
  1031. {
  1032. $dmax_pm = hesk_POST('dmax_pm') == '+' ? '+' : '-';
  1033. $dmax_num = intval(hesk_POST('dmax_num', 0));
  1034. $dmax_type = hesk_POST('dmax_type');
  1035. if ( ! in_array($dmax_type, array('day', 'week', 'month', 'year')))
  1036. {
  1037. $dmax_type = 'day';
  1038. }
  1039. $cf['dmax'] = $dmax_pm . $dmax_num . ' ' . $dmax_type;
  1040. }
  1041. // Minimum date should not be higher than maximum date
  1042. if (strlen($cf['dmin']) && strlen($cf['dmax']))
  1043. {
  1044. if (strtotime($cf['dmin']) > strtotime($cf['dmax']))
  1045. {
  1046. $hesk_error_buffer[] = $hesklang['d_mm'];
  1047. }
  1048. }
  1049. // Date format
  1050. $date_format = hesk_POST('date_format');
  1051. if ($date_format == 'custom')
  1052. {
  1053. $date_format = hesk_POST('date_format_custom');
  1054. }
  1055. $cf['date_format'] = preg_replace('/[^a-zA-Z0-9 \/\.\_+\-,;:#(){}\[\]\'@*]/', '', $date_format);
  1056. $cf['value'] = array('dmin' => $cf['dmin'], 'dmax' => $cf['dmax'], 'date_format' => $cf['date_format']);
  1057. break;
  1058. case 'email':
  1059. $cf['email_multi'] = hesk_POST('email_multi') ? 1 : 0;
  1060. $cf['email_type'] = hesk_POST('email_type', 'none');
  1061. $cf['value'] = array('multiple' => $cf['email_multi'], 'email_type' => $cf['email_type']);
  1062. break;
  1063. case 'hidden':
  1064. $cf['hidden_max_length'] = hesk_checkMinMax(intval(hesk_POST('hidden_max_length')), 1, 10000, 255);
  1065. $cf['hidden_default_value'] = stripslashes(hesk_input(hesk_POST('hidden_default_value'), 0, 0, HESK_SLASH));
  1066. $cf['value'] = array('max_length' => $cf['hidden_max_length'], 'default_value' => $cf['hidden_default_value']);
  1067. break;
  1068. case 'readonly':
  1069. $max_length = hesk_POST('readonly_max_length');
  1070. $value = hesk_POST('readonly_default_value');
  1071. $cf['value'] = array('default_value' => $value, 'max_length' => $max_length);
  1072. break;
  1073. default:
  1074. $cf['type'] = 'text';
  1075. $cf['max_length'] = hesk_checkMinMax(intval(hesk_POST('max_length')), 1, 10000, 255);
  1076. $cf['default_value'] = stripslashes(hesk_input(hesk_POST('default_value'), 0, 0, HESK_SLASH));
  1077. $cf['value'] = array('max_length' => $cf['max_length'], 'default_value' => $cf['default_value']);
  1078. }
  1079. // Enable
  1080. $cf['use'] = hesk_POST('use') == 2 ? 2 : 1;
  1081. // req
  1082. $cf['req'] = hesk_POST('req');
  1083. $cf['req'] = $cf['req'] == 2 ? 2 : ($cf['req'] == 1 ? 1 : 0);
  1084. // Private fields cannot be req for customers
  1085. if ($cf['use'] == 2 && $cf['req'] == 1)
  1086. {
  1087. $cf['req'] = 0;
  1088. }
  1089. // Located above or below "Message"?
  1090. $cf['place'] = hesk_POST('place') ? 1 : 0;
  1091. // Get allowed categories
  1092. if (hesk_POST('category'))
  1093. {
  1094. $cf['category'] = 1;
  1095. $cf['categories'] = hesk_POST_array('categories');
  1096. foreach ($cf['categories'] as $key => $cat_id)
  1097. {
  1098. if ( ! isset($hesk_settings['categories'][$cat_id]) )
  1099. {
  1100. unset($cf['categories'][$key]);
  1101. }
  1102. }
  1103. if ( ! count($cf['categories']))
  1104. {
  1105. $hesk_error_buffer[] = $hesklang['cf_nocat'];
  1106. }
  1107. }
  1108. else
  1109. {
  1110. $cf['category'] = 0;
  1111. $cf['categories'] = array();
  1112. }
  1113. // Any errors?
  1114. if (count($hesk_error_buffer))
  1115. {
  1116. $_SESSION['new_cf'] = $cf;
  1117. return false;
  1118. }
  1119. $cf['names'] = addslashes(json_encode($cf['names']));
  1120. $cf['value'] = $cf['type'] == 'date' ? json_encode($cf['value']) : addslashes(json_encode($cf['value']));
  1121. return $cf;
  1122. } // END cf_validate()
  1123. function new_cf()
  1124. {
  1125. global $hesk_settings, $hesklang;
  1126. global $hesk_error_buffer;
  1127. // A security check
  1128. # hesk_token_check('POST');
  1129. // Validate inputs
  1130. if (($cf = cf_validate()) == false)
  1131. {
  1132. $tmp = '';
  1133. foreach ($hesk_error_buffer as $error)
  1134. {
  1135. $tmp .= "<li>$error</li>\n";
  1136. }
  1137. $hesk_error_buffer = $tmp;
  1138. $hesk_error_buffer = $hesklang['rfm'].'<br /><br /><ul>'.$hesk_error_buffer.'</ul>';
  1139. hesk_process_messages($hesk_error_buffer,'custom_fields.php');
  1140. }
  1141. // Get the lowest available custom field ID
  1142. $res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `use`='0' ORDER BY `id` ASC LIMIT 1");
  1143. $row = hesk_dbFetchRow($res);
  1144. $_SESSION['cford'] = intval($row[0]);
  1145. // Insert custom field into database
  1146. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET
  1147. `use` = '{$cf['use']}',
  1148. `place` = '{$cf['place']}',
  1149. `type` = '{$cf['type']}',
  1150. `req` = '{$cf['req']}',
  1151. `category` = ".(count($cf['categories']) ? "'".json_encode($cf['categories'])."'" : 'NULL').",
  1152. `name` = '".hesk_dbEscape($cf['names'])."',
  1153. `value` = ".(strlen($cf['value']) ? "'".hesk_dbEscape($cf['value'])."'" : 'NULL').",
  1154. `order` = 990
  1155. WHERE `id`={$_SESSION['cford']}");
  1156. // Update order
  1157. update_cf_order();
  1158. // Clear cache
  1159. hesk_purge_cache('cf');
  1160. // Show success
  1161. hesk_process_messages($hesklang['cf_added'],'custom_fields.php','SUCCESS');
  1162. } // End new_cf()