From 2fdba1861f98f30637fc192446cd75af05c7d119 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 6 Aug 2014 15:27:23 -0500 Subject: [PATCH] Add validation errors for custom number formats And fixup the migration patch --- include/class.config.php | 3 +++ include/class.topic.php | 4 ++++ include/staff/helptopic.inc.php | 1 + include/staff/settings-tickets.inc.php | 1 + include/upgrader/streams/core/8f99b8bf-00000000.task.php | 5 ++--- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/class.config.php b/include/class.config.php index 79bb05fd4..8fdb403e9 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -981,6 +981,9 @@ class OsticketConfig extends Config { $errors['default_help_topic'] = 'Default help topic must be set to active'; } + if (!preg_match('`(?!<\\\)#`', $vars['number_format'])) + $errors['number_format'] = 'Ticket number format requires at least one hash character (#)'; + if(!Validator::process($f, $vars, $errors) || $errors) return false; diff --git a/include/class.topic.php b/include/class.topic.php index 940d9156b..703b8ff3b 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -341,6 +341,10 @@ class Topic { if (!is_numeric($vars['dept_id'])) $errors['dept_id']='You must select a department'; + if ($vars['custom-numbers'] && !preg_match('`(?!<\\\)#`', $vars['number_format'])) + $errors['number_format'] = + 'Ticket number format requires at least one hash character (#)'; + if($errors) return false; foreach (array('sla_id','form_id','page_id','topic_pid') as $f) diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php index a13daf551..0eb7307a3 100644 --- a/include/staff/helptopic.inc.php +++ b/include/staff/helptopic.inc.php @@ -271,6 +271,7 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"'; $seq = new RandomSequence(); echo $seq->current($info['number_format']); } ?></span></span> + <div class="error"><?php echo $errors['number_format']; ?></div> </td> </tr> <tr> diff --git a/include/staff/settings-tickets.inc.php b/include/staff/settings-tickets.inc.php index 793b61b85..759d98dbf 100644 --- a/include/staff/settings-tickets.inc.php +++ b/include/staff/settings-tickets.inc.php @@ -31,6 +31,7 @@ if(!($maxfileuploads=ini_get('max_file_uploads'))) echo $seq->current($config['number_format']); ?></span></span> <i class="help-tip icon-question-sign" href="#number_format"></i> + <div class="error"><?php echo $errors['number_format']; ?></div> </td> </tr> <tr><td width="220">Default Ticket Number Sequence:</td> diff --git a/include/upgrader/streams/core/8f99b8bf-00000000.task.php b/include/upgrader/streams/core/8f99b8bf-00000000.task.php index 4644062a3..8a6b8d7f5 100644 --- a/include/upgrader/streams/core/8f99b8bf-00000000.task.php +++ b/include/upgrader/streams/core/8f99b8bf-00000000.task.php @@ -11,11 +11,10 @@ class SequenceLoader extends MigrationTask { $i18n = new Internationalization('en_US'); $sequences = $i18n->getTemplate('sequence.yaml')->getData(); foreach ($sequences as $s) { - Sequence::create($s); - $s->save(); + Sequence::create($s)->save(); } db_query('UPDATE '.SEQUENCE_TABLE.' SET `next`= ' - .'(SELECT MAX(ticket_id) FROM '.TICKET_TABLE.') ' + .'(SELECT MAX(ticket_id)+1 FROM '.TICKET_TABLE.') ' .'WHERE `id`=1'); } } -- GitLab