Advertisement
Guest User

page.cdr.php

a guest
Feb 3rd, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 75.47 KB | None | 0 0
  1. <?php
  2. //      License for all code of this FreePBX module can be found in the license file inside the module directory
  3. //  Portions Copyright (C) 2011 Igor Okunev
  4. //  Portions Copyright (C) 2011 Mikael Carlsson
  5. //      Copyright 2013 Schmooze Com Inc.
  6. //
  7. if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
  8. if(isset($_POST['need_csv'])) {
  9.         //CDRs are ghetto!!
  10.         ob_clean();
  11. }
  12.  
  13. global $amp_conf, $db;
  14. // Are a crypt password specified? If not, use the supplied.
  15. $REC_CRYPT_PASSWORD = (isset($amp_conf['AMPPLAYKEY']) && trim($amp_conf['AMPPLAYKEY']) != "")?trim($amp_conf['AMPPLAYKEY']):'TheWindCriesMary';
  16. $dispnum = "cdr";
  17. $db_result_limit = 100;
  18.  
  19. // Check if cdr database and/or table is set, if not, use our default settings
  20. $db_name = !empty($amp_conf['CDRDBNAME'])?$amp_conf['CDRDBNAME']:"asteriskcdrdb";
  21. $db_table_name = !empty($amp_conf['CDRDBTABLENAME'])?$amp_conf['CDRDBTABLENAME']:"cdr";
  22. $system_monitor_dir = isset($amp_conf['ASTSPOOLDIR'])?$amp_conf['ASTSPOOLDIR']."/monitor":"/var/spool/asterisk/monitor";
  23.  
  24. // if CDRDBHOST and CDRDBTYPE are not empty then we assume an external connection and don't use the default connection
  25. //
  26. if (!empty($amp_conf["CDRDBHOST"]) && !empty($amp_conf["CDRDBTYPE"])) {
  27.         $db_hash = array('mysql' => 'mysql', 'postgres' => 'pgsql');
  28.         $db_type = $db_hash[$amp_conf["CDRDBTYPE"]];
  29.         $db_host = $amp_conf["CDRDBHOST"];
  30.         $db_port = empty($amp_conf["CDRDBPORT"]) ? '' :  ':' . $amp_conf["CDRDBPORT"];
  31.         $db_user = empty($amp_conf["CDRDBUSER"]) ? $amp_conf["AMPDBUSER"] : $amp_conf["CDRDBUSER"];
  32.         $db_pass = empty($amp_conf["CDRDBPASS"]) ? $amp_conf["AMPDBPASS"] : $amp_conf["CDRDBPASS"];
  33.         $datasource = $db_type . '://' . $db_user . ':' . $db_pass . '@' . $db_host . $db_port . '/' . $db_name;
  34.         $dbcdr = DB::connect($datasource); // attempt connection
  35.         if(DB::isError($dbcdr)) {
  36.                 die_freepbx($dbcdr->getDebugInfo());
  37.         }
  38. } else {
  39.         $dbcdr = $db;
  40. }
  41.  
  42. // For use in encrypt-decrypt of path and filename for the recordings
  43. include_once("crypt.php");
  44. switch ($action) {
  45.         case 'cdr_play':
  46.         case 'cdr_audio':
  47.         include_once("$action.php");
  48.                 exit;
  49.                 break;
  50.         case 'download_audio':
  51.                         $file = $db->getOne('SELECT recordingfile FROM ' . $db_name.'.'.$db_table_name . ' WHERE uniqueid = ?',
  52.                          array($_REQUEST['cdr_file']));
  53.                         db_e($file);
  54.                         if ($file) {
  55.                                 $rec_parts = explode('-',$file);
  56.                                 $fyear = substr($rec_parts[3],0,4);
  57.                                 $fmonth = substr($rec_parts[3],4,2);
  58.                                 $fday = substr($rec_parts[3],6,2);
  59.                                 $monitor_base = $amp_conf['MIXMON_DIR'] ? $amp_conf['MIXMON_DIR'] : $amp_conf['ASTSPOOLDIR'] . '/monitor';
  60.                                 $file = "$monitor_base/$fyear/$fmonth/$fday/" . $file;
  61.                                 download_file($file, '', '', true);
  62.                         }
  63.                         exit;
  64.                 break;
  65.         default:
  66.                 break;
  67. }
  68.  
  69. // FREEPBX-8845
  70. foreach ($_POST as $k => $v) {
  71.         $_POST[$k] = preg_replace('/;/', ' ', $dbcdr->escapeSimple($v));
  72. }
  73.  
  74. $h_step = 30;
  75. if(!isset($_POST['need_csv'])) {
  76. ?>
  77.         <h3><?php echo _('CDR Reports'); ?></h3><hr>
  78.         <div id="maincdr">
  79.         <table class="cdr">
  80.         <tr><td>
  81.                 <form method="post" enctype="application/x-www-form-urlencoded">
  82.                 <fieldset>
  83.                 <legend class="title"><?php echo _("Call Detail Record Search")?></legend>
  84.                         <table width="100%">
  85.                         <tr>
  86.                                 <th><?php echo _("Order By")?></th>
  87.                                 <th><?php echo _("Search conditions")?></th>
  88.                                 <th>&nbsp;</th>
  89.                         </tr>
  90.                         <tr>
  91.                                 <?php $calldate_tooltip = _("Select time span for your report. You can select Date, Month, Year, Hour and Minute to narrow your search");?>
  92.                                 <td><input <?php if (empty($_POST['order']) || $_POST['order'] == 'calldate') { echo 'checked="checked"'; } ?> type="radio" name="order" value="calldate" />&nbsp;<?php echo "<a href=\"#\" class=\"info\">"._("Call Date")."<span>".$calldate_tooltip."</span></a>"?>:</td>
  93.                                 <td><?php echo _("From")?>:
  94.                                 <input type="text" name="startday" id="startday" size="2" maxlength="2" value="<?php if (isset($_POST['startday'])) { echo htmlspecialchars($_POST['startday']); } else { echo '01'; } ?>" />
  95.                                 <select name="startmonth" id="startmonth">
  96. <?php
  97.                                 $months = array('01' => _('January'), '02' => _('February'), '03' => _('March'), '04' => _('April'), '05' => _('May'), '06' => _('June'), '07' => _('July'), '08' => _('August'), '09' => _('September'), '10' => _('October'), '11' => _('November'), '12' => _('December'));
  98.                                 foreach ($months as $i => $month) {
  99.                                         if ((empty($_POST['startmonth']) && date('m') == $i) || (isset($_POST['startmonth']) && $_POST['startmonth'] == $i)) {
  100.                                                 echo "<option value=\"$i\" selected=\"selected\">$month</option>\n";
  101.                                         } else {
  102.                                                 echo "<option value=\"$i\">$month</option>\n";
  103.                                         }
  104.                                 }
  105. ?>
  106.                                 </select>
  107.                                 <select name="startyear" id="startyear">
  108. <?php
  109.                                 for ( $i = 2000; $i <= date('Y'); $i++) {
  110.                                         if ((empty($_POST['startyear']) && date('Y') == $i) || (isset($_POST['startyear']) && $_POST['startyear'] == $i)) {
  111.                                                 echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  112.                                         } else {
  113.                                                 echo "<option value=\"$i\">$i</option>\n";
  114.                                         }
  115.                                 }
  116. ?>
  117.                                 </select>
  118.                                 <input type="text" name="starthour" id="starthour" size="2" maxlength="2" value="<?php if (isset($_POST['starthour'])) { echo htmlspecialchars($_POST['starthour']); } else { echo '00'; } ?>" />:
  119.                                 <input type="text" name="startmin" id="startmin" size="2" maxlength="2" value="<?php if (isset($_POST['startmin'])) { echo htmlspecialchars($_POST['startmin']); } else { echo '00'; } ?>" /><?php echo _("To")?>:
  120.                                 <input type="text" name="endday" id="endday" size="2" maxlength="2" value="<?php if (isset($_POST['endday'])) { echo htmlspecialchars($_POST['endday']); } else { echo '31'; } ?>" />
  121.                                 <select name="endmonth" id="endmonth">
  122. <?php
  123.                                 foreach ($months as $i => $month) {
  124.                                 if ((empty($_POST['endmonth']) && date('m') == $i) || (isset($_POST['endmonth']) && $_POST['endmonth'] == $i)) {
  125.                         echo "<option value=\"$i\" selected=\"selected\">$month</option>\n";
  126.                                         } else {
  127.                                 echo "<option value=\"$i\">$month</option>\n";
  128.                                 }
  129.                                 }
  130. ?>
  131. </select>
  132. <select name="endyear" id="endyear">
  133. <?php
  134. for ( $i = 2000; $i <= date('Y'); $i++) {
  135.         if ((empty($_POST['endyear']) && date('Y') == $i) || (isset($_POST['endyear']) && $_POST['endyear'] == $i)) {
  136.                 echo "        <option value=\"$i\" selected=\"selected\">$i</option>\n";
  137.         } else {
  138.                 echo "        <option value=\"$i\">$i</option>\n";
  139.         }
  140. }
  141. ?>
  142. </select>
  143.         <input type="text" name="endhour" id="endhour" size="2" maxlength="2" value="<?php if (isset($_POST['endhour'])) { echo htmlspecialchars($_POST['endhour']); } else { echo '23'; } ?>" />:
  144.         <input type="text" name="endmin" id="endmin" size="2" maxlength="2" value="<?php if (isset($_POST['endmin'])) { echo htmlspecialchars($_POST['endmin']); } else { echo '59'; } ?>" />
  145.         </td>
  146. <td rowspan="10" valign='top' align='right'>
  147. <fieldset>
  148. <legend class="title"><?php echo _("Extra options")?></legend>
  149. <table>
  150. <tr>
  151. <td><?php echo _("Report type")?> : </td>
  152. <td>
  153. <input <?php if ( (empty($_POST['need_html']) && empty($_POST['need_chart']) && empty($_POST['need_chart_cc']) && empty($_POST['need_csv'])) || ( ! empty($_POST['need_html']) &&  $_POST['need_html'] == 'true' ) ) { echo 'checked="checked"'; } ?> type="checkbox" name="need_html" value="true" /> : <?php echo _("CDR search")?><br />
  154. <input <?php if ( ! empty($_POST['need_csv']) && $_POST['need_csv'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="need_csv" value="true" /> : <?php echo _("CSV file")?><br/>
  155. <input <?php if ( ! empty($_POST['need_chart']) && $_POST['need_chart'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="need_chart" value="true" /> : <?php echo _("Call Graph")?><br />
  156. <!--
  157. <input <?php if ( ! empty($_POST['need_chart_cc']) && $_POST['need_chart_cc'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="need_chart_cc" value="true" /> : <?php echo _("Concurrent Calls")?><br />
  158. -->
  159. </td>
  160. </tr>
  161. <tr>
  162. <td><label for="Result limit"><?php echo _("Result limit")?> : </label></td>
  163. <td>
  164. <input value="<?php
  165. if (isset($_POST['limit']) ) {
  166.         echo htmlspecialchars($_POST['limit']);
  167. } else {
  168.         echo $db_result_limit;
  169. } ?>" name="limit" size="6" />
  170. </td>
  171. </tr>
  172. </table>
  173. </fieldset>
  174. </td>
  175. </tr>
  176. <tr>
  177. <?php $cnum_tooltip = _("Search for calls based on CallerID Number. You can enter multiple numbers separated by a comma. This field support Asterisk regular expression. Example<br>");?>
  178. <?php $cnum_tooltip .= _("<b>_2XXN, _562., _.0075</b> = search for any match of these numbers<br>");?>
  179. <?php $cnum_tooltip .= _("<b>_!2XXN, _562., _.0075</b> = Search for any match <b>except</b> for these numbers");?>
  180. <?php $cnum_tooltip .= _("<br>Asterisk pattern matching<br>");?>
  181. <?php $cnum_tooltip .= _("<b>X</b> = matches any digit from 0-9<br>");?>
  182. <?php $cnum_tooltip .= _("<b>Z</b> = matches any digit from 1-9<br>");?>
  183. <?php $cnum_tooltip .= _("<b>N</b> = matches any digit from 2-9<br>");?>
  184. <?php $cnum_tooltip .= _("<b>[1237-9]</b> = matches any digit or letter in the brackets<br>(in this example, 1,2,3,7,8,9)<br>");?>
  185. <?php $cnum_tooltip .= _("<b>.</b> = wildcard, matches one or more characters<br>");?>
  186. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'cnum') { echo 'checked="checked"'; } ?> type="radio" name="order" value="cnum" />&nbsp;<label for="cnum"><?php echo "<a href=\"#\" class=\"info\">"._("CallerID Number")."<span>$cnum_tooltip</span></a>"?>:</label></td>
  187. <td><input type="text" name="cnum" id="cnum" value="<?php if (isset($_POST['cnum'])) { echo htmlspecialchars($_POST['cnum']); } ?>" />
  188. <?php echo _("Not")?>:<input <?php if ( isset($_POST['cnum_neg'] ) && $_POST['cnum_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="cnum_neg" value="true" />
  189. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['cnum_mod']) || $_POST['cnum_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="cnum_mod" value="begins_with" />
  190. <?php echo _("Contains")?>:<input <?php if (isset($_POST['cnum_mod']) && $_POST['cnum_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="cnum_mod" value="contains" />
  191. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['cnum_mod']) && $_POST['cnum_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="cnum_mod" value="ends_with" />
  192. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['cnum_mod']) && $_POST['cnum_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="cnum_mod" value="exact" />
  193. </td>
  194. </tr>
  195.  
  196. <tr>
  197. <?php $cnam_tooltip = _("Select CallerID Name to search for.");?>
  198. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'cnam') { echo 'checked="checked"'; } ?> type="radio" name="order" value="cnam" />&nbsp;<label for="cnam"><?php echo "<a href=\"#\" class=\"info\">"._("CallerID Name")."<span>$cnam_tooltip</span></a>"?>:</label></td>
  199. <td><input type="text" name="cnam" id="cnam" value="<?php if (isset($_POST['cnam'])) { echo htmlspecialchars($_POST['cnam']); } ?>" />
  200. <?php echo _("Not")?>:<input <?php if ( isset($_POST['cnam_neg'] ) && $_POST['cnam_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="cnam_neg" value="true" />
  201. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['cnam_mod']) || $_POST['cnam_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="cnam_mod" value="begins_with" />
  202. <?php echo _("Contains")?>:<input <?php if (isset($_POST['cnam_mod']) && $_POST['cnam_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="cnam_mod" value="contains" />
  203. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['cnam_mod']) && $_POST['cnam_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="cnam_mod" value="ends_with" />
  204. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['cnam_mod']) && $_POST['cnam_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="cnam_mod" value="exact" />
  205. </td>
  206. </tr>
  207.  
  208. <tr>
  209. <?php $obcnum_tooltip = _("Search for calls based on outbound CID used. You can enter multiple numbers separated by a comma. This field support Asterisk regular expression. Example<br>");?>
  210. <?php $obcnum_tooltip .= _("<b>_2XXN, _562., _.0075</b> = search for any match of these numbers<br>");?>
  211. <?php $obcnum_tooltip .= _("<b>_!2XXN, _562., _.0075</b> = Search for any match <b>except</b> for these numbers");?>
  212. <?php $obcnum_tooltip .= _("<br>Asterisk pattern matching<br>");?>
  213. <?php $obcnum_tooltip .= _("<b>X</b> = matches any digit from 0-9<br>");?>
  214. <?php $obcnum_tooltip .= _("<b>Z</b> = matches any digit from 1-9<br>");?>
  215. <?php $obcnum_tooltip .= _("<b>N</b> = matches any digit from 2-9<br>");?>
  216. <?php $obcnum_tooltip .= _("<b>[1237-9]</b> = matches any digit or letter in the brackets<br>(in this example, 1,2,3,7,8,9)<br>");?>
  217. <?php $obcnum_tooltip .= _("<b>.</b> = wildcard, matches one or more characters<br>");?>
  218. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'outbound_cnum') { echo 'checked="checked"'; } ?> type="radio" name="order" value="outbound_cnum" />&nbsp;<label for="outbound_cnum"><?php echo "<a href=\"#\" class=\"info\">"._("Outbound CallerID Number")."<span>$obcnum_tooltip</span></a>"?>:</label></td>
  219. <td><input type="text" name="outbound_cnum" id="outbound_cnum" value="<?php if (isset($_POST['outbound_cnum'])) { echo htmlspecialchars($_POST['outbound_cnum']); } ?>" />
  220. <?php echo _("Not")?>:<input <?php if ( isset($_POST['outbound_cnum_neg'] ) && $_POST['outbound_cnum_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="outbound_cnum_neg" value="true" />
  221. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['outbound_cnum_mod']) || $_POST['outbound_cnum_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="outbound_cnum_mod" value="begins_with" />
  222. <?php echo _("Contains")?>:<input <?php if (isset($_POST['outbound_cnum_mod']) && $_POST['outbound_cnum_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="outbound_cnum_mod" value="contains" />
  223. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['outbound_cnum_mod']) && $_POST['outbound_cnum_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="outbound_cnum_mod" value="ends_with" />
  224. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['outbound_cnum_mod']) && $_POST['outbound_cnum_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="outbound_cnum_mod" value="exact" />
  225. </td>
  226. </tr>
  227.  
  228. <tr>
  229. <?php $did_tooltip = _("Search for a DID.");?>
  230. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'did') { echo 'checked="checked"'; } ?> type="radio" name="order" value="did" />&nbsp;<label for="did"><?php echo "<a href=\"#\" class=\"info\">"._("DID")."<span>$did_tooltip</span></a>"?></label></td>
  231. <td><input type="text" name="did" id="did" value="<?php if (isset($_POST['did'])) { echo htmlspecialchars($_POST['did']); } ?>" />
  232. <?php echo _("Not")?>:<input <?php if ( isset($_POST['did_neg'] ) && $_POST['did_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="did_neg" value="true" />
  233. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['did_mod']) || $_POST['did_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="did_mod" value="begins_with" />
  234. <?php echo _("Contains")?>:<input <?php if (isset($_POST['did_mod']) && $_POST['did_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="did_mod" value="contains" />
  235. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['did_mod']) && $_POST['did_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="did_mod" value="ends_with" />
  236. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['did_mod']) && $_POST['did_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="did_mod" value="exact" />
  237. </td>
  238. </tr>
  239. <tr>
  240. <?php $destination_tooltip = _("Search for destination calls. You can enter multiple sources separated by a comma. This field support Asterisk regular expression. Example<br>");?>
  241. <?php $destination_tooltip .= _("<b>_2XXN, _562., _.0075</b> = search for any match of these numbers<br>");?>
  242. <?php $destination_tooltip .= _("<b>_!2XXN, _562., _.0075</b> = Search for any match <b>except</b> for these numbers");?>
  243. <?php $destination_tooltip .= _("<br>Asterisk pattern matching<br>");?>
  244. <?php $destination_tooltip .= _("<b>X</b> = matches any digit from 0-9<br>");?>
  245. <?php $destination_tooltip .= _("<b>Z</b> = matches any digit from 1-9<br>");?>
  246. <?php $destination_tooltip .= _("<b>N</b> = matches any digit from 2-9<br>");?>
  247. <?php $destination_tooltip .= _("<b>[1237-9]</b> = matches any digit or letter in the brackets<br>(in this example, 1,2,3,7,8,9)<br>");?>
  248. <?php $destination_tooltip .= _("<b>.</b> = wildcard, matches one or more characters<br>");?>
  249. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'dst') { echo 'checked="checked"'; } ?> type="radio" name="order" value="dst" />&nbsp;<label for="dst"><?php echo "<a href=\"#\" class=\"info\">"._("Destination")."<span>$destination_tooltip</span></a>"?>:</label></td>
  250. <td><input type="text" name="dst" id="dst" value="<?php if (isset($_POST['dst'])) { echo htmlspecialchars($_POST['dst']); } ?>" />
  251. <?php echo _("Not")?>:<input <?php if ( isset($_POST['dst_neg'] ) &&  $_POST['dst_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="dst_neg" value="true" />
  252. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['dst_mod']) || $_POST['dst_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="dst_mod" value="begins_with" />
  253. <?php echo _("Contains")?>:<input <?php if (isset($_POST['dst_mod']) && $_POST['dst_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="dst_mod" value="contains" />
  254. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['dst_mod']) && $_POST['dst_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="dst_mod" value="ends_with" />
  255. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['dst_mod']) && $_POST['dst_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="dst_mod" value="exact" />
  256. </td>
  257. </tr>
  258. <?php
  259.         // TODO: make this configurable since it requires outbound CNAM lookup
  260. ?>
  261. <tr>
  262. <?php $dstcnam_tooltip = _("Select Destination Caller Name to search for.");?>
  263. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'dst_cnam') { echo 'checked="checked"'; } ?> type="radio" name="order" value="dst_cnam" />&nbsp;<label for="dst_cnam"><?php echo "<a href=\"#\" class=\"info\">"._("Destination CallerID Name")."<span>$dstcnam_tooltip</span></a>"?>:</label></td>
  264. <td><input type="text" name="dst_cnam" id="dst_cnam" value="<?php if (isset($_POST['dst_cnam'])) { echo htmlspecialchars($_POST['dst_cnam']); } ?>" />
  265. <?php echo _("Not")?>:<input <?php if ( isset($_POST['dst_cnam_neg'] ) && $_POST['dst_cnam_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="dst_cnam_neg" value="true" />
  266. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['dst_cnam_mod']) || $_POST['dst_cnam_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="dst_cnam_mod" value="begins_with" />
  267. <?php echo _("Contains")?>:<input <?php if (isset($_POST['dst_cnam_mod']) && $_POST['dst_cnam_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="dst_cnam_mod" value="contains" />
  268. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['dst_cnam_mod']) && $_POST['dst_cnam_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="dst_cnam_mod" value="ends_with" />
  269. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['dst_cnam_mod']) && $_POST['dst_cnam_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="dst_cnam_mod" value="exact" />
  270. </td>
  271. </tr>
  272.  
  273. <tr>
  274. <?php $userfield_tooltip = _("Search for userfield data (if enabled).");?>
  275. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'userfield') { echo 'checked="checked"'; } ?> type="radio" name="order" value="userfield" />&nbsp;<label for="userfield"><?php echo "<a href=\"#\" class=\"info\">"._("Userfield")."<span>$userfield_tooltip</span></a>"?>:</label></td>
  276. <td><input type="text" name="userfield" id="userfield" value="<?php if (isset($_POST['userfield'])) { echo htmlspecialchars($_POST['userfield']); } ?>" />
  277. <?php echo _("Not")?>:<input <?php if (  isset($_POST['userfield_neg'] ) && $_POST['userfield_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="userfield_neg" value="true" />
  278. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['userfield_mod']) || $_POST['userfield_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="userfield_mod" value="begins_with" />
  279. <?php echo _("Contains")?>:<input <?php if (isset($_POST['userfield_mod']) && $_POST['userfield_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="userfield_mod" value="contains" />
  280. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['userfield_mod']) && $_POST['userfield_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="userfield_mod" value="ends_with" />
  281. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['userfield_mod']) && $_POST['userfield_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="userfield_mod" value="exact" />
  282. </td>
  283. </tr>
  284. <tr>
  285. <?php $accountcode_tooltip = _("Search for accountcode.");?>
  286. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'accountcode') { echo 'checked="checked"'; } ?> type="radio" name="order" value="accountcode" />&nbsp;<label for="userfield"><?php echo "<a href=\"#\" class=\"info\">"._("Account Code")."<span>$accountcode_tooltip</span></a>"?>:</label></td>
  287. <td><input type="text" name="accountcode" id="accountcode" value="<?php if (isset($_POST['accountcode'])) { echo htmlspecialchars($_POST['accountcode']); } ?>" />
  288. <?php echo _("Not")?>:<input <?php if ( isset($_POST['accountcode_neg'] ) &&  $_POST['accountcode_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="accountcode_neg" value="true" />
  289. <?php echo _("Begins With")?>:<input <?php if (empty($_POST['accountcode_mod']) || $_POST['accountcode_mod'] == 'begins_with') { echo 'checked="checked"'; } ?> type="radio" name="accountcode_mod" value="begins_with" />
  290. <?php echo _("Contains")?>:<input <?php if (isset($_POST['accountcode_mod']) && $_POST['accountcode_mod'] == 'contains') { echo 'checked="checked"'; } ?> type="radio" name="accountcode_mod" value="contains" />
  291. <?php echo _("Ends With")?>:<input <?php if (isset($_POST['accountcode_mod']) && $_POST['accountcode_mod'] == 'ends_with') { echo 'checked="checked"'; } ?> type="radio" name="accountcode_mod" value="ends_with" />
  292. <?php echo _("Exactly")?>:<input <?php if (isset($_POST['accountcode_mod']) && $_POST['accountcode_mod'] == 'exact') { echo 'checked="checked"'; } ?> type="radio" name="accountcode_mod" value="exact" />
  293. </td>
  294. </tr>
  295. <tr>
  296. <?php $duration_tooltip = _("Search for calls that matches the call length specified.");?>
  297. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'duration') { echo 'checked="checked"'; } ?> type="radio" name="order" value="duration" />&nbsp;<label><?php echo "<a href=\"#\" class=\"info\">"._("Duration")."<span>$duration_tooltip</span></a>"?>:</label></td>
  298. <td><?php echo _("Between")?>:
  299. <input type="text" name="dur_min" value="<?php if (isset($_POST['dur_min'])) { echo htmlspecialchars($_POST['dur_min']); } ?>" size="3" maxlength="5" />
  300. <?php echo _("And")?>:
  301. <input type="text" name="dur_max" value="<?php if (isset($_POST['dur_max'])) { echo htmlspecialchars($_POST['dur_max']); } ?>" size="3" maxlength="5" />
  302. <?php echo _("Seconds")?>
  303. </td>
  304. </tr>
  305. <tr>
  306. <?php $disposition_tooltip = _("Search for calls that matches either ANSWERED, BUSY, FAILED or NO ANSWER.");?>
  307. <td><input <?php if (isset($_POST['order']) && $_POST['order'] == 'disposition') { echo 'checked="checked"'; } ?> type="radio" name="order" value="disposition" />&nbsp;<label for="disposition"><?php echo "<a href=\"#\" class=\"info\">"._("Disposition")."<span>$disposition_tooltip</span></a>"?>:</label></td>
  308. <td>
  309.  
  310. <select name="disposition" id="disposition">
  311. <option <?php if (empty($_POST['disposition']) || $_POST['disposition'] == 'all') { echo 'selected="selected"'; } ?> value="all"><?php echo _("All Dispositions")?></option>
  312. <option <?php if (isset($_POST['disposition']) && $_POST['disposition'] == 'ANSWERED') { echo 'selected="selected"'; } ?> value="ANSWERED"><?php echo _("Answered")?></option>
  313. <option <?php if (isset($_POST['disposition']) && $_POST['disposition'] == 'BUSY') { echo 'selected="selected"'; } ?> value="BUSY"><?php echo _("Busy")?></option>
  314. <option <?php if (isset($_POST['disposition']) && $_POST['disposition'] == 'FAILED') { echo 'selected="selected"'; } ?> value="FAILED"><?php echo _("Failed")?></option>
  315. <option <?php if (isset($_POST['disposition']) && $_POST['disposition'] == 'NO ANSWER') { echo 'selected="selected"'; } ?> value="NO ANSWER"><?php echo _("No Answer")?></option>
  316. </select>
  317. <?php echo _("Not")?>:<input <?php if ( isset($_POST['disposition_neg'] ) && $_POST['disposition_neg'] == 'true' ) { echo 'checked="checked"'; } ?> type="checkbox" name="disposition_neg" value="true" />
  318. </td>
  319. </tr>
  320. <tr>
  321. <td>
  322. <select name="sort" id="sort">
  323. <option <?php if (isset($_POST['sort']) && $_POST['sort'] == 'ASC') { echo 'selected="selected"'; } ?> value="ASC"><?php echo _("Oldest First")?></option>
  324. <option <?php if (empty($_POST['sort']) || $_POST['sort'] == 'DESC') { echo 'selected="selected"'; } ?> value="DESC"><?php echo _("Newest First")?></option>
  325. </select>
  326. </td>
  327. <td><table width="100%"><tr><td>
  328. <label for="group"><?php echo _("Group By")?>:</label>
  329. <select name="group" id="group">
  330. <optgroup label="<?php echo _("Account Information")?>">
  331. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'accountcode') { echo 'selected="selected"'; } ?> value="accountcode"><?php echo _("Account Code")?></option>
  332. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'userfield') { echo 'selected="selected"'; } ?> value="userfield"><?php echo _("User Field")?></option>
  333. </optgroup>
  334. <optgroup label="<?php echo _("Date/Time")?>">
  335. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'minutes1') { echo 'selected="selected"'; } ?> value="minutes1"><?php echo _("Minute")?></option>
  336. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'minutes10') { echo 'selected="selected"'; } ?> value="minutes10"><?php echo _("10 Minutes")?></option>
  337. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'hour') { echo 'selected="selected"'; } ?> value="hour"><?php echo _("Hour")?></option>
  338. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'hour_of_day') { echo 'selected="selected"'; } ?> value="hour_of_day"><?php echo _("Hour of day")?></option>
  339. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'day_of_week') { echo 'selected="selected"'; } ?> value="day_of_week"><?php echo _("Day of week")?></option>
  340. <option <?php if (empty($_POST['group']) || $_POST['group'] == 'day') { echo 'selected="selected"'; } ?> value="day"><?php echo _("Day")?></option>
  341. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'week') { echo 'selected="selected"'; } ?> value="week"><?php echo _("Week ( Sun-Sat )")?></option>
  342. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'month') { echo 'selected="selected"'; } ?> value="month"><?php echo _("Month")?></option>
  343. </optgroup>
  344. <optgroup label="<?php echo _("Telephone Number")?>">
  345. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'dst') { echo 'selected="selected"'; } ?> value="dst"><?php echo _("Destination Number")?></option>
  346. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'did') { echo 'selected="selected"'; } ?> value="did"><?php echo _("DID")?></option>
  347. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'cnum') { echo 'selected="selected"'; } ?> value="cnum"><?php echo _("Caller ID Number")?></option>
  348. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'cnam') { echo 'selected="selected"'; } ?> value="cnam"><?php echo _("Caller ID Name")?></option>
  349. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'outbound_cnum') { echo 'selected="selected"'; } ?> value="outbound_cnum"><?php echo _("Outbound Caller ID Number")?></option>
  350. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'outbound_cnam') { echo 'selected="selected"'; } ?> value="outbound_cnam"><?php echo _("Outbound Caller ID Name")?></option>
  351. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'dst_cnam') { echo 'selected="selected"'; } ?> value="dst_cnam"><?php echo _("Destination Caller ID Name")?></option>
  352. </optgroup>
  353. <optgroup label="<?php echo _("Tech info")?>">
  354. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'disposition') { echo 'selected="selected"'; } ?> value="disposition">Disposition</option>
  355. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'disposition_by_day') { echo 'selected="selected"'; } ?> value="disposition_by_day">Disposition by Day</option>
  356. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'disposition_by_hour') { echo 'selected="selected"'; } ?> value="disposition_by_hour">Disposition by Hour</option>
  357. <option <?php if (isset($_POST['group']) && $_POST['group'] == 'dcontext') { echo 'selected="selected"'; } ?> value="dcontext">Destination context</option>
  358. </optgroup>
  359. </select></td><td align="left" width="40%">
  360. <input type="submit" value="<?php echo _("Search")?>" />
  361. </td></td></table>
  362. </td>
  363. </tr>
  364. </table>
  365. </fieldset>
  366. </form>
  367. </td>
  368. </tr>
  369. </table>
  370. <?php
  371. }
  372.  
  373. // Determine all CEL events associated with this uid, and then get all CDR records related to this event stream
  374. // to display below
  375. //
  376. if ($amp_conf['CEL_ENABLED'] && !isset($_POST['need_html']) && $action == 'cel_show') {
  377.         echo '<a id="CEL"></a>';
  378.         $cdr_uids = array();
  379.  
  380.         $uid = $dbcdr->escapeSimple($_REQUEST['uid']);
  381.  
  382.         $db_cel_name = !empty($amp_conf['CELDBNAME'])?$amp_conf['CELDBNAME']:"asteriskcdrdb";
  383.         $db_cel_table_name = !empty($amp_conf['CELDBTABLENAME'])?$amp_conf['CELDBTABLENAME']:"cel";
  384.         $cel = cdr_get_cel($uid, $db_cel_name . '.' . $db_cel_table_name);
  385.         $tot_cel_events = count($cel);
  386.  
  387.         if ( $tot_cel_events ) {
  388.                 echo "<p class=\"center title\">"._("Call Event Log - Search Returned")." ".$tot_cel_events." "._("Events")."</p>";
  389.                 echo "<table id=\"cdr_table\" class=\"cdr\">";
  390.  
  391.                 $i = $h_step - 1;
  392.                 foreach($cel as $row) {
  393.  
  394.                         // accumulate all id's for CDR query
  395.                         //
  396.                         $cdr_uids[] = $row['uniqueid'];
  397.                         $cdr_uids[] = $row['linkedid'];
  398.  
  399.                         ++$i;
  400.                         if ($i == $h_step) {
  401.                         ?>
  402.                                 <tr>
  403.                                 <th class="record_col"><?php echo _("Time")?></th>
  404.                                 <th class="record_col"><?php echo _("Event")?></th>
  405.                                 <th class="record_col"><?php echo _("CNAM")?></th>
  406.                                 <th class="record_col"><?php echo _("CNUM")?></th>
  407.                                 <th class="record_col"><?php echo _("ANI")?></th>
  408.                                 <th class="record_col"><?php echo _("DID")?></th>
  409.                                 <th class="record_col"><?php echo _("AMA")?></th>
  410.                                 <th class="record_col"><?php echo _("exten")?></th>
  411.                                 <th class="record_col"><?php echo _("context")?></th>
  412.                                 <th class="record_col"><?php echo _("App")?></th>
  413.                                 <th class="record_col"><?php echo _("channel")?></th>
  414.                                 <th class="record_col"><?php echo _("UserDefType")?></th>
  415.                                 <th class="record_col"><?php echo _("EventExtra")?></th>
  416.                                 <th class="img_col"><a href="#CEL" title="Go to the top of the CEL table"><img src="images/scrollup.gif" alt="CEL Table" /></a></th>
  417.                                 </tr>
  418.                                 <?php
  419.                                 $i = 0;
  420.                         }
  421.  
  422.                         echo "  <tr class=\"record\">\n";
  423.                         cdr_formatCallDate($row['eventtime']);
  424.                         cdr_cel_formatEventType($row['eventtype']);
  425.                         cdr_formatCNAM($row['cid_name']);
  426.                         cdr_formatCNUM($row['cid_num']);
  427.                         cdr_formatANI($row['cid_ani']);
  428.                         cdr_formatDID($row['cid_dnid']);
  429.                         cdr_formatAMAFlags($row['amaflags']);
  430.                         cdr_formatExten($row['exten']);
  431.                         cdr_formatContext($row['context']);
  432.                         cdr_formatApp($row['appname'], $row['appdata']);
  433.                         cdr_cel_formatChannelName($row['channame']);
  434.                         cdr_cel_formatUserDefType($row['userdeftype']);
  435.                         cdr_cel_formatEventExtra($row['eventextra']);
  436.                         echo "    <td></td>\n";
  437.                         echo "    <td></td>\n";
  438.                         echo "  </tr>\n";
  439.                 }
  440.                 echo "</table>";
  441.         }
  442.         // now determine CDR query that we will use below in the same code that normally
  443.         // displays the CDR data, in this case all related records that are involved with
  444.         // this event stream.
  445.         //
  446.         $where = "WHERE `uniqueid` IN ('" . implode("','",array_unique($cdr_uids)) . "')";
  447.         $query = "SELECT `calldate`, `clid`, `did`, `src`, `dst`, `dcontext`, `channel`, `dstchannel`, `lastapp`, `lastdata`, `duration`, `billsec`, `disposition`, `amaflags`, `accountcode`, `uniqueid`, `userfield`, unix_timestamp(calldate) as `call_timestamp`, `recordingfile`, `cnum`, `cnam`, `outbound_cnum`, `outbound_cnam`, `dst_cnam` FROM $db_name.$db_table_name $where";
  448.         $resultscdr = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC);
  449. }
  450. if(!isset($_POST['need_csv'])) {
  451.        echo '<a id="CDR"></a>';
  452. }
  453.  
  454. $startmonth = empty($_POST['startmonth']) ? date('m') : $_POST['startmonth'];
  455. $startyear = empty($_POST['startyear']) ? date('Y') : $_POST['startyear'];
  456.  
  457. if (empty($_POST['startday'])) {
  458.         $startday = '01';
  459. } elseif (isset($_POST['startday']) && ($_POST['startday'] > date('t', strtotime("$startyear-$startmonth")))) {
  460.         $startday = $_POST['startday'] = date('t', strtotime("$startyear-$startmonth"));
  461. } else {
  462.         $startday = sprintf('%02d',$_POST['startday']);
  463. }
  464. $starthour = empty($_POST['starthour']) ? '00' : sprintf('%02d',$_POST['starthour']);
  465. $startmin = empty($_POST['startmin']) ? '00' : sprintf('%02d',$_POST['startmin']);
  466.  
  467. $startdate = "'$startyear-$startmonth-$startday $starthour:$startmin:00'";
  468. $start_timestamp = mktime( $starthour, $startmin, 59, $startmonth, $startday, $startyear );
  469.  
  470. $endmonth = empty($_POST['endmonth']) ? date('m') : $_POST['endmonth'];
  471. $endyear = empty($_POST['endyear']) ? date('Y') : $_POST['endyear'];
  472.  
  473. if (empty($_POST['endday']) || (isset($_POST['endday']) && ($_POST['endday'] > date('t', strtotime("$endyear-$endmonth-01"))))) {
  474.         $endday = $_POST['endday'] = date('t', strtotime("$endyear-$endmonth"));
  475. } else {
  476.         $endday = sprintf('%02d',$_POST['endday']);
  477. }
  478. $endhour = empty($_POST['endhour']) ? '23' : sprintf('%02d',$_POST['endhour']);
  479. $endmin = empty($_POST['endmin']) ? '59' : sprintf('%02d',$_POST['endmin']);
  480.  
  481. $enddate = "'$endyear-$endmonth-$endday $endhour:$endmin:59'";
  482. $end_timestamp = mktime( $endhour, $endmin, 59, $endmonth, $endday, $endyear );
  483.  
  484. #
  485. # asterisk regexp2sqllike
  486. #
  487. if ( !isset($_POST['outbound_cnum']) ) {
  488.         $outbound_cnum_number = NULL;
  489. } else {
  490.         $outbound_cnum_number = cdr_asteriskregexp2sqllike( 'outbound_cnum', '' );
  491. }
  492.  
  493. if ( !isset($_POST['cnum']) ) {
  494.         $cnum_number = NULL;
  495. } else {
  496.         $cnum_number = cdr_asteriskregexp2sqllike( 'cnum', '' );
  497. }
  498.  
  499. if ( !isset($_POST['dst']) ) {
  500.         $dst_number = NULL;
  501. } else {
  502.         $dst_number = cdr_asteriskregexp2sqllike( 'dst', '' );
  503. }
  504.  
  505. $date_range = "calldate BETWEEN $startdate AND $enddate";
  506.  
  507. $mod_vars['outbound_cnum'][] = $outbound_cnum_number;
  508. $mod_vars['outbound_cnum'][] = empty($_POST['outbound_cnum_mod']) ? NULL : $_POST['outbound_cnum_mod'];
  509. $mod_vars['outbound_cnum'][] = empty($_POST['outbound_cnum_neg']) ? NULL : $_POST['outbound_cnum_neg'];
  510.  
  511. $mod_vars['cnum'][] = $cnum_number;
  512. $mod_vars['cnum'][] = empty($_POST['cnum_mod']) ? NULL : $_POST['cnum_mod'];
  513. $mod_vars['cnum'][] = empty($_POST['cnum_neg']) ? NULL : $_POST['cnum_neg'];
  514.  
  515. $mod_vars['cnam'][] = !isset($_POST['cnam']) ? NULL : $_POST['cnam'];
  516. $mod_vars['cnam'][] = empty($_POST['cnam_mod']) ? NULL : $_POST['cnam_mod'];
  517. $mod_vars['cnam'][] = empty($_POST['cnam_neg']) ? NULL : $_POST['cnam_neg'];
  518.  
  519. $mod_vars['dst_cnam'][] = !isset($_POST['dst_cnam']) ? NULL : $_POST['dst_cnam'];
  520. $mod_vars['dst_cnam'][] = empty($_POST['dst_cnam_mod']) ? NULL : $_POST['dst_cnam_mod'];
  521. $mod_vars['dst_cnam'][] = empty($_POST['dst_cnam_neg']) ? NULL : $_POST['dst_cnam_neg'];
  522.  
  523. $mod_vars['did'][] = !isset($_POST['did']) ? NULL : $_POST['did'];
  524. $mod_vars['did'][] = empty($_POST['did_mod']) ? NULL : $_POST['did_mod'];
  525. $mod_vars['did'][] = empty($_POST['did_neg']) ? NULL : $_POST['did_neg'];
  526.  
  527. $mod_vars['dst'][] = $dst_number;
  528. $mod_vars['dst'][] = empty($_POST['dst_mod']) ? NULL : $_POST['dst_mod'];
  529. $mod_vars['dst'][] = empty($_POST['dst_neg']) ? NULL : $_POST['dst_neg'];
  530.  
  531. $mod_vars['userfield'][] = !isset($_POST['userfield']) ? NULL : $_POST['userfield'];
  532. $mod_vars['userfield'][] = empty($_POST['userfield_mod']) ? NULL : $_POST['userfield_mod'];
  533. $mod_vars['userfield'][] = empty($_POST['userfield_neg']) ? NULL : $_POST['userfield_neg'];
  534.  
  535. $mod_vars['accountcode'][] = !isset($_POST['accountcode']) ? NULL : $_POST['accountcode'];
  536. $mod_vars['accountcode'][] = empty($_POST['accountcode_mod']) ? NULL : $_POST['accountcode_mod'];
  537. $mod_vars['accountcode'][] = empty($_POST['accountcode_neg']) ? NULL : $_POST['accountcode_neg'];
  538. $result_limit = (!isset($_POST['limit']) || empty($_POST['limit'])) ? $db_result_limit : $_POST['limit'];
  539.  
  540. $multi = array('dst', 'cnum', 'outbound_cnum');
  541. foreach ($mod_vars as $key => $val) {
  542.         if (is_blank($val[0])) {
  543.                 unset($_POST[$key.'_mod']);
  544.                 $$key = NULL;
  545.         } else {
  546.                 $pre_like = '';
  547.                 if ( $val[2] == 'true' ) {
  548.                         $pre_like = ' NOT ';
  549.                 }
  550.                 switch ($val[1]) {
  551.                         case "contains":
  552.                                 if (in_array($key, $multi)) {
  553.                                         $values = explode(',',$val[0]);
  554.                                         if (count($values) > 1) {
  555.                                                 foreach ($values as $key_like => $value_like) {
  556.                                                         if ($key_like == 0) {
  557.                                                                 $$key = "AND $key $pre_like LIKE '%$value_like%'";
  558.                                                         } else {
  559.                                                                 $$key .= " OR $key $pre_like LIKE '%$value_like%'";
  560.                                                         }
  561.                                                 }
  562.                                         } else {
  563.                                                 $$key = "AND $key $pre_like LIKE '%$val[0]%'";
  564.                                         }
  565.                                 } else {
  566.                                         $$key = "AND $key $pre_like LIKE '%$val[0]%'";
  567.                                 }
  568.                         break;
  569.                         case "ends_with":
  570.                                 if (in_array($key, $multi)) {
  571.                                         $values = explode(',',$val[0]);
  572.                                         if (count($values) > 1) {
  573.                                                 foreach ($values as $key_like => $value_like) {
  574.                                                         if ($key_like == 0) {
  575.                                                                 $$key = "AND $key $pre_like LIKE '%$value_like'";
  576.                                                         } else {
  577.                                                                 $$key .= " OR $key $pre_like LIKE '%$value_like'";
  578.                                                         }
  579.                                                 }
  580.                                         } else {
  581.                                                 $$key = "AND $key $pre_like LIKE '%$val[0]'";
  582.                                         }
  583.                                 } else {
  584.                                         $$key = "AND $key $pre_like LIKE '%$val[0]'";
  585.                                 }
  586.                         break;
  587.                         case "exact":
  588.                                 if ( $val[2] == 'true' ) {
  589.                                         $$key = "AND $key != '$val[0]'";
  590.                                 } else {
  591.                                         $$key = "AND $key = '$val[0]'";
  592.                                 }
  593.                         break;
  594.                         case "asterisk-regexp":
  595.                                 $ast_dids = preg_split('/\s*,\s*/', $val[0], -1, PREG_SPLIT_NO_EMPTY);
  596.                                 $ast_key = '';
  597.                                 foreach ($ast_dids as $adid) {
  598.                                         if (strlen($ast_key) > 0 ) {
  599.                                                 if ( $pre_like == ' NOT ' ) {
  600.                                                         $ast_key .= " and ";
  601.                                                 } else {
  602.                                                         $ast_key .= " or ";
  603.                                                 }
  604.                                                 if ( '_' == substr($adid,0,1) ) {
  605.                                                         $adid = substr($adid,1);
  606.                                                 }
  607.                                         }
  608.                                         $ast_key .= " $key $pre_like RLIKE '^$adid\$'";
  609.                                 }
  610.                                 $$key = "AND ( $ast_key )";
  611.                         break;
  612.                         case "begins_with":
  613.                         default:
  614.                                 if (in_array($key, $multi)) {
  615.                                         $values = explode(',',$val[0]);
  616.                                         if (count($values) > 1) {
  617.                                                 foreach ($values as $key_like => $value_like) {
  618.                                                         if ($key_like == 0) {
  619.                                                                 $$key = "AND $key $pre_like LIKE '$value_like%'";
  620.                                                         } else {
  621.                                                                 $$key .= " OR $key $pre_like LIKE '$value_like%'";
  622.                                                         }
  623.                                                 }
  624.                                         } else {
  625.                                                 $$key = "AND $key $pre_like LIKE '$val[0]%'";
  626.                                         }
  627.                                 } else {
  628.                                         $$key = "AND $key $pre_like LIKE '$val[0]%'";
  629.                                 }
  630.                         break;
  631.                 }
  632.         }
  633. }
  634.  
  635. if ( isset($_POST['disposition_neg']) && $_POST['disposition_neg'] == 'true' ) {
  636.         $disposition = (empty($_POST['disposition']) || $_POST['disposition'] == 'all') ? NULL : "AND disposition != '$_POST[disposition]'";
  637. } else {
  638.         $disposition = (empty($_POST['disposition']) || $_POST['disposition'] == 'all') ? NULL : "AND disposition = '$_POST[disposition]'";
  639. }
  640.  
  641. $duration = (!isset($_POST['dur_min']) || is_blank($_POST['dur_max'])) ? NULL : "AND duration BETWEEN '$_POST[dur_min]' AND '$_POST[dur_max]'";
  642. $order = empty($_POST['order']) ? 'ORDER BY calldate' : "ORDER BY $_POST[order]";
  643. $sort = empty($_POST['sort']) ? 'DESC' : $_POST['sort'];
  644. $group = empty($_POST['group']) ? 'day' : $_POST['group'];
  645.  
  646. //Allow people to search SRC and DSTChannels using existing fields
  647. if (isset($cnum)) {
  648.   $cnum_length = strlen($cnum);
  649.   $cnum_type = substr($cnum, 0 ,strpos($cnum , 'cnum') -1);
  650.   $cnum_remaining = substr($cnum, strpos($cnum , 'cnum'));
  651.   $src = str_replace('AND cnum', '', $cnum);
  652.  
  653.   $cnum = "$cnum_type ($cnum_remaining OR src $src)";
  654. }
  655.  
  656. if (isset($dst)) {
  657.   $dst_length = strlen($dst);
  658.   $dst_type = substr($dst, 0 ,strpos($dst , 'dst') -1);
  659.   $dst_remaining = substr($dst, strpos($dst , 'dst'));
  660.   $dstchannel = str_replace('AND dst', '', $dst);
  661.  
  662.   $dst = "$dst_type ($dst_remaining OR dstchannel $dstchannel)";
  663. }
  664.  
  665. // Build the "WHERE" part of the query
  666. $where = "WHERE $date_range $cnum $outbound_cnum $cnam $dst_cnam $did $dst $userfield $accountcode $disposition $duration";
  667.  
  668. if ( isset($_POST['need_csv']) && $_POST['need_csv'] == 'true' ) {
  669.         $query = "(SELECT calldate, clid, did, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, amaflags, accountcode, uniqueid, userfield, cnum, cnam, outbound_cnum, outbound_cnam, dst_cnam FROM $db_name.$db_table_name $where $order $sort LIMIT $result_limit)";
  670.         $resultcsv = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC);
  671.         cdr_export_csv($resultcsv);
  672. }
  673.  
  674. if ( empty($resultcdr) && isset($_POST['need_html']) && $_POST['need_html'] == 'true' ) {
  675.         $query = "SELECT `calldate`, `clid`, `did`, `src`, `dst`, `dcontext`, `channel`, `dstchannel`, `lastapp`, `lastdata`, `duration`, `billsec`, `disposition`, `amaflags`, `accountcode`, `uniqueid`, `userfield`, unix_timestamp(calldate) as `call_timestamp`, `recordingfile`, `cnum`, `cnam`, `outbound_cnum`, `outbound_cnam`, `dst_cnam`  FROM $db_name.$db_table_name $where $order $sort LIMIT $result_limit";
  676.         $resultscdr = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC);
  677. }
  678. if ( isset($resultscdr) ) {
  679.         $tot_calls_raw = sizeof($resultscdr);
  680. } else {
  681.         $tot_calls_raw = 0;
  682. }
  683. if ( $tot_calls_raw ) {
  684.         // This is a bit of a hack, if we generated CEL data above, then these are simply the records all related to that CEL
  685.         // event stream.
  686.         //
  687.         if (!isset($cel)) {
  688.                 echo "<p class=\"center title\">"._("Call Detail Record - Search Returned")." ".$tot_calls_raw." "._("Calls")."</p>";
  689.         } else {
  690.                 echo "<p class=\"center title\">"._("Related Call Detail Records") . "</p>";
  691.         }
  692.         echo "<table id=\"cdr_table\" class=\"cdr\">";
  693.  
  694.         $i = $h_step - 1;
  695.         $id = -1;  // tracker for recording index
  696.         foreach($resultscdr as $row) {
  697.                 ++$id;  // Start at table row 1
  698.                 ++$i;
  699.                 if ($i == $h_step) {
  700.                 ?>
  701.                         <tr>
  702.                         <th class="record_col"><?php echo _("Call Date")?></th>
  703.                         <th class="record_col"><?php echo _("Recording")?></th>
  704.                         <th class="record_col"><?php echo _("System")?></th>
  705.                         <th class="record_col"><?php echo _("CallerID")?></th>
  706.                         <th class="record_col"><?php echo _("Outbound CallerID")?></th>
  707.                         <th class="record_col"><?php echo _("DID")?></th>
  708.                         <th class="record_col"><?php echo _("App")?></th>
  709.                         <th class="record_col"><?php echo _("Destination")?></th>
  710.                         <th class="record_col"><?php echo _("Disposition")?></th>
  711.                         <th class="record_col"><?php echo _("Duration")?></th>
  712.                         <th class="record_col"><?php echo _("Userfield")?></th>
  713.                         <th class="record_col"><?php echo _("Account")?></th>
  714.                         <th class="img_col"><a href="#CDR" title="Go to the top of the CDR table"><img src="images/scrollup.gif" alt="CDR Table" /></a></th>
  715.                         <th class="img_col"><a href="#Graph" title="Go to the top of the CDR graph"><img src="images/scrolldown.gif" alt="CDR Graph" /></a></th>
  716.                         </tr>
  717.                         <?php
  718.                         $i = 0;
  719.                         ++$id;
  720.                 }
  721.  
  722.                 /* If CDR claims there is a call recording we make sure there is and the file is there, or we set it blank. In some cases
  723.                  * a recording may have been planned but not done so this assures there are no dead links.
  724.                  */
  725.                 if ($row['recordingfile']) {
  726.                         $rec_parts = explode('-',$row['recordingfile']);
  727.                         $fyear = substr($rec_parts[3],0,4);
  728.                         $fmonth = substr($rec_parts[3],4,2);
  729.                         $fday = substr($rec_parts[3],6,2);
  730.                         $monitor_base = $amp_conf['MIXMON_DIR'] ? $amp_conf['MIXMON_DIR'] : $amp_conf['ASTSPOOLDIR'] . '/monitor';
  731.                         $recordingfile = "$monitor_base/$fyear/$fmonth/$fday/" . $row['recordingfile'];
  732.                         if (!file_exists($recordingfile)) {
  733.                                 $recordingfile = '';
  734.                         }
  735.                 } else {
  736.                         $recordingfile = '';
  737.                 }
  738.  
  739.                 echo "  <tr class=\"record\">\n";
  740.                 cdr_formatCallDate($row['calldate']);
  741.                 cdr_formatRecordingFile($recordingfile, $row['recordingfile'], $id, $row['uniqueid']);
  742.                 cdr_formatUniqueID($row['uniqueid']);
  743.  
  744.                 $tcid = $row['cnam'] == '' ? '<' . $row['cnum'] . '>' : $row['cnam'] . ' <' . $row['cnum'] . '>';
  745.                 if ($row['outbound_cnum'] != '') {
  746.                         $cid = '<' . $row['outbound_cnum'] . '>';
  747.                         if ($row['outbound_cnam'] != '') {
  748.                                 $cid = $row['outbound_cnam'] . ' ' . $cid;
  749.                         }
  750.                 } else {
  751.                         $cid = $tcid;
  752.                 }
  753.                 // for legacy records
  754.                 if ($cid == '<>') {
  755.                         $cid = $row['src'];
  756.                         $tcid = $row['clid'];
  757.                 }
  758.                 //cdr_formatSrc($cid, $tcid);
  759.                 if ($row['cnum'] != '' || $row['cnum'] != '') {
  760.                         cdr_formatCallerID($row['cnam'], $row['cnum'], $row['channel']);
  761.                 } else {
  762.                         cdr_formatSrc($row['src'], $row['clid']);
  763.                 }
  764.                 cdr_formatCallerID($row['outbound_cnam'], $row['outbound_cnum'], $row['dstchannel']);
  765.                 cdr_formatDID($row['did']);
  766.                 cdr_formatApp($row['lastapp'], $row['lastdata']);
  767.                 cdr_formatDst($row['dst'], $row['dst_cnam'], $row['dstchannel'], $row['dcontext']);
  768.                 cdr_formatDisposition($row['disposition'], $row['amaflags']);
  769.                 cdr_formatDuration($row['duration'], $row['billsec']);
  770.                 cdr_formatUserField($row['userfield']);
  771.                 cdr_formatAccountCode($row['accountcode']);
  772.                 echo "    <td></td>\n";
  773.                 echo "    <td></td>\n";
  774.                 echo "  </tr>\n";
  775.                 echo '<tr id="playback-'.$id.'" class="playback" style="display:none;"><td colspan="14"><div id="jquery_jplayer_'.$id.'" class="jp-jplayer"></div>
  776.  <div id="jp_container_'.$id.'" class="jp-audio">
  777.    <div class="jp-type-single">
  778.      <div class="jp-gui jp-interface">
  779.        <ul class="jp-controls">
  780.          <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
  781.          <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
  782.          <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
  783.          <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
  784.          <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
  785.          <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
  786.        </ul>
  787.        <div class="jp-progress">
  788.          <div class="jp-seek-bar">
  789.            <div class="jp-play-bar"></div>
  790.          </div>
  791.        </div>
  792.        <div class="jp-volume-bar">
  793.          <div class="jp-volume-bar-value"></div>
  794.        </div>
  795.        <div class="jp-time-holder">
  796.          <div class="jp-current-time"></div>
  797.          <div class="jp-duration"></div>
  798.          <ul class="jp-toggles">
  799.            <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
  800.            <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
  801.          </ul>
  802.        </div>
  803.      </div>
  804.      <div class="jp-details">
  805.        <ul>
  806.          <li><span class="jp-title"></span></li>
  807.        </ul>
  808.      </div>
  809.      <div class="jp-no-solution">
  810.        <span>Update Required</span>
  811.        To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
  812.      </div>
  813.    </div>
  814.  </div>';
  815.         }
  816.         echo "</table>";
  817. }
  818. ?>
  819.  
  820. <!-- Display Call Usage Graph -->
  821. <?php
  822.  
  823. echo '<a id="Graph"></a>';
  824.  
  825. //NEW GRAPHS
  826. $group_by_field = $group;
  827. // ConcurrentCalls
  828. $group_by_field_php = array( '', 32, '' );
  829.  
  830. switch ($group) {
  831.         case "disposition_by_day":
  832.             $graph_col_title = 'Disposition by day';
  833.             $group_by_field_php = array('%Y-%m-%d / ',17,'');
  834.             $group_by_field = "CONCAT(DATE_FORMAT(calldate, '$group_by_field_php[0]'),disposition)";
  835.         break;
  836.         case "disposition_by_hour":
  837.             $graph_col_title = 'Disposition by hour';
  838.             $group_by_field_php = array( '%Y-%m-%d %H / ', 20, '' );
  839.             $group_by_field = "CONCAT(DATE_FORMAT(calldate, '$group_by_field_php[0]'),disposition)";
  840.         break;
  841.         case "disposition":
  842.             $graph_col_title = 'Disposition';
  843.         break;
  844.         case "dcontext":
  845.             $graph_col_title = 'Destination context';
  846.         break;
  847.         case "accountcode":
  848.                 $graph_col_title = _("Account Code");
  849.         break;
  850.         case "dst":
  851.                 $graph_col_title = _("Destination Number");
  852.         break;
  853.         case "did":
  854.                 $graph_col_title = _("DID");
  855.         break;
  856.         case "cnum":
  857.                 $graph_col_title = _("Caller ID Number");
  858.         break;
  859.         case "cnam":
  860.                 $graph_col_title = _("Caller ID Name");
  861.         break;
  862.         case "outbound_cnum":
  863.                 $graph_col_title = _("Outbound Caller ID Number");
  864.         break;
  865.         case "outbound_cnam":
  866.                 $graph_col_title = _("Outbound Caller ID Name");
  867.         break;
  868.         case "dst_cnam":
  869.                 $graph_col_title = _("Destination Caller ID Name");
  870.         break;
  871.         case "userfield":
  872.                 $graph_col_title = _("User Field");
  873.         break;
  874.         case "hour":
  875.                 $group_by_field_php = array( '%Y-%m-%d %H', 13, '' );
  876.                 $group_by_field = "DATE_FORMAT(calldate, '$group_by_field_php[0]')";
  877.                 $graph_col_title = _("Hour");
  878.         break;
  879.         case "hour_of_day":
  880.                 $group_by_field_php = array('%H',2,'');
  881.                 $group_by_field = "DATE_FORMAT(calldate, '$group_by_field_php[0]')";
  882.                 $graph_col_title = _("Hour of day");
  883.         break;
  884.         case "week":
  885.                 $group_by_field_php = array('%V',2,'');
  886.                 $group_by_field = "DATE_FORMAT(calldate, '$group_by_field_php[0]') ";
  887.                 $graph_col_title = _("Week ( Sun-Sat )");
  888.         break;
  889.         case "month":
  890.                 $group_by_field_php = array('%Y-%m',7,'');
  891.                 $group_by_field = "DATE_FORMAT(calldate, '$group_by_field_php[0]')";
  892.                 $graph_col_title = _("Month");
  893.         break;
  894.         case "day_of_week":
  895.                 $group_by_field_php = array('%w - %A',20,'');
  896.                 $group_by_field = "DATE_FORMAT( calldate, '%W' )";
  897.                 $graph_col_title = _("Day of week");
  898.         break;
  899.         case "minutes1":
  900.                 $group_by_field_php = array( '%Y-%m-%d %H:%M', 16, '' );
  901.                 $group_by_field = "DATE_FORMAT(calldate, '%Y-%m-%d %H:%i')";
  902.                 $graph_col_title = _("Minute");
  903.         break;
  904.         case "minutes10":
  905.                 $group_by_field_php = array('%Y-%m-%d %H:%M',15,'0');
  906.                 $group_by_field = "CONCAT(SUBSTR(DATE_FORMAT(calldate, '%Y-%m-%d %H:%i'),1,15), '0')";
  907.                 $graph_col_title = _("10 Minutes");
  908.         break;
  909.         case "day":
  910.         default:
  911.                 $group_by_field_php = array('%Y-%m-%d',10,'');
  912.                 $group_by_field = "DATE_FORMAT(calldate, '$group_by_field_php[0]')";
  913.                 $graph_col_title = _("Day");
  914. }
  915.  
  916. if ( isset($_POST['need_chart']) && $_POST['need_chart'] == 'true' ) {
  917.         $query2 = "SELECT $group_by_field AS group_by_field, count(*) AS total_calls, sum(duration) AS total_duration FROM $db_name.$db_table_name $where GROUP BY group_by_field ORDER BY group_by_field ASC LIMIT $result_limit";
  918.         $result2 = $dbcdr->getAll($query2, DB_FETCHMODE_ASSOC);
  919.  
  920.         $tot_calls = 0;
  921.         $tot_duration = 0;
  922.         $max_calls = 0;
  923.         $max_duration = 0;
  924.         $tot_duration_secs = 0;
  925.         $result_array = array();
  926.         foreach($result2 as $row) {
  927.                 $tot_duration_secs += $row['total_duration'];
  928.                 $tot_calls += $row['total_calls'];
  929.                 if ( $row['total_calls'] > $max_calls ) {
  930.                         $max_calls = $row['total_calls'];
  931.                 }
  932.                 if ( $row['total_duration'] > $max_duration ) {
  933.                         $max_duration = $row['total_duration'];
  934.                 }
  935.                 array_push($result_array,$row);
  936.         }
  937.         $tot_duration = sprintf('%02d', intval($tot_duration_secs/60)).':'.sprintf('%02d', intval($tot_duration_secs%60));
  938.  
  939.         if ( $tot_calls ) {
  940.                 $html = "<p class=\"center title\">"._("Call Detail Record - Call Graph by")." ".$graph_col_title."</p><table class=\"cdr\">";
  941.                 $html .= "<tr><th class=\"end_col\">". $graph_col_title . "</th>";
  942.                 $html .= "<th class=\"center_col\">"._("Total Calls").": ". $tot_calls ." / "._("Max Calls").": ". $max_calls ." / "._("Total Duration").": ". $tot_duration ."</th>";
  943.                 $html .= "<th class=\"end_col\">"._("Average Call Time")."</th>";
  944.                 $html .= "<th class=\"img_col\"><a href=\"#CDR\" title=\""._("Go to the top of the CDR table")."\"><img src=\"images/scrollup.gif\" alt=\"CDR Table\" /></a></th>";
  945.                 $html .= "<th class=\"img_col\"><a href=\"#Graph\" title=\""._("Go to the CDR Graph")."\"><img src=\"images/scrolldown.gif\" alt=\"CDR Graph\" /></a></th>";
  946.                 $html .= "</tr>";
  947.                 echo $html;
  948.  
  949.                 foreach ($result_array as $row) {
  950.                         $avg_call_time = sprintf('%02d', intval(($row['total_duration']/$row['total_calls'])/60)).':'.sprintf('%02d', intval($row['total_duration']/$row['total_calls']%60));
  951.                         $bar_calls = $row['total_calls']/$max_calls*100;
  952.                         $percent_tot_calls = intval($row['total_calls']/$tot_calls*100);
  953.                         $bar_duration = $row['total_duration']/$max_duration*100;
  954.                         $percent_tot_duration = intval($row['total_duration']/$tot_duration_secs*100);
  955.                         $html_duration = sprintf('%02d', intval($row['total_duration']/60)).':'.sprintf('%02d', intval($row['total_duration']%60));
  956.                         echo "  <tr>\n";
  957.                         echo "    <td class=\"end_col\">".$row['group_by_field']."</td><td class=\"center_col\"><div class=\"bar_calls\" style=\"width : $bar_calls%\">".$row['total_calls']." - $percent_tot_calls%</div><div class=\"bar_duration\" style=\"width : $bar_duration%\">$html_duration - $percent_tot_duration%</div></td><td class=\"chart_data\">$avg_call_time</td>\n";
  958.                         echo "    <td></td>\n";
  959.                         echo "    <td></td>\n";
  960.                         echo "  </tr>\n";
  961.                 }
  962.                 echo "</table>";
  963.         }
  964. }
  965. if ( isset($_POST['need_chart_cc']) && $_POST['need_chart_cc'] == 'true' ) {
  966.         $date_range = "( (calldate BETWEEN $startdate AND $enddate) or (calldate + interval duration second  BETWEEN $startdate AND $enddate) or ( calldate + interval duration second >= $enddate AND calldate <= $startdate ) )";
  967.         $where = "WHERE $date_range $cnum $outbound_cnum $cnam $dst_cnam $did $dst $userfield $accountcode $disposition $duration";
  968.  
  969.         $tot_calls = 0;
  970.         $max_calls = 0;
  971.         $result_array_cc = array();
  972.         $result_array = array();
  973.         if ( strpos($group_by_field,'DATE_FORMAT') === false ) {
  974.                 /* not date time fields */
  975.                 $query3 = "SELECT $group_by_field AS group_by_field, count(*) AS total_calls, unix_timestamp(calldate) AS ts, duration FROM $db_name.$db_table_name $where GROUP BY group_by_field, unix_timestamp(calldate) ORDER BY group_by_field ASC LIMIT $result_limit";
  976.                 $result3 = $dbcdr->getAll($query3, DB_FETCHMODE_ASSOC);
  977.                 $group_by_str = '';
  978.                 foreach($result3 as $row) {
  979.                         if ( $group_by_str != $row['group_by_field'] ) {
  980.                                 $group_by_str = $row['group_by_field'];
  981.                                 $result_array = array();
  982.                         }
  983.                         for ( $i=$row['ts']; $i<=$row['ts']+$row['duration']; ++$i ) {
  984.                                 if ( isset($result_array[ "$i" ]) ) {
  985.                                         $result_array[ "$i" ] += $row['total_calls'];
  986.                                 } else {
  987.                                         $result_array[ "$i" ] = $row['total_calls'];
  988.                                 }
  989.                                 if ( $max_calls < $result_array[ "$i" ] ) {
  990.                                         $max_calls = $result_array[ "$i" ];
  991.                                 }
  992.                                 if ( ! isset($result_array_cc[ $row['group_by_field'] ]) || $result_array_cc[ $row['group_by_field'] ][1] < $result_array[ "$i" ] ) {
  993.                                         $result_array_cc[$row['group_by_field']][0] = $i;
  994.                                         $result_array_cc[$row['group_by_field']][1] = $result_array[ "$i" ];
  995.                                 }
  996.                         }
  997.                         $tot_calls += $row['total_calls'];
  998.                 }
  999.         } else {
  1000.                 /* data fields */
  1001.                 $query3 = "SELECT unix_timestamp(calldate) AS ts, duration FROM $db_name.$db_table_name $where ORDER BY unix_timestamp(calldate) ASC LIMIT $result_limit";
  1002.                 $result3 = $dbcdr->getAll($query3, DB_FETCHMODE_ASSOC);
  1003.                 $group_by_str = '';
  1004.                 foreach($result3 as $row) {
  1005.                         $group_by_str_cur = substr(strftime($group_by_field_php[0],$row['ts']),0,$group_by_field_php[1]) . $group_by_field_php[2];
  1006.                         if ( $group_by_str_cur != $group_by_str ) {
  1007.                                 if ( $group_by_str ) {
  1008.                                         for ( $i=$start_timestamp; $i<$row['ts']; ++$i ) {
  1009.                                                 if ( ! isset($result_array_cc[ "$group_by_str" ]) || ( isset($result_array["$i"]) && $result_array_cc[ "$group_by_str" ][1] < $result_array["$i"] ) ) {
  1010.                                                         $result_array_cc[ "$group_by_str" ][0] = $i;
  1011.                                                         $result_array_cc[ "$group_by_str" ][1] = isset($result_array["$i"]) ? $result_array["$i"] : 0;
  1012.                                                 }
  1013.                                                 unset( $result_array[$i] );
  1014.                                         }
  1015.                                         $start_timestamp = $row['ts'];
  1016.                                 }
  1017.                                 $group_by_str = $group_by_str_cur;
  1018.                         }
  1019.                         for ( $i=$row['ts']; $i<=$row['ts']+$row['duration']; ++$i ) {
  1020.                                 if ( isset($result_array["$i"]) ) {
  1021.                                         ++$result_array["$i"];
  1022.                                 } else {
  1023.                                         $result_array["$i"]=1;
  1024.                                 }
  1025.                                 if ( $max_calls < $result_array["$i"] ) {
  1026.                                         $max_calls = $result_array["$i"];
  1027.                                 }
  1028.                         }
  1029.                         $tot_calls++;
  1030.                 }
  1031.                 for ( $i=$start_timestamp; $i<=$end_timestamp; ++$i ) {
  1032.                         $group_by_str = substr(strftime($group_by_field_php[0],$i),0,$group_by_field_php[1]) . $group_by_field_php[2];
  1033.                         if ( ! isset($result_array_cc[ "$group_by_str" ]) || ( isset($result_array["$i"]) && $result_array_cc[ "$group_by_str" ][1] < $result_array["$i"] ) ) {
  1034.                                 $result_array_cc[ "$group_by_str" ][0] = $i;
  1035.                                 $result_array_cc[ "$group_by_str" ][1] = isset($result_array["$i"]) ? $result_array["$i"] : 0;
  1036.                         }
  1037.                 }
  1038.         }
  1039.         if ( $tot_calls ) {
  1040.                 $html = "<p class=\"center title\">"._("Call Detail Record - Concurrent Calls by")." ".$graph_col_title."</p><table class=\"cdr\">";
  1041.                 $html .= "<tr><th class=\"end_col\">". $graph_col_title . "</th>";
  1042.                 $html .= "<th class=\"center_col\">"._("Total Calls").": ". $tot_calls ." / "._("Max Calls").": ". $max_calls ."</th>";
  1043.                 $html .= "<th class=\"end_col\">"._("Time")."</th>";
  1044.                 $html .= "</tr>";
  1045.                 echo $html;
  1046.  
  1047.                 ksort($result_array_cc);
  1048.  
  1049.                 foreach ( array_keys($result_array_cc) as $group_by_key ) {
  1050.                         $full_time = strftime( '%Y-%m-%d %H:%M:%S', $result_array_cc[ "$group_by_key" ][0] );
  1051.                         $group_by_cur = $result_array_cc[ "$group_by_key" ][1];
  1052.                         $bar_calls = $group_by_cur/$max_calls*100;
  1053.                         echo "  <tr>\n";
  1054.                         echo "    <td class=\"end_col\">$group_by_key</td><td class=\"center_col\"><div class=\"bar_calls\" style=\"width : $bar_calls%\">&nbsp;$group_by_cur</div></td><td>$full_time</td>\n";
  1055.                         echo "  </tr>\n";
  1056.                 }
  1057.  
  1058.                 echo "</table>";
  1059.         }
  1060. }
  1061.  
  1062. ?>
  1063. </div>
  1064. <?php
  1065. /* CDR Table Display Functions */
  1066. function cdr_formatCallDate($calldate) {
  1067.         echo "<td>".$calldate."</td>";
  1068. }
  1069.  
  1070. function cdr_formatUniqueID($uniqueid) {
  1071.         global $amp_conf;
  1072.  
  1073.         $system = explode('-', $uniqueid, 2);
  1074.         if ($amp_conf['CEL_ENABLED']) {
  1075.                 $href=$_SERVER['SCRIPT_NAME']."?display=cdr&action=cel_show&uid=" . urlencode($uniqueid);
  1076.                 echo '<td title="' . _("UniqueID") . ": " . $uniqueid . '">' .
  1077.                         '<a href="' . $href . '" >' . $system[0] . '</a></td>';
  1078.         } else {
  1079.                 echo '<td title="' . _("UniqueID") . ": " . $uniqueid . '">' . $system[0] . '</td>';
  1080.         }
  1081. }
  1082.  
  1083. function cdr_formatChannel($channel) {
  1084.         $chan_type = explode('/', $channel, 2);
  1085.         echo '<td title="' . _("Channel") . ": " . $channel . '">' . $chan_type[0] . "</td>";
  1086. }
  1087.  
  1088. function cdr_formatSrc($src, $clid) {
  1089.         if (empty($src)) {
  1090.                 echo "<td class=\"record_col\">UNKNOWN</td>";
  1091.         } else {
  1092.                 $clid = htmlspecialchars($clid);
  1093.                 echo '<td title="' . _("CallerID") . ": " . $clid . '">' . $src . "</td>";
  1094.         }
  1095. }
  1096.  
  1097. function cdr_formatCallerID($cnam, $cnum, $channel) {
  1098.         $dcnum = $cnum == '' && $cnam == '' ? '' : htmlspecialchars('<' . $cnum . '>');
  1099.         $dcnam = htmlspecialchars($cnam == '' ? '' : '"' . $cnam . ' "');
  1100.         echo '<td title="' ._("Channel") . ": " . $channel . '">' . $dcnam . $dcnum . '</td>';
  1101. }
  1102.  
  1103. function cdr_formatDID($did) {
  1104.         $did = htmlspecialchars($did);
  1105.         echo '<td title="' . _("DID") . ": " . $did . '">' . $did . "</td>";
  1106. }
  1107.  
  1108. function cdr_formatANI($ani) {
  1109.         $ani = htmlspecialchars($ani);
  1110.         echo '<td title="' . _("ANI") . ": " . $ani . '">' . $ani . "</td>";
  1111. }
  1112.  
  1113. function cdr_formatApp($app, $lastdata) {
  1114.         $app = htmlspecialchars($app);
  1115.         $lastdata = htmlspecialchars($lastdata);
  1116.         echo '<td title="' .  _("Application") . ": " . $app . "(" . $lastdata . ")" . '">'
  1117.         . $app . "</td>";
  1118. }
  1119.  
  1120. function cdr_formatDst($dst, $dst_cnam, $channel, $dcontext) {
  1121.         if ($dst == 's') {
  1122.                 $dst .= ' [' . $dcontext . ']';
  1123.         }
  1124.         if ($dst_cnam != '') {
  1125.                 $dst = '"' . $dst_cnam . '" ' . $dst;
  1126.         }
  1127.         echo '<td title="' . _("Channel") . ": " . $channel . ' ' . _("Destination Context") . ": " . $dcontext . '">'
  1128.                 . $dst . "</td>";
  1129. }
  1130.  
  1131. function cdr_formatDisposition($disposition, $amaflags) {
  1132.         switch ($amaflags) {
  1133.                 case 0:
  1134.                         $amaflags = 'DOCUMENTATION';
  1135.                         break;
  1136.                 case 1:
  1137.                         $amaflags = 'IGNORE';
  1138.                         break;
  1139.                 case 2:
  1140.                         $amaflags = 'BILLING';
  1141.                         break;
  1142.                 case 3:
  1143.                 default:
  1144.                         $amaflags = 'DEFAULT';
  1145.         }
  1146.         echo '<td title="' . _("AMA Flag") . ": " . $amaflags . '">'
  1147.                 . $disposition . "</td>";
  1148. }
  1149.  
  1150. function cdr_formatDuration($duration, $billsec) {
  1151.         $duration = sprintf('%02d', intval($duration/60)).':'.sprintf('%02d', intval($duration%60));
  1152.         $billduration = sprintf('%02d', intval($billsec/60)).':'.sprintf('%02d', intval($billsec%60));
  1153.         echo '<td title="' . _("Billing Duration") . ": " . $billduration . '">'
  1154.                 . $duration . "</td>";
  1155. }
  1156.  
  1157. function cdr_formatUserField($userfield) {
  1158.         $userfield = htmlspecialchars($userfield);
  1159.         echo "<td>".$userfield."</td>";
  1160. }
  1161.  
  1162. function cdr_formatAccountCode($accountcode) {
  1163.         $accountcode = htmlspecialchars($accountcode);
  1164.         echo "<td>".$accountcode."</td>";
  1165. }
  1166.  
  1167. function cdr_formatRecordingFile($recordingfile, $basename, $id, $uid) {
  1168.  
  1169.         global $REC_CRYPT_PASSWORD;
  1170.  
  1171.         if ($recordingfile) {
  1172.                 $crypt = new Crypt();
  1173.                 // Encrypt the complete file
  1174.                 $audio = urlencode($crypt->encrypt($recordingfile, $REC_CRYPT_PASSWORD));
  1175.                 $recurl=$_SERVER['SCRIPT_NAME']."?quietmode=1&display=cdr&action=cdr_play&recordingpath=$audio";
  1176.                 $download_url=$_SERVER['SCRIPT_NAME']."?display=cdr&action=download_audio&cdr_file=$uid";
  1177.                 $playbackRow = $id +1;
  1178.                 //
  1179.                 echo "<td title=\"$basename\"><a href=\"#\" onClick=\"javascript:cdr_play($playbackRow,'$recurl','$uid'); return false;\"><img src=\"assets/cdr/images/cdr_sound.png\" alt=\"Call recording\" /></a>
  1180.                <a href=\"$download_url\"><img src=\"assets/cdr/images/cdr_download.png\" alt=\"Call recording\" /></a></td>";
  1181.  
  1182.         } else {
  1183.                 echo "<td></td>";
  1184.         }
  1185. }
  1186.  
  1187. function cdr_formatCNAM($cnam) {
  1188.         $cnam = htmlspecialchars($cnam);
  1189.         echo '<td title="' . _("Caller ID Name") . ": " . $cnam . '">' . $cnam . "</td>";
  1190. }
  1191.  
  1192. function cdr_formatCNUM($cnum) {
  1193.         $cnum = htmlspecialchars($cnum);
  1194.         echo '<td title="' . _("Caller ID Number") . ": " . $cnum . '">' . $cnum . "</td>";
  1195. }
  1196.  
  1197. function cdr_formatExten($exten) {
  1198.         $exten = htmlspecialchars($exten);
  1199.         echo '<td title="' . _("Dialplan exten") . ": " . $exten . '">' . $exten . "</td>";
  1200. }
  1201.  
  1202. function cdr_formatContext($context) {
  1203.         $context = htmlspecialchars($context);
  1204.         echo '<td title="' . _("Dialplan context") . ": " . $context . '">' . $context . "</td>";
  1205. }
  1206.  
  1207. function cdr_formatAMAFlags($amaflags) {
  1208.         switch ($amaflags) {
  1209.                 case 0:
  1210.                         $amaflags = 'DOCUMENTATION';
  1211.                         break;
  1212.                 case 1:
  1213.                         $amaflags = 'IGNORE';
  1214.                         break;
  1215.                 case 2:
  1216.                         $amaflags = 'BILLING';
  1217.                         break;
  1218.                 case 3:
  1219.                 default:
  1220.                         $amaflags = 'DEFAULT';
  1221.         }
  1222.         echo '<td title="' . _("AMA Flag") . ": " . $amaflags . '">'
  1223.                 . $amaflags . "</td>";
  1224. }
  1225.  
  1226. // CEL Specific Formating:
  1227. //
  1228.  
  1229. function cdr_cel_formatEventType($eventtype) {
  1230.         $eventtype = htmlspecialchars($eventtype);
  1231.         echo "<td>".$eventtype."</td>";
  1232. }
  1233.  
  1234. function cdr_cel_formatUserDefType($userdeftype) {
  1235.         $userdeftype = htmlspecialchars($userdeftype);
  1236.         echo '<td title="' .  _("UserDefType") . ": " . $userdeftype . '">'
  1237.         . $userdeftype . "</td>";
  1238. }
  1239.  
  1240. function cdr_cel_formatEventExtra($eventextra) {
  1241.         $eventextra = htmlspecialchars($eventextra);
  1242.         echo '<td title="' .  _("Event Extra") . ": " . $eventextra . '">'
  1243.         . $eventextra . "</td>";
  1244. }
  1245.  
  1246. function cdr_cel_formatChannelName($channel) {
  1247.         $chan_type = explode('/', $channel, 2);
  1248.         $type = htmlspecialchars($chan_type[0]);
  1249.         $channel = htmlspecialchars($channel);
  1250.         echo '<td title="' . _("Channel") . ": " . $channel . '">' . $channel . "</td>";
  1251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement