v_cdr.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('cdr_csv_view')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. require_once "resources/header.php";
  32. require_once "resources/paging.php";
  33. require_once "v_cdr_import.php";
  34. require "lib_cdr.php";
  35. $order_by = $_GET["order_by"];
  36. $order = $_GET["order"];
  37. if (count($_REQUEST)>0) {
  38. $cdr_id = $_REQUEST["cdr_id"];
  39. $caller_id_name = $_REQUEST["caller_id_name"];
  40. $caller_id_number = $_REQUEST["caller_id_number"];
  41. $destination_number = $_REQUEST["destination_number"];
  42. $context = $_REQUEST["context"];
  43. $start_stamp = $_REQUEST["start_stamp"];
  44. $answer_stamp = $_REQUEST["answer_stamp"];
  45. $end_stamp = $_REQUEST["end_stamp"];
  46. $duration = $_REQUEST["duration"];
  47. $billsec = $_REQUEST["billsec"];
  48. $hangup_cause = $_REQUEST["hangup_cause"];
  49. $uuid = $_REQUEST["uuid"];
  50. $bleg_uuid = $_REQUEST["bleg_uuid"];
  51. $accountcode = $_REQUEST["accountcode"];
  52. $read_codec = $_REQUEST["read_codec"];
  53. $write_codec = $_REQUEST["write_codec"];
  54. $remote_media_ip = $_REQUEST["remote_media_ip"];
  55. $network_addr = $_REQUEST["network_addr"];
  56. }
  57. //call detail record list
  58. echo "<div align='center'>";
  59. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  60. echo "<tr class='border'>\n";
  61. echo " <td align=\"center\">\n";
  62. echo " <br>";
  63. echo "<table width='100%' border='0'><tr>\n";
  64. echo "<td align='left' width='50%' nowrap><b>Call Detail Records</b></td>\n";
  65. echo "<td align='left' width='50%' align='right'>&nbsp;</td>\n";
  66. echo "</tr>\n";
  67. echo "<tr>\n";
  68. echo "<td align='left' colspan='2'>\n";
  69. echo "Call Detail Records (CDRs) are detailed information on the calls. \n";
  70. echo "The information contains source, destination, duration, and other useful call details. \n";
  71. echo "Use the fields to filter the information for the specific call records that are desired. \n";
  72. echo "Then view the calls in the list or download them as comma seperated file by using the 'csv' button. \n";
  73. //To do an advanced search of the call detail records click on the following advanced button.
  74. echo "<br />\n";
  75. echo "<br />\n";
  76. echo "</td>\n";
  77. echo "</tr></table>\n";
  78. if (strlen($cdr_id) > 0) { $sql_where .= "and cdr_id like '%$cdr_id%' "; }
  79. if (strlen($caller_id_name) > 0) { $sql_where .= "and caller_id_name like '%$caller_id_name%' "; }
  80. if (strlen($caller_id_number) > 0) { $sql_where .= "and caller_id_number like '%$caller_id_number%' "; }
  81. if (strlen($destination_number) > 0) { $sql_where .= "and destination_number like '%$destination_number%' "; }
  82. if (strlen($context) > 0) { $sql_where .= "and context like '%$context%' "; }
  83. if (strlen($start_stamp) > 0) { $sql_where .= "and start_stamp like '%$start_stamp%' "; }
  84. if (strlen($answer_stamp) > 0) { $sql_where .= "and answer_stamp like '%$answer_stamp%' "; }
  85. if (strlen($end_stamp) > 0) { $sql_where .= "and end_stamp like '%$end_stamp%' "; }
  86. if (strlen($duration) > 0) { $sql_where .= "and duration like '%$duration%' "; }
  87. if (strlen($billsec) > 0) { $sql_where .= "and billsec like '%$billsec%' "; }
  88. if (strlen($hangup_cause) > 0) { $sql_where .= "and hangup_cause like '%$hangup_cause%' "; }
  89. if (strlen($uuid) > 0) { $sql_where .= "and uuid like '%$uuid%' "; }
  90. if (strlen($bleg_uuid) > 0) { $sql_where .= "and bleg_uuid like '%$bleg_uuid%' "; }
  91. if (strlen($accountcode) > 0) { $sql_where .= "and accountcode like '%$accountcode%' "; }
  92. if (strlen($read_codec) > 0) { $sql_where .= "and read_codec like '%$read_codec%' "; }
  93. if (strlen($write_codec) > 0) { $sql_where .= "and write_codec like '%$write_codec%' "; }
  94. if (strlen($remote_media_ip) > 0) { $sql_where .= "and remote_media_ip like '%$remote_media_ip%' "; }
  95. if (strlen($network_addr) > 0) { $sql_where .= "and network_addr like '%$network_addr%' "; }
  96. if (!if_group("admin") && !if_group("superadmin")) {
  97. $sql_where = "where ";
  98. if (count($_SESSION['user']['extension']) > 0) {
  99. foreach ($_SESSION['user']['extension'] as &$row) {
  100. if ($row['user'] > 0) { $sql_where .= "or domain_uuid = '$domain_uuid' and caller_id_number = '".$row['user']."' ". $sql_where_orig." \n"; } //source
  101. if ($row['user'] > 0) { $sql_where .= "or domain_uuid = '$domain_uuid' and destination_number = '".$row['user']."' ".$sql_where_orig." \n"; } //destination
  102. if ($row['user'] > 0) { $sql_where .= "or domain_uuid = '$domain_uuid' and destination_number = '*99".$row['user']."' ".$sql_where_orig." \n"; } //destination
  103. }
  104. }
  105. }
  106. else {
  107. //superadmin or admin
  108. $sql_where = "where domain_uuid = '$domain_uuid' ".$sql_where;
  109. }
  110. $sql_where = str_replace ("where or", "where", $sql_where);
  111. $sql_where = str_replace ("where and", " and", $sql_where);
  112. $sql = "";
  113. $sql .= " select * from v_cdr ";
  114. $sql .= $sql_where;
  115. if (strlen($order_by) == 0) {
  116. $sql .= "order by cdr_id desc ";
  117. }
  118. else {
  119. $sql .= "order by $order_by $order ";
  120. }
  121. $prep_statement = $db->prepare(check_sql($sql));
  122. $prep_statement->execute();
  123. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  124. $num_rows = count($result);
  125. unset ($prep_statement, $result, $sql);
  126. $param = "";
  127. $param .= "&caller_id_name=$caller_id_name";
  128. $param .= "&start_stamp=$start_stamp";
  129. $param .= "&hangup_cause=$hangup_cause";
  130. $param .= "&caller_id_number=$caller_id_number";
  131. $param .= "&destination_number=$destination_number";
  132. $param .= "&context=$context";
  133. $param .= "&answer_stamp=$answer_stamp";
  134. $param .= "&end_stamp=$end_stamp";
  135. $param .= "&duration=$duration";
  136. $param .= "&billsec=$billsec";
  137. $param .= "&uuid=$uuid";
  138. $param .= "&bleg_uuid=$bleg_uuid";
  139. $param .= "&accountcode=$accountcode";
  140. $param .= "&read_codec=$read_codec";
  141. $param .= "&write_codec=$write_codec";
  142. $param .= "&remote_media_ip=$remote_media_ip";
  143. $param .= "&network_addr=$network_addr";
  144. $rows_per_page = 200;
  145. $page = $_GET['page'];
  146. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  147. list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
  148. $offset = $rows_per_page * $page;
  149. $sql = "";
  150. $sql .= " select * from v_cdr ";
  151. $sql .= $sql_where;
  152. if (strlen($order_by) == 0) {
  153. $sql .= "order by cdr_id desc ";
  154. }
  155. else {
  156. $sql .= "order by $order_by $order ";
  157. }
  158. $sql .= " limit $rows_per_page offset $offset ";
  159. //echo $sql;
  160. $prep_statement = $db->prepare(check_sql($sql));
  161. $prep_statement->execute();
  162. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  163. $result_count = count($result);
  164. unset ($prep_statement, $sql);
  165. $c = 0;
  166. $row_style["0"] = "row_style0";
  167. $row_style["1"] = "row_style1";
  168. //search the call detail records
  169. if (if_group("admin") || if_group("superadmin")) {
  170. echo "<div align='center'>\n";
  171. echo "<form method='post' action=''>";
  172. echo "<table width='95%' cellpadding='3' border='0'>";
  173. echo "<tr>";
  174. echo "<td width='33.3%'>\n";
  175. echo "<table width='100%'>";
  176. //echo " <tr>";
  177. //echo " <td>Source Name:</td>";
  178. //echo " <td><input type='text' class='txt' name='caller_id_name' value='$caller_id_name'></td>";
  179. //echo " </tr>";
  180. echo " <tr>";
  181. echo " <td align='left' width='25%'>Start:</td>";
  182. echo " <td align='left' width='75%'><input type='text' class='txt' name='start_stamp' value='$start_stamp'></td>";
  183. echo " </tr>";
  184. echo " <tr>";
  185. echo " <td align='left' width='25%'>Status:</td>";
  186. echo " <td align='left' width='75%'><input type='text' class='txt' name='hangup_cause' value='$hangup_cause'></td>";
  187. echo " </tr>";
  188. echo "</table>\n";
  189. echo "</td>\n";
  190. echo "<td width='33.3%'>\n";
  191. echo "<table width='100%'>";
  192. echo " <tr>";
  193. echo " <td align='left' width='25%'>Source:</td>";
  194. echo " <td align='left' width='75%'><input type='text' class='txt' name='caller_id_number' value='$caller_id_number'></td>";
  195. echo " </tr>";
  196. echo " <tr>";
  197. echo " <td align='left' width='25%'>Destination:</td>";
  198. echo " <td align='left' width='75%'><input type='text' class='txt' name='destination_number' value='$destination_number'></td>";
  199. echo " </tr>";
  200. echo "</table>\n";
  201. echo "</td>\n";
  202. echo "<td width='33.3%'>\n";
  203. echo "<table width='100%'>\n";
  204. //echo " <tr>";
  205. //echo " <td>Context:</td>";
  206. //echo " <td><input type='text' class='txt' name='context' value='$context'></td>";
  207. //echo " </tr>";
  208. //echo " <tr>";
  209. //echo " <td>Answer:</td>";
  210. //echo " <td><input type='text' class='txt' name='answer_stamp' value='$answer_stamp'></td>";
  211. //echo " </tr>";
  212. //echo " <tr>";
  213. //echo " <td>End:</td>";
  214. //echo " <td><input type='text' class='txt' name='end_stamp' value='$end_stamp'></td>";
  215. //echo " </tr>";
  216. echo " <tr>";
  217. echo " <td align='left' width='25%'>Duration:</td>";
  218. echo " <td align='left' width='75%'><input type='text' class='txt' name='duration' value='$duration'></td>";
  219. echo " </tr>";
  220. echo " <tr>";
  221. echo " <td align='left' width='25%'>Bill:</td>";
  222. echo " <td align='left' width='75%'><input type='text' class='txt' name='billsec' value='$billsec'></td>";
  223. echo " </tr>";
  224. //echo " <tr>";
  225. //echo " <td>UUID:</td>";
  226. //echo " <td><input type='text' class='txt' name='uuid' value='$uuid'></td>";
  227. //echo " </tr>";
  228. //echo " <tr>";
  229. //echo " <td>Bleg UUID:</td>";
  230. //echo " <td><input type='text' class='txt' name='bleg_uuid' value='$bleg_uuid'></td>";
  231. //echo " </tr>";
  232. //echo " <tr>";
  233. //echo " <td>Account Code:</td>";
  234. //echo " <td><input type='text' class='txt' name='accountcode' value='$accountcode'></td>";
  235. //echo " </tr>";
  236. //echo " <tr>";
  237. //echo " <td>Read Codec:</td>";
  238. //echo " <td><input type='text' class='txt' name='read_codec' value='$read_codec'></td>";
  239. //echo " </tr>";
  240. //echo " <tr>";
  241. //echo " <td>Write Codec:</td>";
  242. //echo " <td><input type='text' class='txt' name='write_codec' value='$write_codec'></td>";
  243. //echo " </tr>";
  244. //echo " <tr>";
  245. //echo " <td>Remote Media IP:</td>";
  246. //echo " <td><input type='text' class='txt' name='remote_media_ip' value='$remote_media_ip'></td>";
  247. //echo " </tr>";
  248. //echo " <tr>";
  249. //echo " <td>Network Address:</td>";
  250. //echo " <td><input type='text' class='txt' name='network_addr' value='$network_addr'></td>";
  251. //echo " </tr>";
  252. //echo " <tr>";
  253. echo " </tr>";
  254. echo "</table>";
  255. echo "</td>";
  256. echo "</tr>";
  257. echo "<tr>\n";
  258. echo "<td colspan='2' align='right'>\n";
  259. //echo " <input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_search.php'\" value='advanced'>\n";
  260. echo "</td>\n";
  261. echo "<td colspan='1' align='right'>\n";
  262. echo " <input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_search.php'\" value='advanced'>&nbsp;\n";
  263. echo " <input type='submit' class='btn' name='submit' value='filter'>\n";
  264. echo "</td>\n";
  265. echo "</tr>";
  266. echo "</table>";
  267. echo "</form>";
  268. }
  269. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  270. echo "<tr>\n";
  271. echo "<th>Start</th>\n";
  272. //echo th_order_by('start_stamp', 'Start', $order_by, $order);
  273. echo th_order_by('caller_id_name', 'CID Name', $order_by, $order);
  274. echo "<th>Source</th>\n";
  275. //echo th_order_by('caller_id_number', 'Source', $order_by, $order);
  276. echo "<th>Destination</th>\n";
  277. //echo th_order_by('destination_number', 'Destination', $order_by, $order);
  278. //echo th_order_by('context', 'Context', $order_by, $order);
  279. //echo th_order_by('answer_stamp', 'Answer', $order_by, $order);
  280. //echo th_order_by('end_stamp', 'End', $order_by, $order);
  281. echo "<th>Duration</th>\n";
  282. //echo th_order_by('duration', 'Duration', $order_by, $order);
  283. echo "<th>Bill</th>\n";
  284. //echo th_order_by('billsec', 'Bill', $order_by, $order);
  285. echo "<th>Status</th>\n";
  286. //echo th_order_by('hangup_cause', 'Status', $order_by, $order);
  287. echo "<form method='post' action='v_cdr_csv.php'>";
  288. echo "<td align='left' width='22'>\n";
  289. echo "<input type='hidden' name='caller_id_name' value='$caller_id_name'>\n";
  290. echo "<input type='hidden' name='start_stamp' value='$start_stamp'>\n";
  291. echo "<input type='hidden' name='hangup_cause' value='$hangup_cause'>\n";
  292. echo "<input type='hidden' name='caller_id_number' value='$caller_id_number'>\n";
  293. echo "<input type='hidden' name='destination_number' value='$destination_number'>\n";
  294. echo "<input type='hidden' name='context' value='$context'>\n";
  295. echo "<input type='hidden' name='answer_stamp' value='$answer_stamp'>\n";
  296. echo "<input type='hidden' name='end_stamp' value='$end_stamp'>\n";
  297. echo "<input type='hidden' name='duration' value='$duration'>\n";
  298. echo "<input type='hidden' name='billsec' value='$billsec'>\n";
  299. echo "<input type='hidden' name='uuid' value='$uuid'>\n";
  300. echo "<input type='hidden' name='bleg_uuid' value='$bleg_uuid'>\n";
  301. echo "<input type='hidden' name='accountcode' value='$accountcode'>\n";
  302. echo "<input type='hidden' name='read_codec' value='$read_codec'>\n";
  303. echo "<input type='hidden' name='write_codec' value='$write_codec'>\n";
  304. echo "<input type='hidden' name='remote_media_ip' value='$remote_media_ip'>\n";
  305. echo "<input type='hidden' name='network_addr' value='$network_addr'>\n";
  306. echo "<input type='submit' class='btn' name='submit' value=' csv '>\n";
  307. //echo " <input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_csv.php?id=".$row[cdr_id]."'\" value='csv'>\n";
  308. //echo " <input type='button' class='btn' name='' alt='add' onclick=\"window.location='v_cdr_edit.php'\" value='+'>\n";
  309. echo "</td>\n";
  310. echo "</form>\n";
  311. echo "<tr>\n";
  312. if ($result_count == 0) { //no results
  313. }
  314. else { //received results
  315. foreach($result as $row) {
  316. //print_r( $row );
  317. echo "<tr >\n";
  318. echo " <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[start_stamp]."&nbsp;</td>\n";
  319. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[caller_id_name]."&nbsp;</td>\n";
  320. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[caller_id_number]."&nbsp;</td>\n";
  321. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[destination_number]."&nbsp;</td>\n";
  322. //echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[context]."&nbsp;</td>\n";
  323. //echo " <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[answer_stamp]."&nbsp;</td>\n";
  324. //echo " <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[end_stamp]."&nbsp;</td>\n";
  325. $duration = $row[duration];
  326. //if ($duration < 60) { $duration = $duration. " sec"; }
  327. //if ($duration > 60) { $duration = round(($duration/60), 2). " min"; }
  328. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;".$duration."&nbsp;</td>\n";
  329. echo " <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[billsec]."&nbsp;</td>\n";
  330. echo " <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".strtolower($row[hangup_cause])."&nbsp;</td>\n";
  331. echo " <td valign='top' align='right'>\n";
  332. //echo " <a href='v_cdr_edit.php?id=".$row[cdr_id]."' alt='add'>$v_link_label_view</a>\n";
  333. echo " <input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_edit.php?id=".$row[cdr_id]."'\" value=' > '>\n";
  334. //echo " <input type='button' class='btn' name='' alt='delete' onclick=\"if (confirm('Are you sure you want to delete this?')) { window.location='v_cdr_delete.php?id=".$row[cdr_id]."' }\" value='x'>\n";
  335. echo " </td>\n";
  336. echo "</tr>\n";
  337. if ($c==0) { $c=1; } else { $c=0; }
  338. } //end foreach
  339. unset($sql, $result, $row_count);
  340. } //end if results
  341. echo "<tr>\n";
  342. echo "<td colspan='7'>\n";
  343. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  344. echo " <tr>\n";
  345. echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
  346. echo " <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
  347. echo " <td width='33.3%' align='right'>&nbsp;</td>\n";
  348. //echo " <td width='33.3%' align='right'><input type='button' class='btn' name='' alt='add' onclick=\"window.location='v_cdr_edit.php'\" value='+'></td>\n";
  349. echo " </tr>\n";
  350. echo " </table>\n";
  351. echo "</td>\n";
  352. echo "</tr>\n";
  353. echo "</table>";
  354. echo "</div>";
  355. echo "<br><br>";
  356. echo "<br><br>";
  357. echo "</td>";
  358. echo "</tr>";
  359. echo "</table>";
  360. echo "</div>";
  361. echo "<br><br>";
  362. require "resources/require.php";
  363. require_once "resources/footer.php";
  364. ?>