zoiper.php 7.9 KB

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