Overview

Packages

  • None
  • Operator

Classes

  • ExportCDRForm
  • GraphCDRForm
  • Operator
  • Operator_Driver
  • Operator_Driver_asterisksql
  • SearchCDRForm
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * SearchCDRForm Class
  4:  *
  5:  * Copyright 2008 Alkaloid Networks LLC <http://projects.alkaloid.net>
  6:  *
  7:  * See the enclosed file LICENSE for license information (BSD). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
  9:  *
 10:  * @author  Ben Klang <ben@alkaloid.net>
 11:  * @package Operator
 12:  */
 13: 
 14: class SearchCDRForm extends Horde_Form {
 15: 
 16:     public function __construct($title, &$vars)
 17:     {
 18:         parent::__construct($vars, $title);
 19: 
 20:         // FIXME: Generate a list of clients from Turba?
 21:         //$clients =
 22: 
 23:         $now = time();
 24:         if (!$vars->exists('startdate')) {
 25:             // Default to the beginning of the previous calendar month
 26:             $startdate = array('day' => 1,
 27:                                'month' => date('n', $now),
 28:                                'year' => date('Y', $now),
 29:                                'hour' => 0,
 30:                                'minute' => 0,
 31:                                'second' => 0);
 32:             $vars->set('startdate', $startdate);
 33:         }
 34: 
 35:         if (!$vars->exists('enddate')) {
 36:             // Default to the end of the previous calendar month
 37:             $month = date('n', $now);
 38:             $year = date('Y', $now);
 39:             $lastday = Horde_Date_Utils::daysInMonth($month, $year);
 40:             $enddate = array('day' => $lastday,
 41:                              'month' => $month,
 42:                              'year' => $year,
 43:                              'hour' => 23,
 44:                              'minute' => 59,
 45:                              'second' => 59);
 46:             $vars->set('enddate', $enddate);
 47:         }
 48: 
 49:         try {
 50:             $accountcodes = Operator::getAccountCodes(true);
 51:         } catch (Exception $e) {
 52:             $GLOBALS['notification']->push($e);
 53:             $accountcodes = array();
 54:         }
 55: 
 56: 
 57:         // Parameters for Horde_Form_datetime
 58:         $start_year = date('Y', $now) - 5;
 59:         $end_year = '';
 60:         $picker = true;
 61:         $format_in = null;
 62:         $format_out = '%x';
 63:         $show_seconds = true;
 64:         $params = array($start_year, $end_year, $picker, $format_in,
 65:                         $format_out, $show_seconds);
 66: 
 67:         $this->addVariable(_("Account Code"), 'accountcode', 'enum', false,
 68:                            false, null, array($accountcodes));
 69:         $this->addVariable(_("Destination Context"), 'dcontext', 'text', false,
 70:                            false, _("An empty destination context will match all destination contexts."));
 71:         $this->addVariable(_("Start Date & Time"), 'startdate', 'datetime',
 72:                            true, false, null, $params);
 73:         $this->addVariable(_("End Date & Time"), 'enddate', 'datetime', true,
 74:                            false, null, $params);
 75:     }
 76: }
 77: 
 78: class GraphCDRForm extends SearchCDRForm
 79: {
 80:     public function __construct($title, &$vars)
 81:     {
 82:         parent::__construct($title, $vars);
 83: 
 84:         $graphtypes = Operator::getGraphInfo();
 85:         $graphs = array();
 86:         foreach ($graphtypes as $type => $info) {
 87:             $graphs[$type] = $info['title'];
 88:         }
 89: 
 90:         $this->addVariable(_("Graph"), 'graph', 'enum', true, false,
 91:                            null, array($graphs));
 92:     }
 93: }
 94: 
 95: class ExportCDRForm extends SearchCDRForm
 96: {
 97:     public function __construct($title, &$vars)
 98:     {
 99:         parent::__construct($title, $vars);
100: 
101:         $formats = array(
102:             Horde_Data::EXPORT_CSV => 'Comma-Delimited (CSV)',
103:             Horde_Data::EXPORT_TSV => 'Tab-Delimited',
104:         );
105: 
106:         $this->addVariable(_("Data Format"), 'format', 'enum', true, false,
107:                            null, array($formats));
108:     }
109: 
110:     public function execute()
111:     {
112:         global $operator;
113: 
114:         $start = new Horde_Date($this->_vars->get('startdate'));
115:         $end = new Horde_Date($this->_vars->get('enddate'));
116:         $accountcode = $this->_vars->get('accountcode');
117:         $dcontects = $this->_vars->get('dcontext');
118:         if (empty($dcontext)) {
119:             $dcontext = '%';
120:         }
121:         list($stats, $data) = $operator->driver->getRecords($start, $end,
122:                                                             $accountcode,
123:                                                             $dcontext, 0,
124:                                                             null);
125:         switch($this->_vars->get('format')) {
126:         case Horde_Data::EXPORT_CSV:
127:             $ext = 'csv';
128:             $fmt = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Data')->create('Csv');
129:             break;
130: 
131:         case Horde_Data::EXPORT_TSV:
132:             $ext = 'tsv';
133:             $fmt = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Data')->create('Tsv');
134:             break;
135: 
136:         default:
137:             throw new Operator_Exception(_("Invalid data format requested."));
138:             break;
139:         }
140: 
141:         $filename = 'export-' . uniqid() . '.' . $ext;
142:         $fmt->exportFile($filename, $data, true);
143:         exit;
144:     }
145: }
146: 
API documentation generated by ApiGen