--- loncom/auth/lonroles.pm 2003/04/07 18:24:05 1.56 +++ loncom/auth/lonroles.pm 2003/08/05 12:52:23 1.65 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.56 2003/04/07 18:24:05 www Exp $ +# $Id: lonroles.pm,v 1.65 2003/08/05 12:52:23 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,6 +50,31 @@ use Apache::Constants qw(:common); use Apache::File(); use Apache::lonmenu; use Apache::loncommon; +use Apache::lonannounce; + +sub redirect_user { + my ($r,$title,$url,$msg) = @_; + $msg = $title if (! defined($msg)); + $r->content_type('text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + my $swinfo=&Apache::lonmenu::rawconfig(); + my $bodytag=&Apache::loncommon::bodytag('Switching Role'); + $r->print (<$title + + + +$bodytag + +

$msg

+ + +ENDREDIR + return; +} sub handler { @@ -140,6 +165,7 @@ ENDENTERKEY 'request.role.domain' => $cdom, 'request.course.sec' => $csec); my $msg='Entering course ...'; + if (($cnum) && ($role ne 'ca')) { my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); @@ -151,31 +177,44 @@ ENDENTERKEY unless ($ENV{'request.course.id'}) { &Apache::lonnet::appenv( "request.course.id" => $cdom.'_'.$cnum); - $furl='/adm/notfound.html'; + $furl='/adm/roles?tryagain=1'; $msg= - '

Could not initialize top-level map.

'; + '

Could not initialize course at this time.

Please try again.

'; } - $r->content_type('text/html'); - &Apache::loncommon::no_cache($r); - $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); - my $bodytag=&Apache::loncommon::bodytag('Switching Role'); - print (<Entering Course - - - -$bodytag - -

$msg

- - -ENDREDIR + + # Check to see if the user is a CC entering a course + # for the first time + my (undef, undef, $role, $courseid) = split(/\./, $envkey); + if (substr($courseid, 0, 1) eq '/') { + $courseid = substr($courseid, 1); + } + $courseid =~ s/\//_/; + if ($role eq 'cc' && $ENV{'course.' . $courseid . + '.course.helper.not.run'}) { + $furl = "/adm/helper/course.initialization.helper"; + } + # + # Send the user to the course they selected + &redirect_user($r,'Entering Course', + $furl,$msg); return OK; } } + # + # Send the user to the construction space they selected + if ($role =~ /^(au|ca)$/) { + my $redirect_url = '/priv/'; + if ($role eq 'au') { + $redirect_url.=$ENV{'user.name'}; + } else { + $where =~ /\/(.*)$/; + $redirect_url .= $1; + } + $redirect_url .= '/'; + &redirect_user($r,'Entering Construction Space', + $redirect_url); + return OK; + } } } } @@ -214,15 +253,11 @@ ENDHEADER "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn); } -# ---------------------------------------------------------------- Who is this? +# ------------------------------------------------- Can this user re-init, etc? - my $advanced=0; - foreach $envkey (keys %ENV) { - if ($envkey=~/^user\.role\./) { - my (undef,undef,$role,@pwhere)=split(/\./,$envkey); - if ($role ne 'st') { $advanced=1; } - } - } + my $advanced=$ENV{'user.adv'}; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']); + my $tryagain=$ENV{'form.tryagain'}; # -------------------------------------------------------- Generate Page Output # --------------------------------------------------------------- Error Header? @@ -262,7 +297,7 @@ ENDHEADER $r->print("Author and Co-Author roles may not be available on ". "servers other than your home server."); } else { - $r->print("

Enter a Course

\n"); + $r->print("

Select a Course to Enter

\n"); } if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) { $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'}; @@ -271,11 +306,14 @@ ENDHEADER $r->print(''); $r->print(''); } - $r->print('
Show all roles: print(' checked'); } - $r->print('>
'); + if ($ENV{'user.adv'}) { + $r->print( + '
Show all roles: print(' checked'); } + $r->print('>'); + } # ----------------------------------------------------------------------- Table - $r->print(''); + $r->print('
'); unless ($nochoose) { $r->print(''); } $r->print(''. ''."\n"); @@ -429,7 +467,11 @@ ENDHEADER } elsif ($tstatus eq 'is') { $r->print(''); - } elsif ($ENV{'user.adv'}) { + } elsif ($tryagain) { + $r->print + (''); + } elsif ($advanced) { $r->print (''); @@ -437,6 +479,9 @@ ENDHEADER $r->print(''); } } + $tremark.=&Apache::lonannounce::showday(time,1, + &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); + $r->print('
 User RoleExtentStartEndRemark
 '.$trole. ''.$ttype. ''.$twhere. @@ -525,7 +570,10 @@ ENDHEADER } } } - + if ($advanced) { + $r->print('

This is LON-CAPA '. + $r->dir_config('lonVersion').'

'); + } $r->print("\n"); return OK; } @@ -549,6 +597,36 @@ Invoked by /etc/httpd/conf/srm.conf: ErrorDocument 500 /adm/errorhandler +=head1 OVERVIEW + +=head2 Choosing Roles + +C is a handler that allows a user to switch roles in +mid-session. LON-CAPA attempts to work with "No Role Specified", the +default role that a user has before selecting a role, as widely as +possible, but certain handlers for example need specification which +course they should act on, etc. Both in this scenario, and when the +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. + +=begin latex + +\begin{figure} +\begin{center} +\includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen} + \caption{\label{Sample_Roles_Screen}Sample Roles Screen} +\end{center} +\end{figure} + +=end latex + +=head2 Role Initialization + +The privileges for a user are established at login time and stored in the session environment. As a consequence, a new role does not become active till the next login. Handlers are able to query for privileges using C's C<&allowed> function. When a user first logs in, their role is the "common" role, which means that they have the sum of all of their privileges. During a session it might become necessary to choose a particular role, which as a consequence also limits the user to only the privileges in that particular role. + =head1 INTRODUCTION This module enables a user to select what role he wishes to