$cache = &$GLOBALS['cache'];
// Work around warnings in Image_Graph
-error_reporting(E_NONE);
-ini_set("display_errors", 0);
+// Needed for Image_Graph <= 0.7.2 and Image_Canvas <= 0.3.2
+//error_reporting(E_NONE);
+//ini_set("display_errors", 0);
#setlocale(LC_ALL, Horde_Nls::select());
#setlocale(LC_ALL, 'en_US');
if (!empty($conf['ttf_font'])) {
// add a TrueType font
$Font =& $graph->addNew('ttf_font', $conf['ttf_font']);
- // set the font size to 11 pixels
+ // Set the font size to 11 pixels. Yes, 8 really does mean 11
$Font->setSize(8);
$graph->setFont($Font);
}
function _format($number)
{
+ // Only show the decimal if the value has digits after the decimal
if (($number - (int)$number) == 0) {
return money_format('%!.0n', $number);
} else {
$currency = '';
$suffix = '';
if ($showCurrency) {
+ // FIXME: Make currency configurable
//$currency = 'ISK ';
$currency = '';
}
* Search the database for call detail records, taking permissions into
* consideration.
*
- * @return boolean|PEAR_Error True on success, PEAR_Error on failure.
+ * @return boolean True on success
+ * @throws Operator_Exception
*/
function getRecords($start, $end, $accountcode = null, $dcontext = null,
$rowstart = 0, $rowlimit = 100)
return $this->_getRecords($start, $end, $accountcode, $dcontext,
$rowstart, $rowlimit);
}
- return PEAR::raiseError(_("You do not have permission to view call detail records for that account code."));
+ throw new Operator_Exception(_("You do not have permission to view call detail records for that account code."));
}
/**
* @param string dcontext Destination of calls. Defaults to null.
*
*
- * @return array|PEAR_Error Array of call statistics. The key of each
+ * @return array Array of call statistics. The key of each
* element is the month name in date('Y-m')
* format and the value being an array of
- * statistics for calls placed that month. This
- * method will additionall return PEAR_Error
- * on failure.
+ * statistics for calls placed that month.
+ * @throws Operator_Exception|Horde_Date_Exception
*/
function getMonthlyCallStats($start, $end, $accountcode = null,
$dcontext = null){
$dcontext);
}
- return PEAR::raiseError(_("You do not have permission to view call detail records for that account code."));
+ throw new Operator_Exception(_("You do not have permission to view call detail records for that account code."));
}
/**
/**
* Get call detail records from the database
*
- * @return boolean|PEAR_Error True on success, PEAR_Error on failure.
+ * @return boolean
+ * @throws Operator_Exception|Horde_Date_Exception
*/
function _getRecords($start, $end, $accountcode = null, $dcontext = null,
$rowstart = 0, $rowlimit = 100)
if (!is_numeric($rowstart)) {
Horde::logMessage('Invalid start row requested.', __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal error. Details have been logged for the administrator."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
if (!is_numeric($rowlimit)) {
Horde::logMessage('Invalid row limit requested.', __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal error. Details have been logged for the administrator."));
+ 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);
- if (is_a($start, 'PEAR_Error')) {
- return $start;
- }
}
$filter[] = 'calldate >= ?';
$values[] = $start->strftime('%Y-%m-%d %T');
// End Date
if (!is_a($end, 'Horde_Date')) {
$end = new Horde_Date($end);
- if (is_a($end, 'PEAR_Error')) {
- return $end;
- }
}
$filter[] = 'calldate < ?';
$values[] = $end->strftime('%Y-%m-%d %T');
$res = $this->_db->limitQuery($sql, $rowstart, $rowlimit, $values);
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."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
$data = array();
$res = $this->_db->getRow($sql, $values, DB_FETCHMODE_ASSOC);
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."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
return array_merge($data, $res);
* @param string dcontext Destination of calls. Defaults to null.
*
*
- * @return array|PEAR_Error Array of call statistics. The key of each
+ * @return array Array of call statistics. The key of each
* element is the month name in date('Y-m')
* format and the value being an array of
- * statistics for calls placed that month. This
- * method will additionall return PEAR_Error
- * on failure.
+ * statistics for calls placed that month.
+ * @throws Operator_Exception|Horde_Date_Exception
*/
function _getMonthlyCallStats($start, $end, $accountcode = null,
$dcontext = null)
{
if (!is_a($start, 'Horde_Date') || !is_a($end, 'Horde_Date')) {
Horde::logMessage('Start ane end date must be Horde_Date objects.', __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal error. Details have been logged for the administrator."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
/* Make sure we have a valid database connection. */
$numcalls_res = $this->_db->getAll($sql, $values, DB_FETCHMODE_ASSOC);
if (is_a($numcalls_res, 'PEAR_Error')) {
Horde::logMessage($numcalls_res, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal error. Details have been logged for the administrator."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
$sql = sprintf($minutes_query, $filterstring);
$minutes_res = $this->_db->getAll($sql, $values, DB_FETCHMODE_ASSOC);
if (is_a($minutes_res, 'PEAR_Error')) {
Horde::logMessage($minutes_res, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal error. Details have been logged for the administrator."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
$sql = sprintf($failed_query, $filterstring);
$failed_res = $this->_db->getAll($sql, $values, DB_FETCHMODE_ASSOC);
if (is_a($failed_res, 'PEAR_Error')) {
Horde::logMessage($failed_res, __FILE__, __LINE__, PEAR_LOG_ERR);
- return PEAR::raiseError(_("Internal error. Details have been logged for the administrator."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
// Normalize the results from the database. This is done because
$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."));
+ throw new Operator_Exception(_("Internal error. Details have been logged for the administrator."));
}
return $res;
if (empty($dcontext)) {
$dcontext = '%';
}
- $start = new Horde_Date($vars->get('startdate'));
- $end = new Horde_Date($vars->get('enddate'));
- if (is_a($start, 'PEAR_Error') || is_a($end, 'PEAR_Error')) {
- $notification->push(_("Invalid date requested."));
- } else {
+ 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']);
- if (is_a($data, 'PEAR_Error')) {
- $notification->push($data);
- $data = array();
- }
+
$_SESSION['operator']['lastsearch']['params'] = array(
'accountcode' => $vars->get('accountcode'),
'dcontext' => $vars->get('dcontext'),
'startdate' => $vars->get('startdate'),
'enddate' => $vars->get('enddate'));
$_SESSION['operator']['lastdata'] = $data;
+ } catch (Exception $e) {
+ //$notification->push(_("Invalid date requested."));
+ $notification->push($e);
+ $data = array();
}
} else {
if (isset($_SESSION['operator']['lastsearch']['params'])) {
if (empty($dcontext)) {
$dcontext = '%';
}
- $start = new Horde_Date($vars->get('startdate'));
- $end = new Horde_Date($vars->get('enddate'));
- if (is_a($start, 'PEAR_Error') || is_a($end, 'PEAR_Error')) {
- $notification->push(_("Invalid date requested."));
- } elseif (($end->month - $start->month) == 0 &&
- ($end->year - $start->year) == 0) {
- $notification->push(_("You must select a range that includes more than one month to view these graphs."));
- } else {
- // See if we have cached data
- $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->getMonthlyCallStats($start,
- $end,
- $accountcode,
- $dcontext);
- if (is_a($stats, 'PEAR_Error')) {
- $notification->push($stats);
- $stats = array();
- } else {
+ try {
+ $start = new Horde_Date($vars->get('startdate'));
+ $end = new Horde_Date($vars->get('enddate'));
+
+ if (($end->month - $start->month) == 0 &&
+ ($end->year - $start->year) == 0) {
+ // FIXME: This should not cause an error but is due to a bug in
+ // Image_Graph.
+ $notification->push(_("You must select a range that includes more than one month to view these graphs."));
+ } else {
+ // See if we have cached data
+ $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->getMonthlyCallStats($start,
+ $end,
+ $accountcode,
+ $dcontext);
+
$res = $cache->set($cachekey, serialize($stats), 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."));
- unset($stats);
+ $stats = array();
}
+
+ } else {
+ // Cached data is stored serialized
+ $stats = unserialize($stats);
}
- } else {
- // Cached data is stored serialized
- $stats = unserialize($stats);
+ $_SESSION['operator']['lastsearch']['params'] = array(
+ 'accountcode' => $vars->get('accountcode'),
+ 'dcontext' => $vars->get('dcontext'),
+ 'startdate' => $vars->get('startdate'),
+ 'enddate' => $vars->get('enddate'));
}
- $_SESSION['operator']['lastsearch']['params'] = array(
- 'accountcode' => $vars->get('accountcode'),
- 'dcontext' => $vars->get('dcontext'),
- 'startdate' => $vars->get('startdate'),
- 'enddate' => $vars->get('enddate'));
+ } catch (Horde_Exception $e) {
+ //$notification->push(_("Invalid dates requested."));
+ $notification->push($e);
+ $stats = array();
}
} else {
if (isset($_SESSION['operator']['lastsearch']['params'])) {