From 4013ca6cf29a315aff537eddb672b9112ed55f51 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Mon, 21 Dec 2009 04:01:12 +0000 Subject: [PATCH] A bunch of changes that make it possible to list extensions and load the edit extension form git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@502 06cd67b6-e706-0410-b29e-9de616bca6e9 --- extensions.php | 46 ++++----------- lib/Driver/Ldap.php | 4 +- lib/Forms/ExtensionForm.php | 128 +++--------------------------------------- lib/Shout.php | 49 +--------------- templates/extensions/edit.inc | 6 ++ templates/extensions/list.inc | 19 +++---- 6 files changed, 38 insertions(+), 214 deletions(-) create mode 100644 templates/extensions/edit.inc diff --git a/extensions.php b/extensions.php index e4eaaa335..b1dd05de0 100644 --- a/extensions.php +++ b/extensions.php @@ -9,14 +9,16 @@ */ @define('SHOUT_BASE', dirname(__FILE__)); require_once SHOUT_BASE . '/lib/base.php'; +require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php'; //require_once SHOUT_BASE . '/lib/Shout.php'; $action = Horde_Util::getFormData('action'); $extension = Horde_Util::getFormData('extension'); +$extensions = $shout_extensions->getExtensions($context); $vars = Horde_Variables::getDefaultVariables(); -$tabs = Shout::getTabs($context, $vars); +//$tabs = Shout::getTabs($context, $vars); $RENDERER = new Horde_Form_Renderer(); @@ -29,43 +31,19 @@ switch ($action) { # Treat adds just like an empty edit $action = 'edit'; - $extension = 0; + case 'edit': $title .= sprintf(_("Edit Extension %s"), $extension); - $beendone = 0; - $wereerrors = 0; - $FormName = 'UserDetailsForm'; + $vars = new Horde_Variables($extensions[$extension]); $Form = &Horde_Form::singleton($FormName, $vars); - if (is_a($Form, 'PEAR_Error')) { - $notification->push($Form); - } else { - $FormValid = $Form->validate($vars, true); - if (is_a($FormValid, 'PEAR_Error')) { - $notification->push($FormValid); - } else { - $Form->fillUserForm($vars, $extension); - } - } + $Form->open($RENDERER, $vars, 'index.php', 'post'); + $Form->preserveVarByPost($vars, 'extension'); + $Form->preserveVarByPost($vars, 'context'); + $Form->preserveVarByPost($vars, 'section'); - if (!$FormValid || !$Form->isSubmitted()) { - # Display the form for editing - $Form->open($RENDERER, $vars, 'index.php', 'post'); - $Form->preserveVarByPost($vars, 'extension'); - $Form->preserveVarByPost($vars, 'context'); - $Form->preserveVarByPost($vars, 'section'); - $RENDERER->beginActive($Form->getTitle()); - $RENDERER->renderFormActive($Form, $vars); - $RENDERER->submit(); - $RENDERER->end(); - $Form->close($RENDERER); - } else { - # Process the Valid and Submitted form - $notification->push("How did we get HERE?!", 'horde.error'); - } - break; case 'save': $title .= sprintf(_("Save Extension %s"), $extension); @@ -120,7 +98,6 @@ switch ($action) { break; case 'delete': $title .= sprintf(_("Delete Extension %s"), $extension); - $context = Horde_Util::getFormData('context'); $extension = Horde_Util::getFormData('extension'); $res = $shout->deleteUser($context, $extension); @@ -135,7 +112,6 @@ switch ($action) { default: $action = 'list'; $title .= _("List Users"); - $extensions = $shout_extensions->getExtensions($context); } require SHOUT_TEMPLATES . '/common-header.inc'; @@ -143,8 +119,8 @@ require SHOUT_TEMPLATES . '/menu.inc'; $notification->notify(); -echo $tabs->render($section); +//echo $tabs->render($section); require SHOUT_TEMPLATES . '/extensions/' . $action . '.inc'; -require $registry->get('templates', 'horde') . '/common-footer.inc'; +require $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/lib/Driver/Ldap.php b/lib/Driver/Ldap.php index 6fd1640ae..c4324176e 100644 --- a/lib/Driver/Ldap.php +++ b/lib/Driver/Ldap.php @@ -115,8 +115,8 @@ class Shout_Driver_Ldap extends Shout_Driver $entries[$context] = array(); $i = 0; while ($i < $res['count']) { - list($extension) = explode('@', $res[$i]['AstVoicemailMailbox'][0]); - $entries[$context][$extension] = array(); + list($extension) = explode('@', $res[$i]['astvoicemailmailbox'][0]); + $entries[$context][$extension] = array('extension' => $extension); $j = 0; $entries[$context][$extension]['mailboxopts'] = array(); diff --git a/lib/Forms/ExtensionForm.php b/lib/Forms/ExtensionForm.php index 5a3de4eb5..1fdf8f7e3 100644 --- a/lib/Forms/ExtensionForm.php +++ b/lib/Forms/ExtensionForm.php @@ -2,7 +2,7 @@ /** * $Id$ * - * Copyright 2005 Ben Klang + * Copyright 2005-2009 Ben Klang * * See the enclosed file LICENSE for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl.php. @@ -13,141 +13,29 @@ // {{{ class UserDetailsForm extends Horde_Form { - var $_userdetails = false; // Store the user's details for fillUserForm - function UserDetailsForm(&$vars) { - global $shout, $notification; + global $shout_extensions; $context = $vars->get('context'); - $extension = $vars->get('extension'); - - $users = &$shout->getUsers($context); - if (is_a($users, 'PEAR_Error')) { - $notification->push($users); - } - if (array_key_exists($extension, $users)) { - # We must be editing an existing user -// $this->fillUserForm(&$vars, $users[$extension]); - $this->_userdetails = $users[$extension]; - $limits = &$shout->getLimits($context, $extension); - if (is_a($limits, 'PEAR_Error')) { - $notification->push($limits); - } + if ($vars->exists('extension')) { $formtitle = "Edit User"; - $this->addHidden('', 'uid', 'text', true); + $extension = $vars->get('extension'); } else { - $limits = &$shout->getLimits($context); - if (is_a($limits, 'PEAR_Error')) { - $notification->push($limits); - } $formtitle = "Add User"; } - parent::Horde_Form($vars, _("$formtitle - Context: $context")); - + parent::__construct($vars, _("$formtitle - Context: $context")); $this->addHidden('', 'action', 'text', true); $vars->set('action', 'save'); + $this->addHidden('', 'extension', 'int', true); + $vars->set('newextension', $extension); $this->addVariable(_("Full Name"), 'name', 'text', true); $this->addVariable(_("Extension"), 'newextension', 'int', true); $this->addVariable(_("E-Mail Address"), 'email', 'email', true); $this->addVariable(_("Pager E-Mail Address"), 'pageremail', 'email', false); - # TODO: Integrate with To-Be-Written user manager and possibly make this - # TODO: new user also an email account. $this->addVariable(_("PIN"), 'mailboxpin', 'int', true); - # FIXME: Make this work if limits don't exist. - $t = 1; - while ($t <= $limits['telephonenumbersmax']) { - $this->addVariable(_("Telephone Number $t:"), "telephonenumber[$t]", - 'cellphone', false); - $t++; - } - - $this->addVariable(_("Music on Hold while transferring"), 'moh', - 'boolean', true, false);#, _("When checked, a calling user will hear music on hold while the caller is connected")); - $this->addVariable(_("Allow Call Transfers"), 'transfer', - 'boolean', true, false);#, _("When checked, the called user will be allowed to transfer the incoming call to other extensions")); - $this->addVariable(_("Explicit Call Acceptance"), 'eca', - 'boolean', true, false);#, _("When checked, the called user will be required to press 1 to accept the call. Only turn this off if you really know what you're doing!")); -// $this->addVariable(_("Call Appearance"), 'callappearance', -// 'radio', $vars->get('eca'), false, null, array('values' => -// array('caller' => 'From Calling Party', -// 'self' => 'From Self', -// 'switch' => 'From V-Office', -// ) -// ) -// ); - return true; } - // {{{ fillUserForm method - /** - * Fill in the blanks for the UserDetailsForm - * - * @param object Reference to a Variables object to fill in - * - * @param array User details - * - * @return boolean True if successful, Pear::raiseError object on failure - */ - function fillUserForm(&$vars) - { - #Array ( [dialopts] => Array ( [0] => m [1] => t ) [mailboxopts] => Array ( - #) [mailboxpin] => 1234 [name] => Ricardo Paul [phonenumbers] => Array ( ) - #[dialtimeout] => 30 [email] => ricardo.paul@v-office.biz [pageremail] => ) - if (!$this->_userdetails) { - return true; - } - foreach(array('name', 'email', 'pageremail', 'mailboxpin', 'uid', 'telephonenumber') as $var) { - # FIXME This will be done the Right Way in Shout 0.7 - $vars->set($var, $this->_userdetails[$var]); - } -// $vars->set('name', $this->_userdetails['name']); -// $vars->set('email', $this->_userdetails['email']); -// $vars->set('pager', $this->_userdetails['pager']); -// $vars->set('mailboxpin', $this->_userdetails['mailboxpin']); -// $vars->set('uid', $this->_userdetails['uid']); - $vars->set('newextension', $vars->get('extension')); - - $vars->set('moh', false); - $vars->set('eca', false); - $vars->set('transfer', false); -// $vars->set('callappearance', 'caller'); - - - foreach ($this->_userdetails['dialopts'] as $opt) { - if ($opt == 'm') { - $vars->set('moh', true); - } - if ($opt == 't') { - $vars->set('transfer', true); - } - if (preg_match('/^e(\(.*\))*/', $opt, $matches)) { - # This matches 'e' and 'e(ARGS)' - $vars->set('eca', true); -// if (count($matches) > 1) { -// # We must have found an argument -// switch($matches[1]) { -// case '(${VOFFICENUM})': -// $vars->set('callappearance', 'switch'); -// break; -// -// case '(${CALLERANI})': -// $vars->set('callappearance', 'self'); -// break; -// -// case '(${CALLERIDNUM})': -// default: -// $vars->set('callappearance', 'caller'); -// break; -// -// } -// } - } - } - return true; - } - // }}} -} -// }}} +} \ No newline at end of file diff --git a/lib/Shout.php b/lib/Shout.php index 6d7e9bbcb..1ceae103d 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -33,49 +33,10 @@ class Shout require_once 'Horde/Menu.php'; $menu = new Horde_Menu(HORDE_MENU_MASK_ALL); - $permprefix = "shout:contexts:$context"; - - if (isset($context) && $section == "usermgr" && - Shout::checkRights("$permprefix:users", - PERMS_EDIT, 1)) { - $url = Horde::applicationUrl("index.php"); - $url = Horde_Util::addParameter($url, array('context' => $context, - 'section' => $section, - 'action' => 'add')); - - # Goofy hack to make the icon make a little more sense - # when editing/deleting users -// if (!isset($action)) { - $icontitle = "Add"; -// } else { -// $icontitle = $action; -// $icontitle[0] = strtoupper($action[0]); -// } - # End goofy hack - - $menu->add($url, _("$icontitle User"), "add-user.gif"); - } - if (isset($context) && isset($section) && $section == "dialplan" && - Shout::checkRights("$permprefix:dialplan", - PERMS_EDIT, 1)) { - $url = Horde::applicationUrl("dialplan.php"); - $url = Horde_Util::addParameter($url, array('context' => $context, - 'section' => $section, - 'action' => 'add')); - - # Goofy hack to make the icon make a little sense - # when editing/deleting users - if (!isset($action)) { - $icontitle = "Add"; - } else { - $icontitle = $action; - $icontitle[0] = strtoupper($action[0]); - } - # End goofy hack + $menu->add(Horde::applicationUrl('extensions.php'), _("Extensions"), "user.png"); + $menu->add(Horde::applicationUrl('routes.php'), _("Call Paths")); - $menu->add($url, _("$icontitle Extension"), "add-extension.gif"); - } if ($returnType == 'object') { return $menu; @@ -102,25 +63,21 @@ class Shout if (Shout::checkRights($permprefix . ':extensions', null, 1)) { $url = Horde::applicationUrl('extensions.php'); - $url = Horde_Util::addParameter($url, 'context', $context); - $tabs->addTab(_("_Extensions"), $url, 'usermgr'); + $tabs->addTab(_("_Extensions"), $url, 'extensions'); } if (Shout::checkRights($permprefix . ':dialplan', null, 1)) { $url = Horde::applicationUrl('dialplan.php'); - $url = Horde_Util::addParameter($url, 'context', $context); $tabs->addTab(_("_Automated Attendant"), $url, 'dialplan'); } if (Shout::checkRights($permprefix . ':conference', null, 1)) { $url = Horde::applicationUrl('conference.php'); - $url = Horde_Util::addParameter($url, 'context', $context); $tabs->addTab(_("_Conference Rooms"), $url, 'conference'); } if (Shout::checkRights($permprefix . ':moh', null, 1)) { $url = Horde::applicationUrl('moh.php'); - $url = Horde_Util::addParameter($url, 'context', $context); $tabs->addTab(_("_Music on Hold"), $url, 'moh'); } diff --git a/templates/extensions/edit.inc b/templates/extensions/edit.inc new file mode 100644 index 000000000..a95682f37 --- /dev/null +++ b/templates/extensions/edit.inc @@ -0,0 +1,6 @@ +beginActive($Form->getTitle()); +$RENDERER->renderFormActive($Form, $vars); +$RENDERER->submit(); +$RENDERER->end(); +$Form->close($RENDERER); \ No newline at end of file diff --git a/templates/extensions/list.inc b/templates/extensions/list.inc index cddc8fffa..907506f79 100644 --- a/templates/extensions/list.inc +++ b/templates/extensions/list.inc @@ -11,29 +11,26 @@ $user) { - $rowcolor = $line % 2; - $line++; - $url = Horde::applicationUrl("index.php"); + foreach ($extensions as $extension => $info) { + + $url = Horde::applicationUrl("extensions.php"); $url = Horde_Util::addParameter($url, array( - 'context' => $context, 'extension' => $extension, - 'section' => $section, ) ); - $editurl = Horde_Util::addParameter($url, "action=edit"); - $deleteurl = Horde_Util::addParameter($url, "action=delete"); + $editurl = Horde_Util::addParameter($url, 'action', 'edit'); + $deleteurl = Horde_Util::addParameter($url, 'action', 'delete'); ?> - + - + - +