bulk_account_settings_users.php 20 KB

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