-
Notifications
You must be signed in to change notification settings - Fork 2
/
my_groups.php
211 lines (196 loc) · 7.94 KB
/
my_groups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* my groups
*
* @copyright (c) 2004-15 bitweaver.org
*
* @package users
* @subpackage functions
*/
/**
* required setup
*/
require_once( '../kernel/includes/setup_inc.php' );
global $gBitUser, $gBitSystem;
// PERMISSIONS: registered user required
if ( !$gBitUser->isRegistered() ) {
$gBitSystem->fatalError( tra( "You are not logged in." ));
}
if( !empty( $_REQUEST["cancel"] ) ) {
bit_redirect( USERS_PKG_URL.'my_groups.php' );
}
if ( $gBitUser->hasPermission('p_users_create_personal_groups' ) ) {
if( !empty( $_REQUEST['group_id'] ) ) {
$allPerms = $gBitUser->getGroupPermissions( array( 'sort_mode' => !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : NULL ));
// get grouplist separately from the $users stuff to avoid splitting of data due to pagination
$listHash = array( 'sort_mode' => 'group_name_asc' );
$groupList = $gBitUser->getAllGroups( $listHash );
} else {
// get grouplist separately from the $users stuff to avoid splitting of data due to pagination
$listHash = array( 'sort_mode' => !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : 'group_name_asc' );
$groupList = $gBitUser->getAllGroups( $listHash );
}
// Remember a package limit if it is set.
$gBitSmarty->assign( 'package',isset( $_REQUEST['package'] ) ? $_REQUEST['package'] : 'all' );
// Save the join
if( isset($_REQUEST["save"] ) ) {
if( empty($_REQUEST["name"] ) ) {
$_REQUEST["name"] = $_REQUEST["olgroup"];
}
if( $gBitUser->storeGroup( $_REQUEST ) ) {
$successMsg = tra("Group changes were saved sucessfully.");
} else {
$errorMsg = $gBitUser->mErrors['groups'];
}
// Update Permissions
} elseif (isset($_REQUEST['updateperms'])) {
$listHash = array( 'group_id' => $_REQUEST['group_id'] );
$updatePerms = $gBitUser->getgroupPermissions( $listHash );
foreach (array_keys($_REQUEST['perm']) as $per) {
if( isset($_REQUEST['perm'][$per]) && !isset($updatePerms[$per]) ) {
// we have an unselected perm that is now selected
$gBitUser->assignPermissionToGroup($per, $_REQUEST['group_id']);
} elseif( empty($_REQUEST['perm'][$per]) && isset($updatePerms[$per]) ) {
// we have a selected perm that is now UNselected
$gBitUser->removePermissionFromGroup($per, $_REQUEST['group_id']);
}
}
// let's reload just to be safe.
$allPerms = $gBitUser->getGroupPermissions();
// Do some action
} elseif (isset($_REQUEST["action"])) {
// Process a form to remove a group
if( $_REQUEST["action"] == 'delete' ) {
if( $gBitUser->getDefaultGroup( $_REQUEST['group_id'] ) ) {
$errorMsg = tra("You cannot remove this group, as it is currently set as your 'Default' group");
} else {
$gBitUser->expungeGroup( $_REQUEST['group_id'] );
$successMsg = tra("The group was deleted.");
unset( $_REQUEST['group_id'] );
}
// remove a permission from a group
} elseif ($_REQUEST["action"] == 'remove') {
$gBitUser->removePermissionFromGroup( $_REQUEST["permission"], $_REQUEST['group_id'] );
$successMsg = tra("Permission Removed");
$mid = 'bitpackage:users/my_group_edit.tpl';
// Create a new group
} elseif( $_REQUEST["action"] == 'create' ) {
$gBitSystem->setBrowserTitle( tra('Create New Group') );
$mid = 'bitpackage:users/my_group_edit.tpl';
// Assign a permission to a group
} elseif ($_REQUEST["action"] == 'assign') {
$gBitUser->assignPermissionToGroup($_REQUEST["perm"], $_REQUEST['group_id']);
$successMsg = tra("Permission Assigned");
$mid = 'bitpackage:users/my_group_edit.tpl';
}
// Search for users to add
} elseif (!empty($_REQUEST['submitUserSearch'])) {
$searchParams = array('find' => $_REQUEST['find']);
$gBitUser->getList($searchParams);
$foundUsers = $searchParams['data'];
$mid = 'bitpackage:users/my_group_edit.tpl';
$gBitSmarty->assignByRef('foundUsers', $foundUsers);
} elseif (!empty($_REQUEST['assignuser'])) {
if( !empty($_REQUEST['group_id'] ) ) {
if ($_REQUEST['group_id'] != -1 && $groupList[$_REQUEST['group_id']]['user_id'] == $gBitUser->mUserId) {
$gBitUser->addUserToGroup( $_REQUEST['assignuser'], $_REQUEST['group_id'] );
}
else {
$errorMsg = tra("You can not assign users to this group.");
}
}
$mid = 'bitpackage:users/my_group_edit.tpl';
}
// get pagination url
// get grouplist separately from the $users stuff to avoid splitting of data due to pagination
$listHash = array( 'sort_mode' => 'group_name_asc' );
$groupList = $gBitUser->getAllUserGroups();
if( !empty( $_REQUEST['group_id'] ) ) {
// we don't want our own group listed when editing
if( !empty( $groupList[$_REQUEST['group_id']] ) ) {
unset( $groupList[$_REQUEST['group_id']] );
}
$groupInfo = $gBitUser->getGroupInfo( $_REQUEST['group_id'] );
$groupUsers = $gBitUser->getGroupUsers( $_REQUEST['group_id'] );
$gBitSmarty->assignByRef('groupUsers', $groupUsers);
$gBitSmarty->assignByRef('groupInfo', $groupInfo);
$gBitSmarty->assignByRef( 'allPerms', $allPerms );
$gBitSystem->setBrowserTitle( 'Admininster Group: '.$groupInfo['group_name'].' '.(isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : '') );
$mid = 'bitpackage:users/my_group_edit.tpl';
}
$gBitSmarty->assign('groups', $groupList);
// $gBitSmarty->assign( (!empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'edit').'TabSelect', 'tdefault' );
}
/* join or leave a public group. */
if ( ( !empty( $_REQUEST['add_public_group'] ) || !empty( $_REQUEST['remove_public_group'] ) ) && !empty( $_REQUEST['public_group_id'] ) ) {
$groupInfo = $gBitUser->getGroupInfo( $_REQUEST['public_group_id'] );
if ( empty($groupInfo) || $groupInfo['is_public'] != 'y' ) {
if (empty($_REQUEST['add_public_group'])) {
$errorMsg[] = tra("You can't join this group.");
}
else {
$errorMsg[] = tra("You can't leave this group.");
}
} elseif ( !empty( $_REQUEST['add_public_group'] ) ) {
$gBitUser->addUserToGroup( $gBitUser->mUserId, $_REQUEST['public_group_id'] );
} elseif ( !empty( $_REQUEST['remove_public_group'] ) ) {
$gBitUser->removeUserFromGroup( $gBitUser->mUserId, $_REQUEST['public_group_id'] );
}
$gBitUser->loadPermissions();
if ( !empty( $_REQUEST['add_public_group'] ) && !empty( $groupInfo['after_registration_page'] ) ) {
if ( $gBitUser->verifyId( $groupInfo['after_registration_page'] ) ) {
$url = BIT_ROOT_URL."index.php?content_id=".$groupInfo['after_registration_page'];
} elseif( strpos( $groupInfo['after_registration_page'], '/' ) === FALSE ) {
$url = BitPage::getDisplayUrlFromHash( $groupInfo['after_registration_page'] );
} else {
$url = $groupInfo['after_registration_page'];
}
bit_redirect( $url );
}
}
/* Load up public groups and check if the user can join or leave them */
$systemGroups = $gBitUser->getGroups( $gBitUser->mUserId, TRUE );
$gBitSmarty->assignByRef( 'systemGroups', $systemGroups);
$listHash = array(
'is_public'=>'y',
'sort_mode' => array( 'is_default_asc', 'group_desc_asc' ),
);
$publicGroups = $gBitUser->getAllGroups( $listHash );
if( count( $publicGroups )) {
foreach ( $systemGroups as $groupId=>$groupInfo ) {
foreach ( $publicGroups as $key=>$publicGroup) {
if ( $publicGroups[$key]['group_id'] == $groupId) {
if ($publicGroups[$key]['is_default'] != 'y' ) {
$systemGroups[$groupId]['public'] = 'y';
$canRemovePublic = 'y';
}
$publicGroups[$key]['used'] = 'y';
break;
}
}
}
foreach ( $publicGroups as $groupInfo) {
if ( empty($groupInfo['used'] ) && $groupInfo['is_default'] != 'y' ) {
$gBitSmarty->assign( 'canAddPublic' , 'y');
break;
}
}
$gBitSmarty->assignByRef( 'publicGroups', $publicGroups );
if (isset($canRemovePublic)) {
$gBitSmarty->assign( 'canRemovePublic' , 'y');
}
}
// Remember error and success messages.
if (!empty($errorMsg)) {
$gBitSmarty->assign('errorMsg',$errorMsg);
}
if (!empty($successMsg)) {
$gBitSmarty->assign('successMsg',$successMsg);
}
// Default the template if we aren't doing an edit.
if (empty($mid)) {
$mid = 'bitpackage:users/my_groups_list.tpl';
}
// Display the template for group administration
$gBitSystem->display( $mid , NULL, array( 'display_mode' => 'display' ));
?>