Annotation of loncom/auth/lonroles.pm, revision 1.68

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # User Roles Screen
1.31      www         3: #
1.68    ! www         4: # $Id: lonroles.pm,v 1.67 2003/09/11 20:03:28 albertel Exp $
1.31      www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       harris41   28: # (Directory Indexer
                     29: # (Login Screen
1.32      harris41   30: # YEAR=1999
1.1       harris41   31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
                     32: # 11/23 Gerd Kortemeyer)
1.32      harris41   33: # YEAR=2000
1.7       www        34: # 1/14,03/06,06/01,07/22,07/24,07/25,
1.19      www        35: # 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28,
1.20      www        36: # 12/08,12/28,
1.32      harris41   37: # YEAR=2001
1.20      www        38: # 01/15/01 Gerd Kortemeyer
1.28      www        39: # 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer
1.33      www        40: # 12/29 Gerd Kortemeyer
1.32      harris41   41: #
                     42: ###
1.22      harris41   43: 
1.1       harris41   44: package Apache::lonroles;
                     45: 
                     46: use strict;
                     47: use Apache::lonnet();
1.7       www        48: use Apache::lonuserstate();
1.1       harris41   49: use Apache::Constants qw(:common);
1.2       www        50: use Apache::File();
1.26      www        51: use Apache::lonmenu;
1.29      albertel   52: use Apache::loncommon;
1.57      www        53: use Apache::lonannounce;
1.1       harris41   54: 
1.62      matthew    55: sub redirect_user {
                     56:     my ($r,$title,$url,$msg) = @_;
                     57:     $msg = $title if (! defined($msg));
                     58:     $r->content_type('text/html');
                     59:     &Apache::loncommon::no_cache($r);
                     60:     $r->send_http_header;
                     61:     my $swinfo=&Apache::lonmenu::rawconfig();
                     62:     my $bodytag=&Apache::loncommon::bodytag('Switching Role');
                     63:     $r->print (<<ENDREDIR);
                     64: <head><title>$title</title>
                     65: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">
                     66: </head>
                     67: <html>
                     68: $bodytag
                     69: <script>
                     70: $swinfo
                     71: </script>
                     72: <h1>$msg</h1>
                     73: </body>
                     74: </html>
                     75: ENDREDIR
                     76:     return;
                     77: }
                     78: 
1.1       harris41   79: sub handler {
1.10      www        80: 
1.1       harris41   81:     my $r = shift;
                     82: 
1.6       www        83:     my $now=time;
                     84:     my $then=$ENV{'user.login.time'};
                     85:     my $envkey;
                     86: 
1.10      www        87: 
1.6       www        88: # ================================================================== Roles Init
                     89: 
                     90:     if ($ENV{'form.selectrole'}) {
1.33      www        91: 	if ($ENV{'request.course.id'}) {
                     92: 	    my %temp=('logout_'.$ENV{'request.course.id'} => time);
                     93: 	    &Apache::lonnet::put('email_status',\%temp);
                     94:         }
1.55      albertel   95: 	&Apache::lonnet::appenv("request.course.id"   => '',
                     96: 				"request.course.fn"   => '',
                     97: 				"request.course.uri"  => '',
                     98: 				"request.course.sec"  => '',
                     99: 				"request.role"        => 'cm',
1.56      www       100:                                 "request.role.adv"    => $ENV{'user.adv'},
1.55      albertel  101: 				"request.role.domain" => $ENV{'user.domain'});
1.13      www       102:         foreach $envkey (keys %ENV) {
1.40      matthew   103:             next if ($envkey!~/^user\.role\./);
                    104: 	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
1.6       www       105:             my $where=join('.',@pwhere);
                    106:             my $trolecode=$role.'.'.$where;
                    107:             if ($ENV{'form.'.$trolecode}) {
1.55      albertel  108: 		my ($tstart,$tend)=split(/\./,$ENV{$envkey});
                    109: 		my $tstatus='is';
                    110: 		if ($tstart) {
                    111: 		    if ($tstart>$then) { 
                    112: 			$tstatus='future';
                    113: 		    }
                    114: 		}
                    115: 		if ($tend) {
                    116: 		    if ($tend<$then) { $tstatus='expired'; }
                    117: 		    if ($tend<$now) { $tstatus='will_not'; }
                    118: 		}
                    119: 		if ($tstatus eq 'is') {
                    120: 		    $where=~s/^\///;
                    121: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
1.53      www       122: # check for keyed access
1.55      albertel  123: 		    if (($role eq 'st') && 
                    124:                        ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
                    125: 		         unless (&Apache::lonnet::validate_access_key(
                    126: 				     $ENV{'environment.key.'.$cdom.'_'.$cnum},
                    127: 					     $cdom,$cnum)) {
1.53      www       128: # there is no valid key
1.55      albertel  129: 			     if ($ENV{'form.newkey'}) {
1.53      www       130: # student attempts to register a new key
1.55      albertel  131: 			     } else {
1.53      www       132: # print form to enter a new key
1.55      albertel  133: 				 $r->content_type('text/html');
                    134: 				 &Apache::loncommon::no_cache($r);
                    135: 				 $r->send_http_header;
                    136: 				 my $swinfo=&Apache::lonmenu::rawconfig();
                    137: 				 my $bodytag=&Apache::loncommon::bodytag
                    138: 				    ('Enter Access Key to Unlock this Course');
                    139: 				 $r->print(<<ENDENTERKEY);
1.53      www       140: <head><title>Entering Course Access Key</title>
                    141: </head>
                    142: <html>
                    143: $bodytag
                    144: <script>
                    145: $swinfo
                    146: </script>
                    147: <form method="post">
                    148: <input type="hidden" name="selectrole" value="$ENV{'form.selectrole'}" />
                    149: <input type="text" size="20" name="newkey" value="$ENV{'form.newkey'}" />
                    150: <input type="submit" value="Enter key" />
                    151: </form>
                    152: </body></html>
                    153: ENDENTERKEY
1.55      albertel  154: 				 return OK;
                    155: 			     }
                    156: 			 }
                    157: 		     }
1.56      www       158:                     my $tadv=0;
                    159:                     if (($trolecode!~/^st/) && 
                    160:                         ($trolecode!~/^ta/) && 
                    161:                         ($trolecode!~/^cm/)) { $tadv=1; }
                    162: 		    &Apache::lonnet::appenv(
                    163:                                            'request.role'        => $trolecode,
                    164: 					   'request.role.adv'    => $tadv,
                    165: 					   'request.role.domain' => $cdom,
                    166: 					   'request.course.sec'  => $csec);
1.55      albertel  167: 		    my $msg='Entering course ...';
1.62      matthew   168: 
1.55      albertel  169: 		    if (($cnum) && ($role ne 'ca')) {
                    170: 			my ($furl,$ferr)=
                    171: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                    172: 			if (($ENV{'form.orgurl'}) && 
                    173: 			    ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.67      albertel  174: 			    my $dest=$ENV{'form.orgurl'};
1.68    ! www       175: 
1.67      albertel  176: 				&Apache::lonnet::cleanenv();
1.68    ! www       177: 
1.67      albertel  178: 			    $r->internal_redirect($dest);
1.55      albertel  179: 			    return OK;
                    180: 			} else {
                    181: 			    unless ($ENV{'request.course.id'}) {
                    182: 				&Apache::lonnet::appenv(
                    183: 				      "request.course.id"  => $cdom.'_'.$cnum);
1.61      www       184: 				$furl='/adm/roles?tryagain=1';
1.55      albertel  185: 				$msg=
1.67      albertel  186: 	 '<h1><font color=red>Could not initialize course at this time.</font></h1><h3>Please try again.</h3>'.$ferr;
1.55      albertel  187: 			    }
1.58      bowersj2  188: 
                    189: 			    # Check to see if the user is a CC entering a course 
                    190: 			    # for the first time
                    191: 			    my (undef, undef, $role, $courseid) = split(/\./, $envkey);
                    192: 			    if (substr($courseid, 0, 1) eq '/') {
                    193: 				$courseid = substr($courseid, 1);
                    194: 			    }
                    195: 			    $courseid =~ s/\//_/;
                    196: 			    if ($role eq 'cc' && $ENV{'course.' . $courseid . 
                    197: 							  '.course.helper.not.run'}) {
                    198: 				$furl = "/adm/helper/course.initialization.helper";
                    199: 			    }
1.62      matthew   200:                             #
                    201:                             # Send the user to the course they selected
                    202:                             &redirect_user($r,'Entering Course',
                    203:                                            $furl,$msg);
1.20      www       204:                             return OK;
1.55      albertel  205: 			}
                    206: 		    }
1.62      matthew   207:                     #
                    208:                     # Send the user to the construction space they selected
                    209:                     if ($role =~ /^(au|ca)$/) {
                    210:                         my $redirect_url = '/priv/';
                    211:                         if ($role eq 'au') {
                    212:                             $redirect_url.=$ENV{'user.name'};
                    213:                         } else {
                    214:                             $where =~ /\/(.*)$/;
                    215:                             $redirect_url .= $1;
                    216:                         }
                    217:                         $redirect_url .= '/';
                    218:                         &redirect_user($r,'Entering Construction Space',
                    219:                                        $redirect_url);
                    220:                         return OK;
                    221:                     }
1.55      albertel  222: 		}
                    223:             }
1.6       www       224:         }
1.40      matthew   225:     }
1.44      www       226: 
1.10      www       227: 
1.6       www       228: # =============================================================== No Roles Init
1.10      www       229: 
                    230:     $r->content_type('text/html');
1.30      albertel  231:     &Apache::loncommon::no_cache($r);
1.10      www       232:     $r->send_http_header;
                    233:     return OK if $r->header_only;
                    234: 
1.52      www       235:     my $swinfo=&Apache::lonmenu::rawconfig();
1.41      www       236:     my $bodytag=&Apache::loncommon::bodytag('User Roles');
1.48      www       237:     my $helptag=&Apache::loncommon::help_open_topic
1.52      www       238:      ("General_Intro","Click here for help");
1.10      www       239:     $r->print(<<ENDHEADER);
                    240: <html>
                    241: <head>
                    242: <title>LON-CAPA User Roles</title>
1.41      www       243: </head>
                    244: $bodytag
1.45      www       245: $helptag<br />
1.26      www       246: <script>
                    247: $swinfo
                    248: window.focus();
                    249: </script>
1.10      www       250: ENDHEADER
1.6       www       251: 
1.2       www       252: # ------------------------------------------ Get Error Message from Environment
                    253: 
                    254:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12      www       255:     if ($ENV{'user.error.msg'}) {
1.55      albertel  256: 	$r->log_reason(
                    257:    "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
1.12      www       258:     }
1.1       harris41  259: 
1.61      www       260: # ------------------------------------------------- Can this user re-init, etc?
1.6       www       261: 
1.61      www       262:     my $advanced=$ENV{'user.adv'};
                    263:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
                    264:     my $tryagain=$ENV{'form.tryagain'};
1.6       www       265: 
1.2       www       266: # -------------------------------------------------------- Generate Page Output
1.6       www       267: # --------------------------------------------------------------- Error Header?
1.2       www       268:     if ($error) {
                    269: 	$r->print("<h1>LON-CAPA Access Control</h1>");
1.4       www       270:         $r->print("<hr><pre>Access  : ".
                    271:                   Apache::lonnet::plaintext($priv)."\n");
                    272:         $r->print("Resource: $fn\n");
                    273:         $r->print("Action  : $msg\n</pre><hr>");
1.2       www       274:     } else {
1.25      www       275:         if ($ENV{'user.error.msg'}) {
                    276: 	    $r->print(
                    277:  '<h3><font color=red>You need to choose another user role or '.
                    278:  'enter a specific course for this function</font></h3>');
                    279: 	}
1.2       www       280:     }
1.6       www       281: # -------------------------------------------------------- Choice or no choice?
1.2       www       282:     if ($nochoose) {
1.6       www       283:         if ($advanced) {
1.55      albertel  284: 	    $r->print("<h2>Assigned User Roles</h2>\n");
1.6       www       285:         } else {
1.55      albertel  286: 	    $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
                    287: 	    if ($ENV{'request.course.id'}) {
                    288: 		$r->print(' another');
                    289: 	    } else {
                    290: 		$r->print(' a certain');
                    291: 	    } 
                    292: 	    $r->print(' course.</body></html>');
                    293: 	    return OK;
1.6       www       294:         } 
                    295:     } else {
                    296:         if ($advanced) {
1.55      albertel  297: 	    $r->print("Your home server is ".
                    298: 		      $Apache::lonnet::hostname{&Apache::lonnet::homeserver
                    299:                       ($ENV{'user.name'},$ENV{'user.domain'})}.
                    300: 		      "<br />\n");
                    301: 	    $r->print("Author and Co-Author roles may not be available on ".
                    302: 		      "servers other than your home server.");
1.6       www       303:         } else {
1.59      albertel  304: 	    $r->print("<h2>Select a Course to Enter</h2>\n");
1.17      www       305:         }
1.18      www       306:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
                    307:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6       www       308:         }
1.11      www       309:         $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6       www       310:         $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
                    311:         $r->print('<input type=hidden name=selectrole value=1>');
                    312:     }
1.63      www       313:     if ($ENV{'user.adv'}) {
                    314: 	$r->print(
                    315: 	      '<br />Show all roles: <input type="checkbox" name="showall"');
                    316: 	if ($ENV{'form.showall'}) { $r->print(' checked'); }
                    317: 	$r->print('><input type=submit value="Display">');
                    318:     }
1.6       www       319: # ----------------------------------------------------------------------- Table
1.63      www       320:     $r->print('<br /><table><tr>');
1.6       www       321:     unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
1.55      albertel  322:     $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
                    323: 	      '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.4       www       324: 
1.3       albertel  325:     foreach $envkey (sort keys %ENV) {
1.35      matthew   326:         my $button = 1;
1.49      www       327:         my $switchserver='';
1.2       www       328:         if ($envkey=~/^user\.role\./) {
1.40      matthew   329: 	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
1.46      matthew   330:             next if (!defined($role) || $role eq '');
1.4       www       331:             my $where=join('.',@pwhere);
1.6       www       332:             my $trolecode=$role.'.'.$where;
1.4       www       333:             my ($tstart,$tend)=split(/\./,$ENV{$envkey});
                    334:             my $tremark='';
                    335:             my $tstatus='is';
                    336:             my $tpstart='&nbsp;';
                    337:             my $tpend='&nbsp;';
1.47      www       338:             my $tfont='#000000';
1.4       www       339:             if ($tstart) {
                    340: 		if ($tstart>$then) { 
1.35      matthew   341:                     $tstatus='future';
                    342:                     if ($tstart<$now) { $tstatus='will'; }
1.4       www       343:                 }
                    344:                 $tpstart=localtime($tstart);
                    345:             }
                    346:             if ($tend) {
1.23      www       347:                 if ($tend<$then) { 
1.35      matthew   348:                     $tstatus='expired'; 
1.23      www       349:                 } elsif ($tend<$now) { 
1.35      matthew   350:                     $tstatus='will_not'; 
1.23      www       351:                 }
1.4       www       352:                 $tpend=localtime($tend);
                    353:             }
1.6       www       354:             if ($ENV{'request.role'} eq $trolecode) {
                    355: 		$tstatus='selected';
                    356:             }
1.4       www       357:             my $tbg;
1.35      matthew   358:             if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
                    359:                 ($ENV{'form.showall'})) {
                    360:                 if ($tstatus eq 'is') {
                    361:                     $tbg='#77FF77';
1.47      www       362:                     $tfont='#003300';
1.35      matthew   363:                 } elsif ($tstatus eq 'future') {
                    364:                     $tbg='#FFFF77';
1.49      www       365:                     $button=0;
1.35      matthew   366:                 } elsif ($tstatus eq 'will') {
                    367:                     $tbg='#FFAA77';
                    368:                     $tremark.='Active at next login. ';
                    369:                 } elsif ($tstatus eq 'expired') {
                    370:                     $tbg='#FF7777';
1.47      www       371:                     $tfont='#330000';
1.49      www       372:                     $button=0;
1.35      matthew   373:                 } elsif ($tstatus eq 'will_not') {
                    374:                     $tbg='#AAFF77';
                    375:                     $tremark.='Expired after logout. ';
                    376:                 } elsif ($tstatus eq 'selected') {
                    377:                     $tbg='#11CC55';
1.47      www       378:                     $tfont='#002200';
1.35      matthew   379:                     $tremark.='Currently selected. ';
                    380:                 }
                    381:                 my $trole;
                    382:                 if ($role =~ /^cr\//) {
                    383:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
                    384:                     $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
                    385:                     $trole=$rrole;
1.8       www       386:                 } else {
1.35      matthew   387:                     $trole=Apache::lonnet::plaintext($role);
                    388:                 }
                    389:                 my $ttype;
                    390:                 my $twhere;
                    391:                 my ($tdom,$trest,$tsection)=
                    392:                     split(/\//,Apache::lonnet::declutter($where));
                    393:                 # First, Co-Authorship roles
                    394:                 if ($role eq 'ca') {
1.39      stredwic  395:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.49      www       396:                     if ($home ne $r->dir_config('lonHostID')) {
                    397: 			$button=0;
1.51      www       398:                         $switchserver=&Apache::lonnet::escape('http://'.
                    399:                          $Apache::lonnet::hostname{$home}.
                    400:                          '/adm/login?domain='.$ENV{'user.domain'}.
                    401: 			  '&username='.$ENV{'user.name'}.
                    402:                           '&firsturl=/priv/'.$trest);
1.49      www       403:                     }
1.35      matthew   404:                     #next if ($home eq 'no_host');
                    405:                     $home = $Apache::lonnet::hostname{$home};
                    406:                     $ttype='Construction Space';
                    407:                     $twhere='User: '.$trest.'<br />Domain: '.$tdom.'<br />'.
                    408:                         ' Server:&nbsp;'.$home;
                    409:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
                    410:                 } elsif ($role eq 'au') {
                    411:                     # Authors
                    412:                     my $home = &Apache::lonnet::homeserver
1.39      stredwic  413:                         ($ENV{'user.name'},$ENV{'user.domain'});
1.49      www       414:                     if ($home ne $r->dir_config('lonHostID')) {
                    415: 			$button=0;
1.51      www       416:                         $switchserver=&Apache::lonnet::escape('http://'.
                    417:                          $Apache::lonnet::hostname{$home}.
                    418:                           '/adm/login?domain='.$ENV{'user.domain'}.
                    419: 			   '&username='.$ENV{'user.name'}.
                    420:                            '&firsturl=/priv/'.$ENV{'user.name'});
1.49      www       421:                     }
1.35      matthew   422:                     #next if ($home eq 'no_host');
                    423:                     $home = $Apache::lonnet::hostname{$home};
                    424:                     $ttype='Construction Space';
                    425:                     $twhere='Domain: '.$tdom.'<br />Server:&nbsp;'.$home;
                    426:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
                    427:                 } elsif ($trest) {
                    428:                     $ttype='Course';
                    429:                     if ($tsection) {
                    430:                         $ttype.='<br>Section/Group: '.$tsection;
1.37      albertel  431: 		    }
1.35      matthew   432:                     my $tcourseid=$tdom.'_'.$trest;
                    433:                     if ($ENV{'course.'.$tcourseid.'.description'}) {
1.47      www       434:                         $twhere=$ENV{'course.'.$tcourseid.'.description'};
                    435:                         unless ($twhere eq 'Currently not available') {
1.55      albertel  436: 			    $twhere.=' <font size="-2">'.
1.49      www       437:         &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont).
                    438:                                     '</font>';
1.55      albertel  439: 			}
1.8       www       440:                     } else {
1.35      matthew   441:                         my %newhash=Apache::lonnet::coursedescription
                    442:                             ($tcourseid);
                    443:                         if (%newhash) {
1.49      www       444:                             $twhere=$newhash{'description'}.
                    445:                               ' <font size="-2">'.
                    446:         &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont).
                    447:                               '</font>';
1.35      matthew   448:                         } else {
                    449:                             $twhere='Currently not available';
                    450:                             $ENV{'course.'.$tcourseid.'.description'}=$twhere;
                    451:                         }
1.8       www       452:                     }
1.37      albertel  453: 		    if ($role ne 'st') { $twhere.="<br />Domain:".$tdom; }
1.35      matthew   454:                 } elsif ($tdom) {
                    455:                     $ttype='Domain';
                    456:                     $twhere=$tdom;
                    457:                 } else {
                    458:                     $ttype='System';
                    459:                     $twhere='system wide';
1.13      www       460:                 }
1.35      matthew   461:  
                    462:                 $r->print('<tr bgcolor='.$tbg.'>');
                    463:                 unless ($nochoose) {
                    464:                     if (!$button) {
1.49      www       465: 			if ($switchserver) {
                    466: 			    $r->print('<td><a href="/adm/logout?handover='.
                    467:                               $switchserver.'">Switch Server</a></td>');
                    468:                         } else {
                    469:                             $r->print('<td>&nbsp;</td>');
                    470:                         }
1.35      matthew   471:                     } elsif ($tstatus eq 'is') {
                    472:                         $r->print('<td><input type=submit value=Select name="'.
                    473:                                   $trolecode.'"></td>');
1.61      www       474:                     } elsif ($tryagain) {
                    475:                         $r->print
                    476:                         ('<td><input type=submit value="Try Selecting Again"'.
                    477:                              ' name="'.$trolecode.'"></td>');
                    478:                     } elsif ($advanced) {
1.35      matthew   479:                         $r->print
                    480:                             ('<td><input type=submit value="Re-Initialize"'.
                    481:                              ' name="'.$trolecode.'"></td>');
                    482:                     } else {
                    483:                         $r->print('<td>&nbsp;</td>');
                    484:                     }
1.6       www       485:                 }
1.57      www       486:                 $tremark.=&Apache::lonannounce::showday(time,1,
                    487:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
                    488:                 
1.55      albertel  489: 		$r->print('<td><font color="'.$tfont.'">'.$trole.
1.47      www       490:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
                    491:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
                    492:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
                    493:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
                    494:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
                    495:                       '&nbsp;</font></td></tr>'."\n");
1.55      albertel  496: 	    }
1.4       www       497:         }
                    498:     }
1.14      www       499:     my $tremark='';
1.47      www       500:     my $tfont='#003300';
1.14      www       501:     if ($ENV{'request.role'} eq 'cm') {
1.19      www       502: 	$r->print('<tr bgcolor="#11CC55">');
1.14      www       503:         $tremark='Currently selected.';
1.47      www       504:         $tfont='#002200';
1.14      www       505:     } else {
                    506:         $r->print('<tr bgcolor="#77FF77">');
                    507:     }
                    508:     unless ($nochoose) {
1.55      albertel  509: 	if ($ENV{'request.role'} ne 'cm') {
                    510: 	    $r->print('<td><input type=submit value=Select name="cm"></td>');
                    511: 	} else {
                    512: 	    $r->print('<td>&nbsp;</td>');
                    513: 	}
1.14      www       514:     }
1.47      www       515:     $r->print('<td colspan=5><font color="'.$tfont.'">No role specified'.
                    516:       '</font></td><td><font color="'.$tfont.'">'.$tremark.
                    517:       '&nbsp;</font></td></tr>'."\n");
1.4       www       518: 
                    519:     $r->print('</table>');
                    520:     unless ($nochoose) {
                    521: 	$r->print("</form>\n");
                    522:     }
1.22      harris41  523: # ------------------------------------------------------------ Privileges Info
1.55      albertel  524:     if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
                    525: 	$r->print('<hr><h2>Current Privileges</h2>');
1.4       www       526: 
1.55      albertel  527: 	foreach $envkey (sort keys %ENV) {
                    528: 	    if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
                    529: 		my $where=$envkey;
                    530: 		$where=~s/^user\.priv\.$ENV{'request.role'}\.//;
                    531: 		my $ttype;
                    532: 		my $twhere;
                    533: 		my ($tdom,$trest,$tsec)=
                    534: 		    split(/\//,Apache::lonnet::declutter($where));
                    535: 		if ($trest) {
                    536: 		    if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
                    537: 			$ttype='Construction Space';
                    538: 			$twhere='User: '.$trest.', Domain: '.$tdom;
                    539: 		    } else {
                    540: 			$ttype='Course';
                    541: 			$twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
                    542: 			if ($tsec) {
                    543: 			    $twhere.=' (Section/Group: '.$tsec.')';
                    544: 			}
                    545: 		    }
                    546: 		} elsif ($tdom) {
                    547: 		    $ttype='Domain';
                    548: 		    $twhere=$tdom;
                    549: 		} else {
                    550: 		    $ttype='System';
                    551: 		    $twhere='/';
                    552: 		}
                    553: 		$r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
                    554: 		foreach (sort split(/:/,$ENV{$envkey})) {
                    555: 		    if ($_) {
                    556: 			my ($prv,$restr)=split(/\&/,$_);
                    557: 			my $trestr='';
                    558: 			if ($restr ne 'F') {
                    559: 			    my $i;
                    560: 			    $trestr.=' (';
                    561: 			    for ($i=0;$i<length($restr);$i++) {
                    562: 				$trestr.=
                    563: 			       Apache::lonnet::plaintext(substr($restr,$i,1));
                    564: 				if ($i<length($restr)-1) { $trestr.=', '; }
                    565: 			    }
                    566: 			    $trestr.=')';
                    567: 			}
                    568: 			$r->print('<li>'.
                    569: 				  Apache::lonnet::plaintext($prv).$trestr.
                    570: 				  '</li>');
                    571: 		    }
                    572: 		}
                    573: 		$r->print('</ul>');
                    574: 	    }
                    575: 	}
1.4       www       576:     }
1.66      www       577:     $r->print(&Apache::lonnet::getannounce());
1.65      www       578:     if ($advanced) {
                    579: 	$r->print('<p><small><i>This is LON-CAPA '.
                    580: 		  $r->dir_config('lonVersion').'</i></small></p>');
                    581:     }
1.1       harris41  582:     $r->print("</body></html>\n");
                    583:     return OK;
                    584: } 
                    585: 
                    586: 1;
                    587: __END__
1.32      harris41  588: 
                    589: =head1 NAME
                    590: 
                    591: Apache::lonroles - User Roles Screen
                    592: 
                    593: =head1 SYNOPSIS
                    594: 
                    595: Invoked by /etc/httpd/conf/srm.conf:
                    596: 
                    597:  <Location /adm/roles>
                    598:  PerlAccessHandler       Apache::lonacc
                    599:  SetHandler perl-script
                    600:  PerlHandler Apache::lonroles
                    601:  ErrorDocument     403 /adm/login
                    602:  ErrorDocument	  500 /adm/errorhandler
                    603:  </Location>
1.64      bowersj2  604: 
                    605: =head1 OVERVIEW
                    606: 
                    607: =head2 Choosing Roles
                    608: 
                    609: C<lonroles> is a handler that allows a user to switch roles in
                    610: mid-session. LON-CAPA attempts to work with "No Role Specified", the
                    611: default role that a user has before selecting a role, as widely as
                    612: possible, but certain handlers for example need specification which
                    613: course they should act on, etc. Both in this scenario, and when the
                    614: handler determines via C<lonnet>'s C<&allowed> function that a certain
                    615: action is not allowed, C<lonroles> is used as error handler. This
                    616: allows the user to select another role which may have permission to do
                    617: what they were trying to do. C<lonroles> can also be accessed via the
                    618: B<CRS> button in the Remote Control. 
                    619: 
                    620: =begin latex
                    621: 
                    622: \begin{figure}
                    623: \begin{center}
                    624: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
                    625:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
                    626: \end{center}
                    627: \end{figure}
                    628: 
                    629: =end latex
                    630: 
                    631: =head2 Role Initialization
                    632: 
                    633: 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<lonnet>'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.
1.32      harris41  634: 
                    635: =head1 INTRODUCTION
                    636: 
                    637: This module enables a user to select what role he wishes to
                    638: operate under (instructor, student, teaching assistant, course
                    639: coordinator, etc).  These roles are pre-established by the actions
                    640: of upper-level users.
                    641: 
                    642: This is part of the LearningOnline Network with CAPA project
                    643: described at http://www.lon-capa.org.
                    644: 
                    645: =head1 HANDLER SUBROUTINE
                    646: 
                    647: This routine is called by Apache and mod_perl.
                    648: 
                    649: =over 4
                    650: 
                    651: =item *
                    652: 
                    653: Roles Initialization (yes/no)
                    654: 
                    655: =item *
                    656: 
                    657: Get Error Message from Environment
                    658: 
                    659: =item *
                    660: 
                    661: Who is this?
                    662: 
                    663: =item *
                    664: 
                    665: Generate Page Output
                    666: 
                    667: =item *
                    668: 
                    669: Choice or no choice
                    670: 
                    671: =item *
                    672: 
                    673: Table
                    674: 
                    675: =item *
                    676: 
                    677: Privileges
                    678: 
                    679: =back
                    680: 
                    681: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>