group_members.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (permission_exists('group_member_view') || if_group("superadmin")) {
  26. //access allowed
  27. }
  28. else {
  29. echo "access denied";
  30. return;
  31. }
  32. //requires a superadmin to view members of the superadmin group
  33. if (!if_group("superadmin") && $_GET["group_name"] == "superadmin") {
  34. echo "access denied";
  35. return;
  36. }
  37. //add multi-lingual support
  38. $language = new text;
  39. $text = $language->get();
  40. //get the http data
  41. $action = $_REQUEST['action'] ?? '';
  42. $group_uuid = $_REQUEST['group_uuid'] ?? '';
  43. $group_members = $_REQUEST['group_members'] ?? '';
  44. //set default values
  45. $group_name = '';
  46. $domain_uuid = '';
  47. $list_row_url = '';
  48. //process the http post data by action
  49. if (!empty($action) && !empty($group_members)) {
  50. switch ($action) {
  51. case 'delete':
  52. if (permission_exists('group_member_delete') && is_uuid($group_uuid)) {
  53. $obj = new groups;
  54. $obj->group_uuid = $group_uuid;
  55. $obj->delete_members($group_members);
  56. }
  57. break;
  58. }
  59. header('Location: group_members.php?group_uuid='.urlencode($group_uuid));
  60. exit;
  61. }
  62. //get the group uuid, lookup domain uuid (if any) and name
  63. $sql = "select domain_uuid, group_name from v_groups ";
  64. $sql .= "where group_uuid = :group_uuid ";
  65. $parameters['group_uuid'] = $group_uuid;
  66. $database = new database;
  67. $row = $database->select($sql, $parameters, 'row');
  68. if (is_array($row) && sizeof($row) != 0) {
  69. $domain_uuid = $row["domain_uuid"];
  70. $group_name = $row["group_name"];
  71. }
  72. unset($sql, $parameters, $row);
  73. //get the the users array
  74. if (permission_exists('group_member_add')) {
  75. $sql = "select * from v_users where ";
  76. $sql .= "domain_uuid = :domain_uuid ";
  77. $sql .= "order by username ";
  78. $parameters['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : $_SESSION['domain_uuid'];
  79. $database = new database;
  80. $users = $database->select($sql, $parameters, 'all');
  81. unset($sql, $parameters);
  82. }
  83. //get the groups users
  84. $sql = "select u.user_uuid, u.username, ug.user_group_uuid, ug.domain_uuid, ug.group_uuid ";
  85. $sql .= "from v_user_groups as ug, v_users as u, v_domains as d ";
  86. $sql .= "where ug.user_uuid = u.user_uuid ";
  87. $sql .= "and ug.domain_uuid = d.domain_uuid ";
  88. if (is_uuid($domain_uuid)) {
  89. $sql .= "and ug.domain_uuid = :domain_uuid_ug ";
  90. $parameters['domain_uuid_ug'] = $domain_uuid;
  91. }
  92. if (!permission_exists('user_all')) {
  93. $sql .= "and u.domain_uuid = :domain_uuid_u ";
  94. $parameters['domain_uuid_u'] = $_SESSION['domain_uuid'];
  95. }
  96. $sql .= "and ug.group_uuid = :group_uuid ";
  97. $sql .= "order by d.domain_name asc, u.username asc ";
  98. $parameters['group_uuid'] = $group_uuid;
  99. $database = new database;
  100. $user_groups = $database->select($sql, $parameters, 'all');
  101. $num_rows = is_array($user_groups) && @sizeof($user_groups) != 0 ? sizeof($user_groups) : 0;
  102. unset($sql, $parameters);
  103. //add group_member to the users array
  104. if (!empty($users)) {
  105. foreach ($users as &$field) {
  106. $field['group_member'] = 'false';
  107. if (!empty($user_groups)) {
  108. foreach($user_groups as $row) {
  109. if ($row['user_uuid'] == $field['user_uuid']) {
  110. $field['group_member'] = 'true';
  111. break;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. //create token
  118. $object = new token;
  119. $token = $object->create($_SERVER['PHP_SELF']);
  120. //include the header
  121. $document['title'] = $text['title-group_members'];
  122. require_once "resources/header.php";
  123. //show the content
  124. echo "<div class='action_bar' id='action_bar'>\n";
  125. echo " <div class='heading'><b>".$text['header-group_members']." (".$group_name.": ".$num_rows.")</b></div>\n";
  126. echo " <div class='actions'>\n";
  127. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'groups.php']);
  128. if (permission_exists('group_permission_view')) {
  129. echo button::create(['type'=>'button','label'=>$text['button-permissions'],'icon'=>'key','style'=>'margin-right: 15px;','link'=>'group_permissions.php?group_uuid='.urlencode($group_uuid)]);
  130. }
  131. if (permission_exists('group_member_add')) {
  132. echo "<form class='inline' method='post' action='group_member_add.php'>\n";
  133. echo " <select name='user_uuid' class='formfld'>\n";
  134. echo " <option value=''>".$text['label-select']."...</option>\n";
  135. foreach ($users as $row) {
  136. if ($row['group_member'] === 'false') {
  137. echo "<option value='".escape($row['user_uuid'])."'>".escape($row['username'])."</option>\n";
  138. }
  139. }
  140. echo " </select>\n";
  141. echo "<input type='hidden' name='domain_uuid' value='".(is_uuid($domain_uuid) ? escape($domain_uuid) : $_SESSION['domain_uuid'])."'>\n";
  142. echo "<input type='hidden' name='group_uuid' value='".escape($group_uuid)."'>\n";
  143. echo "<input type='hidden' name='group_name' value='".escape($group_name)."'>\n";
  144. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  145. echo button::create(['type'=>'submit','label'=>$text['button-add_member'],'icon'=>$_SESSION['theme']['button_icon_add'],'collapse'=>'hide-xs']);
  146. echo " </form>\n";
  147. }
  148. if (permission_exists('group_member_delete') && $user_groups) {
  149. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','collapse'=>'hide-xs','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  150. }
  151. echo " </div>\n";
  152. echo " <div style='clear: both;'></div>\n";
  153. echo "</div>\n";
  154. if (permission_exists('group_member_delete') && $user_groups) {
  155. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
  156. }
  157. echo "<form id='form_list' method='post'>\n";
  158. echo "<input type='hidden' id='action' name='action' value=''>\n";
  159. echo "<input type='hidden' name='group_uuid' value='".escape($group_uuid)."'>\n";
  160. echo "<table class='list'>\n";
  161. echo "<tr class='list-header'>\n";
  162. if (permission_exists('group_member_delete')) {
  163. echo " <th class='checkbox'>\n";
  164. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".(!empty($user_groups) ?: "style='visibility: hidden;'").">\n";
  165. echo " </th>\n";
  166. }
  167. if (permission_exists('user_all')) {
  168. echo "<th class='pct-30'>".$text['label-domain']."</th>\n";
  169. }
  170. echo " <th>".$text['label-username']."</th>\n";
  171. echo "</tr>\n";
  172. if (is_array($user_groups) && @sizeof($user_groups) != 0) {
  173. $x = 0;
  174. foreach ($user_groups as &$row) {
  175. echo "<tr class='list-row' href='".$list_row_url."'>";
  176. if (permission_exists('group_member_delete')) {
  177. echo " <td class='checkbox'>\n";
  178. echo " <input type='checkbox' name='group_members[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  179. echo " <input type='hidden' name='group_members[$x][uuid]' value='".escape($row['user_uuid'])."' />\n";
  180. echo " </td>\n";
  181. }
  182. if (permission_exists('user_all')) {
  183. echo "<td class='no-wrap' onclick=\"if (document.getElementById('checkbox_".$x."').checked) { document.getElementById('checkbox_".$x."').checked = false; document.getElementById('checkbox_all').checked = false; } else { document.getElementById('checkbox_".$x."').checked = true; }\">".$_SESSION['domains'][$row["domain_uuid"]]['domain_name']."</td>\n";
  184. }
  185. echo "<td class='no-wrap' onclick=\"if (document.getElementById('checkbox_".$x."').checked) { document.getElementById('checkbox_".$x."').checked = false; document.getElementById('checkbox_all').checked = false; } else { document.getElementById('checkbox_".$x."').checked = true; }\">".$row["username"]."</td>\n";
  186. echo "</tr>\n";
  187. $x++;
  188. }
  189. }
  190. echo "</table>\n";
  191. echo "<br />";
  192. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>";
  193. echo "</form>";
  194. //include the footer
  195. require_once "resources/footer.php";
  196. ?>