From d9beb14ef6719a17d46b859a1b000c1361782bdb Mon Sep 17 00:00:00 2001 From: JediKev <kevin@enhancesoft.com> Date: Fri, 13 Jul 2018 11:58:59 -0500 Subject: [PATCH] department: Error Feedback This addresses an issue where osTicket did not ensure associated items exist before saving to the database. This also addresses an issue where the Parent Topic error was not displayed on page. --- include/class.dept.php | 29 ++++++++++++++++++++++------- include/staff/department.inc.php | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/class.dept.php b/include/class.dept.php index 8f09237c4..2392dc205 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -620,6 +620,21 @@ implements TemplateVariable { if ($vars['pid'] && !($p = static::lookup($vars['pid']))) $errors['pid'] = __('Department selection is required'); + if ($vars['sla_id'] && !SLA::lookup($vars['sla_id'])) + $errors['sla_id'] = __('Invalid SLA'); + + if ($vars['manager_id'] && !Staff::lookup($vars['manager_id'])) + $errors['manager_id'] = __('Unknown Staff'); + + if ($vars['email_id'] && !Email::lookup($vars['email_id'])) + $errors['email_id'] = __('Unknown System Email'); + + if ($vars['tpl_id'] && !EmailTemplateGroup::lookup($vars['tpl_id'])) + $errors['tpl_id'] = __('Unknown Template Set'); + + if ($vars['autoresp_email_id'] && !Email::lookup($vars['autoresp_email_id'])) + $errors['autoresp_email_id'] = __('Unkown System Email'); + // Format access update as [array(dept_id, role_id, alerts?)] $access = array(); if (isset($vars['members'])) { @@ -634,17 +649,17 @@ implements TemplateVariable { return false; $this->pid = $vars['pid'] ?: null; - $this->ispublic = isset($vars['ispublic'])?$vars['ispublic']:0; - $this->email_id = isset($vars['email_id'])?$vars['email_id']:0; - $this->tpl_id = isset($vars['tpl_id'])?$vars['tpl_id']:0; - $this->sla_id = isset($vars['sla_id'])?$vars['sla_id']:0; - $this->autoresp_email_id = isset($vars['autoresp_email_id'])?$vars['autoresp_email_id']:0; + $this->ispublic = isset($vars['ispublic']) ? (int) $vars['ispublic'] : 0; + $this->email_id = isset($vars['email_id']) ? (int) $vars['email_id'] : 0; + $this->tpl_id = isset($vars['tpl_id']) ? (int) $vars['tpl_id'] : 0; + $this->sla_id = isset($vars['sla_id']) ? (int) $vars['sla_id'] : 0; + $this->autoresp_email_id = isset($vars['autoresp_email_id']) ? (int) $vars['autoresp_email_id'] : 0; $this->manager_id = $vars['manager_id'] ?: 0; $this->name = Format::striptags($vars['name']); $this->signature = Format::sanitize($vars['signature']); $this->group_membership = $vars['group_membership']; - $this->ticket_auto_response = isset($vars['ticket_auto_response'])?$vars['ticket_auto_response']:1; - $this->message_auto_response = isset($vars['message_auto_response'])?$vars['message_auto_response']:1; + $this->ticket_auto_response = isset($vars['ticket_auto_response']) ? (int) $vars['ticket_auto_response'] : 1; + $this->message_auto_response = isset($vars['message_auto_response']) ? (int) $vars['message_auto_response'] : 1; $this->flags = 0; $this->setFlag(self::FLAG_ASSIGN_MEMBERS_ONLY, isset($vars['assign_members_only'])); $this->setFlag(self::FLAG_DISABLE_AUTO_CLAIM, isset($vars['disable_auto_claim'])); diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index 2ea8825e3..85b077388 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -67,6 +67,7 @@ $info = Format::htmlchars(($errors && $_POST) ? $_POST : $info); ?>><?php echo $name; ?></option> <?php } ?> </select> + <span class="error"><?php echo $errors['pid']; ?></span> </td> </tr> <tr> -- GitLab