From: Ben Klang Date: Mon, 8 Mar 2010 22:15:25 +0000 (-0500) Subject: Shout: Change references from "context" to "account" X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=79e12c3181f5d34210cc564c70734cb41167d3a1;p=horde.git Shout: Change references from "context" to "account" --- diff --git a/shout/config/conf.xml b/shout/config/conf.xml index ab0cf074d..869af7166 100644 --- a/shout/config/conf.xml +++ b/shout/config/conf.xml @@ -14,8 +14,8 @@ - Context Storage - Sql + Account Storage + Sql diff --git a/shout/devices.php b/shout/devices.php index 7dc827edd..7d29db491 100644 --- a/shout/devices.php +++ b/shout/devices.php @@ -14,11 +14,11 @@ $shout = Horde_Registry::appInit('shout'); require_once SHOUT_BASE . '/lib/Forms/DeviceForm.php'; -$context = $_SESSION['shout']['context']; +$account = $_SESSION['shout']['account']; $action = Horde_Util::getFormData('action'); $vars = Horde_Variables::getDefaultVariables(); -//$tabs = Shout::getTabs($context, $vars); +//$tabs = Shout::getTabs($account, $vars); $RENDERER = new Horde_Form_Renderer(); @@ -28,7 +28,7 @@ switch ($action) { case 'add': case 'edit': $vars = Horde_Variables::getDefaultVariables(); - $vars->set('context', $context); + $vars->set('account', $account); $Form = new DeviceDetailsForm($vars); // Show the list if the save was successful, otherwise back to edit. @@ -53,7 +53,7 @@ case 'edit': // Create a new add/edit form $devid = Horde_Util::getFormData('devid'); - $devices = $shout->devices->getDevices($context); + $devices = $shout->devices->getDevices($account); $vars = new Horde_Variables($devices[$devid]); $vars->set('action', $action); @@ -68,7 +68,7 @@ case 'delete': $devid = Horde_Util::getFormData('devid'); $vars = Horde_Variables::getDefaultVariables(); - $vars->set('context', $context); + $vars->set('account', $account); $Form = new DeviceDeleteForm($vars); $FormValid = $Form->validate($vars, true); @@ -86,7 +86,7 @@ case 'delete': } $vars = Horde_Variables::getDefaultVariables(array()); - $vars->set('context', $context); + $vars->set('account', $account); $Form = new DeviceDeleteForm($vars); break; @@ -99,7 +99,7 @@ default: // Fetch the (possibly updated) list of extensions try { - $devices = $shout->devices->getDevices($context); + $devices = $shout->devices->getDevices($account); } catch (Exception $e) { $notification->push($e); $devices = array(); diff --git a/shout/dialplan.php b/shout/dialplan.php index a08413d76..a2971718b 100644 --- a/shout/dialplan.php +++ b/shout/dialplan.php @@ -16,9 +16,9 @@ require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php'; $action = Horde_Util::getFormData('action'); $menu = Horde_Util::getFormData('menu'); -$context = $_SESSION['shout']['context']; +$account = $_SESSION['shout']['account']; -$menus = $shout->storage->getMenus($context); +$menus = $shout->storage->getMenus($account); switch($action) { case 'edit': diff --git a/shout/extensions.php b/shout/extensions.php index 8e69baaf0..29cc94bcd 100644 --- a/shout/extensions.php +++ b/shout/extensions.php @@ -15,9 +15,9 @@ $shout = Horde_Registry::appInit('shout'); require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php'; $action = Horde_Util::getFormData('action'); -$context = $_SESSION['shout']['context']; +$account = $_SESSION['shout']['account']; -//$tabs = Shout::getTabs($context, $vars); +//$tabs = Shout::getTabs($account, $vars); $RENDERER = new Horde_Form_Renderer(); @@ -28,7 +28,7 @@ switch ($action) { case 'add': case 'edit': $vars = Horde_Variables::getDefaultVariables(); - $vars->set('context', $context); + $vars->set('account', $account); $Form = new ExtensionDetailsForm($vars); $FormValid = $Form->validate($vars, true); @@ -50,7 +50,7 @@ case 'edit': // Create a new add/edit form $extension = Horde_Util::getFormData('extension'); - $extensions = $shout->extensions->getExtensions($context); + $extensions = $shout->extensions->getExtensions($account); $vars = new Horde_Variables($extensions[$extension]); if ($action == 'edit') { $vars->set('oldextension', $extension); @@ -67,7 +67,7 @@ case 'delete': $extension = Horde_Util::getFormData('extension'); $vars = Horde_Variables::getDefaultVariables(); - $vars->set('context', $context); + $vars->set('account', $account); $Form = new ExtensionDeleteForm($vars); $FormValid = $Form->validate($vars, true); @@ -86,7 +86,7 @@ case 'delete': } $vars = Horde_Variables::getDefaultVariables(array()); - $vars->set('context', $context); + $vars->set('account', $account); $Form = new ExtensionDeleteForm($vars); break; @@ -100,7 +100,7 @@ default: // Fetch the (possibly updated) list of extensions try { - $extensions = $shout->extensions->getExtensions($context); + $extensions = $shout->extensions->getExtensions($account); } catch (Exception $e) { $notification->push($e); $extensions = array(); diff --git a/shout/lib/Ajax/Application.php b/shout/lib/Ajax/Application.php index 2968ff6b2..2f5f94dbf 100644 --- a/shout/lib/Ajax/Application.php +++ b/shout/lib/Ajax/Application.php @@ -34,12 +34,12 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base { $vars = $this->_vars; $shout = Horde_Registry::appInit('shout'); - $context = $_SESSION['shout']['context']; + $account = $_SESSION['shout']['account']; try { $shout = $GLOBALS['registry']->getApiInstance('shout', 'application'); - $shout->extensions->addDestination($context, $vars->extension, $vars->type, $vars->destination); + $shout->extensions->addDestination($account, $vars->extension, $vars->type, $vars->destination); - return $shout->extensions->getExtensions($context); + return $shout->extensions->getExtensions($account); } catch (Exception $e) { //FIXME: Create a way to notify the user of the failure. Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); @@ -54,13 +54,13 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base { $vars = $this->_vars; $shout = Horde_Registry::appInit('shout'); - $context = $_SESSION['shout']['context']; + $account = $_SESSION['shout']['account']; try { // FIXME: Use Form? $shout = $GLOBALS['registry']->getApiInstance('shout', 'application'); - $shout->extensions->deleteDestination($context, $vars->extension, $vars->type, $vars->destination); + $shout->extensions->deleteDestination($account, $vars->extension, $vars->type, $vars->destination); - return $shout->extensions->getExtensions($context); + return $shout->extensions->getExtensions($account); } catch (Exception $e) { //FIXME: Create a way to notify the user of the failure. Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); @@ -75,9 +75,9 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base { $vars = $this->_vars; $shout = Horde_Registry::appInit('shout'); - $context = $_SESSION['shout']['context']; + $account = $_SESSION['shout']['account']; try { - return $shout->extensions->getExtensions($context); + return $shout->extensions->getExtensions($account); } catch (Exception $e) { //FIXME: Create a way to notify the user of the failure. Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); @@ -93,8 +93,8 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base try { $vars = $this->_vars; $shout = Horde_Registry::appInit('shout'); - $context = $_SESSION['shout']['context']; - $menus = $shout->storage->getMenus($context); + $account = $_SESSION['shout']['account']; + $menus = $shout->storage->getMenus($account); $menu = $vars->menu; if (!isset($menus[$menu])) { Horde::logMessage("User requested a menu that does not exist.", __FILE__, __LINE__, PEAR_LOG_ERR); @@ -104,7 +104,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base return false; } $data['meta'] = $menus[$menu]; - $data['actions'] = $shout->dialplan->getMenuActions($context, $menu); + $data['actions'] = $shout->dialplan->getMenuActions($account, $menu); return $data; } catch (Exception $e) { //FIXME: Create a way to notify the user of the failure. @@ -120,8 +120,8 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base try { $vars = $this->_vars; $GLOBALS['shout'] = Horde_Registry::appInit('shout'); - $context = $_SESSION['shout']['context']; - $actions = Shout::getMenuActions(); + $account = $_SESSION['shout']['account']; + $actions = Shout::getMenuActions($contex, $menu); return $actions; } catch (Exception $e) { //FIXME: Create a way to notify the user of the failure. @@ -138,7 +138,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base throw new Shout_Exception("Invalid action requested."); } $GLOBALS['shout'] = Horde_Registry::appInit('shout'); - $context = $_SESSION['shout']['context']; + $account = $_SESSION['shout']['account']; $actions = Shout::getMenuActions(); $action = $actions[$action]; $form = new Horde_Form($vars, $action['description'], 'editActionForm'); @@ -154,6 +154,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base $info['required'], $info['readonly'], $info['description'], $info['params']); } + $form->setButtons(_("Save")); $this->_responseType = 'html'; diff --git a/shout/lib/Application.php b/shout/lib/Application.php index 4110a39d4..bff3fd6c7 100644 --- a/shout/lib/Application.php +++ b/shout/lib/Application.php @@ -80,35 +80,35 @@ class Shout_Application extends Horde_Registry_Application $this->dialplan = Shout_Driver::factory('dialplan'); try { - $contexts = $this->storage->getContexts(); + $accounts = $this->storage->getAccounts(); } catch (Shout_Exception $e) { $GLOBALS['notification']->push($e); - $contexts = false; + $accounts = false; } - $context = Horde_Util::getFormData('context'); - if (empty($context) && !empty($_SESSION['shout']['context'])) { - $context = $_SESSION['shout']['context']; + $account = Horde_Util::getFormData('account'); + if (empty($account) && !empty($_SESSION['shout']['account'])) { + $account = $_SESSION['shout']['account']; } - if (!empty($context) && !in_array($context, $contexts)) { - // Requested context not available - $GLOBALS['notification']->push(_("You do not have permission to access that context."), 'horde.error'); - $context = false; + if (!empty($account) && !in_array($account, $accounts)) { + // Requested account not available + $GLOBALS['notification']->push(_("You do not have permission to access that account."), 'horde.error'); + $account = false; } - if (empty($context)) { - if (count($contexts)) { - // Default to the user's first context - $context = reset($contexts); + if (empty($account)) { + if (count($accounts)) { + // Default to the user's first account + $account = reset($accounts); } else { - // No context requested and/or no contexts available anyway - $GLOBALS['notification']->push("Please select a context to continue.", 'horde.info'); - $context = false; + // No account requested and/or no accounts available anyway + $GLOBALS['notification']->push("Please select a account to continue.", 'horde.info'); + $account = false; } } - $_SESSION['shout']['context'] = $context; + $_SESSION['shout']['account'] = $account; } /** @@ -123,19 +123,19 @@ class Shout_Application extends Horde_Registry_Application self::$_perms['tree']['shout']['superadmin'] = false; self::$_perms['title']['shout:superadmin'] = _("Super Administrator"); - if (empty($this->contexts)) { + if (empty($this->accounts)) { $this->__construct(array('init' => true)); } - $contexts = $this->contexts->getContexts(); + $accounts = $this->accounts->getAccounts(); - self::$_perms['tree']['shout']['contexts'] = false; - self::$_perms['title']['shout:contexts'] = _("Contexts"); + self::$_perms['tree']['shout']['accounts'] = false; + self::$_perms['title']['shout:accounts'] = _("Accounts"); // Run through every contact source. - foreach ($contexts as $context) { - self::$_perms['tree']['shout']['contexts'][$context] = false; - self::$_perms['title']['shout:contexts:' . $context] = $context; + foreach ($accounts as $account) { + self::$_perms['tree']['shout']['accounts'][$account] = false; + self::$_perms['title']['shout:accounts:' . $account] = $account; foreach( array( @@ -144,8 +144,8 @@ class Shout_Application extends Horde_Registry_Application 'conferences' => 'Conference Rooms', ) as $module => $modname) { - self::$_perms['tree']['shout']['contexts'][$context][$module] = false; - self::$_perms['title']["shout:contexts:$context:$module"] = $modname; + self::$_perms['tree']['shout']['accounts'][$account][$module] = false; + self::$_perms['title']["shout:accounts:$account:$module"] = $modname; } } diff --git a/shout/lib/Driver.php b/shout/lib/Driver.php index 06a6374c1..c925078f6 100644 --- a/shout/lib/Driver.php +++ b/shout/lib/Driver.php @@ -26,85 +26,85 @@ class Shout_Driver { } /** - * Get a list of contexts from the instantiated driver and filter - * the returned contexts for those which the current user can see/edit + * Get a list of accounts from the instantiated driver and filter + * the returned accounts for those which the current user can see/edit * - * @param optional string $filter Filter for types of contexts to return. + * @param optional string $filter Filter for types of accounts to return. * One of "system" "customer" or "all" * - * @param optional string $filterperms Filter contexts for given permissions + * @param optional string $filterperms Filter accounts for given permissions * - * @return array Contexts valid for this user + * @return array Accounts valid for this user * * @access public */ - function getContexts($filters = "all", $filterperms = null) + function getAccounts($filters = "all", $filterperms = null) { throw new Shout_Exception("This function is not implemented."); } /** - * For the given context and type, make sure the context has the + * For the given account and type, make sure the account has the * appropriate properties, that it is effectively of that "type" * - * @param string $context the context to check type for + * @param string $account the account to check type for * - * @param string $type the type to verify the context is of + * @param string $type the type to verify the account is of * - * @return boolean true of the context is of type, false if not + * @return boolean true of the account is of type, false if not * * @access public */ - function checkContextType($context, $type) + function checkAccountType($account, $type) { throw new Shout_Exception("This function is not implemented."); } /** - * Get a list of users valid for the current context. Return an array + * Get a list of users valid for the current account. Return an array * indexed by the extension. * - * @param string $context Context for which users should be returned + * @param string $account Account for which users should be returned * * @return array User information indexed by voice mailbox number */ - function getUsers($context) + function getUsers($account) { throw new Shout_Exception("This function is not implemented."); } /** - * Returns the name of the user's default context + * Returns the name of the user's default account * - * @return string User's default context + * @return string User's default account */ - function getHomeContext() + function getHomeAccount() { throw new Shout_Exception("This function is not implemented."); } /** - * Get a context's properties + * Get a account's properties * - * @param string $context Context to get properties for + * @param string $account Account for which to get properties * - * @return integer Bitfield of properties valid for this context + * @return integer Bitfield of properties valid for this account */ - function getContextProperties($context) + function getAccountProperties($account) { throw new Shout_Exception("This function is not implemented."); } /** - * Get a context's extensions and return as a multi-dimensional associative + * Get a account's extensions and return as a multi-dimensional associative * array * - * @param string $context Context to return extensions for + * @param string $account account to return extensions for * * @return array Multi-dimensional associative array of extensions data * */ - function getDialplan($context) + function getDialplan($account) { throw new Shout_Exception("This function is not implemented."); } @@ -116,7 +116,7 @@ class Shout_Driver { * also implements some basic checks, so a typical backend will still * call this method via parent:: * - * @param string $context Context to which the user should be added + * @param string $account Account to which the user should be added * * @param string $extension Extension to be saved * @@ -125,26 +125,26 @@ class Shout_Driver { * @return TRUE on success, PEAR::Error object on error * @throws Shout_Exception */ - public function saveExtension($context, $extension, $details) + public function saveExtension($account, $extension, $details) { - if (empty($context) || empty($extension)) { + if (empty($account) || empty($extension)) { throw new Shout_Exception(_("Invalid extension.")); } - if (!Shout::checkRights("shout:contexts:$context:extensions", PERMS_EDIT, 1)) { - throw new Shout_Exception(_("Permission denied to save extensions in this context.")); + if (!Shout::checkRights("shout:accounts:$account:extensions", PERMS_EDIT, 1)) { + throw new Shout_Exception(_("Permission denied to save extensions in this account.")); } } - public function deleteExtension($context, $extension) + public function deleteExtension($account, $extension) { - if (empty($context) || empty($extension)) { + if (empty($account) || empty($extension)) { throw new Shout_Exception(_("Invalid extension.")); } - if (!Shout::checkRights("shout:contexts:$context:extensions", + if (!Shout::checkRights("shout:accounts:$account:extensions", PERMS_DELETE, 1)) { - throw new Shout_Exception(_("Permission denied to delete extensions in this context.")); + throw new Shout_Exception(_("Permission denied to delete extensions in this account.")); } } @@ -155,7 +155,7 @@ class Shout_Driver { * also implements some basic checks, so a typical backend will still * call this method via parent:: * - * @param string $context Context to which the user should be added + * @param string $account Account to which the user should be added * * @param string $extension Extension to be saved * @@ -164,18 +164,18 @@ class Shout_Driver { * @return TRUE on success, PEAR::Error object on error * @throws Shout_Exception */ - public function saveDevice($context, $devid, &$details) + public function saveDevice($account, $devid, &$details) { - if (empty($context)) { + if (empty($account)) { throw new Shout_Exception(_("Invalid device information.")); } - if (!Shout::checkRights("shout:contexts:$context:devices", PERMS_EDIT, 1)) { - throw new Shout_Exception(_("Permission denied to save devices in this context.")); + if (!Shout::checkRights("shout:accounts:$account:devices", PERMS_EDIT, 1)) { + throw new Shout_Exception(_("Permission denied to save devices in this account.")); } if (empty($devid) || !empty($details['genauthtok'])) { - list($devid, $password) = Shout::genDeviceAuth($context); + list($devid, $password) = Shout::genDeviceAuth($account); $details['devid'] = $devid; $details['password'] = $password; } @@ -190,18 +190,18 @@ class Shout_Driver { * also implements some basic checks, so a typical backend will still * call this method via parent:: * - * @param $context + * @param $account * @param $devid */ - public function deleteDevice($context, $devid) + public function deleteDevice($account, $devid) { - if (empty($context) || empty($devid)) { + if (empty($account) || empty($devid)) { throw new Shout_Exception(_("Invalid device.")); } - if (!Shout::checkRights("shout:contexts:$context:devices", + if (!Shout::checkRights("shout:accounts:$account:devices", PERMS_DELETE, 1)) { - throw new Shout_Exception(_("Permission denied to delete devices in this context.")); + throw new Shout_Exception(_("Permission denied to delete devices in this account.")); } } diff --git a/shout/lib/Driver/Ldap.php b/shout/lib/Driver/Ldap.php index eaae47f58..c70a16446 100644 --- a/shout/lib/Driver/Ldap.php +++ b/shout/lib/Driver/Ldap.php @@ -43,18 +43,18 @@ class Shout_Driver_Ldap extends Shout_Driver } /** - * Get a list of users valid for the contexts + * Get a list of users valid for the accounts * - * @param string $context Context in which to search + * @param string $account Account in which to search * * @return array User information indexed by voice mailbox number */ - public function getExtensions($context) + public function getExtensions($account) { static $entries = array(); - if (isset($entries[$context])) { - return $entries[$context]; + if (isset($entries[$account])) { + return $entries[$account]; } $this->_params['basedn']; @@ -62,7 +62,7 @@ class Shout_Driver_Ldap extends Shout_Driver $filter = '(&'; $filter .= '(objectClass=AsteriskVoiceMail)'; $filter .= '(objectClass=AsteriskUser)'; - $filter .= '(AstContext='.$context.')'; + $filter .= '(AstContext='.$account.')'; $filter .= ')'; $attributes = array( @@ -90,55 +90,55 @@ class Shout_Driver_Ldap extends Shout_Driver // ATTRIBUTES RETURNED FROM ldap_get_entries ARE ALL LOWER CASE!! // It's a PHP thing. - $entries[$context] = array(); + $entries[$account] = array(); $i = 0; while ($i < $res['count']) { list($extension) = explode('@', $res[$i]['astvoicemailmailbox'][0]); - $entries[$context][$extension] = array('extension' => $extension); + $entries[$account][$extension] = array('extension' => $extension); $j = 0; - $entries[$context][$extension]['mailboxopts'] = array(); + $entries[$account][$extension]['mailboxopts'] = array(); if (empty($res[$i]['astvoicemailoptions']['count'])) { $res[$i]['astvoicemailoptions']['count'] = -1; } while ($j < $res[$i]['astvoicemailoptions']['count']) { - $entries[$context][$extension]['mailboxopts'][] = + $entries[$account][$extension]['mailboxopts'][] = $res[$i]['astvoicemailoptions'][$j]; $j++; } - $entries[$context][$extension]['mailboxpin'] = + $entries[$account][$extension]['mailboxpin'] = $res[$i]['astvoicemailpassword'][0]; - $entries[$context][$extension]['name'] = + $entries[$account][$extension]['name'] = $res[$i]['cn'][0]; - $entries[$context][$extension]['email'] = + $entries[$account][$extension]['email'] = $res[$i]['astvoicemailemail'][0]; - $entries[$context][$extension]['pageremail'] = + $entries[$account][$extension]['pageremail'] = $res[$i]['astvoicemailpager'][0]; $j = 0; - $entries[$context][$extension]['numbers'] = array(); + $entries[$account][$extension]['numbers'] = array(); if (empty($res[$i]['telephonenumber']['count'])) { $res[$i]['telephonenumber']['count'] = -1; } while ($j < $res[$i]['telephonenumber']['count']) { - $entries[$context][$extension]['numbers'][] = + $entries[$account][$extension]['numbers'][] = $res[$i]['telephonenumber'][$j]; $j++; } $j = 0; - $entries[$context][$extension]['devices'] = array(); + $entries[$account][$extension]['devices'] = array(); if (empty($res[$i]['astuserchannel']['count'])) { $res[$i]['astuserchannel']['count'] = -1; } while ($j < $res[$i]['astuserchannel']['count']) { // Trim off the Asterisk channel type from the device string $device = explode('/', $res[$i]['astuserchannel'][$j], 2); - $entries[$context][$extension]['devices'][] = $device[1]; + $entries[$account][$extension]['devices'][] = $device[1]; $j++; } @@ -147,26 +147,26 @@ class Shout_Driver_Ldap extends Shout_Driver } - ksort($entries[$context]); + ksort($entries[$account]); - return($entries[$context]); + return($entries[$account]); } /** * Add a new destination valid for this extension. * A destination is either a telephone number or a VoIP device. * - * @param string $context Context for the extension + * @param string $account Account for the extension * @param string $extension Extension for which to return destinations * @param string $type Destination type ("device" or "number") * @param string $destination The destination itself * * @return boolean True on success. */ - function addDestination($context, $extension, $type, $destination) + function addDestination($account, $extension, $type, $destination) { // FIXME: Permissions check - $dn = $this->_getExtensionDn($context, $extension); + $dn = $this->_getExtensionDn($account, $extension); $attr = $this->_getDestAttr($type, $destination); $res = ldap_mod_add($this->_LDAP, $dn, $attr); @@ -184,14 +184,14 @@ class Shout_Driver_Ldap extends Shout_Driver * Get a list of destinations valid for this extension. * A destination is either a telephone number or a VoIP device. * - * @param string $context Context for the extension + * @param string $account Account for the extension * @param string $extension Extension for which to return destinations */ - function getDestinations($context, $extension) + function getDestinations($account, $extension) { // FIXME: LDAP filter injection $filter = '(&(AstContext=%s)(AstVoicemailMailbox=%s))'; - $filter = sprintf($filter, $context, $extension); + $filter = sprintf($filter, $account, $extension); $attrs = array('telephoneNumber', 'AstUserChannel'); @@ -225,9 +225,9 @@ class Shout_Driver_Ldap extends Shout_Driver 'devices' => $res['astuserchannel']); } - function deleteDestination($context, $extension, $type, $destination) + function deleteDestination($account, $extension, $type, $destination) { - $dn = $this->_getExtensionDn($context, $extension); + $dn = $this->_getExtensionDn($account, $extension); $attr = $this->_getDestAttr($type, $destination); $res = ldap_mod_del($this->_LDAP, $dn, $attr); @@ -252,7 +252,7 @@ class Shout_Driver_Ldap extends Shout_Driver case 'device': // FIXME: Check that the device is valid and associated with this - // context. + // account. // FIXME: Allow for different device types $attr = array('AstUserChannel' => "SIP/" . $destination); break; @@ -268,7 +268,7 @@ class Shout_Driver_Ldap extends Shout_Driver /** * Save an extension to the LDAP tree * - * @param string $context Context to which the user should be added + * @param string $account Account to which the user should be added * * @param string $extension Extension to be saved * @@ -277,14 +277,14 @@ class Shout_Driver_Ldap extends Shout_Driver * @return TRUE on success, PEAR::Error object on error * @throws Shout_Exception */ - public function saveExtension($context, $extension, $details) + public function saveExtension($account, $extension, $details) { // Check permissions - parent::saveExtension($context, $extension, $details); + parent::saveExtension($account, $extension, $details); // FIXME: Fix and uncomment the below -// // Check to ensure the extension is unique within this context -// $filter = "(&(objectClass=AstVoicemailMailbox)(context=$context))"; +// // Check to ensure the extension is unique within this account +// $filter = "(&(objectClass=AstVoicemailMailbox)(context=$account))"; // $reqattrs = array('dn', $ldapKey); // $res = @ldap_search($this->_LDAP, $this->_params['basedn'], // $filter, $reqattrs); @@ -300,7 +300,7 @@ class Shout_Driver_Ldap extends Shout_Driver // throw new Shout_Exception(_("Duplicate extension found. Not saving changes.")); // } // FIXME: Quote these strings - $uid = $extension . '@' . $context; + $uid = $extension . '@' . $account; $entry = array( 'objectClass' => array('top', 'account', 'AsteriskVoicemail', 'AsteriskUser'), @@ -309,7 +309,7 @@ class Shout_Driver_Ldap extends Shout_Driver 'AstVoicemailEmail' => $details['email'], 'AstVoicemailMailbox' => $extension, 'AstVoicemailPassword' => $details['mailboxpin'], - 'AstContext' => $context, + 'AstContext' => $account, ); $rdn = 'uid=' . $uid; $dn = $rdn . ',' . $this->_params['basedn']; @@ -318,7 +318,7 @@ class Shout_Driver_Ldap extends Shout_Driver // This is a change to an existing extension // First, identify the DN to modify // FIXME: Quote these strings - $olddn = $this->_getExtensionDn($context, $extension); + $olddn = $this->_getExtensionDn($account, $extension); // If the extension has changed we need to perform an object rename if ($extension != $details['oldextension']) { @@ -364,17 +364,17 @@ class Shout_Driver_Ldap extends Shout_Driver /** * Deletes an extension from the LDAP tree * - * @param string $context Context to delete the user from + * @param string $account Account to delete the user from * @param string $extension Extension of the user to be deleted * * @return boolean True on success, PEAR::Error object on error */ - public function deleteExtension($context, $extension) + public function deleteExtension($account, $extension) { // Check permissions - parent::deleteExtension($context, $extension); + parent::deleteExtension($account, $extension); - $dn = $this->_getExtensionDn($context, $extension); + $dn = $this->_getExtensionDn($account, $extension); $res = @ldap_delete($this->_LDAP, $dn); if ($res === false) { @@ -389,14 +389,14 @@ class Shout_Driver_Ldap extends Shout_Driver /** * - * @param $context + * @param $account * @param $extension */ - protected function _getExtensionDn($context, $extension) + protected function _getExtensionDn($account, $extension) { // FIXME: Sanitize filter string against LDAP injection $filter = '(&(AstVoicemailMailbox=%s)(AstContext=%s))'; - $filter = sprintf($filter, $extension, $context); + $filter = sprintf($filter, $extension, $account); $attributes = array('dn'); $res = ldap_search($this->_LDAP, $this->_params['basedn'], diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index 7573d894a..74a1dace8 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -44,14 +44,14 @@ class Shout_Driver_Sql extends Shout_Driver $this->_connect(); } - public function getContexts() + public function getAccounts() { $this->_connect(); - $sql = 'SELECT context_name FROM shout_contexts'; + $sql = 'SELECT name, accountcode FROM accounts'; $vars = array(); - $msg = 'SQL query in Shout_Driver_Sql#getContexts(): ' . $sql; + $msg = 'SQL query in Shout_Driver_Sql#getAccounts(): ' . $sql; Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG); $result = $this->_db->query($sql, $vars); if ($result instanceof PEAR_Error) { @@ -63,30 +63,32 @@ class Shout_Driver_Sql extends Shout_Driver throw new Shout_Exception($row); } - $contexts = array(); + $accounts = array(); while ($row && !($row instanceof PEAR_Error)) { - $contexts[] = $row['context_name']; + $accounts[$accountcode] = $row['name']; $row = $result->fetchRow(DB_FETCHMODE_ASSOC); } $result->free(); - return $contexts; + return $accounts; } - public function getMenus($context) + public function getMenus($account) { static $menus; - if (isset($menus[$context])) { - return $menus[$context]; + if (isset($menus[$account])) { + return $menus[$account]; } $this->_connect(); - $sql = 'SELECT menu_name, menu_description, menu_soundfile ' . - 'FROM shout_menus WHERE context_name = ?'; - $vars = array($context); + $sql = 'SELECT accounts.accountcode AS account, menus.name AS name, ' . + 'menus.description AS description, menus.soundfile AS soundfile ' . + 'FROM menus INNER JOIN accounts ON menus.account_id = accounts.id ' . + 'WHERE accounts.accountcode = ?'; + $vars = array($account); - $msg = 'SQL query in Shout_Driver_Sql#getContexts(): ' . $sql; + $msg = 'SQL query in Shout_Driver_Sql#getMenus(): ' . $sql; Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG); $result = $this->_db->query($sql, $vars); if ($result instanceof PEAR_Error) { @@ -98,10 +100,10 @@ class Shout_Driver_Sql extends Shout_Driver throw new Shout_Exception($row); } - $menus[$context] = array(); + $menus[$account] = array(); while ($row && !($row instanceof PEAR_Error)) { $menu = $row['menu_name']; - $menus[$context][$menu] = array( + $menus[$account][$menu] = array( 'name' => $menu, 'description' => $row['menu_description'], 'soundfile' => $row['menu_soundfile'] @@ -109,30 +111,66 @@ class Shout_Driver_Sql extends Shout_Driver $row = $result->fetchRow(DB_FETCHMODE_ASSOC); } $result->free(); - return $menus[$context]; + return $menus[$account]; } - function getMenuActions($context, $menu) + function getMenuActions($account, $menu) { - return array(); + static $menuActions; + if (!empty($menuActions[$menu])) { + return $menuActions[$menu]; + } + + $sql = "SELECT accounts.accountcode AS account, menus.name AS description, " . + "actions.name AS action, menu_entries.digit AS digit, " . + "menu_entries.args AS args FROM menu_entries " . + "INNER JOIN menus ON menu_entries.menu_id = menus.id " . + "INNER JOIN actions ON menu_entries.action_id = actions.id " . + "INNER JOIN accounts ON menus.account_id = accounts.id " . + "WHERE accounts.accountcode = ? AND menus.name = ?"; + $values = array($account, $menuid); + + $msg = 'SQL query in Shout_Driver_Sql#getMenuActions(): ' . $sql; + Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG); + $result = $this->_db->query($sql, $vars); + if ($result instanceof PEAR_Error) { + throw new Shout_Exception($result); + } + + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + if ($row instanceof PEAR_Error) { + throw new Shout_Exception($row); + } + + $menuActions[$menu] = array(); + while ($row && !($row instanceof PEAR_Error)) { + $menuActions[$menu][$row['digit']] = array( + 'digit' => $row['digit'], + 'action' => $row['action'], + 'args' => Horde_Yaml::load($row['args']) + ); + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + } + $result->free(); + return $menus[$menu]; } /** - * Get a list of devices for a given context + * Get a list of devices for a given account * - * @param string $context Context in which to search for devicess + * @param string $account Account in which to search for devicess * - * @return array Array of devices within this context with their information + * @return array Array of devices within this account with their information * * @access private */ - public function getDevices($context) + public function getDevices($account) { $sql = 'SELECT id, name, alias, callerid, context, mailbox, host, ' . 'permit, nat, secret, disallow, allow ' . 'FROM %s WHERE accountcode = ?'; $sql = sprintf($sql, $this->_params['table']); - $args = array($context); + $args = array($account); $msg = 'SQL query in Shout_Driver_Sql#getDevices(): ' . $sql; Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG); $sth = $this->_db->prepare($sql); @@ -179,29 +217,29 @@ class Shout_Driver_Sql extends Shout_Driver /** * Save a device (add or edit) to the backend. * - * @param string $context The context in which this device is valid + * @param string $account The account in which this device is valid * @param string $devid Device ID to save * @param array $details Array of device details */ - public function saveDevice($context, $devid, &$details) + public function saveDevice($account, $devid, &$details) { // Check permissions and possibly update the authentication tokens - parent::saveDevice($context, $devid, $details); + parent::saveDevice($account, $devid, $details); // See getDevices() for an explanation of these conversions $details['alias'] = $details['name']; $details['name'] = $details['devid']; unset($details['devid']); - $details['mailbox'] .= '@' . $context; + $details['mailbox'] .= '@' . $account; // Prepare the SQL query and arguments $args = array( $details['name'], - $context, + $account, $details['callerid'], $details['mailbox'], $details['password'], - $context, + $account, $details['alias'], ); @@ -236,9 +274,9 @@ class Shout_Driver_Sql extends Shout_Driver return true; } - public function deleteDevice($context, $devid) + public function deleteDevice($account, $devid) { - parent::deleteDevice($context, $devid); + parent::deleteDevice($account, $devid); $sql = 'DELETE FROM %s WHERE devid = ?'; $sql = sprintf($sql, $this->_params['table']); @@ -256,13 +294,13 @@ class Shout_Driver_Sql extends Shout_Driver } /** - * Get a list of users valid for the contexts + * Get a list of users valid for the accounts * - * @param string $context Context on which to search + * @param string $account Account on which to search * * @return array User information indexed by voice mailbox number */ - public function getExtensions($context) + public function getExtensions($account) { throw new Shout_Exception("Not implemented yet."); } @@ -270,7 +308,7 @@ class Shout_Driver_Sql extends Shout_Driver /** * Save a user to the LDAP tree * - * @param string $context Context to which the user should be added + * @param string $account Account to which the user should be added * * @param string $extension Extension to be saved * @@ -278,21 +316,21 @@ class Shout_Driver_Sql extends Shout_Driver * * @return TRUE on success, PEAR::Error object on error */ - public function saveExtension($context, $extension, $userdetails) + public function saveExtension($account, $extension, $userdetails) { - parent::saveExtension($context, $extension, $details); + parent::saveExtension($account, $extension, $details); throw new Shout_Exception("Not implemented."); } /** * Deletes a user from the LDAP tree * - * @param string $context Context to delete the user from + * @param string $account Account to delete the user from * @param string $extension Extension of the user to be deleted * * @return boolean True on success, PEAR::Error object on error */ - public function deleteExtension($context, $extension) + public function deleteExtension($account, $extension) { throw new Shout_Exception("Not implemented."); } diff --git a/shout/lib/Forms/DeviceForm.php b/shout/lib/Forms/DeviceForm.php index 0d2182ced..c24d93a98 100644 --- a/shout/lib/Forms/DeviceForm.php +++ b/shout/lib/Forms/DeviceForm.php @@ -26,8 +26,8 @@ class DeviceDetailsForm extends Horde_Form { $edit = false; } - $context = $vars->get('context'); - parent::__construct($vars, _("$formtitle - Context: $context")); + $account = $vars->get('account'); + parent::__construct($vars, _("$formtitle - Account: $account")); $this->addHidden('', 'action', 'text', true); if ($edit) { $this->addHidden('', 'devid', 'text', true); @@ -48,7 +48,7 @@ class DeviceDetailsForm extends Horde_Form { global $shout; $action = $this->_vars->get('action'); - $context = $this->_vars->get('context'); + $account = $this->_vars->get('account'); $devid = $this->_vars->get('devid'); // For safety, we force the device ID and password rather than rely @@ -58,7 +58,7 @@ class DeviceDetailsForm extends Horde_Form { $devid = null; $password = null; } else { // $action must be 'edit' - $devices = $shout->devices->getDevices($context); + $devices = $shout->devices->getDevices($account); if (!isset($devices[$devid])) { // The device requested doesn't already exist. This can't // be a valid edit. @@ -87,7 +87,7 @@ class DeviceDetailsForm extends Horde_Form { 'password' => $password, ); - $shout->devices->saveDevice($context, $devid, $details); + $shout->devices->saveDevice($account, $devid, $details); } } @@ -97,13 +97,13 @@ class DeviceDeleteForm extends Horde_Form function __construct(&$vars) { $devid = $vars->get('devid'); - $context = $vars->get('context'); + $account = $vars->get('account'); - $title = _("Delete Device %s - Context: %s"); - $title = sprintf($title, $devid, $context); + $title = _("Delete Device %s - Account: %s"); + $title = sprintf($title, $devid, $account); parent::__construct($vars, $title); - $this->addHidden('', 'context', 'text', true); + $this->addHidden('', 'account', 'text', true); $this->addHidden('', 'devid', 'text', true); $this->addHidden('', 'action', 'text', true); $this->setButtons(array(_("Delete"), _("Cancel"))); @@ -112,8 +112,8 @@ class DeviceDeleteForm extends Horde_Form function execute() { global $shout; - $context = $this->_vars->get('context'); + $account = $this->_vars->get('account'); $devid = $this->_vars->get('devid'); - $shout->devices->deleteDevice($context, $devid); + $shout->devices->deleteDevice($account, $devid); } } \ No newline at end of file diff --git a/shout/lib/Forms/ExtensionForm.php b/shout/lib/Forms/ExtensionForm.php index b633ad2de..eb97dbdd0 100644 --- a/shout/lib/Forms/ExtensionForm.php +++ b/shout/lib/Forms/ExtensionForm.php @@ -25,7 +25,7 @@ class ExtensionDetailsForm extends Horde_Form { { global $shout; - $context = $_SESSION['shout']['context']; + $account = $_SESSION['shout']['account']; $action = $vars->get('action'); if ($action == 'edit') { $formtitle = "Edit User"; @@ -33,7 +33,7 @@ class ExtensionDetailsForm extends Horde_Form { $formtitle = "Add User"; } - parent::__construct($vars, _("$formtitle - Context: $context")); + parent::__construct($vars, _("$formtitle - Account: $account")); $extension = $vars->get('extension'); @@ -51,15 +51,15 @@ class ExtensionDetailsForm extends Horde_Form { /** * Process this form, saving its information to the backend. * - * @param string $context Context in which to execute this save - * FIXME: is there a better way to get the $context and $shout->extensions? + * @param string $account Account in which to execute this save + * FIXME: is there a better way to get the $account and $shout->extensions? */ function execute() { global $shout; $extension = $this->_vars->get('extension'); - $context = $this->_vars->get('context'); + $account = $this->_vars->get('account'); // FIXME: Input Validation (Text::??) $details = array( @@ -70,7 +70,7 @@ class ExtensionDetailsForm extends Horde_Form { 'mailboxpin' => $this->_vars->get('mailboxpin'), ); - $shout->extensions->saveExtension($context, $extension, $details); + $shout->extensions->saveExtension($account, $extension, $details); } } @@ -80,13 +80,13 @@ class ExtensionDeleteForm extends Horde_Form function __construct(&$vars) { $extension = $vars->get('extension'); - $context = $vars->get('context'); + $account = $vars->get('account'); - $title = _("Delete Extension %s - Context: %s"); - $title = sprintf($title, $extension, $context); + $title = _("Delete Extension %s - Account: %s"); + $title = sprintf($title, $extension, $account); parent::__construct($vars, $title); - $this->addHidden('', 'context', 'text', true); + $this->addHidden('', 'account', 'text', true); $this->addHidden('', 'extension', 'int', true); $this->addHidden('', 'action', 'text', true); $this->setButtons(array(_("Delete"), _("Cancel"))); @@ -95,8 +95,8 @@ class ExtensionDeleteForm extends Horde_Form function execute() { global $shout; - $context = $this->_vars->get('context'); + $account = $this->_vars->get('account'); $extension = $this->_vars->get('extension'); - $shout->extensions->deleteExtension($context, $extension); + $shout->extensions->deleteExtension($account, $extension); } } diff --git a/shout/lib/Shout.php b/shout/lib/Shout.php index 6b183b31d..9b2736da3 100644 --- a/shout/lib/Shout.php +++ b/shout/lib/Shout.php @@ -24,7 +24,7 @@ class Shout */ static public function getMenu($returnType = 'object') { - global $conf, $context, $section, $action; + global $conf, $account, $section, $action; require_once 'Horde/Menu.php'; @@ -106,13 +106,13 @@ class Shout * provisioning can be done automatically. For these reasons, having * user-friendly usernames and passswords is not terribly important. * - * @param string $context Context for this credential pair + * @param string $account Account for this credential pair * * @return array Array of (string $deviceID, string $devicePassword) */ - static public function genDeviceAuth($context) + static public function genDeviceAuth($account) { - $devid = $context . substr(uniqid(), 6); + $devid = $account . substr(uniqid(), 6); // This simple password generation algorithm inspired by Jon Haworth // http://www.laughing-buddha.net/jon/php/password/ @@ -140,17 +140,17 @@ class Shout static public function getMenuActions() { global $shout; - $context = $_SESSION['shout']['context']; + $account = $_SESSION['shout']['account']; return array( - 'menu' => array( + 'jump' => array( 'description' => _("Jump to menu."), 'args' => array ( 'menuName' => array( 'name' => _("Menu"), 'type' => 'enum', 'required' => true, - 'params' => array(self::getNames($shout->dialplan->getMenus($context))) + 'params' => array(self::getNames($shout->dialplan->getMenus($account))) ) ) ), @@ -161,18 +161,18 @@ class Shout 'name' => _("Extension"), 'type' => 'enum', 'required' => true, - 'params' => array(self::getNames($shout->extensions->getExtensions($context))) + 'params' => array(self::getNames($shout->extensions->getExtensions($account))) ) ) ), - 'voicemail' => array( + 'leave_message' => array( 'description' => _("Leave a message."), 'args' => array( 'mailbox' => array( 'name' => _("Mailbox"), 'type' => 'enum', 'required' => true, - 'params' => array(self::getNames($shout->extensions->getExtensions($context))) + 'params' => array(self::getNames($shout->extensions->getExtensions($account))) ) ) ), @@ -204,6 +204,7 @@ class Shout 'description' => _("Restart the current menu."), 'args' => array() ), + // TODO: Actions to implement: Queue ); } diff --git a/shout/templates/devices/list.inc b/shout/templates/devices/list.inc index 48b2e1f37..b45b29d71 100644 --- a/shout/templates/devices/list.inc +++ b/shout/templates/devices/list.inc @@ -9,7 +9,7 @@ - Context: + Account:
diff --git a/shout/templates/dialplan/edit.inc b/shout/templates/dialplan/edit.inc index e38c0451d..b1543a817 100644 --- a/shout/templates/dialplan/edit.inc +++ b/shout/templates/dialplan/edit.inc @@ -42,9 +42,7 @@ function editAction(digit) // Draw the selectActionForm $('editActionOverlay').show(); - while ((e = $('selectAction').childNodes[0]) != null) { - $('selectAction').removeChild(e); - } + empty('selectAction'); var p = document.createElement('p'); p.id = 'actionPrompt'; var text = document.createTextNode(''); @@ -93,9 +91,8 @@ function saveAction(digit) parameters: params, onSuccess: function(r) { alert('FIXME'); - while ((e = $('editAction').childNodes[0]) != null) { - $('editAction').removeChild(e); - } + empty('selectAction'); + empty('editAction'); $('editActionOverlay').hide(); } }); @@ -117,9 +114,7 @@ function refreshMenu() var col; var img; var text; - while ((e = $('menuInfo').childNodes[0]) != null) { - $('menuInfo').removeChild(e); - } + empty('menuInfo'); var meta = menuInfo.get('meta'); @@ -177,6 +172,13 @@ function getMetaRow(name, value) return row; } +function empty(p) +{ + while ((e = $(p).childNodes[0]) != null) { + $(p).removeChild(e); + } +} + $('editActionOverlay').hide(); new Ajax.Request(ajax_url + 'getMenuInfo', { diff --git a/shout/templates/dialplan/list.inc b/shout/templates/dialplan/list.inc index c476e9ca8..2b948f02c 100644 --- a/shout/templates/dialplan/list.inc +++ b/shout/templates/dialplan/list.inc @@ -11,7 +11,7 @@ - Context: + Account:
diff --git a/shout/templates/extensions/list.inc b/shout/templates/extensions/list.inc index 4a538733c..9166a14f7 100644 --- a/shout/templates/extensions/list.inc +++ b/shout/templates/extensions/list.inc @@ -9,7 +9,7 @@ - Context: + Account:
diff --git a/shout/templates/menu.inc b/shout/templates/menu.inc index 013992828..25e1bf10d 100644 --- a/shout/templates/menu.inc +++ b/shout/templates/menu.inc @@ -1,44 +1,44 @@ getValue('widget_accesskey') ? - Horde::getAccessKey(_("Select _Context")) : ''; + Horde::getAccessKey(_("Select _Account")) : ''; $menu_view = $prefs->getValue('menu_view'); ?>