--- loncom/auth/lonroles.pm 2010/01/02 19:14:29 1.231.4.9 +++ loncom/auth/lonroles.pm 2010/06/03 14:41:07 1.252 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.231.4.9 2010/01/02 19:14:29 raeburn Exp $ +# $Id: lonroles.pm,v 1.252 2010/06/03 14:41:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -57,8 +57,7 @@ course they should act on, etc. Both in handler determines via C's C<&allowed> function that a certain action is not allowed, C is used as error handler. This allows the user to select another role which may have permission to do -what they were trying to do. C can also be accessed via the -B button in the Remote Control. +what they were trying to do. =begin latex @@ -138,28 +137,25 @@ use Apache::lonannounce; use Apache::lonlocal; use Apache::lonpageflip(); use Apache::lonnavdisplay(); +use Apache::loncoursequeueadmin; use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; sub redirect_user { - my ($r,$title,$url,$msg,$launch_nav) = @_; + my ($r,$title,$url,$msg) = @_; $msg = $title if (! defined($msg)); &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); - my $navwindow; - if ($launch_nav eq 'on') { - $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef, - ($url =~ m-^/adm/whatsnew-)); - } else { - $navwindow.=&Apache::lonnavmaps::close(); - } + # Breadcrumbs + my $brcrum = [{'href' => $url, + 'text' => 'Switching Role'},]; my $start_page = &Apache::loncommon::start_page('Switching Role',undef, - {'redirect' => [1,$url]}); + {'redirect' => [1,$url], + 'bread_crumbs' => $brcrum,}); my $end_page = &Apache::loncommon::end_page(); # Note to style police: @@ -167,12 +163,6 @@ sub redirect_user { $url=~s/ /\%20/g; $r->print(< -// - -$navwindow

$msg

$end_page ENDREDIR @@ -185,17 +175,25 @@ sub error_page { &Apache::loncommon::no_cache($r); $r->send_http_header; return OK if $r->header_only; - $r->print(&Apache::loncommon::start_page('Problems during Course Initialization'). + # Breadcrumbs + my $brcrum = [{'href' => $dest, + 'text' => 'Problems during Course Initialization'},]; + $r->print(&Apache::loncommon::start_page('Problems during Course Initialization', + undef, + {'bread_crumbs' => $brcrum,}) + ); + $r->print( ''. '

'.&mt('The following problems occurred:'). - '
'. + '
'. $error. - '


'.&mt('Continue').''. - &Apache::loncommon::end_page()); + '


'.&mt('Continue').'' + ); + $r->print(&Apache::loncommon::end_page()); } sub handler { @@ -225,7 +223,16 @@ sub handler { if ($env{'request.course.id'}) { # Check if user is CC trying to select a course role if ($env{'form.switchrole'}) { - if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { + my $switch_is_active; + if (defined($env{'user.role.'.$env{'form.switchrole'}})) { + my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}}); + if (!$end || $end > $now) { + if (!$start || $start < $refresh) { + $switch_is_active = 1; + } + } + } + unless ($switch_is_active) { &adhoc_course_role($refresh,$then); } } @@ -243,12 +250,12 @@ sub handler { # Check if user is a DC trying to enter a course or author space and needs privs to be created if ($numdc > 0) { foreach my $envkey (keys %env) { -# Is this an ad-hoc CC-role? - if (my ($domain,$coursenum) = - ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) { +# Is this an ad-hoc Coordinator role? + if (my ($ccrole,$domain,$coursenum) = + ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { &Apache::lonnet::check_adhoc_privs($domain,$coursenum, - $then,$refresh,$now,'cc'); + $then,$refresh,$now,$ccrole); } last; } @@ -261,7 +268,7 @@ sub handler { my ($server_status,$home) = &check_author_homeserver($user,$domain); if ($server_status eq 'switchserver') { my $trolecode = 'au./'.$domain.'/'; - my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); } last; @@ -272,7 +279,7 @@ sub handler { my ($server_status,$home) = &check_author_homeserver($user,$domain); if ($server_status eq 'switchserver') { my $trolecode = 'ca./'.$domain.'/'.$user; - my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); } last; @@ -293,7 +300,7 @@ sub handler { if ($server_status eq 'switchserver') { my $trolecode = 'ca./'.$domain.'/'.$user; my $switchserver = '/adm/switchserver?' - .'otherserver='.$home.'&role='.$trolecode; + .'otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); } } else { @@ -479,8 +486,8 @@ ENDENTERKEY $courseid = substr($courseid, 1); } $courseid =~ s/\//_/; - if ($role eq 'cc' && $env{'course.' . $courseid . - '.course.helper.not.run'}) { + if ((($role eq 'cc') || ($role eq 'co')) + && ($env{'course.' . $courseid .'.course.helper.not.run'})) { $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected } elsif ($env{'request.course.id'}) { @@ -490,10 +497,9 @@ ENDENTERKEY my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&'); $dest .= '?symb='.$esc_symb; } - &redirect_user($r,&mt('Entering [_1]', - $env{'course.'.$courseid.'.description'}), - $dest,$msg, - $env{'environment.remotenavmap'}); + &redirect_user($r, &mt('Entering [_1]', + $env{'course.'.$courseid.'.description'}), + $dest, $msg); return OK; } if (&Apache::lonnet::allowed('whn', @@ -506,9 +512,8 @@ ENDENTERKEY unless ($startpage eq 'firstres') { $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); - &redirect_user($r,&mt('New in course'), - '/adm/whatsnew?refpage=start',$msg, - $env{'environment.remotenavmap'}); + &redirect_user($r, &mt('New in course'), + '/adm/whatsnew?refpage=start', $msg); return OK; } } @@ -520,10 +525,9 @@ ENDENTERKEY } $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); - &redirect_user($r,&mt('Entering [_1]', - $env{'course.'.$courseid.'.description'}), - $furl,$msg, - $env{'environment.remotenavmap'}); + &redirect_user($r, &mt('Entering [_1]', + $env{'course.'.$courseid.'.description'}), + $furl, $msg); } return OK; } @@ -659,7 +663,7 @@ ENDHEADER if ($reinit) { $r->print( '

'. - &mt('As your session file for the course or community has expired, you will need to re-select the course.').'

'); + &mt('As your session file for the course or community has expired, you will need to re-select it.').''); } else { $r->print( '

'. @@ -692,16 +696,16 @@ ENDHEADER $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); if ($env{'user.adv'}) { + $r->print('

' .' ' .'

'); } else { if ($countactive > 0) { - &queued_selfenrollment($r); + $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment()); my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); - $r->print( '

' .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]' @@ -726,7 +730,7 @@ ENDHEADER $r->print('

'.&mt('Currently no active roles, courses or communities').'

'); } &findcourse_advice($r); - &requestcourse_advice($r); + &requestcourse_advice($r); $r->print(''); if ($countfuture) { $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); @@ -757,6 +761,13 @@ ENDHEADER return OK; } # ----------------------------------------------------------------------- Table + + if ($numdc > 0) { + $r->print(&coursepick_jscript()); + $r->print(&Apache::loncommon::coursebrowser_javascript(). + &Apache::loncommon::authorbrowser_javascript()); + } + unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) { $r->print("

".&mt('Select a Course to Enter')."

\n"); } @@ -768,28 +779,37 @@ ENDHEADER $env{'form.destsymb'}.'" />'); } } + my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose); if ($env{'environment.recentroles'}) { my %recent_roles = &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'}); my $output=''; - foreach (sort(keys(%recent_roles))) { - if (ref($roletext{'user.role.'.$_}) eq 'ARRAY') { + foreach my $role (sort(keys(%recent_roles))) { + if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') { $output.= &Apache::loncommon::start_data_table_row(). - $roletext{'user.role.'.$_}->[0]. - &Apache::loncommon::end_data_table_row(). - &Apache::loncommon::continue_data_table_row(). - $roletext{'user.role.'.$_}->[1]. + $roletext{'user.role.'.$role}->[0]. &Apache::loncommon::end_data_table_row(); - if ($_ =~ m-dc\./($match_domain)/- + if ($roletext{'user.role.'.$role}->[1] ne '') { + $output .= &Apache::loncommon::continue_data_table_row(). + $roletext{'user.role.'.$role}->[1]. + &Apache::loncommon::end_data_table_row(); + } + if ($role =~ m{dc\./($match_domain)/} && $dcroles{$1}) { $output .= &adhoc_roles_row($1,'recent'); } } elsif ($numdc > 0) { - unless ($_ =~/^error\:/) { - $output.=&display_cc_role('user.role.'.$_); + unless ($role =~/^error\:/) { + my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role); + $output.= &Apache::loncommon::start_data_table_row(). + $roletext. + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::continue_data_table_row(). + $role_text_end. + &Apache::loncommon::end_data_table_row(); } - } + } } if ($output) { $r->print(&Apache::loncommon::start_data_table_empty_row() @@ -802,12 +822,6 @@ ENDHEADER $doheaders ++; } } - - if ($numdc > 0) { - $r->print(&coursepick_jscript()); - $r->print(&Apache::loncommon::coursebrowser_javascript(). - &Apache::loncommon::authorbrowser_javascript()); - } &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext); if ($countactive > 1) { my $tremark=''; @@ -930,7 +944,7 @@ sub gather_roles { foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + $switchserver='otherserver='.$home.'&role='.$trolecode; } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -950,7 +964,7 @@ sub gather_roles { foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + $switchserver='otherserver='.$home.'&role='.$trolecode; } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -963,10 +977,11 @@ sub gather_roles { } elsif ($trest) { my $tcourseid=$tdom.'_'.$trest; $ttype = &Apache::loncommon::course_type($tcourseid); - $trole = &Apache::lonnet::plaintext($role,$ttype); + $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid); if ($env{'course.'.$tcourseid.'.description'}) { $twhere=$env{'course.'.$tcourseid.'.description'}; $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey; + $twhere = &HTML::Entities::encode($twhere,'"<>&'); unless ($twhere eq &mt('Currently not available')) { $twhere.=' '. &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). @@ -977,12 +992,12 @@ sub gather_roles { if (%newhash) { $sortkey=$role."\0".$tdom."\0".$newhash{'description'}. "\0".$envkey; - $twhere=$newhash{'description'}. - ' '. - &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). - ''; + $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&'). + ' '. + &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). + ''; $ttype = $newhash{'type'}; - $trole = &Apache::lonnet::plaintext($role,$ttype); + $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid); } else { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; @@ -1114,10 +1129,12 @@ sub print_rolerows { if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') { $output.= &Apache::loncommon::start_data_table_row(). $roletext->{$sortrole->{$which}}->[0]. - &Apache::loncommon::end_data_table_row(). - &Apache::loncommon::continue_data_table_row(). - $roletext->{$sortrole->{$which}}->[1]. &Apache::loncommon::end_data_table_row(); + if ($roletext->{$sortrole->{$which}}->[1] ne '') { + $output .= &Apache::loncommon::continue_data_table_row(). + $roletext->{$sortrole->{$which}}->[1]. + &Apache::loncommon::end_data_table_row(); + } } if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) { if (ref($dcroles) eq 'HASH') { @@ -1162,8 +1179,8 @@ sub findcourse_advice { } $r->print('

'.&mt('Self-Enrollment').'

'. '

'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','','',$domdesc).'
'); - $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'

'); - &queued_selfenrollment($r); + $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'

'. + &Apache::loncoursequeueadmin::queued_selfenrollment()); return; } @@ -1175,12 +1192,12 @@ sub requestcourse_advice { &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms); if (keys(%request_doms) > 0) { my ($types,$typename) = &Apache::loncommon::course_types(); - if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { + if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { $r->print('

'.&mt('Request creation of a course or community').'

'. '

'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'

    '); my (@reqdoms,@reqtypes); foreach my $type (sort(keys(%request_doms))) { - push(@reqtypes,$type); + push(@reqtypes,$type); if (ref($request_doms{$type}) eq 'ARRAY') { my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}})); $r->print( @@ -1213,53 +1230,10 @@ sub requestcourse_advice { } if (@reqdoms == 1 || @showtypes > 0) { $requrl .= '&state=crstype&action=new'; - } - $r->print('
'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','','').'

'); - } - } - return; -} - -sub queued_selfenrollment { - my ($r) = @_; - my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests'); - my %reqs_by_date; - foreach my $item (keys(%selfenrollrequests)) { - if (ref($selfenrollrequests{$item}) eq 'HASH') { - if ($selfenrollrequests{$item}{'status'} eq 'request') { - if ($selfenrollrequests{$item}{'timestamp'}) { - push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item); - } } + $r->print(''.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','','').'

'); } } - if (keys(%reqs_by_date)) { - my $rolename = &Apache::lonnet::plaintext('st'); - $r->print(''.&mt('Enrollment requests pending Course Coordinator approval').'
'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). - ''.&mt('Date requested').''.&mt('Course title').''. - ''.&mt('User role').''.&mt('Section').''. - &Apache::loncommon::end_data_table_header_row()); - my @sorted = sort { $a <=> $b } (keys(%reqs_by_date)); - foreach my $item (@sorted) { - if (ref($reqs_by_date{$item}) eq 'ARRAY') { - foreach my $crs (@{$reqs_by_date{$item}}) { - my %courseinfo = &Apache::lonnet::coursedescription($crs); - my $usec = $selfenrollrequests{$crs}{'section'}; - if ($usec eq '') { - $usec = &mt('No section'); - } - $r->print(&Apache::loncommon::start_data_table_row(). - ''.&Apache::lonlocal::locallocaltime($item).''. - ''.$courseinfo{'description'}.''. - ''.$rolename.''.$usec.''. - &Apache::loncommon::end_data_table_row()); - } - } - } - $r->print(&Apache::loncommon::end_data_table()); - } return; } @@ -1585,9 +1559,12 @@ sub display_cc_role { my $advanced = $env{'user.adv'}; my $tryagain = $env{'form.tryagain'}; unless ($rolekey =~/^error\:/) { - if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) { - my $tcourseid = $1.'_'.$2; - my $trolecode = 'cc./'.$1.'/'.$2; + if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) { + my $ccrole = $1; + my $tdom = $2; + my $trest = $3; + my $tcourseid = $tdom.'_'.$trest; + my $trolecode = $ccrole.'./'.$tdom.'/'.$trest; my $twhere; my $ttype; my $tbg='LC_roles_is'; @@ -1595,16 +1572,16 @@ sub display_cc_role { if (%newhash) { $twhere=$newhash{'description'}. ' '. - &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1). + &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom). ''; $ttype = $newhash{'type'}; } else { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; } - my $trole = &Apache::lonnet::plaintext('cc',$ttype); + my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid); $twhere.="
".&mt('Domain').":".$1; - ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,''); + ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,''); } } return ($roletext,$roletext_end); @@ -1622,7 +1599,7 @@ sub adhoc_roles_row { my $carole = &Apache::lonnet::plaintext('ca'); my $selectcalink = &coauthorlink($dcdom,$rowtype); $output.=$ccrole.': '.$selectcclink - .' | '.$carole.': '.$selectcalink + .' | '.$carole.': '.$selectcalink.'' .&Apache::loncommon::end_data_table_row(); return $output; } @@ -1680,8 +1657,7 @@ course they should act on, etc. Both in handler determines via C's C<&allowed> function that a certain action is not allowed, C is used as error handler. This allows the user to select another role which may have permission to do -what they were trying to do. C can also be accessed via the -B button in the Remote Control. +what they were trying to do. =begin latex