From 4b850f0de6cd3cb0852b08a60d769a49b31a991d Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Sat, 2 Jul 2005 09:28:37 +0000 Subject: [PATCH] First commit using the new interface that Mandy helped design. Most of the permissions and front-end selection work, but there's still a wierd bug in the LDAP check for context type. Next job is to generate tabular content. Yay! git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@45 06cd67b6-e706-0410-b29e-9de616bca6e9 --- index.php | 49 ++++++++-------------------------- lib/Driver.php | 64 ++++++++++++++++++++++++++++++-------------- lib/Driver/ldap.php | 62 +++++++++++++++++++++++++++++++++++++++++-- lib/Shout.php | 57 ++++++++++++++++++++++++++++++---------- moh.php | 15 +++++++++++ templates/menu.inc | 59 ++++++++++++++++++++++++++++++++++++++--- users.php | 76 +++++++++-------------------------------------------- 7 files changed, 241 insertions(+), 141 deletions(-) create mode 100644 moh.php diff --git a/index.php b/index.php index 9b90c09c8..676ed50b6 100644 --- a/index.php +++ b/index.php @@ -30,58 +30,31 @@ $contexts = $shout->getContexts(); $vars = &Variables::getDefaultVariables(); #$ticket->setDetails($vars); +if (count($contexts) == 1) { + $context = $contexts[0]; +} + #$title = '[#' . $ticket->getId() . '] ' . $ticket->get('summary'); require SHOUT_TEMPLATES . '/common-header.inc'; require SHOUT_TEMPLATES . '/menu.inc'; -$tabs = &Shout::getTabs($vars); +$tabs = &Shout::getTabs($context, $vars); $tabs->preserve('context', $context); -echo $tabs->render(); +echo "
"; +echo $tabs->render($section); switch ($section) { - case "contexts": - require "contexts.php"; - break; - + case "conference": + case "dialplan": case "users": - require "users.php"; - break; - case "moh": - require "moh.php"; - break; - - case "global": - require "global.php"; + require "$section.php"; break; default: break; } -// $form = &new TicketDetailsForm($vars); -// $form->addAttributes($whups->getAllTicketAttributesWithNames( -// $ticket->getId())); -// -// $RENDERER = &new Horde_Form_Renderer(); -// $RENDERER->beginInactive($title); -// $RENDERER->renderFormInactive($form, $vars); -// $RENDERER->end(); -// -// echo '
'; -// -// $COMMENT = &new Comment(); -// $COMMENT->begin(_("History")); -// $history = Whups::permissionsFilter($whups->getHistory($ticket->getId()), -// 'comment', PERMS_READ); -// $chtml = array(); -// foreach ($history as $comment_values) { -// $chtml[] = $COMMENT->render(new Variables($comment_values)); -// } -// if ($prefs->getValue('comment_sort_dir')) { -// $chtml = array_reverse($chtml); -// } -// echo implode('', $chtml); -// $COMMENT->end(); + require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/lib/Driver.php b/lib/Driver.php index 1f0ef73b3..68d3d462b 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -62,32 +62,56 @@ class Shout_Driver { # Narrow down the list of contexts to those valid for this user. - global $perms; - - $superadminPermName = "shout:superadmin"; - if ($perms->exists($superadminPermName)) { - $superadmin = $perms->getPermissions($superadminPermName) & - ($filterperms); - } else { - $superadmin = 0; - } - - foreach($contexts as $context) { - $permName = "shout:contexts:".$context; - if ($perms->exists($permName)) { - $userperms = $perms->getPermissions($permName) & - ($filterperms); - } else { - $userperms = 0; - } - - if ((($userperms | $superadmin) ^ ($filterperms)) == 0) { +// global $perms; +// +// $superadminPermName = "shout:superadmin"; +// if ($perms->exists($superadminPermName)) { +// $superadmin = $perms->getPermissions($superadminPermName) & +// ($filterperms); +// } else { +// $superadmin = 0; +// } +// +// foreach($contexts as $context) { +// $permName = "shout:contexts:".$context; +// if ($perms->exists($permName)) { +// $userperms = $perms->getPermissions($permName) & +// ($filterperms); +// } else { +// $userperms = 0; +// } +// +// if ((($userperms | $superadmin) ^ ($filterperms)) == 0) { +// $retcontexts[$context] = $context; +// } +// } + foreach ($contexts as $context) { + if (Shout::checkRights("shout:contexts:$context", $filterperms)) { $retcontexts[] = $context; } } return $retcontexts; } // }}} + + // {{{ checkContextType + /** + * For the given context and type, make sure the context has the + * appropriate properties, that it is effectively of that "type" + * + * @param string $context the context to check type for + * + * @param string $type the type to verify the context is of + * + * @return boolean true of the context is of type, false if not + * + * @access public + */ + function checkContextType($context, $type) + { + return $this->_checkContextType($context, $type); + } + //}}} // {{{ /** diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index 4ca2bfc5a..fc8b9c97a 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -51,8 +51,14 @@ class Shout_Driver_ldap extends Shout_Driver case "customer": $searchfilter="(objectClass=vofficeCustomer)"; break; - case "system": - $searchfilter="(!(objectClass=vofficeCustomer))"; + case "extensions": + $searchfilter="(objectClass=asteriskExtensions)"; + break; + case "moh": + $searchfilter="(objectClass=asteriskMusicOnHold)"; + break; + case "conference": + $searchfilter="(objectClass=asteriskMeetMe)"; break; case "all": default: @@ -82,6 +88,58 @@ class Shout_Driver_ldap extends Shout_Driver return $entries; } // }}} + + // {{{ _checkContextType method + /** + * For the given context and type, make sure the context has the + * appropriate properties, that it is effectively of that "type" + * + * @param string $context the context to check type for + * + * @param string $type the type to verify the context is of + * + * @return boolean true of the context is of type, false if not + * + * @access public + */ + function _checkContextType($context, $type) { + switch ($type) { + case "dialplan": + $searchfilter = "(objectClass=asteriskExtensions)"; + break; + case "moh": + $searchfilter="(objectClass=asteriskMusicOnHold)"; + break; + case "conference": + $searchfilter="(objectClass=asteriskMeetMe)"; + break; + case "all": + default: + $searchfilter=""; + break; + } + + $res = ldap_search($this->_LDAP, + SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], + "(&(objectClass=asteriskObject)$searchfilter(context=$context))", + array("context")); + if (!$res) { + return PEAR::raiseError("Unable to search directory for context +type"); + } + + $res = ldap_get_entries($this->_LDAP, $res); + if (!$res) { + return PEAR::raiseError("Unable to get results from LDAP query"); + } + print_r($res); + if ($res['count'] == 1) { + return true; + } else { + return false; + } + } + // }}} // {{{ _getUsers method /** diff --git a/lib/Shout.php b/lib/Shout.php index ed4bc43ef..8bb3d707e 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -64,30 +64,59 @@ null, $cellclass); * * @return object Horde_UI_Tabs */ - function &getTabs(&$vars) + function &getTabs($context, &$vars) { global $shout; if (!Auth::isAdmin("shout", PERMS_SHOW|PERMS_READ)) { return false; } + + $permprefix = "shout:contexts:$context"; + $tabs = &new Horde_UI_Tabs('section', $vars); - if (count($shout->getContexts()) > 1 || - Auth::isAdmin("shout:superadmin", PERMS_SHOW|PERMS_READ)) { - $tabs->addTab(_("Contexts"), - Horde::applicationUrl('index.php'), 'contexts'); + + if (Shout::checkRights("$permprefix:users") && + $shout->checkContextType($context, "conference")) { + $tabs->addTab(_("Users"), + Horde::applicationUrl("index.php?context=$context"), + 'users'); } - $tabs->addTab(_("Users"), - Horde::applicationUrl('index.php'), 'users'); - $tabs->addTab(_("Music on Hold"), - Horde::applicationUrl('index.php'), 'moh'); - // $tabs->addTab(_("Watch"), Horde::applicationUrl('ticket/watch.php')); - if (Auth::isAdmin('shout:superadmin', PERMS_READ|PERMS_SHOW)) { - $tabs->addTab(_("Global Settings"), - Horde::applicationUrl('index.php'), 'global'); + + if (Shout::checkRights("$permprefix:dialplan") && + $shout->checkContextType($context, "conference")) { + $tabs->addTab(_("Dial Plan"), + Horde::applicationUrl('index.php'), 'dialplan'); } - + + if (Shout::checkRights("$permprefix:conference") && + $shout->checkContextType($context, "conference")) { + $tabs->addTab(_("Conference Rooms"), + Horde::applicationUrl('index.php'), 'conference'); + } + + if (Shout::checkRights("$permprefix:moh") && + $shout->checkContextType($context, "conference")) { + $tabs->addTab(_("Music on Hold"), + Horde::applicationUrl('index.php'), 'moh'); + } + return $tabs; } + function checkRights($permname, $permmask = null) + { + if ($permmask == null) { + $permmask = PERMS_SHOW|PERMS_READ; + } + + $superadmin = Auth::isAdmin("shout:superadmin", $permmask); + $user = Auth::isAdmin($permname, $permmask); + $test = $superadmin | $user; + if ($test) { + return TRUE; + } else { + return FALSE; + } + } } // }}} \ No newline at end of file diff --git a/moh.php b/moh.php new file mode 100644 index 000000000..7d684e4e9 --- /dev/null +++ b/moh.php @@ -0,0 +1,15 @@ +push(_("Internal error viewing requested page"), + 'horde.error'); + $notification->notify(); + require $registry->get('templates', 'horde') . '/common-footer.inc'; + exit(); +} + diff --git a/templates/menu.inc b/templates/menu.inc index 5c38df53d..6a89e5204 100644 --- a/templates/menu.inc +++ b/templates/menu.inc @@ -1,5 +1,58 @@ +getValue('widget_accesskey') ? + Horde::getAccessKey(_("Select _Context")) : ''; +$menu_view = $prefs->getValue('menu_view'); +?> + -
-notify(array('listeners' => 'status')) ?> \ No newline at end of file + + + + + diff --git a/users.php b/users.php index 33972a24c..ea7461fae 100644 --- a/users.php +++ b/users.php @@ -3,67 +3,15 @@ if (!defined(SHOUT_BASE)) { define(SHOUT_BASE, dirname(__FILE__)); } -# Check that we are properly initialized -if (is_a($contexts, 'PEAR_Error')) { - $notification->push(_("Internal error viewing requested page"), - 'horde.error'); - $notification->notify(); - require $registry->get('templates', 'horde') . '/common-footer.inc'; - exit(); -} - -if (($context != "") && !in_array($context, $contexts)) { - $notification->push("You do not have permission to access this system.", - 'horde.error'); - $notification->notify(); - require $registry->get('templates', 'horde') . '/common-footer.inc'; - exit(); -} - -require_once SHOUT_BASE . "/lib/Users.php"; - -$RENDERER = &new Horde_Form_Renderer(); -$empty = ''; -$vars = &Variables::getDefaultVariables($empty); -$formname = $vars->get('formname'); - -$title = "Users"; - -$contexts = $shout->getContexts("customer"); - -if (count($contexts) < 1) { - # We should never get here except by malformed request - # (intentional or otherwise) - $notification->push(_("Internal error viewing requested page"), - 'horde.error'); - $notification->notify(); - require $registry->get('templates', 'horde') . '/common-footer.inc'; - exit(); -} - -if (count($contexts) > 1) { - # User is allowed to view more than one context. Prompt him - # for the context to view - - $form = &Horde_Form::singleton('SelectContextForm', $vars); - $valid = $form->validate($vars, true); - /* - if ($valid) { - } else {*/ - if ($formname != 'selectcontext') { - $form->clearValidation(); - } - $form->open($RENDERER, $vars, 'users.php', 'post'); - $RENDERER->beginActive($form->getTitle()); - $RENDERER->renderFormActive($form, $vars); - $RENDERER->submit(); - $RENDERER->end(); - $form->close($RENDERER); - // } -} else { - # Based on the logic above, count($contexts) must == 1 - # Force the user to veiw that context - $context = $contexts[0]; -} - -print_r($shout->getUsers($context)); \ No newline at end of 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 -- 2.11.0