[turba] Turba Patch - allowing LDAP addresses to be added to SQL addressbooks

jonathan soong jon.soong at imvs.sa.gov.au
Mon Aug 18 21:58:07 PDT 2003


Hi Rob,

i've got a fix for this, so that if users had created lists in Turba 1.2 
, they will now be able to still use them. (ie backwards compatibility)

(these patches are against the ORIGINAL /lib/Turba.php and browse.php 
files from the 1.2 STABLE release)

please let me know if this fixes it

jon

Rob Wiltbank wrote:

>Having put this into production we've found a little glitch -- if a user 
>is added into an existing list, it seems that it will corrupt that list 
>and kick back this error:
>
>A fatal error has occurred:
>
>Unable to load the definition of Turba_Driver_.
>
>[line 44 of /var/www/html/horde/turba/lib/Driver.php]
>
>However, if new contacts are added into a new list, then it's fine.  Any 
>thoughts on this?
>
>Rob
>
>  
>
-------------- next part --------------
--- /home/iisjsoo/turba-1.2/lib/Turba.php	Mon Feb 10 21:16:30 2003
+++ lib/Turba.php	Tue Aug 19 13:02:57 2003
@@ -17,6 +17,52 @@
  */
 class Turba {
 
+/* iisjsoo
+ * 
+ *      Function written to take an $objectKey of form: 
+ *
+ *                'localsql'|'38183e5d7ace6910e33eb925f29181c6'
+ *                'localldap'|'uid=asddf,dn=adsf,dn=com'
+ *
+ *      and it returns an array of the two parts:
+ *
+ *            Array([0]=>'localsql', [1]=>'38183e5d7ace6910e33eb925f29181c6')
+ *            Array([0]=>'localldap', [1]=>'uid=asddf,dn=adsf,dn=com')
+ * 
+ *      You should probably call it like:
+ *          list($objectKeySource, $objectKey)  = splitSourceAndKey($objectKey);
+ */       
+
+function splitSourceAndKey($objectKey) {
+ if (preg_match("/\|/", $objectKey)) {
+   $objectKeyArr = preg_split('/\|/', $objectKey);
+   $objectKeySource = $objectKeyArr[0];
+   $objectKeyKey = $objectKeyArr[1];
+   return array($objectKeySource, $objectKeyKey);
+ } else {
+    // this is for backwards compatibility
+  return array(PERSONAL_ADDRESS_BOOK_SOURCE, $objectKey);
+//   return -1;
+ }
+}
+/* iisjsoo
+ *
+ * Function written to send back a list member and a source
+ * when it is sent as an array.
+ *
+ * It defaults to sending back the PERSONAL_ADDRESS_BOOK_SOURCE
+ * if a string and not an array is sent
+ *
+ */
+function getListMember($listMember) {
+  if (is_array($listMember)) { 
+    return array($listMember[0], $listMember[1]);
+  } else {
+    // this is for backwards compatibility
+    return array(PERSONAL_ADDRESS_BOOK_SOURCE, $listMember);
+  }
+}
+
     function getBareEmail($address)
     {
         require_once 'Mail/RFC822.php';
@@ -173,3 +219,4 @@
     }
 
 }
+?>
-------------- next part --------------
--- /home/iisjsoo/turba-1.2/browse.php	Wed Mar  5 02:33:34 2003
+++ browse.php	Tue Aug 19 13:03:09 2003
@@ -69,13 +69,20 @@
         /* Remove a contact from a list. */
         $keys = Horde::getFormData('objectkeys');
         if (is_array($keys)) {
-
             $key = Horde::getFormData('key', false);
             if ($key && $key != "**search") {
                 /* We are removing a contact from a list. */
                 $list = $driver->getObject($key);
                 foreach ($keys as $objectKey) {
-                    if (!$list->removeMember($driver->getObject($objectKey))) {
+/* iisjsoo
+ *
+ *  This was changed so that it takes into account the source of the
+ *  entry
+ *
+ */
+        	    list($objectKeySource, $objectKey)  = Turba::splitSourceAndKey($objectKey);
+                    $driver = &Turba_Source::singleton($objectKeySource, $cfgSources[$objectKeySource]);
+                    if (!$list->removeMemberSource($driver->getObject($objectKey))) {
                         Horde::raiseMessage(_("There was an error removing this object."), HORDE_ERROR);
                     } else {
                         Horde::raiseMessage(_("Contact removed from list."), HORDE_SUCCESS);
@@ -84,6 +91,13 @@
             } else {
                 /* We are deleting an object. */
                 foreach ($keys as $objectKey) {
+/* iisjsoo
+ *
+ *  This was changed so that it takes into account the source of the
+ *  entry
+ *
+ */
+        	    list($objectKeySource, $objectKey)  = Turba::splitSourceAndKey($objectKey);
                     if (!$driver->removeObject($objectKey)) {
                         Horde::raiseMessage(_("There was an error deleting this object."), HORDE_ERROR);
                     }
@@ -102,47 +116,13 @@
         }
         break;
 
+/* iisjsoo: 
+ *         i moved the TURBA_ADD functionality to a separate include file - this was
+ *         so Advanced Search could also add users.
+ *         
+*/
     case TURBA_ADD:
-        /* Add a contact to a list */
-        $keys = Horde::getFormData('objectkeys');
-        $targetKey = Horde::getFormData('targetList');
-        if (empty($targetKey)) {
-            break;
-        }
-
-        if (!Horde::getFormData('targetNew')) {
-            $target = $driver->getObject($targetKey);
-        }
-
-        if (!empty($target) && is_object($target) && $target->isGroup()) {
-            /* Adding contact to an existing list */
-            if (is_array($keys)) {
-                foreach ($keys as $objectKey) {
-                    $target->addMember($driver->getObject($objectKey));
-                }
-                $target->store();
-            }
-        } else {
-            /* Adding conect to a new list */
-            $newList = array();
-            $newList['__owner'] = Auth::getAuth();
-            $newList['__type'] = 'Group';
-            $newList['name'] = $targetKey;
-
-            $targetKey = $driver->addObject($newList);
-            $target = $driver->getObject($targetKey);
-
-            if (!empty($target) && is_object($target) && $target->isGroup()) {
-                if (is_array($keys)) {
-                    foreach ($keys as $objectKey) {
-                        $target->addMember($driver->getObject($objectKey));
-                    }
-                    $target->store();
-                }
-            } else {
-                Horde::raiseMessage(_("There was an error creating a new list."), HORDE_ERROR);
-            }
-        }
+        require TURBA_BASE . '/lib/adduser.inc'; 
         break;
     }
 }
@@ -165,13 +145,20 @@
                    !isset($columns[$prefs->getValue('sortby') - 1])) ?
         'lastname' : $columns[$prefs->getValue('sortby') - 1];
 
-    /* Create list of lists for Add to. */
+/* Create list of lists for Add to. */
+/* iisjsoo: 
+ *         this next block is new - it is used so that addresses can be added
+ *         to any address books. (e.g. ldap addresses can be added to sql books)
+*/
     $addToList = array();
-    if (!empty($cfgSources[$source]['map']['__type'])) {
-        $listList = $driver->search(array('__type' => 'Group'), null, null, 0);
+   foreach ($sources as $src=>$val) {
+     if (!empty($cfgSources[$src]['map']['__type'])) {
+       $tmp_driver = &Turba_Source::singleton($source, $cfgSources[$src]);
+       $listList = $tmp_driver->search(array('__type' => 'Group'), null, null, 0);
         $listList->reset();
         while ($listObject = $listList->next()) {
-            $addToList[] = array('name' => $listObject->getValue('name'), 'key' => $listObject->getValue('__key'));
+         $addToList[] = array('name' => $listObject->getValue('name'), 'key' => $src."|".$listObject->getValue('__key'));
+        }
         }
     }
 
@@ -198,29 +185,44 @@
 
     } else if (Horde::getFormData('key')) {
         /* We are displaying the contents of a list */
+            $templates[] = '/browse/header.inc';
+
+        /*  iisjsoo:
+         *      First we will grab an array using the listMembersArray() function to
+         *      give us all users in this list as well as the source they come from.
+         *
+         *      Then we will go thru the list and extract the users from their sources
+         *      into a Turba_List which will be passed on.
+         *
+         *      Note: there could be a performance enhancement here - make only one driver
+         *            for each source
+         */
+            require_once TURBA_BASE . '/lib/List.php';
+            $results = &new Turba_List();
+            $listType = 'list';
+	     
+            $driver = &Turba_Source::singleton(PERSONAL_ADDRESS_BOOK_SOURCE, $cfgSources[PERSONAL_ADDRESS_BOOK_SOURCE]);
         $list = $driver->getObject(Horde::getFormData('key'));
-        if (isset($list) && is_object($list) && $list->isGroup()) {
-            $title = sprintf(_("Addresses in list: %s"), $list->getValue('name'));
-            include TURBA_TEMPLATES . '/browse/header.inc';
-            /* Show List Members */
-            if (!is_object($results = $list->listMembers($sortcolumn, $prefs->getValue('sortdir')))) {
-                Horde::raiseMessage(_("Failed to browse list"), HORDE_ERROR);
-                include TURBA_BASE . '/status.php';
-            } else {
-                $listType = "list";
+            $results_array = $list->listMembersArray();
+            if (count($results_array) != 0) {
+                foreach ($results_array as $tmp=>$listMember) {
+        /*  iisjsoo:
+         *     The $results_array contains entries of the form: 
+         *                 'localsql'|'38183e5d7ace6910e33eb925f29181c6'
+         *                'localldap'|'uid=asddf,dn=adsf,dn=com'
+         */
+        	  list($listMemberSource, $listMemberKey)  = Turba::getListMember($listMember);
+                  $driver = &Turba_Source::singleton($listMemberSource, $cfgSources[$listMemberSource]);
+                  $tmp2= $driver->getObject($listMemberKey);
+                  $results->insert($tmp2);
+                }
+            }
                 include TURBA_TEMPLATES . '/browse/actions.inc';
                 include TURBA_TEMPLATES . '/browse/column_headers.inc';
-
                 require_once TURBA_BASE . '/lib/ListView.php';
                 $display = &new Turba_ListView($results, TURBA_TEMPLATES . '/browse/contactrow.inc');
                 $numDisplayed = $display->display();
-
                 include TURBA_TEMPLATES . '/browse/column_footers.inc';
-            }
-        } else {
-            Horde::raiseMessage(_("There was an error displaying the select List"), HORDE_ERROR);
-            include TURBA_BASE . '/status.php';
-        }
     } else {
         /* We are displaying the contents of the address book */
         $title = sprintf(_("Contents of %s"), $cfgSources[$source]['title']);


More information about the turba mailing list