zoiper.php 7.7 KB

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