function flt_users_custom_column($content = '', $column_name, $id) { if ('rs_groups' == $column_name) { global $scoper, $current_user; static $all_groups; if (!isset($all_groups)) { $all_groups = ScoperAdminLib::get_all_groups(); } if (empty($all_groups)) { return; } // query for group membership without cache because otherwise we'll clutter groups col with WP Role Metagroup display if ($group_ids = WP_Scoped_User::get_groups_for_user($id, array('no_cache' => true))) { $group_names = array(); foreach ($group_ids as $group_id) { foreach ($all_groups as $group) { if ($group_id == $group->ID) { $group_names[$group->display_name] = $group_id; break; } } } if ($group_names) { uksort($group_names, "strnatcasecmp"); foreach ($group_names as $name => $id) { $group_names[$name] = "<a href='" . "admin.php?page=rs-groups&mode=edit&id={$id}'>{$name}</a>"; } return implode(", ", $group_names); } } } else { return $content; } }
function _scoper_sseo_groups($group_labels) { $group_labels = array(); $groups = ScoperAdminLib::get_all_groups(UNFILTERED_RS, COLS_ALL_RS, array()); foreach ($groups as $group) { if (empty($group->meta_id)) { $group_labels[$group->ID] = $group->display_name; } } return $group_labels; }
function get_agents($role_bases = '') { if (empty($role_bases)) { $role_bases = array(ROLE_BASIS_USER, ROLE_BASIS_GROUPS); } $agents = array(); if (in_array(ROLE_BASIS_USER, $role_bases)) { global $scoper; $agents[ROLE_BASIS_USER] = $scoper->users_who_can('', COLS_ID_NAME_RS); } if (in_array(ROLE_BASIS_GROUPS, $role_bases)) { $agents[ROLE_BASIS_GROUPS] = ScoperAdminLib::get_all_groups(UNFILTERED_RS); if (!$agents[ROLE_BASIS_GROUPS]) { unset($agents[ROLE_BASIS_GROUPS]); } } return $agents; }
function printGroupMembers() { $results = ScoperAdminLib::get_all_groups(FILTERED_RS); $alt = false; if (isset($results) && count($results) > 0) { echo "\n<table class='rs-member_table' width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">"; echo "\n\t<tr class=\"thead\">"; echo "\n\t\t<th>Group Name</th>\n\t\t<th>Members</th>\n\t\t<th> </th>"; echo "\n\t</tr>"; foreach ($results as $result) { $alt = !$alt; $style = $alt ? 'class=\'alternate\'' : 'margin: 1em 0 1em 0;'; echo "<tr " . $style . "><td>" . $result->display_name . "</td><td>"; if ($members = ScoperAdminLib::get_group_members($result->ID)) { printf(_n('%d user', '%d users', count($members), 'scoper'), count($members)); echo '<br />'; foreach ($members as $member) { echo "- " . $member->display_name . "<br />"; } } else { if ($result->meta_id) { _e('(automatic)', 'scoper'); } else { _e('(no users)', 'scoper'); } } echo "</td><td " . $style . ">"; if (!$result->meta_id) { echo "<a class='edit' href='admin.php?page=rs-group_members&mode=edit&id={$result->ID}'>" . __awp('Edit') . "</a>"; } echo "</td></tr>"; } echo "\n</table>"; } else { echo "<p><strong>" . __('No groups available.', 'scoper') . "</strong></p>"; } }
echo '<a href="#new">' . __('add new') . '</a>'; echo " · <a href='{$url_def}'>" . __('set defaults') . '</a>'; echo " · <a href='{$url_members}'>" . __('browse members') . '</a>'; echo ' )</span>'; } echo '</h2>'; if (scoper_get_option('display_hints')) { echo '<div class="rs-hint">'; if (defined('GROUPS_HINT_RS')) { echo GROUPS_HINT_RS; } else { _e('By creating User Groups, you can assign RS roles to multiple users. Note that group membership itself has no effect on the users until you assign roles to the group.', 'scoper'); } echo '</div><br />'; } $results = ScoperAdminLib::get_all_groups(FILTERED_RS, COLS_ALL_RS, array('include_norole_groups' => true, 'reqd_caps' => 'recommend_group_membership')); $i = 0; if (isset($results) && count($results)) { $msg = __('You are about to delete the group %s. Do you wish to continue?', 'scoper'); $msg = sprintf($msg, '"\'+name+\'"'); ?> <script type="text/javascript"> function DelConfirm(name){ var message= '<?php echo $msg; ?> '; return confirm(message); } </script> <table class="rs-member_table" width="100%" border="0" cellspacing="3" cellpadding="3">
} global $scoper, $wpdb, $current_rs_user; $role_assigner = init_role_assigner(); require_once dirname(__FILE__) . '/admin_lib-bulk_rs.php'; require_once dirname(__FILE__) . '/admin_ui_lib_rs.php'; require_once dirname(__FILE__) . '/role_assignment_lib_rs.php'; $role_bases = array(); $agents = array(); $is_administrator = is_user_administrator_rs(); if (USER_ROLES_RS && $is_administrator) { $role_bases[] = ROLE_BASIS_USER; $agents[ROLE_BASIS_USER] = $scoper->users_who_can('', COLS_ID_NAME_RS); $agent_list_prefix[ROLE_BASIS_USER] = ''; } if (GROUP_ROLES_RS && $is_administrator) { if ($agents[ROLE_BASIS_GROUPS] = ScoperAdminLib::get_all_groups(UNFILTERED_RS)) { $role_bases[] = ROLE_BASIS_GROUPS; $agent_list_prefix[ROLE_BASIS_GROUPS] = __('Groups') . ': '; } } if (empty($role_bases)) { wp_die(__awp('Cheatin’ uh?')); } $duration_limits_enabled = scoper_get_option('role_duration_limits'); $content_date_limits_enabled = scoper_get_option('role_content_date_limits'); $agent_names = array(); foreach ($role_bases as $role_basis) { foreach ($agents[$role_basis] as $agent) { $agent_names[$role_basis][$agent->ID] = str_replace(' ', ' ', $agent->display_name); } }
function update_user_groups_multi_status($user_id, $stored_groups, $editable_group_ids) { global $current_rs_user; $posted_groups = array(); $is_administrator = is_user_administrator_rs(); $can_manage = $is_administrator || current_user_can('manage_groups'); $can_moderate = $can_manage || current_user_can('recommend_group_membership'); if (!$can_moderate && !current_user_can('request_group_membership')) { return; } if ($can_manage) { $posted_groups['active'] = explode(',', trim($_POST['current_agents_rs_csv'], '')); } else { $stored_groups = array_diff_key($stored_groups, array('active' => true)); } if ($can_moderate) { $posted_groups['recommended'] = !empty($_POST['recommended_agents_rs_csv']) ? explode(',', trim($_POST['recommended_agents_rs_csv'], '')) : array(); $stored_groups['recommended'] = array_fill_keys($current_rs_user->get_groups_for_user($current_rs_user->ID, array('status' => 'recommended')), true); $editable_group_ids['recommended'] = ScoperAdminLib::get_all_groups(FILTERED_RS, COL_ID_RS, array('reqd_caps' => 'recommend_group_membership')); if (isset($editable_group_ids['active'])) { $editable_group_ids['recommended'] = array_unique($editable_group_ids['recommended'] + $editable_group_ids['active']); } } $stored_groups['requested'] = array_fill_keys($current_rs_user->get_groups_for_user($current_rs_user->ID, array('status' => 'requested')), true); $editable_group_ids['requested'] = ScoperAdminLib::get_all_groups(FILTERED_RS, COL_ID_RS, array('reqd_caps' => 'request_group_membership')); if (isset($editable_group_ids['recommended'])) { $editable_group_ids['requested'] = array_unique($editable_group_ids['requested'] + $editable_group_ids['recommended']); } $posted_groups['requested'] = !empty($_POST['requested_agents_rs_csv']) ? explode(',', trim($_POST['requested_agents_rs_csv'], '')) : array(); $all_posted_groups = agp_array_flatten($posted_groups); $all_stored_groups = array(); foreach (array_keys($stored_groups) as $status) { $all_stored_groups = $all_stored_groups + $stored_groups[$status]; } foreach ($stored_groups as $status => $stored) { if (!$editable_group_ids[$status]) { continue; } // remove group memberships which were not posted for any status, if logged user can edit the group foreach (array_keys($stored) as $group_id) { if (!in_array($group_id, $all_posted_groups)) { if (in_array($group_id, $editable_group_ids[$status])) { ScoperAdminLib::remove_group_user($group_id, $user_id); } } } } foreach ($posted_groups as $status => $posted) { if (!$editable_group_ids[$status]) { continue; } // insert or update group memberships as specified, if logged user can edit the group foreach ($posted as $group_id) { if (in_array($group_id, $editable_group_ids[$status])) { if (!in_array($group_id, $all_stored_groups)) { ScoperAdminLib::add_group_user($group_id, $user_id, $status); } elseif (!in_array($group_id, $stored_groups[$status])) { ScoperAdminLib::update_group_user($group_id, $user_id, $status); } } } } }
function display_ui_user_groups() { if (!($all_groups = ScoperAdminLib::get_all_groups(UNFILTERED_RS))) { return; } global $current_rs_user, $profileuser; $user_id = $profileuser->ID; $editable_ids = ScoperAdminLib::get_all_groups(FILTERED_RS, COL_ID_RS); if ($user_id == $current_rs_user->ID) { $stored_groups = array_keys($current_rs_user->groups); } else { $user = new WP_Scoped_User($user_id, '', array('skip_role_merge' => 1)); $stored_groups = array_keys($user->groups); } // can't manually edit membership of WP Roles groups, other metagroups $all_ids = array(); foreach ($all_groups as $key => $group) { $all_ids[] = $group->ID; if (!empty($group->meta_id) && !is_null($group->meta_id) && in_array($group->ID, $editable_ids) && !strpos($group->meta_id, '_editable')) { $editable_ids = array_diff($editable_ids, array($group->ID)); $stored_groups = array_diff($stored_groups, array($group->ID)); unset($all_groups[$key]); } } // avoid incorrect eligible count if orphaned group roles are included in editable_ids $editable_ids = array_intersect($editable_ids, $all_ids); if (!$editable_ids && !$stored_groups) { return; } echo "<div id='userprofile_groupsdiv_rs' class='rs-group_members'>"; echo "<h3>"; if (defined('GROUPS_CAPTION_RS')) { echo GROUPS_CAPTION_RS; } else { _e('User Groups', 'scoper'); } echo "</h3>"; if (scoper_get_option('group_ajax')) { $arr_display_names = array(); $group_ids = array(); $group_ids['active'] = $stored_groups; $group_ids['recommended'] = $current_rs_user->get_groups_for_user($user_id, array('status' => 'recommended')); $group_ids['requested'] = $current_rs_user->get_groups_for_user($user_id, array('status' => 'requested')); foreach ($group_ids as $key => $ids) { foreach ($ids as $group_id) { foreach (array_keys($all_groups) as $nkey) { if ($all_groups[$nkey]->ID == $group_id) { $arr_display_names[$key][$group_id] = $all_groups[$nkey]->display_name; break; } } } } global $scoper_user_search; $scoper_user_search->output_html($arr_display_names, 'groups'); } else { $css_id = 'group'; $locked_ids = array_diff($stored_groups, $editable_ids); $args = array('suppress_extra_prefix' => true, 'eligible_ids' => $editable_ids, 'locked_ids' => $locked_ids); require_once dirname(__FILE__) . '/agents_checklist_rs.php'; ScoperAgentsChecklist::agents_checklist(ROLE_BASIS_GROUPS, $all_groups, $css_id, array_flip($stored_groups), $args); echo '</fieldset>'; } echo '</div><br />'; echo "<input type='hidden' name='rs_editing_user_groups' value='1' />"; }
<?php require_once dirname(__FILE__) . '/groups-support.php'; wp_nonce_field('scoper-assign-termroles'); if (isset($_POST['rs_submit'])) { $stored_groups = isset($_POST['group']) ? $_POST['group'] : array(); scoper_update_option('default_groups', $stored_groups); echo '<div id="message" class="updated fade"><p>'; printf(__('Default Groups Updated: %s groups', 'scoper'), count($stored_groups)); echo '</p></div>'; } else { $stored_groups = scoper_get_option('default_groups'); } if (!($all_groups = ScoperAdminLib::get_all_groups(UNFILTERED_RS))) { return; } if ($editable_ids = ScoperAdminLib::get_all_groups(FILTERED_RS, COL_ID_RS)) { echo "<div id='default_groupsdiv_rs' style='margin-top:1em'>"; if (!$stored_groups) { $stored_groups = array(); echo '<p><strong>'; _e('No default groups defined.', 'scoper'); echo '</strong></p>'; } // WP Roles groups, other metagroups can't be a default group foreach ($all_groups as $key => $group) { if (!empty($group->meta_id) && in_array($group->ID, $editable_ids)) { $editable_ids = array_diff($editable_ids, array($group->ID)); } } $css_id = 'group'; $locked_ids = array_diff($stored_groups, $editable_ids);
function load_roles($src_name, $object_type, $object_id) { //log_mem_usage_rs( 'start ItemRolesUI::load_roles()' ); if ('edit.php' == $GLOBALS['pagenow']) { return; } if (!scoper_get_otype_option('use_object_roles', $src_name, $object_type)) { return; } if (!($src = $this->scoper->data_sources->get($src_name))) { return; } $this->loaded_src_name = $src_name; $this->loaded_object_type = $object_type; $this->loaded_object_id = $object_id; $this->indicate_blended_roles = scoper_get_option('indicate_blended_roles'); $this->all_agents = array(); $this->agent_captions = array(); $this->agent_captions_plural = array(); $this->eligible_agent_ids = array(); // note: if object_id = 0, default roles will be retrieved $get_defaults = !$object_id; $obj_roles = array(); $role_defs = $this->scoper->role_defs->get_matching('rs', $src_name, $object_type); $this->role_handles = array_keys($role_defs); // for default roles, distinguish between various object types $filter_role_handles = $object_id ? '' : array_keys($role_defs); if (GROUP_ROLES_RS) { $this->current_roles[ROLE_BASIS_GROUPS] = ScoperRoleAssignments::organize_assigned_roles(OBJECT_SCOPE_RS, $src_name, $object_id, $filter_role_handles, ROLE_BASIS_GROUPS, $get_defaults); } //log_mem_usage_rs( 'load_roles: organize_assigned_roles for groups' ); if (USER_ROLES_RS) { $this->current_roles[ROLE_BASIS_USER] = ScoperRoleAssignments::organize_assigned_roles(OBJECT_SCOPE_RS, $src_name, $object_id, $filter_role_handles, ROLE_BASIS_USER, $get_defaults); } //log_mem_usage_rs( 'load_roles: organize_assigned_roles for users' ); if (GROUP_ROLES_RS) { $this->all_groups = ScoperAdminLib::get_all_groups(UNFILTERED_RS); //log_mem_usage_rs( 'load_roles: get_all_groups' ); if (!empty($this->all_groups)) { $this->agent_captions[ROLE_BASIS_GROUPS] = __('Group', 'scoper'); $this->agent_captions_plural[ROLE_BASIS_GROUPS] = __('Groups', 'scoper'); $this->all_agents[ROLE_BASIS_GROUPS] = $this->all_groups; $this->all_agents[ROLE_BASIS_GROUPS] = $this->all_groups; } //log_mem_usage_rs( 'load_roles: set all_groups properties' ); } if (USER_ROLES_RS) { $this->agent_captions[ROLE_BASIS_USER] = __('User', 'scoper'); $this->agent_captions_plural[ROLE_BASIS_USER] = __awp('Users'); // note: all users are eligible for a reading role assignment, but we may not be displaying user checkboxes $user_csv_input = scoper_get_option("user_role_assignment_csv"); if (!$user_csv_input) { $this->all_agents[ROLE_BASIS_USER] = $this->scoper->users_who_can('', COLS_ID_NAME_RS); } elseif ($object_id) { $assignees = array(); if ($this->current_roles[ROLE_BASIS_USER]) { foreach (array_keys($this->current_roles[ROLE_BASIS_USER]) as $role_handle) { $assignees = array_merge($assignees, array_keys($this->current_roles[ROLE_BASIS_USER][$role_handle]['assigned'])); } } $assignees = array_unique($assignees); global $wpdb; $this->all_agents[ROLE_BASIS_USER] = scoper_get_results("SELECT ID, display_name FROM {$wpdb->users} WHERE ID IN ('" . implode("','", $assignees) . "')"); } else { $this->all_agents[ROLE_BASIS_USER] = array(); } //log_mem_usage_rs( 'load_roles: users_who_can for all_agents' ); //users eligible for an editing role assignments are those who have the basic edit cap via taxonomy or blog role if (scoper_get_otype_option('limit_object_editors', $src_name, $object_type)) { // Limit eligible page contribs/editors based on blog ownership of "edit_posts" // Otherwise, since pages are generally not categorized, only Blog Editors and Admins are eligible for object role ass'n // It's more useful to exclude Blog Subscribers while including all others $role_object_type = 'page' == $object_type ? 'post' : $object_type; $reqd_caps = $this->scoper->cap_defs->get_matching($src_name, $role_object_type, OP_EDIT_RS, '', BASE_CAPS_RS); // status-specific and 'others' caps will not be returned $args = array('ignore_strict_terms' => true, 'ignore_group_roles' => true, 'skip_object_roles' => true); $this->eligible_agent_ids[ROLE_BASIS_USER][OP_EDIT_RS] = $this->scoper->users_who_can(array_keys($reqd_caps), COL_ID_RS, '', 0, $args); //log_mem_usage_rs( 'load_roles: users_who_can for eligible_agent_ids' ); } } $this->blog_term_roles = array(); // Pull object and blog/term role assignments for all roles // Do this first so contained / containing roles can be accounted for in UI foreach ($role_defs as $role_handle => $role_def) { if ($this->indicate_blended_roles && isset($role_def->valid_scopes[OBJECT_SCOPE_RS])) { // might need to check term/blog assignment of a different role to reflect object's current status if (!empty($role_def->other_scopes_check_role) && !empty($src->cols->status)) { $status = $this->scoper->data_sources->detect('status', $src, $object_id); if (isset($role_def->other_scopes_check_role[$status])) { $blog_term_role_handle = $role_def->other_scopes_check_role[$status]; } elseif (isset($role_def->other_scopes_check_role[''])) { $blog_term_role_handle = $role_def->other_scopes_check_role['']; } else { $blog_term_role_handle = $role_handle; } } else { $blog_term_role_handle = $role_handle; } $this_args = array('skip_object_roles' => true, 'object_type' => $object_type, 'ignore_group_roles' => true); if (empty($user_csv_input)) { $this->blog_term_roles[ROLE_BASIS_USER][$role_handle] = $this->scoper->users_who_can($blog_term_role_handle, COL_ID_RS, $src_name, $object_id, $this_args); //log_mem_usage_rs( "load_roles: users_who_can for $role_handle users" ); } else { $this->blog_term_roles[ROLE_BASIS_USER][$role_handle] = array(); } $this->blog_term_roles[ROLE_BASIS_GROUPS][$role_handle] = $this->scoper->groups_who_can($blog_term_role_handle, COL_ID_RS, $src_name, $object_id, $this_args); //log_mem_usage_rs( "load_roles: groups_who_can for $role_handle groups" ); } } $this->do_propagation_cboxes = !empty($src->cols->parent) && !$this->scoper->data_sources->member_property($src_name, 'object_types', $object_type, 'ignore_object_hierarchy'); $this->object_strict_roles = array(); $this->child_strict_roles = array(); $args = array('id' => $object_id, 'include_child_restrictions' => true); if ($restrictions = $this->scoper->get_restrictions(OBJECT_SCOPE_RS, $src_name, $args)) { //log_mem_usage_rs( "load_roles: get_restrictions" ); foreach ($this->role_handles as $role_handle) { // defaults for this role if (isset($restrictions['unrestrictions'][$role_handle]) && is_array($restrictions['unrestrictions'][$role_handle])) { $this->object_strict_roles[$role_handle] = true; $this->child_strict_roles[$role_handle] = true; } else { $this->object_strict_roles[$role_handle] = false; $this->child_strict_roles[$role_handle] = false; } // role is not default strict, and a restriction is set if (isset($restrictions['restrictions'][$role_handle][$object_id])) { switch ($restrictions['restrictions'][$role_handle][$object_id]) { case ASSIGN_FOR_ENTITY_RS: $this->object_strict_roles[$role_handle] = true; $this->child_strict_roles[$role_handle] = false; break; case ASSIGN_FOR_CHILDREN_RS: $this->object_strict_roles[$role_handle] = false; $this->child_strict_roles[$role_handle] = true; break; case ASSIGN_FOR_BOTH_RS: $this->object_strict_roles[$role_handle] = true; $this->child_strict_roles[$role_handle] = true; } // end switch // role IS default strict, and no unrestriction is set } elseif (isset($restrictions['unrestrictions'][$role_handle][$object_id])) { switch ($restrictions['unrestrictions'][$role_handle][$object_id]) { case ASSIGN_FOR_ENTITY_RS: $this->object_strict_roles[$role_handle] = false; $this->child_strict_roles[$role_handle] = true; break; case ASSIGN_FOR_CHILDREN_RS: $this->object_strict_roles[$role_handle] = true; $this->child_strict_roles[$role_handle] = false; break; case ASSIGN_FOR_BOTH_RS: $this->object_strict_roles[$role_handle] = false; $this->child_strict_roles[$role_handle] = false; } // end switch } } // end foreach Role Handle } //log_mem_usage_rs( 'end ItemRolesUI::load_roles()' ); }
function output_html($agents, $agent_type = 'users') { if ('groups' == $agent_type) { $reqd_caps = 'manage_groups'; if (!empty($this->status[0])) { if ('requested' == $this->status[0]) { $reqd_caps = 'request_group_membership'; } elseif ('recommended' == $this->status[0]) { $reqd_caps = 'recommend_group_membership'; } } $editable_group_ids = ScoperAdminLib::get_all_groups(FILTERED_RS, COL_ID_RS, array('reqd_caps' => $reqd_caps)); } if (!empty($this->list_ids)) { ?> <div id="agents_selection_rs"> <?php if (defined(strtoupper($agent_type) . '_SEARCH_CAPTION_RS')) { echo constant(strtoupper($agent_type) . '_SEARCH_CAPTION_RS'); } elseif ('groups' == $agent_type) { _e('Search for Groups', 'scoper'); } else { _e('Search for Users', 'scoper'); } ?> <br /> <table style="width: 100%"><tr> <td style="vertical-align: top; padding-right:1em;"> <input id="item_search_text" type="text" size="12" /> <button type="button" id="item_submit">Search</button> <br /><br /> <select id="item_results" multiple="multiple" style="height:160px;width:200px;"></select> </td> <td> <span id="item_msg"></span> <button type="button" id="add_item" class="rs_add">Add ></button> </td> <td> <?php echo $this->list_captions[0]; ?> <br /> <select name="<?php echo $this->list_ids[0]; ?> []" id="<?php echo $this->list_ids[0]; ?> " multiple="multiple" style="height:100px;width:200px;"> <?php if (!empty($agents[$this->status[0]])) { foreach ($agents[$this->status[0]] as $value => $caption) { if ('users' == $agent_type || in_array($value, $editable_group_ids)) { echo "<option value='{$value}'>{$caption}</option>"; } } } ?> </select> <br /> <span id="box1Counter_0" class="countLabel"></span> <select id="box1Storage_0" style='display:none'> </select> </td> <td> <button id="to2_0" type="button" class="rs_remove"><?php echo esc_html($this->remove_button[0]); ?> </button> <button id="allTo2_0" type="button" class="rs_remove"><?php echo esc_html($this->remove_all_button[0]); ?> </button> <br /><br /> <button id="allTo1_0" type="button"><?php echo esc_html($this->restore_all_button[0]); ?> </button> <button id="to1_0" type="button"><?php echo esc_html($this->restore_button[0]); ?> </button></td> <td> <?php echo $this->removal_captions[0]; ?> <br /> <select id="<?php echo $this->removal_ids[0]; ?> " multiple="multiple" style="height:100px;width:100px;"></select> <br/> <span id="box2Counter_0" class="countLabel"></span> <select id="box2Storage_0" style='display:none'> </select> </td> </tr> <?php // now that the search box and highest accessable selection box is outputted, also display recommended / requested items if (count($this->list_ids) > 1) { for ($key = 1; $key < count($this->list_ids); $key++) { ?> <tr> <td></td> <td></td> <td> <?php echo $this->list_captions[$key]; ?> <br /> <select name="<?php echo $this->list_ids[$key]; ?> []" id="<?php echo $this->list_ids[$key]; ?> " multiple="multiple" style="height:100px;width:200px;"> <?php if (!empty($agents[$this->status[$key]])) { foreach ($agents[$this->status[$key]] as $value => $caption) { if ('users' == $agent_type || in_array($value, $editable_group_ids)) { echo "<option value='{$value}'>{$caption}</option>"; } } } ?> </select> <br /> <span id="box1Counter_<?php echo $key; ?> " class="countLabel"></span> <select id="box1Storage_<?php echo $key; ?> " style='display:none'> </select> <br /> </td> <td> <?php if (!empty($this->approval_button_id[$key])) { echo "<button id='{$this->approval_button_id[$key]}' type='button' class='rs_approve'>{$this->approval_caption[$key]}</button><br /><br />"; } ?> <button id="to2_<?php echo $key; ?> " type="button" class="rs_remove"><?php echo $this->remove_button[$key]; ?> </button> <button id="allTo2_<?php echo $key; ?> " type="button" class="rs_remove"><?php echo $this->remove_all_button[$key]; ?> </button> <br /> <button id="allTo1_<?php echo $key; ?> " type="button"><?php echo $this->restore_all_button[$key]; ?> </button> <button id="to1_<?php echo $key; ?> " type="button"><?php echo $this->restore_button[$key]; ?> </button></td> <td> <?php echo $this->removal_captions[$key]; ?> <br /> <select id="<?php echo $this->removal_ids[$key]; ?> " multiple="multiple" style="height:100px;width:100px;"></select> <br/> <span id="box2Counter_<?php echo $key; ?> " class="countLabel"></span> <select id="box2Storage_<?php echo $key; ?> " style='display:none'> </select> </td> </tr> <?php } } // more than one listbox to display ?> </table> </div> <?php foreach ($this->list_ids as $key => $list_id) { if ($agents && !empty($agents[$this->status[$key]])) { $csv = implode(',', array_keys($agents[$this->status[$key]])); } else { $csv = ''; } echo "<input type='hidden' id='{$list_id}_csv' name='{$list_id}_csv' value='" . $csv . "' />"; } } // any list_ids set (logged user can submit groups for any status) $captions = array(); $captions['active'] = __('Active Membership', 'scoper'); $captions['recommended'] = __('Recommended Membership', 'scoper'); $captions['requested'] = __('Requested Membership', 'scoper'); if ('groups' == $agent_type) { // display uneditable groups $uneditable_groups = array(); foreach (array_keys($agents) as $status) { $uneditable_groups[$status] = array(); $status_editable = false !== array_search($status, $this->status); foreach ($agents[$status] as $group_id => $group_name) { if ((!$status_editable || !in_array($group_id, $editable_group_ids)) && false === strpos($group_name, '[')) { $uneditable_groups[$status][] = $group_name; } } if ($uneditable_groups[$status]) { $groups_csv = implode(", ", $uneditable_groups[$status]); printf(__('<b>%1$s</b>: %2$s', 'scoper'), $captions[$status], $groups_csv); echo '<br /><br />'; } } } else { foreach (array_keys($agents) as $status) { if (false === array_search($status, $this->status)) { $users_csv = implode(", ", $agents[$status]); printf(__('<b>%1$s</b>: %2$s', 'scoper'), $captions[$status], $users_csv); echo '<br /><br />'; } } } }
function agent_ids_from_csv($csv_id, $role_basis) { static $groups_by_name; if (ROLE_BASIS_GROUPS == $role_basis && !empty($_POST[$csv_id])) { if (!isset($groups_by_name)) { $all_groups = ScoperAdminLib::get_all_groups(); $groups_by_name = array(); foreach ($all_groups as $group) { $groups_by_name[$group->display_name] = $group->ID; } } } $agent_ids = array(); if (!empty($_POST[$csv_id])) { $agent_names = explode(",", $_POST[$csv_id]); // role assignments for item foreach ($agent_names as $agent_name) { if (empty($agent_name)) { continue; } else { $agent_name = trim($agent_name); } if (ROLE_BASIS_GROUPS == $role_basis) { if (isset($groups_by_name[$agent_name])) { $agent_ids[] = $groups_by_name[$agent_name]; } elseif (intval($agent_name) && in_array($agent_name, $groups_by_name)) { $agent_ids[] = $agent_name; } } else { require_once dirname(__FILE__) . '/user_lib_rs.php'; if ($user = awp_get_user_by_name($agent_name)) { $agent_ids[] = $user->ID; } elseif (intval($agent_name) && awp_get_user_by_id($agent_name)) { $agent_ids[] = $agent_name; } } } } return $agent_ids; }
$searches = array(); $where = 'AND ('; foreach (array('group_name', 'group_description') as $col) { $searches[] = $col . " LIKE '%{$_GET['rs_group_search']}%'"; } $where .= implode(' OR ', $searches); $where .= ')'; } else { $where = ''; } if ('recommended' == $_GET['rs_target_status']) { $reqd_caps = 'recommend_group_membership'; } elseif ('requested' == $_GET['rs_target_status']) { $reqd_caps = 'request_group_membership'; } else { $reqd_caps = 'manage_groups'; } // determine all currently stored groups (of any status) for user in question (not necessarily logged user) if (!empty($_GET['rs_agent_id'])) { $user_groups = $GLOBALS['current_rs_user']->get_groups_for_user($_GET['rs_agent_id'], array('status' => 'any')); } else { $user_groups = array(); } if ($groups = ScoperAdminLib::get_all_groups(FILTERED_RS, COLS_ALL_RS, array('include_norole_groups' => false, 'reqd_caps' => $reqd_caps, 'where' => $where))) { foreach ($groups as $row) { if ((is_null($row->meta_id) || empty($row->meta_id)) && !in_array($row->ID, $user_groups)) { echo "<option value='{$row->ID}'>{$row->display_name}</option>"; } } } }