some client cleanups

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

following Jason Felice's latest submissions that move the client configuration
over to Turba, this patch applies the new getClients() method in the Turba API
in a few more places in Whups. It also modifies the documentation to reflect
the fact that Turba is now a pre-requisite for Whups.

thanks,

bo.


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
fix_clients_to_turba.diff (text/diff, 20.3 KB)
Index: whups/admin.php
===================================================================
RCS file: /repository/whups/admin.php,v
retrieving revision 1.45
diff -u -r1.45 admin.php
--- whups/admin.php	18 Jul 2003 16:34:30 -0000	1.45
+++ whups/admin.php	8 Aug 2003 09:33:09 -0000
@@ -293,36 +293,29 @@
                                         $vars->getVar('subjectlist'), $vars->getVar('subjects'),
                                         $vars->getVar('versioned'));
          if (!is_a($result, 'PEAR_Error')) {
-             if (isset($conf['client']['driver'])) {
-                 /* Update client links. */
-                 switch ($conf['client']['driver']) {
-                 case 'turba':
-                     $clients = $vars->getVar('clients');
-                     $clientsource = $conf['client']['params']['addressbook'];
-                     require_once HORDE_BASE . '/lib/Links.php';
-                     $links = &Horde_Links::singleton($registry->getApp());
-                     $from_application = 'projects'; 
-                     $from_parameters  = array('module_id' => $vars->getVar('module'));
-                     $to_application = 'contacts';
-                     $link_type = 'client';
-                     /* Delete all current client links for this module. */
-                     $delete_status = $links->deleteLink($from_application, $from_parameters, $to_application, '*', $link_type);
+             /* Update client links. */
+             $clients = $vars->getVar('clients');
+             $clientsource = $GLOBALS['registry']->call('clients/getClientSource');
+             require_once HORDE_BASE . '/lib/Links.php';
+             $links = &Horde_Links::singleton($registry->getApp());
+             $from_application = 'projects'; 
+             $from_parameters  = array('module_id' => $vars->getVar('module'));
+             $to_application = 'contacts';
+             $link_type = 'client';
+             /* Delete all current client links for this module. */
+             $delete_status = $links->deleteLink($from_application, $from_parameters, $to_application, '*', $link_type);
 
-                     /* Now add in all the new client links. */
-                     foreach ($clients as $client) {
-                         $to_parameters = array('source' => $clientsource, 'id' => $client); 
-                         $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
-                         if (is_a($status, 'PEAR_Error')) {
-                             $notification->push($status, 'horde.error');
-                         } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
-                             $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
-                             $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
-                         } else {
-                             $notification->push(_("Link added."), 'horde.success');
-                         }
-                     }
-                     break;
-                     /* Any future client sources can be added here. */
+             /* Now add in all the new client links. */
+             foreach ($clients as $client) {
+                 $to_parameters = array('source' => $clientsource, 'id' => $client); 
+                 $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+                 if (is_a($status, 'PEAR_Error')) {
+                     $notification->push($status, 'horde.error');
+                 } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
+                     $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
+                     $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
+                 } else {
+                     $notification->push(_("Link added."), 'horde.success');
                  }
              }
 
Index: whups/create.php
===================================================================
RCS file: /repository/whups/create.php,v
retrieving revision 1.36
diff -u -r1.36 create.php
--- whups/create.php	4 Aug 2003 12:40:13 -0000	1.36
+++ whups/create.php	8 Aug 2003 09:33:09 -0000
@@ -151,41 +151,35 @@
     $message = sprintf(_("Your ticket id is %s. "), $tid);
     $message .= _("An appropriate person has been notified of this request.");
     $notification->push($message, 'horde.success');
-    if (isset($conf['client']['driver'])) {
-        /* Add a link from this ticket to the selected client. */
-        switch ($conf['client']['driver']) {
-        case 'turba':
-            if (!empty($info['client'])) {
-                $clientsource = $conf['client']['params']['addressbook'];
-                require_once HORDE_BASE . '/lib/Links.php';
-                $links = &Horde_Links::singleton($registry->getApp());
 
-                // $tid needs to be a string // to match properly.
-                $from_parameters = array('ticket_id' => (string)$tid);
-                $from_application = 'projects';
-                $to_application = 'contacts';
-                $link_type = 'client';
+    /* Add a link from this ticket to the selected client. */
+    if (!empty($info['client'])) {
+        $clientsource = $GLOBALS['registry']->call('clients/getClientSource');
+        require_once HORDE_BASE . '/lib/Links.php';
+        $links = &Horde_Links::singleton($registry->getApp());
 
-                /* Now add in the new client link(s). */
-                $clients = $info['client'];
-                if (!is_array($clients)) {
-                    $clients = array($clients);
-                }
-                foreach ($clients as $client_id) {
-                    $to_parameters = array('source' => $clientsource, 'id' => (string)$client_id);
-                    $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
-                    if (is_a($status, 'PEAR_Error')) {
-                        $notification->push($status, 'horde.error');
-                    } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
-                        $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
-                        $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
-                    } else {
-                        $notification->push(_("Link added."), 'horde.success');
-                    }
-                }
+        // $tid needs to be a string to match properly.
+        $from_parameters = array('ticket_id' => (string)$tid);
+        $from_application = 'projects';
+        $to_application = 'contacts';
+        $link_type = 'client';
+
+        /* Now add in the new client link(s). */
+        $clients = $info['client'];
+        if (!is_array($clients)) {
+            $clients = array($clients);
+        }
+        foreach ($clients as $client_id) {
+            $to_parameters = array('source' => $clientsource, 'id' => (string)$client_id);
+            $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+            if (is_a($status, 'PEAR_Error')) {
+                $notification->push($status, 'horde.error');
+            } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
+                $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
+                $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
+            } else {
+                $notification->push(_("Link added."), 'horde.success');
             }
-            break;
-            /* Any future client sources can be added here. */
         }
     }
 
Index: whups/details.php
===================================================================
RCS file: /repository/whups/details.php,v
retrieving revision 1.51
diff -u -r1.51 details.php
--- whups/details.php	1 Aug 2003 19:56:45 -0000	1.51
+++ whups/details.php	8 Aug 2003 09:33:09 -0000
@@ -347,9 +347,7 @@
     $form->addAttributes($attributes);
     $details['user_id_requester'] = Whups::formatUser($details['user_id_requester']);
     $details['user_id_owner'] = Whups::getOwners($ticket);
-    if (isset($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
-        $details['client_name'] = Whups::getClients($details['module'], $ticket);
-    }
+    $details['client_name'] = Whups::getClients($details['module'], $ticket);
 
     $RENDERER->beginInactive(sprintf(_("Ticket %s Details"), $ticket));
     $RENDERER->renderFormInactive($form, new Horde_Form_Vars($details));
Index: whups/search.php
===================================================================
RCS file: /repository/whups/search.php,v
retrieving revision 1.47
diff -u -r1.47 search.php
--- whups/search.php	7 Aug 2003 14:28:03 -0000	1.47
+++ whups/search.php	8 Aug 2003 09:33:09 -0000
@@ -46,15 +46,13 @@
         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");
-                }
+            $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();
@@ -95,11 +93,7 @@
                                            array(urlencode(session_name()),
                                                  '__formToken_' . $form->getName(),
                                                  '_formvars'));
-            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);
-            }
+            $whups->saveSearch(sprintf(_("Module: %s, Client: %s, Ticket: %s, Category: %s, Type: %s"), $moduleName, $clientName, $idName, $catName, $typeName), $qUrl);
         }
 
         // Munge the search criteria into acceptability.
Index: whups/lib/Create.php
===================================================================
RCS file: /repository/whups/lib/Create.php,v
retrieving revision 1.38
diff -u -r1.38 Create.php
--- whups/lib/Create.php	4 Aug 2003 12:40:15 -0000	1.38
+++ whups/lib/Create.php	8 Aug 2003 09:33:10 -0000
@@ -59,17 +59,14 @@
             $typetype = 'enum';
             $type_params = array($types);
         }
-        if (isset($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
-            /* Only list clients if a client driver has been configured. */
-            if (count($clientlist) == 0) {
-                $clienttype = 'invalid';
-                $client_params = array(_("There are no clients associated with this module; until there are, you cannot create any tickets in this module."));
-            } else {
-                $clienttype = 'multienum';
-                $client_params = array($clientlist);
-            }
-            $this->addVariable(_("Client"), 'client', $clienttype, true, false, null, $client_params);
+        if (count($clientlist) == 0) {
+            $clienttype = 'invalid';
+            $client_params = array(_("There are no clients associated with this module; until there are, you cannot create any tickets in this module."));
+        } else {
+            $clienttype = 'multienum';
+            $client_params = array($clientlist);
         }
+        $this->addVariable(_("Client"), 'client', $clienttype, true, false, null, $client_params);
         $this->addVariable(_("Ticket Type"), 'type', $typetype, true, false, null, $type_params);
 
         if (!empty($info['versioned'])) {
Index: whups/lib/Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.55
diff -u -r1.55 Driver.php
--- whups/lib/Driver.php	7 Aug 2003 19:35:39 -0000	1.55
+++ whups/lib/Driver.php	8 Aug 2003 09:33:10 -0000
@@ -72,11 +72,10 @@
     function getClients($module = null, $ticket = null)
     {
         /* Get client data from the clients API provider. */
-        global $registry;
         $clients = array();
         $args = array('addresses' => array(''), 
                       'fields' => array('name'));
-        $results = $registry->call('clients/clientSearch', $args);
+        $results = $GLOBALS['registry']->call('clients/clientSearch', $args);
         $clientlist = $results[''];
         if (!empty($clientlist)) {
             foreach ($clientlist as $client) {
@@ -98,34 +97,13 @@
 
     function getClientDetails($clients)
     {
-        /* Gets client records from the client source.  Records must
+        /* Gets client records from the client API.  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 = '';
-        }
-
-        if (empty($clients)) {
-            return array();
-        }
-
-        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;
+        /* Get client data from the client provider. */
+        foreach ($clients as $client_id) {
+            $args = array('key' => $client_id);
+            $results[] = $GLOBALS['registry']->call('contacts/getClient', $args);
         }
 
         return $results;
Index: whups/lib/Search.php
===================================================================
RCS file: /repository/whups/lib/Search.php,v
retrieving revision 1.57
diff -u -r1.57 Search.php
--- whups/lib/Search.php	7 Aug 2003 14:28:04 -0000	1.57
+++ whups/lib/Search.php	8 Aug 2003 09:33:10 -0000
@@ -38,17 +38,15 @@
         $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);
+        $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: whups/lib/Whups.php
===================================================================
RCS file: /repository/whups/lib/Whups.php,v
retrieving revision 1.62
diff -u -r1.62 Whups.php
--- whups/lib/Whups.php	30 Jul 2003 03:15:13 -0000	1.62
+++ whups/lib/Whups.php	8 Aug 2003 09:33:10 -0000
@@ -384,7 +384,7 @@
         return implode(', ', $results);
     }
 
-    function getClients($module = null, $ticket = null)
+    function getClients($module = null, $ticket = null, $returnformat = 'list')
     {
         global $whups;
         $clients = $whups->getClients($module, $ticket);
@@ -392,7 +392,11 @@
             Horde::logMessage($clients, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $clients->getMessage();
         }
-        return implode(', ', $clients);
+        if ($returnformat == 'list') {
+            return implode(', ', $clients);
+        } else {
+            return $clients;
+        }
     }
 
 }
Index: whups/lib/Driver/sql.php
===================================================================
RCS file: /repository/whups/lib/Driver/sql.php,v
retrieving revision 1.122
diff -u -r1.122 sql.php
--- whups/lib/Driver/sql.php	8 Aug 2003 03:20:56 -0000	1.122
+++ whups/lib/Driver/sql.php	8 Aug 2003 09:33:10 -0000
@@ -784,12 +784,9 @@
                                     0);
         }
 
-        /* Add the client name for this ticket (if available). */
-        if (isset($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
-            $client_name = Whups::getClients($result[0]['module'], $result[0]['id']);
-            $result[0]['_client_name'] = !empty($client_name) ? $client_name : '';
-
-        }
+        /* Add the client name for this ticket. */
+        $client_name = Whups::getClients($result[0]['module'], $result[0]['id']);
+        $result[0]['_client_name'] = !empty($client_name) ? $client_name : '';
 
         return $result[0];
     }
Index: whups/docs/INSTALL
===================================================================
RCS file: /repository/whups/docs/INSTALL,v
retrieving revision 1.5
diff -u -r1.5 INSTALL
--- whups/docs/INSTALL	31 Jul 2003 17:41:44 -0000	1.5
+++ whups/docs/INSTALL	8 Aug 2003 09:33:10 -0000
@@ -48,6 +48,12 @@
      Whups store its data in an SQL database. Build PHP with whichever
      SQL driver you require; see the Horde INSTALL file for details.
 
+  3. A working Turba installation.
+
+     Whups uses Turba address books to store information about 
+     clients. You must configure Turba and specify one of your 
+     address books as your 'Client' address book.
+
 
 INSTALLING Whups
 ----------------
Index: turba/lib/api.php
===================================================================
RCS file: /repository/turba/lib/api.php,v
retrieving revision 1.59
diff -u -r1.59 api.php
--- turba/lib/api.php	7 Aug 2003 19:40:59 -0000	1.59
+++ turba/lib/api.php	8 Aug 2003 09:33:10 -0000
@@ -58,6 +58,15 @@
     'args' => array('addressbook', 'key'),
     'type' => 'array');
 
+$_services['getClient'] = array(
+    'args' => array('key'),
+    'type' => 'array');
+
+$_services['getClientSource'] = array(
+    'args' => array(),
+    'type' => 'string');
+
+
 $_services['block'] = array(
     'args' => array('type', 'params'),
     'type' => 'array');
@@ -489,6 +498,20 @@
     }
 
     return $result;
+}
+
+function _turba_getClient($key = '')
+{
+    global $conf;
+    $args = array('addressbook' => $conf['client']['addressbook'],
+                  'key' => $key);
+    return $GLOBALS['registry']->call('clients/getContact', $args);
+}
+
+function _turba_getClientSource()
+{
+    global $conf;
+    return $conf['client']['addressbook'];
 }
 
 function _turba_getFieldById($source, $id, $field)
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.