From: Ben Klang Date: Mon, 4 Jul 2005 05:51:38 +0000 (+0000) Subject: A number of changes aimed at integrating more closely with Mandy's development X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0aa099ae69021f68b278cae710d72858c9e7edf7;p=horde.git A number of changes aimed at integrating more closely with Mandy's development git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@46 06cd67b6-e706-0410-b29e-9de616bca6e9 --- diff --git a/contexts.php b/contexts.php deleted file mode 100644 index d9c7299be..000000000 --- a/contexts.php +++ /dev/null @@ -1,29 +0,0 @@ -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]§ion=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 diff --git a/index.php b/index.php index 676ed50b6..b1e6d0e61 100644 --- 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 "
"; +// 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"; diff --git a/lib/Driver.php b/lib/Driver.php index 68d3d462b..538c044a7 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -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 diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index fc8b9c97a..f48a3fbbc 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -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 /** diff --git a/lib/Shout.php b/lib/Shout.php index 8bb3d707e..7088a11d6 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -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 index 4ea141994..000000000 --- a/lib/Users.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * 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 - * @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 diff --git a/shout.webprj b/shout.webprj index 9fefa8166..5e6292acb 100644 --- a/shout.webprj +++ b/shout.webprj @@ -9,26 +9,26 @@ - + - - - + + - + + - + - + - + @@ -39,8 +39,12 @@ - - + + + + + + @@ -61,7 +65,7 @@ -//w3c//dtd xhtml 1.0 strict//en - + Ben Klang ben@alkaloid.net Gubed @@ -73,17 +77,23 @@ - - + + - - + + + + + + + + diff --git a/templates/menu.inc b/templates/menu.inc index 6a89e5204..8e15fa842 100644 --- a/templates/menu.inc +++ b/templates/menu.inc @@ -12,7 +12,7 @@ $menu_view = $prefs->getValue('menu_view');