From: Ben Klang Date: Tue, 1 Jul 2008 22:25:00 +0000 (+0000) Subject: Make use of a drop-down box to select the context instead of a text box X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1eb7cd55179131974a58f5b50db850dda9ddbe76;p=horde.git Make use of a drop-down box to select the context instead of a text box --- diff --git a/lib/Driver/asterisksql.php b/lib/Driver/asterisksql.php index 60cb27f5e..799b70b7c 100644 --- a/lib/Driver/asterisksql.php +++ b/lib/Driver/asterisksql.php @@ -20,7 +20,7 @@ * The table structure can be created by the scripts/sql/operator_foo.sql * script. * - * $Horde: incubator/operator/lib/Driver/asterisksql.php,v 1.6 2008/07/01 20:29:11 bklang Exp $ + * $Horde: incubator/operator/lib/Driver/asterisksql.php,v 1.7 2008/07/01 22:25:01 bklang Exp $ * * Copyright 2007-2008 The Horde Project (http://www.horde.org/) * @@ -155,7 +155,7 @@ class Operator_Driver_asterisksql extends Operator_Driver { * method will additionall return PEAR_Error * on failure. */ - function getCallStatsByMonth($start, $end, $accountcode = null, + function getMonthlyCallStats($start, $end, $accountcode = null, $dcontext = null) { if (!is_a($start, 'Horde_Date') || !is_a($end, 'Horde_Date')) { @@ -294,6 +294,23 @@ class Operator_Driver_asterisksql extends Operator_Driver { return $stats; } + function getAccountCodes() + { + /* Make sure we have a valid database connection. */ + $this->_connect(); + + $sql = 'SELECT DISTINCT(accountcode) FROM ' . $this->_params['table'] . + ' ORDER BY accountcode'; + Horde::logMessage(sprintf('Operator_Driver_asterisksql::getAccountCodes(): %s', $sql), __FILE__, __LINE__, PEAR_LOG_DEBUG); + $res = $this->_db->getCol($sql, 'accountcode'); + if (is_a($res, 'PEAR_Error')) { + Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR); + return PEAR::raiseError(_("Internal error. Details have been logged for the administrator.")); + } + + return $res; + } + /** * Attempts to open a connection to the SQL server. * diff --git a/lib/Form/SearchCDR.php b/lib/Form/SearchCDR.php index fb768266a..9e7153d06 100644 --- a/lib/Form/SearchCDR.php +++ b/lib/Form/SearchCDR.php @@ -2,7 +2,7 @@ /** * SearchCDRForm Class * - * $Horde: incubator/operator/lib/Form/SearchCDR.php,v 1.2 2008/06/27 17:17:11 bklang Exp $ + * $Horde: incubator/operator/lib/Form/SearchCDR.php,v 1.3 2008/07/01 22:25:01 bklang Exp $ * * Copyright 2008 Alkaloid Networks LLC * @@ -61,7 +61,8 @@ class SearchCDRForm extends Horde_Form { $params = array($start_year, $end_year, $picker, $format_in, $format_out, $show_seconds); - $this->addVariable(_("Account Code"), 'accountcode', 'text', false, false, _("An empty account code will select records with an empty account code. To search for all records account codes use %")); + $this->addVariable(_("Account Code"), 'accountcode', 'enum', false, false, null, array(Operator::getAccountCodes())); + //$this->addVariable(_("Account Code"), 'accountcode', 'text', false, false, _("An empty account code will select records with an empty account code. To search for all records account codes use %")); $this->addVariable(_("Destination Context"), 'dcontext', 'text', false, false, _("An empty destination context will select records with an empty destination context. To search for all destination contexts use %")); $this->addVariable(_("Start Date/Time"), 'startdate', 'datetime', true, false, null, $params); $this->addVariable(_("End Date/Time"), 'enddate', 'datetime', true, false, null, $params); diff --git a/lib/Operator.php b/lib/Operator.php index eb493b20e..b73b2e2da 100644 --- a/lib/Operator.php +++ b/lib/Operator.php @@ -2,7 +2,7 @@ /** * Operator Base Class. * - * $Horde: incubator/operator/lib/Operator.php,v 1.2 2008/07/01 20:29:29 bklang Exp $ + * $Horde: incubator/operator/lib/Operator.php,v 1.3 2008/07/01 22:25:00 bklang Exp $ * * Copyright 2008 Alkaloid Networks LLC * @@ -82,4 +82,46 @@ class Operator { break; } } + + /** + * Get a list of valid account codes from the database + * + * @return array List of valid account codes. + */ + function getAccountCodes() + { + global $cache, $operator_driver; + + // Use 0 lifetime to allow cache lifetime to be set when storing the + // object. + $accountcodes = $cache->get('operator-accountcodes', 0); + if ($accountcodes === false) { + $accountcodes = $operator_driver->getAccountCodes(); + + // Add an option to select all accounts + $keys = $accountcodes; + array_unshift($keys, '%'); + $values = $accountcodes; + array_unshift($values, _("-- All Accounts --")); + + if ($index = array_search('', $values)) { + $values[$index] = _("-- Empty Accountcode --"); + } + + // Make the index of each array entry the same as its value + $accountcodes = array_combine($keys, $values); + + $res = $cache->set('operator-accountcodes', + serialize($accountcodes), 600); + if ($res === false) { + Horde::logMessage('The cache system has experienced an error. Unable to continue.', __FILE__, __LINE__, PEAR_LOG_ERR); + $notification->push(_("Internal error. Details have been logged for the administrator.")); + $accountcodes = array(); + } + } else { + $accountcodes = unserialize($accountcodes); + } + + return $accountcodes; + } } diff --git a/search.php b/search.php index 66d56090d..e14966f2c 100644 --- a/search.php +++ b/search.php @@ -1,6 +1,6 @@ * @@ -24,17 +24,14 @@ $vars = Variables::getDefaultVariables(); $form = new SearchCDRForm($vars); if ($form->isSubmitted() && $form->validate($vars, true)) { - if ($vars->exists('accountcode')) { - $accountcode = $vars->get('accountcode'); - } else { - // Search all accounts. - $accountcode = null; - } + $accountcode = $vars->get('accountcode'); + $dcontext = $vars->get('dcontext'); $start = new Horde_Date($vars->get('startdate')); $end = new Horde_Date($vars->get('enddate')); - $data = $operator_driver->getData($start, $end, $accountcode); + $data = $operator_driver->getData($start, $end, $accountcode, $dcontext); $_SESSION['operator']['lastsearch']['params'] = array( 'accountcode' => $vars->get('accountcode'), + 'dcontext' => $vars->get('dcontext'), 'startdate' => $vars->get('startdate'), 'enddate' => $vars->get('enddate')); $_SESSION['operator']['lastsearch']['data'] = $data; diff --git a/viewgraph.php b/viewgraph.php index 007720a43..1a4bea0e9 100644 --- a/viewgraph.php +++ b/viewgraph.php @@ -1,6 +1,6 @@ * @@ -24,28 +24,18 @@ $vars = Variables::getDefaultVariables(); $form = new SearchCDRForm($vars); if ($form->isSubmitted() && $form->validate($vars, true)) { - if ($vars->exists('accountcode')) { - $accountcode = $vars->get('accountcode'); - } else { - // Search all accounts. - $accountcode = null; - } - if ($vars->exists('dcontext')) { - $dcontext = $vars->get('dcontext'); - } else { - // Search all contexts. - $dcontext = null; - } + $accountcode = $vars->get('accountcode'); + $dcontext = $vars->get('dcontext'); $start = new Horde_Date($vars->get('startdate')); $end = new Horde_Date($vars->get('enddate')); // See if we have cached data - $cachekey = md5(serialize(array('getCallStatsByMonth', $start, $end, + $cachekey = md5(serialize(array('getMonthlyCallStats', $start, $end, $accountcode, $dcontext))); // Use 0 lifetime to allow cache lifetime to be set when storing the object $stats = $cache->get($cachekey, 0); if ($stats === false) { - $stats = $operator_driver->getCallStatsByMonth($start, $end, + $stats = $operator_driver->getMonthlyCallStats($start, $end, $accountcode, $dcontext); $res = $cache->set($cachekey, serialize($stats), 600); if ($res === false) { @@ -59,6 +49,7 @@ if ($form->isSubmitted() && $form->validate($vars, true)) { } $_SESSION['operator']['lastsearch']['params'] = array( 'accountcode' => $vars->get('accountcode'), + 'dcontext' => $vars->get('dcontext'), 'startdate' => $vars->get('startdate'), 'enddate' => $vars->get('enddate')); } else {