user_json.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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) 2022
  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. //check permissions
  25. if (permission_exists('user_view')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //get order and order by
  33. $order_by = $_GET["order_by"];
  34. $order = $_GET["order"];
  35. //add the search string
  36. if (isset($_GET["search"])) {
  37. $search = strtolower($_GET["search"]);
  38. }
  39. //connect to the database
  40. $database = new database;
  41. //check to see if contact details are in the view
  42. $sql = "select * from view_users ";
  43. $sql .= "where domain_uuid = :domain_uuid ";
  44. $parameters = null;
  45. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  46. $row = $database->select($sql, $parameters, 'row');
  47. if (isset($row['contact_organization'])) {
  48. $show_contact_fields = true;
  49. }
  50. else {
  51. $show_contact_fields = false;
  52. }
  53. unset($parameters);
  54. //get the list
  55. $sql = "select domain_name, domain_uuid, user_uuid, username, group_names, ";
  56. if ($show_contact_fields) {
  57. $sql .= "contact_organization,contact_name, ";
  58. }
  59. $sql .= "cast(user_enabled as text) ";
  60. $sql .= "from view_users ";
  61. $sql .= "where true ";
  62. if (isset($search)) {
  63. $sql .= "and (";
  64. $sql .= " lower(username) like :search ";
  65. $sql .= " or lower(group_names) like :search ";
  66. $sql .= " or lower(contact_organization) like :search ";
  67. $sql .= " or lower(contact_name) like :search ";
  68. //$sql .= " or lower(user_status) like :search ";
  69. $sql .= ") ";
  70. $parameters['search'] = '%'.$search.'%';
  71. }
  72. if ($_GET['show'] == "all" && permission_exists('user_all')) {
  73. }
  74. else {
  75. $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
  76. $parameters['domain_uuid'] = $domain_uuid;
  77. }
  78. $sql .= "and ( ";
  79. $sql .= " group_level <= :group_level ";
  80. $sql .= " or group_level is null ";
  81. $sql .= ") ";
  82. $parameters['group_level'] = $_SESSION['user']['group_level'];
  83. $sql .= order_by($order_by, $order, 'username', 'asc');
  84. $sql .= "limit 300\n";
  85. $users = $database->select($sql, $parameters, 'all');
  86. unset($sql, $parameters);
  87. //return the contacts as json
  88. if (is_array($users)) {
  89. echo json_encode($users, true);
  90. }
  91. ?>