mobile_twinning.php 6.0 KB

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