[cvs] [Wiki] changed: CustomizingPreferences

Wiki Guest wiki at wiki.horde.org
Wed Feb 23 22:12:44 PST 2005


guest [68.228.225.160]  Wed, 23 Feb 2005 22:12:44 -0800

Modified page: http://wiki.horde.org/display.php?page=CustomizingPreferences
New Revision:  1.3

@@ -14,9 +14,99 @@
 
 -----
 
 +++ hooks.php
+I have created some hooks for capturing the users Identity and Email address to automatically set their Default identity the 
+first time that they log in. These hooks assume LDAP backend and should be instructive for someone wanting to create their
+own custom hooks...this wasn't easy to figure out.
 
+The first modification I did to hooks.php was to add the following (don't forget to add the
+'hook' => 'true', to $prefs('from_addr')'
+
+<code type="php">
+if (!function_exists('_prefs_hook_from_addr')) {
+
+   function _prefs_hook_from_addr($user = null)
+     {
+
+       $ldapServer = 'localhost';
+       $ldapPort = '389';
+       $searchBase = 'ou=People,dc=azapple,dc=com';
+       $ds = @ldap_connect($ldapServer, $ldapPort);
+
+       if (is_null($user)) {
+         $user = Auth::getAuth();
+       }
+
+       $uid = Auth::getBareAuth();
+       $binddn = 'uid=' . $uid . ',' . $searchBase;
+       $bindpw = Auth::getCredential('password');
+
+       if (@ldap_bind($ds, $binddn, $bindpw)) {
+         $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $uid);
+       }
+
+       $information = @ldap_get_entries($ds, $searchResult);
+
+        // derive the email address if possible
+        if ($information[0]['mail'][0] != '') {
+           $emailname = $information[0]['mail'][0];
+        } else {
+           $emailname = $information[0]['uid'][0];
+        }
+
+         // $emailname = $information[0]['mail'][0];
+
+         ldap_close($ds);
+
+         return $emailname;
+     }
+}
+</code>
+The second modification I did to hooks.php was to add the following (don't forget to add the
+'hook' => 'true', to $prefs('fullname')'
+<code type="php">
+if (!function_exists('_prefs_hook_fullname')) {
+
+   function _prefs_hook_fullname($user = null)
+   {
+
+        $ldapServer = 'localhost';
+        $ldapPort = '389';
+        $searchBase = 'ou=People,dc=azapple,dc=com';
+        $ds = @ldap_connect($ldapServer, $ldapPort);
+
+        if (is_null($user)) {
+            $user = Auth::getAuth();
+        }
+
+        $uid = Auth::getBareAuth();
+        $binddn = 'uid=' . $uid . ',' . $searchBase;
+        $bindpw = Auth::getCredential('password');
+
+        if (@ldap_bind($ds, $binddn, $bindpw)) {
+            $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $uid);
+        }
+
+        $information = @ldap_get_entries($ds, $searchResult);
+
+        // derive the email address if possible
+        if ($information[0]['cn'][0] != '') {
+           $name = $information[0]['cn'][0];
+        } else {
+           $name = $information[0]['gecos'][0];
+        }
+
+           // $test = ($information[0]['gecos'][0]);
+
+        ldap_close($ds);
+
+        return $name;
+   }
+}
+</code>
+CW
+----
 add your customizations here...
 
 -----
 


More information about the cvs mailing list