* 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/)
*
* 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')) {
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.
*
/**
* 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 <http://projects.alkaloid.net>
*
$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);
/**
* 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 <http://projects.alkaloid.net>
*
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;
+ }
}
<?php
/**
- * $Horde: incubator/operator/search.php,v 1.2 2008/06/26 17:31:27 bklang Exp $
+ * $Horde: incubator/operator/search.php,v 1.3 2008/07/01 22:25:00 bklang Exp $
*
* Copyright 2008 Alkaloid Networks LLC <http://projects.alkaloid.net>
*
$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;
<?php
/**
- * $Horde: incubator/operator/viewgraph.php,v 1.3 2008/06/27 17:17:10 bklang Exp $
+ * $Horde: incubator/operator/viewgraph.php,v 1.4 2008/07/01 22:25:00 bklang Exp $
*
* Copyright 2008 Alkaloid Networks LLC <http://projects.alkaloid.net>
*
$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) {
}
$_SESSION['operator']['lastsearch']['params'] = array(
'accountcode' => $vars->get('accountcode'),
+ 'dcontext' => $vars->get('dcontext'),
'startdate' => $vars->get('startdate'),
'enddate' => $vars->get('enddate'));
} else {