sms_mdr.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /* $Id$ */
  3. /*
  4. call.php
  5. Copyright (C) 2008, 2009 Mark J Crane
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are met:
  9. 1. Redistributions of source code must retain the above copyright notice,
  10. this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  16. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  17. AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  18. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. POSSIBILITY OF SUCH DAMAGE.
  24. Contributor(s):
  25. Mark J Crane <[email protected]>
  26. James Rose <[email protected]>
  27. */
  28. //includes files
  29. require_once dirname(__DIR__, 2) . "/resources/require.php";
  30. require_once "resources/check_auth.php";
  31. //check permissions
  32. if (permission_exists('sms_view')) {
  33. //access granted
  34. }
  35. else {
  36. echo "access denied";
  37. exit;
  38. }
  39. //add multi-lingual support
  40. $language = new text;
  41. $text = $language->get();
  42. //include the header
  43. require_once "resources/header.php";
  44. require_once "resources/paging.php";
  45. //set variables
  46. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  47. //$sql = "select domain_name, extension, sms_message_uuid,start_stamp,from_number,to_number,message,direction from v_sms_messages, v_domains, v_extensions where v_sms_messages.domain_uuid = v_domains.domain_uuid and v_sms_messages.extension_uuid = v_extensions.extension_uuid and v_domains.domain_uuid = :domain_uuid order by start_stamp DESC";
  48. $num_rows = '0';
  49. $param = "";
  50. //get the number of rows in the v_xml_cdr
  51. $sql = "select count(*) as num_rows from v_sms_messages, v_domains ";
  52. $sql .= "WHERE v_domains.domain_uuid = v_sms_messages.domain_uuid and v_domains.domain_uuid = '" . $domain_uuid . "' ";
  53. $prep_statement = $db->prepare(check_sql($sql));
  54. if ($prep_statement) {
  55. $prep_statement->execute();
  56. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  57. if ($row['num_rows'] > 0) {
  58. $num_rows = $row['num_rows'];
  59. } else {
  60. $num_rows = '0';
  61. }
  62. }
  63. unset($prep_statement, $result);
  64. //set the default paging
  65. if ($_SESSION['domain']['paging']['numeric'] != '' && $rows_per_page > $_SESSION['domain']['paging']['numeric']) {
  66. $rows_per_page = $_SESSION['domain']['paging']['numeric'];
  67. } else {
  68. $rows_per_page = 50;
  69. }
  70. //prepare to page the results
  71. //$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; //set on the page that includes this page
  72. $page = $_GET['page'];
  73. if (strlen($page) == 0) {
  74. $page = 0;
  75. $_GET['page'] = 0;
  76. }
  77. list($paging_controls_mini, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page, true); //top
  78. list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); //bottom
  79. $offset = $rows_per_page * $page;
  80. //get messages from the database
  81. $sql = "SELECT domain_name, v_sms_messages.extension_uuid as extension, sms_message_uuid,start_stamp,from_number,to_number,message,direction ";
  82. $sql .= "FROM v_sms_messages, v_domains ";
  83. $sql .= "WHERE v_domains.domain_uuid = v_sms_messages.domain_uuid ";
  84. $sql .= "and v_domains.domain_uuid = :domain_uuid order by start_stamp DESC ";
  85. if ($rows_per_page == 0) {
  86. $sql .= " limit " . $_SESSION['cdr']['limit']['numeric'] . " offset 0 ";
  87. } else {
  88. $sql .= " limit " . $rows_per_page . " offset " . $offset . " ";
  89. }
  90. error_log("SQL: " . print_r($sql,true));
  91. $prep_statement = $db->prepare(check_sql($sql));
  92. $prep_statement->execute(array(':domain_uuid' => $domain_uuid));
  93. $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
  94. $result_count = count($result);
  95. unset ($prep_statement, $sql);
  96. $c = 0;
  97. $row_style["0"] = "row_style0";
  98. $row_style["1"] = "row_style1";
  99. //mod paging parameters for inclusion in column sort heading links
  100. $param = substr($param, 1); //remove leading '&'
  101. $param = substr($param, 0, strrpos($param, '&order_by=')); //remove trailing order by
  102. //show the results
  103. $col_count = 6;
  104. echo "<form name='frm' method='post' action='xml_cdr_delete.php'>\n";
  105. echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  106. echo "<tr>\n";
  107. echo "<th>&nbsp;</th>\n";
  108. if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) {
  109. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param);
  110. $col_count++;
  111. }
  112. echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, null, $param);
  113. echo th_order_by('start_stamp', $text['label-start'], $order_by, $order, null, "style='text-align: center;'", $param);
  114. echo th_order_by('caller_id_number', $text['label-source'], $order_by, $order, null, null, $param);
  115. echo th_order_by('destination_number', $text['label-destination'], $order_by, $order, null, null, $param);
  116. echo th_order_by('message', $text['label-message'], $order_by, $order, null, null, $param);
  117. echo "</tr>\n";
  118. if ($result_count > 0) {
  119. echo "<tr>\n";
  120. //determine if theme images exist
  121. $theme_image_path = $_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/";
  122. $theme_cdr_images_exist = (
  123. file_exists($theme_image_path."icon_cdr_inbound_answered.png") &&
  124. file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") &&
  125. file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") &&
  126. file_exists($theme_image_path."icon_cdr_inbound_failed.png") &&
  127. file_exists($theme_image_path."icon_cdr_outbound_answered.png") &&
  128. file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") &&
  129. file_exists($theme_image_path."icon_cdr_outbound_failed.png") &&
  130. file_exists($theme_image_path."icon_cdr_local_answered.png") &&
  131. file_exists($theme_image_path."icon_cdr_local_voicemail.png") &&
  132. file_exists($theme_image_path."icon_cdr_local_cancelled.png") &&
  133. file_exists($theme_image_path."icon_cdr_local_failed.png")
  134. ) ? true : false;
  135. foreach($result as $index => $row) {
  136. $tmp_start_epoch = ($_SESSION['domain']['time_format']['text'] == '12h') ? date("j M Y g:i:sa", $row['start_stamp']) : date("j M Y H:i:s", $row['start_epoch']);
  137. $extension = " - ";
  138. if(!empty($row['extension'])) {
  139. $sql = "SELECT extension FROM v_extensions WHERE extension_uuid = :extension_uuid";
  140. $prep_statement = $db->prepare(check_sql($sql));
  141. $prep_statement->execute(array(':extension_uuid' => $row['extension']));
  142. $result = $prep_statement->fetch(PDO::FETCH_ASSOC);
  143. $extension = !empty($result['extension'])?$result['extension']:" - ";
  144. }
  145. //determine call result and appropriate icon
  146. echo "<td valign='top' class='".$row_style[$c]."'>\n";
  147. if ($theme_cdr_images_exist) {
  148. $call_result = 'answered';
  149. echo "<img src='".PROJECT_PATH."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_".$row['direction']."_".$call_result.".png' width='16' style='border: none; cursor: help;' title='".$text['label-'.$row['direction']].": ".$text['label-'.$call_result]."'>\n";
  150. }
  151. else { echo "&nbsp;"; }
  152. echo "</td>\n";
  153. //domain name
  154. if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) {
  155. echo " <td valign='top' class='".$row_style[$c]."'>";
  156. echo $row['domain_name'].'&nbsp;';
  157. echo " </td>\n";
  158. }
  159. echo " <td valign='top' class='".$row_style[$c]."'>".escape($extension)."&nbsp;</td>\n";
  160. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['start_stamp'])."&nbsp;</td>\n";
  161. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['from_number'])."&nbsp;</td>\n";
  162. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['to_number'])."&nbsp;</td>\n";
  163. echo " <td valign='top' class='".$row_style[$c]."'>".escape(urldecode($row['message']))."&nbsp;</td>\n";
  164. echo "</tr>\n";
  165. $c = ($c) ? 0 : 1;
  166. } // end foreach
  167. unset($sql, $result, $row_count);
  168. } // end if
  169. echo "</table>\n";
  170. echo "</form>\n";
  171. echo "<br><br>";
  172. if ($result_count == $rows_per_page) {
  173. echo $paging_controls;
  174. }
  175. echo "<br><br>";
  176. //show the footer
  177. require_once "resources/footer.php";
  178. ?>