Пример #1
0
    function display_inputs($mode, $assignment_modes, $args = array())
    {
        $defaults = array('role_bases' => '', 'agents' => '', 'agent_caption_plural' => '', 'max_scopes' => array(), 'scope' => '', 'src_or_tx_name' => '');
        $args = array_merge($defaults, (array) $args);
        extract($args);
        global $scoper;
        echo "<br /><a name='scoper_submit'></a>";
        echo '<ul class="rs-list_horiz"><li style="float:left;"><h3>1.&nbsp;';
        if (ROLE_ASSIGNMENT_RS == $mode) {
            $msg = __('Select Assignment Mode', 'scoper');
            echo "{$msg}</h3></li>";
            if (OBJECT_SCOPE_RS == $scope) {
                $src = $scoper->data_sources->get($src_or_tx_name);
                $date_col_defined = !empty($src->cols->date);
            } elseif (TERM_SCOPE_RS == $scope) {
                $tx = $scoper->taxonomies->get($src_or_tx_name);
                $date_col_defined = $scoper->data_sources->member_property($tx->object_source, 'cols', 'date');
            } else {
                $date_col_defined = true;
            }
            $duration_limits_enabled = $date_col_defined && scoper_get_option('role_duration_limits');
            $content_date_limits_enabled = OBJECT_SCOPE_RS != $scope && $date_col_defined && scoper_get_option('role_content_date_limits');
            $num = $duration_limits_enabled || $content_date_limits_enabled ? 5 : 4;
        } else {
            $msg = __('Select Restriction Mode', 'scoper');
            echo "{$msg}</h3></li>";
            $num = 3;
            $duration_limits_enabled = $content_date_limits_enabled = false;
        }
        echo "<li style='float:right;'><h3>{$num}.&nbsp;";
        _e('Review and Submit', 'scoper');
        echo '</h3></li>';
        echo '</ul>';
        ?>


	<ul class="rs-list_horiz">
	
	<?php 
        if (ROLE_RESTRICTION_RS == $mode) {
            echo '<li>';
            echo '<select id="max_scope" name="max_scope">';
            $retain_value = isset($_POST["max_scope"]) ? $_POST["max_scope"] : '';
            foreach ($max_scopes as $max_scope => $caption) {
                $selected = $status_id === $retain_value ? 'selected="selected"' : '';
                echo "<option value='{$max_scope}' {$selected}>{$caption}</option>";
            }
            echo '</select></li>';
        }
        ?>

	
	<li style="margin-left:0.5em">
	<?php 
        $for_name = ROLE_ASSIGNMENT_RS == $mode ? 'assign_for' : 'require_for';
        echo "<select id='{$for_name}' name='{$for_name}'>";
        $retain_value = isset($_POST[$for_name]) ? $_POST[$for_name] : 0;
        foreach ($assignment_modes as $status_id => $caption) {
            $selected = $status_id === $retain_value ? 'selected="selected"' : '';
            echo "<option value='{$status_id}' {$selected}>{$caption}</option>";
        }
        echo '</select>';
        ?>

	</li><li style='margin: 0 0.25em 0.25em 0.5em;padding-top:0.35em;'>
	
	</li>
	<li style='float:right;margin: 0 0.25em 0.25em 0.25em;'><span class="submit" style="border:none;">
	<input type="submit" name="rs_submit" class="button-primary" value="<?php 
        _e('Update &raquo;', 'scoper');
        ?>
" />
	</span></li>
	</ul>
	<p style="clear:both"></p>
	<?php 
        if (ROLE_ASSIGNMENT_RS == $mode) {
            echo '<br /><h3>2.&nbsp;';
            //printf( _ x('Select %s to Modify', 'Users or Groups', 'scoper'), $agent_caption_plural );
            printf(__('Select %s to Modify', 'scoper'), $agent_caption_plural);
            echo '</h3>';
            $args = array('suppress_extra_prefix' => true, 'filter_threshold' => 20, 'default_hide_threshold' => 20, 'check_for_incomplete_submission' => true);
            require_once dirname(__FILE__) . '/agents_checklist_rs.php';
            ScoperAgentsChecklist::all_agents_checklist($role_bases, $agents, $args);
            echo '<p style="clear:both"></p>';
            echo '<hr />';
        }
        //=================== end users/groups and assignment mode selection display ====================
        if ($duration_limits_enabled || $content_date_limits_enabled) {
            echo '<br /><h3 style="margin-bottom: 0">3.&nbsp;';
            _e('Set Role Duration and/or Content Date Limits (optional)', 'scoper');
            echo '</h3>';
            ScoperAdminBulkLib::display_date_limit_inputs($duration_limits_enabled, $content_date_limits_enabled);
        }
        if (ROLE_ASSIGNMENT_RS == $mode) {
            $num = $duration_limits_enabled || $content_date_limits_enabled ? 4 : 3;
            echo "<br /><h3>{$num}.&nbsp;";
            $msg = __('Select Roles to Assign / Remove', 'scoper');
            echo "{$msg}</h3>";
        } else {
            $num = 2;
            echo "<br /><h3>{$num}.&nbsp;";
            $msg = __('Select Roles to Modify', 'scoper');
            echo "{$msg}</h3>";
        }
    }
Пример #2
0
<li style='float:right;margin: 0 0.25em 0.25em 0.25em;'><span class="submit" style="border:none;">
<input type="submit" name="rs_submit" class="button-primary" value="<?php 
_e('Update &raquo;', 'scoper');
?>
" />
</span></li>
</ul>
<p style="clear:both"></p>
<?php 
echo '<br /><h3>2.&nbsp;';
//printf( _ x('Select %s to Modify', 'Users or Groups', 'scoper'), $agent_caption_plural );
printf(__('Select %s to Modify', 'scoper'), $agent_caption_plural);
echo '</h3>';
$args = array('suppress_extra_prefix' => true, 'filter_threshold' => 20, 'default_hide_threshold' => 20, 'check_for_incomplete_submission' => true);
require_once dirname(__FILE__) . '/agents_checklist_rs.php';
ScoperAgentsChecklist::all_agents_checklist($role_bases, $agents, $args);
echo '<p style="clear:both"></p>';
//=================== end users/groups selection display ====================
echo '<hr /><br />';
if ($duration_limits_enabled || $content_date_limits_enabled) {
    echo '<h3 style="margin-bottom: 0">3.&nbsp;';
    _e('Set Role Duration and/or Content Date Limits (optional)', 'scoper');
    echo '</h3>';
    ScoperAdminBulkLib::display_date_limit_inputs($duration_limits_enabled, $content_date_limits_enabled);
    echo '<br /><h3>4.&nbsp;';
} else {
    echo '<br /><h3>3.&nbsp;';
}
_e('Select Roles to Assign / Remove', 'scoper');
echo '</h3>';
echo "<a href='javascript:void(0);' onclick=\"agp_check_by_name('roles[]', true, false, true);\">";
 function group_members_checklist($group_id, $user_class = 'member', $all_users = '')
 {
     global $scoper;
     if (!$all_users) {
         $all_users = $scoper->users_who_can('', COLS_ID_NAME_RS);
     }
     if ($group_id) {
         $group = ScoperAdminLib::get_group($group_id);
     }
     if ('member' == $user_class) {
         $current_ids = $group_id ? array_flip(ScoperAdminLib::get_group_members($group_id, COL_ID_RS)) : array();
         if (!empty($group) && in_array($group->meta_id, array('rv_pending_rev_notice_ed_nr_', 'rv_scheduled_rev_notice_ed_nr_'))) {
             $args = array('any_object' => true);
             $eligible_ids = array();
             foreach (get_post_types(array('public' => true), 'object') as $_type => $_type_obj) {
                 $args['object_type'] = $_type;
                 $type_eligible_ids = $scoper->users_who_can(array($_type_obj->cap->edit_published_posts, $_type_obj->cap->edit_others_posts), COL_ID_RS, 'post', 0, $args);
                 $eligible_ids = array_merge($eligible_ids, $type_eligible_ids);
             }
             $eligible_ids = array_unique($eligible_ids);
         } else {
             // force_all_users arg is a temporary measure to ensure that any user can be viewed / added to a sitewide MU group regardless of what blog backend it's edited through
             $_args = IS_MU_RS && scoper_get_option('mu_sitewide_groups', true) ? array('force_all_users' => true) : array();
             $eligible_ids = $scoper->users_who_can('', COL_ID_RS, '', '', $_args);
         }
         $admin_ids = array();
     } else {
         $group_role_defs = 'moderator' == $user_class ? array('rs_group_moderator') : array('rs_group_manager');
         if ($group_id) {
             require_once dirname(__FILE__) . '/role_assignment_lib_rs.php';
             $current_roles = ScoperRoleAssignments::organize_assigned_roles(OBJECT_SCOPE_RS, 'group', $group_id, $group_role_defs, ROLE_BASIS_USER);
             $current_roles = agp_array_flatten($current_roles, false);
             $current_ids = isset($current_roles['assigned']) ? $current_roles['assigned'] : array();
         } else {
             $current_ids = array();
         }
         $cap_name = defined('SCOPER_USER_ADMIN_CAP') ? constant('SCOPER_USER_ADMIN_CAP') : 'edit_users';
         $admin_ids = $scoper->users_who_can($cap_name, COL_ID_RS);
         // optionally, limit available group managers according to role_admin_blogwide_editor_only option
         if ('manager' == $user_class) {
             $require_blogwide_editor = false;
             if (!empty($group)) {
                 if (!strpos($group->meta_id, '_nr_')) {
                     // don't limit manager selection for groups that don't have role assignments
                     $require_blogwide_editor = scoper_get_option('role_admin_blogwide_editor_only');
                 }
             }
             if ('admin' == $require_blogwide_editor) {
                 $eligible_ids = $admin_ids;
             } elseif ('admin_content' == $require_blogwide_editor) {
                 $cap_name = defined('SCOPER_CONTENT_ADMIN_CAP') ? constant('SCOPER_CONTENT_ADMIN_CAP') : 'activate_plugins';
                 $eligible_ids = array_unique(array_merge($admin_ids, $scoper->users_who_can($cap_name, COL_ID_RS)));
             } elseif ($require_blogwide_editor) {
                 $post_editors = $scoper->users_who_can('edit_others_posts', COL_ID_RS);
                 $page_editors = $scoper->users_who_can('edit_others_pages', COL_ID_RS);
                 $eligible_ids = array_unique(array_merge($post_editors, $page_editors, $admin_ids));
             } else {
                 $eligible_ids = '';
             }
         } else {
             $eligible_ids = '';
         }
     }
     // endif user class is not "member"
     $css_id = $user_class;
     $args = array('eligible_ids' => $eligible_ids, 'via_other_scope_ids' => $admin_ids, 'suppress_extra_prefix' => true);
     require_once dirname(__FILE__) . '/agents_checklist_rs.php';
     ScoperAgentsChecklist::agents_checklist(ROLE_BASIS_USER, $all_users, $css_id, $current_ids, $args);
 }
 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' />";
 }
        $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);
    $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);
    ?>
	</div>
	<span class="submit" style="border:none;">
	<input type="submit" name="rs_submit" value="<?php 
    _e('Update &raquo;', 'scoper');
    ?>
" />
	</span>
	<?php 
} else {
    _e('No groups defined.', 'scoper');
}
?>
	
<a name="scoper_notes"></a>
 function _agents_checklist_display($agents_subset, $role_basis, $all_agents, $id_prefix, $stored_assignments, $args, &$key, &$action_links)
 {
     $defaults = array('eligible_ids' => '', 'locked_ids' => '', 'suppress_extra_prefix' => false, 'check_for_incomplete_submission' => false, 'checkall_threshold' => 6, 'filter_threshold' => 10, 'default_hide_threshold' => 20, 'caption_length_limit' => 20, 'emsize_threshold' => 4, 'objtype_display_name' => '', 'objtype_display_name_plural' => '', 'propagation' => false, 'for_children_ids' => '', 'for_entity_ids' => '', 'via_other_scope_ids' => '', 'via_other_scope_prefix' => '/', 'via_other_scope_suffix' => '/', 'via_other_role_ids' => '', 'via_other_role_prefix' => '(', 'via_other_role_suffix' => ')', 'via_other_basis_ids' => '', 'via_other_basis_prefix' => "|", 'via_other_basis_suffix' => '|', 'inherited_prefix' => '{', 'inherited_suffix' => '}', 'suppress_last_agents' => false);
     $args = array_merge($defaults, (array) $args);
     extract($args);
     $ie_checkbox_style = !empty($GLOBALS['is_IE']) ? "style='height:1em'" : '';
     if (ELIGIBLE_ITEMS_RS == $agents_subset && scoper_get_option("{$role_basis}_role_assignment_csv")) {
         return ScoperAgentsChecklist::eligible_agents_input_box($role_basis, $id_prefix, $propagation);
     }
     if (is_array($eligible_ids) && empty($eligible_ids)) {
         $eligible_ids = array(-1);
     } else {
         if (!is_array($eligible_ids)) {
             $eligible_ids = array();
         } else {
             $eligible_ids = array_flip($eligible_ids);
         }
     }
     if (!is_array($stored_assignments)) {
         $stored_assignments = array();
     }
     if (!is_array($locked_ids)) {
         $locked_ids = array();
     } else {
         $locked_ids = array_flip($locked_ids);
     }
     if (!is_array($for_children_ids)) {
         $for_children_ids = array();
     } else {
         $for_children_ids = array_flip($for_children_ids);
     }
     if (is_array($for_entity_ids) && !empty($for_entity_ids)) {
         $for_entity_ids = array_flip($for_entity_ids);
     }
     if (!$via_other_scope_ids || !is_array($via_other_scope_ids)) {
         $via_other_scope_ids = array();
     } else {
         $via_other_scope_ids = array_flip($via_other_scope_ids);
     }
     if (!is_array($via_other_role_ids)) {
         $via_other_role_ids = array();
     } else {
         $via_other_role_ids = array_flip($via_other_role_ids);
     }
     if (!is_array($via_other_basis_ids)) {
         $via_other_basis_ids = array();
     } else {
         $via_other_basis_ids = array_flip($via_other_basis_ids);
     }
     if (!$suppress_extra_prefix) {
         $id_prefix .= "_{$role_basis}";
     }
     $any_inherited = $any_other_scope = $any_other_role = $any_other_basis = $any_date_limits = false;
     $agent_count = array();
     $agent_count[CURRENT_ITEMS_RS] = count($stored_assignments);
     if (empty($eligible_ids)) {
         $agent_count[ELIGIBLE_ITEMS_RS] = count($all_agents) - count($stored_assignments);
     } elseif ($eligible_ids != array(-1)) {
         foreach (array_keys($all_agents) as $_key) {
             $all_agent_ids[$all_agents[$_key]->ID] = true;
         }
         $eligible_ids = array_intersect_key($eligible_ids, $all_agent_ids);
         $agent_count[ELIGIBLE_ITEMS_RS] = count(array_diff_key($eligible_ids, $stored_assignments));
     } else {
         $agent_count[ELIGIBLE_ITEMS_RS] = 0;
     }
     $default_hide_filtered_list = $default_hide_threshold && $agent_count[$agents_subset] > $default_hide_threshold;
     $checked = $agents_subset == CURRENT_ITEMS_RS ? $checked = "checked='checked'" : '';
     // determine whether to show caption, show/hide checkbox and filter textbox
     $any_display_filtering = $agent_count[CURRENT_ITEMS_RS] > $filter_threshold || $agent_count[ELIGIBLE_ITEMS_RS] > $filter_threshold;
     if ($agent_count[$agents_subset] > $filter_threshold) {
         if (ROLE_BASIS_GROUPS == $role_basis) {
             $caption = CURRENT_ITEMS_RS == $agents_subset ? __('show current groups (%d)', 'scoper') : __('show eligible groups (%d)', 'scoper');
         } else {
             $caption = CURRENT_ITEMS_RS == $agents_subset ? __('show current users (%d)', 'scoper') : __('show eligible users (%d)', 'scoper');
         }
         $js_call = "agp_display_if('div_{$agents_subset}_{$id_prefix}', this.id);" . "agp_display_if('chk-links_{$agents_subset}_{$id_prefix}', this.id);";
         $flt_checked = !$default_hide_filtered_list ? "checked='checked'" : '';
         $ul_class = 'rs-agents-ul';
         echo "<ul class='rs-list_horiz {$ul_class}'><li>";
         // IE6 (at least) does not render label reliably without this
         echo "<input type='checkbox' name='rs-jscheck[]' value='validate_me_{$agents_subset}_{$id_prefix}' id='chk_{$agents_subset}_{$id_prefix}' {$flt_checked} onclick=\"{$js_call}\" {$ie_checkbox_style} /> ";
         echo "<strong><label for='chk_{$agents_subset}_{$id_prefix}'>";
         printf($caption, $agent_count[$agents_subset]);
         echo '</label></strong>';
         echo '</li>';
         $class = $default_hide_filtered_list ? '' : 'class="agp_js_show"';
         echo "\r\n" . "<li style='clear:both;'>&nbsp;&nbsp;<label for='flt_{$agents_subset}_{$id_prefix}' id='lbl_flt_{$id_prefix}'>";
         _e('filter:', 'scoper');
         $js_call = "agp_filter_ul('list_{$agents_subset}_{$id_prefix}', this.value, 'chk_{$agents_subset}_{$id_prefix}', 'chk-links_{$agents_subset}_{$id_prefix}');";
         echo " <input type='text' id='flt_{$agents_subset}_{$id_prefix}' size='10' onkeyup=\"{$js_call}\" />";
         echo "</label></li>";
         echo "<li {$class} style='display:none;' id='chk-links_{$agents_subset}_{$id_prefix}'>";
         $js_call = "agp_check_by_name('{$id_prefix}[]', true, true, false, 'list_{$agents_subset}_{$id_prefix}', 1);";
         echo "\r\n" . "&nbsp;&nbsp;" . "<a href='javascript:void(0)' onclick=\"{$js_call}\">";
         _e('select', 'scoper');
         echo '</a>&nbsp;&nbsp;';
         $js_call = "agp_check_by_name('{$id_prefix}[]', '', true, false, 'list_{$agents_subset}_{$id_prefix}', 1);";
         echo "\r\n" . "<a href='javascript:void(0)' onclick=\"{$js_call}\">";
         _e('unselect', 'scoper');
         echo "</a>";
         if ($propagation) {
             $js_call = "agp_check_by_name('p_{$id_prefix}[]', true, true, false, 'list_{$agents_subset}_{$id_prefix}', 1);";
             echo "\r\n" . "&nbsp;&nbsp;" . "<a href='javascript:void(0)' onclick=\"{$js_call}\">";
             _e('propagate', 'scoper');
             echo '</a>&nbsp;&nbsp;';
             $js_call = "agp_check_by_name('p_{$id_prefix}[]', '', true, false, 'list_{$agents_subset}_{$id_prefix}', 1);";
             echo "\r\n" . "<a href='javascript:void(0)' onclick=\"{$js_call}\">";
             _e('unpropagate', 'scoper');
             echo "</a>";
         }
         echo '</li></ul>';
     } else {
         $ul_class = '';
         if ($agent_count[$agents_subset]) {
             echo "<ul class='rs-list_horiz rs-agents_filter {$ul_class}'><li>";
             if (ROLE_BASIS_GROUPS == $role_basis) {
                 $caption = CURRENT_ITEMS_RS == $agents_subset ? __('current groups (%d):', 'scoper') : __('eligible groups (%d):', 'scoper');
             } else {
                 $caption = CURRENT_ITEMS_RS == $agents_subset ? __('current users (%d):', 'scoper') : __('eligible users (%d):', 'scoper');
             }
             printf("<div class='rs-agents_caption'><strong>{$caption}</strong></div>", $agent_count[$agents_subset]);
             echo '</li></ul>';
         }
     }
     $title = '';
     if ($propagation) {
         if (!$otype_label_singular) {
             $otype_label_singular = __('object', 'scoper');
         }
         if (!$otype_label) {
             $otype_label = __('objects', 'scoper');
         }
     }
     if ($any_display_filtering || $agent_count[$agents_subset] > $emsize_threshold) {
         global $wp_locale;
         $rtl = isset($wp_locale) && 'rtl' == $wp_locale->text_direction;
         // -------- determine required list item width -----------
         if ($caption_length_limit > 40) {
             $caption_length_limit = 40;
         }
         if ($caption_length_limit < 10) {
             $caption_length_limit = 10;
         }
         $longest_caption_length = 0;
         foreach ($all_agents as $agent) {
             $id = $agent->ID;
             if (is_array($for_entity_ids)) {
                 $role_assigned = isset($for_entity_ids[$id]) || isset($for_children_ids[$id]);
             } else {
                 $role_assigned = isset($stored_assignments[$id]);
             }
             switch ($agents_subset) {
                 case CURRENT_ITEMS_RS:
                     if (!$role_assigned) {
                         continue 2;
                     }
                     break;
                 default:
                     //ELIGIBLE_ITEMS_RS
                     if ($role_assigned) {
                         continue 2;
                     }
                     if ($eligible_ids && !isset($eligible_ids[$id])) {
                         continue 2;
                     }
             }
             $caption = ROLE_BASIS_GROUPS == $role_basis && $agent->meta_id ? ScoperAdminLib::get_metagroup_name($agent->meta_id) : $agent->display_name;
             if ($role_assigned && !empty($stored_assignments[$id]['inherited_from'])) {
                 $caption = $inherited_prefix . $caption . $inherited_suffix;
             } elseif (!$role_assigned && isset($via_other_basis_ids[$id])) {
                 $caption = $via_other_basis_prefix . $caption . $via_other_basis_suffix;
             } elseif (isset($via_other_role_ids[$id])) {
                 $caption = $via_other_role_prefix . $caption . $via_other_role_suffix;
             } elseif (isset($via_other_scope_ids[$id])) {
                 $caption = $via_other_scope_prefix . $caption . $via_other_scope_suffix;
             }
             if (strlen($caption) > $longest_caption_length) {
                 if (strlen($caption) >= $caption_length_limit) {
                     $longest_caption_length = $caption_length_limit + 2;
                 } else {
                     $longest_caption_length = strlen($caption);
                 }
             }
         }
         if ($longest_caption_length < 10) {
             $longest_caption_length = 10;
         }
         //if ( ! $ems_per_character = scoper_get_option('ems_per_character') )
         if (defined('UI_EMS_PER_CHARACTER')) {
             $ems_per_character = UI_EMS_PER_CHARACTER;
         } else {
             $ems_per_character = 0.85;
         }
         $list_width_ems = $ems_per_character * $longest_caption_length;
         if ($propagation) {
             $list_width_ems = $list_width_ems + 1.0;
         }
         $ems_integer = intval($list_width_ems);
         $ems_half = $list_width_ems - $ems_integer >= 0.5 ? '_5' : '';
         $ul_class = "rs-agents_list_{$ems_integer}{$ems_half}";
         $hide_class = $default_hide_filtered_list && $agent_count[$agents_subset] > $filter_threshold ? 'class="agp_js_hide"' : '';
         echo "\r\n" . "<div id='div_{$agents_subset}_{$id_prefix}' {$hide_class}>" . "<div class='rs-agents_emsized'>" . "<ul class='{$ul_class}' id='list_{$agents_subset}_{$id_prefix}'>";
     } else {
         $ul_class = "rs-agents_list_auto";
         echo "\r\n<ul class='{$ul_class}' id='list_{$agents_subset}_{$id_prefix}'>";
     }
     //-------- end list item width determination --------------
     $last_agents = array();
     $last_agents_prop = array();
     foreach ($all_agents as $agent) {
         $id = $agent->ID;
         $agent_display_name = ROLE_BASIS_GROUPS == $role_basis && $agent->meta_id ? ScoperAdminLib::get_metagroup_name($agent->meta_id) : $agent->display_name;
         if (is_array($for_entity_ids)) {
             $role_assigned = isset($for_entity_ids[$id]) || isset($for_children_ids[$id]);
         } else {
             $role_assigned = isset($stored_assignments[$id]);
         }
         switch ($agents_subset) {
             case CURRENT_ITEMS_RS:
                 if (!$role_assigned) {
                     continue 2;
                 }
                 break;
             default:
                 //ELIGIBLE_ITEMS_RS
                 if ($role_assigned) {
                     continue 2;
                 }
                 if ($eligible_ids && !isset($eligible_ids[$id])) {
                     continue 2;
                 }
         }
         // markup for role duration / content date limits
         $title = '';
         // we can't set the title because it's used by JS for onkey filtering
         $limit_class = '';
         $link_class = '';
         $limit_style = '';
         if (isset($stored_assignments[$id])) {
             ScoperAdminUI::set_agent_formatting($stored_assignments[$id], $title, $limit_class, $link_class, $limit_style);
         }
         if ($title) {
             $any_date_limits = true;
             $label_title = " title='{$title}'";
         } else {
             $label_title = '';
         }
         $disabled = $locked_ids && isset($locked_ids[$id]) ? " disabled='disabled'" : '';
         $li_title = "title=' " . agp_strtolower($agent_display_name) . " '";
         if ($check_for_incomplete_submission && isset($_POST['scoper_error']) && isset($_POST[$id_prefix])) {
             $this_checked = in_array($id, $_POST[$id_prefix]) ? ' checked="checked"' : '';
         } else {
             if ($role_assigned && (!is_array($for_entity_ids) || isset($for_entity_ids[$id]))) {
                 $this_checked = ' checked="checked"';
             } else {
                 $this_checked = '';
             }
         }
         if ($this_checked && !$suppress_last_agents) {
             $last_agents[] = $id;
         }
         if (isset($via_other_role_ids[$id])) {
             $label_class = " class='rs-via-r{$limit_class}'";
         } elseif (!$role_assigned && isset($via_other_basis_ids[$id])) {
             $label_class = " class='rs-via-b{$limit_class}'";
         } elseif (isset($via_other_scope_ids[$id])) {
             $label_class = " class='rs-via-s{$limit_class}'";
         } elseif ($limit_class) {
             $label_class = " class='" . trim($limit_class) . "'";
         } else {
             $label_class = '';
         }
         echo "\r\n<li {$li_title}>" . "<input type='checkbox' name='{$id_prefix}[]'{$disabled}{$this_checked} value='{$id}' id='{$id_prefix}{$id}' {$ie_checkbox_style} />";
         if ($propagation) {
             if ($check_for_incomplete_submission && isset($_POST['scoper_error']) && isset($_POST["p_{$id_prefix}"])) {
                 $this_checked_prop = in_array($id, $_POST["p_{$id_prefix}"]) ? ' checked="checked"' : '';
             } else {
                 if (isset($for_children_ids[$id])) {
                     $this_checked_prop = " checked='checked'";
                 } else {
                     $this_checked_prop = '';
                 }
             }
             if ($this_checked_prop && !$suppress_last_agents) {
                 $last_agents_prop[] = $id;
             }
             echo "{" . "<input type='checkbox' name='p_{$id_prefix}[]'{$disabled}{$this_checked_prop} value='{$id}' id='p_{$id_prefix}{$id}' {$ie_checkbox_style} />" . "}";
         }
         echo "<label {$title} {$limit_style} for='{$id_prefix}{$id}'{$label_class}{$label_title}>";
         $caption = $agent_display_name;
         if (strlen($caption) > $caption_length_limit) {
             if (!empty($rtl)) {
                 $caption = '...' . substr($caption, strlen($caption) - $caption_length_limit);
             } else {
                 $caption = substr($caption, 0, $caption_length_limit) . '...';
             }
         }
         if ($role_assigned && !empty($stored_assignments[$id]['inherited_from'])) {
             $caption = $inherited_prefix . $caption . $inherited_suffix;
             $any_inherited = true;
         } elseif (isset($via_other_role_ids[$id])) {
             $caption = $via_other_role_prefix . $caption . $via_other_role_suffix;
             $any_other_role = true;
         } elseif (!$role_assigned && isset($via_other_basis_ids[$id])) {
             $caption = $via_other_basis_prefix . $caption . $via_other_basis_suffix;
             $any_other_basis = true;
         } elseif (isset($via_other_scope_ids[$id])) {
             $caption = $via_other_scope_prefix . $caption . $via_other_scope_suffix;
             $any_other_scope = true;
         }
         $caption = ' ' . $caption;
         echo $caption;
         // str_replace(' ', '&nbsp;', $caption);
         echo '</label></li>';
     }
     //foreach agent
     echo "\r\n<li></li></ul>";
     // prevent invalid markup if no other li's
     if (CURRENT_ITEMS_RS == $agents_subset) {
         $last_agents = implode("~", $last_agents);
         $last_agents_prop = implode("~", $last_agents_prop);
         echo "<input type=\"hidden\" id=\"last_{$id_prefix}\" name=\"last_{$id_prefix}\" value=\"{$last_agents}\" />";
         echo "<input type=\"hidden\" id=\"last_p_{$id_prefix}\" name=\"last_p_{$id_prefix}\" value=\"{$last_agents_prop}\" />";
     }
     if ($any_display_filtering || $agent_count[$agents_subset] > $emsize_threshold) {
         echo '</div></div>';
     }
     // display key
     if ($any_inherited && $inherited_prefix) {
         $key['inherited'] = "{$inherited_prefix} {$inherited_suffix}" . '<span class="rs-keytext">' . sprintf(__('inherited from parent %s', 'scoper'), agp_strtolower($otype_label_singular)) . '</span>';
     }
     if ($any_other_role && $via_other_role_prefix) {
         $key['other_role'] = "<span class='rs-via-r'>{$via_other_role_prefix}&nbsp;{$via_other_role_suffix}" . '<span class="rs-keytext">' . str_replace(' ', '&nbsp;', __('has via other role', 'scoper')) . '</span></span>';
     }
     if ($any_other_basis && $via_other_basis_prefix) {
         $key['other_basis'] = "<span class='rs-via-b'>{$via_other_basis_prefix}&nbsp;{$via_other_basis_suffix}" . '<span class="rs-keytext">' . str_replace(' ', '&nbsp;', __('has via group', 'scoper')) . '</span></span>';
     }
     if ($any_other_scope && $via_other_scope_prefix) {
         $key['other_scope'] = "<span class='rs-via-s'>{$via_other_scope_prefix}&nbsp;{$via_other_scope_suffix}" . '<span class="rs-keytext">' . str_replace(' ', '&nbsp;', __('has via other scope', 'scoper')) . '</span></span>';
     }
     if ($propagation) {
         $key['propagation'] = "{<input type='checkbox' disabled='disabled' name='rs-prop_key_{$agents_subset}_{$id_prefix}' id='rs-prop_key_{$agents_subset}_{$id_prefix}' style='vertical-align:middle' />}" . '<span class="rs-keytext">' . sprintf(__('propagate to sub-%s', 'scoper'), agp_strtolower($otype_label)) . '</span>';
     }
     if ($any_date_limits && !empty($object_id)) {
         if (empty($GLOBALS['post']) || 'auto-draft' != $GLOBALS['post']->post_status) {
             //don't display link for auto-drafts
             $action_links['limits'] = sprintf(__('%1$sEdit date limits%2$s', 'scoper'), "<a href='admin.php?page=rs-{$object_type}-roles#item-{$object_id}'>", '</a>');
         }
     }
 }
 function draw_object_roles_content($src_name, $object_type, $role_handle, $object_id = '', $skip_user_validation = false, $object = false)
 {
     //log_mem_usage_rs( 'start ItemRolesUI::draw_object_roles_content()' );
     if (!$object_id) {
         $object_id = scoper_get_object_id($src_name, $object_type);
     }
     if (!empty($object) && 'auto-draft' == $object->post_status) {
         $object_id = 0;
     }
     if ($src_name != $this->loaded_src_name || $object_type != $this->loaded_object_type || $object_id != $this->loaded_object_id) {
         $this->load_roles($src_name, $object_type, $object_id);
     }
     if (!($otype_def = $this->scoper->data_sources->member_property($src_name, 'object_types', $object_type))) {
         return;
     }
     if (!$skip_user_validation && !$this->scoper_admin->user_can_admin_role($role_handle, $object_id, $src_name, $object_type)) {
         return;
     }
     // since we may be dumping a lot of hidden user <li> into the page, enumerate role names to shorten html
     $role_code = 'r' . array_search($role_handle, $this->role_handles);
     $role_def = $this->scoper->role_defs->get($role_handle);
     if (!isset($role_def->valid_scopes[OBJECT_SCOPE_RS])) {
         return;
     }
     if (empty($this->drew_objroles_marker)) {
         echo "<input type='hidden' name='rs_object_roles' value='true' />";
         $this->drew_objroles_marker = true;
     }
     // ========== OBJECT RESTRICTION CHECKBOX(ES) ============
     // checkbox to control object role scoping (dictates whether taxonomy and blog role assignments also be honored for operations on this object )
     $checked = empty($this->object_strict_roles[$role_handle]) ? '' : 'checked="checked"';
     $val = $checked ? '1' : '0';
     echo "<input type='hidden' name='last_objscope_{$role_code}' value='{$val}' id='last_objscope_{$role_code}' />";
     echo "\r\n<p style='margin-bottom:0.8em;'>" . "<span class='alignright'><a href='#wphead'>" . __('top', 'scoper') . '</a></span>' . "<label for='objscope_{$role_code}'>" . "<input type='checkbox' class='rs-check' name='objscope_{$role_code}' value='1' id='objscope_{$role_code}' {$checked} /> " . sprintf(__('Restrict for %1$s (<strong>only</strong> selected users/groups are %2$s)', 'scoper'), $otype_def->labels->singular_name, $this->scoper->role_defs->get_abbrev($role_handle, OBJECT_UI_RS)) . '</label></p>';
     if ($this->do_propagation_cboxes) {
         $checked = empty($this->child_strict_roles[$role_handle]) ? '' : 'checked="checked"';
         $val = $checked ? '1' : '0';
         echo "<input type='hidden' name='last_objscope_children_{$role_code}' value='{$val}' id='last_objscope_children_{$role_code}' />";
         echo "<p style='margin-top: 0.5em;'>" . "<label for='objscope_children_{$role_code}'>" . "<input type='checkbox' class='rs-check' name='objscope_children_{$role_code}' value='1' id='objscope_children_{$role_code}' {$checked} /> " . sprintf(__('Restrict for Sub-%1$s', 'scoper'), $otype_def->labels->name) . '</label></p>';
     }
     // ========== OBJECT ROLE ASSIGNMENT CHECKBOX(ES) ============
     // toggle groups / users view if both are enabled
     //echo "<p style='margin: 1em 0 0.2em 0;'><strong>" . sprintf(__('Assign %s Role:', 'scoper'), $display_name ) . '</strong></p>';
     //echo '<br />';
     $toggle_agents = USER_ROLES_RS && GROUP_ROLES_RS && !empty($this->all_groups);
     if ($toggle_agents) {
         if (!empty($this->current_roles[ROLE_BASIS_USER][$role_handle])) {
             $default_role_basis = ROLE_BASIS_USER;
         } else {
             $default_role_basis = ROLE_BASIS_GROUPS;
         }
         $class_selected = 'agp-selected_agent_colorized agp-selected_agent agp-agent';
         $class_unselected = 'agp-unselected_agent_colorized agp-unselected_agent agp-agent';
         $class = ROLE_BASIS_GROUPS == $default_role_basis ? "class='{$class_selected}'" : "class='{$class_unselected}'";
         $js_call = "agp_swap_display('{$role_code}_groups', '{$role_code}_user', '{$role_code}_show_group_roles', '{$role_code}_show_user_roles', '{$class_selected}', '{$class_unselected}')";
         $bottom_margin = !empty($GLOBALS['is_IE']) ? '-0.7em' : 0;
         echo "\r\n" . "<div class='agp_js_show' style='display:none;margin:0 0 {$bottom_margin} 0'>" . "<ul class='rs-list_horiz' style='margin-bottom:-0.1em'><li {$class}>" . "<a href='javascript:void(0)' id='{$role_code}_show_group_roles' onclick=\"{$js_call}\">" . __('Groups', 'scoper') . '</a></li>';
         $class = ROLE_BASIS_USER == $default_role_basis ? "class='{$class_selected}'" : "class='{$class_unselected}'";
         $js_call = "agp_swap_display('{$role_code}_user', '{$role_code}_groups', '{$role_code}_show_user_roles', '{$role_code}_show_group_roles', '{$class_selected}', '{$class_unselected}')";
         echo "\r\n" . "<li {$class}><a href='javascript:void(0)' id='{$role_code}_show_user_roles' onclick=\"{$js_call}\">" . __awp('Users') . '</a></li>' . '</ul></div>';
     }
     $class = "class='rs-agents'";
     //need effective line break here if not IE
     echo "<div style='clear:both;margin:0 0 0.3em 0' {$class}>";
     $role_ops = $this->scoper->cap_defs->get_cap_ops($this->scoper->role_defs->role_caps[$role_handle]);
     $agents_reqd_op = isset($role_ops[OP_EDIT_RS]) ? OP_EDIT_RS : OP_READ_RS;
     $containing_roles = $this->scoper->role_defs->get_containing_roles($role_handle);
     require_once dirname(__FILE__) . '/agents_checklist_rs.php';
     $args = array('suppress_extra_prefix' => true, 'default_hide_threshold' => 20, 'propagation' => $this->do_propagation_cboxes, 'otype_label_singular' => $otype_def->labels->singular_name, 'otype_label' => $otype_def->labels->name, 'object_type' => $object_type, 'object_id' => $object_id);
     $args['via_other_role_ids'] = array();
     // must set this here b/c subsequent for loop is set up for users iteration to recall via_other_role_ids from groups iteration
     foreach ($this->agent_captions as $role_basis => $agent_caption) {
         if (!is_array($this->blog_term_roles[$role_basis][$role_handle])) {
             $this->blog_term_roles[$role_basis][$role_handle] = array();
         }
         // for the purpose of indicating implicit role ownership, we will consider any assignment of a containing role as equivalent
         foreach (array_keys($containing_roles) as $containing_role_handle) {
             if (isset($this->blog_term_roles[$role_basis][$containing_role_handle]) && is_array($this->blog_term_roles[$role_basis][$containing_role_handle])) {
                 $this->blog_term_roles[$role_basis][$role_handle] = array_merge($this->blog_term_roles[$role_basis][$role_handle], $this->blog_term_roles[$role_basis][$containing_role_handle]);
             }
         }
         $this->blog_term_roles[$role_basis][$role_handle] = array_unique($this->blog_term_roles[$role_basis][$role_handle]);
         $hide_class = $toggle_agents && $role_basis != $default_role_basis ? ' class="agp_js_hide"' : '';
         echo "\r\n<div id='{$role_code}_{$role_basis}' {$hide_class}>";
         // also abbreviate "groups" to 'g', 'user' to 'u'
         $id_prefix = $role_code . substr($role_basis, 0, 1);
         if ($this->indicate_blended_roles && $object_id && GROUP_ROLES_RS && ROLE_BASIS_USER == $role_basis) {
             $args['via_other_basis_ids'] = array();
             // note users who are in a group that has this role object-assigned
             if (!empty($this->current_roles[ROLE_BASIS_GROUPS][$role_handle]['assigned'])) {
                 foreach (array_keys($this->current_roles[ROLE_BASIS_GROUPS][$role_handle]['assigned']) as $group_id) {
                     if (!isset($this->group_members[$group_id])) {
                         $this->group_members[$group_id] = ScoperAdminLib::get_group_members($group_id, COL_ID_RS, true);
                     }
                     //arg: maybe WP role metagroup
                     $args['via_other_basis_ids'] = array_merge($args['via_other_basis_ids'], $this->group_members[$group_id]);
                 }
             }
             // note users who are in a group that has this role term-assigned or blog-assigned (and not restricted)
             foreach ($this->blog_term_roles[ROLE_BASIS_GROUPS][$role_handle] as $group_id) {
                 if (!isset($this->group_members[$group_id])) {
                     $this->group_members[$group_id] = ScoperAdminLib::get_group_members($group_id, COL_ID_RS, true);
                 }
                 //arg: maybe WP role metagroup
                 $args['via_other_basis_ids'] = array_merge($args['via_other_basis_ids'], $this->group_members[$group_id]);
             }
             // note users who are in a group that has a containing role object-assigned
             // (note: via_other_role_ids element was set in previous iteration since ROLE_BASIS_GROUPS is first element in agents_caption array
             foreach ($args['via_other_role_ids'] as $group_id) {
                 if (!isset($this->group_members[$group_id])) {
                     $this->group_members[$group_id] = ScoperAdminLib::get_group_members($group_id, COL_ID_RS, true);
                 }
                 //arg: maybe WP role metagroup
                 $args['via_other_basis_ids'] = array_merge($args['via_other_basis_ids'], $this->group_members[$group_id]);
             }
             $args['via_other_basis_ids'] = array_unique($args['via_other_basis_ids']);
         }
         if ($this->indicate_blended_roles) {
             $args['via_other_scope_ids'] = $this->blog_term_roles[$role_basis][$role_handle];
         }
         $args['via_other_role_ids'] = array();
         if ($this->indicate_blended_roles && $containing_roles) {
             foreach (array_keys($containing_roles) as $containing_role_handle) {
                 if (isset($this->current_roles[$role_basis][$containing_role_handle]['assigned'])) {
                     $args['via_other_role_ids'] = array_merge($args['via_other_role_ids'], array_keys($this->current_roles[$role_basis][$containing_role_handle]['assigned']));
                 }
             }
             $args['via_other_role_ids'] = array_unique($args['via_other_role_ids']);
         }
         if ($object_id && $this->do_propagation_cboxes) {
             $args['for_entity_ids'] = isset($this->current_roles[$role_basis][$role_handle]['entity']) ? array_keys($this->current_roles[$role_basis][$role_handle]['entity']) : array();
             $args['for_children_ids'] = isset($this->current_roles[$role_basis][$role_handle]['children']) ? array_keys($this->current_roles[$role_basis][$role_handle]['children']) : '';
         }
         $args['eligible_ids'] = isset($this->eligible_agent_ids[$role_basis][$agents_reqd_op]) ? $this->eligible_agent_ids[$role_basis][$agents_reqd_op] : '';
         if ('post' == $src_name && 'auto-draft' == $object->post_status) {
             $args['suppress_last_agents'] = true;
         }
         if (!empty($this->current_roles[$role_basis][$role_handle]['assigned'])) {
             ScoperAgentsChecklist::agents_checklist($role_basis, $this->all_agents[$role_basis], $id_prefix, $this->current_roles[$role_basis][$role_handle]['assigned'], $args);
         } else {
             ScoperAgentsChecklist::agents_checklist($role_basis, $this->all_agents[$role_basis], $id_prefix, '', $args);
         }
         echo "\r\n</div>";
     }
     // end foreach role basis caption (user or group)
     echo '</div>';
     // class rs-agents
     //log_mem_usage_rs( 'end ItemRolesUI::draw_object_roles_content()' );
 }