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

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

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