Groups" Tab * It allows to manage Groups by editing, adding or deleting ************************************************************/ require_once( dirname(__FILE__).'/groups-support.php'); global $wpdb; global $scoper; $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : ''; $cancel = isset($_REQUEST['cancel']) ? $_REQUEST['cancel'] : ''; $success_msg = ''; $errorMessage = ""; $all_users = array(); $suppress_groups_list = false; $can_manage_all_groups = is_user_administrator_rs() || awp_user_can('manage_groups', BLOG_SCOPE_RS); switch ($mode) { case "add": if( ! $can_manage_all_groups ) wp_die(__awp('Cheatin’ uh?')); check_admin_referer( 'scoper-edit-groups' ); if ( ! empty($_POST['groupName']) ) { $_POST['groupName'] = str_replace( '[', '', $_POST['groupName'] ); $_POST['groupName'] = str_replace( ']', '', $_POST['groupName'] ); } if( ! UserGroups_tp::isValidName($_POST['groupName'])) { if($_POST['groupName'] == "") $errorMessage = __("Please specify a name for the group.", 'scoper'); else $errorMessage = sprintf( __("A group with the name %s already exists.", 'scoper'), $_POST['groupName']); } else { if( UserGroups_tp::createGroup ($_POST['groupName'], $_POST['groupDesc'])){ $success_msg = sprintf( __("Group %s created successfuly.", 'scoper'), $_POST['groupName']); $group = UserGroups_tp::getGroupByName($_POST['groupName']); } } //$suppress_groups_list = true; break; case "edit": $id = $_REQUEST['id']; if( ! is_user_administrator_rs() && ! current_user_can('recommend_group_membership', $id) && ! current_user_can('manage_groups', $id) ) wp_die(__awp('Cheatin’ uh?')); $group = ScoperAdminLib::get_group($id); if ( $group->meta_id && ! strpos($group->meta_id, '_ed_') ) die( __('This meta group is automatically populated. You cannot manually edit it.', 'scoper') ); $group->prev_name = $group->display_name; $suppress_groups_list = true; break; case "editSubmit": $group->ID = $_POST['groupID']; if ( $can_manage_all_groups || current_user_can( 'manage_groups', $_POST['groupID'] ) ) { if ( ! empty($_POST['groupName']) ) { $_POST['groupName'] = str_replace( '[', '', $_POST['groupName'] ); $_POST['groupName'] = str_replace( ']', '', $_POST['groupName'] ); } //to continue edit $group->display_name = $_POST['groupName']; $group->prev_name = $_POST['prevName']; $group->descript = $_POST['groupDesc']; if ( $get_group = ScoperAdminLib::get_group($group->ID) ) $group->meta_id = $get_group->meta_id; check_admin_referer( 'scoper-edit-group_' . $group->ID ); if ( ! $group->meta_id ) { // editable metagroups can have users edited but not group name\ if(! UserGroups_tp::isValidName($_POST['groupName']) && $_POST['groupName'] != $_POST['prevName']){ if($_POST['groupName'] == ""){ $errorMessage = __("Please specify a name for the group.", 'scoper'); $mode = "edit"; } else { $errorMessage = sprintf( __("A group with the name %s already exists.", 'scoper'), $_POST['groupName']); $mode = "edit"; } } else { if ( UserGroups_tp::updateGroup ($_POST['groupID'], $_POST['groupName'], $_POST['groupDesc']) ) { $success_msg = sprintf( __("Group %s updated successfuly.", 'scoper'), $_POST['groupName']); } else { $errorMessage = sprintf( __("Group %s was not updated successfuly.", 'scoper'), $_POST['prevName']); $mode = "edit"; } } } else $success_msg = sprintf( __("Group %s updated successfuly.", 'scoper'), ''); } else { // endif logged user is a group manager / administrator $success_msg = __("Group members updated successfuly.", 'scoper'); } break; case "delete": $idDel = $_REQUEST['id']; if($idDel != ""){ if( ! $can_manage_all_groups && ! current_user_can('manage_groups', $idDel) ) wp_die(__awp('Cheatin’ uh?')); check_admin_referer( 'scoper-edit-group_' . $idDel ); if(UserGroups_tp::deleteGroup($idDel)){ UserGroups_tp::write( __("Group Deleted.", 'scoper') ); }else{ UserGroups_tp::write( __("Invalid group. No groups were deleted.", 'scoper'), false); } $_REQUEST['id'] = ""; } break; case "approve": if( awp_ver('2.8') && scoper_get_option( 'group_ajax' ) ) { if ( $can_manage_all_groups || current_user_can( 'manage_groups', $_GET['id'] ) ) $status = 'active'; elseif ( current_user_can( 'recommend_group_membership', $_GET['id'] ) ) $status = 'recommended'; else break; $update_user = new WP_User( $_GET['user'] ); $update_group = ScoperAdminLib::get_group( $_GET['id'] ); if ( $update_user->ID && $update_group->ID ) { ScoperAdminLib::update_group_user( $_GET['id'], $_GET['user'], $status ); $success_msg = __("Group members updated successfuly.", 'scoper'); } else { $errorMessage = __("Error updating group membership.", 'scoper'); } } break; default: switch($cancel){ case 1: UserGroups_tp::write( __("Group edit cancelled.", 'scoper') ); break; default: break; } break; } if ( ! $errorMessage && ( ('editSubmit' == $mode) || ('add' == $mode) || ('approve' == $mode) ) ) { // ----- add/delete group members or managers ---- // members $current_members = array(); if( scoper_get_option( 'group_ajax' ) ) { $current_members['active'] = ScoperAdminLib::get_group_members($group->ID, COL_ID_RS); UserGroups_tp::update_group_members_multi_status( $group->ID, $current_members ); } else { $current_members = ScoperAdminLib::get_group_members($group->ID, COL_ID_RS); $posted_members = ( isset($_POST['member']) ) ? $_POST['member'] : array(); if ( ! empty($_POST['member_csv']) ) { if ( $csv_for_item = ScoperAdminLib::agent_ids_from_csv( 'member_csv', 'user' ) ) $posted_members = array_merge($posted_members, $csv_for_item); } if ( $delete_members = array_diff($current_members, $posted_members) ) { ScoperAdminLib::remove_group_user($group->ID, $delete_members); $success_msg .= ' ' . sprintf( _n('%d member deleted.', '%d members deleted.', count($delete_members), 'scoper'), count($delete_members) ); } if ( $new_members = array_diff($posted_members, $current_members) ) { ScoperAdminLib::add_group_user($group->ID, $new_members); $success_msg .= ' ' . sprintf( _n('%d member added.', '%d members added.', count($new_members), 'scoper'), count($new_members) ); } } if ( $can_manage_all_groups || current_user_can('manage_groups', $group->ID) ) { $role_assigner = init_role_assigner(); if ( $can_manage_all_groups ) { // group managers $users = ( isset($_POST['manager']) ) ? array_fill_keys( $_POST['manager'], 'entity' ) : array(); if ( ! empty($_POST['manager_csv']) ) { if ( $csv_for_item = ScoperAdminLib::agent_ids_from_csv( 'manager_csv', 'user' ) ) { foreach ( $csv_for_item as $id ) $users[$id] = 'entity'; } } $role_arg = array( 'rs_group_manager' => $users ); $args = array( 'implicit_removal' => true ); $role_assigner->assign_roles( OBJECT_SCOPE_RS, 'group', $group->ID, $role_arg, ROLE_BASIS_USER, $args ); } if ( scoper_get_option( 'group_ajax' ) ) { // group moderators $users = ( isset($_POST['moderator']) ) ? array_fill_keys( $_POST['moderator'], 'entity' ) : array(); if ( ! empty($_POST['moderator_csv']) ) { if ( $csv_for_item = ScoperAdminLib::agent_ids_from_csv( 'moderator_csv', 'user' ) ) { foreach ( $csv_for_item as $id ) $users[$id] = 'entity'; } } $role_arg = array( 'rs_group_moderator' => $users ); $args = array( 'implicit_removal' => true ); $role_assigner->assign_roles( OBJECT_SCOPE_RS, 'group', $group->ID, $role_arg, ROLE_BASIS_USER, $args ); } } // -------- end member / manager update ---------- UserGroups_tp::write( $success_msg ); if ( 'add' == $mode ) $group = ''; } ?>
meta_id ) ? ScoperAdminLib::get_metagroup_name( $result->meta_id, $result->display_name ) : $result->display_name; if ( ( ! $result->meta_id || strpos($result->meta_id, '_ed_') ) && ( is_user_administrator_rs() || current_user_can('recommend_group_membership', $result->ID) ) ) { $url = "admin.php?page=rs-groups&mode=edit&id={$result->ID}"; echo "$name"; } else echo $name; ?> | meta_id ) echo ScoperAdminLib::get_metagroup_descript( $result->meta_id, $result->descript ); else echo $result->descript; ?> | meta_id && ( $can_manage_all_groups || current_user_can('manage_groups', $result->ID) ) ):?> ID}"; $url = wp_nonce_url( $url, 'scoper-edit-group_' . $result->ID ); ?> |
" . __('No groups available.', 'scoper') . "
"; } ?>