From 462c1665d9b0e6df28c0891cd1f27fb87032b344 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Sun, 16 Jul 2006 02:19:26 +0000 Subject: [PATCH] Refactoring code to be more Horde-ish git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@372 06cd67b6-e706-0410-b29e-9de616bca6e9 --- index.php | 59 +++++++++--------------------------------------- lib/Driver/ldap.php | 31 +++++-------------------- lib/Shout.php | 65 ++++++++++++++++++++++++++--------------------------- lib/api.php | 7 +++--- lib/base.php | 36 ++++++++++++++++++++++++----- usermgr.php | 43 ++++++++++++++++++++--------------- usermgr/list.php | 3 --- 7 files changed, 105 insertions(+), 139 deletions(-) diff --git a/index.php b/index.php index c3c668ceb..74f7aead1 100644 --- a/index.php +++ b/index.php @@ -11,54 +11,15 @@ */ @define('SHOUT_BASE', dirname(__FILE__)); -require_once SHOUT_BASE . '/lib/base.php'; -require_once SHOUT_BASE . '/lib/Shout.php'; - -// Variable handling libraries -require_once 'Horde/Variables.php'; -require_once 'Horde/Text/Filter.php'; - -$context = Util::getFormData("context"); -$section = Util::getFormData("section"); - -$contexts = &$shout->getContexts(); -# Check that we are properly initialized -if (is_a($contexts, 'PEAR_Error')) { - $notification->push($contexts, 'horde.error'); - $contexts = false; -} elseif (count($contexts) == 1) { - # Default to the user's only context - $context = $contexts[0]; -} elseif (!$context) { - # Attempt to locate the user's "home" context - $context = $shout->getHomeContext(); - if (is_a($context, 'PEAR_Error')) { - $notification->push($context); - } - $context = ''; -} - -$vars = &Variables::getDefaultVariables(); -$tabs = &Shout::getTabs($context, $vars); -$tabs->preserve('context', $context); - -switch ($section) { - case "conference": - case "dialplan": - case "security": - case "usermgr": - case "moh": - break; - default: - $section = $tabs->_tabs[0]['tabname']; - break; +$shout_configured = (is_readable(SHOUT_BASE . '/config/conf.php') && + is_readable(SHOUT_BASE . '/config/applist.xml') && + is_readable(SHOUT_BASE . '/config/defines.php')); + +if (!$shout_configured) { +require SHOUT_BASE . '/../lib/Test.php'; + Horde_Test::configFilesMissing('Shout', SHOUT_BASE, + array('conf.php', 'applist.xml', 'defines.php')); } -# We've passed the initialization tests. This flag allows other pages to run. -$SHOUT_RUNNING = true; - -require SHOUT_BASE . "/$section.php"; -#print '
'; - -#print '
'; -require $registry->get('templates', 'horde') . '/common-footer.inc'; +require_once SHOUT_BASE . '/lib/base.php'; +header('Location: ' . Horde::applicationUrl('usermgr.php')); diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index 0bcabc850..8dfe2a87c 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -3,13 +3,11 @@ # Make Shout methods available require_once SHOUT_BASE . '/lib/Shout.php'; -// {{{ Shout_Driver_ldap class class Shout_Driver_ldap extends Shout_Driver { var $_ldapKey; // Index used for storing objects var $_appKey; // Index used for moving info to/from the app - // {{{ Class local variables /** * Handle for the current database connection. * @var object LDAP $_LDAP @@ -23,9 +21,7 @@ class Shout_Driver_ldap extends Shout_Driver */ var $_connected = false; - // }}} - // {{{ Shout_Driver_ldap constructor /** * Constructs a new Shout LDAP driver object. * @@ -73,9 +69,7 @@ class Shout_Driver_ldap extends Shout_Driver break; } } - // }}} - // {{{ getContexts method /** * Get a list of contexts from the backend * @@ -174,9 +168,7 @@ class Shout_Driver_ldap extends Shout_Driver # return the array return $entries[$searchfilters]; } - // }}} - // {{{ checkContextType method /** * For the given context and type, make sure the context has the * appropriate properties, that it is effectively of that "type" @@ -229,9 +221,7 @@ type"); return false; } } - // }}} - // {{{ getUsers method /** * Get a list of users valid for the contexts * @@ -239,7 +229,7 @@ type"); * * @return array User information indexed by voice mailbox number */ - function &getUsers($context) + function getUsers($context) { static $entries = array(); @@ -334,9 +324,7 @@ type"); return($entries[$context]); } - // }}} - // {{{ getHomeContext method /** * Returns the name of the user's default context * @@ -366,9 +354,11 @@ type"); # Assume the user only has one context. The schema enforces this # FIXME: Handle cases where the managing user isn't a valid telephone # system user - # FIXME: Handle cases where no attribute is found? + # FIXME: Do we want to warn? If so, how? This PEAR::Error shows up + # in unfavorable places (ie. perms screen) if ($res['count'] != 1) { - return PEAR::raiseError(_("Unable to determine default context")); + //return PEAR::raiseError(_("Unable to determine default context")); + return ''; } return $res[0]['context'][0]; } @@ -421,9 +411,7 @@ for $context")); } return $properties; } - // }}} - // {{{ getDialplan method /** * Get a context's dialplan and return as a multi-dimensional associative * array @@ -554,9 +542,7 @@ 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 @@ -686,9 +672,7 @@ for $context")); return $cachedlimits[$context]; } } - // }}} - // {{{ /** * Save a user to the LDAP tree * @@ -859,9 +843,7 @@ for $context")); # We must have been successful return true; } - // }}} - // {{{ deleteUser method /** * Deletes a user from the LDAP tree * @@ -896,7 +878,6 @@ for $context")); } return true; } - // }}} /* Needed because uksort can't take a classed function as its callback arg */ @@ -908,7 +889,6 @@ for $context")); return $ret; } - // {{{ connect method /** * Attempts to open a connection to the LDAP server. * @@ -949,5 +929,4 @@ Check authentication credentials."); } return true; } - // }}} } diff --git a/lib/Shout.php b/lib/Shout.php index 2021e4255..199a03577 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -16,14 +16,12 @@ */ require_once SHOUT_BASE . "/config/defines.php"; -// {{{ Class Shout class Shout { var $applist = array(); var $_applist_curapp = ''; var $_applist_curfield = ''; - // {{{ getMenu method /** * Build Shout's list of menu items. * @@ -86,9 +84,7 @@ class Shout return $menu->render(); } } - // }}} - // {{{ /** * Generate the tabs at the top of each Shout pages * @@ -96,52 +92,55 @@ class Shout * * @return object Horde_UI_Tabs */ - function &getTabs($context, &$vars) + function getTabs($context, &$vars) { global $shout; - # FIXME Is this right? - if (!Auth::isAdmin("shout", PERMS_SHOW|PERMS_READ)) { - return false; - } - $permprefix = "shout:contexts:$context"; + $permprefix = 'shout:contexts:' . $context; $tabs = &new Horde_UI_Tabs('section', $vars); - if (Shout::checkRights("$permprefix:users", null, 1) && - $shout->checkContextType($context, "users")) { - $tabs->addTab(_("User Manager"), - Horde::applicationUrl("index.php?context=$context"), - 'usermgr'); + if (Shout::checkRights($permprefix . ':users', null, 1) && + $shout->checkContextType($context, 'users')) { + + $url = Horde::applicationUrl('usermgr.php'); + $url = Util::addParameter($url, 'context', $context); + $tabs->addTab(_("_User Manager"), $url, 'usermgr'); } - if (Shout::checkRights("$permprefix:dialplan", null, 1) && - $shout->checkContextType($context, "dialplan")) { - $tabs->addTab(_("Dial Plan"), - Horde::applicationUrl('index.php'), 'dialplan'); + if (Shout::checkRights($permprefix . ':dialplan', null, 1) && + $shout->checkContextType($context, 'dialplan')) { + + $url = Horde::applicationUrl('dialplan.php'); + $url = Util::addParameter($url, 'context', $context); + $tabs->addTab(_("_Dial Plan"), $url, 'dialplan'); } - if (Shout::checkRights("$permprefix:conference", null, 1) && - $shout->checkContextType($context, "conference")) { - $tabs->addTab(_("Conference Rooms"), - Horde::applicationUrl('index.php'), 'conference'); + if (Shout::checkRights($permprefix . ':conference', null, 1) && + $shout->checkContextType($context, 'conference')) { + + $url = Horde::applicationUrl('conference.php'); + $url = Util::addParameter($url, 'context', $context); + $tabs->addTab(_("_Conference Rooms"), $url, 'conference'); } - if (Shout::checkRights("$permprefix:moh", null, 1) && + if (Shout::checkRights($permprefix . ':moh', null, 1) && $shout->checkContextType($context, "moh")) { - $tabs->addTab(_("Music on Hold"), - Horde::applicationUrl('index.php'), 'moh'); + + $url = Horde::applicationUrl('moh.php'); + $url = Util::addParameter($url, 'context', $context); + $tabs->addTab(_("_Music on Hold"), $url, 'moh'); } - if (Auth::isAdmin("shout:superadmin", PERMS_SHOW|PERMS_READ)) { - $tabs->addTab(_("Security"), - Horde::applicationUrl('index.php'), 'security'); + if (Perms::hasPermission('shout:superadmin', Auth::getAuth(), PERMS_SHOW|PERMS_READ)) { + $url = Horde::applicationUrl('security.php'); + $url = Util::addParameter($url, 'context', $context); + $tabs->addTab(_("_Security"), $url, 'security'); } return $tabs; } - // {{{ /** * Checks for the given permissions for the current user on the given * permission. Optionally check for higher-level permissions and ultimately @@ -169,7 +168,7 @@ class Shout $user = 0; $superadmin = 0; - $superadmin = $perms->hasPermission("shout:superadmin", + $superadmin = $perms->hasPermission('shout:superadmin', Auth::getAuth(), $permmask); while ($numparents >= 0) { @@ -186,9 +185,10 @@ class Shout $numparents--; } $test = $superadmin | $user; +$ret = ($test & $permmask) == $permmask; +print "Shout::checkRights() returning $ret"; return ($test & $permmask) == $permmask; } - // }}} function getContextTypes() { @@ -400,4 +400,3 @@ class Shout } } } -// }}} \ No newline at end of file diff --git a/lib/api.php b/lib/api.php index 906cc74e6..ce6d59f23 100644 --- a/lib/api.php +++ b/lib/api.php @@ -34,7 +34,7 @@ function _shout_perms() $perms['tree']['shout']['superadmin'] = false; $perms['title']['shout:superadmin'] = _("Super Administrator"); - $contexts = $GLOBALS['shout']->getContexts(); + $contexts = $shout->getContexts(); $perms['tree']['shout']['contexts'] = false; $perms['title']['shout:contexts'] = _("Contexts"); @@ -57,11 +57,10 @@ function _shout_perms() } } - // function _shout_getContexts($searchfilters = SHOUT_CONTEXT_ALL, // $filterperms = null) - + return $perms; } function _shout_attributes() @@ -128,4 +127,4 @@ function _shout_attributes() ); return $shoutAttributes; -} \ No newline at end of file +} diff --git a/lib/base.php b/lib/base.php index 2918ecdae..bdfd9a354 100644 --- a/lib/base.php +++ b/lib/base.php @@ -53,17 +53,41 @@ require_once SHOUT_BASE . '/lib/Shout.php'; require_once SHOUT_BASE . '/lib/Driver.php'; // Form libraries. -// require_once 'Horde/Form.php'; -// require_once 'Horde/Form/Renderer.php'; +require_once 'Horde/Form.php'; +require_once 'Horde/Form/Renderer.php'; // Variable handling libraries -// require_once 'Horde/Variables.php'; -// require_once 'Horde/Text/Filter.php'; +require_once 'Horde/Variables.php'; +require_once 'Horde/Text/Filter.php'; // UI classes. require_once 'Horde/UI/Tabs.php'; -$GLOBALS['shout'] = &Shout_Driver::singleton(); +$shout = Shout_Driver::singleton(); // Horde libraries. -require_once 'Horde/Help.php'; \ No newline at end of file +require_once 'Horde/Help.php'; + +$context = Util::getFormData('context'); +$section = Util::getFormData('section'); + +$contexts = $shout->getContexts(); + +// Check that we are properly initialized +if (is_a($contexts, 'PEAR_Error')) { + $notification->push($contexts); + $contexts = false; +} elseif (count($contexts) == 1) { + // Default to the user's only context + $context = $contexts[0]; +} elseif (!$context) { + // Attempt to locate the user's "home" context + $context = $shout->getHomeContext(); + if (is_a($context, 'PEAR_Error')) { + $notification->push($context); + } + $context = ''; +} + +// We've passed the initialization tests. This flag allows other pages to run. +$SHOUT_RUNNING = true; diff --git a/usermgr.php b/usermgr.php index 6bb17299e..a01f94a0f 100644 --- a/usermgr.php +++ b/usermgr.php @@ -7,45 +7,52 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. */ +@define('SHOUT_BASE', dirname(__FILE__)); +require_once SHOUT_BASE . '/lib/base.php'; +require_once SHOUT_BASE . '/lib/Shout.php'; if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { + # FIXME! This needs to redirect somewhere more sensical header('Location: /'); exit(); } -// Form libraries. -require_once 'Horde/Form.php'; -require_once 'Horde/Form/Renderer.php'; +$action = Util::getFormData('action'); +$extension = Util::getFormData('extension'); -$action = Util::getFormData("action"); -$extension = Util::getFormData("extension"); +$vars = Variables::getDefaultVariables(); +$tabs = Shout::getTabs($context, $vars); +$tabs->preserve('context', $context); + +$section = 'usermgr'; $title = _("User Manager: "); + switch ($action) { - case "add": + case 'add': $title .= _("Add User"); # Treat adds just like an empty edit - $action = "edit"; + $action = 'edit'; $extension = 0; break; - case "edit": - $title .= _("Edit User (Extension ") . "$extension)"; + case 'edit': + $title .= sprintf(_("Edit User (Extension %s)"), $extension); break; - case "save": - $title .= _("Save User (Extension ") . "$extension)"; + case 'save': + $title .= sprintf(_("Save User (Extension %s)"), $extension); break; - case "delete": - $title .= _("Delete User (Extension ") . "$extension)"; + case 'delete': + $title .= sprintf(_("Delete User (Extension %s)"), $extension); break; - case "list": + case 'list': default: $title .= _("List Users"); - $action = "list"; + $action = 'list'; break; } - +require SHOUT_BASE . '/usermgr/' . $action . '.php'; require SHOUT_TEMPLATES . '/common-header.inc'; require SHOUT_TEMPLATES . '/menu.inc'; @@ -54,6 +61,6 @@ $notification->notify(); echo $tabs->render($section); -require SHOUT_BASE . "/usermgr/$action.php"; +require SHOUT_TEMPLATES . '/usermgr/' . $action . '.inc'; -require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file +require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/usermgr/list.php b/usermgr/list.php index c0d2efcbf..45cfc22c4 100644 --- a/usermgr/list.php +++ b/usermgr/list.php @@ -16,6 +16,3 @@ if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { } $users = &$shout->getUsers($context); -ksort($users); -$notification->notify(); -require SHOUT_TEMPLATES . "/users/userlist.inc"; \ No newline at end of file -- 2.11.0