mobile_twinning.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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-2025
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. KonradSC <[email protected]>
  20. Mark J Crane <[email protected]>
  21. */
  22. //includes
  23. require_once dirname(__DIR__, 2) . "/resources/require.php";
  24. require_once "resources/pdo.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. //initialize the database object
  36. $database = new database;
  37. //add multi-lingual support
  38. $language = new text;
  39. $text = $language->get();
  40. //get order and order by
  41. $order_by = $_GET["order_by"] ?? 'extension';
  42. $order = $_GET["order"] ?? 'asc';
  43. $sort = $order_by == 'extension' ? 'natural' : null;
  44. //get total extension count for domain
  45. if (isset($_SESSION['limit']['extensions']['numeric'])) {
  46. $sql = "select count(*) from v_extensions ";
  47. $sql .= "where domain_uuid = :domain_uuid ";
  48. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  49. $total_extensions = $database->select($sql, $parameters, 'column');
  50. unset($sql, $parameters);
  51. }
  52. //add the search term
  53. $search = strtolower($_GET["search"] ?? '');
  54. //get total extension count
  55. $sql = "select count(*) from v_extensions ";
  56. $sql .= "where true ";
  57. if (!(!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('extension_all'))) {
  58. $sql .= "and domain_uuid = :domain_uuid ";
  59. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  60. }
  61. if (!empty($search)) {
  62. $sql .= "and ( ";
  63. $sql .= " lower(extension) like :search ";
  64. $sql .= " or lower(mobile_twinning_number) like :search ";
  65. $sql .= " or lower(description) like :search ";
  66. $sql .= ") ";
  67. $parameters['search'] = '%'.$search.'%';
  68. }
  69. $num_rows = $database->select($sql, $parameters ?? null, 'column');
  70. //prepare to page the results
  71. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  72. $param = "&search=".$search."&order_by=".$order_by."&order=".$order;
  73. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  74. $_GET['page'] = check_str($_GET['page']);
  75. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page, true); //top
  76. list($paging_controls, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page); //bottom
  77. $offset = $rows_per_page * $_GET['page'];
  78. //get all the extensions from the database
  79. $sql = "select e.extension, m.mobile_twinning_number, e.description, m.mobile_twinning_uuid, e.extension_uuid \n";
  80. $sql .= "FROM v_extensions AS e \n ";
  81. $sql .= "LEFT OUTER JOIN v_mobile_twinnings AS m ON m.extension_uuid = e.extension_uuid ";
  82. $sql .= "where true ";
  83. if (!(!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('extension_all'))) {
  84. $sql .= "and e.domain_uuid = :domain_uuid ";
  85. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  86. }
  87. if (!empty($search)) {
  88. $sql .= "and ( ";
  89. $sql .= " lower(extension) like :search ";
  90. $sql .= " or lower(mobile_twinning_number) like :search ";
  91. $sql .= " or lower(description) like :search ";
  92. $sql .= ") ";
  93. $parameters['search'] = '%'.$search.'%';
  94. }
  95. $sql .= "and e.enabled = 'true' ";
  96. if (strlen($order_by)> 0) {
  97. $sql .= "order by $order_by $order ";
  98. }
  99. else {
  100. $sql .= "order by extension asc ";
  101. }
  102. $sql .= " limit $rows_per_page offset $offset ";
  103. $result = $database->select($sql, $parameters ?? null, 'all');
  104. $result_count = count($result);
  105. unset($parameters, $sql);
  106. //create token
  107. $object = new token;
  108. $token = $object->create($_SERVER['PHP_SELF']);
  109. //include the header
  110. require_once "resources/header.php";
  111. //set the alternating styles
  112. $c = 0;
  113. $row_style["0"] = "row_style0";
  114. $row_style["1"] = "row_style1";
  115. //begin the content
  116. echo "<div class='action_bar' id='action_bar'>\n";
  117. echo " <div class='heading'><b>".$text['header-mobile_twinning']."</b><div class='count'>".number_format($result_count)."</div></div>\n";
  118. echo " <div class='actions'>\n";
  119. if ((if_group("admin") || if_group("superadmin"))) {
  120. echo " <form method='get' action=''>\n";
  121. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
  122. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  123. if ($paging_controls_mini != '') {
  124. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  125. }
  126. echo " </form>\n";
  127. }
  128. echo " </div>\n";
  129. echo " <div style='clear: both;'></div>\n";
  130. echo "</div>\n";
  131. echo $text['description-mobile_twinning']."\n";
  132. echo "<br /><br />";
  133. echo "<div class='card'>\n";
  134. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  135. echo "<tr>\n";
  136. echo th_order_by('extension', $text['table-extension'], $order_by,$order);
  137. echo th_order_by('m.mobile_twinning_number', $text['table-twinning_number'], $order_by, $order);
  138. echo th_order_by('e.description', $text['table-description'], $order_by, $order);
  139. echo "</tr>\n";
  140. if ($result_count > 0) {
  141. foreach($result as $row) {
  142. $tr_link = (permission_exists('mobile_twinning_edit')) ? " href='mobile_twinning_edit.php?id=".$row['mobile_twinning_uuid']."&extid=".$row['extension_uuid']."'" : null;
  143. echo "<tr ".$tr_link.">\n";
  144. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['extension'])."</td>\n";
  145. echo " <td valign='top' class='".$row_style[$c]."'>".escape(format_phone(substr($row['mobile_twinning_number'],-10)))."</td>\n";
  146. echo " <td valign='top' class='row_stylebg' width='40%'>".escape($row['description'])."&nbsp;</td>\n";
  147. echo " <td class='list_control_icons'>";
  148. echo " <a href='mobile_twinning_edit.php?id=".$row['mobile_twinning_uuid']."&extid=".$row['extension_uuid']."'>$v_link_label_edit</a>";
  149. echo " </td>\n";
  150. echo "</tr>\n";
  151. if ($c==0) { $c=1; } else { $c=0; }
  152. } //end foreach
  153. unset($sql, $result, $row_count);
  154. } //end if results
  155. echo "</table>";
  156. echo "</div>\n";
  157. if (strlen($paging_controls) > 0) {
  158. echo "<br />";
  159. echo $paging_controls."\n";
  160. }
  161. echo "<br><br>";
  162. //show the footer
  163. require_once "resources/footer.php";
  164. ?>