mobile_twinning.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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-2016
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. KonradSC <[email protected]>
  20. Mark J Crane <[email protected]>
  21. */
  22. //includes
  23. include "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. require_once "resources/paging.php";
  27. //check permissions
  28. if (permission_exists('mobile_twinning_view')) {
  29. //access granted
  30. }
  31. else {
  32. echo "access denied";
  33. exit;
  34. }
  35. //add multi-lingual support
  36. $language = new text;
  37. $text = $language->get();
  38. //get the https values and set as variables
  39. $order_by = check_str($_GET["order_by"]);
  40. $order = check_str($_GET["order"]);
  41. //handle search term
  42. $search = check_str($_GET["search"]);
  43. if (strlen($search) > 0) {
  44. $sql_mod = "and ( ";
  45. $sql_mod .= "e.extension ILIKE '%".$search."%' ";
  46. $sql_mod .= "or m.mobile_twinning_description ILIKE '%".$search."%' ";
  47. $sql_mod .= "or m.mobile_twinning_number ILIKE '%".$search."%' ";
  48. $sql_mod .= ") ";
  49. }
  50. if (strlen($order_by) < 1) {
  51. $order_by = "e.extension";
  52. $order = "ASC";
  53. }
  54. //get total extension count from the database
  55. $sql = "select count(*) as num_rows from v_extensions where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod." ";
  56. $prep_statement = $db->prepare($sql);
  57. if ($prep_statement) {
  58. $prep_statement->execute();
  59. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  60. $total_extensions = $row['num_rows'];
  61. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  62. $numeric_extensions = $row['num_rows'];
  63. }
  64. }
  65. unset($prep_statement, $row);
  66. //prepare to page the results
  67. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  68. $param = "&search=".$search."&order_by=".$order_by."&order=".$order;
  69. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  70. $_GET['page'] = check_str($_GET['page']);
  71. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page, true); //top
  72. list($paging_controls, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page); //bottom
  73. $offset = $rows_per_page * $_GET['page'];
  74. //get all the extensions from the database
  75. $sql = "select e.extension, m.mobile_twinning_number, e.description, m.mobile_twinning_uuid, e.extension_uuid \n";
  76. $sql .= "FROM v_extensions AS e \n ";
  77. $sql .= "LEFT OUTER JOIN v_mobile_twinnings AS m ON m.extension_uuid = e.extension_uuid ";
  78. $sql .= "where e.domain_uuid = '$domain_uuid' ";
  79. $sql .= $sql_mod; //add search mod from above
  80. $sql .= "and e.enabled = 'true' ";
  81. if (strlen($order_by)> 0) {
  82. $sql .= "order by $order_by $order ";
  83. }
  84. else {
  85. $sql .= "order by extension asc ";
  86. }
  87. $sql .= " limit $rows_per_page offset $offset ";
  88. $prep_statement = $db->prepare(check_sql($sql));
  89. $prep_statement->execute();
  90. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  91. $result_count = count($result);
  92. unset ($prep_statement, $sql);
  93. //set the alternating styles
  94. $c = 0;
  95. $row_style["0"] = "row_style0";
  96. $row_style["1"] = "row_style1";
  97. //begin the content
  98. require_once "resources/header.php";
  99. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  100. echo " <tr>\n";
  101. echo " <td align='left' width='100%'>\n";
  102. echo " <b>".$text['header-mobile_twinning']." (".$numeric_extensions.")</b><br>\n";
  103. echo " </td>\n";
  104. echo " <td align='right' width='100%' style='vertical-align: top;'>";
  105. if ((if_group("admin") || if_group("superadmin"))) {
  106. echo " <form method='get' action=''>\n";
  107. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  108. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
  109. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  110. if ($paging_controls_mini != '') {
  111. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  112. }
  113. echo " </td>\n";
  114. echo " </td>\n";
  115. echo " </form>\n";
  116. }
  117. echo " </tr>\n";
  118. echo " <tr>\n";
  119. echo " <td colspan='2'>\n";
  120. echo " ".$text['description-mobile_twinning']."\n";
  121. echo " </td>\n";
  122. echo " </tr>\n";
  123. echo "</table>\n";
  124. echo "<br>";
  125. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  126. echo "<tr>\n";
  127. echo th_order_by('extension', $text['table-extension'], $order_by,$order);
  128. echo th_order_by('m.mobile_twinning_number', $text['table-twinning_number'], $order_by, $order);
  129. echo th_order_by('e.description', $text['table-description'], $order_by, $order);
  130. echo "</tr>\n";
  131. if ($result_count > 0) {
  132. foreach($result as $row) {
  133. $tr_link = (permission_exists('mobile_twinning_edit')) ? " href='mobile_twinning_edit.php?id=".$row['mobile_twinning_uuid']."&extid=".$row['extension_uuid']."'" : null;
  134. echo "<tr ".$tr_link.">\n";
  135. echo " <td valign='top' class='".$row_style[$c]."'>".$row['extension']."</td>\n";
  136. echo " <td valign='top' class='".$row_style[$c]."'>".format_phone(substr($row['mobile_twinning_number'],-10))."</td>\n";
  137. echo " <td valign='top' class='row_stylebg' width='40%'>".$row['description']."&nbsp;</td>\n";
  138. echo "</tr>\n";
  139. if ($c==0) { $c=1; } else { $c=0; }
  140. } //end foreach
  141. unset($sql, $result, $row_count);
  142. } //end if results
  143. echo "</table>";
  144. if (strlen($paging_controls) > 0) {
  145. echo "<br />";
  146. echo $paging_controls."\n";
  147. }
  148. echo "<br><br>";
  149. //show the footer
  150. require_once "resources/footer.php";
  151. ?>