From: Ben Klang Date: Thu, 26 Jan 2006 23:39:22 +0000 (+0000) Subject: Minor code restructuring taking the Horde lessons I've learned into account. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a39657af69d6d51bec1a90057939cd6763f11b1d;p=horde.git Minor code restructuring taking the Horde lessons I've learned into account. Will be branching the code soon so this can become the first "beta" release. git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@266 06cd67b6-e706-0410-b29e-9de616bca6e9 --- diff --git a/andrew.session b/andrew.session index a4a82b2fe..263f3d91e 100644 --- a/andrew.session +++ b/andrew.session @@ -60,62 +60,73 @@ - - + + + - - + + - - + + - - - - - - - + + + + + + + + - + - + + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - + + + + + + + + + - - - - + + + + + + @@ -124,6 +135,7 @@ + diff --git a/andrew.webprj b/andrew.webprj index fffd348d2..d31d03d4e 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -4,51 +4,42 @@ -//w3c//dtd xhtml 1.0 strict//en - + - + - - - - - - - + + + + + + + - - - - + - + - - - - + + + + - - - - - - + + + + + + - - - - - - - - - - - + + + + + @@ -111,12 +102,12 @@ templates/ toolbars/ - - - + + + - - + + @@ -139,6 +130,14 @@ - + + + + + + + + + diff --git a/config/conf.xml b/config/conf.xml index 2e0a5033a..b09984d73 100644 --- a/config/conf.xml +++ b/config/conf.xml @@ -2,13 +2,12 @@ - + Shout Storage - + - + authenticating users to Horde?">ldap + * Copyright 2005-2006 Ben Klang * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @package shout */ -@define('SHOUT_BASE', dirname(__FILE__)); -# FIXME Need a cleaner script prologue... probably all we need to do is check -# for some kind of sane startup vars and otherwise redirect to '/' -# This standard prologue should be consistent across every file that ends in .php -$shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php'));# && - #@is_readable(SHOUT_BASE . '/config/prefs.php')); -if (!$shout_configured) { - require SHOUT_BASE . '/../lib/Test.php'; - Horde_Test::configFilesMissing('Shout', SHOUT_BASE, - array('conf.php', 'prefs.php')); +if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { + header('Location: /'); + exit(); } -require_once SHOUT_BASE . '/lib/base.php'; -require_once SHOUT_BASE . '/lib/Shout.php'; +require_once SHOUT_BASE . '/lib/Dialplan.php'; +$dialplan = &$shout->getDialplan($context); -$context = Util::getFormData("context"); -$section = "dialplan"; -$action = Util::getFormData("action"); -if ($button = Util::getFormData("submitbutton")) { - $action = $button; -} -$extension = Util::getFormData("extension"); +// Set up the tree. +$dpgui = Shout_Dialplan::singleton('x', $dialplan); -$contexts = &$shout->getContexts(); -$vars = &Variables::getDefaultVariables(); +$action = Util::getFormData("action"); -if (!isset($context)) {#FIXME || !Shout::checkContext()) { - $url = Horde::applicationUrl("index.php"); - header("Location: $url"); - exit(0); +switch($action) { +case "do": + echo "stuff\n"; + break; } -switch ($action) { - case "add": - $title = _("Add Extension"); - # Treat adds just like an empty edit - unset($extension); - $action = 'edit'; - break; - case "Add Priority": - $dialplan = &$shout->getDialplan($context); - #FIXME Handle added-but-not-yet-saved priorities - $dialplan['extensions'][$extension][] = ''; - $action = 'edit'; - break; - case "Add 5 Priorities": - $dialplan = &$shout->getDialplan($context); - $dialplan['extensions'][$extension][] = ''; - $dialplan['extensions'][$extension][] = ''; - $dialplan['extensions'][$extension][] = ''; - $dialplan['extensions'][$extension][] = ''; - $dialplan['extensions'][$extension][] = ''; - $action = 'edit'; - break; - case "edit": - $title = _("Edit Extension") . "$extension"; - break; - case "Save": - case "save": - $title = _("Save Extension") . "$extension"; - break; - case "delete": - $title = _("Delete Extension") . "$extension"; - break; - default: - $url = Horde::applicationUrl('/'); - header("Location: $url"); - exit(); -} +$title = _("Dialplan Manager"); require SHOUT_TEMPLATES . '/common-header.inc'; require SHOUT_TEMPLATES . '/menu.inc'; -echo "
"; +$notification->notify(); -$tabs = &Shout::getTabs($context, $vars); -$tabs->preserve('context', $context); echo $tabs->render($section); require SHOUT_BASE . "/dialplan/$action.php"; +require SHOUT_TEMPLATES . '/dialplan/manager.inc'; + +// Horde::addScriptFile('httpclient.js', 'horde', true); +// Horde::addScriptFile('hideable.js', 'horde', true); +// require HORDE_TEMPLATES . '/common-header.inc'; +// require HORDE_TEMPLATES . '/portal/sidebar.inc'; + + +// require SHOUT_TEMPLATES . "/dialplan/dialplanlist.inc"; + + + + + + + + + + require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/index.php b/index.php index dc69e5d84..7daac1891 100644 --- a/index.php +++ b/index.php @@ -2,85 +2,69 @@ /** * $Id$ * - * Copyright 2005 Ben Klang + * Copyright 2005-2006 Ben Klang * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @package shout */ @define('SHOUT_BASE', dirname(__FILE__)); -$shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php'));# && +$shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php') && + @is_readable(SHOUT_BASE . '/config/defines.php'));# && #@is_readable(SHOUT_BASE . '/config/prefs.php')); if (!$shout_configured) { require SHOUT_BASE . '/../lib/Test.php'; Horde_Test::configFilesMissing('Shout', SHOUT_BASE, - array('conf.php', 'prefs.php')); + array('conf.php', 'defines.php')); + #, 'prefs.php')); } 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(); -$vars = &Variables::getDefaultVariables(); -#$ticket->setDetails($vars); - -if (count($contexts) == 1) { +# 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(); } +$vars = &Variables::getDefaultVariables(); $tabs = &Shout::getTabs($context, $vars); $tabs->preserve('context', $context); -if (!$section) { - $section = $tabs->_tabs[0]['tabname']; -} - -#require_once SHOUT_TEMPLATES . '/comment.inc'; -#require_once 'Horde/Variables.php'; -#require_once 'Horde/Text/Filter.php'; - - -#$title = '[#' . $ticket->getId() . '] ' . $ticket->get('summary'); -require SHOUT_TEMPLATES . '/common-header.inc'; -require SHOUT_TEMPLATES . '/menu.inc'; - -// if (!$section) { -// $section = -print '
'; -echo $tabs->render($section); switch ($section) { case "conference": - $title = _('Conferences'); - break; case "dialplan": - $title = _('Dial Plan'); - break; case "security": - $title = _('Security/Access Control'); - break; - case "system": - $title = _('System Settings'); - break; - case "users": - $title = _('Users'); - break; + case "usermgr": case "moh": - $title = _('Music on Hold'); break; - default: - require SHOUT_TEMPLATES . '/common-footer.inc'; - require $registry->get('templates', 'horde') . '/common-footer.inc'; - exit(); + $section = $tabs->_tabs[0]['tabname']; break; } +# We've passed the initialization tests. This flag allows other pages to run. +$SHOUT_RUNNING = true; + +require SHOUT_BASE . "/$section.php"; + +#print '
'; -require "main/$section.php"; -print '
'; -require SHOUT_TEMPLATES . '/common-footer.inc'; +#print '
'; require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/lib/Driver.php b/lib/Driver.php index dcc3e6e7d..0d86a2224 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -14,7 +14,6 @@ * @since Shout 0.1 * @package Shout */ -require_once SHOUT_BASE . "/lib/defines.php"; // {{{ Shout_Driver class class Shout_Driver { diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index e42dd6854..ba69261b0 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -210,15 +210,87 @@ type"); return $entries[$context]; } - $registry = &Registry::singleton(); - require_once $registry->applicationFilePath('%application%/lib/defines.php', 'congregation'); - $users = $registry->callByPackage('congregation', 'getUsersByContext', - array($context, CONGREGATION_USER_PHONE)); + $basedn = SHOUT_USERS_BRANCH.','.$this->_params['basedn']; + + $filter = '(&'; + $filter .= '(objectClass='.SHOUT_USER_OBJECTCLASS.')'; + $filter .= '(context='.$context.')'; + $filter .= ')'; + + $attributes = array( + 'voiceMailbox', + 'asteriskUserDialOptions', + 'asteriskVoiceMailboxOptions', + 'voiceMailboxPin', + 'cn', + 'telephoneNumber', + 'asteriskUserDialTimeout', + 'mail', + 'asteriskPager', + ); + + $search = @ldap_search($this->_LDAP, $basedn, $filter, $attributes); - foreach ($users as $user) { - $extension = $user['extension']; - $entries[$context][$extension] = $user; + if (!$search) { + return PEAR::raiseError("Unable to search directory: " . + ldap_error($this->_LDAP)); } + + $res = ldap_get_entries($this->_LDAP, $search); + + # + # ATTRIBUTES RETURNED FROM ldap_get_entries ARE ALL LOWER CASE!! + # + $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++; + + } + ksort($entries[$context]); return($entries[$context]); @@ -236,14 +308,20 @@ type"); # 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))", - array('context')); + + $basedn = SHOUT_USERS_BRANCH.','.$this->_params['basedn']; + $filter = '(&'; + $filter .= '(mail='.Auth::getAuth().')'; + $filter .= '(objectClass='.SHOUT_USER_OBJECTCLASS.')'; + $filter .= ')'; + $attributes = array('context'); + + $res = @ldap_search($this->_LDAP, $basedn, $filter, $attributes); if (!$res) { return PEAR::raiseError("Unable to locate any customers " . "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn'] . " matching those search filters"); + # FIXME Better error string above } $res = ldap_get_entries($this->_LDAP, $res); @@ -251,6 +329,7 @@ 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? return $res[0]['context'][0]; } // }}} diff --git a/lib/Shout.php b/lib/Shout.php index aca316965..eac179385 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -14,7 +14,7 @@ * @since Shout 0.1 * @package Shout */ -require_once SHOUT_BASE . "/lib/defines.php"; +require_once SHOUT_BASE . "/config/defines.php"; // {{{ Class Shout class Shout @@ -109,9 +109,9 @@ class Shout if (Shout::checkRights("$permprefix:users", null, 1) && $shout->checkContextType($context, "users")) { - $tabs->addTab(_("Users"), + $tabs->addTab(_("User Manager"), Horde::applicationUrl("index.php?context=$context"), - 'users'); + 'usermgr'); } if (Shout::checkRights("$permprefix:dialplan", null, 1) && @@ -132,11 +132,6 @@ class Shout Horde::applicationUrl('index.php'), 'moh'); } - if (Auth::isAdmin("shout:system", PERMS_SHOW|PERMS_READ)) { - $tabs->addTab(_("System Settings"), - Horde::applicationUrl('index.php'), 'system'); - } - if (Auth::isAdmin("shout:superadmin", PERMS_SHOW|PERMS_READ)) { $tabs->addTab(_("Security"), Horde::applicationUrl('index.php'), 'security'); diff --git a/lib/User.php b/lib/User.php index 1b5e08a40..55d3f2e6f 100644 --- a/lib/User.php +++ b/lib/User.php @@ -113,13 +113,13 @@ class UserDetailsForm extends Horde_Form { $vars->set('eca', false); } - if (in_array('__CALLPRESENT:${VOFFICENUM}', $userdetails['dialopts'])) { + if (in_array('e(${VOFFICENUM})', $userdetails['dialopts'])) { $vars->set('eca', true); $vars->set('callappearance', 'v-office'); - } elseif (in_array('__CALLPRESENT:${CALLER}', $userdetails['dialopts'])) { + } elseif (in_array('e(${CALLER})', $userdetails['dialopts'])) { $vars->set('eca', true); $vars->set('callappearance', 'caller'); - } elseif (in_array('__CALLPRESENT:${SELF}', $userdetails['dialopts'])) { + } elseif (in_array('e(${SELF})', $userdetails['dialopts'])) { $vars->set('eca', true); $vars->set('callappearance', 'self'); } diff --git a/lib/api.php b/lib/api.php index 1dd003e4e..cfba48bb6 100644 --- a/lib/api.php +++ b/lib/api.php @@ -10,7 +10,6 @@ * @package Shout */ @define('SHOUT_BASE', dirname(__FILE__) . "/.."); -require_once SHOUT_BASE . "/lib/defines.php"; $_services['perms'] = array( 'args' => array(), diff --git a/lib/defines.php b/lib/defines.php deleted file mode 100644 index 12ca70501..000000000 --- a/lib/defines.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * See the enclosed file COPYING for license information (GPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. - */ - -if (!defined(SHOUT_BASE)) { - define(SHOUT_BASE, dirname(__FILE__)); -} - -require_once SHOUT_BASE . '/lib/Dialplan.php'; - -$dialplan = &$shout->getDialplan($context); - -// Set up the tree. -$dpgui = Shout_Dialplan::singleton('x', $dialplan); -require SHOUT_TEMPLATES . '/dialplan/manager.inc'; - -// Horde::addScriptFile('httpclient.js', 'horde', true); -// Horde::addScriptFile('hideable.js', 'horde', true); -// require HORDE_TEMPLATES . '/common-header.inc'; -// require HORDE_TEMPLATES . '/portal/sidebar.inc'; - - -// require SHOUT_TEMPLATES . "/dialplan/dialplanlist.inc"; \ No newline at end of file diff --git a/main/moh.php b/main/moh.php deleted file mode 100644 index 7d684e4e9..000000000 --- a/main/moh.php +++ /dev/null @@ -1,15 +0,0 @@ -push(_("Internal error viewing requested page"), - 'horde.error'); - $notification->notify(); - require $registry->get('templates', 'horde') . '/common-footer.inc'; - exit(); -} - diff --git a/main/users.php b/main/users.php deleted file mode 100644 index 266edc8ca..000000000 --- a/main/users.php +++ /dev/null @@ -1,7 +0,0 @@ -getUsers($context); -ksort($users); -require SHOUT_TEMPLATES . "/users/userlist.inc"; \ No newline at end of file diff --git a/moh.php b/moh.php new file mode 100644 index 000000000..3c89ebd82 --- /dev/null +++ b/moh.php @@ -0,0 +1,26 @@ + + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @package shout + */ +if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { + header('Location: /'); + exit(); +} + +$title = _('Music on Hold'); + +require SHOUT_TEMPLATES . '/common-header.inc'; +require SHOUT_TEMPLATES . '/menu.inc'; + +$notification->notify(); + +$tabs->render($section); + +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/security.php b/security.php index 55d47934a..11f312697 100644 --- a/security.php +++ b/security.php @@ -2,22 +2,28 @@ /** * $Id$ * - * Copyright 2005 Ben Klang + * Copyright 2005-2006 Ben Klang * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @package shout */ -@define('SHOUT_BASE', dirname(__FILE__)); -$shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php'));# && - #@is_readable(SHOUT_BASE . '/config/prefs.php')); -if (!$shout_configured) { - require SHOUT_BASE . '/../lib/Test.php'; - Horde_Test::configFilesMissing('Shout', SHOUT_BASE, - array('conf.php', 'prefs.php')); +if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { + header('Location: /'); + exit(); } -require_once SHOUT_BASE . '/lib/base.php'; -require_once SHOUT_BASE . '/lib/Shout.php'; +$title = _('Security'); + +require SHOUT_TEMPLATES . '/common-header.inc'; +require SHOUT_TEMPLATES . '/menu.inc'; + +$notification->notify(); + +$tabs->render($section); + +Shout::getApplist(); -Shout::getApplist(); \ No newline at end of file +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/templates/common-header.inc b/templates/common-header.inc index 58a1be412..35f14f6fd 100644 --- a/templates/common-header.inc +++ b/templates/common-header.inc @@ -6,7 +6,7 @@ ?> - + $user) { $rowcolor = $line % 2; $line++; - $url = Horde::applicationUrl("users.php"); - $url = Util::addParameter($url, array('context' => $context, - 'extension' => $extension)); + $url = Horde::applicationUrl("index.php"); + $url = Util::addParameter($url, + array( + 'context' => $context, + 'extension' => $extension, + 'section' => 'users', + ) + ); $editurl = Util::addParameter($url, "action=edit"); $deleteurl = Util::addParameter($url, "action=delete"); ?> diff --git a/usermgr.php b/usermgr.php index 47857eb6e..1af7ee5be 100644 --- a/usermgr.php +++ b/usermgr.php @@ -2,70 +2,56 @@ /** * $Id$ * - * Copyright 2005 Ben Klang + * Copyright 2005-2006 Ben Klang * * 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) { + header('Location: /'); + exit(); +} // Form libraries. 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'; - - -$context = Util::getFormData("context"); -$section = "users"; $action = Util::getFormData("action"); $extension = Util::getFormData("extension"); -$contexts = &$shout->getContexts(); -$vars = &Variables::getDefaultVariables(); - -if (!isset($context)) {#FIXME || !Shout::checkContext()) { - $url = Horde::applicationUrl("index.php"); - header("Location: $url"); - exit(0); -} - - +$title = _("User Manager: "); switch ($action) { case "add": - $title = _("Add User"); + $title .= _("Add User"); # Treat adds just like an empty edit unset($extension); break; case "edit": - $title = _("Edit User (Extension") . "$extension)"; + $title .= _("Edit User (Extension") . "$extension)"; break; case "save": - $title = _("Save User (Extension") . "$extension)"; + $title .= _("Save User (Extension") . "$extension)"; break; case "delete": - $title = _("Delete User (Extension") . "$extension)"; + $title .= _("Delete User (Extension") . "$extension)"; break; + case "list": default: - $url = Horde::applicationUrl('/'); - header("Location: $url"); - exit(); + $title .= _("List Users"); + $action = "list"; + break; } + + require SHOUT_TEMPLATES . '/common-header.inc'; require SHOUT_TEMPLATES . '/menu.inc'; $notification->notify(); -$tabs = &Shout::getTabs($context, $vars); -$tabs->preserve('context', $context); echo $tabs->render($section); -require SHOUT_BASE . "/users/$action.php"; +require SHOUT_BASE . "/usermgr/$action.php"; require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file