From 0e8d7b6587fcba7369f7b580c84019bc9f6a05df Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 29 Oct 2015 06:45:16 +0000 Subject: [PATCH] Ticket Source Consolidate and protect where ticket sources are defined Only show IP address when if the ticket source is web. Otherwise, phone ticket created by agents will have an IP of the agent showing. --- include/class.ticket.php | 26 +++++++++++++++++++------- include/staff/ticket-open.inc.php | 11 ++++++++--- include/staff/ticket-view.inc.php | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/class.ticket.php b/include/class.ticket.php index 3fe355de2..6854f6c64 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -139,6 +139,16 @@ class TicketModel extends VerySimpleModel { /* @trans */ 'Ability to delete tickets'), ); + // Ticket Sources + static protected $sources = array( + 'Phone' => + /* @trans */ 'Phone', + 'Email' => + /* @trans */ 'Email', + 'Other' => + /* @trans */ 'Other', + ); + function getId() { return $this->ticket_id; } @@ -199,6 +209,10 @@ EOF; static function getPermissions() { return self::$perms; } + + static function getSources() { + return self::$sources; + } } RolePermission::register(/* @trans */ 'Tickets', TicketModel::getPermissions(), true); @@ -3392,13 +3406,11 @@ implements RestrictedAccess, Threadable { return false; } - if ($vars['source'] && !in_array( - strtolower($vars['source']), array('email','phone','other')) - ) { - $errors['source'] = sprintf( - __('Invalid source given - %s'),Format::htmlchars($vars['source']) - ); - } + if (isset($vars['source']) // Check ticket source if provided + && !array_key_exists($vars['source'], Ticket::getSources())) + $errors['source'] = sprintf( __('Invalid source given - %s'), + Format::htmlchars($vars['source'])); + if (!$vars['uid']) { // Special validation required here diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 3173d7e92..b8330a0f5 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -129,9 +129,14 @@ if ($_POST) </td> <td> <select name="source"> - <option value="Phone" selected="selected"><?php echo __('Phone'); ?></option> - <option value="Email" <?php echo ($info['source']=='Email')?'selected="selected"':''; ?>><?php echo __('Email'); ?></option> - <option value="Other" <?php echo ($info['source']=='Other')?'selected="selected"':''; ?>><?php echo __('Other'); ?></option> + <?php + $source = $info['source'] ?: 'Phone'; + foreach (Ticket::getSources() as $k => $v) + echo sprintf('<option value="%s" %s>%s</option>', + $k, + ($source == $k ) ? 'selected="selected"' : '', + $v); + ?> </select> <font class="error"><b>*</b> <?php echo $errors['source']; ?></font> </td> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 156b2c323..9cddf094e 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -328,7 +328,7 @@ if($ticket->isOverdue()) <td><?php echo Format::htmlchars($ticket->getSource()); - if($ticket->getIP()) + if (!strcasecmp($ticket->getSource(), 'Web') && $ticket->getIP()) echo ' <span class="faded">('.$ticket->getIP().')</span>'; ?> </td> -- GitLab