Overview

Packages

  • None
  • Operator

Classes

  • ExportCDRForm
  • GraphCDRForm
  • Operator
  • Operator_Driver
  • Operator_Driver_asterisksql
  • SearchCDRForm
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Operator Base Class.
  4:  *
  5:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Ben Klang <ben@alkaloid.net>
 11:  * @package Operator
 12:  */
 13: class Operator {
 14: 
 15:     /**
 16:      * Build Operator's list of menu items.
 17:      */
 18:     public static function getMenu($returnType = 'object')
 19:     {
 20:         global $conf, $registry, $browser, $print_link;
 21: 
 22:         $menu = new Horde_Menu(Horde_Menu::MASK_ALL);
 23:         $menu->add(Horde::url('viewgraph.php'), _("_View Graphs"), 'graphs.png', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
 24:         $menu->add(Horde::url('search.php'), _("_Search"), 'search.png');
 25: 
 26:         /* Export */
 27:         if ($GLOBALS['conf']['menu']['export']) {
 28:             $menu->add(Horde::url('export.php'), _("_Export"), 'data.png');
 29:         }
 30: 
 31:         if ($returnType == 'object') {
 32:             return $menu;
 33:         } else {
 34:             return $menu->render();
 35:         }
 36:     }
 37: 
 38:     public static function getColumns()
 39:     {
 40:         static $columns = array();
 41:         if (!empty($columns)) {
 42:             return $columns;
 43:         }
 44: 
 45:         $columns = array(
 46:             'accountcode' => _("Account Code"),
 47:             'src' => _("Source"),
 48:             'dst' => _("Destination"),
 49:             'dcontext' => _("Destination Context"),
 50:             'clid' => _("Caller ID"),
 51:             'channel' => _("Channel"),
 52:             'dstchannel' => _("Destination Channel"),
 53:             'lastapp' => _("Last Application"),
 54:             'lastdata' => _("Last Application Data"),
 55:             'start' => _("Start Time"),
 56:             'answer' => _("Answer Time"),
 57:             'end' => _("End Time"),
 58:             'duration' => _("Duration (sec)"),
 59:             'billsec' => _("Billable Duration (sec)"),
 60:             'disposition' => _("Disposition"),
 61:             'amaflags' => _("AMA Flag"),
 62:             'userfield' => _("User Defined Field"),
 63:             'uniqueid' => _("Unique ID"));
 64: 
 65:         return $columns;
 66:     }
 67: 
 68: 
 69:     public static function getColumnName($column)
 70:     {
 71:         $columns = Operator::getColumns();
 72:         return $columns[$column];
 73:     }
 74: 
 75:     public static function getAMAFlagName($flagid)
 76:     {
 77:         // See <asterisk/cdr.h> for definitions
 78:         switch($flagid) {
 79:         case 1:
 80:             return _("OMIT");
 81:             break;
 82:         case 2:
 83:             return _("BILLING");
 84:             break;
 85:         case 3:
 86:             return _("DOCUMENTATION");
 87:             break;
 88:         }
 89:     }
 90: 
 91:     /**
 92:      * Get a list of valid account codes from the database
 93:      *
 94:      * @return array  List of valid account codes.
 95:      */
 96:     public static function getAccountCodes($permfilter = false)
 97:     {
 98:         $operator = $GLOBALS['registry']->getApiInstance('operator', 'application');;
 99: 
100:         // Set up arrays for filtering
101:         $keys = $values = $operator->driver->getAccountCodes();
102:         $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
103: 
104:         if ($GLOBALS['registry']->isAdmin() ||
105:             $perms->hasPermission('operator:accountcodes',
106:                                              $GLOBALS['registry']->getAuth(),
107:                                              Horde_Perms::READ)) {
108:             $permfilter = false;
109:         }
110: 
111:         if (!$permfilter ||
112:             $perms->hasPermission('operator:accountcodes:%',
113:                                              $GLOBALS['registry']->getAuth(),
114:                                              Horde_Perms::READ)) {
115: 
116:             // Add an option to select all accounts
117:             array_unshift($keys, '%');
118:             array_unshift($values, _("-- All Accounts Combined --"));
119:         }
120: 
121:         // Only add the Empty value if it is exists in the backend
122:         if ($index = array_search('', $values)) {
123:            $values[$index] = _("-- Empty Accountcode --");
124:         }
125: 
126:         if ($permfilter) {
127:             // Filter the returned list of account codes through Permissions
128:             // if requested.
129:             $accountcodes = array();
130:             foreach ($keys as $index => $accountcode) {
131:                 if (empty($accountcode)) {
132:                     $permitem = 'operator:accountcodes';
133:                 } else {
134:                     $permitem = 'operator:accountcodes:' . $accountcode;
135:                 }
136: 
137:                 if ($GLOBALS['registry']->isAdmin() ||
138:                     $perms->hasPermission($permitem, $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) {
139:                     $accountcodes[$accountcode] = $values[$index];
140:                 }
141:             }
142: 
143:             if (empty($accountcodes)) {
144:                 throw new Operator_Exception(_("You do not have permission to view any accounts."));
145:             }
146:         } else {
147:             $accountcodes = array_combine($keys, $values);
148:         }
149:         return $accountcodes;
150:     }
151: 
152:     public static function getGraphInfo($graphid = null)
153:     {
154:         static $graphs;
155: 
156:         if (empty($graphs)) {
157:             $graphs = array(
158:                 'numcalls' => array(
159:                     'title' => _("Number of Calls by Month"),
160:                     'axisX' => _("Month"),
161:                     'axisY' => _("Number of Calls"),
162:                 ),
163:                 'minutes' => array(
164:                     'title' => _("Total Minutes Used by Month"),
165:                     'axisX' => _("Month"),
166:                     'axisY' => _("Minute"),
167:                     'numberformat' => '%0.1f',
168:                 ),
169: 
170: //                'failed' => array(
171: //                    'title' => _("Number of Failed Calls by Month"),
172: //                    'axisX' => _("Month"),
173: //                    'axisY' => _("Failed Calls"),
174: //                ),
175:              );
176:         }
177: 
178:         if ($graphid === null) {
179:             return $graphs;
180:         }
181: 
182:         if (isset($graphs[$graphid])) {
183:             return $graphs[$graphid];
184:         } else {
185:             throw new Operator_Exception(_("Invalid graph type."));
186:         }
187:     }
188: 
189: }
190: 
API documentation generated by ApiGen