From 31b3aeabf853fa2115d70e6a6e06174dd2cc13e0 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 14 Nov 2016 15:52:39 -0500 Subject: [PATCH] Fix multilang custom fields, add validators to CF on admin new ticket --- admin/custom_fields.php | 5 +- admin/new_ticket.php | 124 ++++++++++++++++++++++++++++------------ 2 files changed, 89 insertions(+), 40 deletions(-) diff --git a/admin/custom_fields.php b/admin/custom_fields.php index e059953a..09f6d65f 100755 --- a/admin/custom_fields.php +++ b/admin/custom_fields.php @@ -148,7 +148,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); $info): ?> - + @@ -737,6 +737,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); } } + $k = 1; foreach ($hesk_settings['custom_fields'] as $id => $cf) { $id = intval(str_replace('custom', '', $id)); @@ -820,8 +821,8 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); diff --git a/admin/new_ticket.php b/admin/new_ticket.php index f32417de..7fe6d350 100644 --- a/admin/new_ticket.php +++ b/admin/new_ticket.php @@ -348,7 +348,13 @@ $show_quick_help = $show['show']; /* custom fields BEFORE comments */ foreach ($hesk_settings['custom_fields'] as $k => $v) { if ($v['use'] && $v['place'] == 0 && hesk_is_custom_field_in_category($k, $category)) { - $v['req'] = $v['req']==2 ? '*' : ''; + if ($v['req'] == 2) { + $v['req']= '*'; + $required_attribute = 'data-error="' . $hesklang['this_field_is_required'] . '" required'; + } else { + $v['req'] = ''; + $required_attribute = ''; + } if ($v['type'] == 'checkbox') { $k_value = array(); @@ -367,7 +373,7 @@ $show_quick_help = $show['show']; /* Radio box */ case 'radio': $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; - echo '
'; + echo '
'; foreach ($v['value']['radio_options'] as $option) { @@ -385,10 +391,18 @@ $show_quick_help = $show['show']; $formattedId = preg_replace("/[\s-]+/", " ", $v['name']); $formattedId = preg_replace("/[\s_]/", "-", $formattedId); - echo '
'; + echo '
+ +
'; } - echo '
'; + echo ' +
+
+
'; break; /* Select drop-down box */ @@ -400,8 +414,8 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; - echo '
-
'; // Show "Click to select"? if (!empty($v['value']['show_select'])) { @@ -419,7 +433,8 @@ $show_quick_help = $show['show']; echo ''; } - echo '
'; + echo ' +
'; break; /* Checkbox */ @@ -429,7 +444,7 @@ $show_quick_help = $show['show']; $formattedId = preg_replace("/[\s_]/", "-", $formattedId); $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; - echo '
'; + echo '
'; foreach ($v['value']['checkbox_options'] as $option) { if (in_array($option, $k_value)) { @@ -438,9 +453,10 @@ $show_quick_help = $show['show']; $checked = ''; } - echo '
'; + echo '
'; } - echo '
'; + echo ' +
'; break; /* Large text box */ @@ -452,12 +468,16 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; echo '
- -
-
'; + +
+
'; break; case 'date': + if ($required_attribute != '') { + $required_attribute .= ' pattern="[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])"'; + } + //Clean up multiple dashes or whitespaces $formattedId = preg_replace("/[\s-]+/", " ", $v['name']); $formattedId = preg_replace("/[\s_]/", "-", $formattedId); @@ -468,8 +488,9 @@ $show_quick_help = $show['show'];
- + +
'; break; @@ -483,8 +504,11 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; echo '
- -
+ +
+ +
+
'; break; @@ -504,8 +528,11 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; echo '
- -
+ +
+ +
+
'; } } @@ -722,7 +749,13 @@ $show_quick_help = $show['show']; foreach ($hesk_settings['custom_fields'] as $k => $v) { if ($v['use'] && $v['place'] == 1 && hesk_is_custom_field_in_category($k, $category)) { - $v['req'] = $v['req']==2 ? '*' : ''; + if ($v['req'] == 2) { + $v['req']= '*'; + $required_attribute = 'data-error="' . $hesklang['this_field_is_required'] . '" required'; + } else { + $v['req'] = ''; + $required_attribute = ''; + } if ($v['type'] == 'checkbox') { $k_value = array(); @@ -742,12 +775,15 @@ $show_quick_help = $show['show']; case 'radio': $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; - echo '
'; + echo '
'; foreach ($v['value']['radio_options'] as $option) { - if (strlen($k_value) == 0 || $k_value == $option) { + if (strlen($k_value) == 0) { + $k_value = $option; + $checked = empty($v['value']['no_default']) ? 'checked' : ''; + } elseif ($k_value == $option) { $k_value = $option; $checked = 'checked'; } else { @@ -758,10 +794,10 @@ $show_quick_help = $show['show']; $formattedId = preg_replace("/[\s-]+/", " ", $v['name']); $formattedId = preg_replace("/[\s_]/", "-", $formattedId); - echo '
'; + echo '
'; } - echo '
'; + echo '
'; break; /* Select drop-down box */ @@ -773,8 +809,8 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; - echo '
-
'; // Show "Click to select"? if (!empty($v['value']['show_select'])) { @@ -792,7 +828,7 @@ $show_quick_help = $show['show']; echo ''; } - echo '
'; + echo '
'; break; /* Checkbox */ @@ -802,7 +838,7 @@ $show_quick_help = $show['show']; $formattedId = preg_replace("/[\s_]/", "-", $formattedId); $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; - echo '
'; + echo '
'; foreach ($v['value']['checkbox_options'] as $option) { if (in_array($option, $k_value)) { @@ -811,9 +847,9 @@ $show_quick_help = $show['show']; $checked = ''; } - echo '
'; + echo '
'; } - echo '
'; + echo '
'; break; /* Large text box */ @@ -825,12 +861,17 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; echo '
- -
+ +
+
'; break; case 'date': + if ($required_attribute != '') { + $required_attribute .= ' pattern="[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])"'; + } + //Clean up multiple dashes or whitespaces $formattedId = preg_replace("/[\s-]+/", " ", $v['name']); $formattedId = preg_replace("/[\s_]/", "-", $formattedId); @@ -841,8 +882,9 @@ $show_quick_help = $show['show'];
- + +
'; break; @@ -856,8 +898,11 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' isError' : ''; echo '
- -
+ +
+ +
+
'; break; @@ -876,8 +921,11 @@ $show_quick_help = $show['show']; $cls = in_array($k, $_SESSION['iserror']) ? ' class="isError" ' : ''; echo '
- -
+ +
+ +
+
'; } }