groups.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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) 2018-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('group_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['groups'])) {
  39. $action = $_POST['action'];
  40. $search = $_POST['search'];
  41. $groups = $_POST['groups'];
  42. }
  43. //process the http post data by action
  44. if ($action != '' && is_array($groups) && @sizeof($groups) != 0) {
  45. switch ($action) {
  46. case 'copy':
  47. if (permission_exists('group_add')) {
  48. $obj = new groups;
  49. $obj->copy($groups);
  50. }
  51. break;
  52. case 'toggle':
  53. if (permission_exists('group_edit')) {
  54. $obj = new groups;
  55. $obj->toggle($groups);
  56. }
  57. break;
  58. case 'delete':
  59. if (permission_exists('group_delete')) {
  60. $obj = new groups;
  61. $obj->delete($groups);
  62. }
  63. break;
  64. }
  65. header('Location: groups.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(group_name) like :search ";
  76. $sql_search .= " or lower(group_description) like :search ";
  77. $sql_search .= ") ";
  78. $parameters['search'] = '%'.$search.'%';
  79. }
  80. //get the count
  81. $sql = "select count(*) from view_groups ";
  82. if ($_GET['show'] == "all" && permission_exists('group_all')) {
  83. if (isset($sql_search)) {
  84. $sql .= "where ".$sql_search;
  85. }
  86. }
  87. else {
  88. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  89. if (isset($sql_search)) {
  90. $sql .= "and ".$sql_search;
  91. }
  92. $parameters['domain_uuid'] = $domain_uuid;
  93. }
  94. $database = new database;
  95. $num_rows = $database->select($sql, $parameters, 'column');
  96. //prepare to page the results
  97. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  98. $param = $search ? "&search=".$search : null;
  99. $param = ($_GET['show'] == 'all' && permission_exists('group_all')) ? "&show=all" : null;
  100. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  101. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  102. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  103. $offset = $rows_per_page * $page;
  104. //get the list
  105. $sql = str_replace('count(*)', '*', $sql);
  106. $sql .= order_by($order_by, $order, 'group_name', 'asc');
  107. $sql .= limit_offset($rows_per_page, $offset);
  108. $database = new database;
  109. $groups = $database->select($sql, $parameters, 'all');
  110. unset($sql, $parameters);
  111. //get permission counts for each group
  112. if (is_array($groups) && @sizeof($groups) != 0) {
  113. $sql = "select group_uuid, count(group_permission_uuid) as permission_count from v_group_permissions group by group_uuid";
  114. $database = new database;
  115. $result = $database->select($sql, null, 'all');
  116. if (is_array($result) && @sizeof($result) != 0) {
  117. foreach ($result as $row) {
  118. $group_permissions[$row['group_uuid']] = $row['permission_count'];
  119. }
  120. }
  121. unset($sql);
  122. }
  123. //create token
  124. $object = new token;
  125. $token = $object->create($_SERVER['PHP_SELF']);
  126. //include the header
  127. $document['title'] = $text['title-groups'];
  128. require_once "resources/header.php";
  129. //show the content
  130. echo "<div class='action_bar' id='action_bar'>\n";
  131. echo " <div class='heading'><b>".$text['title-groups']." (".$num_rows.")</b></div>\n";
  132. echo " <div class='actions'>\n";
  133. echo button::create(['type'=>'button','label'=>$text['button-users'],'icon'=>$_SESSION['theme']['button_icon_users'],'onclick'=>"window.location='../users/users.php'"]);
  134. echo button::create(['type'=>'button','label'=>$text['button-restore_default'],'icon'=>$_SESSION['theme']['button_icon_sync'],'style'=>'margin-right: 15px;','link'=>'permissions_default.php']);
  135. if (permission_exists('group_add')) {
  136. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'group_edit.php']);
  137. }
  138. if (permission_exists('group_add') && $groups) {
  139. 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; }"]);
  140. }
  141. if (permission_exists('group_edit') && $groups) {
  142. 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; }"]);
  143. }
  144. if (permission_exists('group_delete') && $groups) {
  145. 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; }"]);
  146. }
  147. echo "<form id='form_search' class='inline' method='get'>\n";
  148. if (permission_exists('group_all')) {
  149. if ($_GET['show'] == 'all') {
  150. echo " <input type='hidden' name='show' value='all'>\n";
  151. }
  152. else {
  153. echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
  154. }
  155. }
  156. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
  157. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
  158. echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'groups.php','style'=>($search == '' ? 'display: none;' : null)]);
  159. if ($paging_controls_mini != '') {
  160. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  161. }
  162. echo " </form>\n";
  163. echo " </div>\n";
  164. echo " <div style='clear: both;'></div>\n";
  165. echo "</div>\n";
  166. echo $text['description-groups']."\n";
  167. echo "<br /><br />\n";
  168. echo "<form id='form_list' method='post'>\n";
  169. echo "<input type='hidden' id='action' name='action' value=''>\n";
  170. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  171. echo "<table class='list'>\n";
  172. echo "<tr class='list-header'>\n";
  173. if (permission_exists('group_add') || permission_exists('group_edit') || permission_exists('group_delete')) {
  174. echo " <th class='checkbox'>\n";
  175. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($groups ?: "style='visibility: hidden;'").">\n";
  176. echo " </th>\n";
  177. }
  178. if ($_GET['show'] == 'all' && permission_exists('group_all')) {
  179. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  180. }
  181. echo th_order_by('group_name', $text['label-group_name'], $order_by, $order);
  182. echo " <th class='shrink' colspan='2'>".$text['label-tools']."</th>\n";
  183. echo th_order_by('group_level', $text['label-group_level'], $order_by, $order, null, "class='center'");
  184. echo th_order_by('group_protected', $text['label-group_protected'], $order_by, $order, null, "class='center'");
  185. echo " <th class='pct-30 hide-sm-dn'>".$text['label-group_description']."</th>\n";
  186. if (permission_exists('group_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  187. echo " <td class='action-button'>&nbsp;</td>\n";
  188. }
  189. echo "</tr>\n";
  190. if (is_array($groups) && @sizeof($groups) != 0) {
  191. $x = 0;
  192. foreach ($groups as $row) {
  193. if (permission_exists('group_edit')) {
  194. $list_row_url = "group_edit.php?id=".urlencode($row['group_uuid']);
  195. }
  196. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  197. if (permission_exists('group_add') || permission_exists('group_edit') || permission_exists('group_delete')) {
  198. echo " <td class='checkbox'>\n";
  199. echo " <input type='checkbox' name='groups[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  200. echo " <input type='hidden' name='groups[$x][uuid]' value='".escape($row['group_uuid'])."' />\n";
  201. echo " </td>\n";
  202. }
  203. if ($_GET['show'] == 'all' && permission_exists('group_all')) {
  204. echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";
  205. }
  206. echo " <td>\n";
  207. if (permission_exists('group_edit')) {
  208. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['group_name'])."</a>\n";
  209. }
  210. else {
  211. echo " ".escape($row['group_name']);
  212. }
  213. echo " </td>\n";
  214. echo " <td class='no-link no-wrap pr-15'><a href='group_permissions.php?group_uuid=".urlencode($row['group_uuid'])."'>".$text['label-group_permissions']." (".($group_permissions[$row['group_uuid']] ?: 0).")</a></td>\n";
  215. echo " <td class='no-link no-wrap'><a href='groupmembers.php?group_uuid=".urlencode($row['group_uuid'])."'>".$text['label-group_members']." (".$row['group_members'].")</a></td>\n";
  216. echo " <td class='center'>".escape($row['group_level'])."</td>\n";
  217. if (permission_exists('group_edit')) {
  218. echo " <td class='no-link center'>\n";
  219. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['group_protected']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  220. }
  221. else {
  222. echo " <td class='center'>\n";
  223. echo $text['label-'.$row['group_protected']];
  224. }
  225. echo " </td>\n";
  226. echo " <td class='description overflow hide-sm-dn'>".escape($row['group_description'])."</td>\n";
  227. if (permission_exists('group_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  228. echo " <td class='action-button'>\n";
  229. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  230. echo " </td>\n";
  231. }
  232. echo "</tr>\n";
  233. $x++;
  234. }
  235. unset($groups);
  236. }
  237. echo "</table>\n";
  238. echo "<br />\n";
  239. echo "<div align='center'>".$paging_controls."</div>\n";
  240. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  241. echo "</form>\n";
  242. //include the footer
  243. require_once "resources/footer.php";
  244. ?>