--- loncom/auth/lonroles.pm 2008/05/14 22:26:48 1.190 +++ loncom/auth/lonroles.pm 2008/05/14 23:52:52 1.191 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.190 2008/05/14 22:26:48 www Exp $ +# $Id: lonroles.pm,v 1.191 2008/05/14 23:52:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -530,8 +530,12 @@ ENDHEADER my (%roletext,%sortrole,%roleclass); my $countactive=0; + my $countfuture=0; + my $countwill=0; my $inrole=0; my $possiblerole=''; + my %futureroles; + my %roles_nextlogin; foreach $envkey (sort keys %env) { my $button = 1; my $switchserver=''; @@ -568,9 +572,13 @@ ENDHEADER } elsif ($tstatus eq 'future') { $tbg='#FFFF77'; $button=0; + $futureroles{$trolecode} = $tstart.':'.$tend; + $countfuture ++; } elsif ($tstatus eq 'will') { $tbg='#FFAA77'; $tremark.=&mt('Active at next login. '); + $roles_nextlogin{$trolecode} = $tstart.':'.$tend; + $countwill ++; } elsif ($tstatus eq 'expired') { $tbg='#FF7777'; $tfont='#330000'; @@ -693,7 +701,30 @@ ENDHEADER } else { $r->print('

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

'); } - $r->print(''.&Apache::loncommon::end_page()); + &findcourse_advice($r); + $r->print(''); + if ($countfuture) { + $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); + my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole, + $nochoose); + &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles, + \%roletext); + my $tremark=''; + my $tfont='#003300'; + if ($env{'request.role'} eq 'cm') { + $r->print(''); + $tremark=&mt('Currently selected. '); + $tfont='#002200'; + } else { + $r->print(''); + } + $r->print(''.&mt('No role specified'). + ''.$tremark. + ' '."\n"); + + $r->print(''); + } + $r->print(&Apache::loncommon::end_page()); return OK; # Is there only one choice? } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) { @@ -711,21 +742,7 @@ ENDHEADER unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) { $r->print("

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

\n"); } - $r->print('
'); - unless ($nochoose) { $r->print(''); } - $r->print(''."\n"); - my $doheaders=-1; - foreach my $type ('Domain','Construction Space','Course','Unavailable','System') { - my $haverole=0; - foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { - if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { - $haverole=1; - } - } - if ($haverole) { $doheaders++; } - } - + my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose); if ($env{'environment.recentroles'}) { my %recent_roles = &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'}); @@ -757,27 +774,7 @@ ENDHEADER $r->print(&coursepick_jscript()); $r->print(&Apache::loncommon::coursebrowser_javascript()); } - foreach my $type ('Construction Space','Domain','Course','Unavailable','System') { - my $output; - foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { - if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { - $output.=$roletext{$sortrole{$which}}; - if ($sortrole{$which} =~ m-dc\./($match_domain)/-) { - if ($dcroles{$1}) { - $output .= &allcourses_row($1,''). - &allcoauthors_row($1,''); - } - } - } - } - if ($output) { - if ($doheaders > 0) { - $r->print("". - ""); - } - $r->print($output); - } - } + &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext); my $tremark=''; my $tfont='#003300'; if ($env{'request.role'} eq 'cm') { @@ -818,6 +815,88 @@ ENDHEADER return OK; } +sub roletable_headers { + my ($r,$roleclass,$sortrole,$nochoose) = @_; + my $doheaders; + if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) { + $r->print('
 '.&mt('User Role').''.&mt('Extent'). - ''.&mt('Start').''.&mt('End').'
".&mt($type)."
'); + if (!$nochoose) { $r->print(''); } + $r->print(''."\n"); + $doheaders=-1; + my @roletypes = &roletypes(); + foreach my $type (@roletypes) { + my $haverole=0; + foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) { + if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) { + $haverole=1; + } + } + if ($haverole) { $doheaders++; } + } + } + return $doheaders; +} + +sub roletypes { + my @types = ('Domain','Construction Space','Course','Unavailable','System'); + return @types; +} + +sub print_rolerows { + my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_; + if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) { + my @types = &roletypes(); + foreach my $type (@types) { + my $output; + foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) { + if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) { + if (ref($roletext) eq 'HASH') { + $output.=$roletext->{$sortrole->{$which}}; + if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) { + if (ref($dcroles) eq 'HASH') { + if ($dcroles->{$1}) { + $output .= &allcourses_row($1,''). + &allcoauthors_row($1,''); + } + } + } + } + } + } + if ($output) { + if ($doheaders > 0) { + $r->print("". + ""); + } + $r->print($output); + } + } + } +} + +sub findcourse_advice { + my ($r) = @_; + my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); + if (&check_autoenroll($env{'user.domain'})) { + $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).' +'); + } else { + $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'
'); + } + $r->print('

'.&mt('The [_1]Course Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created.','','',$domdesc).'
'); + $r->print(&mt('You can search the course catalog for courses which permit self-enrollment, if you would like to enroll in a course.').'

'); + return; +} + sub privileges_info { my ($which) = @_; my $output; @@ -1219,6 +1298,24 @@ sub courseloadpage { return $startpage; } +sub check_autoenroll { + my ($dom) = @_; + my $run_enroll = 0; + my $settings; + my %domconfig = + &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom); + if (ref($domconfig{'autoenroll'}) eq 'HASH') { + $settings = $domconfig{'autoenroll'}; + if ($settings->{'run'} eq '1') { + $run_enroll = 1; + } + } else { + $run_enroll = &localenroll::run($dom); + } + return $run_enroll; +} + + 1; __END__
 '.&mt('User Role').''.&mt('Extent') + .''.&mt('Start').''.&mt('End') + .'
". + &mt($type)."