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 52KB

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