users.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 - 2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. require_once "resources/paging.php";
  26. //check permissions
  27. if (permission_exists('user_view')) {
  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 http post data
  38. if (is_array($_POST['users'])) {
  39. $action = $_POST['action'];
  40. $search = $_POST['search'];
  41. $users = $_POST['users'];
  42. }
  43. //process the http post data by action
  44. if ($action != '' && is_array($users) && @sizeof($users) != 0) {
  45. switch ($action) {
  46. case 'copy':
  47. if (permission_exists('user_add')) {
  48. $obj = new users;
  49. $obj->copy($users);
  50. }
  51. break;
  52. case 'toggle':
  53. if (permission_exists('user_edit')) {
  54. $obj = new users;
  55. $obj->toggle($users);
  56. }
  57. break;
  58. case 'delete':
  59. if (permission_exists('user_delete')) {
  60. $obj = new users;
  61. $obj->delete($users);
  62. }
  63. break;
  64. }
  65. header('Location: users.php'.($search != '' ? '?search='.urlencode($search) : null));
  66. exit;
  67. }
  68. //get order and order by
  69. $order_by = $_GET["order_by"];
  70. $order = $_GET["order"];
  71. //add the search string
  72. if (isset($_GET["search"])) {
  73. $search = strtolower($_GET["search"]);
  74. $sql_search = " (";
  75. $sql_search .= " lower(username) like :search ";
  76. $sql_search .= " or lower(groups) like :search ";
  77. $sql_search .= " or lower(contact_organization) like :search ";
  78. $sql_search .= " or lower(contact_name) like :search ";
  79. //$sql_search .= " or lower(user_status) like :search ";
  80. $sql_search .= ") ";
  81. $parameters['search'] = '%'.$search.'%';
  82. }
  83. //get the count
  84. $sql = "select count(*) from view_users ";
  85. if ($_GET['show'] == "all" && permission_exists('user_all')) {
  86. if (isset($sql_search)) {
  87. $sql .= "where ".$sql_search;
  88. }
  89. else {
  90. $sql.= "where true ";
  91. }
  92. }
  93. else {
  94. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  95. if (isset($sql_search)) {
  96. $sql .= "and ".$sql_search;
  97. }
  98. $parameters['domain_uuid'] = $domain_uuid;
  99. }
  100. $sql .= "and ( ";
  101. $sql .= " group_level <= :group_level ";
  102. $sql .= " or group_level is null ";
  103. $sql .= ") ";
  104. $parameters['group_level'] = $_SESSION['user']['group_level'];
  105. $database = new database;
  106. $num_rows = $database->select($sql, $parameters, 'column');
  107. //prepare to page the results
  108. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  109. $param = $search ? "&search=".$search : null;
  110. $param = ($_GET['show'] == 'all' && permission_exists('user_all')) ? "&show=all" : null;
  111. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  112. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  113. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  114. $offset = $rows_per_page * $page;
  115. //get the list
  116. $sql = "select * from view_users ";
  117. if ($_GET['show'] == "all" && permission_exists('user_all')) {
  118. if (isset($sql_search)) {
  119. $sql .= "where ".$sql_search;
  120. }
  121. else {
  122. $sql.= "where true ";
  123. }
  124. }
  125. else {
  126. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  127. if (isset($sql_search)) {
  128. $sql .= "and ".$sql_search;
  129. }
  130. $parameters['domain_uuid'] = $domain_uuid;
  131. }
  132. $sql .= "and ( ";
  133. $sql .= " group_level <= :group_level ";
  134. $sql .= " or group_level is null ";
  135. $sql .= ") ";
  136. $parameters['group_level'] = $_SESSION['user']['group_level'];
  137. $sql .= order_by($order_by, $order, 'username', 'asc');
  138. $sql .= limit_offset($rows_per_page, $offset);
  139. $database = new database;
  140. $users = $database->select($sql, $parameters, 'all');
  141. unset($sql, $parameters);
  142. //create token
  143. $object = new token;
  144. $token = $object->create($_SERVER['PHP_SELF']);
  145. //include the header
  146. $document['title'] = $text['title-users'];
  147. require_once "resources/header.php";
  148. //show the content
  149. echo "<div class='action_bar' id='action_bar'>\n";
  150. echo " <div class='heading'><b>".$text['title-users']." (".$num_rows.")</b></div>\n";
  151. echo " <div class='actions'>\n";
  152. if (permission_exists('user_add')) {
  153. if (!isset($id)) {
  154. echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'style'=>'margin-right: 15px;','link'=>'user_imports.php']);
  155. }
  156. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'user_edit.php']);
  157. }
  158. if (permission_exists('user_add') && $users) {
  159. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  160. }
  161. if (permission_exists('user_edit') && $users) {
  162. echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  163. }
  164. if (permission_exists('user_delete') && $users) {
  165. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  166. }
  167. echo "<form id='form_search' class='inline' method='get'>\n";
  168. if (permission_exists('user_all')) {
  169. if ($_GET['show'] == 'all') {
  170. echo " <input type='hidden' name='show' value='all'>\n";
  171. }
  172. else {
  173. echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
  174. }
  175. }
  176. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
  177. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
  178. echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'users.php','style'=>($search == '' ? 'display: none;' : null)]);
  179. if ($paging_controls_mini != '') {
  180. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  181. }
  182. echo " </form>\n";
  183. echo " </div>\n";
  184. echo " <div style='clear: both;'></div>\n";
  185. echo "</div>\n";
  186. echo $text['description-users']."\n";
  187. echo "<br /><br />\n";
  188. echo "<form id='form_list' method='post'>\n";
  189. echo "<input type='hidden' id='action' name='action' value=''>\n";
  190. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  191. echo "<table class='list'>\n";
  192. echo "<tr class='list-header'>\n";
  193. if (permission_exists('user_add') || permission_exists('user_edit') || permission_exists('user_delete')) {
  194. echo " <th class='checkbox'>\n";
  195. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($users ?: "style='visibility: hidden;'").">\n";
  196. echo " </th>\n";
  197. }
  198. if ($_GET['show'] == 'all' && permission_exists('user_all')) {
  199. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  200. }
  201. echo th_order_by('username', $text['label-username'], $order_by, $order);
  202. echo th_order_by('groups', $text['label-groups'], $order_by, $order);
  203. if (permission_exists('contact_view')) {
  204. echo th_order_by('contact_organization', $text['label-organization'], $order_by, $order);
  205. echo th_order_by('contact_name', $text['label-name'], $order_by, $order);
  206. //echo th_order_by('contact_name_family', $text['label-contact_name_family'], $order_by, $order);
  207. }
  208. //echo th_order_by('user_status', $text['label-user_status'], $order_by, $order);
  209. //echo th_order_by('add_date', $text['label-add_date'], $order_by, $order);
  210. echo th_order_by('user_enabled', $text['label-user_enabled'], $order_by, $order, null, "class='center'");
  211. if (permission_exists('user_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  212. echo " <td class='action-button'>&nbsp;</td>\n";
  213. }
  214. echo "</tr>\n";
  215. if (is_array($users) && @sizeof($users) != 0) {
  216. $x = 0;
  217. foreach ($users as $row) {
  218. if (permission_exists('user_edit')) {
  219. $list_row_url = "user_edit.php?id=".urlencode($row['user_uuid']);
  220. }
  221. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  222. if (permission_exists('user_add') || permission_exists('user_edit') || permission_exists('user_delete')) {
  223. echo " <td class='checkbox'>\n";
  224. echo " <input type='checkbox' name='users[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  225. echo " <input type='hidden' name='users[$x][uuid]' value='".escape($row['user_uuid'])."' />\n";
  226. echo " </td>\n";
  227. }
  228. if ($_GET['show'] == 'all' && permission_exists('user_all')) {
  229. echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";
  230. }
  231. echo " <td>\n";
  232. if (permission_exists('user_edit')) {
  233. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['username'])."</a>\n";
  234. }
  235. else {
  236. echo " ".escape($row['username']);
  237. }
  238. echo " </td>\n";
  239. echo " <td>".escape($row['groups'])."</td>\n";
  240. if (permission_exists('contact_view')) {
  241. echo " <td>".escape($row['contact_organization'])."</td>\n";
  242. echo " <td>".escape($row['contact_name'])."</td>\n";
  243. //echo " <td>".escape($row['contact_name_given'])."</td>\n";
  244. //echo " <td>".escape($row['contact_name_family'])."</td>\n";
  245. }
  246. //echo " <td>".escape($row['user_status'])."</td>\n";
  247. //echo " <td>".escape($row['add_date'])."</td>\n";
  248. if (permission_exists('user_edit')) {
  249. echo " <td class='no-link center'>\n";
  250. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['user_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  251. }
  252. else {
  253. echo " <td class='center'>\n";
  254. echo $text['label-'.$row['user_enabled']];
  255. }
  256. echo " </td>\n";
  257. if (permission_exists('user_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  258. echo " <td class='action-button'>\n";
  259. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  260. echo " </td>\n";
  261. }
  262. echo "</tr>\n";
  263. $x++;
  264. }
  265. unset($users);
  266. }
  267. echo "</table>\n";
  268. echo "<br />\n";
  269. echo "<div align='center'>".$paging_controls."</div>\n";
  270. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  271. echo "</form>\n";
  272. //include the footer
  273. require_once "resources/footer.php";
  274. ?>