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

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # User Roles Screen
1.31      www         3: #
1.61    ! www         4: # $Id: lonroles.pm,v 1.60 2003/06/18 13:13:10 www 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: 
                     55: sub handler {
1.10      www        56: 
1.1       harris41   57:     my $r = shift;
                     58: 
1.6       www        59:     my $now=time;
                     60:     my $then=$ENV{'user.login.time'};
                     61:     my $envkey;
                     62: 
1.10      www        63: 
1.6       www        64: # ================================================================== Roles Init
                     65: 
                     66:     if ($ENV{'form.selectrole'}) {
1.33      www        67: 	if ($ENV{'request.course.id'}) {
                     68: 	    my %temp=('logout_'.$ENV{'request.course.id'} => time);
                     69: 	    &Apache::lonnet::put('email_status',\%temp);
                     70:         }
1.55      albertel   71: 	&Apache::lonnet::appenv("request.course.id"   => '',
                     72: 				"request.course.fn"   => '',
                     73: 				"request.course.uri"  => '',
                     74: 				"request.course.sec"  => '',
                     75: 				"request.role"        => 'cm',
1.56      www        76:                                 "request.role.adv"    => $ENV{'user.adv'},
1.55      albertel   77: 				"request.role.domain" => $ENV{'user.domain'});
1.13      www        78:         foreach $envkey (keys %ENV) {
1.40      matthew    79:             next if ($envkey!~/^user\.role\./);
                     80: 	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
1.6       www        81:             my $where=join('.',@pwhere);
                     82:             my $trolecode=$role.'.'.$where;
                     83:             if ($ENV{'form.'.$trolecode}) {
1.55      albertel   84: 		my ($tstart,$tend)=split(/\./,$ENV{$envkey});
                     85: 		my $tstatus='is';
                     86: 		if ($tstart) {
                     87: 		    if ($tstart>$then) { 
                     88: 			$tstatus='future';
                     89: 		    }
                     90: 		}
                     91: 		if ($tend) {
                     92: 		    if ($tend<$then) { $tstatus='expired'; }
                     93: 		    if ($tend<$now) { $tstatus='will_not'; }
                     94: 		}
                     95: 		if ($tstatus eq 'is') {
                     96: 		    $where=~s/^\///;
                     97: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
1.53      www        98: # check for keyed access
1.55      albertel   99: 		    if (($role eq 'st') && 
                    100:                        ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
                    101: 		         unless (&Apache::lonnet::validate_access_key(
                    102: 				     $ENV{'environment.key.'.$cdom.'_'.$cnum},
                    103: 					     $cdom,$cnum)) {
1.53      www       104: # there is no valid key
1.55      albertel  105: 			     if ($ENV{'form.newkey'}) {
1.53      www       106: # student attempts to register a new key
1.55      albertel  107: 			     } else {
1.53      www       108: # print form to enter a new key
1.55      albertel  109: 				 $r->content_type('text/html');
                    110: 				 &Apache::loncommon::no_cache($r);
                    111: 				 $r->send_http_header;
                    112: 				 my $swinfo=&Apache::lonmenu::rawconfig();
                    113: 				 my $bodytag=&Apache::loncommon::bodytag
                    114: 				    ('Enter Access Key to Unlock this Course');
                    115: 				 $r->print(<<ENDENTERKEY);
1.53      www       116: <head><title>Entering Course Access Key</title>
                    117: </head>
                    118: <html>
                    119: $bodytag
                    120: <script>
                    121: $swinfo
                    122: </script>
                    123: <form method="post">
                    124: <input type="hidden" name="selectrole" value="$ENV{'form.selectrole'}" />
                    125: <input type="text" size="20" name="newkey" value="$ENV{'form.newkey'}" />
                    126: <input type="submit" value="Enter key" />
                    127: </form>
                    128: </body></html>
                    129: ENDENTERKEY
1.55      albertel  130: 				 return OK;
                    131: 			     }
                    132: 			 }
                    133: 		     }
1.56      www       134:                     my $tadv=0;
                    135:                     if (($trolecode!~/^st/) && 
                    136:                         ($trolecode!~/^ta/) && 
                    137:                         ($trolecode!~/^cm/)) { $tadv=1; }
                    138: 		    &Apache::lonnet::appenv(
                    139:                                            'request.role'        => $trolecode,
                    140: 					   'request.role.adv'    => $tadv,
                    141: 					   'request.role.domain' => $cdom,
                    142: 					   'request.course.sec'  => $csec);
1.55      albertel  143: 		    my $msg='Entering course ...';
                    144: 		    if (($cnum) && ($role ne 'ca')) {
                    145: 			my ($furl,$ferr)=
                    146: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                    147: 			if (($ENV{'form.orgurl'}) && 
                    148: 			    ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
                    149: 			    $r->internal_redirect($ENV{'form.orgurl'});
                    150: 			    return OK;
                    151: 			} else {
                    152: 			    unless ($ENV{'request.course.id'}) {
                    153: 				&Apache::lonnet::appenv(
                    154: 				      "request.course.id"  => $cdom.'_'.$cnum);
1.61    ! www       155: 				$furl='/adm/roles?tryagain=1';
1.55      albertel  156: 				$msg=
1.60      www       157: 	 '<h1><font color=red>Could not initialize course at this time.</font></h1><h3>Please try again.</h3>';
1.55      albertel  158: 			    }
1.58      bowersj2  159: 
                    160: 			    # Check to see if the user is a CC entering a course 
                    161: 			    # for the first time
                    162: 			    my (undef, undef, $role, $courseid) = split(/\./, $envkey);
                    163: 			    if (substr($courseid, 0, 1) eq '/') {
                    164: 				$courseid = substr($courseid, 1);
                    165: 			    }
                    166: 			    $courseid =~ s/\//_/;
                    167: 			    if ($role eq 'cc' && $ENV{'course.' . $courseid . 
                    168: 							  '.course.helper.not.run'}) {
                    169: 				$furl = "/adm/helper/course.initialization.helper";
                    170: 			    }
                    171: 
1.55      albertel  172: 			    $r->content_type('text/html');
                    173: 			    &Apache::loncommon::no_cache($r);
                    174: 			    $r->send_http_header;
                    175: 			    my $swinfo=&Apache::lonmenu::rawconfig();
                    176: 			    my $bodytag=&Apache::loncommon::bodytag('Switching Role');
                    177: 			    print (<<ENDREDIR);
1.20      www       178: <head><title>Entering Course</title>
                    179: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$furl">
                    180: </head>
                    181: <html>
1.43      www       182: $bodytag
1.26      www       183: <script>
                    184: $swinfo
                    185: </script>
1.43      www       186: <h1>$msg</h1>
1.20      www       187: </body>
                    188: </html>
                    189: ENDREDIR
                    190:                             return OK;
1.55      albertel  191: 			}
                    192: 		    }
                    193: 		}
                    194:             }
1.6       www       195:         }
1.40      matthew   196:     }
1.44      www       197: 
1.10      www       198: 
1.6       www       199: # =============================================================== No Roles Init
1.10      www       200: 
                    201:     $r->content_type('text/html');
1.30      albertel  202:     &Apache::loncommon::no_cache($r);
1.10      www       203:     $r->send_http_header;
                    204:     return OK if $r->header_only;
                    205: 
1.52      www       206:     my $swinfo=&Apache::lonmenu::rawconfig();
1.41      www       207:     my $bodytag=&Apache::loncommon::bodytag('User Roles');
1.48      www       208:     my $helptag=&Apache::loncommon::help_open_topic
1.52      www       209:      ("General_Intro","Click here for help");
1.10      www       210:     $r->print(<<ENDHEADER);
                    211: <html>
                    212: <head>
                    213: <title>LON-CAPA User Roles</title>
1.41      www       214: </head>
                    215: $bodytag
1.45      www       216: $helptag<br />
1.26      www       217: <script>
                    218: $swinfo
                    219: window.focus();
                    220: </script>
1.10      www       221: ENDHEADER
1.6       www       222: 
1.2       www       223: # ------------------------------------------ Get Error Message from Environment
                    224: 
                    225:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12      www       226:     if ($ENV{'user.error.msg'}) {
1.55      albertel  227: 	$r->log_reason(
                    228:    "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
1.12      www       229:     }
1.1       harris41  230: 
1.61    ! www       231: # ------------------------------------------------- Can this user re-init, etc?
1.6       www       232: 
1.61    ! www       233:     my $advanced=$ENV{'user.adv'};
        !           234:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
        !           235:     my $tryagain=$ENV{'form.tryagain'};
1.6       www       236: 
1.2       www       237: # -------------------------------------------------------- Generate Page Output
1.6       www       238: # --------------------------------------------------------------- Error Header?
1.2       www       239:     if ($error) {
                    240: 	$r->print("<h1>LON-CAPA Access Control</h1>");
1.4       www       241:         $r->print("<hr><pre>Access  : ".
                    242:                   Apache::lonnet::plaintext($priv)."\n");
                    243:         $r->print("Resource: $fn\n");
                    244:         $r->print("Action  : $msg\n</pre><hr>");
1.2       www       245:     } else {
1.25      www       246:         if ($ENV{'user.error.msg'}) {
                    247: 	    $r->print(
                    248:  '<h3><font color=red>You need to choose another user role or '.
                    249:  'enter a specific course for this function</font></h3>');
                    250: 	}
1.2       www       251:     }
1.6       www       252: # -------------------------------------------------------- Choice or no choice?
1.2       www       253:     if ($nochoose) {
1.6       www       254:         if ($advanced) {
1.55      albertel  255: 	    $r->print("<h2>Assigned User Roles</h2>\n");
1.6       www       256:         } else {
1.55      albertel  257: 	    $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
                    258: 	    if ($ENV{'request.course.id'}) {
                    259: 		$r->print(' another');
                    260: 	    } else {
                    261: 		$r->print(' a certain');
                    262: 	    } 
                    263: 	    $r->print(' course.</body></html>');
                    264: 	    return OK;
1.6       www       265:         } 
                    266:     } else {
                    267:         if ($advanced) {
1.55      albertel  268: 	    $r->print("Your home server is ".
                    269: 		      $Apache::lonnet::hostname{&Apache::lonnet::homeserver
                    270:                       ($ENV{'user.name'},$ENV{'user.domain'})}.
                    271: 		      "<br />\n");
                    272: 	    $r->print("Author and Co-Author roles may not be available on ".
                    273: 		      "servers other than your home server.");
1.6       www       274:         } else {
1.59      albertel  275: 	    $r->print("<h2>Select a Course to Enter</h2>\n");
1.17      www       276:         }
1.18      www       277:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
                    278:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6       www       279:         }
1.11      www       280:         $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6       www       281:         $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
                    282:         $r->print('<input type=hidden name=selectrole value=1>');
                    283:     }
1.27      www       284:     $r->print('<br>Show all roles: <input type=checkbox name=showall');
                    285:     if ($ENV{'form.showall'}) { $r->print(' checked'); }
                    286:     $r->print('><input type=submit value="Display"><br>');
1.6       www       287: # ----------------------------------------------------------------------- Table
                    288:     $r->print('<table><tr>');
                    289:     unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
1.55      albertel  290:     $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
                    291: 	      '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.4       www       292: 
1.3       albertel  293:     foreach $envkey (sort keys %ENV) {
1.35      matthew   294:         my $button = 1;
1.49      www       295:         my $switchserver='';
1.2       www       296:         if ($envkey=~/^user\.role\./) {
1.40      matthew   297: 	    my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
1.46      matthew   298:             next if (!defined($role) || $role eq '');
1.4       www       299:             my $where=join('.',@pwhere);
1.6       www       300:             my $trolecode=$role.'.'.$where;
1.4       www       301:             my ($tstart,$tend)=split(/\./,$ENV{$envkey});
                    302:             my $tremark='';
                    303:             my $tstatus='is';
                    304:             my $tpstart='&nbsp;';
                    305:             my $tpend='&nbsp;';
1.47      www       306:             my $tfont='#000000';
1.4       www       307:             if ($tstart) {
                    308: 		if ($tstart>$then) { 
1.35      matthew   309:                     $tstatus='future';
                    310:                     if ($tstart<$now) { $tstatus='will'; }
1.4       www       311:                 }
                    312:                 $tpstart=localtime($tstart);
                    313:             }
                    314:             if ($tend) {
1.23      www       315:                 if ($tend<$then) { 
1.35      matthew   316:                     $tstatus='expired'; 
1.23      www       317:                 } elsif ($tend<$now) { 
1.35      matthew   318:                     $tstatus='will_not'; 
1.23      www       319:                 }
1.4       www       320:                 $tpend=localtime($tend);
                    321:             }
1.6       www       322:             if ($ENV{'request.role'} eq $trolecode) {
                    323: 		$tstatus='selected';
                    324:             }
1.4       www       325:             my $tbg;
1.35      matthew   326:             if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
                    327:                 ($ENV{'form.showall'})) {
                    328:                 if ($tstatus eq 'is') {
                    329:                     $tbg='#77FF77';
1.47      www       330:                     $tfont='#003300';
1.35      matthew   331:                 } elsif ($tstatus eq 'future') {
                    332:                     $tbg='#FFFF77';
1.49      www       333:                     $button=0;
1.35      matthew   334:                 } elsif ($tstatus eq 'will') {
                    335:                     $tbg='#FFAA77';
                    336:                     $tremark.='Active at next login. ';
                    337:                 } elsif ($tstatus eq 'expired') {
                    338:                     $tbg='#FF7777';
1.47      www       339:                     $tfont='#330000';
1.49      www       340:                     $button=0;
1.35      matthew   341:                 } elsif ($tstatus eq 'will_not') {
                    342:                     $tbg='#AAFF77';
                    343:                     $tremark.='Expired after logout. ';
                    344:                 } elsif ($tstatus eq 'selected') {
                    345:                     $tbg='#11CC55';
1.47      www       346:                     $tfont='#002200';
1.35      matthew   347:                     $tremark.='Currently selected. ';
                    348:                 }
                    349:                 my $trole;
                    350:                 if ($role =~ /^cr\//) {
                    351:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
                    352:                     $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
                    353:                     $trole=$rrole;
1.8       www       354:                 } else {
1.35      matthew   355:                     $trole=Apache::lonnet::plaintext($role);
                    356:                 }
                    357:                 my $ttype;
                    358:                 my $twhere;
                    359:                 my ($tdom,$trest,$tsection)=
                    360:                     split(/\//,Apache::lonnet::declutter($where));
                    361:                 # First, Co-Authorship roles
                    362:                 if ($role eq 'ca') {
1.39      stredwic  363:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.49      www       364:                     if ($home ne $r->dir_config('lonHostID')) {
                    365: 			$button=0;
1.51      www       366:                         $switchserver=&Apache::lonnet::escape('http://'.
                    367:                          $Apache::lonnet::hostname{$home}.
                    368:                          '/adm/login?domain='.$ENV{'user.domain'}.
                    369: 			  '&username='.$ENV{'user.name'}.
                    370:                           '&firsturl=/priv/'.$trest);
1.49      www       371:                     }
1.35      matthew   372:                     #next if ($home eq 'no_host');
                    373:                     $home = $Apache::lonnet::hostname{$home};
                    374:                     $ttype='Construction Space';
                    375:                     $twhere='User: '.$trest.'<br />Domain: '.$tdom.'<br />'.
                    376:                         ' Server:&nbsp;'.$home;
                    377:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
                    378:                 } elsif ($role eq 'au') {
                    379:                     # Authors
                    380:                     my $home = &Apache::lonnet::homeserver
1.39      stredwic  381:                         ($ENV{'user.name'},$ENV{'user.domain'});
1.49      www       382:                     if ($home ne $r->dir_config('lonHostID')) {
                    383: 			$button=0;
1.51      www       384:                         $switchserver=&Apache::lonnet::escape('http://'.
                    385:                          $Apache::lonnet::hostname{$home}.
                    386:                           '/adm/login?domain='.$ENV{'user.domain'}.
                    387: 			   '&username='.$ENV{'user.name'}.
                    388:                            '&firsturl=/priv/'.$ENV{'user.name'});
1.49      www       389:                     }
1.35      matthew   390:                     #next if ($home eq 'no_host');
                    391:                     $home = $Apache::lonnet::hostname{$home};
                    392:                     $ttype='Construction Space';
                    393:                     $twhere='Domain: '.$tdom.'<br />Server:&nbsp;'.$home;
                    394:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
                    395:                 } elsif ($trest) {
                    396:                     $ttype='Course';
                    397:                     if ($tsection) {
                    398:                         $ttype.='<br>Section/Group: '.$tsection;
1.37      albertel  399: 		    }
1.35      matthew   400:                     my $tcourseid=$tdom.'_'.$trest;
                    401:                     if ($ENV{'course.'.$tcourseid.'.description'}) {
1.47      www       402:                         $twhere=$ENV{'course.'.$tcourseid.'.description'};
                    403:                         unless ($twhere eq 'Currently not available') {
1.55      albertel  404: 			    $twhere.=' <font size="-2">'.
1.49      www       405:         &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont).
                    406:                                     '</font>';
1.55      albertel  407: 			}
1.8       www       408:                     } else {
1.35      matthew   409:                         my %newhash=Apache::lonnet::coursedescription
                    410:                             ($tcourseid);
                    411:                         if (%newhash) {
1.49      www       412:                             $twhere=$newhash{'description'}.
                    413:                               ' <font size="-2">'.
                    414:         &Apache::loncommon::syllabuswrapper('Syllabus',$trest,$tdom,$tfont).
                    415:                               '</font>';
1.35      matthew   416:                         } else {
                    417:                             $twhere='Currently not available';
                    418:                             $ENV{'course.'.$tcourseid.'.description'}=$twhere;
                    419:                         }
1.8       www       420:                     }
1.37      albertel  421: 		    if ($role ne 'st') { $twhere.="<br />Domain:".$tdom; }
1.35      matthew   422:                 } elsif ($tdom) {
                    423:                     $ttype='Domain';
                    424:                     $twhere=$tdom;
                    425:                 } else {
                    426:                     $ttype='System';
                    427:                     $twhere='system wide';
1.13      www       428:                 }
1.35      matthew   429:  
                    430:                 $r->print('<tr bgcolor='.$tbg.'>');
                    431:                 unless ($nochoose) {
                    432:                     if (!$button) {
1.49      www       433: 			if ($switchserver) {
                    434: 			    $r->print('<td><a href="/adm/logout?handover='.
                    435:                               $switchserver.'">Switch Server</a></td>');
                    436:                         } else {
                    437:                             $r->print('<td>&nbsp;</td>');
                    438:                         }
1.35      matthew   439:                     } elsif ($tstatus eq 'is') {
                    440:                         $r->print('<td><input type=submit value=Select name="'.
                    441:                                   $trolecode.'"></td>');
1.61    ! www       442:                     } elsif ($tryagain) {
        !           443:                         $r->print
        !           444:                         ('<td><input type=submit value="Try Selecting Again"'.
        !           445:                              ' name="'.$trolecode.'"></td>');
        !           446:                     } elsif ($advanced) {
1.35      matthew   447:                         $r->print
                    448:                             ('<td><input type=submit value="Re-Initialize"'.
                    449:                              ' name="'.$trolecode.'"></td>');
                    450:                     } else {
                    451:                         $r->print('<td>&nbsp;</td>');
                    452:                     }
1.6       www       453:                 }
1.57      www       454:                 $tremark.=&Apache::lonannounce::showday(time,1,
                    455:                          &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
                    456:                 
1.55      albertel  457: 		$r->print('<td><font color="'.$tfont.'">'.$trole.
1.47      www       458:                       '</font></td><td><font color="'.$tfont.'">'.$ttype.
                    459:                       '</font></td><td><font color="'.$tfont.'">'.$twhere.
                    460:                       '</font></td><td><font color="'.$tfont.'">'.$tpstart.
                    461:                       '</font></td><td><font color="'.$tfont.'">'.$tpend.
                    462:                       '</font></td><td><font color="'.$tfont.'">'.$tremark.
                    463:                       '&nbsp;</font></td></tr>'."\n");
1.55      albertel  464: 	    }
1.4       www       465:         }
                    466:     }
1.14      www       467:     my $tremark='';
1.47      www       468:     my $tfont='#003300';
1.14      www       469:     if ($ENV{'request.role'} eq 'cm') {
1.19      www       470: 	$r->print('<tr bgcolor="#11CC55">');
1.14      www       471:         $tremark='Currently selected.';
1.47      www       472:         $tfont='#002200';
1.14      www       473:     } else {
                    474:         $r->print('<tr bgcolor="#77FF77">');
                    475:     }
                    476:     unless ($nochoose) {
1.55      albertel  477: 	if ($ENV{'request.role'} ne 'cm') {
                    478: 	    $r->print('<td><input type=submit value=Select name="cm"></td>');
                    479: 	} else {
                    480: 	    $r->print('<td>&nbsp;</td>');
                    481: 	}
1.14      www       482:     }
1.47      www       483:     $r->print('<td colspan=5><font color="'.$tfont.'">No role specified'.
                    484:       '</font></td><td><font color="'.$tfont.'">'.$tremark.
                    485:       '&nbsp;</font></td></tr>'."\n");
1.4       www       486: 
                    487:     $r->print('</table>');
                    488:     unless ($nochoose) {
                    489: 	$r->print("</form>\n");
                    490:     }
1.22      harris41  491: # ------------------------------------------------------------ Privileges Info
1.55      albertel  492:     if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
                    493: 	$r->print('<hr><h2>Current Privileges</h2>');
1.4       www       494: 
1.55      albertel  495: 	foreach $envkey (sort keys %ENV) {
                    496: 	    if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
                    497: 		my $where=$envkey;
                    498: 		$where=~s/^user\.priv\.$ENV{'request.role'}\.//;
                    499: 		my $ttype;
                    500: 		my $twhere;
                    501: 		my ($tdom,$trest,$tsec)=
                    502: 		    split(/\//,Apache::lonnet::declutter($where));
                    503: 		if ($trest) {
                    504: 		    if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
                    505: 			$ttype='Construction Space';
                    506: 			$twhere='User: '.$trest.', Domain: '.$tdom;
                    507: 		    } else {
                    508: 			$ttype='Course';
                    509: 			$twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
                    510: 			if ($tsec) {
                    511: 			    $twhere.=' (Section/Group: '.$tsec.')';
                    512: 			}
                    513: 		    }
                    514: 		} elsif ($tdom) {
                    515: 		    $ttype='Domain';
                    516: 		    $twhere=$tdom;
                    517: 		} else {
                    518: 		    $ttype='System';
                    519: 		    $twhere='/';
                    520: 		}
                    521: 		$r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
                    522: 		foreach (sort split(/:/,$ENV{$envkey})) {
                    523: 		    if ($_) {
                    524: 			my ($prv,$restr)=split(/\&/,$_);
                    525: 			my $trestr='';
                    526: 			if ($restr ne 'F') {
                    527: 			    my $i;
                    528: 			    $trestr.=' (';
                    529: 			    for ($i=0;$i<length($restr);$i++) {
                    530: 				$trestr.=
                    531: 			       Apache::lonnet::plaintext(substr($restr,$i,1));
                    532: 				if ($i<length($restr)-1) { $trestr.=', '; }
                    533: 			    }
                    534: 			    $trestr.=')';
                    535: 			}
                    536: 			$r->print('<li>'.
                    537: 				  Apache::lonnet::plaintext($prv).$trestr.
                    538: 				  '</li>');
                    539: 		    }
                    540: 		}
                    541: 		$r->print('</ul>');
                    542: 	    }
                    543: 	}
1.4       www       544:     }
1.2       www       545: 
1.1       harris41  546:     $r->print("</body></html>\n");
                    547:     return OK;
                    548: } 
                    549: 
                    550: 1;
                    551: __END__
1.32      harris41  552: 
                    553: =head1 NAME
                    554: 
                    555: Apache::lonroles - User Roles Screen
                    556: 
                    557: =head1 SYNOPSIS
                    558: 
                    559: Invoked by /etc/httpd/conf/srm.conf:
                    560: 
                    561:  <Location /adm/roles>
                    562:  PerlAccessHandler       Apache::lonacc
                    563:  SetHandler perl-script
                    564:  PerlHandler Apache::lonroles
                    565:  ErrorDocument     403 /adm/login
                    566:  ErrorDocument	  500 /adm/errorhandler
                    567:  </Location>
                    568: 
                    569: =head1 INTRODUCTION
                    570: 
                    571: This module enables a user to select what role he wishes to
                    572: operate under (instructor, student, teaching assistant, course
                    573: coordinator, etc).  These roles are pre-established by the actions
                    574: of upper-level users.
                    575: 
                    576: This is part of the LearningOnline Network with CAPA project
                    577: described at http://www.lon-capa.org.
                    578: 
                    579: =head1 HANDLER SUBROUTINE
                    580: 
                    581: This routine is called by Apache and mod_perl.
                    582: 
                    583: =over 4
                    584: 
                    585: =item *
                    586: 
                    587: Roles Initialization (yes/no)
                    588: 
                    589: =item *
                    590: 
                    591: Get Error Message from Environment
                    592: 
                    593: =item *
                    594: 
                    595: Who is this?
                    596: 
                    597: =item *
                    598: 
                    599: Generate Page Output
                    600: 
                    601: =item *
                    602: 
                    603: Choice or no choice
                    604: 
                    605: =item *
                    606: 
                    607: Table
                    608: 
                    609: =item *
                    610: 
                    611: Privileges
                    612: 
                    613: =back
                    614: 
                    615: =cut

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