sms.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('sms_view')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //add multi-lingual support
  32. $language = new text;
  33. $text = $language->get();
  34. //get the http values and set them as variables
  35. $search = check_str($_GET["search"]);
  36. $order_by = check_str($_GET["order_by"]);
  37. $order = check_str($_GET["order"]);
  38. require_once "resources/header.php";
  39. $document['title'] = $text['title-sms'];
  40. require_once "resources/paging.php";
  41. //get total extension count from the database
  42. $sql = "select ";
  43. $sql .= "(select count(*) from v_sms_destinations where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod.") as num_rows ";
  44. if ($db_type == "pgsql") {
  45. $sql .= ",(select count(*) as count from v_sms_destinations ";
  46. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  47. $sql .= ") as numeric_sms ";
  48. }
  49. $prep_statement = $db->prepare($sql);
  50. if ($prep_statement) {
  51. $prep_statement->execute();
  52. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  53. $total_sms_destinations = $row['num_rows'];
  54. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  55. $numeric_sms = $row['numeric_sms'];
  56. }
  57. }
  58. unset($prep_statement, $row);
  59. //prepare to page the results
  60. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  61. $param = "&search=".$search;
  62. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  63. $_GET['page'] = check_str($_GET['page']);
  64. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_sms_destinations, $param, $rows_per_page, true); //top
  65. list($paging_controls, $rows_per_page, $var_3) = paging($total_sms_destinations, $param, $rows_per_page); //bottom
  66. $offset = $rows_per_page * $_GET['page'];
  67. //to cast or not to cast
  68. if ($db_type == "pgsql") {
  69. $order_text = ($total_sms_destinations == $numeric_sms) ? "cast(destination as bigint)" : "destination asc";
  70. }
  71. else {
  72. //$order_text = "extension asc"; //extension doesn't exist in this table 8/23/2018/jblack
  73. $order_text = "destination asc";
  74. }
  75. //get the extensions
  76. $sql = "select * from v_sms_destinations ";
  77. $sql .= "where domain_uuid = '$domain_uuid' ";
  78. $sql .= $sql_mod; //add search mod from above
  79. if (strlen($order_by) > 0) {
  80. $sql .= ($order_by == 'destination') ? "order by $order_text ".$order." " : "order by ".$order_by." ".$order." ";
  81. }
  82. else {
  83. $sql .= "order by $order_text ";
  84. }
  85. $sql .= "limit $rows_per_page offset $offset ";
  86. $prep_statement = $db->prepare(check_sql($sql));
  87. $prep_statement->execute();
  88. $sms_destinations = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  89. //echo $sql;
  90. unset ($prep_statement, $sql);
  91. //show the content
  92. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  93. echo " <tr>\n";
  94. echo " <td align='left' width='100%'><b>".$text['header-sms']." (".$total_sms_destinations.")</b><br>\n";
  95. echo " ".$text['description-sms']."\n";
  96. echo " </td>\n";
  97. echo " <form method='get' action=''>\n";
  98. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  99. if (if_group("superadmin")) {
  100. echo " <input type='button' class='btn' style='margin-right: 15px;' value='".$text['button-mdr']."' onclick=\"window.location.href='sms_mdr.php'\">\n";
  101. }
  102. echo " <input type='button' class='btn' style='margin-right: 15px;' value='".$text['button-broadcast']."' onclick=\"window.location.href='sms_broadcast.php'\">\n";
  103. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
  104. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  105. if ($paging_controls_mini != '') {
  106. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  107. }
  108. echo " </td>\n";
  109. echo " </form>\n";
  110. echo " </tr>\n";
  111. echo "</table>\n";
  112. echo "<br />";
  113. $c = 0;
  114. $row_style["0"] = "row_style0";
  115. $row_style["1"] = "row_style1";
  116. echo "<form name='frm' method='post' action='sms_delete.php'>\n";
  117. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  118. echo "<tr>\n";
  119. if (permission_exists('sms_delete') && is_array($sms_destinations)) {
  120. echo "<th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' id='chk_all' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
  121. }
  122. echo th_order_by('destination', $text['label-destination'], $order_by, $order);
  123. echo th_order_by('carrier', $text['label-carrier'], $order_by, $order);
  124. echo th_order_by('enabled', $text['label-enabled'], $order_by, $order);
  125. echo th_order_by('description', $text['label-description'], $order_by, $order);
  126. echo "<td class='list_control_icon'>\n";
  127. if (permission_exists('sms_add')) {
  128. echo "<a href='sms_edit.php' alt='".$text['button-add']."'>".$v_link_label_add."</a>";
  129. }
  130. if (permission_exists('sms_delete') && is_array($sms_destinations)) {
  131. echo "<a href='javascript:void(0);' onclick=\"if (confirm('".$text['confirm-delete']."')) { document.forms.frm.submit(); }\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
  132. }
  133. echo "</td>\n";
  134. echo "</tr>\n";
  135. if (!empty($sms_destinations) && is_array($sms_destinations)) {
  136. foreach($sms_destinations as $row) {
  137. $tr_link = (permission_exists('sms_edit')) ? " href='sms_edit.php?id=".$row['sms_destination_uuid']."'" : null;
  138. echo "<tr ".$tr_link.">\n";
  139. if (permission_exists('sms_delete')) {
  140. echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='text-align: center; vertical-align: middle; padding: 0px;'>";
  141. echo " <input type='checkbox' name='id[]' id='checkbox_".$row['sms_destination_uuid']."' value='".$row['sms_destination_uuid']."' onclick=\"if (!this.checked) { document.getElementById('chk_all').checked = false; }\">";
  142. echo " </td>";
  143. $ext_ids[] = 'checkbox_'.$row['sms_destination_uuid'];
  144. }
  145. echo " <td valign='top' class='".$row_style[$c]."'>";
  146. if (permission_exists('sms_edit')) {
  147. echo "<a href='sms_edit.php?id=".$row['sms_destination_uuid']."'>".$row['destination']."</a>";
  148. }
  149. else {
  150. echo $row['destination'];
  151. }
  152. echo "</td>\n";
  153. echo " <td valign='top' class='".$row_style[$c]."'>".$row['carrier']."</td>\n";
  154. echo " <td valign='top' class='".$row_style[$c]."'>".ucwords($row['enabled'])."</td>\n";
  155. echo " <td valign='top' class='row_stylebg' width='30%'>".$row['description']."&nbsp;</td>\n";
  156. echo " <td class='list_control_icons'>";
  157. if (permission_exists('sms_edit')) {
  158. echo "<a href='sms_edit.php?id=".$row['sms_destination_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
  159. }
  160. if (permission_exists('sms_delete')) {
  161. echo "<a href='sms_delete.php?id[]=".$row['sms_destination_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
  162. }
  163. echo "</td>\n";
  164. echo "</tr>\n";
  165. $c = ($c) ? 0 : 1;
  166. }
  167. unset($sms_destinations, $row);
  168. }
  169. if (is_array($sms_destinations)) {
  170. echo "<tr>\n";
  171. echo " <td colspan='20' class='list_control_icons'>\n";
  172. if (permission_exists('sms_add')) {
  173. echo "<a href='sms_edit.php' alt='".$text['button-add']."'>".$v_link_label_add."</a>";
  174. }
  175. if (permission_exists('sms_delete')) {
  176. echo "<a href='javascript:void(0);' onclick=\"if (confirm('".$text['confirm-delete']."')) { document.forms.frm.submit(); }\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
  177. }
  178. echo " </td>\n";
  179. echo "</tr>\n";
  180. }
  181. echo "</table>";
  182. echo "</form>";
  183. if (strlen($paging_controls) > 0) {
  184. echo "<center>".$paging_controls."</center>\n";
  185. }
  186. echo "<br /><br />".((is_array($sms_destinations)) ? "<br /><br />" : null);
  187. // check or uncheck all checkboxes
  188. if (!empty($ext_ids) && sizeof($ext_ids) > 0) {
  189. echo "<script>\n";
  190. echo " function check(what) {\n";
  191. echo " document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
  192. foreach ($ext_ids as $ext_id) {
  193. echo " document.getElementById('".$ext_id."').checked = (what == 'all') ? true : false;\n";
  194. }
  195. echo " }\n";
  196. echo "</script>\n";
  197. }
  198. if (!empty($sms_destinations) && is_array($sms_destinations)) {
  199. // check all checkboxes
  200. key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true);
  201. // delete checked
  202. key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], 'document.forms.frm.submit();', true);
  203. }
  204. //show the footer
  205. require_once "resources/footer.php";
  206. ?>