search tickets by client
Bo Daley <[email protected]>
| Newsgroups | gmane.comp.horde.whups |
|---|---|
| Message-ID | <[email protected]> |
hi all, this adds the ability to search for tickets in Whups by client. hopefully it makes sense this way! thanks, bo. -- Whups mailing list Frequently Asked Questions: http://horde.org/faq/ To unsubscribe, mail: [email protected]
search_clients.diff
(text/diff, 9.5 KB)
Index: whups/search.php
===================================================================
RCS file: /repository/whups/search.php,v
retrieving revision 1.46
diff -u -r1.46 search.php
--- whups/search.php 7 Jul 2003 14:32:25 -0000 1.46
+++ whups/search.php 7 Aug 2003 03:02:22 -0000
@@ -46,6 +46,16 @@
if (Auth::getAuth()) {
$moduleInfo = $whups->getModule($info['module']);
$moduleName = !empty($moduleInfo['name']) ? $moduleInfo['name'] : _("Any");
+ if (!empty($conf['client']['driver']) && $conf['client']['driver'] != 'none') {
+ $clientInfo = $whups->getClientDetails($info['client']);
+ $clientName = '';
+ foreach ($clientInfo as $client) {
+ $clientName .= !empty($clientName) ? ', ' . $client['name'] : $client['name'];
+ }
+ if (empty($clientName)) {
+ $clientName = _("Any");
+ }
+ }
$idName = $vars->getVar('id') ? $vars->getVar('id') : _("Any");
$categories = $whups->getCategories();
$cat = $vars->getVar('category');
@@ -85,7 +95,11 @@
array(urlencode(session_name()),
'__formToken_' . $form->getName(),
'_formvars'));
- $whups->saveSearch(sprintf(_("Module: %s, Ticket: %s, Category: %s, Type: %s"), $moduleName, $idName, $catName, $typeName), $qUrl);
+ if (!empty($clientName)) {
+ $whups->saveSearch(sprintf(_("Module: %s, Client: %s, Ticket: %s, Category: %s, Type: %s"), $moduleName, $clientName, $idName, $catName, $typeName), $qUrl);
+ } else {
+ $whups->saveSearch(sprintf(_("Module: %s, Ticket: %s, Category: %s, Type: %s"), $moduleName, $idName, $catName, $typeName), $qUrl);
+ }
}
// Munge the search criteria into acceptability.
@@ -103,6 +117,9 @@
}
$tickets = $whups->getTicketsByProperties($info);
+ if (!empty($info['client'])) {
+ $tickets = $whups->filterTicketsByClient($tickets, $info['client']);
+ }
if (is_a($tickets, 'PEAR_Error')) {
$notification->push(sprintf(_("There was an error performing your search: %s"), $tickets->getMessage()), 'horde.error');
} else {
Index: whups/lib/Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.53
diff -u -r1.53 Driver.php
--- whups/lib/Driver.php 30 Jul 2003 03:15:13 -0000 1.53
+++ whups/lib/Driver.php 7 Aug 2003 03:02:22 -0000
@@ -88,8 +88,8 @@
$addressbook = $conf['client']['params']['addressbook'];
global $registry;
$clients = array();
- $args = array('addresses' => array(''),
- 'addressbooks' => array($addressbook),
+ $args = array('addresses' => array(''),
+ 'addressbooks' => array($addressbook),
'fields' => array('name')
);
$results = $registry->call('contacts/search', $args);
@@ -117,6 +117,40 @@
return $clients;
}
+ function getClientDetails($clients)
+ {
+ /* Gets client records from the client source.
+ * Records must minimally have a 'key' and a 'name' attribute
+ */
+
+ $results = array();
+ global $conf;
+
+ if (!empty($conf['client']['driver'])) {
+ $clientsource = $conf['client']['driver'];
+ } else {
+ $clientsource = '';
+ }
+
+ switch ($clientsource) {
+ case 'turba':
+ /* Get client data from a Turba addressbook. */
+ foreach ($clients as $client_id) {
+ if (!empty($conf['client']['params']['addressbook'])) {
+ $addressbook = $conf['client']['params']['addressbook'];
+ global $registry;
+ $args = array('addressbook' => $addressbook,
+ 'key' => $client_id);
+ $results[] = $registry->call('contacts/getContact', $args);
+ }
+ }
+ break;
+ }
+
+ return $results;
+
+ }
+
function filterClientLinks($type, $clients, $value)
{
/**
@@ -148,6 +182,54 @@
}
}
return $clients_filtered;
+ }
+
+ function filterTicketsByClient($tickets, $clients)
+ {
+ /**
+ * Take a list of tickets and return only those associated
+ * with the specified client IDs.
+ */
+ global $registry;
+ $tickets_filtered = array();
+ if (!is_array($clients)) {
+ $clients = array($clients);
+ }
+ require_once HORDE_BASE . '/lib/Links.php';
+ $links = &Horde_Links::singleton($registry->getApp());
+ $from_application = 'projects';
+ $to_application = 'contacts';
+ $link_type = 'projects/client';
+ for ($i=0; $i<count($tickets); $i++) {
+ $ticket_id = $tickets[$i]['id'];
+ $from_parameters = array('ticket_id' => $ticket_id);
+ $client_links = $links->listLinks($link_type, $from_parameters);
+ foreach ($client_links as $l) {
+ foreach ($clients as $client_id) {
+ if ($client_id == $l['to_parameters']['id']) {
+ $tickets_filtered[] = $tickets[$i];
+ }
+ }
+ }
+ }
+ return $tickets_filtered;
+ }
+
+ function filterTicketsByState($tickets, $state_category=array())
+ {
+ /**
+ * Take a list of tickets and return only those of the
+ * specified state_category.
+ */
+ $tickets_filtered = array();
+ foreach ($tickets as $ticket) {
+ foreach ($state_category as $state) {
+ if ($ticket['_state_category'] == $state) {
+ $tickets_filtered[] = $ticket;
+ }
+ }
+ }
+ return $tickets_filtered;
}
function notifyTicket($ticket_id, $summary, $module_name, $creator, $client_name=null)
Index: whups/lib/Search.php
===================================================================
RCS file: /repository/whups/lib/Search.php,v
retrieving revision 1.56
diff -u -r1.56 Search.php
--- whups/lib/Search.php 4 Aug 2003 02:24:48 -0000 1.56
+++ whups/lib/Search.php 7 Aug 2003 03:02:22 -0000
@@ -19,7 +19,7 @@
function SearchForm(&$vars)
{
- global $whups;
+ global $whups, $conf;
parent::Horde_Form($vars);
@@ -37,6 +37,18 @@
$this->addVariable(_("Ticket ID"), 'id', 'intlist', false);
$this->addVariable(_("Module Name"), 'module', $modtype, false, false, null, $type_params);
+
+ if (!empty($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
+ $clients = Whups::getClients('', '', 'array');
+ if (count($clients)) {
+ $clienttype = 'multienum';
+ $type_params = array($clients);
+ } else {
+ $clienttype = 'invalid';
+ $type_params = array(_("There are no clients which you can search."));
+ }
+ $this->addVariable(_("Client"), 'client', $clienttype, false, false, null, $type_params);
+ }
$cats = &$this->addVariable(_("Tickets which are"), 'category', 'multienum', false, false, _("If you don't select any categories, no filtering will be done on ticket category."), array($whups->getCategories(), 4));
$cats->setDefault(array('unconfirmed', 'new', 'assigned'));
Index: turba/lib/api.php
===================================================================
RCS file: /repository/turba/lib/api.php,v
retrieving revision 1.56
diff -u -r1.56 api.php
--- turba/lib/api.php 6 Aug 2003 18:55:04 -0000 1.56
+++ turba/lib/api.php 7 Aug 2003 03:02:22 -0000
@@ -50,6 +50,10 @@
'args' => array('field', 'addressbooks'),
'type' => 'array');
+$_services['getContact'] = array(
+ 'args' => array('addressbook', 'key'),
+ 'type' => 'array');
+
$_services['block'] = array(
'args' => array('type', 'params'),
'type' => 'array');
@@ -432,6 +436,32 @@
return PEAR::raiseError(_("More than 1 entry returned."), 'horde.warning', null, null, $source);
} elseif (!isset($result)) {
return PEAR::raiseError(sprintf(_("No %s entry found for %s."), $field, $address), 'horde.warning', null, null, $source);
+ }
+
+ return $result;
+}
+
+function _turba_getContact($addressbook = '', $key = '')
+{
+ require_once dirname(__FILE__) . '/base.php';
+ require_once TURBA_BASE . '/lib/Source.php';
+ require TURBA_BASE . '/config/attributes.php';
+ global $cfgSources;
+ $result = array();
+
+ if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) {
+ return array();
+ }
+
+ if (isset($cfgSources[$addressbook])) {
+ $driver = &Turba_Source::singleton($addressbook, $cfgSources[$addressbook]);
+ if (!is_a($driver, 'PEAR_Error')) {
+ $object = $driver->getObject($key);
+ /* Check permissions on this object. */
+ if (Turba::checkPermissions($object, 'object', _PERMS_READ)) {
+ $result = $object->attributes;
+ }
+ }
}
return $result;