userlist.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. require_once "root.php";
  22. require_once "includes/require.php";
  23. require_once "includes/checkauth.php";
  24. if (permission_exists("user_view") || if_group("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //require_once "includes/header.php";
  32. require_once "includes/paging.php";
  33. $order_by = $_GET["order_by"];
  34. $order = $_GET["order"];
  35. $field_name = $_REQUEST["field_name"];
  36. $field_value = $_REQUEST["field_value"];
  37. echo "<div align='center'>";
  38. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  39. echo "<tr class='border'>\n";
  40. echo " <td align=\"center\">\n";
  41. //page title and description
  42. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  43. echo "<form method='post' action=''>";
  44. echo "<tr>\n";
  45. echo "<td align='left' width='90%' nowrap><b>User Manager</b></td>\n";
  46. echo "<td align='right' nowrap='nowrap'>Search by:&nbsp;</td>";
  47. echo "<td align='left'>\n";
  48. echo " <select name='field_name' style='width:150px' class='frm'>\n";
  49. echo " <option value=''></option>\n";
  50. if ($field_name == "username") {
  51. echo " <option value='username' selected='selected'>Username</option>\n";
  52. }
  53. else {
  54. echo " <option value='username'>Username</option>\n";
  55. }
  56. //if ($field_name == "user_email") {
  57. // echo " <option value='user_email' selected='selected'>Email</option>\n";
  58. //}
  59. //else {
  60. // echo " <option value='user_email'>Email</option>\n";
  61. //}
  62. echo " </select>\n";
  63. echo "</td>\n";
  64. echo "<td align='left' width='3px'>&nbsp;</td>";
  65. echo "<td align='left'><input type='text' class='txt' style='width: 150px' name='field_value' value='$field_value'></td>";
  66. echo "<td align='left' width='60px'><input type='submit' class='btn' name='submit' value='search'></td>";
  67. //echo " <input type='button' class='btn' name='' alt='view' onclick=\"window.location='user_search.php'\" value='advanced'>&nbsp;\n";
  68. echo "</tr>\n";
  69. echo "</form>";
  70. echo "<tr>\n";
  71. echo "<td align='left' colspan='4'>\n";
  72. echo "Add, edit, delete, and search for users. \n";
  73. echo "<br />\n";
  74. echo "<br />\n";
  75. echo "</td>\n";
  76. echo "</tr>\n";
  77. //get the user list from the database
  78. $sql = "";
  79. $sql .= " select * from v_users ";
  80. $sql .= " where domain_uuid = '$domain_uuid' ";
  81. if (strlen($field_name) > 0 && strlen($field_value) > 0) {
  82. $sql .= " and $field_name = '$field_value' ";
  83. }
  84. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  85. $prep_statement = $db->prepare(check_sql($sql));
  86. $prep_statement->execute();
  87. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  88. $num_rows = count($result);
  89. unset ($prep_statement, $result, $sql);
  90. $rows_per_page = 200;
  91. $param = "";
  92. $page = $_GET['page'];
  93. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  94. list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
  95. $offset = $rows_per_page * $page;
  96. $sql = "";
  97. $sql .= " select * from v_users ";
  98. $sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  99. if (strlen($field_name) > 0 && strlen($field_value) > 0) {
  100. $sql .= " and $field_name like '%$field_value%' ";
  101. }
  102. if (strlen($order_by)> 0) {
  103. $sql .= "order by $order_by $order ";
  104. }
  105. else {
  106. $sql .= "order by username ";
  107. }
  108. $sql .= " limit $rows_per_page offset $offset ";
  109. $prep_statement = $db->prepare(check_sql($sql));
  110. $prep_statement->execute();
  111. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  112. $result_count = count($result);
  113. unset ($prep_statement, $sql);
  114. //alternate the row style
  115. $c = 0;
  116. $row_style["0"] = "row_style0";
  117. $row_style["1"] = "row_style1";
  118. //show the data
  119. echo "<div align='center'>\n";
  120. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  121. echo "<tr>\n";
  122. echo th_order_by('username', 'Username', $order_by, $order);
  123. //echo th_order_by('user_email', 'Email', $order_by, $order);
  124. //echo th_order_by('user_template_name', 'Template', $order_by, $order);
  125. echo "<td align='right' width='42'>\n";
  126. if (permission_exists('user_add')) {
  127. echo " <a href='signup.php' alt='add'>$v_link_label_add</a>\n";
  128. }
  129. echo "</td>\n";
  130. echo "<tr>\n";
  131. if ($result_count > 0) {
  132. foreach($result as $row) {
  133. echo "<tr >\n";
  134. echo " <td valign='top' class='".$row_style[$c]."'>".$row['username']."&nbsp;</td>\n";
  135. //echo " <td valign='top' class='".$row_style[$c]."'>".$row['user_email']."&nbsp;</td>\n";
  136. echo " <td valign='top' align='right'>\n";
  137. if (permission_exists('user_edit')) {
  138. echo " <a href='usersupdate.php?id=".$row['user_uuid']."' alt='edit'>$v_link_label_edit</a>\n";
  139. }
  140. if (permission_exists('user_delete')) {
  141. echo " <a href='userdelete.php?id=".$row['user_uuid']."' alt='delete' onclick=\"return confirm('Do you really want to delete this?')\">$v_link_label_delete</a>\n";
  142. }
  143. echo " </td>\n";
  144. echo "</tr>\n";
  145. if ($c==0) { $c=1; } else { $c=0; }
  146. } //end foreach
  147. unset($sql, $result, $row_count);
  148. } //end if results
  149. echo "<tr>\n";
  150. echo "<td colspan='49' align='left'>\n";
  151. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  152. echo " <tr>\n";
  153. echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
  154. echo " <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
  155. echo " <td width='33.3%' align='right'>\n";
  156. if (permission_exists('user_add')) {
  157. echo " <a href='signup.php' alt='add'>$v_link_label_add</a>\n";
  158. }
  159. echo " </td>\n";
  160. echo " </tr>\n";
  161. echo " </table>\n";
  162. echo "</td>\n";
  163. echo "</tr>\n";
  164. echo "</table>";
  165. echo "</div>";
  166. echo "<br><br>";
  167. echo "<br><br>";
  168. echo "</td>";
  169. echo "</tr>";
  170. echo "</table>";
  171. echo "</div>";
  172. echo "<br><br>";
  173. ?>