--- loncom/interface/loncreateuser.pm 2002/04/23 21:05:45 1.33
+++ loncom/interface/loncreateuser.pm 2009/03/18 15:27:13 1.268.2.7
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.33 2002/04/23 21:05:45 matthew Exp $
+# $Id: loncreateuser.pm,v 1.268.2.7 2009/03/18 15:27:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,110 +25,426 @@
#
# http://www.lon-capa.org/
#
-# (Create a course
-# (My Desk
-#
-# (Internal Server Error Handler
-#
-# (Login Screen
-# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
-# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
-#
-# YEAR=2001
-# 3/1/1 Gerd Kortemeyer)
-#
-# 3/1 Gerd Kortemeyer)
-#
-# 2/14 Gerd Kortemeyer)
-#
-# 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer
-# April Guy Albertelli
-# 05/10,10/16 Gerd Kortemeyer
-# 11/12,11/13,11/15 Scott Harrison
-# 02/11/02 Matthew Hall
-#
-# $Id: loncreateuser.pm,v 1.33 2002/04/23 21:05:45 matthew Exp $
###
package Apache::loncreateuser;
+=pod
+
+=head1 NAME
+
+Apache::loncreateuser.pm
+
+=head1 SYNOPSIS
+
+ Handler to create users and custom roles
+
+ Provides an Apache handler for creating users,
+ editing their login parameters, roles, and removing roles, and
+ also creating and assigning custom roles.
+
+=head1 OVERVIEW
+
+=head2 Custom Roles
+
+In LON-CAPA, roles are actually collections of privileges. "Teaching
+Assistant", "Course Coordinator", and other such roles are really just
+collection of privileges that are useful in many circumstances.
+
+Creating custom roles can be done by the Domain Coordinator through
+the Create User functionality. That screen will show all privileges
+that can be assigned to users. For a complete list of privileges,
+please see C.
+
+Custom role definitions are stored in the C'.$lt{'usrt'}.'
'."\n".
+ &Apache::loncommon::start_data_table();
+
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'tools.aboutme','tools.portfolio','tools.blog');
+ my @usertools = ('aboutme','blog','portfolio');
+ foreach my $item (@usertools) {
+ my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off);
+ $cust_off = 'checked="checked" ';
+ $tool_on = 'checked="checked" ';
+ $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item);
+ if ($userenv{'tools.'.$item} eq '') {
+ $custom_access = 'default';
+ if (!$curr_access) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ } else {
+ $custom_access = 'custom';
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ if ($userenv{'tools.'.$item} == 0) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ }
+ $output .= ' '."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{$item}.' '."\n".
+ ' '.&mt('Availability determined currently from [_1] setting.',$custom_access).
+ ' '.$lt{'avai'}.': '.
+ ($curr_access?&mt('Yes'):&mt('No')).' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chse'}.': '.
+ ' -- '.
+ $lt{'cusa'}.': '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ }
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ $output .= ''."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'disk'}.' '."\n".
+ ' '.$lt{'cuqu'}.': '.
+ $currquota.' Mb. '.
+ $defaultinfo.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' Mb '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ return $output;
+}
+
# =================================================================== Phase one
-sub phase_one {
- my $r=shift;
- my $defdom=$ENV{'user.domain'};
- my @domains = &Apache::loncommon::get_domains();
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- $r->print(<<"ENDDOCUMENT");
-
-
-Create User, Change User Privileges
-
-
-
-ENDDOCUMENT
+ENDCUSTOM
+ }
+ } else {
+ my $actiontext = $lt{'srad'};
+ if ($env{'form.action'} eq 'singlestudent') {
+ $actiontext = $lt{'srst'};
+ }
+ $r->print("
+$actiontext
");
+ if ($env{'form.origform'} ne 'crtusername') {
+ $r->print("\n".$response);
+ }
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
+ }
+ $r->print(&Apache::loncommon::end_page());
}
-# =================================================================== Phase two
-sub phase_two {
- my $r=shift;
- my $ccuname=$ENV{'form.ccuname'};
- my $ccdomain=$ENV{'form.ccdomain'};
-
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
-
- my $defdom=$ENV{'user.domain'};
+sub entry_form {
+ my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my ($usertype,$inexact);
+ if (ref($srch) eq 'HASH') {
+ if (($srch->{'srchin'} eq 'dom') &&
+ ($srch->{'srchby'} eq 'uname') &&
+ ($srch->{'srchtype'} eq 'exact') &&
+ ($srch->{'srchdomain'} ne '') &&
+ ($srch->{'srchterm'} ne '')) {
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
+ $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+ } else {
+ $inexact = 1;
+ }
+ }
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser',$cancreate,$usertype);
+ my $srchbutton = &mt('Search');
+ if ($env{'form.action'} eq 'singlestudent') {
+ $srchbutton = &mt('Search and Enroll');
+ } elsif ($cancreate && $responsemsg ne '' && $inexact) {
+ $srchbutton = &mt('Search or Add New User');
+ }
+ my $output = <<"ENDBLOCK";
+
+ENDBLOCK
+ if ($env{'form.phase'} eq '') {
+ my $defdom=$env{'request.role.domain'};
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+ my %lt=&Apache::lonlocal::texthash(
+ 'enro' => 'Enroll one student',
+ 'admo' => 'Add/modify a single user',
+ 'crea' => 'create new user if required',
+ 'uskn' => "username is known",
+ 'crnu' => 'Create a new user',
+ 'usr' => 'Username',
+ 'dom' => 'in domain',
+ 'enrl' => 'Enroll',
+ 'cram' => 'Create/Modify user',
+ );
+ my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
+ my ($title,$buttontext,$showresponse);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $title = $lt{'enro'};
+ $buttontext = $lt{'enrl'};
+ } else {
+ $title = $lt{'admo'};
+ $buttontext = $lt{'cram'};
+ }
+ if ($cancreate) {
+ $title .= ' ('.$lt{'crea'}.')';
+ } else {
+ $title .= ' ('.$lt{'uskn'}.')';
+ }
+ if ($env{'form.origform'} eq 'crtusername') {
+ $showresponse = $responsemsg;
+ }
+ $output .= <<"ENDDOCUMENT";
+
+
+ENDDOCUMENT
+ }
+ return $output;
+}
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
- my $dochead =<<"ENDDOCHEAD";
-
-
-
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
+ $r->print(''.$lt{'usel'}.'
');
+ } elsif ($env{'form.action'} eq 'singlestudent') {
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+ 'Course_Add_Student'));
+ $r->print($jscript."$lt{'stusrch'}
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
+ $r->print(''.$lt{'stusel'}.'
');
+ }
+ $r->print(''.&Apache::loncommon::end_page());
+}
+
+sub print_user_query_page {
+ my ($r,$caller) = @_;
+# FIXME - this is for a network-wide name search (similar to catalog search)
+# To use frames with similar behavior to catalog/portfolio search.
+# To be implemented.
+ return;
+}
+
+sub print_user_modification_page {
+ my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_;
+ if (($ccuname eq '') || ($ccdomain eq '')) {
+ my $usermsg = &mt('No username and/or domain provided.');
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$usermsg);
+ return;
+ }
+ my ($form,$formname);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $form = 'document.enrollstudent';
+ $formname = 'enrollstudent';
+ } else {
+ $form = 'document.cu';
+ $formname = 'cu';
+ }
+ my %abv_auth = &auth_abbrev();
+ my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
+ my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+ if ($uhome eq 'no_host') {
+ my $usertype;
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($ccdomain,'username');
+ $usertype =
+ &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($ccdomain,$context,
+ $usertype);
+ if (!$cancreate) {
+ my $helplink = ' href="javascript:helpMenu('."'display'".')"';
+ my %usertypetext = (
+ official => 'institutional',
+ unofficial => 'non-institutional',
+ );
+ my $response;
+ if ($env{'form.origform'} eq 'crtusername') {
+ $response = ''.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
+ '
';
+ }
+ $response .= ''.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the helpdesk for assistance.',$helplink).'
';
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$response);
+ return;
+ }
+ $newuser = 1;
+ my $checkhash;
+ my $checks = { 'username' => 1 };
+ $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
+ if (ref($alerts{'username'}) eq 'HASH') {
+ if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
+ my $domdesc =
+ &Apache::lonnet::domain($ccdomain,'description');
+ if ($alerts{'username'}{$ccdomain}{$ccuname}) {
+ my $userchkmsg;
+ if (ref($curr_rules{$ccdomain}) eq 'HASH') {
+ $userchkmsg =
+ &Apache::loncommon::instrule_disallow_msg('username',
+ $domdesc,1).
+ &Apache::loncommon::user_rule_formats($ccdomain,
+ $domdesc,$curr_rules{$ccdomain}{'username'},
+ 'username');
+ }
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$userchkmsg);
+ return;
+ }
+ }
+ }
+ } else {
+ $newuser = 0;
+ }
+ if ($response) {
+ $response = '
'.$response;
+ }
+
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ my %loaditem;
+
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
+
+ my $js = &validation_javascript($context,$ccdomain,$pjump_def,
+ $groupslist,$newuser,$formname,\%loaditem);
+ my $args = {'add_entries' => \%loaditem};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ }
+ my $start_page =
+ &Apache::loncommon::start_page('User Management',$js,$args);
+ my %breadcrumb_text = &singleuser_breadcrumb();
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage($form)",
+ text=>$breadcrumb_text{'search'},
+ faq=>282,bug=>'Instructor Interface',});
+
+ if ($env{'form.phase'} eq 'userpicked') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage($form,'get_user_info','select')",
+ text=>$breadcrumb_text{'userpicked'},
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
+ text=>$breadcrumb_text{'modify'},
+ faq=>282,bug=>'Instructor Interface',});
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+ $helpitem);
+
my $forminfo =<<"ENDFORMINFO";
-
$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDNEWUSER +first name | middle name | last name | generation | -
---|---|---|---|
-END - } else { - $r->print(' | '.$userenv{$_}.' | '); - } + if ($env{'form.action'} eq 'singlestudent') { + $r->print($lt{'ens'}); + } else { + $r->print($lt{'cup'}); } - $r->print(<
Revoke | Role | Extent | '. - 'Start | End | '); - foreach my $area (keys(%rolesdump)) { - if ($area!~/^rolesdef/) { - my $role = $rolesdump{$area}; - my $thisrole=$area; - $area=~s/\_\w\w$//; - my ($role_code,$role_end_time,$role_start_time) = - split(/_/,$role); - my $bgcol='ffffff'; - my $allows=0; - if ($area=~/^\/(\w+)\/(\d\w+)/) { - my %coursedata= - &Apache::lonnet::coursedescription($1.'_'.$2); - my $carea='Course: '.$coursedata{'description'}; - $inccourses{$1.'_'.$2}=1; - if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) { - $allows=1; - } - # Compute the background color based on $area - $bgcol=$1.'_'.$2; - $bgcol=~s/[^8-9b-e]//g; - $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); - if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { - $carea.='
---|---|---|---|---|
'); - my $active=1; - $active=0 if (($role_end_time) && ($now>$role_end_time)); - if (($active) && ($allows)) { - $r->print(''); - } else { - $r->print(' '); - } - $r->print(' | '. - &Apache::lonnet::plaintext($role_code). - ' | '.$area.' | '. - ($role_start_time ? localtime($role_start_time) - : ' ' ) - .' | '. - ($role_end_time ? localtime($role_end_time) - : ' ' ) - ." |
$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDBADAUTH - } else { - # This user is not allowed to modify the users - # authentication scheme, so just notify them of the problem - $r->print(<$authformint
\n". - "$authformfsys
$authformloc
"; - } - elsif ($currentauth=~/^internal:/) { - $authformcurrent=$authformint; - $authform_other="$authformkrb
". - "$authformfsys
$authformloc
"; - } - elsif ($currentauth=~/^unix:/) { - $authformcurrent=$authformfsys; - $authform_other="$authformkrb
". - "$authformint
$authformloc;
"; - } - elsif ($currentauth=~/^localauth:/) { - $authformcurrent=$authformloc; - $authform_other="$authformkrb
". - "$authformint
$authformfsys
"; - } - $authformcurrent=<$generalrule
-$authformnop
-$authformcurrent
-Activate | Role | Extent | -Start | End | ||||||
---|---|---|---|---|---|---|---|---|---|---|
- | Co-Author | -$cudom\_$cuname | -
+ if ($env{'form.action'} eq 'singlestudent') {
+ $r->print(' '."\n"); + } else { + $r->print(' '.&mt('Add Roles').''); + my $addrolesdisplay = 0; + if ($context eq 'domain' || $context eq 'author') { + $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain); + } + if ($context eq 'domain') { + my $add_domainroles = &new_domain_roles($r); + if (!$addrolesdisplay) { + $addrolesdisplay = $add_domainroles; + } + $r->print(&course_level_dc($env{'request.role.domain'},'Course')); + $r->print(''."\n"); + } elsif ($context eq 'author') { + if ($addrolesdisplay) { + $r->print(' print(' onClick="auth_check()" \>'."\n"); + } else { + $r->print('onClick="this.form.submit()" \>'."\n"); + } + } else { + $r->print(' '. + &mt('Back to previous page').''); + } + } else { + $r->print(&course_level_table(%inccourses)); + $r->print(' '."\n"); + } + } + $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain'])); + $r->print(''); + $r->print(''); + $r->print("".&Apache::loncommon::end_page()); + return; +} + +sub singleuser_breadcrumb { + my %breadcrumb_text; + if ($env{'form.action'} eq 'singlestudent') { + $breadcrumb_text{'search'} = 'Enroll a student'; + $breadcrumb_text{'userpicked'} = 'Select a user', + $breadcrumb_text{'modify'} = 'Set section/dates', + } else { + $breadcrumb_text{'search'} = 'Create/modify a user'; + $breadcrumb_text{'userpicked'} = 'Select a user', + $breadcrumb_text{'modify'} = 'Set user role', + } + return %breadcrumb_text; +} + +sub date_sections_select { + my ($context,$newuser,$formname,$permission) = @_; + my $cid = $env{'request.course.id'}; + my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid); + my $date_table = ' '.&mt('Starting and Ending Dates').''."\n". + &Apache::lonuserutils::date_setting_table(undef,undef,$context, + undef,$formname,$permission); + my $rowtitle = 'Section'; + my $secbox = ''.&mt('Section').''."\n". + &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle, + $permission); + my $output = $date_table.$secbox; + return $output; +} + +sub validation_javascript { + my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname, + $loaditem) = @_; + my $dc_setcourse_code = ''; + my $nondc_setsection_code = ''; + if ($context eq 'domain') { + my $dcdom = $env{'request.role.domain'}; + $loaditem->{'onload'} = "document.cu.coursedesc.value='';"; + $dc_setcourse_code = + &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context); + } else { + my $checkauth; + if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) { + $checkauth = 1; + } + if ($context eq 'course') { + $nondc_setsection_code = + &Apache::lonuserutils::setsections_javascript($formname,$groupslist, + undef,$checkauth); + } + if ($checkauth) { + $nondc_setsection_code .= + &Apache::lonuserutils::verify_authen($formname,$context); + } + } + my $js = &user_modification_js($pjump_def,$dc_setcourse_code, + $nondc_setsection_code,$groupslist); + my ($jsback,$elements) = &crumb_utilities(); + $js .= "\n". + ''; + return $js; +} + +sub display_existing_roles { + my ($r,$ccuname,$ccdomain,$inccourses) = @_; + my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname); + # Build up table of user roles to allow revocation and re-enabling of roles. + my ($tmp) = keys(%rolesdump); + if ($tmp !~ /^(con_lost|error)/i) { + my $now=time; + my %lt=&Apache::lonlocal::texthash( + 'rer' => "Existing Roles", + 'rev' => "Revoke", + 'del' => "Delete", + 'ren' => "Re-Enable", + 'rol' => "Role", + 'ext' => "Extent", + 'sta' => "Start", + 'end' => "End", + ); + my (%roletext,%sortrole,%roleclass,%rolepriv); + foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]); + my $b1=join('_',(split('_',$b))[1,0]); + return $a1 cmp $b1; + } keys(%rolesdump)) { + next if ($area =~ /^rolesdef/); + my $envkey=$area; + my $role = $rolesdump{$area}; + my $thisrole=$area; + $area =~ s/\_\w\w$//; + my ($role_code,$role_end_time,$role_start_time) = + split(/_/,$role); +# Is this a custom role? Get role owner and title. + my ($croleudom,$croleuname,$croletitle)= + ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$}); + my $allowed=0; + my $delallowed=0; + my $sortkey=$role_code; + my $class='Unknown'; + if ($area =~ m{^/($match_domain)/($match_courseid)} ) { + $class='Course'; + my ($coursedom,$coursedir) = ($1,$2); + $sortkey.="\0$coursedom"; + # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3). + my %coursedata= + &Apache::lonnet::coursedescription($1.'_'.$2); + my $carea; + if (defined($coursedata{'description'})) { + $carea=$coursedata{'description'}. + ''.&mt('Domain').': '.$coursedom.(' 'x8). + &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom); + $sortkey.="\0".$coursedata{'description'}; + $class=$coursedata{'type'}; + } else { + $carea=&mt('Unavailable course').': '.$area; + $sortkey.="\0".&mt('Unavailable course').': '.$area; + } + $sortkey.="\0$coursedir"; + $inccourses->{$1.'_'.$2}=1; + if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) || + (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) { + $allowed=1; + } + if ((&Apache::lonnet::allowed('dro',$1)) || + (&Apache::lonnet::allowed('dro',$ccdomain))) { + $delallowed=1; + } +# - custom role. Needs more info, too + if ($croletitle) { + if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) { + $allowed=1; + $thisrole.='.'.$role_code; + } + } + # Compute the background color based on $area + if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) { + $carea.=' Section: '.$3; + $sortkey.="\0$3"; + if (!$allowed) { + if ($env{'request.course.sec'} eq $3) { + if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) { + $allowed = 1; + } + } + } + } + $area=$carea; + } else { + $sortkey.="\0".$area; + # Determine if current user is able to revoke privileges + if ($area=~m{^/($match_domain)/}) { + if ((&Apache::lonnet::allowed('c'.$role_code,$1)) || + (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) { + $allowed=1; + } + if (((&Apache::lonnet::allowed('dro',$1)) || + (&Apache::lonnet::allowed('dro',$ccdomain))) && + ($role_code ne 'dc')) { + $delallowed=1; + } + } else { + if (&Apache::lonnet::allowed('c'.$role_code,'/')) { + $allowed=1; + } + } + if ($role_code eq 'ca' || $role_code eq 'au') { + $class='Construction Space'; + } elsif ($role_code eq 'su') { + $class='System'; + } else { + $class='Domain'; + } + } + if (($role_code eq 'ca') || ($role_code eq 'aa')) { + $area=~m{/($match_domain)/($match_username)}; + if (&Apache::lonuserutils::authorpriv($2,$1)) { + $allowed=1; + } else { + $allowed=0; + } + } + my $row = ''; + $row.= ' | '; + my $active=1; + $active=0 if (($role_end_time) && ($now>$role_end_time)); + if (($active) && ($allowed)) { + $row.= ''; + } else { + if ($active) { + $row.=' '; + } else { + $row.=&mt('expired or revoked'); + } + } + $row.=' | '; + if ($allowed && !$active) { + $row.= ''; + } else { + $row.=' '; + } + $row.=' | ';
+ if ($delallowed) {
+ $row.= '';
+ } else {
+ $row.=' ';
+ }
+ my $plaintext='';
+ if (!$croletitle) {
+ $plaintext=&Apache::lonnet::plaintext($role_code,$class)
+ } else {
+ $plaintext=
+ "Customrole '$croletitle' defined by $croleuname\@$croleudom"; + } + $row.= ' | '.$plaintext. + ' | '.$area. + ' | '.($role_start_time?localtime($role_start_time) + : ' ' ). + ' | '.($role_end_time ?localtime($role_end_time) + : ' ' ) + ." | "; + $sortrole{$sortkey}=$envkey; + $roletext{$envkey}=$row; + $roleclass{$envkey}=$class; + $rolepriv{$envkey}=$allowed; + #$r->print($row); + } # end of foreach (table building loop) + my $rolesdisplay = 0; + my %output = (); + foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') { + $output{$type} = ''; + foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { + if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) { + $output{$type}.= + &Apache::loncommon::start_data_table_row(). + $roletext{$sortrole{$which}}. + &Apache::loncommon::end_data_table_row(); + } + } + unless($output{$type} eq '') { + $output{$type} = '
".&mt($type)." | '.$lt{'rev'}.' | '.$lt{'ren'}.' | '.$lt{'del'}. +' | '.$lt{'rol'}.' | '.$lt{'ext'}. +' | '.$lt{'sta'}.' | '.$lt{'end'}.' | '. +&Apache::loncommon::end_data_table_header_row()); + foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') { + if ($output{$type}) { + $r->print($output{$type}."\n"); + } + } + $r->print(&Apache::loncommon::end_data_table()); + } + } # End of check for keys in rolesdump + return; +} + +sub new_coauthor_roles { + my ($r,$ccuname,$ccdomain) = @_; + my $addrolesdisplay = 0; + # + # Co-Author + # + if (&Apache::lonuserutils::authorpriv($env{'user.name'}, + $env{'request.role.domain'}) && + ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) { + # No sense in assigning co-author role to yourself + $addrolesdisplay = 1; + my $cuname=$env{'user.name'}; + my $cudom=$env{'request.role.domain'}; + my %lt=&Apache::lonlocal::texthash( + 'cs' => "Construction Space", + 'act' => "Activate", + 'rol' => "Role", + 'ext' => "Extent", + 'sta' => "Start", + 'end' => "End", + 'cau' => "Co-Author", + 'caa' => "Assistant Co-Author", + 'ssd' => "Set Start Date", + 'sed' => "Set End Date" + ); + $r->print(''.$lt{'act'}.' | '.$lt{'rol'}.' | '. + ''.$lt{'ext'}.' | '.$lt{'sta'}.' | '. + ''.$lt{'end'}.' | '."\n". + &Apache::loncommon::end_data_table_header_row()."\n". + &Apache::loncommon::start_data_table_row().' ++ + | +'.$lt{'cau'}.' | +'.$cudom.'_'.$cuname.' | ++ '.$lt{'ssd'}.' | +Set Start Date | -+"javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.' | '."\n". + &Apache::loncommon::end_data_table_row()."\n". + &Apache::loncommon::start_data_table_row()."\n". +'+ | '.$lt{'caa'}.' | +'.$cudom.'_'.$cuname.' | +Set End Date | - -
Activate | Role | Extent | '. - 'Start | End | - | $plrole | -$thisdomain | -
+ return $addrolesdisplay;;
+}
+
+sub new_domain_roles {
+ my ($r) = @_;
+ my $addrolesdisplay = 0;
+ #
+ # Domain level
+ #
+ my $num_domain_level = 0;
+ my $domaintext =
+ ''.&mt('Domain Level').''. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ' | '.&mt('Activate').' | '.&mt('Role').' | '. + &mt('Extent').' | '. + ''.&mt('Start').' | '.&mt('End').' | '. + &Apache::loncommon::end_data_table_header_row(); + foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) { + foreach my $role ('dc','li','dg','au','sc') { + if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) { + my $plrole=&Apache::lonnet::plaintext($role); + my %lt=&Apache::lonlocal::texthash( + 'ssd' => "Set Start Date", + 'sed' => "Set End Date" + ); + $num_domain_level ++; + $domaintext .= +&Apache::loncommon::start_data_table_row(). +'+ | '.$plrole.' | +'.$thisdomain.' | +Set Start Date | -+"javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.' | +Set End Date | - -ENDDROW +"javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.''. +&Apache::loncommon::end_data_table_row(); } - } + } } - $r->print('
---|
'.$authformcurrent. + ' | ||
'. + ' | '.&mt('Currently in use').' | '. + ''. + &mt('will override current values'). + ' |