From 3b29b519787df83592fa60559f1638835a84b639 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Mon, 18 Jul 2005 12:16:43 +0000 Subject: [PATCH] Performance tweak: most shout methods can return references now and the driver backend caches much more data. More UI tweaks, experimenting with dialplan UI options. **** NOTE **** This version now relies on an edited HORDE_BASE./lib/Horde/VarRenderer/html.php to render the new form type 'priority'. This is a test, we'll see how it works out git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@67 06cd67b6-e706-0410-b29e-9de616bca6e9 --- dialplan.php | 22 ++++++++- dialplan/edit.php | 32 ++++++++---- index.php | 2 +- lib/Dialplan.php | 137 +++++++++++++++++++++++++++++++++++++++++++--------- lib/Driver/ldap.php | 36 ++++++++------ lib/System.php | 2 +- lib/User.php | 2 +- main/dialplan.php | 2 +- main/users.php | 2 +- shout.webprj | 75 ++++++++++++++++------------ templates/menu.inc | 3 +- users.php | 2 +- 12 files changed, 228 insertions(+), 89 deletions(-) diff --git a/dialplan.php b/dialplan.php index efce48e0d..c729ee899 100644 --- a/dialplan.php +++ b/dialplan.php @@ -23,9 +23,12 @@ require_once SHOUT_BASE . '/lib/Shout.php'; $context = Util::getFormData("context"); $section = "dialplan"; $action = Util::getFormData("action"); +if ($button = Util::getFormData("submitbutton")) { + $action = $button; +} $extension = Util::getFormData("extension"); -$contexts = $shout->getContexts(); +$contexts = &$shout->getContexts(); $vars = &Variables::getDefaultVariables(); if (!isset($context)) {#FIXME || !Shout::checkContext()) { @@ -34,7 +37,6 @@ if (!isset($context)) {#FIXME || !Shout::checkContext()) { exit(0); } - switch ($action) { case "add": $title = _("Add Extension"); @@ -42,9 +44,25 @@ switch ($action) { 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; diff --git a/dialplan/edit.php b/dialplan/edit.php index 662657ed8..c0a4dd26a 100644 --- a/dialplan/edit.php +++ b/dialplan/edit.php @@ -18,17 +18,31 @@ $wereerrors = 0; $vars = &Variables::getDefaultVariables($empty); $formname = $vars->get('formname'); +$context = $vars->get('context'); +$extension = $vars->get('extension'); +$dialplan = &$shout->getDialplan($context); -$UserDetailsForm = &Horde_Form::singleton('UserDetailsForm', $vars); -$UserDetailsFormValid = $UserDetailsForm->validate($vars, true); +$ExtensionDetailsForm = &Horde_Form::singleton('ExtensionDetailsForm', $vars); +$ExtensionDetailsFormValid = $ExtensionDetailsForm->validate($vars, true); -$UserDetailsForm->open($RENDERER, $vars, 'dialplan.php', 'post'); -$UserDetailsForm->preserveVarByPost($vars, "section"); -$UserDetailsForm->preserve($vars); +$ExtensionDetailsForm->open($RENDERER, $vars, 'dialplan.php', 'post'); +$ExtensionDetailsForm->preserveVarByPost($vars, "section"); +$ExtensionDetailsForm->preserve($vars); require SHOUT_TEMPLATES . '/table-limiter-begin.inc'; -$RENDERER->beginActive($UserDetailsForm->getTitle()); -$RENDERER->renderFormActive($UserDetailsForm, $vars); -$RENDERER->submit(); +$RENDERER->beginActive($ExtensionDetailsForm->getTitle()); +$RENDERER->renderFormActive($ExtensionDetailsForm, $vars); +# FIXME Maybe this should be a subclass inheriting from the From/Renderer object +# instead of a simple include? +$i = 0; +require SHOUT_TEMPLATES . '/dialplan/priority-form-begin.inc'; +foreach ($dialplan['extensions'][$extension] as $priority => $application) { + require SHOUT_TEMPLATES . '/dialplan/priority-form-line.inc'; + $i++; +} +require SHOUT_TEMPLATES . '/dialplan/priority-form-end.inc'; +$RENDERER->submit('Add Priority'); +$RENDERER->submit('Add 5 Priorities'); +$RENDERER->submit('Save'); $RENDERER->end(); -$UserDetailsForm->close($RENDERER); +$ExtensionDetailsForm->close($RENDERER); require SHOUT_TEMPLATES . '/table-limiter-end.inc'; \ No newline at end of file diff --git a/index.php b/index.php index 77088cea2..896c7c4b3 100644 --- a/index.php +++ b/index.php @@ -23,7 +23,7 @@ require_once SHOUT_BASE . '/lib/Shout.php'; $context = Util::getFormData("context"); $section = Util::getFormData("section"); -$contexts = $shout->getContexts(); +$contexts = &$shout->getContexts(); $vars = &Variables::getDefaultVariables(); #$ticket->setDetails($vars); diff --git a/lib/Dialplan.php b/lib/Dialplan.php index c61ad7113..4bee05ea2 100644 --- a/lib/Dialplan.php +++ b/lib/Dialplan.php @@ -18,7 +18,8 @@ class ExtensionDetailsForm extends Horde_Form { $context = $vars->get("context"); $extension = $vars->get("extension"); - $dialplan = $shout->getDialplan($context); + $dialplan = &$shout->getDialplan($context); + $extendata = $dialplan['extensions'][$extension]; if (array_key_exists($extension, $dialplan['extensions'])) { $formtitle = "Edit Extension"; } else { @@ -31,8 +32,14 @@ class ExtensionDetailsForm extends Horde_Form { $this->addHidden('', 'oldextension', 'text', true); $vars->set('oldextension', $extension); $this->addHidden('', 'action', 'text', true); - $vars->set('action', 'save'); +// $vars->set('action', 'save'); $this->addVariable(_("Extension"), 'extension', 'text', true); + $this->addVariable(_("Priority"), 'priority', 'priority', true); +// foreach ($extendata as $priority => $application) { +// $vars->set("priority$priority", $application); +// $this->addVariable("Priority $priority", "priority$priority", +// 'text', false); +// } } // {{{ fillUserForm method @@ -78,29 +85,111 @@ class ExtensionDetailsForm extends Horde_Form { } // }}} -class ExtensionPriorityForm extends ExtensionDetailsForm { +class Horde_Form_Type_priority extends Horde_Form_Type { - function ExtensionPriorityForm(&$vars) +// var $_regex; +// var $_size; +// var $_maxlength; + + /** + * The initialisation function for the text variable type. + * + * @access private + * + * @param string $regex Any valid PHP PCRE pattern syntax that + * needs to be matched for the field to be + * considered valid. If left empty validity + * will be checked only for required fields + * whether they are empty or not. + * If using this regex test it is advisable + * to enter a description for this field to + * warn the user what is expected, as the + * generated error message is quite generic + * and will not give any indication where + * the regex failed. + * @param integer $size The size of the input field. + * @param integer $maxlength The max number of characters. + */ + function init() + { + } +// function init($regex = '', $size = 40, $maxlength = null) +// { +// $this->_regex = $regex; +// $this->_size = $size; +// $this->_maxlength = $maxlength; +// } + + function isValid(&$var, &$vars, $value, &$message) { - global $shout; - $context = $vars->get("context"); - $extension = $vars->get("extension"); - - $dialplan = $shout->getDialplan($context); - if (array_key_exists($extension, $dialplan['extensions'])) { - $formtitle = "Edit Extension"; - } else { - $formtitle = "Add Extension"; - } - - parent::Horde_Form($vars, _("$formtitle - Context: $context")); - - $this->addHidden('', 'context', 'text', true); - $this->addHidden('', 'oldextension', 'text', true); - $vars->set('oldextension', $extension); - $this->addHidden('', 'action', 'text', true); - $vars->set('action', 'save'); - $this->addVariable(_("Extension"), 'extension', 'text', true); + $valid = true; + +// if ($var->isRequired() && empty($this->_regex)) { +// $valid = strlen(trim($value)) > 0; +// +// if (!$valid) { +// $message = _("This field is required."); +// } +// } elseif (!empty($this->_regex)) { +// $valid = preg_match($this->_regex, $value); +// +// if (!$valid) { +// $message = _("You have to enter a valid value."); +// } +// } + + return $valid; } + + function getSize() + { + return $this->_size; + } + + function getMaxLength() + { + return $this->_maxlength; + } + + /** + * Return info about field type. + */ + function about() + { + $about = array(); + $about['name'] = _("Extension Priority"); + $about['params'] = array( + 'priority' => array('label' => _("Priority"), + 'type' => 'int'), + 'application' => array('label' => _("Application"), + 'type' => 'stringlist'), + 'args' => array('label' => _("Arguments"), + 'type' => 'text'), + ); + return $about; + } + } -// }}} \ No newline at end of file + +// require_once HORDE_BASE . '/lib/Horde/UI/VarRenderer.php'; +// require_once HORDE_BASE . '/lib/Horde/UI/VarRenderer/html.php'; +// class Horde_UI_VarRenderer_html_priority extends Horde_UI_VarRenderer_html +// { +// function _renderVarInput_priority(&$form, &$var, &$vars) +// { +// echo ''; +// echo '\n'; +// echo ''; +// } +// +// function _renderVarDisplay_priority(&$form, &$var, &$vars) +// { +// echo ''; +// echo '\n'; +// echo ''; +// } +// } \ No newline at end of file diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index 842eef607..b9b3b1b67 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -42,7 +42,7 @@ class Shout_Driver_ldap extends Shout_Driver * * @access private */ - function getContexts($searchfilters = SHOUT_CONTEXT_ALL, + function &getContexts($searchfilters = SHOUT_CONTEXT_ALL, $filterperms = null) { static $entries = array(); @@ -179,7 +179,7 @@ type"); * * @return array User information indexed by voice mailbox number */ - function getUsers($context) + function &getUsers($context) { static $entries = array(); @@ -335,8 +335,13 @@ for $context")); * @return array Multi-dimensional associative array of extensions data * */ - function getDialplan($context) + function &getDialplan($context) { + static $dialplans = array(); + if (array_key_exists($context, $dialplans)) { + return $dialplans[$context]; + } + $res = ldap_search($this->_LDAP, SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], "(&(objectClass=asteriskExtensions)(context=$context))", @@ -350,7 +355,7 @@ for $context")); } $res = ldap_get_entries($this->_LDAP, $res); - $retdialplan = array(); + $dialplans[$context] = array(); $i = 0; while ($i < $res['count']) { # Handle extension lines @@ -371,36 +376,37 @@ for $context")); $token2 = strpos($line, ',', $token1 + 1); $extension = substr($line, 0, $token1); - if (!isset($retdialplan[$extension])) { - $retdialplan[$extension] = array(); + if (!isset($dialplans[$context][$extension])) { + $dialplan[$context][$extension] = array(); } $token1++; # Get the priority $priority = substr($line, $token1, $token2 - $token1); - $retdialplan[$extension][$priority] = array(); + $dialplans[$context][$extension][$priority] = array(); $token2++; # Get Application and args $application = substr($line, $token2); # Merge all that data into the returning array - $retdialplan['extensions'][$extension][$priority] = + $dialplans[$context]['extensions'][$extension][$priority] = $application; $j++; } # Sort the extensions data - foreach ($retdialplan['extensions'] as $extension) { - ksort($extension); + foreach ($dialplans[$context]['extensions'] as + $extension => $data) { + ksort($dialplans[$context]['extensions'][$extension]); } - ksort($retdialplan['extensions']); + ksort($dialplans[$context]['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; + $dialplans[$context]['include'][$j] = $line; $j++; } } @@ -410,7 +416,7 @@ for $context")); $j = 0; while ($j < $res[$i]['asteriskignorepat']['count']) { @$line = $res[$i]['asteriskignorepat'][$j]; - $retdialplan['include'][$j] = $line; + $dialplans[$context]['ignorepat'][$j] = $line; $j++; } } @@ -419,7 +425,7 @@ for $context")); $j = 0; while ($j < $res[$i]['asteriskextensionbareline']['count']) { @$line = $res[$i]['asteriskextensionbareline'][$j]; - $retdialplan['bareline'][$j] = $line; + $dialplans[$context]['bareline'][$j] = $line; $j++; } } @@ -427,7 +433,7 @@ for $context")); # Increment object $i++; } - return $retdialplan; + return $dialplans[$context]; } // }}} diff --git a/lib/System.php b/lib/System.php index d6622c315..e7f4dcf73 100644 --- a/lib/System.php +++ b/lib/System.php @@ -24,7 +24,7 @@ class ContextForm extends Horde_Form { $contextfilter = SHOUT_CONTEXT_CUSTOMERS | SHOUT_CONTEXT_EXTENSIONS| SHOUT_CONTEXT_MOH | SHOUT_CONTEXT_CONFERENCE; - $contexts = $shout->getContexts($contextfilter); + $contexts = &$shout->getContexts($contextfilter); foreach ($contexts as $context) { $tmpcontexts[$context] = $context; } diff --git a/lib/User.php b/lib/User.php index 4160beb68..b0f979e90 100644 --- a/lib/User.php +++ b/lib/User.php @@ -18,7 +18,7 @@ class UserDetailsForm extends Horde_Form { $context = $vars->get("context"); $extension = $vars->get("extension"); - $users = $shout->getUsers($context); + $users = &$shout->getUsers($context); if (array_key_exists($extension, $users)) { # We must be editing an existing user $this->fillUserForm(&$vars, $users[$extension]); diff --git a/main/dialplan.php b/main/dialplan.php index 51d9332ef..14aedf7ab 100644 --- a/main/dialplan.php +++ b/main/dialplan.php @@ -2,5 +2,5 @@ if (!defined(SHOUT_BASE)) { define(SHOUT_BASE, dirname(__FILE__)); } -$dialplan = $shout->getDialplan($context); +$dialplan = &$shout->getDialplan($context); require SHOUT_TEMPLATES . "/dialplan/dialplanlist.inc"; \ No newline at end of file diff --git a/main/users.php b/main/users.php index 45304443d..266edc8ca 100644 --- a/main/users.php +++ b/main/users.php @@ -2,6 +2,6 @@ if (!defined(SHOUT_BASE)) { define(SHOUT_BASE, dirname(__FILE__)); } -$users = $shout->getUsers($context); +$users = &$shout->getUsers($context); ksort($users); require SHOUT_TEMPLATES . "/users/userlist.inc"; \ No newline at end of file diff --git a/shout.webprj b/shout.webprj index 7db6eeb67..738ac88e5 100644 --- a/shout.webprj +++ b/shout.webprj @@ -9,36 +9,39 @@ - + - + - - + + + + + - + - - + + - + - + @@ -48,22 +51,27 @@ - - + + + + + + + - + - + - + @@ -88,14 +96,14 @@ - + - - + + - + Ben Klang ben@alkaloid.net Gubed @@ -110,26 +118,29 @@ - + - + - - + + - - - - - - - - - - + + + + + + + + + + + + + diff --git a/templates/menu.inc b/templates/menu.inc index 66e7a35cc..2a2a44cf7 100644 --- a/templates/menu.inc +++ b/templates/menu.inc @@ -12,7 +12,8 @@ $menu_view = $prefs->getValue('menu_view');