예제 #1
0
 public static function add_bulk_users_to_group()
 {
     $added_users = 0;
     //ERROR - No users selected!
     if (empty($_REQUEST['users'])) {
         $response = new WP_Ajax_Response(array('what' => 'bulk_enroll', 'action' => 'add_bulk_users_to_group', 'id' => new WP_Error('error', __('No users were selected.', 'contexture-page-security')), 'supplemental' => array('html' => CTXPS_Components::render_wp_message(__('No users were selected.', 'contexture-page-security'), 'error'))));
         $response->send();
     }
     //ERROR - No group selected
     if (empty($_REQUEST['group_id'])) {
         $response = new WP_Ajax_Response(array('what' => 'bulk_enroll', 'action' => 'add_bulk_users_to_group', 'id' => new WP_Error('error', __('No group was selected.', 'contexture-page-security')), 'supplemental' => array('html' => CTXPS_Components::render_wp_message(__('No group was selected.', 'contexture-page-security'), 'error'))));
         $response->send();
     }
     //Loop through all selected users...
     foreach ($_REQUEST['users'] as $user) {
         //Ensure users exists and is isnt already in group
         if (CTXPS_Queries::check_user_exists($user['value']) && !CTXPS_Queries::check_membership($user['value'], $_REQUEST['group_id'])) {
             //Try to add user
             if (CTXPS_Queries::add_membership($user['value'], $_REQUEST['group_id'])) {
                 //increment for added users
                 $added_users++;
             }
         }
     }
     $response = new WP_Ajax_Response(array('what' => 'bulk_enroll', 'action' => 'add_bulk_users_to_group', 'id' => 1, 'data' => '', 'supplemental' => array('html' => CTXPS_Components::render_wp_message(sprintf(__('%d users were enrolled.', 'contexture-page-security'), $added_users), 'updated fade'))));
     $response->send();
 }
         $actionmessage = '<div id="message" class="updated below-h2"><p>' . __('Group details have been saved.', 'contexture-page-security') . ' <a href="' . $linkBack . 'users.php?page=ps_groups">' . __('Return to group list', 'contexture-page-security') . ' &gt;&gt;</a></p></div>';
     }
     break;
 case 'addusr':
     //Make sure user exists in db
     if (!username_exists($_GET['add-username'])) {
         $actionmessage = sprintf('<div class="error below-h2"><p>' . __('User &quot;%s&quot; does not exist.', 'contexture-page-security') . '</p></div>', esc_attr($_GET['add-username']));
     } else {
         //Get the user id from the username
         $AddUserId = CTXPS_Queries::get_user_id_by_username($_GET['add-username']);
         //Make sure user isnt already in the group
         if (CTXPS_Queries::check_membership($AddUserId, $_GET['groupid']) > 0) {
             $actionmessage = '<div class="error below-h2"><p>' . __('User is already in this group.', 'contexture-page-security') . '</p></div>';
         } else {
             //Add user to group
             if (CTXPS_Queries::add_membership($AddUserId, $_GET['groupid']) === false) {
                 $actionmessage = '<div class="error below-h2"><p>' . __('An error occurred. User could not be added to the group.', 'contexture-page-security') . '</p></div>';
             } else {
                 $actionmessage = sprintf('<div id="message" class="updated below-h2"><p>' . __('User &quot;%s&quot; has been added to the group.', 'contexture-page-security') . '</p></div>', esc_attr($_GET['add-username']));
             }
         }
     }
     break;
 case 'rmvusr':
     //Remove the user from the group
     if (CTXPS_Queries::delete_membership($_GET['usrid'], $_GET['groupid']) === false) {
         $actionmessage = '<div class="error below-h2"><p>' . __('An error occurred. User could not be removed from group.', 'contexture-page-security') . '</p></div>';
     } else {
         $actionmessage = sprintf('<div id="message" class="updated below-h2"><p>' . __('User &quot;%s&quot; was removed from the group.', 'contexture-page-security') . '</p></div>', esc_attr($_GET['usrname']));
     }
     break;