bulk_account_settings_users.php 20 KB

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