A number of changes aimed at integrating more closely with Mandy's development
authorBen Klang <ben@alkaloid.net>
Mon, 4 Jul 2005 05:51:38 +0000 (05:51 +0000)
committerBen Klang <ben@alkaloid.net>
Mon, 4 Jul 2005 05:51:38 +0000 (05:51 +0000)
git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@46 06cd67b6-e706-0410-b29e-9de616bca6e9

contexts.php [deleted file]
index.php
lib/Driver.php
lib/Driver/ldap.php
lib/Shout.php
lib/Users.php [deleted file]
shout.webprj
templates/menu.inc
users.php

diff --git a/contexts.php b/contexts.php
deleted file mode 100644 (file)
index d9c7299..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-if (!defined(SHOUT_BASE)) {
-    define(SHOUT_BASE, dirname(__FILE__));
-}
-
-# Check that we are properly initialized
-if (!isset($contexts) || is_a($contexts, 'PEAR_Error')) {
-    $notification->push(_("Internal error viewing requested page"),
-                        'horde.error');
-}
-
-if (count($contexts) < 1) {
-    $notification->push(_("You do not have permission to access this
-system.", 'horde.error'));
-    exit();
-} elseif (count($contexts) == 1) {
-    header("Location: " .
-        Horde::applicationUrl("index.php?context=$contexts[0]&section=users"));
-    exit();
-}
-
-$notification->notify();
-
-# Print the contexts
-$toggle = false;
-foreach($contexts as $context) {
-    include SHOUT_TEMPLATES . "/context/contextline.inc";
-    $toggle = !$toggle;
-}
\ No newline at end of file
index 676ed50..b1e6d0e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -32,6 +32,8 @@ $vars = &Variables::getDefaultVariables();
 
 if (count($contexts) == 1) {
     $context = $contexts[0];
+} elseif (!$context) {
+    $context = $shout->getHomeContext();
 }
 
 #$title = '[#' . $ticket->getId() . '] ' . $ticket->get('summary');
@@ -42,10 +44,17 @@ $tabs = &Shout::getTabs($context, $vars);
 $tabs->preserve('context', $context);
 
 echo "<br />";
+// if (!$section) {
+//     $section = 
+if (!$section) {
+    $section = $tabs->_tabs[0]['tabname'];
+}
+
 echo $tabs->render($section);
 switch ($section) {
     case "conference":
     case "dialplan":
+    case "security":
     case "users":
     case "moh":
         require "$section.php";
index 68d3d46..538c044 100644 (file)
@@ -48,7 +48,7 @@ class Shout_Driver {
     *
     * @access public
     */
-    function getContexts($filter = "all", $filterperms = null)
+    function getContexts($filters = "all", $filterperms = null)
     {
         # Initialize array to be returned
         $retcontexts = array();
@@ -58,7 +58,7 @@ class Shout_Driver {
         }
 
         # Collect the master list of contexts from the backend
-        $contexts = $this->_getContexts($filter);
+        $contexts = $this->_getContexts($filters);
 
 
         # Narrow down the list of contexts to those valid for this user.
@@ -127,7 +127,35 @@ class Shout_Driver {
         return $this->_getUsers($context);
     }
     // }}}
-
+    
+    // {{{ getHomeContext method
+    /**
+     * Returns the name of the user's default context
+     *
+     * @return string User's default context
+     */
+    function getHomeContext()
+    {
+        return $this->_getHomeContext();
+    }
+    // }}}
+    
+        // {{{ getExtensions method
+    /**
+     * Get a context's extensions and return as a multi-dimensional associative
+     * array
+     *
+     * @param string $context Context to return extensions for
+     *
+     * @return array Multi-dimensional associative array of extensions data
+     *
+     */
+    function getDialplan($context)
+    {
+        return $this->_getDialplan($context);
+    }
+    // }}}
+    
     // {{{ factory method
     /**
      * Attempts to return a concrete Shout_Driver instance based on
index fc8b9c9..f48a3fb 100644 (file)
@@ -42,29 +42,39 @@ class Shout_Driver_ldap extends Shout_Driver
     *
     * @access private
     */
-    function _getContexts($filter = "all")
+    function _getContexts($filters = "all")
     {
         # TODO Add caching mechanism here.  Possibly cache results per
         # filter $this->contexts['customer'] and return either data
         # or possibly a reference to that data
-        switch ($filter) {
-            case "customer":
-                $searchfilter="(objectClass=vofficeCustomer)";
-                break;
-            case "extensions":
-                $searchfilter="(objectClass=asteriskExtensions)";
-                break;
-            case "moh":
-                $searchfilter="(objectClass=asteriskMusicOnHold)";
-                break;
-            case "conference":
-                $searchfilter="(objectClass=asteriskMeetMe)";
-                break;
-            case "all":
-            default:
-                $searchfilter="";
-                break;
+        if(!is_array($filters)) {
+            $tmp = $filters;
+            $filters = array();
+            $filters[] = $tmp;
         }
+        
+        $searchfilter = "(|";
+        foreach ($filters as $filter) {
+            switch ($filter) {
+                case "customers":
+                    $searchfilter.="(objectClass=vofficeCustomer)";
+                    break;
+                case "extensions":
+                    $searchfilter.="(objectClass=asteriskExtensions)";
+                    break;
+                case "moh":
+                    $searchfilter.="(objectClass=asteriskMusicOnHold)";
+                    break;
+                case "conference":
+                    $searchfilter.="(objectClass=asteriskMeetMe)";
+                    break;
+                case "all":
+                default:
+                    $searchfilter.="(objectClass=*)";
+                    break;
+            }
+        }
+        $searchfilter .= ")";
 
         # Collect all the possible contexts from the backend
         $res = ldap_search($this->_LDAP,
@@ -104,6 +114,9 @@ class Shout_Driver_ldap extends Shout_Driver
      */
     function _checkContextType($context, $type) {
         switch ($type) {
+            case "users":
+                $searchfilter = "(objectClass=vofficeCustomer)";
+                break;
             case "dialplan":
                 $searchfilter = "(objectClass=asteriskExtensions)";
                 break;
@@ -132,7 +145,7 @@ type");
         if (!$res) {
             return PEAR::raiseError("Unable to get results from LDAP query");
         }
-        print_r($res);
+
         if ($res['count'] == 1) {
             return true;
         } else {
@@ -198,6 +211,137 @@ type");
         return $entries;
     }
     // }}}
+    
+    // {{{ _getHomeContext method
+    /**
+     * Returns the name of the user's default context
+     *
+     * @return string User's default context
+     */
+    function _getHomeContext()
+    {
+        $res = ldap_search($this->_LDAP,
+            SHOUT_USERS_BRANCH.','.$this->_params['basedn'],
+            "(&(mail=".Auth::getAuth().")(objectClass=asteriskUser))",
+            array('context'));
+        if (!$res) {
+            return PEAR::raiseError("Unable to locate any customers " .
+            "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn'] .
+            " matching those search filters");
+        }
+
+        $res = ldap_get_entries($this->_LDAP, $res);
+        
+        # Assume the user only has one context.  The schema encforces this
+        return $res[0]['context'][0];
+    }
+    // }}}
+    
+    // {{{ _getDialplan method
+    /**
+     * Get a context's dialplan and return as a multi-dimensional associative
+     * array
+     *
+     * @param string $context Context to return extensions for
+     *
+     * @return array Multi-dimensional associative array of extensions data
+     *
+     */
+    function _getDialplan($context)
+    {
+        $res = ldap_search($this->_LDAP,
+            SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'],
+            "(&(objectClass=asteriskExtensions)(context=$context))",
+            array('asteriskExtensionLine', 'asteriskIncludeLine',
+                'asteriskIgnorePat', 'description',
+                'asteriskExtensionBareLine'));
+        if (!$res) {
+            return PEAR::raiseError("Unable to locate any extensions " .
+            "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn'] .
+            " matching those search filters");
+        }
+
+        $res = ldap_get_entries($this->_LDAP, $res);
+        $retdialplan = array();
+        $i = 0;
+        while ($i < $res['count']) {
+            # Handle extension lines
+            if (isset($res[$i]['asteriskextensionline'])) {
+                $j = 0;
+                while ($j < $res[$i]['asteriskextensionline']['count']) {
+                    @$line = $res[$i]['asteriskextensionline'][$j];
+                    
+                    # Basic sanity check for length.  FIXME
+                    if (strlen($line) < 5) {
+                        break;
+                    }
+                    # Can't use strtok here because there may be ','s in the arg
+                    # string
+                    
+                    # Get the extension
+                    $token1 = strpos($line, ',');
+                    $token2 = strpos($line, ',', $token1 + 1);
+                    
+                    $extension = substr($line, 0, $token1);
+                    if (!isset($retdialplan[$extension])) {
+                        $retdialplan[$extension] = array();
+                    }
+                    $token1++;
+                    # Get the priority
+                    $priority = substr($line, $token1, $token2 - $token1);
+                    $retdialplan[$extension][$priority] = array();
+                    $token2++;
+                    
+                    # Get Application and args
+                    $application = substr($line, $token2);
+                    
+                    # Merge all that data into the returning array
+                    $retdialplan['extensions'][$extension][$priority] =
+                        $application;
+                    $j++;
+                }
+                
+                # Sort the extensions data
+                foreach ($retdialplan['extensions'] as $extension) {
+                    ksort($extension);
+                }
+                ksort($retdialplan['extensions']);
+            }
+            # Handle include lines
+            if (isset($res[$i]['asteriskincludeline'])) {
+                $j = 0;
+                while ($j < $res[$i]['asteriskincludeline']['count']) {
+                    @$line = $res[$i]['asteriskincludeline'][$j];
+                    $retdialplan['include'][$j] = $line;
+                    $j++;
+                }
+            }
+            
+            # Handle ignorepat
+            if (isset($res[$i]['asteriskignorepat'])) {
+                $j = 0;
+                while ($j < $res[$i]['asteriskignorepat']['count']) {
+                    @$line = $res[$i]['asteriskignorepat'][$j];
+                    $retdialplan['include'][$j] = $line;
+                    $j++;
+                }
+            }
+            # Handle ignorepat
+            if (isset($res[$i]['asteriskextensionbareline'])) {
+                $j = 0;
+                while ($j < $res[$i]['asteriskextensionbareline']['count']) {
+                    @$line = $res[$i]['asteriskextensionbareline'][$j];
+                    $retdialplan['bareline'][$j] = $line;
+                    $j++;
+                }
+            }
+            
+            # Increment object
+            $i++;
+        }
+        return $retdialplan;
+    }
+    // }}}
 
     // {{{ getUserPhoneNumbers method
     /**
index 8bb3d70..7088a11 100644 (file)
@@ -76,14 +76,14 @@ null, $cellclass);
         $tabs = &new Horde_UI_Tabs('section', $vars);
         
         if (Shout::checkRights("$permprefix:users") &&
-            $shout->checkContextType($context, "conference")) {
+            $shout->checkContextType($context, "users")) {
             $tabs->addTab(_("Users"),
                     Horde::applicationUrl("index.php?context=$context"),
                     'users');
         }
         
         if (Shout::checkRights("$permprefix:dialplan") &&
-            $shout->checkContextType($context, "conference")) {
+            $shout->checkContextType($context, "dialplan")) {
             $tabs->addTab(_("Dial Plan"),
                 Horde::applicationUrl('index.php'), 'dialplan');
         }
@@ -95,11 +95,16 @@ null, $cellclass);
         }
        
        if (Shout::checkRights("$permprefix:moh") &&
-            $shout->checkContextType($context, "conference")) {
+            $shout->checkContextType($context, "moh")) {
             $tabs->addTab(_("Music on Hold"),
                 Horde::applicationUrl('index.php'), 'moh');
         }
-       
+        
+        if (Auth::isAdmin("shout:superadmin", PERMS_SHOW|PERMS_READ)) {
+            $tabs->addTab(_("Security"),
+                Horde::applicationUrl('index.php'), 'security');
+        }
+
         return $tabs;
     }
 
diff --git a/lib/Users.php b/lib/Users.php
deleted file mode 100644 (file)
index 4ea1419..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
- * SelectContextForm Class
- *
- * $Horde: shout/lib/Users.php,v 1.56 2005/01/03 14:35:44 jan Exp $
- *
- * Copyright 2005 Ben Klang <ben@alkaloid.net>
- *
- * See the enclosed file LICENSE for license information (BSD). If you
- * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
- *
- * @author  Ben Klang <ben@alkaloid.net>
- * @package Whups
- */
-class SelectContextForm extends Horde_Form {
-
-    var $_useFormToken = false;
-
-    function SelectContextForm(&$vars)
-    {
-        global $shout;
-
-        parent::Horde_Form($vars, _("Choose a context"));
-
-        $contexts = $shout->getContexts("customer");
-        if (count($contexts)) {
-            $contexts = &$this->addVariable(_("Context"), 'context', 'enum',
-                true, false, null, array($contexts, _("Choose:")));
-            if (!Auth::getAuth()) {
-                $this->addVariable(_("Your Email Address"), 'user_email',
-                    'email', true);
-            } else {
-                require_once 'Horde/Form/Action.php';
-                $contexts->setAction(Horde_Form_Action::factory('submit'));
-            }
-        } else {
-            $this->addVariable(_("Context"), 'context', 'invalid', true,
-                false, null, array(_("There are no contexts which you have
-permission to view.")));
-        }
-    }
-
-}
\ No newline at end of file
index 9fefa81..5e6292a 100644 (file)
@@ -9,26 +9,26 @@
     <item url="templates/" uploadstatus="2" />
     <item url="lib/" uploadstatus="2" />
     <item url="lib/Driver/" uploadstatus="2" />
-    <item modified_time="1120296144" url="lib/Driver/ldap.php" uploadstatus="2" />
+    <item modified_time="1120357513" url="lib/Driver/ldap.php" uploadstatus="2" />
     <item modified_time="1120268017" url="lib/base.php" uploadstatus="2" />
-    <item modified_time="1120293699" url="lib/Driver.php" uploadstatus="2" />
-    <item modified_time="1120183942" url="contexts.php" uploadstatus="2" />
-    <item modified_time="1120294641" url="index.php" uploadstatus="2" />
+    <item modified_time="1120357486" url="lib/Driver.php" uploadstatus="2" />
+    <item modified_time="1120357642" url="index.php" uploadstatus="2" />
     <uploadprofiles showtreeviews="true" defaultProfile="Shout" >
       <profile remote_host="picasso.v-office.biz" remote_port="" remote_path="/srv/vhost/users/aklang/sites/intranet.v-office.biz/shout" remote_protocol="sftp" user="aklang" name="Shout" >
         <uploadeditem upload_time="0" url="config/" />
         <uploadeditem upload_time="1120073766" url="config/conf.xml" />
         <uploadeditem upload_time="1120183942" url="contexts.php" />
-        <uploadeditem upload_time="1120294641" url="index.php" />
+        <uploadeditem upload_time="1120355053" url="dialplan.php" />
+        <uploadeditem upload_time="1120357642" url="index.php" />
         <uploadeditem upload_time="1120021874" url="index.php~" />
         <uploadeditem upload_time="0" url="lib/" />
-        <uploadeditem upload_time="1120293699" url="lib/Driver.php" />
+        <uploadeditem upload_time="1120357486" url="lib/Driver.php" />
         <uploadeditem upload_time="1120022560" url="lib/Driver.php~" />
         <uploadeditem upload_time="0" url="lib/Driver/" />
-        <uploadeditem upload_time="1120296144" url="lib/Driver/ldap.php" />
+        <uploadeditem upload_time="1120357513" url="lib/Driver/ldap.php" />
         <uploadeditem upload_time="1120026921" url="lib/Driver/ldap.php~" />
         <uploadeditem upload_time="1120288491" url="lib/SelectContext.php" />
-        <uploadeditem upload_time="1120294951" url="lib/Shout.php" />
+        <uploadeditem upload_time="1120357628" url="lib/Shout.php" />
         <uploadeditem upload_time="1120279975" url="lib/Users.php" />
         <uploadeditem upload_time="1120268017" url="lib/base.php" />
         <uploadeditem upload_time="1120073766" url="lib/defines.php" />
         <uploadeditem upload_time="1120073766" url="templates/content_page" />
         <uploadeditem upload_time="0" url="templates/context/" />
         <uploadeditem upload_time="1120175005" url="templates/context/contextline.inc" />
-        <uploadeditem upload_time="1120293059" url="templates/menu.inc" />
-        <uploadeditem upload_time="1120294295" url="users.php" />
+        <uploadeditem upload_time="0" url="templates/dialplan/" />
+        <uploadeditem upload_time="1120377494" url="templates/dialplan/dialplanlist.inc" />
+        <uploadeditem upload_time="1120357382" url="templates/menu.inc" />
+        <uploadeditem upload_time="0" url="templates/users/" />
+        <uploadeditem upload_time="1120378861" url="templates/users/userlist.inc" />
+        <uploadeditem upload_time="1120355014" url="users.php" />
       </profile>
     </uploadprofiles>
     <debuggers>
@@ -61,7 +65,7 @@
     <defaultDTD>-//w3c//dtd xhtml 1.0 strict//en</defaultDTD>
     <item modified_time="1120073766" url="config/conf.xml" uploadstatus="1" />
     <item url="config/" uploadstatus="1" />
-    <item modified_time="1120294951" url="lib/Shout.php" uploadstatus="1" />
+    <item modified_time="1120357628" url="lib/Shout.php" uploadstatus="1" />
     <author>Ben Klang</author>
     <email>ben@alkaloid.net</email>
     <debuggerclient>Gubed</debuggerclient>
     </teamdata>
     <events/>
     <item modified_time="1120174958" url="templates/common-header.inc" uploadstatus="1" />
-    <item modified_time="1120293059" url="templates/menu.inc" uploadstatus="1" />
-    <item modified_time="1120294295" url="users.php" uploadstatus="1" />
+    <item modified_time="1120357382" url="templates/menu.inc" uploadstatus="1" />
+    <item modified_time="1120355014" url="users.php" uploadstatus="1" />
     <item url="templates/context/" uploadstatus="1" />
     <item modified_time="1120175005" url="templates/context/contextline.inc" uploadstatus="1" />
-    <item modified_time="1120287842" url="moh.php" />
-    <item modified_time="1120288491" url="lib/SelectContext.php" />
+    <item modified_time="1120287842" url="moh.php" uploadstatus="1" />
+    <item url="templates/users/" uploadstatus="1" />
+    <item modified_time="1120378861" url="templates/users/userlist.inc" uploadstatus="1" />
+    <item modified_time="1120355053" url="dialplan.php" uploadstatus="1" />
+    <item modified_time="1120377494" url="templates/dialplan/dialplanlist.inc" uploadstatus="1" />
+    <item url="templates/dialplan/" uploadstatus="1" />
     <treestatus>
       <openfolder url="lib" />
       <openfolder url="lib/Driver" />
       <openfolder url="templates" />
       <openfolder url="templates/context" />
+      <openfolder url="templates/dialplan" />
+      <openfolder url="templates/users" />
     </treestatus>
   </project>
 </webproject>
index 6a89e52..8e15fa8 100644 (file)
@@ -12,7 +12,7 @@ $menu_view = $prefs->getValue('menu_view');
    <label for="context" accesskey="<?php echo $accesskey ?>">
     <select id="context" name="context" onchange="contextSubmit()">
      <?php
-        foreach ($shout->getContexts() as $item) {
+        foreach ($shout->getContexts("customers") as $item) {
             print "<option name=\"$item\"";
             if ($item == $context) {
                 print " selected";
index ea7461f..8b2b6f4 100644 (file)
--- a/users.php
+++ b/users.php
@@ -3,15 +3,4 @@ if (!defined(SHOUT_BASE)) {
     define(SHOUT_BASE, dirname(__FILE__));
 }
 
-// # Check that we are properly initialized
-// if (is_a($contexts, 'PEAR_Error')) {
-//     # FIXME change this to a Horde::fatal
-//     $notification->push(_("Internal error viewing requested page"),
-//                         'horde.error');
-//     $notification->notify();
-//     require $registry->get('templates', 'horde') . '/common-footer.inc';
-//     exit();
-// }
-// 
-// 
-// print_r($shout->getUsers($context));
\ No newline at end of file
+require SHOUT_TEMPLATES . "/users/userlist.inc";
\ No newline at end of file