Operator: Misc fixes
authorBen Klang <ben@alkaloid.net>
Tue, 12 Jan 2010 20:22:27 +0000 (15:22 -0500)
committerBen Klang <ben@alkaloid.net>
Tue, 12 Jan 2010 20:22:27 +0000 (15:22 -0500)
* 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
operator/lib/Driver/asterisksql.php
operator/lib/Form/SearchCDR.php
operator/search.php
operator/templates/search.inc

index af819a3..0fea285 100644 (file)
@@ -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);
index e990ca9..dd26b28 100644 (file)
@@ -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);
     }
 
     /**
index 58ca314..d54fc70 100644 (file)
@@ -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);
     }
 }
index 645e836..cba775c 100644 (file)
@@ -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'));
index 9951791..8bbb5b1 100644 (file)
@@ -1,8 +1,8 @@
 Call Statistics Summary:<br />
 <ul>
-<li>Total Calls: <?php echo $data['numcalls']; ?></li>
-<li>Total Minutes: <?php echo round($data['minutes'], 1); ?></li>
-<li>Failed Calls: <?php echo $data['failed']; ?></li>
+<li>Total Calls: <?php echo $stats['numcalls']; ?></li>
+<li>Total Minutes: <?php echo round($stats['minutes'], 1); ?></li>
+<li>Failed Calls: <?php echo $stats['failed']; ?></li>
 </ul>
 <br />
 <table class="striped">