more types stuff

Bo Daley <[email protected]>
Newsgroups gmane.comp.horde.whups
Message-ID <[email protected]>
hi again,

here's another addition that we're finding useful over here -- the ability to
change the type of a ticket after its been entered into the system. This could
be useful (eg) when  someone has entered the ticket incorrectly to begin with,
or
when a ticket passes from one area to another -- all depends how you've set up
your types.

Hopefully all the files are attached properly this time..

thanks!

bo.


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
details.php.diff (text/diff, 1.8 KB)
Index: details.php
===================================================================
RCS file: /repository/whups/details.php,v
retrieving revision 1.47
diff -u -r1.47 details.php
--- details.php	19 Jun 2003 18:09:38 -0000	1.47
+++ details.php	24 Jun 2003 07:19:21 -0000
@@ -37,6 +37,7 @@
     $ACTIONS->addAction(_("Assign Ticket"), 'details.php', 'at');
     $ACTIONS->addAction(_("Set State"), 'details.php', 'ss');
     $ACTIONS->addAction(_("Set Priority"), 'details.php', 'sp');
+    $ACTIONS->addAction(_("Set Type"), 'details.php', 'st');
 } else {
     $ACTIONS->addAction(_("Set Priority"), 'details.php', 'gp');
 }
@@ -179,6 +180,26 @@
     }
 }
 
+//////// Set Type action
+if ($form == 'settypeform') {
+    $settypeform = &Horde_Form::singleton('SetTypeForm', $vars);
+    $settypeform->validate($vars);
+
+    if ($settypeform->isValid()) {
+        $settypeform->getInfo($vars, $info);
+        $comment_id = $whups->setTicketType($info);
+        if (array_key_exists('group', $info)) {
+            Whups::addCommentPerms($comment_id, $info['group']);
+        }
+
+        $details = $whups->getTicketDetails($ticket);
+        $notification->push(_("Set Ticket Type"), 'horde.success');
+        $action = '';
+    } else {
+        $action = 'st';
+    }
+}
+
 //////// Edit Attributes action
 if ($form == 'editattributesform') {
     $editattributesform = &Horde_Form::singleton('EditAttributesForm', $vars, $attributes);
@@ -255,6 +276,7 @@
  case 'ac': $form = &Horde_Form::singleton('AddCommentForm', $vars); break;
  case 'ss': $form = &Horde_Form::singleton('SetStateForm', $vars); break;
  case 'sp': $form = &Horde_Form::singleton('SetPriorityForm', $vars); break;
+ case 'st': $form = &Horde_Form::singleton('SetTypeForm', $vars); break;
  case 'gp': $form = &Horde_Form::singleton('GuestPriorityForm', $vars); break;
 }
conf.php.dist.diff (text/diff, 575 B)
Index: conf.php.dist
===================================================================
RCS file: /repository/whups/config/conf.php.dist,v
retrieving revision 1.17
diff -u -r1.17 conf.php.dist
--- conf.php.dist	27 Apr 2003 00:28:17 -0000	1.17
+++ conf.php.dist	24 Jun 2003 07:20:00 -0000
@@ -79,6 +79,10 @@
 // $conf['mail']['onpriority'] = array('owner', 'requester');
 $conf['mail']['onpriority'] = array();
 
+// Should we send mail on ticket type change? Set to 'all',
+// 'owner', 'requester', or 'none'.
+$conf['mail']['ontype'] = array();
+
 
 /**
  ** Menu settings
html.php.dist.diff (text/diff, 685 B)
Index: html.php.dist
===================================================================
RCS file: /repository/whups/config/html.php.dist,v
retrieving revision 1.10
diff -u -r1.10 html.php.dist
--- html.php.dist	19 Jun 2003 18:06:34 -0000	1.10
+++ html.php.dist	24 Jun 2003 07:19:44 -0000
@@ -25,6 +25,10 @@
 $css['.priority-change']['color'] = 'white';
 $css['.priority-change']['font-weight'] = 'bold';
 
+$css['.type-change']['background-color'] = '#7777cc';
+$css['.type-change']['color'] = 'white';
+$css['.type-change']['font-weight'] = 'bold';
+
 $css['.comment']['background-color'] = '#000099';
 $css['.comment']['color'] = 'white';
 $css['.comment']['font-weight'] = 'bold';
Driver.php.diff (text/diff, 1.4 KB)
Index: Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.44
diff -u -r1.44 Driver.php
--- Driver.php	19 Jun 2003 04:02:53 -0000	1.44
+++ Driver.php	24 Jun 2003 07:20:33 -0000
@@ -155,6 +155,24 @@
         $this->_sendMails($GLOBALS['conf']['mail']['onpriority'], $ticket_id, $subject, $message, Auth::getAuth());
     }
 
+    function notifyTypeChange($info, $type)
+    {
+        $ticket_id = $info['id'];
+        $type_name = $this->getTypeName($type);
+
+        $subject = sprintf(_("Ticket %s has changed type"), $ticket_id);
+
+        $message  = sprintf(_("-Ticket %s"), $ticket_id) . "\n";
+        $message .= sprintf(_("-Module: %s"), $info['_module_name']) . "\n";
+        $message .= sprintf(_("-New Type: %s"), $type_name) . "\n";
+        $message .= "\n" . _("-Summary:") . "\n" . $this->_splitMessage($info['summary']) . "\n";
+        $message .= '@@comment_placeholder@@';
+        $message .= "\n\n" . $this->_getTicketUrl($ticket_id) . "\n\n";
+
+        $this->_disclaimer($message);
+        $this->_sendMails($GLOBALS['conf']['mail']['ontype'], $ticket_id, $subject, $message, Auth::getAuth());
+    }
+
     function _disclaimer(&$message)
     {
         $message1 = sprintf(_("This mail was automatically generated by %s"), $GLOBALS['registry']->getParam('name'));
Search.php.diff (text/diff, 1.5 KB)
Index: Search.php
===================================================================
RCS file: /repository/whups/lib/Search.php,v
retrieving revision 1.51
diff -u -r1.51 Search.php
--- Search.php	20 Jun 2003 20:13:42 -0000	1.51
+++ Search.php	24 Jun 2003 07:20:56 -0000
@@ -337,6 +337,45 @@
 
 }
 
+class SetTypeForm extends Horde_Form {
+
+    function SetTypeForm(&$vars)
+    {
+        global $whups;
+
+        parent::Horde_Form($vars);
+
+        $this->addHidden('', 'id', 'int', true, true);
+
+        /* Types */
+        $module = $vars->getVar('module');
+        $this->addVariable(_("New Type"), 'type', 'enum', true, false, null, array($whups->getTypes($module)));
+
+        $this->addVariable(_("Comment"), 'newcomment', 'longtext', false);
+
+        /* Groups */
+        $groups = &Group::singleton();
+        $mygroups = $groups->getGroupMemberships(Auth::getAuth());
+        if (count($mygroups)) {
+            $grouplist = array(0 => _("Any Group"));
+            foreach ($mygroups as $group) {
+                $grouplist[$group] = $group;
+            }
+            $this->addVariable(_("Viewable only by members of"), 'group', 'enum', true, false, null, array($grouplist));
+        }
+    }
+
+    function validate(&$vars)
+    {
+        if (!Auth::getAuth()) {
+            $this->setError('_auth', _("Permission Denied."));
+        }
+
+        return parent::validate($vars);
+    }
+
+}
+
 class EditAttributesForm extends Horde_Form {
 
     function EditAttributesForm(&$vars, $attributes)
sql.php.diff (text/diff, 6.7 KB)
Index: sql.php
===================================================================
RCS file: /repository/whups/lib/Driver/sql.php,v
retrieving revision 1.107
diff -u -r1.107 sql.php
--- sql.php	24 Jun 2003 02:57:07 -0000	1.107
+++ sql.php	24 Jun 2003 07:21:12 -0000
@@ -223,7 +223,7 @@
             return $result;
         }
 
-        $result = $this->_updateLog($new_id, $state, $priority, $requester, $new_comment_id);
+        $result = $this->_updateLog($new_id, $state, $priority, $type, $requester, $new_comment_id);
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $result;
@@ -305,7 +305,7 @@
         Horde::logMessage('SQL Query by Whups_Driver_sql::assignTicket(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
         $result = $this->_query($query);
         $new_comment_id = $this->_addComment($ticket_id, $comment, Auth::getAuth());
-        $this->_updateLog($ticket_id, $state, $ticket_details['priority'], Auth::getAuth(), $new_comment_id);
+        $this->_updateLog($ticket_id, $state, $ticket_details['priority'], '', Auth::getAuth(), $new_comment_id);
 
         $this->notifyAssignment($ticket_details, $owners, $state);
 
@@ -355,7 +355,7 @@
         Horde::logMessage('SQL Query by Whups_Driver_sql::setTicketState(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
         $this->_query($query);
         $new_comment_id = $this->_addComment($ticket_id, $newcomment, Auth::getAuth());
-        $this->_updateLog($ticket_id, $tostate, '', Auth::getAuth(), $new_comment_id);
+        $this->_updateLog($ticket_id, $tostate, '', '', Auth::getAuth(), $new_comment_id);
 
         $this->notifyStateChange($this->getTicketDetails($ticket_id),
                                  $type, $tostate);
@@ -374,7 +374,7 @@
         Horde::logMessage('SQL Query by Whups_Driver_sql::setTicketPriority(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
         $this->_query($query);
         $new_comment_id = $this->_addComment($ticket_id, $newcomment, Auth::getAuth());
-        $this->_updateLog($ticket_id, '', $priority, Auth::getAuth(), $new_comment_id);
+        $this->_updateLog($ticket_id, '', $priority, '', Auth::getAuth(), $new_comment_id);
 
         $this->notifyPriorityChange($this->getTicketDetails($ticket_id),
                                     $type, $priority);
@@ -382,6 +382,23 @@
         return $new_comment_id;
     }
 
+    function setTicketType(&$info)
+    {
+        $ticket_id = $info['id'];
+        $newcomment = $info['newcomment'];
+        $type = $info['type'];
+
+        $query = "UPDATE whups_tickets SET type_id = $type WHERE ticket_id = $ticket_id";
+        Horde::logMessage('SQL Query by Whups_Driver_sql::setTicketType(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        $this->_query($query);
+        $new_comment_id = $this->_addComment($ticket_id, $newcomment, Auth::getAuth());
+        $this->_updateLog($ticket_id, '', '', $type, Auth::getAuth(), $new_comment_id);
+
+        $this->notifyTypeChange($this->getTicketDetails($ticket_id), $type);
+
+        return $new_comment_id;
+    }
+
     function &executeQuery(&$query, &$vars, $get_details = true, $munge = true)
     {
         $this->tables  = array('whups_tickets' => 1);
@@ -733,15 +750,16 @@
         $where = "whups_comments.ticket_id = $ticket";
         $join  = 'LEFT JOIN whups_logs ON whups_comments.comment_id = whups_logs.comment_id_log ';
         $join .= 'LEFT JOIN whups_states ON whups_logs.state_id_to = whups_states.state_id ';
-        $join .= 'LEFT JOIN whups_priorities ON whups_logs.priority_id_to = whups_priorities.priority_id';
+        $join .= 'LEFT JOIN whups_priorities ON whups_logs.priority_id_to = whups_priorities.priority_id ';
+        $join .= 'LEFT JOIN whups_types ON whups_logs.type_id_to = whups_types.type_id';
 
         $tables = 'whups_comments';
 
         $fields = array('comment_id', 'ticket_id', 'user_id_creator', 'comment_text');
         $fields = $this->_prefixTableToColumns('whups_comments', $fields);
         $fields .= ', whups_comments.comment_timestamp AS timestamp';
-        $fields .= ', whups_logs.priority_id_to, whups_logs.state_id_to';
-        $fields .= ', whups_priorities.priority_name, whups_states.state_name';
+        $fields .= ', whups_logs.priority_id_to, whups_logs.state_id_to, whups_logs.type_id_to';
+        $fields .= ', whups_priorities.priority_name, whups_states.state_name, whups_types.type_name';
 
         $desc = $reverse ? ' DESC' : '';
 
@@ -1100,6 +1118,13 @@
         return $this->_getAll($query);
     }
 
+    function getTypeName($type)
+    {
+        $query = "SELECT type_name FROM whups_types WHERE type_id = $type";
+        Horde::logMessage('SQL Query by Whups_Driver_sql::getTypeName(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        return $this->_getOne($query);
+    }
+
     function updateType($typeID, $name, $description)
     {
         $query = 'UPDATE whups_types SET' .
@@ -1595,7 +1620,7 @@
 
             // FIXME: The log needs to know that this was an attribute
             // change.
-            $this->_updateLog($ticket_id, '', '', Auth::getAuth(), $new_comment_id);
+            $this->_updateLog($ticket_id, '', '', '', Auth::getAuth(), $new_comment_id);
         }
 
         return isset($new_comment_id) ? $new_comment_id : true;
@@ -1797,7 +1822,7 @@
         return $clause;
     }
 
-    function _updateLog($ticket, $tostate, $topriority, $user, $comment_id)
+    function _updateLog($ticket, $tostate, $topriority, $totype, $user, $comment_id)
     {
         if (empty($tostate)) {
             $query = "SELECT state_id FROM whups_tickets WHERE ticket_id = $ticket";
@@ -1809,9 +1834,14 @@
             Horde::logMessage('SQL Query by Whups_Driver_sql::_updateLog(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
             $topriority = $this->_getOne($query);
         }
+        if (empty($totype)) {
+            $query = "SELECT type_id FROM whups_tickets WHERE ticket_id = $ticket";
+            Horde::logMessage('SQL Query by Whups_Driver_sql::_updateLog(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+            $totype = $this->_getOne($query);
+        }
 
-        $query = "INSERT INTO whups_logs (ticket_id, state_id_to, priority_id_to, log_timestamp, user_id, comment_id_log) " .
-                 "VALUES ($ticket, $tostate, $topriority, " . time() . ", '$user', $comment_id)";
+        $query = "INSERT INTO whups_logs (ticket_id, state_id_to, priority_id_to, type_id_to, log_timestamp, user_id, comment_id_log) " .
+                 "VALUES ($ticket, $tostate, $topriority, $totype, " . time() . ", '$user', $comment_id)";
         Horde::logMessage('SQL Query by Whups_Driver_sql::_updateLog(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
         return $this->_query($query);
     }
comment.inc.diff (text/diff, 1.6 KB)
Index: comment.inc
===================================================================
RCS file: /repository/whups/templates/comment.inc,v
retrieving revision 1.20
diff -u -r1.20 comment.inc
--- comment.inc	19 Jun 2003 18:06:33 -0000	1.20
+++ comment.inc	24 Jun 2003 07:22:00 -0000
@@ -14,6 +14,7 @@
 
     var $state = -1;
     var $priority = -1;
+    var $type = -1;
 
     function Comment()
     {
@@ -36,6 +37,7 @@
 
         $newstate = $vars->getVar('state_name');
         $newpriority = $vars->getVar('priority_name');
+        $newtype = $vars->getVar('type_name');
 
         $user = $vars->getVar('user_id_creator');
         $author = Whups::formatUser($user);
@@ -61,6 +63,16 @@
             $prioritylabel = '';
         }
 
+        if ($this->type === -1) {
+            $typelabel = sprintf(_("Initial type of '%s' set by %s on %s."), $newtype, $user, $time);
+            $this->type = $newtype;
+        } elseif ($newtype && $newtype != $this->type) {
+            $typelabel = sprintf(_("Type changed to '%s' by %s on %s."), $newtype, $user, $time);
+            $this->type = $newtype;
+        } else {
+            $typelabel = '';
+        }
+
         $body = $vars->getVar('comment_text');
         $body = Text::linkUrls($body, true);
         $body = Text::htmlSpaces($body);
@@ -80,6 +92,9 @@
 <?php endif; ?>
 <?php if ($prioritylabel): ?>
   <tr><td class="priority-change"><?php echo $prioritylabel ?></td></tr>
+<?php endif; ?>
+<?php if ($typelabel): ?>
+  <tr><td class="type-change"><?php echo $typelabel ?></td></tr>
 <?php endif; ?>
 <?php if ($body): ?>
  <tr>
whups.sql.diff (text/diff, 574 B)
Index: whups.sql
===================================================================
RCS file: /repository/whups/scripts/drivers/whups.sql,v
retrieving revision 1.24
diff -u -r1.24 whups.sql
--- whups.sql	19 Jun 2003 04:02:58 -0000	1.24
+++ whups.sql	24 Jun 2003 07:26:16 -0000
@@ -130,6 +130,7 @@
     ticket_id          INT NOT NULL,
     state_id_to        INT NOT NULL,
     priority_id_to     INT NOT NULL,
+    type_id_to         INT NOT NULL, 
     log_timestamp      INT NOT NULL,
     user_id            VARCHAR(255) NOT NULL,
     comment_id_log     INT NOT NULL,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.