From 87ddb89baac52825eec6a64afc5f39ef76e3342f Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Tue, 12 Jan 2010 15:22:27 -0500 Subject: [PATCH] Operator: Misc fixes * PHPdoc change to Operator_Driver#getRecords() * Ensure start date is before end date * Move date object checking to parent class * Fix return type of Operator_Driver#getRecords() * Add warning when number of calls in search is exceeded --- operator/lib/Driver.php | 19 +++++++++++++++++-- operator/lib/Driver/asterisksql.php | 17 ++++------------- operator/lib/Form/SearchCDR.php | 4 ++-- operator/search.php | 17 +++++++++++++---- operator/templates/search.inc | 6 +++--- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/operator/lib/Driver.php b/operator/lib/Driver.php index af819a3cf..0fea28529 100644 --- a/operator/lib/Driver.php +++ b/operator/lib/Driver.php @@ -19,12 +19,27 @@ class Operator_Driver { * Search the database for call detail records, taking permissions into * consideration. * - * @return boolean True on success + * @return array [0] contains summary statistics; [1] is an array of the + * actual call records. * @throws Operator_Exception */ function getRecords($start, $end, $accountcode = null, $dcontext = null, $rowstart = 0, $rowlimit = 100) { + // Start Date + if (!is_a($start, 'Horde_Date')) { + $start = new Horde_Date($start); + } + + // End Date + if (!is_a($end, 'Horde_Date')) { + $end = new Horde_Date($end); + } + + if ($start->compareDate($end) > 0) { + throw new Operator_Exception(_("\"Start\" date must be on or before \"End\" date.")); + } + if (empty($accountcode) || $accountcode == '%') { $permentry = 'operator:accountcodes'; } else { @@ -70,7 +85,7 @@ class Operator_Driver { $GLOBALS['perms']->hasPermission('operator:accountcodes', Horde_Auth::getAuth(), Horde_Perms::READ) || - $GLOBALS['perms']->hasPermission($permentry, Horde_Auth::getAuth(), + $GLOBALS['perms']->hasPermission($permentry, Horde_Auth::getAuth(), Horde_Perms::READ)) { return $this->_getMonthlyCallStats($start, $end, $accountcode, $dcontext); diff --git a/operator/lib/Driver/asterisksql.php b/operator/lib/Driver/asterisksql.php index e990ca959..dd26b28fe 100644 --- a/operator/lib/Driver/asterisksql.php +++ b/operator/lib/Driver/asterisksql.php @@ -74,7 +74,8 @@ class Operator_Driver_asterisksql extends Operator_Driver { /** * Get call detail records from the database * - * @return boolean + * @return array [0] contains summary statistics; [1] is an array of the + * actual call records. * @throws Operator_Exception|Horde_Date_Exception */ function _getRecords($start, $end, $accountcode = null, $dcontext = null, @@ -99,18 +100,8 @@ class Operator_Driver_asterisksql extends Operator_Driver { throw new Operator_Exception(_("Internal error. Details have been logged for the administrator.")); } - - // Start Date - if (!is_a($start, 'Horde_Date')) { - $start = new Horde_Date($start); - } $filter[] = 'calldate >= ?'; $values[] = $start->strftime('%Y-%m-%d %T'); - - // End Date - if (!is_a($end, 'Horde_Date')) { - $end = new Horde_Date($end); - } $filter[] = 'calldate < ?'; $values[] = $end->strftime('%Y-%m-%d %T'); @@ -144,7 +135,7 @@ class Operator_Driver_asterisksql extends Operator_Driver { Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR); throw new Operator_Exception(_("Internal error. Details have been logged for the administrator.")); } - + $data = array(); while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { $data[] = $row; @@ -164,7 +155,7 @@ class Operator_Driver_asterisksql extends Operator_Driver { throw new Operator_Exception(_("Internal error. Details have been logged for the administrator.")); } - return array_merge($data, $res); + return array($res, $data); } /** diff --git a/operator/lib/Form/SearchCDR.php b/operator/lib/Form/SearchCDR.php index 58ca31427..d54fc7059 100644 --- a/operator/lib/Form/SearchCDR.php +++ b/operator/lib/Form/SearchCDR.php @@ -68,7 +68,7 @@ class SearchCDRForm extends Horde_Form { $this->addVariable(_("Account Code"), 'accountcode', 'enum', false, false, null, array($accountcodes)); $this->addVariable(_("Destination Context"), 'dcontext', 'text', false, false, _("An empty destination context will match all destination contexts.")); - $this->addVariable(_("Start Date/Time"), 'startdate', 'datetime', true, false, null, $params); - $this->addVariable(_("End Date/Time"), 'enddate', 'datetime', true, false, null, $params); + $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/operator/search.php b/operator/search.php index 645e83604..cba775cea 100644 --- a/operator/search.php +++ b/operator/search.php @@ -19,6 +19,7 @@ require_once OPERATOR_BASE . '/lib/Form/SearchCDR.php'; $renderer = new Horde_Form_Renderer(); $vars = Horde_Variables::getDefaultVariables(); +$data = array(); if (!$vars->exists('rowstart')) { $rowstart = 0; @@ -42,9 +43,10 @@ if ($form->isSubmitted() && $form->validate($vars, true)) { try { $start = new Horde_Date($vars->get('startdate')); $end = new Horde_Date($vars->get('enddate')); - $data = $operator->driver->getRecords($start, $end, $accountcode, - $dcontext, $rowstart, - $GLOBALS['conf']['storage']['searchlimit']); + list($stats, $data) = $operator->driver->getRecords($start, $end, + $accountcode, + $dcontext, $rowstart, + $GLOBALS['conf']['storage']['searchlimit']); $_SESSION['operator']['lastsearch']['params'] = array( 'accountcode' => $vars->get('accountcode'), @@ -52,6 +54,7 @@ if ($form->isSubmitted() && $form->validate($vars, true)) { 'startdate' => $vars->get('startdate'), 'enddate' => $vars->get('enddate')); $_SESSION['operator']['lastdata'] = $data; + } catch (Exception $e) { //$notification->push(_("Invalid date requested.")); $notification->push($e); @@ -79,12 +82,18 @@ $pager = new Horde_Ui_Pager('page', $pager_vars, // Limit the domain list to the current page $data = array_slice($data, $page*$perpage, $perpage); +// See if we got the complete set of records +if ($stats['numcalls'] > $GLOBALS['conf']['storage']['searchlimit']) { + $msg = _("Number of calls exceeded search limit (%s). Try narrowing your search dates or exporting the data."); + $notification->push(sprintf($msg, $GLOBALS['conf']['storage']['searchlimit']), 'horde.warning'); +} + $title = _("Search Call Detail Records"); Horde::addScriptFile('stripe.js', 'horde', true); require OPERATOR_TEMPLATES . '/common-header.inc'; require OPERATOR_TEMPLATES . '/menu.inc'; - +$notification->notify(); $form->renderActive($renderer, $vars); $columns = unserialize($prefs->getValue('columns')); diff --git a/operator/templates/search.inc b/operator/templates/search.inc index 9951791e7..8bbb5b126 100644 --- a/operator/templates/search.inc +++ b/operator/templates/search.inc @@ -1,8 +1,8 @@ Call Statistics Summary:

-- 2.11.0