zoiper.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/pdo.php";
  24. require_once "resources/check_auth.php";
  25. require_once "resources/paging.php";
  26. //check permissions
  27. if (permission_exists('zoiper')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //get the https values and set as variables
  38. $order_by = check_str($_GET["order_by"]);
  39. $order = check_str($_GET["order"]);
  40. //get the SIP port if set. If not default will be 5060 in zoiper app
  41. if (isset($_SESSION['zoiper']['sip_port']['text'])) {
  42. $zoiper_sip_port = ":" . $_SESSION['zoiper']['sip_port']['text'];
  43. }
  44. //handle search term
  45. $search = check_str($_GET["search"]);
  46. if (strlen($search) > 0) {
  47. $sql_mod = "and ( ";
  48. $sql_mod .= "extension ILIKE '%".$search."%' ";
  49. $sql_mod .= "or description ILIKE '%".$search."%' ";
  50. $sql_mod .= ") ";
  51. }
  52. if (strlen($order_by) < 1) {
  53. $order_by = "extension";
  54. $order = "ASC";
  55. }
  56. //get total extension count from the database
  57. $sql = "select count(*) as num_rows from v_extensions where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod." ";
  58. //$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  59. $prep_statement = $db->prepare($sql);
  60. if ($prep_statement) {
  61. $prep_statement->execute();
  62. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  63. $total_extensions = $row['num_rows'];
  64. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  65. $numeric_extensions = $row['num_rows'];
  66. }
  67. }
  68. unset($prep_statement, $row);
  69. //prepare to page the results
  70. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  71. $param = "&search=".$search."&order_by=".$order_by."&order=".$order;
  72. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  73. $_GET['page'] = check_str($_GET['page']);
  74. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page, true); //top
  75. list($paging_controls, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page); //bottom
  76. $offset = $rows_per_page * $_GET['page'];
  77. //get all the extensions from the database
  78. $sql = "select * from v_extensions ";
  79. $sql .= "where domain_uuid = '$domain_uuid' ";
  80. $sql .= $sql_mod; //add search mod from above
  81. $sql .= "and enabled = 'true' ";
  82. if (!(if_group("admin") || if_group("superadmin"))) {
  83. if (count($_SESSION['user']['extension']) > 0) {
  84. $sql .= "and (";
  85. $x = 0;
  86. foreach($_SESSION['user']['extension'] as $row) {
  87. if ($x > 0) { $sql .= "or "; }
  88. $sql .= "extension = '".$row['user']."' ";
  89. $x++;
  90. }
  91. $sql .= ")";
  92. }
  93. else {
  94. //hide any results when a user has not been assigned an extension
  95. $sql .= "and extension = 'disabled' ";
  96. }
  97. }
  98. if (strlen($order_by)> 0) {
  99. $sql .= "order by $order_by $order ";
  100. }
  101. else {
  102. $sql .= "order by extension asc ";
  103. }
  104. $sql .= " limit $rows_per_page offset $offset ";
  105. $prep_statement = $db->prepare(check_sql($sql));
  106. $prep_statement->execute();
  107. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  108. $result_count = count($result);
  109. unset ($prep_statement, $sql);
  110. $c = 0;
  111. $row_style["0"] = "row_style0";
  112. $row_style["1"] = "row_style1";
  113. //begin the content
  114. require_once "resources/header.php";
  115. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  116. echo " <tr>\n";
  117. echo " <td align='left' width='100%'>\n";
  118. echo " <b>".$text['title']."</b><br>\n";
  119. echo " </td>\n";
  120. echo " <td align='right' width='100%' style='vertical-align: top;'>\n";
  121. if ((if_group("admin") || if_group("superadmin"))) {
  122. echo " <form method='get' action=''>\n";
  123. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  124. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".escape($search)."'>\n";
  125. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n";
  126. if ($paging_controls_mini != '') {
  127. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  128. }
  129. echo " </td>\n";
  130. echo " </td>\n";
  131. echo " </form>\n";
  132. }
  133. echo " </tr>\n";
  134. echo " <tr>\n";
  135. echo " <td colspan='2'>\n";
  136. echo " ".$text['description-zoiper']."\n";
  137. echo " </td>\n";
  138. echo " </tr>\n";
  139. echo " <tr>\n";
  140. echo " <td colspan='2'>\n";
  141. echo " <b>".$text['title-mobile']."</b><br>\n";
  142. echo " </td>\n";
  143. echo " </tr>\n";
  144. echo " <tr>\n";
  145. echo " <td colspan='2'>\n";
  146. echo " ".$text['description-zoiper2']."\n";
  147. echo " </td>\n";
  148. echo " </tr>\n";
  149. echo "</table>\n";
  150. echo "<br>\n";
  151. echo "<div class='card'>\n";
  152. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  153. echo "<tr>\n";
  154. echo th_order_by('extension', $text['table-extension'], $order_by,$order);
  155. echo "<th>".$text['table-tools']."</th>\n";
  156. echo "<th>".$text['table-qr']."</th>\n";
  157. // echo "<th>".$text['table-password']."</th>\n";
  158. echo th_order_by('description', $text['table-description'], $order_by, $order);
  159. echo "</tr>\n";
  160. if ($result_count > 0) {
  161. foreach($result as $row) {
  162. $tr_url = "https://www.zoiper.com/en/page/" . $_SESSION['zoiper']['page_id']['text'] . "?u=" . escape($row['extension']) . "&h=" . escape($row['user_context']) . rawurlencode($zoiper_sip_port) . "&p=" . escape($row['password']) . "&o=" . $_SESSION['zoiper']['outbound_proxy']['text'] . "&t=&x=&a=" . escape($row['extension']) . "&tr=";
  163. $qr_img = "https://oem.zoiper.com/qr.php?provider_id=" . $_SESSION['zoiper']['provider_id']['text'] . "&u=" . escape($row['extension']) . "&h=" . escape($row['user_context']) . rawurlencode($zoiper_sip_port) . "&p=" . escape($row['password']) . "&o=" . $_SESSION['zoiper']['outbound_proxy']['text'] . "&t=&x=&a=" . escape($row['extension']) . "&tr=";
  164. $tr_link = (permission_exists('zoiper')) ? "href='".$tr_url."'" : null;
  165. echo "<tr>\n";
  166. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['extension'])."</td>\n";
  167. echo " <td valign='top' class='".$row_style[$c]."'>\n";
  168. if (permission_exists('zoiper')) { echo "<a href='".$tr_url."' target='_blank'>" . $text['label-zoiper'] . "</a>&nbsp;&nbsp;&nbsp;"; }
  169. echo " </td>\n";
  170. echo " <td valign='top' class='".$row_style[$c]."'>\n";
  171. echo " <a href='".$qr_img."' target='_blank'>" . $text['label-qr'] . "</a>&nbsp;&nbsp;&nbsp;";
  172. echo " </td>\n";
  173. // echo " <td valign='top' class='".$row_style[$c]."'>";
  174. // echo " <option data-toggle='tooltip' ";
  175. // echo "title='User: ".$row['extension']."\n";
  176. // echo "Password: ".$row['password']."' ";
  177. // echo " </option>\n";
  178. // echo "******";
  179. // echo "&nbsp;</td>\n";
  180. echo " <td valign='top' class='row_stylebg' width='40%'>".escape($row['description'])."&nbsp;</td>\n";
  181. echo "</tr>\n";
  182. if ($c==0) { $c=1; } else { $c=0; }
  183. } //end foreach
  184. unset($sql, $result, $row_count);
  185. } //end if results
  186. echo "</table>\n";
  187. echo "</div>\n";
  188. if (strlen($paging_controls) > 0) {
  189. echo "<br />\n";
  190. echo $paging_controls."\n";
  191. }
  192. echo "<br><br>\n";
  193. if ($is_included != "true") {
  194. require_once "resources/footer.php";
  195. }
  196. ?>