* 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 {
$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);
/**
* 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,
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');
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;
throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
- return array_merge($data, $res);
+ return array($res, $data);
}
/**
$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);
}
}
$renderer = new Horde_Form_Renderer();
$vars = Horde_Variables::getDefaultVariables();
+$data = array();
if (!$vars->exists('rowstart')) {
$rowstart = 0;
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'),
'startdate' => $vars->get('startdate'),
'enddate' => $vars->get('enddate'));
$_SESSION['operator']['lastdata'] = $data;
+
} catch (Exception $e) {
//$notification->push(_("Invalid date requested."));
$notification->push($e);
// 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'));
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">