Split user management routines to external module "congregation"
authorBen Klang <ben@alkaloid.net>
Mon, 31 Oct 2005 12:34:40 +0000 (12:34 +0000)
committerBen Klang <ben@alkaloid.net>
Mon, 31 Oct 2005 12:34:40 +0000 (12:34 +0000)
git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@76 06cd67b6-e706-0410-b29e-9de616bca6e9

andrew.webprj
dialplan/edit.php
lib/Driver.php
lib/Driver/ldap.php
lib/Shout.php
lib/User.php
lib/base.php
main/system.php
users/edit.php
users/save.php

index b55c2db..a3a5d8f 100644 (file)
@@ -6,20 +6,20 @@
     <item url="config/" uploadstatus="1" />
     <item modified_time="1120073766" url="config/conf.xml" uploadstatus="1" />
     <item url="dialplan/" uploadstatus="1" />
-    <item modified_time="1121689003" url="dialplan/edit.php" uploadstatus="1" />
+    <item modified_time="1130716381" url="dialplan/edit.php" uploadstatus="1" />
     <item url="lib/" uploadstatus="1" />
     <item url="lib/Driver/" uploadstatus="1" />
-    <item modified_time="1126200076" url="lib/Driver/ldap.php" uploadstatus="1" />
-    <item modified_time="1120648387" url="lib/base.php" uploadstatus="1" />
+    <item modified_time="1130709096" url="lib/Driver/ldap.php" uploadstatus="1" />
+    <item modified_time="1130704853" url="lib/base.php" uploadstatus="1" />
     <item modified_time="1121689003" url="lib/Dialplan.php" uploadstatus="1" />
-    <item modified_time="1120815592" url="lib/Driver.php" uploadstatus="1" />
-    <item modified_time="1129871131" url="lib/Shout.php" uploadstatus="1" />
+    <item modified_time="1130705377" url="lib/Driver.php" uploadstatus="1" />
+    <item modified_time="1130703542" url="lib/Shout.php" uploadstatus="1" />
     <item modified_time="1121689003" url="lib/System.php" uploadstatus="1" />
-    <item modified_time="1122529264" url="lib/User.php" uploadstatus="1" />
+    <item modified_time="1130724077" url="lib/User.php" uploadstatus="1" />
     <item url="main/" uploadstatus="1" />
     <item modified_time="1121689003" url="main/dialplan.php" uploadstatus="1" />
     <item modified_time="1121401845" url="main/moh.php" uploadstatus="1" />
-    <item modified_time="1121401845" url="main/system.php" uploadstatus="1" />
+    <item modified_time="1130716385" url="main/system.php" uploadstatus="1" />
     <item modified_time="1121689003" url="main/users.php" uploadstatus="1" />
     <item url="templates/" uploadstatus="1" />
     <item url="templates/context/" uploadstatus="1" />
     <item url="users/" uploadstatus="1" />
     <item modified_time="1122704539" url="users/add.php" uploadstatus="1" />
     <item modified_time="1122704539" url="users/delete.php" uploadstatus="1" />
-    <item modified_time="1121834514" url="users/edit.php" uploadstatus="1" />
-    <item modified_time="1122529264" url="users/save.php" uploadstatus="1" />
+    <item modified_time="1130716394" url="users/edit.php" uploadstatus="1" />
+    <item modified_time="1130716388" url="users/save.php" uploadstatus="1" />
     <item modified_time="1121689003" url="dialplan.php" uploadstatus="1" />
-    <item modified_time="1129871121" url="index.php" uploadstatus="1" />
+    <item modified_time="1121689003" url="index.php" uploadstatus="1" />
     <item modified_time="1122704475" url="users.php" uploadstatus="1" />
     <item url="" uploadstatus="1" />
     <uploadprofiles showtreeviews="true" defaultProfile="Shout" >
       <profile remote_host="" remote_port="" remote_path="" remote_protocol="ftp" user="" name="@" />
-      <profile remote_host="picasso.v-office.biz" remote_port="22" remote_path="/srv/vhost/users/alkaloid/sites/intranet.v-office.biz/shout" remote_protocol="sftp" user="aklang" name="Shout" >
+      <profile remote_host="picasso.v-office.biz" remote_port="22" remote_path="/srv/vhost/users/alkaloid/sites/intranet.v-office.biz/shout" remote_protocol="sftp" user="alkaloid" name="Shout" >
         <uploadeditem upload_time="0" url="config/" />
         <uploadeditem upload_time="1120073766" url="config/conf.xml" />
         <uploadeditem upload_time="1121689003" url="dialplan.php" />
         <uploadeditem upload_time="0" url="dialplan/" />
-        <uploadeditem upload_time="1121689003" url="dialplan/edit.php" />
-        <uploadeditem upload_time="1129871121" url="index.php" />
+        <uploadeditem upload_time="1130716381" url="dialplan/edit.php" />
+        <uploadeditem upload_time="1121689003" url="index.php" />
         <uploadeditem upload_time="0" url="lib/" />
         <uploadeditem upload_time="1121689003" url="lib/Dialplan.php" />
-        <uploadeditem upload_time="1120815592" url="lib/Driver.php" />
+        <uploadeditem upload_time="1130705377" url="lib/Driver.php" />
         <uploadeditem upload_time="0" url="lib/Driver/" />
-        <uploadeditem upload_time="1126200076" url="lib/Driver/ldap.php" />
-        <uploadeditem upload_time="1129871131" url="lib/Shout.php" />
+        <uploadeditem upload_time="1130709096" url="lib/Driver/ldap.php" />
+        <uploadeditem upload_time="1130703542" url="lib/Shout.php" />
         <uploadeditem upload_time="1121689003" url="lib/System.php" />
-        <uploadeditem upload_time="1122529264" url="lib/User.php" />
-        <uploadeditem upload_time="1120648387" url="lib/base.php" />
+        <uploadeditem upload_time="1130724077" url="lib/User.php" />
+        <uploadeditem upload_time="1130705457" url="lib/api.php" />
+        <uploadeditem upload_time="1130704853" url="lib/base.php" />
+        <uploadeditem upload_time="1130706300" url="lib/defines.php" />
         <uploadeditem upload_time="0" url="main/" />
         <uploadeditem upload_time="1121689003" url="main/dialplan.php" />
         <uploadeditem upload_time="1121401845" url="main/moh.php" />
-        <uploadeditem upload_time="1121401845" url="main/system.php" />
+        <uploadeditem upload_time="1130716385" url="main/system.php" />
         <uploadeditem upload_time="1121689003" url="main/users.php" />
         <uploadeditem upload_time="0" url="templates/" />
         <uploadeditem upload_time="1120174958" url="templates/common-header.inc" />
         <uploadeditem upload_time="0" url="users/" />
         <uploadeditem upload_time="1122704539" url="users/add.php" />
         <uploadeditem upload_time="1122704539" url="users/delete.php" />
-        <uploadeditem upload_time="1121834514" url="users/edit.php" />
-        <uploadeditem upload_time="1122529264" url="users/save.php" />
+        <uploadeditem upload_time="1130716394" url="users/edit.php" />
+        <uploadeditem upload_time="1130716388" url="users/save.php" />
       </profile>
     </uploadprofiles>
     <templates>templates/</templates>
     <toolbars>toolbars/</toolbars>
+    <item modified_time="1130705457" url="lib/api.php" uploadstatus="1" />
     <author>Ben Klang</author>
     <email>ben@alkaloid.net</email>
     <debuggerclient>No Debugger</debuggerclient>
-    <exclude cvsignore="false" >*~;</exclude>
+    <exclude cvsignore="true" >*~;CVS;.*~;</exclude>
     <teamdata>
       <taskleaders/>
       <subprojectleaders/>
       <mailinglist address="" />
     </teamdata>
     <events/>
+    <item modified_time="1130706300" url="lib/defines.php" />
     <treestatus>
+      <openfolder url="config" />
       <openfolder url="dialplan" />
       <openfolder url="lib" />
       <openfolder url="lib/Driver" />
+      <openfolder url="main" />
+      <openfolder url="users" />
     </treestatus>
   </project>
 </webproject>
index c0a4dd2..21e42a1 100644 (file)
@@ -14,7 +14,6 @@ require_once 'Horde/Variables.php';
 $RENDERER = &new Horde_Form_Renderer();
 
 $empty = '';
-$wereerrors = 0;
 
 $vars = &Variables::getDefaultVariables($empty);
 $formname = $vars->get('formname');
index 0f422b3..e9674c7 100644 (file)
@@ -14,6 +14,7 @@
  * @since   Shout 0.1
  * @package Shout
  */
+require_once SHOUT_BASE . "/lib/defines.php";
 
 // {{{ Shout_Driver class
 class Shout_Driver {
@@ -25,6 +26,7 @@ class Shout_Driver {
      * @var array $_params
      */
     var $_params = array();
+
     // }}}
 
     // {{{ Shout_Driver constructor
index 9f5830d..4d556a8 100644 (file)
@@ -22,6 +22,7 @@ class Shout_Driver_ldap extends Shout_Driver
      * @var boolean $_connected
      */
     var $_connected = false;
+
     // }}}
 
     // {{{ Shout_Driver_ldap constructor
@@ -34,42 +35,6 @@ class Shout_Driver_ldap extends Shout_Driver
     {
         parent::Shout_Driver($params);
         $this->_connect();
-       
-        /* These next lines will translate between indexes used in the
-         * application and LDAP.  The rationale is that translation here will
-         * help make Shout more driver-independant.  The keys used to contruct
-         * user arrays should be more appropriate to human-legibility (name
-         * instead of 'cn' and email instead of 'mail').  This translation is
-         * only needed because LDAP indexes users based on an arbitrary
-         * attribute and the application indexes by extension/context.  In my
-         * environment users are indexed by their 'mail' attribute and others
-         * may index based on 'cn' or 'uid'.  Any time a new $prefs['uid'] needs
-         * to be supported, this function should be checked and possibly
-         * modified to handle that translation.
-         */
-        switch($this->_params['uid']) {
-        case 'cn':
-            $this->_ldapKey = 'cn';
-            $this->_appKey = 'name';
-            break;
-        case 'mail':
-            $this->_ldapKey = 'mail';
-            $this->_appKey = 'email';
-            break;
-        case 'uid':
-            # There is no value that maps uid to LDAP so we can choose to use
-            # either extension or name, or anything really.  I want to
-            # support it since it's a very common DN attribute.
-            # Since it's entirely administrator's preference, I'll
-            # set it to name for now
-            $this->_ldapKey = 'uid';
-            $this->_appKey = 'name';
-            break;
-        case 'voiceMailbox':
-            $this->_ldapKey = 'voiceMailbox';
-            $this->_appKey = 'extension';
-            break;
-        }
     }
     // }}}
 
@@ -104,6 +69,7 @@ class Shout_Driver_ldap extends Shout_Driver
             $searchfilter="(objectClass=asteriskObject)";
         } else {
             $searchfilter = "(|";
+            # FIXME Change this to non-V-Office specific objectClass
             if ($searchfilters & SHOUT_CONTEXT_CUSTOMERS) {
                 $searchfilter.="(objectClass=vofficeCustomer)";
             } else {
@@ -130,16 +96,15 @@ class Shout_Driver_ldap extends Shout_Driver
             $searchfilter .= ")";
         }
 
-
         # Collect all the possible contexts from the backend
         $res = @ldap_search($this->_LDAP,
             SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'],
-            "(&(objectClass=asteriskObject)$searchfilter)",
-            array('context'));
+            "$searchfilter");
+            #array('context', 'associatedDomain'));
         if (!$res) {
             return PEAR::raiseError("Unable to locate any contexts " .
             "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn'] .
-            " matching those search filters");
+            " matching those search filters" . ldap_error($this->_LDAP));
         }
 
         $res = ldap_get_entries($this->_LDAP, $res);
@@ -147,8 +112,10 @@ class Shout_Driver_ldap extends Shout_Driver
         $entries[$searchfilters] = array();
         while ($i < $res['count']) {
             $context = $res[$i]['context'][0];
+            @$domain = $res[$i]['associateddomain'][0];
             if (Shout::checkRights("shout:contexts:$context", $filterperms)) {
-                $entries[$searchfilters][] = $context;
+                $entries[$searchfilters][$context] =
+                    array('domain' => $domain);
             }
             $i++;
         }
@@ -222,74 +189,90 @@ type");
      */
     function &getUsers($context)
     {
-    
+
         static $entries = array();
         if (isset($entries[$context])) {
             return $entries[$context];
         }
-        
-        $search = @ldap_search($this->_LDAP,
-            SHOUT_USERS_BRANCH.','.$this->_params['basedn'],
-            '(&(objectClass='.SHOUT_USER_OBJECTCLASS.')(context='.$context.'))',
-            array('voiceMailbox', 'asteriskUserDialOptions',
-                'asteriskVoiceMailboxOptions', 'voiceMailboxPin',
-                'cn', 'telephoneNumber',
-                'asteriskUserDialTimeout', 'mail', 'asteriskPager'));
-        if (!$search) {
-            return PEAR::raiseError("Unable to search directory: " .
-                ldap_error($this->_LDAP));
-        }
-        $res = ldap_get_entries($this->_LDAP, $search);
-        $entries[$context] = array();
-        $i = 0;
-        while ($i < $res['count']) {
-            $extension = $res[$i]['voicemailbox'][0];
-            $entries[$context][$extension] = array();
-
-            $j = 0;
-            $entries[$context][$extension]['dialopts'] = array();
-            while ($j < @$res[$i]['asteriskuserdialoptions']['count']) {
-                $entries[$context][$extension]['dialopts'][] =
-                    $res[$i]['asteriskuserdialoptions'][$j];
-                $j++;
-            }
-
-            $j = 0;
-            $entries[$context][$extension]['mailboxopts'] = array();
-            while ($j < @$res[$i]['asteriskvoicemailboxoptions']['count']) {
-                $entries[$context][$extension]['mailboxopts'][] =
-                    $res[$i]['asteriskvoicemailboxoptions'][$j];
-                $j++;
-            }
-
-            $entries[$context][$extension]['mailboxpin'] =
-                $res[$i]['voicemailboxpin'][0];
-
-            @$entries[$context][$extension]['name'] =
-                $res[$i]['cn'][0];
-
-            $j = 0;
-            $entries[$context][$extension]['phonenumbers'] = array();
-            while ($j < @$res[$i]['telephonenumber']['count']) {
-                $entries[$context][$extension]['phonenumbers'][] =
-                    $res[$i]['telephonenumber'][$j];
-                $j++;
-            }
-
-            # FIXME Do some sanity checking here.  Also set a default?
-            @$entries[$context][$extension]['dialtimeout'] =
-                $res[$i]['asteriskuserdialtimeout'][0];
 
-            @$entries[$context][$extension]['email'] =
-                $res[$i]['mail'][0];
-
-            @$entries[$context][$extension]['pageremail'] =
-                $res[$i]['asteriskpager'][0];
-
-            $i++;
-        }
-
-        return $entries[$context];
+        $contexts = &$this->getContexts();
+        $domain = $contexts[$context]['domain'];
+
+        $registry = &Registry::singleton();
+        require_once $registry->applicationFilePath('%application%/lib/defines.php', 'congregation');
+        $users = $registry->callByPackage('congregation', 'getUsersByDomain',
+            array($domain, CONGREGATION_USER_PHONE));
+
+        foreach ($users as $user) {
+            $extension = $user['extension'];
+            $entries[$context][$extension] = $user;
+        }
+        ksort($entries[$context]);
+
+        return($entries[$context]);
+
+//         $search = @ldap_search($this->_LDAP,
+//             SHOUT_USERS_BRANCH.','.$this->_params['basedn'],
+//'(&(objectClass='.SHOUT_USER_OBJECTCLASS.')(context='.$context.'))',
+//             array('voiceMailbox', 'asteriskUserDialOptions',
+//                 'asteriskVoiceMailboxOptions', 'voiceMailboxPin',
+//                 'cn', 'telephoneNumber',
+//                 'asteriskUserDialTimeout', 'mail', 'asteriskPager'));
+//         if (!$search) {
+//             return PEAR::raiseError("Unable to search directory: " .
+//                 ldap_error($this->_LDAP));
+//         }
+//         $res = ldap_get_entries($this->_LDAP, $search);
+//         $entries[$context] = array();
+//         $i = 0;
+//         while ($i < $res['count']) {
+//             $extension = $res[$i]['voicemailbox'][0];
+//             $entries[$context][$extension] = array();
+//
+//             $j = 0;
+//             $entries[$context][$extension]['dialopts'] = array();
+//             while ($j < @$res[$i]['asteriskuserdialoptions']['count']) {
+//                 $entries[$context][$extension]['dialopts'][] =
+//                     $res[$i]['asteriskuserdialoptions'][$j];
+//                 $j++;
+//             }
+//
+//             $j = 0;
+//             $entries[$context][$extension]['mailboxopts'] = array();
+//             while ($j < @$res[$i]['asteriskvoicemailboxoptions']['count']) {
+//                 $entries[$context][$extension]['mailboxopts'][] =
+//                     $res[$i]['asteriskvoicemailboxoptions'][$j];
+//                 $j++;
+//             }
+//
+//             $entries[$context][$extension]['mailboxpin'] =
+//                 $res[$i]['voicemailboxpin'][0];
+//
+//             @$entries[$context][$extension]['name'] =
+//                 $res[$i]['cn'][0];
+//
+//             $j = 0;
+//             $entries[$context][$extension]['phonenumbers'] = array();
+//             while ($j < @$res[$i]['telephonenumber']['count']) {
+//                 $entries[$context][$extension]['phonenumbers'][] =
+//                     $res[$i]['telephonenumber'][$j];
+//                 $j++;
+//             }
+//
+//             # FIXME Do some sanity checking here.  Also set a default?
+//             @$entries[$context][$extension]['dialtimeout'] =
+//                 $res[$i]['asteriskuserdialtimeout'][0];
+//
+//             @$entries[$context][$extension]['email'] =
+//                 $res[$i]['mail'][0];
+//
+//             @$entries[$context][$extension]['pageremail'] =
+//                 $res[$i]['asteriskpager'][0];
+//
+//             $i++;
+//         }
+//
+//         return $entries[$context];
     }
     // }}}
 
@@ -301,6 +284,9 @@ type");
      */
     function getHomeContext()
     {
+        # FIXME Probably should key this off the domain part of the user's
+        # FIXME Auth::getAuth() and match context with associatedDomain
+        # FIXME Also, cache this lookup
         $res = @ldap_search($this->_LDAP,
             SHOUT_USERS_BRANCH.','.$this->_params['basedn'],
             "(&(mail=".Auth::getAuth().")(objectClass=asteriskUser))",
@@ -386,7 +372,7 @@ for $context"));
         if (isset($dialplans[$context])) {
             return $dialplans[$context];
         }
-        
+
         $res = @ldap_search($this->_LDAP,
             SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'],
             "(&(objectClass=asteriskExtensions)(context=$context))",
@@ -481,12 +467,12 @@ for $context"));
         return $dialplans[$context];
     }
     // }}}
-    
+
     // {{{
     /**
      * Get the limits for the current user, the user's context, and global
      * Return the most specific values in every case.  Return default values
-     * where no data is found.  If $extension is specified, $context must 
+     * where no data is found.  If $extension is specified, $context must
      * also be specified.
      *
      * @param optional string $context Context to search
@@ -495,9 +481,10 @@ for $context"));
      *
      * @return array Array with elements indicating various limits
      */
+     # FIXME Figure out how this fits into Shout/Congregation better
     function &getLimits($context = null, $extension = null)
     {
-    
+
         $limits = array('telephonenumbersmax',
                         'voicemailboxesmax',
                         'asteriskusers');
@@ -514,7 +501,7 @@ for $context"));
             }
             return $limits[$context];
         }
-        
+
         # Set some default limits (to unlimited)
         static $cachedlimits = array();
         # Initialize the limits with defaults
@@ -523,18 +510,18 @@ for $context"));
                 $cachedlimits[$limit] = 99999;
             }
         }
-        
+
         # Collect the global limits
         $res = @ldap_search($this->_LDAP,
             SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'],
             '(&(objectClass=asteriskLimits)(cn=globals))',
             $limits);
-        
+
         if (!$res) {
             return PEAR::raiseError('Unable to search the LDAP server for ' .
                 'global limits');
         }
-        
+
         $res = ldap_get_entries($this->_LDAP, $res);
         # There should only have been one object returned so we'll just take the
         # first result returned
@@ -544,7 +531,7 @@ for $context"));
                     $cachedlimits[$limit] = $res[0][$limit][0];
                 }
             }
-        } else {    
+        } else {
             return PEAR::raiseError("No global object found.");
         }
 
@@ -553,12 +540,12 @@ for $context"));
             $res = ldap_search($this->_LDAP,
                 SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'],
                 "(&(objectClass=asteriskLimits)(cn=$context))");
-            
+
             if (!$res) {
                 return PEAR::raiseError('Unable to search the LDAP server ' .
                     "for $context specific limits");
             }
-            
+
             $cachedlimits[$context][$extension] = array();
             if ($res['count'] > 0) {
                 foreach ($limits as $limit) {
@@ -576,18 +563,18 @@ for $context"));
                         $cachedlimits[$limit];
                 }
             }
-            
+
             if (isset($extension)) {
                 $res = @ldap_search($this->_LDAP,
                     SHOUT_USERS_BRANCH.','.$this->_params['basedn'],
                     "(&(objectClass=asteriskLimits)(voiceMailbox=$extension)".
                     "(context=$context))");
-                
+
                 if (!$res) {
                     return PEAR::raiseError('Unable to search the LDAP server '.
                         "for Extension $extension, $context specific limits");
                 }
-                
+
                 $cachedlimits[$context][$extension] = array();
                 if ($res['count'] > 0) {
                     foreach ($limits as $limit) {
@@ -612,7 +599,7 @@ for $context"));
         }
     }
     // }}}
-    
+
     // {{{
     /**
      * Save a user to the LDAP tree
@@ -627,17 +614,6 @@ for $context"));
      */
     function saveUser($context, $extension, $userdetails)
     {
-        # FIXME: Add test to make sure we aren't duplicating the extension
-        $res = ldap_search($this->_LDAP, SHOUT_USERS_BRANCH.','.$this->_params['basedn'],
-            "(&(objectClass=asteriskUser)(voiceMailbox=".
-                $userdetails['newextension']."))");
-        $res = ldap_get_entries($this->_LDAP, $res);
-        if ($res['count'] > 0) {
-            # The extension already exists.  Do some sanity checking to make
-            # sure we know we're modifying an existing user
-            # FIXME
-        }
-        
         # FIXME Access Control/Authorization
         if (!Shout::checkRights("shout:contexts:$context:users",
             PERMS_DELETE, 1)) {
@@ -646,7 +622,38 @@ for $context"));
         }
         $ldapKey = &$this->_ldapKey;
         $appKey = &$this->_appKey;
-        
+
+        $contexts = &$this->getContexts();
+        $domain = $contexts[$context]['domain'];
+
+        # Check to ensure the extension is unique within this context
+        $filter = '(&(objectClass=asteriskVoiceMailbox)(context='.$context.'))';
+        $reqattrs = array('dn', $ldapKey);
+        $res = @ldap_search($this->_LDAP,
+            SHOUT_USERS_BRANCH . ',' . $this->_params['basedn'],
+            $filter, $reqattrs);
+        if (!$res) {
+            return PEAR::raiseError('Unable to check directory for duplicate extension: ' .
+                ldap_error($this->_LDAP));
+        }
+        if (($res['count'] > 1) ||
+            ($res['count'] != 0 &&
+            !in_array($res[0][$ldapKey], $userdetails[$appKey])_) {
+            return PEAR::raiseError('Duplicate extension found.  Not saving changes.');
+        }
+
+        $validusers = &$this->getUsers($context);
+        $userId = $validusers[$extension][$appKey];
+
+        $registry = &Registry::singleton();
+        require_once $registry->applicationFilePath('%application%/lib/defines.php', 'congregation');
+        $userModes = $registry->callByPackage('congregation', 'getUserModes',
+            array($domain, $userId));
+        # FIXME Handle error here
+
+        $registry->callByPackage('congregation', 'saveUser',
+            array($domain, $userId, $userModes | CONGREGATION_USER_PHONE, ));
+
         $entry = array(
             'cn' => $userdetails['name'],
             'mail' => $userdetails['email'],
@@ -655,18 +662,18 @@ for $context"));
             'context' => $context,
             'asteriskUserDialOptions' => $userdetails['dialopts'],
         );
-        
+
         if (!empty ($userdetails['telephonenumbers'])) {
             $entry['telephoneNumber'] = $userdetails['telephonenumbers'];
         }
-        
+
         $validusers = &$this->getUsers($context);
         if (!isset($validusers[$extension])) {
             # Test to see if we're modifying an existing user that has
             # no telephone system objectClasses and update that object/user
             $rdn = "$ldapKey=".$userdetails[$appKey].',';
             $branch = SHOUT_USERS_BRANCH.','.$this->_params['basedn'];
-            
+
             # This test is something of a hack.  I want a cheap way to check
             # for the existance of an object.  I don't want to do a full search
             # so instead I compare that the dn equals the dn.  If the object
@@ -683,7 +690,7 @@ for $context"));
                 # The object/user exists but doesn't have the Asterisk
                 # objectClasses
                 $extension = $userdetails['newextension'];
-                
+
                 # $tmp is the minimal information required to establish
                 # an account in LDAP as required by the objectClasses.
                 # The entry will be fully populated below.
@@ -699,7 +706,7 @@ for $context"));
                     return PEAR::raiseError("Unable to modify the user: " .
                         ldap_error($this->_LDAP));
                 }
-                
+
                 # Populate the $validusers array to make the edit go smoothly
                 # below
                 $validusers[$extension] = array();
@@ -707,7 +714,7 @@ for $context"));
 
                 # The remainder of the work is done at the outside of the
                 # parent if() like a normal edit.
-                
+
             } elseif ($res === -1) {
                 # We must be adding a new user.
                 $entry['objectClass'] = array(
@@ -719,7 +726,7 @@ for $context"));
                     'asteriskUser',
                     'asteriskVoiceMailbox'
                 );
-                
+
                 # Check to see if the maximum number of users for this context
                 # has been reached
                 $limits = $this->getLimits($context);
@@ -730,19 +737,19 @@ for $context"));
                     print count($validusers).$limits['asteriskusers'];
                     return PEAR::raiseError('Maximum number of users reached.');
                 }
-                
+
                 $res = @ldap_add($this->_LDAP, $rdn.$branch, $entry);
                 if (!$res) {
                     return PEAR::raiseError('LDAP Add failed: ' .
                         ldap_error($this->_LDAP));
                 }
-                
+
                 return true;
             }
         }
-        
+
         # Anything after this point is an edit.
-        
+
         # Check to see if the object needs to be renamed (DN changed)
         if ($validusers[$extension][$appKey] != $entry[$ldapKey]) {
             $oldrdn = $ldapKey.'='.$validusers[$extension][$appKey];
@@ -755,7 +762,7 @@ for $context"));
                     ldap_error($this->_LDAP));
             }
         }
-        
+
         # Update the object/user
         $dn = $ldapKey.'='.$entry[$ldapKey];
         $dn .= ','.SHOUT_USERS_BRANCH.','.$this->_params['basedn'];
@@ -764,16 +771,16 @@ for $context"));
             return PEAR::raiseError('LDAP Modify failed: ' .
                 ldap_error($this->_LDAP));
         }
-        
+
         # We must have been successful
         return true;
     }
     // }}}
-    
+
     // {{{ deleteUser method
     /**
      * Deletes a user from the LDAP tree
-     * 
+     *
      * @param string $context Context to delete the user from
      * @param string $extension Extension of the user to be deleted
      *
@@ -783,21 +790,21 @@ for $context"));
     {
         $ldapKey = &$this->_ldapKey;
         $appKey = &$this->_appKey;
-        
+
         if (!Shout::checkRights("shout:contexts:$context:users",
             PERMS_DELETE, 1)) {
             return PEAR::raiseError("No permission to delete users in this " .
                 "context.");
         }
-        
+
         $validusers = $this->getUsers($context);
         if (!isset($validusers[$extension])) {
             return PEAR::raiseError("That extension does not exist.");
         }
-        
+
         $dn = "$ldapKey=".$validusers[$extension][$appKey];
         $dn .= ',' . SHOUT_USERS_BRANCH . ',' . $this->_params['basedn'];
-        
+
         $res = @ldap_delete($this->_LDAP, $dn);
         if (!$res) {
             return PEAR::raiseError("Unable to delete $extension from " .
@@ -806,7 +813,7 @@ for $context"));
         return true;
     }
     // }}}
-    
+
     // {{{ connect method
     /**
      * Attempts to open a connection to the LDAP server.
index b8cbd66..26cfdd0 100644 (file)
@@ -1,14 +1,20 @@
 <?php
-
-@define(SHOUT_ASTERISK_BRANCH, "ou=Asterisk");
-@define(SHOUT_USERS_BRANCH, "ou=Customers");
-@define(SHOUT_USER_OBJECTCLASS, "asteriskUser");
-
-@define(SHOUT_CONTEXT_ALL, 0);
-@define(SHOUT_CONTEXT_CUSTOMERS, 1 << 0);
-@define(SHOUT_CONTEXT_EXTENSIONS, 1 << 1);
-@define(SHOUT_CONTEXT_MOH, 1 << 2);
-@define(SHOUT_CONTEXT_CONFERENCE, 1 << 3);
+/**
+ * Shout:: defines an set of classes for the Shout application.
+ *
+ * $Horde: shout/lib/Shout.php,v 0.01 2005/06/28 11:15:03 ben Exp $
+ *
+ * Copyright 2005 Ben Klang <ben@alkaloid.net>
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Ben Klang <ben@alkaloid.net>
+ * @version $Revision$
+ * @since   Shout 0.1
+ * @package Shout
+ */
+require_once SHOUT_BASE . "/lib/defines.php";
 
 // {{{ Class Shout
 class Shout
@@ -35,7 +41,7 @@ class Shout
             $url = Util::addParameter($url, array('context' => $context,
                                                   'section' => $section,
                                                   'action' => 'add'));
-            
+
             # Goofy hack to make the icon make a little more sense
             # when editing/deleting users
             if (!isset($action)) {
@@ -56,7 +62,7 @@ class Shout
             $url = Util::addParameter($url, array('context' => $context,
                                                   'section' => $section,
                                                   'action' => 'add'));
-            
+
             # Goofy hack to make the icon make a little sense
             # when editing/deleting users
             if (!isset($action)) {
@@ -69,7 +75,7 @@ class Shout
 
             $menu->add($url, _("$icontitle Extension"), "add-extension.gif");
         }
-        
+
         if ($returnType == 'object') {
             return $menu;
         } else {
index 04143f1..e35dac6 100644 (file)
@@ -18,7 +18,7 @@ class UserDetailsForm extends Horde_Form {
         global $shout;
         $context = $vars->get("context");
         $extension = $vars->get("extension");
-        
+
         $users = &$shout->getUsers($context);
         if (array_key_exists($extension, $users)) {
             # We must be editing an existing user
@@ -31,7 +31,7 @@ class UserDetailsForm extends Horde_Form {
         }
 
         parent::Horde_Form($vars, _("$formtitle - Context: $context"));
-        
+
         $this->addHidden('', 'context', 'text', true);
         $this->addHidden('', 'curextension', 'text', true);
         $vars->set('curextension', $extension);
@@ -40,10 +40,11 @@ class UserDetailsForm extends Horde_Form {
         $this->addVariable(_("Full Name"), 'name', 'text', true);
         $this->addVariable(_("Extension"), 'newextension', 'int', true);
         $this->addVariable(_("E-Mail Address"), 'email', 'text', true);
+        $this->addVariable(_("Pager E-Mail Address"), 'pageremail', 'text', false);
         # TODO: Integrate with To-Be-Written user manager and possibly make this
         # TODO: new user also an email account.
         $this->addVariable(_("PIN"), 'pin', 'int', true);
-        
+
         $t = 1;
         while ($t <= $limits['telephonenumbersmax']) {
             $this->addVariable(_("Telephone Number $t:"), "telephone$t",
@@ -51,15 +52,23 @@ class UserDetailsForm extends Horde_Form {
                 false);
             $t++;
         }
-        
+
         $this->addVariable(_("Music on Hold while transferring"), 'moh',
-            'radio', true, false, null,
-            array('values' => array(true => 'Yes', false => 'No')));
+            'boolean', true, false);#, _("When checked, a calling user will hear music on hold while the caller is connected"));
         $this->addVariable(_("Allow Call Transfers"), 'transfer',
-            'radio', true, false, null,
-            array('values' => array(true => 'Yes', false => 'No')));
+            'boolean', true, false);#, _("When checked, the called user will be allowed to transfer the incoming call to other extensions"));
+        $this->addVariable(_("Explicit Call Acceptance"), 'eca',
+            'boolean', true, false);#, _("When checked, the called user will be required to press 1 to accept the call.  Only turn this off if you really know what you're doing!"));
+        $this->addVariable(_("Call Appearance"), 'callappearance',
+            'radio', true, false, null, array('values' =>
+                array('caller' => 'From Calling Party',
+                    'self' => 'From Self',
+                    'v-office' => 'From V-Office',
+                )
+            )
+        );
     }
-    
+
     // {{{ fillUserForm method
     /**
      * Fill in the blanks for the UserDetailsForm
@@ -74,30 +83,47 @@ class UserDetailsForm extends Horde_Form {
     {
     #Array ( [dialopts] => Array ( [0] => m [1] => t ) [mailboxopts] => Array (
     #) [mailboxpin] => 1234 [name] => Ricardo Paul [phonenumbers] => Array ( )
-    #[dialtimeout] => 30 [email] => ricardo.paul@v-office.biz [pageremail] => ) 
+    #[dialtimeout] => 30 [email] => ricardo.paul@v-office.biz [pageremail] => )
         $vars->set('name', $userdetails['name']);
         $vars->set('email', @$userdetails['email']);
         $vars->set('pin', $userdetails['mailboxpin']);
         $vars->set('newextension', $vars->get('extension'));
-        
+
         $i = 1;
         foreach($userdetails['phonenumbers'] as $number) {
             $vars->set("telephone$i", $number);
             $i++;
         }
-        
+
         if (in_array('m', $userdetails['dialopts'])) {
             $vars->set('moh', true);
         } else {
             $vars->set('moh', false);
         }
-        
+
         if (in_array('t', $userdetails['dialopts'])) {
             $vars->set('transfer', true);
         } else {
             $vars->set('transfer', false);
         }
-        
+
+        if (in_array('e', $userdetails['dialopts'])) {
+            $vars->set('eca', true);
+        } else {
+            $vars->set('eca', false);
+        }
+
+        if (in_array('__CALLPRESENT:${VOFFICENUM}', $userdetails['dialopts'])) {
+            $vars->set('eca', true);
+            $vars->set('callappearance', 'v-office');
+        } elseif (in_array('__CALLPRESENT:${CALLER}', $userdetails['dialopts'])) {
+            $vars->set('eca', true);
+            $vars->set('callappearance', 'caller');
+        } elseif (in_array('__CALLPRESENT:${SELF}', $userdetails['dialopts'])) {
+            $vars->set('eca', true);
+            $vars->set('callappearance', 'self');
+        }
+
         return true;
     }
     // }}}
index e4deede..31e01df 100644 (file)
@@ -51,6 +51,7 @@ require_once 'Horde/Text/Filter.php';
 require_once 'Horde/UI/Tabs.php';
 
 $GLOBALS['shout'] = &Shout_Driver::singleton();
+// $shout = $GLOBALS['shout'];
 
 // Horde libraries.
 require_once 'Horde/Help.php';
\ No newline at end of file
index 6d5eff4..c529220 100644 (file)
@@ -15,7 +15,6 @@ $RENDERER = &new Horde_Form_Renderer();
 
 $empty = '';
 $beendone = 0;
-$wereerrors = 0;
 
 $vars = &Variables::getDefaultVariables($empty);
 $syscontext = Util::getFormData("syscontext");
index 5ecc311..8646060 100644 (file)
@@ -14,7 +14,6 @@ require_once 'Horde/Variables.php';
 $RENDERER = &new Horde_Form_Renderer();
 
 $empty = '';
-$wereerrors = 0;
 
 $vars = &Variables::getDefaultVariables($empty);
 $formname = $vars->get('formname');
index 24d8015..230f571 100644 (file)
@@ -13,8 +13,6 @@ require_once 'Horde/Variables.php';
 
 $RENDERER = &new Horde_Form_Renderer();
 
-$wereerrors = 0;
-
 $vars = &Variables::getDefaultVariables();
 $formname = $vars->get('formname');
 
@@ -57,7 +55,7 @@ if (Util::getFormData('transfer')) {
     $userdetails['dialopts'][] = 't';
 }
 
-$res = $shout->saveUser($context, $curextension, $userdetails);
-if (is_a($res, 'PEAR_Error')) {
-    print $res->getMessage();
-}
\ No newline at end of file
+// $res = $shout->saveUser($context, $curextension, $userdetails);
+// if (is_a($res, 'PEAR_Error')) {
+//     print $res->getMessage();
+// }
\ No newline at end of file