bulk_account_settings_users.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. KonradSC <[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. require_once "resources/check_auth.php";
  27. if (permission_exists('bulk_account_settings_users')) {
  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. //set defaults
  38. $user_ids = [];
  39. //get the http values and set them as variables
  40. $order_by = check_str($_GET["order_by"]);
  41. $order = check_str($_GET["order"]);
  42. $option_selected = check_str($_GET["option_selected"]);
  43. //handle search term
  44. $search = check_str($_GET["search"]);
  45. if (strlen($search) > 0) {
  46. $sql_mod = "and ( ";
  47. $sql_mod .= "username ILIKE '%".$search."%' ";
  48. $sql_mod .= "or user_enabled ILIKE '%".$search."%' ";
  49. $sql_mod .= "or user_status ILIKE '%".$search."%' ";
  50. $sql_mod .= ") ";
  51. }
  52. if (strlen($order_by) < 1) {
  53. $order_by = "username";
  54. $order = "ASC";
  55. }
  56. $domain_uuid = $_SESSION['domain_uuid'];
  57. //get total extension count from the database
  58. $sql = "select count(*) as num_rows from v_users where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod." ";
  59. $prep_statement = $db->prepare($sql);
  60. if ($prep_statement) {
  61. $prep_statement->execute();
  62. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  63. $total_users = $row['num_rows'];
  64. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  65. $numberic_users = $row['num_rows'];
  66. }
  67. }
  68. unset($prep_statement, $row);
  69. //prepare to page the results
  70. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  71. $param = "&search=".$search."&option_selected=".$option_selected;
  72. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  73. $_GET['page'] = check_str($_GET['page']);
  74. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_users, $param, $rows_per_page, true); //top
  75. list($paging_controls, $rows_per_page, $var_3) = paging($total_users, $param, $rows_per_page); //bottom
  76. $offset = $rows_per_page * $_GET['page'];
  77. //get all the users from the database
  78. $sql = "SELECT \n";
  79. $sql .= "username, \n";
  80. $sql .= "user_uuid, \n";
  81. $sql .= "user_status, \n";
  82. $sql .= "user_enabled \n";
  83. $sql .= "FROM v_users \n";
  84. $sql .= "WHERE domain_uuid = '$domain_uuid' and 1 = 1 \n";
  85. $sql .= $sql_mod; //add search mod from above
  86. $sql .= "ORDER BY ".$order_by." ".$order." \n";
  87. $sql .= "limit $rows_per_page offset $offset ";
  88. $database = new database;
  89. $directory = $database->select($sql, 'all');
  90. unset($database);
  91. //get all the users' groups from the database
  92. $sql = "select ";
  93. $sql .= " ug.*, g.domain_uuid as group_domain_uuid ";
  94. $sql .= "from ";
  95. $sql .= " v_user_groups as ug, ";
  96. $sql .= " v_groups as g ";
  97. $sql .= "where ";
  98. $sql .= " ug.group_uuid = g.group_uuid ";
  99. if (!(permission_exists('user_all') && $_GET['showall'] == 'true')) {
  100. $sql .= " and ug.domain_uuid = '".$domain_uuid."' ";
  101. }
  102. $sql .= "order by ";
  103. $sql .= " g.domain_uuid desc, ";
  104. $sql .= " g.group_name asc ";
  105. $database = new database;
  106. $result = $database->select($sql, 'all');
  107. if (is_array($result)) {
  108. foreach($result as $row) {
  109. $user_groups[$row['user_uuid']][] = $row['group_name'].(($row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$row['group_domain_uuid']]['domain_name'] : null);
  110. }
  111. }
  112. unset($database,$result);
  113. //get all the users' timezones from the database
  114. $sql = "select ";
  115. $sql .= " us.*, u.domain_uuid as setting_domain_uuid ";
  116. $sql .= "from ";
  117. $sql .= " v_user_settings as us, ";
  118. $sql .= " v_users as u ";
  119. $sql .= "where ";
  120. $sql .= " us.user_uuid = u.user_uuid ";
  121. $sql .= " and user_setting_subcategory = 'time_zone' ";
  122. $sql .= "order by ";
  123. $sql .= " u.domain_uuid desc, ";
  124. $sql .= " u.username asc ";
  125. $database = new database;
  126. $result = $database->select($sql, 'all');
  127. if (is_array($result) > 0) {
  128. foreach($result as $row) {
  129. $user_time_zone[$row['user_uuid']][] = $row['user_setting_value'];
  130. }
  131. }
  132. unset($database,$result);
  133. //additional includes
  134. require_once "resources/header.php";
  135. $document['title'] = $text['title-users_settings'];
  136. //set the alternating styles
  137. $c = 0;
  138. $row_style["0"] = "row_style0";
  139. $row_style["1"] = "row_style1";
  140. //javascript for password
  141. echo "<script>\n";
  142. echo " function compare_passwords() {\n";
  143. echo " if (document.getElementById('password') === document.activeElement || document.getElementById('password_confirm') === document.activeElement) {\n";
  144. echo " if ($('#password').val() != '' || $('#password_confirm').val() != '') {\n";
  145. echo " if ($('#password').val() != $('#password_confirm').val()) {\n";
  146. echo " $('#password').removeClass('formfld_highlight_good');\n";
  147. echo " $('#password_confirm').removeClass('formfld_highlight_good');\n";
  148. echo " $('#password').addClass('formfld_highlight_bad');\n";
  149. echo " $('#password_confirm').addClass('formfld_highlight_bad');\n";
  150. echo " }\n";
  151. echo " else {\n";
  152. echo " $('#password').removeClass('formfld_highlight_bad');\n";
  153. echo " $('#password_confirm').removeClass('formfld_highlight_bad');\n";
  154. echo " $('#password').addClass('formfld_highlight_good');\n";
  155. echo " $('#password_confirm').addClass('formfld_highlight_good');\n";
  156. echo " }\n";
  157. echo " }\n";
  158. echo " }\n";
  159. echo " else {\n";
  160. echo " $('#password').removeClass('formfld_highlight_bad');\n";
  161. echo " $('#password_confirm').removeClass('formfld_highlight_bad');\n";
  162. echo " $('#password').removeClass('formfld_highlight_good');\n";
  163. echo " $('#password_confirm').removeClass('formfld_highlight_good');\n";
  164. echo " }\n";
  165. echo " }\n";
  166. $req['length'] = $_SESSION['security']['password_length']['numeric'];
  167. $req['number'] = ($_SESSION['security']['password_number']['boolean'] == 'true') ? true : false;
  168. $req['lowercase'] = ($_SESSION['security']['password_lowercase']['boolean'] == 'true') ? true : false;
  169. $req['uppercase'] = ($_SESSION['security']['password_uppercase']['boolean'] == 'true') ? true : false;
  170. $req['special'] = ($_SESSION['security']['password_special']['boolean'] == 'true') ? true : false;
  171. echo " function check_password_strength(pwd) {\n";
  172. echo " if ($('#password').val() != '' || $('#password_confirm').val() != '') {\n";
  173. echo " var msg_errors = [];\n";
  174. if (is_numeric($req['length']) && $req['length'] != 0) {
  175. echo " var re = /.{".$req['length'].",}/;\n"; //length
  176. echo " if (!re.test(pwd)) { msg_errors.push('".$req['length']."+ ".$text['label-characters']."'); }\n";
  177. }
  178. if ($req['number']) {
  179. echo " var re = /(?=.*[\d])/;\n"; //number
  180. echo " if (!re.test(pwd)) { msg_errors.push('1+ ".$text['label-numbers']."'); }\n";
  181. }
  182. if ($req['lowercase']) {
  183. echo " var re = /(?=.*[a-z])/;\n"; //lowercase
  184. echo " if (!re.test(pwd)) { msg_errors.push('1+ ".$text['label-lowercase_letters']."'); }\n";
  185. }
  186. if ($req['uppercase']) {
  187. echo " var re = /(?=.*[A-Z])/;\n"; //uppercase
  188. echo " if (!re.test(pwd)) { msg_errors.push('1+ ".$text['label-uppercase_letters']."'); }\n";
  189. }
  190. if ($req['special']) {
  191. echo " var re = /(?=.*[\W])/;\n"; //special
  192. echo " if (!re.test(pwd)) { msg_errors.push('1+ ".$text['label-special_characters']."'); }\n";
  193. }
  194. echo " if (msg_errors.length > 0) {\n";
  195. echo " var msg = '".$text['message-password_requirements'].": ' + msg_errors.join(', ');\n";
  196. echo " display_message(msg, 'negative', '6000');\n";
  197. echo " return false;\n";
  198. echo " }\n";
  199. echo " else {\n";
  200. echo " return true;\n";
  201. echo " }\n";
  202. echo " }\n";
  203. echo " else {\n";
  204. echo " return true;\n";
  205. echo " }\n";
  206. echo " }\n";
  207. echo " function show_strenth_meter() {\n";
  208. echo " $('#pwstrength_progress').slideDown();\n";
  209. echo " }\n";
  210. echo "</script>\n";
  211. //show the content
  212. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  213. echo " <tr>\n";
  214. echo " <td align='left' width='100%'>\n";
  215. echo " <b>".$text['header-users']." (".$numberic_users.")</b><br>\n";
  216. //options list
  217. echo "<form name='frm' method='get' id=option_selected>\n";
  218. echo " <select class='formfld' name='option_selected' onchange=\"this.form.submit();\">\n";
  219. echo " <option value=''>".$text['label-extension_null']."</option>\n";
  220. if ($option_selected == "user_enabled") {
  221. echo " <option value='user_enabled' selected='selected'>".$text['label-user_enabled']."</option>\n";
  222. }
  223. else {
  224. echo " <option value='user_enabled'>".$text['label-user_enabled']."</option>\n";
  225. }
  226. if ($option_selected == "group") {
  227. echo " <option value='group' selected='selected'>".$text['label-group']."</option>\n";
  228. }
  229. if ($option_selected == "password") {
  230. echo " <option value='password' selected='selected'>".$text['label-password']."</option>\n";
  231. }
  232. else {
  233. echo " <option value='password'>".$text['label-password']."</option>\n";
  234. }
  235. if ($option_selected == "user_status") {
  236. echo " <option value='user_status' selected='selected'>".$text['label-user_status']."</option>\n";
  237. }
  238. else {
  239. echo " <option value='user_status'>".$text['label-user_status']."</option>\n";
  240. }
  241. if ($option_selected == "time_zone") {
  242. echo " <option value='time_zone' selected='selected'>".$text['label-time_zone']."</option>\n";
  243. }
  244. else {
  245. echo " <option value='time_zone'>".$text['label-time_zone']."</option>\n";
  246. }
  247. echo " </select>\n";
  248. echo " </form>\n";
  249. echo "<br />\n";
  250. echo $text['description-user_settings_description']."\n";
  251. echo "</td>\n";
  252. echo " <td align='right' width='100%' style='vertical-align: top;'>";
  253. echo " <form method='get' action=''>\n";
  254. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  255. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='bulk_account_settings.php'\" value='".$text['button-back']."'>\n";
  256. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".escape($search)."'>";
  257. echo " <input type='hidden' class='txt' style='width: 150px' name='option_selected' id='option_selected' value='".escape($option_selected)."'>";
  258. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  259. if ($paging_controls_mini != '') {
  260. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  261. }
  262. echo " </td>\n";
  263. echo " </form>\n";
  264. echo " </tr>\n";
  265. echo " <tr>\n";
  266. echo " <td colspan='2'>\n";
  267. echo " ".$text['description-users_settings']."\n";
  268. echo " </td>\n";
  269. echo " </tr>\n";
  270. echo "</table>\n";
  271. echo "<br />";
  272. if (strlen($option_selected) > 0) {
  273. echo "<form name='users' method='post' action='bulk_account_settings_users_update.php'>\n";
  274. echo "<input class='formfld' type='hidden' name='option_selected' maxlength='255' value=\"".escape($option_selected)."\">\n";
  275. echo "<table width='auto' border='0' cellpadding='0' cellspacing='0'>\n";
  276. echo "<tr>\n";
  277. //option is Password
  278. if($option_selected == 'password') {
  279. echo "<td class='vtable' align='left'>\n";
  280. echo " <input class='formfld' type='password' name='new_setting' maxlength='255' value=\"".escape($new_setting)."\">\n";
  281. echo "<br />\n";
  282. echo $text["description-".escape($option_selected).""]."\n";
  283. echo "</td>\n";
  284. }
  285. //option is Enabled
  286. if($option_selected == 'user_enabled') {
  287. echo "<td class='vtable' align='left'>\n";
  288. echo " <select class='formfld' name='new_setting'>\n";
  289. echo " <option value='true'>".$text['label-true']."</option>\n";
  290. echo " <option value='false'>".$text['label-false']."</option>\n";
  291. echo " </select>\n";
  292. echo " <br />\n";
  293. echo $text["description-".escape($option_selected).""]."\n";
  294. echo "</td>\n";
  295. }
  296. //option is user_status
  297. if($option_selected == 'user_status') {
  298. echo "<td class='vtable' align='left'>\n";
  299. echo " <select name='new_setting' class='formfld' style=''>\n";
  300. echo " <option value=''></option>\n";
  301. echo " <option value='Available'>".$text['option-available']."</option>\n";
  302. echo " <option value='Available (On Demand)'>".$text['option-available_on_demand']."</option>\n";
  303. echo " <option value='Logged Out'>".$text['option-logged_out']."</option>\n";
  304. echo " <option value='On Break'>".$text['option-on_break']."</option>\n";
  305. echo " <option value='Do Not Disturb'>".$text['option-do_not_disturb']."</option>\n";
  306. echo " </select>\n";
  307. echo " <br />\n";
  308. echo $text["description-".escape($option_selected).""]."\n";
  309. echo "</td>\n";
  310. }
  311. //option is user_time_zone
  312. if($option_selected == 'time_zone') {
  313. echo "<td class='vtable' align='left'>\n";
  314. echo " <select name='new_setting' class='formfld' style=''>\n";
  315. echo " <option value=''></option>\n";
  316. //$list = DateTimeZone::listAbbreviations();
  317. $time_zone_identifiers = DateTimeZone::listIdentifiers();
  318. $previous_category = '';
  319. $x = 0;
  320. foreach ($time_zone_identifiers as $key => $row) {
  321. $time_zone = explode("/", $row);
  322. $category = $time_zone[0];
  323. if ($category != $previous_category) {
  324. if ($x > 0) {
  325. echo " </optgroup>\n";
  326. }
  327. echo " <optgroup label='".escape($category)."'>\n";
  328. }
  329. echo " <option value='".escape($row)."'>".escape($row)."</option>\n";
  330. $previous_category = $category;
  331. $x++;
  332. }
  333. echo " </select>\n";
  334. echo " <br />\n";
  335. echo $text["description-".escape($option_selected).""]."\n";
  336. echo "</td>\n";
  337. }
  338. //option is group
  339. if($option_selected == 'group') {
  340. echo " <td class='vtable'>";
  341. $sql = "select * from v_groups ";
  342. $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
  343. $sql .= "order by domain_uuid desc, group_name asc ";
  344. $database = new database;
  345. $result = $database->select($sql, 'all');
  346. $result_count = count($result);
  347. if ($result_count > 0) {
  348. if (isset($assigned_groups)) { echo "<br />\n"; }
  349. echo "<select name='group_uuid_name' class='formfld' style='width: auto; margin-right: 3px;'>\n";
  350. echo " <option value=''></option>\n";
  351. foreach($result as $field) {
  352. if ($field['group_name'] == "superadmin" && !if_group("superadmin")) { continue; } //only show the superadmin group to other superadmins
  353. if ($field['group_name'] == "admin" && (!if_group("superadmin") && !if_group("admin") )) { continue; } //only show the admin group to other admins
  354. if ( !isset($assigned_groups) || (isset($assigned_groups) && !in_array($field["group_uuid"], $assigned_groups)) ) {
  355. echo " <option value='".escape($field['group_uuid'])."|".escape($field['group_name'])."'>".escape($field['group_name']).(($field['domain_uuid'] != '') ? "@".$_SESSION['domains'][$field['domain_uuid']]['domain_name'] : null)."</option>\n";
  356. }
  357. }
  358. echo "</select>";
  359. if ($action == 'edit') {
  360. echo "<input type='button' class='btn' value=\"".$text['button-add']."\" onclick=\"document.getElementById('action').value = '".$text['button-add']."'; submit_form();\">\n";
  361. }
  362. }
  363. unset($sql, $prep_statement, $result);
  364. echo " </td>";
  365. }
  366. echo "<td align='left'>\n";
  367. echo "<input type='button' class='btn' alt='".$text['button-submit']."' onclick=\"if (confirm('".$text['confirm-update']."')) { document.forms.users.submit(); }\" value='".$text['button-submit']."'; if (check_password_strength(document.getElementById('password').value)) { submit_form(); }>\n";
  368. echo "</td>\n";
  369. echo "</tr>\n";
  370. echo "</table>";
  371. echo "<br />";
  372. }
  373. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  374. echo "<tr>\n";
  375. if (is_array($directory)) {
  376. echo "<th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' id='chk_all' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
  377. }
  378. echo th_order_by('username', $text['label-username'], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
  379. echo th_order_by('user_status', $text['label-user_status'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  380. echo th_order_by('username', $text['label-group'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  381. echo th_order_by('username', $text['label-time_zone'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  382. echo th_order_by('user_enabled', $text['label-user_enabled'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  383. echo "</tr>\n";
  384. if (is_array($directory)) {
  385. foreach($directory as $key => $row) {
  386. $tr_link = (permission_exists('extension_edit')) ? " href='/core/users/user_edit.php?id=".$row['user_uuid']."'" : null;
  387. echo "<tr ".$tr_link.">\n";
  388. echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='text-align: center; vertical-align: middle; padding: 0px;'>";
  389. echo " <input type='checkbox' name='id[]' id='checkbox_".escape($row['user_uuid'])."' value='".escape($row['user_uuid'])."' onclick=\"if (!this.checked) { document.getElementById('chk_all').checked = false; }\">";
  390. echo " </td>";
  391. $user_ids[] = 'checkbox_'.$row['user_uuid'];
  392. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['username'])."&nbsp;</td>\n";
  393. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['user_status'])."&nbsp;</td>\n";
  394. echo " <td valign='top' class='".$row_style[$c]."'>";
  395. if (sizeof($user_groups[$row['user_uuid']]) > 0) {
  396. echo implode(', ', $user_groups[$row['user_uuid']]);
  397. }
  398. echo "&nbsp;</td>\n";
  399. echo " <td valign='top' class='".$row_style[$c]."'>";
  400. if (isset($user_time_zone[$row['user_uuid']]) && sizeof($user_time_zone[$row['user_uuid']]) > 0) {
  401. echo implode(', ', $user_time_zone[$row['user_uuid']]);
  402. }
  403. echo "&nbsp;</td>\n";
  404. echo " <td valign='top' class='".$row_style[$c]."'> ".escape($row['user_enabled'])."&nbsp;</td>\n";
  405. echo "</tr>\n";
  406. $c = ($c) ? 0 : 1;
  407. }
  408. unset($directory, $row);
  409. }
  410. echo "</table>";
  411. echo "</form>";
  412. if (strlen($paging_controls) > 0) {
  413. echo "<br />";
  414. echo $paging_controls."\n";
  415. }
  416. echo "<br /><br />".((is_array($directory)) ? "<br /><br />" : null);
  417. // check or uncheck all checkboxes
  418. if (sizeof($user_ids) > 0) {
  419. echo "<script>\n";
  420. echo " function check(what) {\n";
  421. echo " document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
  422. foreach ($user_ids as $user_id) {
  423. echo " document.getElementById('".$user_id."').checked = (what == 'all') ? true : false;\n";
  424. }
  425. echo " }\n";
  426. echo "</script>\n";
  427. }
  428. if (is_array($directory)) {
  429. // check all checkboxes
  430. key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true);
  431. // delete checked
  432. key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], 'document.forms.frm.submit();', true);
  433. }
  434. //show the footer
  435. require_once "resources/footer.php";
  436. ?>