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

1.1       harris41    1: # The LearningOnline Network with CAPA
                      2: # User Roles Screen
1.31      www         3: #
1.117   ! albertel    4: # $Id: lonroles.pm,v 1.116 2005/03/03 07:16:44 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.32      harris41   28: ###
1.22      harris41   29: 
1.1       harris41   30: package Apache::lonroles;
                     31: 
                     32: use strict;
                     33: use Apache::lonnet();
1.7       www        34: use Apache::lonuserstate();
1.1       harris41   35: use Apache::Constants qw(:common);
1.2       www        36: use Apache::File();
1.26      www        37: use Apache::lonmenu;
1.29      albertel   38: use Apache::loncommon;
1.104     raeburn    39: use Apache::lonhtmlcommon;
1.57      www        40: use Apache::lonannounce;
1.72      www        41: use Apache::lonlocal;
1.1       harris41   42: 
1.62      matthew    43: sub redirect_user {
1.95      albertel   44:     my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62      matthew    45:     $msg = $title if (! defined($msg));
1.73      www        46:     &Apache::loncommon::content_type($r,'text/html');
1.62      matthew    47:     &Apache::loncommon::no_cache($r);
                     48:     $r->send_http_header;
                     49:     my $swinfo=&Apache::lonmenu::rawconfig();
1.96      albertel   50:     my $navwindow;
1.95      albertel   51:     if ($launch_nav eq 'on') {
1.96      albertel   52: 	$navwindow.=&Apache::lonnavmaps::launch_win('now');
                     53:     } else {
                     54: 	$navwindow.=&Apache::lonnavmaps::close();
1.95      albertel   55:     }
1.62      matthew    56:     my $bodytag=&Apache::loncommon::bodytag('Switching Role');
1.92      www        57: # Note to style police: 
                     58: # This must only replace the spaces, nothing else, or it bombs elsewhere.
                     59:     $url=~s/ /\%20/g;
1.93      albertel   60:     $r->print(<<ENDREDIR);
1.62      matthew    61: <head><title>$title</title>
                     62: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">
                     63: </head>
                     64: <html>
                     65: $bodytag
1.96      albertel   66: <script type="text/javascript">
1.62      matthew    67: $swinfo
                     68: </script>
1.96      albertel   69: $navwindow
1.62      matthew    70: <h1>$msg</h1>
1.95      albertel   71: <a href="$url">Continue</a>
1.62      matthew    72: </body>
                     73: </html>
                     74: ENDREDIR
                     75:     return;
                     76: }
                     77: 
1.1       harris41   78: sub handler {
1.10      www        79: 
1.1       harris41   80:     my $r = shift;
                     81: 
1.6       www        82:     my $now=time;
                     83:     my $then=$ENV{'user.login.time'};
                     84:     my $envkey;
1.107     raeburn    85:     my %dcroles = ();
                     86:     my $numdc = &check_fordc(\%dcroles,$then);
1.10      www        87: 
1.6       www        88: # ================================================================== Roles Init
                     89:     if ($ENV{'form.selectrole'}) {
1.33      www        90: 	if ($ENV{'request.course.id'}) {
                     91: 	    my %temp=('logout_'.$ENV{'request.course.id'} => time);
                     92: 	    &Apache::lonnet::put('email_status',\%temp);
1.100     albertel   93: 	    &Apache::lonnet::delenv('user.state.'.$ENV{'request.course.id'});
                     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.106     raeburn   102: 
1.110     raeburn   103: # Check if user is a DC trying to enter a course and needs privs to be created
1.107     raeburn   104:         if ($numdc > 0) {
                    105:             foreach my $envkey (keys %ENV) {
                    106:                 if ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-) {
                    107:                     if ($dcroles{$1}) {
1.109     raeburn   108:                         my $cckey = 'user.role.cc./'.$1.'/'.$2;
1.110     raeburn   109:                         &check_privs($cckey,$then,$now);
1.107     raeburn   110:                     }
                    111:                     last;
                    112:                 }
                    113:             }
                    114:         }
                    115: 
1.13      www       116:         foreach $envkey (keys %ENV) {
1.40      matthew   117:             next if ($envkey!~/^user\.role\./);
1.102     raeburn   118:             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
                    119:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.6       www       120:             if ($ENV{'form.'.$trolecode}) {
1.55      albertel  121: 		if ($tstatus eq 'is') {
                    122: 		    $where=~s/^\///;
                    123: 		    my ($cdom,$cnum,$csec)=split(/\//,$where);
1.111     albertel  124: # store role if recent_role list being kept
                    125:                     if ($ENV{'environment.recentroles'}) {
                    126: 			&Apache::lonhtmlcommon::store_recent('roles',
                    127: 							     $trolecode,' ');
                    128:                     }
                    129: 
                    130: 
1.53      www       131: # check for keyed access
1.55      albertel  132: 		    if (($role eq 'st') && 
                    133:                        ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89      www       134: # who is key authority?
                    135: 			my $authdom=$cdom;
                    136: 			my $authnum=$cnum;
                    137: 			if ($ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
                    138: 			    ($authnum,$authdom)=
                    139: 				split(/\W/,$ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'});
                    140: 			}
                    141: # check with key authority
                    142: 			unless (&Apache::lonnet::validate_access_key(
1.55      albertel  143: 				     $ENV{'environment.key.'.$cdom.'_'.$cnum},
1.89      www       144: 					     $authdom,$authnum)) {
1.53      www       145: # there is no valid key
1.55      albertel  146: 			     if ($ENV{'form.newkey'}) {
1.53      www       147: # student attempts to register a new key
1.89      www       148: 				 &Apache::loncommon::content_type($r,'text/html');
                    149: 				 &Apache::loncommon::no_cache($r);
                    150: 				 $r->send_http_header;
                    151: 				 my $swinfo=&Apache::lonmenu::rawconfig();
                    152: 				 my $bodytag=&Apache::loncommon::bodytag
                    153: 				    ('Verifying Access Key to Unlock this Course');
1.90      www       154: 				 my $buttontext=&mt('Enter Course');
                    155: 				 my $message=&mt('Successfully registered key');
                    156: 				 my $assignresult=
                    157: 				     &Apache::lonnet::assign_access_key(
                    158: 						     $ENV{'form.newkey'},
                    159: 						     $authdom,$authnum,
1.91      www       160: 						     $cdom,$cnum,
1.90      www       161:                                                      $ENV{'user.domain'},
                    162: 						     $ENV{'user.name'},
                    163: 	      'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
                    164:                                                      $trolecode);
                    165: 				 unless ($assignresult eq 'ok') {
                    166: 				     $assignresult=~s/^error\:\s*//;
                    167: 				     $message=&mt($assignresult).
                    168: 				     '<br /><a href="/adm/logout">'.
1.89      www       169: 				     &mt('Logout').'</a>';
1.90      www       170: 				     $buttontext=&mt('Re-Enter Key');
                    171: 				 }
1.89      www       172: 				 $r->print(<<ENDENTEREDKEY);
                    173: <head><title>Verifying Course Access Key</title>
                    174: </head>
                    175: <html>
                    176: $bodytag
                    177: <script>
                    178: $swinfo
                    179: </script>
                    180: <form method="post">
                    181: <input type="hidden" name="selectrole" value="1" />
                    182: <input type="hidden" name="$trolecode" value="1" />
1.90      www       183: <font size="+2">$message</font><br />
1.89      www       184: <input type="submit" value="$buttontext" />
                    185: </form>
                    186: </body></html>
                    187: ENDENTEREDKEY
                    188:                                  return OK;
1.55      albertel  189: 			     } else {
1.53      www       190: # print form to enter a new key
1.73      www       191: 				 &Apache::loncommon::content_type($r,'text/html');
1.55      albertel  192: 				 &Apache::loncommon::no_cache($r);
                    193: 				 $r->send_http_header;
                    194: 				 my $swinfo=&Apache::lonmenu::rawconfig();
                    195: 				 my $bodytag=&Apache::loncommon::bodytag
                    196: 				    ('Enter Access Key to Unlock this Course');
                    197: 				 $r->print(<<ENDENTERKEY);
1.53      www       198: <head><title>Entering Course Access Key</title>
                    199: </head>
                    200: <html>
                    201: $bodytag
                    202: <script>
                    203: $swinfo
                    204: </script>
                    205: <form method="post">
1.89      www       206: <input type="hidden" name="selectrole" value="1" />
                    207: <input type="hidden" name="$trolecode" value="1" />
1.53      www       208: <input type="text" size="20" name="newkey" value="$ENV{'form.newkey'}" />
                    209: <input type="submit" value="Enter key" />
                    210: </form>
                    211: </body></html>
                    212: ENDENTERKEY
1.55      albertel  213: 				 return OK;
                    214: 			     }
                    215: 			 }
                    216: 		     }
1.87      www       217: 		    &Apache::lonnet::log($ENV{'user.domain'},
                    218: 					 $ENV{'user.name'},
                    219: 					 $ENV{'user.home'},
                    220: 					 "Role ".$trolecode);
1.101     albertel  221: 		    
1.56      www       222: 		    &Apache::lonnet::appenv(
1.101     albertel  223: 					   'request.role'        => $trolecode,
1.56      www       224: 					   'request.role.domain' => $cdom,
                    225: 					   'request.course.sec'  => $csec);
1.101     albertel  226:                     my $tadv=0;
1.72      www       227: 		    my $msg=&mt('Entering course ...');
1.62      matthew   228: 
1.55      albertel  229: 		    if (($cnum) && ($role ne 'ca')) {
                    230: 			my ($furl,$ferr)=
                    231: 			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                    232: 			if (($ENV{'form.orgurl'}) && 
                    233: 			    ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.67      albertel  234: 			    my $dest=$ENV{'form.orgurl'};
1.71      albertel  235: 			    if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.67      albertel  236: 				&Apache::lonnet::cleanenv();
1.69      albertel  237: 			    }
1.117   ! albertel  238: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
        !           239: 			    &Apache::lonnet::appenv('request.role.adv'=>$tadv);
1.67      albertel  240: 			    $r->internal_redirect($dest);
1.55      albertel  241: 			    return OK;
                    242: 			} else {
                    243: 			    unless ($ENV{'request.course.id'}) {
                    244: 				&Apache::lonnet::appenv(
                    245: 				      "request.course.id"  => $cdom.'_'.$cnum);
1.61      www       246: 				$furl='/adm/roles?tryagain=1';
1.55      albertel  247: 				$msg=
1.72      www       248: 				    '<h1><font color=red>'.
                    249: 			 &mt('Could not initialize course at this time.').
                    250: 		    '</font></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
1.55      albertel  251: 			    }
1.117   ! albertel  252: 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
        !           253: 			    &Apache::lonnet::appenv('request.role.adv'=>$tadv);
1.58      bowersj2  254: 
                    255: 			    # Check to see if the user is a CC entering a course 
                    256: 			    # for the first time
                    257: 			    my (undef, undef, $role, $courseid) = split(/\./, $envkey);
                    258: 			    if (substr($courseid, 0, 1) eq '/') {
                    259: 				$courseid = substr($courseid, 1);
                    260: 			    }
                    261: 			    $courseid =~ s/\//_/;
                    262: 			    if ($role eq 'cc' && $ENV{'course.' . $courseid . 
                    263: 							  '.course.helper.not.run'}) {
                    264: 				$furl = "/adm/helper/course.initialization.helper";
                    265: 			    }
1.62      matthew   266:                             # Send the user to the course they selected
1.78      sakharuk  267:                             &redirect_user($r,&mt('Entering Course'),
1.95      albertel  268:                                            $furl,$msg,
                    269: 					   $ENV{'environment.remotenavmap'});
1.20      www       270:                             return OK;
1.55      albertel  271: 			}
                    272: 		    }
1.62      matthew   273:                     #
                    274:                     # Send the user to the construction space they selected
                    275:                     if ($role =~ /^(au|ca)$/) {
                    276:                         my $redirect_url = '/priv/';
                    277:                         if ($role eq 'au') {
                    278:                             $redirect_url.=$ENV{'user.name'};
                    279:                         } else {
                    280:                             $where =~ /\/(.*)$/;
                    281:                             $redirect_url .= $1;
                    282:                         }
                    283:                         $redirect_url .= '/';
1.78      sakharuk  284:                         &redirect_user($r,&mt('Entering Construction Space'),
1.62      matthew   285:                                        $redirect_url);
                    286:                         return OK;
                    287:                     }
1.104     raeburn   288:                     if ($role eq 'dc') {
1.108     raeburn   289:                         my $redirect_url = '/adm/menu/';
                    290:                         &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104     raeburn   291:                                        $redirect_url);
1.108     raeburn   292:                         return OK;
1.104     raeburn   293:                     }
1.55      albertel  294: 		}
                    295:             }
1.6       www       296:         }
1.40      matthew   297:     }
1.44      www       298: 
1.10      www       299: 
1.6       www       300: # =============================================================== No Roles Init
1.10      www       301: 
1.73      www       302:     &Apache::loncommon::content_type($r,'text/html');
1.30      albertel  303:     &Apache::loncommon::no_cache($r);
1.10      www       304:     $r->send_http_header;
                    305:     return OK if $r->header_only;
                    306: 
1.52      www       307:     my $swinfo=&Apache::lonmenu::rawconfig();
1.41      www       308:     my $bodytag=&Apache::loncommon::bodytag('User Roles');
1.94      albertel  309:     my $helptag='<table><tr><td>'.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','User Roles',1,undef,undef,undef,undef,,&mt("Click here for help")).'</td></td></tr></table>';
1.10      www       310:     $r->print(<<ENDHEADER);
                    311: <html>
                    312: <head>
                    313: <title>LON-CAPA User Roles</title>
1.41      www       314: </head>
                    315: $bodytag
1.45      www       316: $helptag<br />
1.26      www       317: <script>
                    318: $swinfo
                    319: window.focus();
                    320: </script>
1.10      www       321: ENDHEADER
1.6       www       322: 
1.2       www       323: # ------------------------------------------ Get Error Message from Environment
                    324: 
                    325:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12      www       326:     if ($ENV{'user.error.msg'}) {
1.55      albertel  327: 	$r->log_reason(
                    328:    "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
1.12      www       329:     }
1.1       harris41  330: 
1.61      www       331: # ------------------------------------------------- Can this user re-init, etc?
1.6       www       332: 
1.61      www       333:     my $advanced=$ENV{'user.adv'};
                    334:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
                    335:     my $tryagain=$ENV{'form.tryagain'};
1.6       www       336: 
1.2       www       337: # -------------------------------------------------------- Generate Page Output
1.6       www       338: # --------------------------------------------------------------- Error Header?
1.2       www       339:     if ($error) {
                    340: 	$r->print("<h1>LON-CAPA Access Control</h1>");
1.4       www       341:         $r->print("<hr><pre>Access  : ".
                    342:                   Apache::lonnet::plaintext($priv)."\n");
1.115     albertel  343:         $r->print("Resource: ".&Apache::lonenc::check_encrypt($fn)."\n");
1.4       www       344:         $r->print("Action  : $msg\n</pre><hr>");
1.2       www       345:     } else {
1.25      www       346:         if ($ENV{'user.error.msg'}) {
                    347: 	    $r->print(
1.72      www       348:  '<h3><font color=red>'.
                    349:  &mt('You need to choose another user role or enter a specific course for this function').'</font></h3>');
1.25      www       350: 	}
1.2       www       351:     }
1.6       www       352: # -------------------------------------------------------- Choice or no choice?
1.2       www       353:     if ($nochoose) {
1.6       www       354:         if ($advanced) {
1.72      www       355: 	    $r->print("<h2>".&mt('Assigned User Roles')."</h2>\n");
1.6       www       356:         } else {
1.72      www       357: 	    $r->print("<h2>".&mt('Sorry ...')."</h2>\n".
                    358: 		      &mt('This resource might be part of'));
1.55      albertel  359: 	    if ($ENV{'request.course.id'}) {
1.72      www       360: 		$r->print(&mt(' another'));
1.55      albertel  361: 	    } else {
1.72      www       362: 		$r->print(&mt(' a certain'));
1.55      albertel  363: 	    } 
1.72      www       364: 	    $r->print(&mt(' course.').'</body></html>');
1.55      albertel  365: 	    return OK;
1.6       www       366:         } 
                    367:     } else {
                    368:         if ($advanced) {
1.72      www       369: 	    $r->print(&mt("Your home server is ").
1.55      albertel  370: 		      $Apache::lonnet::hostname{&Apache::lonnet::homeserver
                    371:                       ($ENV{'user.name'},$ENV{'user.domain'})}.
                    372: 		      "<br />\n");
1.72      www       373: 	    $r->print(&mt(
                    374:       "Author and Co-Author roles may not be available on servers other than your home server."));
1.17      www       375:         }
1.18      www       376:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
                    377:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6       www       378:         }
1.84      www       379:         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116     albertel  380:         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
                    381:         $r->print('<input type="hidden" name="selectrole" value="1" />');
1.6       www       382:     }
1.63      www       383:     if ($ENV{'user.adv'}) {
                    384: 	$r->print(
1.116     albertel  385: 	      '<br /><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
                    386: 	if ($ENV{'form.showall'}) { $r->print(' checked="checked" '); }
                    387: 	$r->print(' /></label><input type="submit" value="'.&mt('Display').'" />');
1.63      www       388:     }
1.4       www       389: 
1.75      albertel  390:     my (%roletext,%sortrole,%roleclass);
1.84      www       391:     my $countactive=0;
                    392:     my $inrole=0;
                    393:     my $possiblerole='';
1.3       albertel  394:     foreach $envkey (sort keys %ENV) {
1.35      matthew   395:         my $button = 1;
1.49      www       396:         my $switchserver='';
1.75      albertel  397: 	my $roletext;
                    398: 	my $sortkey;
1.2       www       399:         if ($envkey=~/^user\.role\./) {
1.102     raeburn   400:             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
                    401:             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.46      matthew   402:             next if (!defined($role) || $role eq '');
1.102     raeburn   403:             $tremark='';
                    404:             $tpstart='&nbsp;';
                    405:             $tpend='&nbsp;';
                    406:             $tfont='#000000';
1.4       www       407:             if ($tstart) {
1.74      www       408:                 $tpstart=&Apache::lonlocal::locallocaltime($tstart);
1.4       www       409:             }
                    410:             if ($tend) {
1.74      www       411:                 $tpend=&Apache::lonlocal::locallocaltime($tend);
1.4       www       412:             }
1.6       www       413:             if ($ENV{'request.role'} eq $trolecode) {
                    414: 		$tstatus='selected';
                    415:             }
1.4       www       416:             my $tbg;
1.35      matthew   417:             if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
                    418:                 ($ENV{'form.showall'})) {
                    419:                 if ($tstatus eq 'is') {
                    420:                     $tbg='#77FF77';
1.47      www       421:                     $tfont='#003300';
1.84      www       422: 		    $possiblerole=$trolecode;
                    423: 		    $countactive++;
1.35      matthew   424:                 } elsif ($tstatus eq 'future') {
                    425:                     $tbg='#FFFF77';
1.49      www       426:                     $button=0;
1.35      matthew   427:                 } elsif ($tstatus eq 'will') {
                    428:                     $tbg='#FFAA77';
1.72      www       429:                     $tremark.=&mt('Active at next login. ');
1.35      matthew   430:                 } elsif ($tstatus eq 'expired') {
                    431:                     $tbg='#FF7777';
1.47      www       432:                     $tfont='#330000';
1.49      www       433:                     $button=0;
1.35      matthew   434:                 } elsif ($tstatus eq 'will_not') {
                    435:                     $tbg='#AAFF77';
1.72      www       436:                     $tremark.=&mt('Expired after logout. ');
1.35      matthew   437:                 } elsif ($tstatus eq 'selected') {
                    438:                     $tbg='#11CC55';
1.47      www       439:                     $tfont='#002200';
1.84      www       440: 		    $inrole=1;
1.86      albertel  441: 		    $countactive++;
1.72      www       442:                     $tremark.=&mt('Currently selected. ');
1.35      matthew   443:                 }
                    444:                 my $trole;
                    445:                 if ($role =~ /^cr\//) {
                    446:                     my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.72      www       447:                     $tremark.='<br>'.&mt('Defined by ').$rauthor.
                    448: 			&mt(' at ').$rdomain.'.';
1.35      matthew   449:                     $trole=$rrole;
1.8       www       450:                 } else {
1.35      matthew   451:                     $trole=Apache::lonnet::plaintext($role);
                    452:                 }
                    453:                 my $ttype;
                    454:                 my $twhere;
                    455:                 my ($tdom,$trest,$tsection)=
                    456:                     split(/\//,Apache::lonnet::declutter($where));
                    457:                 # First, Co-Authorship roles
                    458:                 if ($role eq 'ca') {
1.39      stredwic  459:                     my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83      albertel  460: 		    my $allowed=0;
                    461: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    462: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    463:                     if (!$allowed) {
1.49      www       464: 			$button=0;
1.51      www       465:                         $switchserver=&Apache::lonnet::escape('http://'.
                    466:                          $Apache::lonnet::hostname{$home}.
                    467:                          '/adm/login?domain='.$ENV{'user.domain'}.
                    468: 			  '&username='.$ENV{'user.name'}.
1.97      albertel  469:                           '&firsturl=/priv/'.$trest.'/');
1.49      www       470:                     }
1.35      matthew   471:                     #next if ($home eq 'no_host');
                    472:                     $home = $Apache::lonnet::hostname{$home};
1.78      sakharuk  473:                     $ttype='Construction Space';
1.72      www       474:                     $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
                    475: 			': '.$tdom.'<br />'.
                    476:                         ' '.&mt('Server').':&nbsp;'.$home;
1.35      matthew   477:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82      www       478: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75      albertel  479: 		    $sortkey=$role."$trest:$tdom";
1.35      matthew   480:                 } elsif ($role eq 'au') {
                    481:                     # Authors
                    482:                     my $home = &Apache::lonnet::homeserver
1.39      stredwic  483:                         ($ENV{'user.name'},$ENV{'user.domain'});
1.83      albertel  484: 		    my $allowed=0;
                    485: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    486: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    487:                     if (!$allowed) {
1.49      www       488: 			$button=0;
1.51      www       489:                         $switchserver=&Apache::lonnet::escape('http://'.
                    490:                          $Apache::lonnet::hostname{$home}.
                    491:                           '/adm/login?domain='.$ENV{'user.domain'}.
                    492: 			   '&username='.$ENV{'user.name'}.
1.97      albertel  493:                            '&firsturl=/priv/'.$ENV{'user.name'}.'/');
1.49      www       494:                     }
1.35      matthew   495:                     #next if ($home eq 'no_host');
                    496:                     $home = $Apache::lonnet::hostname{$home};
1.78      sakharuk  497:                     $ttype='Construction Space';
1.72      www       498:                     $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
                    499: 			':&nbsp;'.$home;
1.35      matthew   500:                     $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82      www       501: 		    $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/');
1.75      albertel  502: 		    $sortkey=$role;
1.35      matthew   503:                 } elsif ($trest) {
1.78      sakharuk  504:                     $ttype='Course';
1.35      matthew   505:                     if ($tsection) {
1.72      www       506:                         $ttype.='<br>'.&mt('Section/Group').': '.$tsection;
1.37      albertel  507: 		    }
1.35      matthew   508:                     my $tcourseid=$tdom.'_'.$trest;
                    509:                     if ($ENV{'course.'.$tcourseid.'.description'}) {
1.47      www       510:                         $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.80      albertel  511: 			$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72      www       512:                         unless ($twhere eq &mt('Currently not available')) {
1.55      albertel  513: 			    $twhere.=' <font size="-2">'.
1.72      www       514:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49      www       515:                                     '</font>';
1.55      albertel  516: 			}
1.8       www       517:                     } else {
1.105     raeburn   518:                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1.35      matthew   519:                         if (%newhash) {
1.80      albertel  520: 			    $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77      albertel  521: 				"\0".$envkey;
1.49      www       522:                             $twhere=$newhash{'description'}.
                    523:                               ' <font size="-2">'.
1.72      www       524:         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49      www       525:                               '</font>';
1.35      matthew   526:                         } else {
1.72      www       527:                             $twhere=&mt('Currently not available');
1.35      matthew   528:                             $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.80      albertel  529: 			    $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.35      matthew   530:                         }
1.8       www       531:                     }
1.72      www       532: 		    if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35      matthew   533:                 } elsif ($tdom) {
1.78      sakharuk  534:                     $ttype='Domain';
1.35      matthew   535:                     $twhere=$tdom;
1.75      albertel  536: 		    $sortkey=$role.$twhere;
1.35      matthew   537:                 } else {
1.78      sakharuk  538:                     $ttype='System';
1.72      www       539:                     $twhere=&mt('system wide');
1.75      albertel  540: 		    $sortkey=$role.$twhere;
1.13      www       541:                 }
1.35      matthew   542:  
1.110     raeburn   543:                 $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$ttype,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
1.75      albertel  544: 		$roletext{$envkey}=$roletext;
                    545: 		if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
                    546: 		$sortrole{$sortkey}=$envkey;
                    547: 		$roleclass{$envkey}=$ttype;
1.55      albertel  548: 	    }
1.4       www       549:         }
1.75      albertel  550:     }
1.84      www       551: # No active roles
                    552:     if ($countactive==0) {
                    553: 	if ($inrole) {
                    554: 	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
                    555: 	} else {
                    556: 	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
                    557: 	}
                    558: 	$r->print('</form></body></html>');
                    559: 	return OK;
                    560: # Is there only one choice?
1.88      www       561:     } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) {
1.84      www       562: 	$r->print('<h3>'.&mt('Please stand by.').'</h3>'.
                    563: 	    '<input type="hidden" name="'.$possiblerole.'" value="1" />');
                    564: 	$r->print("</form>\n");
                    565: 	$r->rflush();
                    566: 	$r->print('<script>document.forms.rolechoice.submit();</script>');
                    567: 	$r->print('</body></html>');
                    568: 	return OK;
                    569:     }
                    570: # More than one possible role
                    571: # ----------------------------------------------------------------------- Table
                    572:     unless (($advanced) || ($nochoose)) {
                    573: 	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
                    574:     }
                    575:     $r->print('<br /><table><tr>');
                    576:     unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
                    577:     $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
                    578:          '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
1.99      www       579: 	      &mt('Remarks and Calendar Announcements').'</th></tr>'."\n");
1.76      albertel  580:     my $doheaders=-1;
1.78      sakharuk  581:     foreach my $type ('Construction Space','Course','Domain','System') {
1.76      albertel  582: 	my $haverole=0;
1.75      albertel  583: 	foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
                    584: 	    if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
1.76      albertel  585: 		$haverole=1;
1.75      albertel  586: 	    }
1.76      albertel  587: 	}
                    588: 	if ($haverole) { $doheaders++; }
                    589:     }
1.111     albertel  590: 
                    591:     if ($ENV{'environment.recentroles'}) {
                    592:         my %recent_roles =
                    593:                &Apache::lonhtmlcommon::get_recent('roles',$ENV{'environment.recentrolesn'});
                    594: 	my $output='';
                    595: 	foreach (sort(keys(%recent_roles))) {
                    596: 	    if (defined($roletext{'user.role.'.$_})) {
                    597: 		$output.=$roletext{'user.role.'.$_};
1.113     raeburn   598: 	    } elsif ($numdc > 0) {
                    599:                 unless ($_ =~/^error\:/) {
                    600:                     $output.=&display_cc_role('user.role.'.$_);
                    601:                 }
                    602:             } 
1.111     albertel  603: 	}
                    604: 	if ($output) {
                    605: 	    $r->print("<tr bgcolor='#BBffBB'><td align='center' colspan='7'>".
                    606: 		      &mt('Recent Roles')."</td>");
                    607: 	    $r->print($output);
                    608: 	    $r->print("</tr>");
1.114     raeburn   609:             $doheaders ++;
1.111     albertel  610: 	}
                    611:     }
                    612: 
1.104     raeburn   613:     if ($numdc > 0) {
1.112     raeburn   614:         $r->print(&coursepick_jscript());
                    615:         $r->print(&Apache::loncommon::coursebrowser_javascript());
1.108     raeburn   616:     }
                    617:     foreach my $type ('Construction Space','Course','Domain','System') {
                    618: 	my $output;
                    619: 	foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
                    620: 	    if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
                    621: 		$output.=$roletext{$sortrole{$which}};
                    622:                 if ($sortrole{$which} =~ m-dc\./(\w+)/-) {
                    623:                     if ($dcroles{$1}) {
                    624:                         $output .= &allcourses_row($1);
1.104     raeburn   625:                     }
                    626:                 }
1.76      albertel  627: 	    }
1.108     raeburn   628: 	}
                    629: 	if ($output) {
                    630: 	    if ($doheaders > 0) {
                    631: 		$r->print("<tr bgcolor='#BBffBB'>".
1.112     raeburn   632: 			  "<td align='center' colspan='7'>".&mt($type)."</td></tr>");
1.76      albertel  633: 	    }
1.108     raeburn   634: 	    $r->print($output);	
                    635: 	}
1.4       www       636:     }
1.14      www       637:     my $tremark='';
1.47      www       638:     my $tfont='#003300';
1.14      www       639:     if ($ENV{'request.role'} eq 'cm') {
1.19      www       640: 	$r->print('<tr bgcolor="#11CC55">');
1.72      www       641:         $tremark=&mt('Currently selected. ');
1.47      www       642:         $tfont='#002200';
1.14      www       643:     } else {
                    644:         $r->print('<tr bgcolor="#77FF77">');
                    645:     }
                    646:     unless ($nochoose) {
1.55      albertel  647: 	if ($ENV{'request.role'} ne 'cm') {
1.72      www       648: 	    $r->print('<td><input type=submit value="'.
                    649: 		      &mt('Select').'" name="cm"></td>');
1.55      albertel  650: 	} else {
                    651: 	    $r->print('<td>&nbsp;</td>');
                    652: 	}
1.14      www       653:     }
1.72      www       654:     $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
1.47      www       655:       '</font></td><td><font color="'.$tfont.'">'.$tremark.
                    656:       '&nbsp;</font></td></tr>'."\n");
1.4       www       657: 
                    658:     $r->print('</table>');
                    659:     unless ($nochoose) {
                    660: 	$r->print("</form>\n");
                    661:     }
1.22      harris41  662: # ------------------------------------------------------------ Privileges Info
1.55      albertel  663:     if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
                    664: 	$r->print('<hr><h2>Current Privileges</h2>');
1.4       www       665: 
1.55      albertel  666: 	foreach $envkey (sort keys %ENV) {
                    667: 	    if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
                    668: 		my $where=$envkey;
                    669: 		$where=~s/^user\.priv\.$ENV{'request.role'}\.//;
                    670: 		my $ttype;
                    671: 		my $twhere;
                    672: 		my ($tdom,$trest,$tsec)=
                    673: 		    split(/\//,Apache::lonnet::declutter($where));
                    674: 		if ($trest) {
                    675: 		    if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
                    676: 			$ttype='Construction Space';
                    677: 			$twhere='User: '.$trest.', Domain: '.$tdom;
                    678: 		    } else {
                    679: 			$ttype='Course';
                    680: 			$twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
                    681: 			if ($tsec) {
                    682: 			    $twhere.=' (Section/Group: '.$tsec.')';
                    683: 			}
                    684: 		    }
                    685: 		} elsif ($tdom) {
                    686: 		    $ttype='Domain';
                    687: 		    $twhere=$tdom;
                    688: 		} else {
                    689: 		    $ttype='System';
                    690: 		    $twhere='/';
                    691: 		}
                    692: 		$r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
                    693: 		foreach (sort split(/:/,$ENV{$envkey})) {
                    694: 		    if ($_) {
                    695: 			my ($prv,$restr)=split(/\&/,$_);
                    696: 			my $trestr='';
                    697: 			if ($restr ne 'F') {
                    698: 			    my $i;
                    699: 			    $trestr.=' (';
                    700: 			    for ($i=0;$i<length($restr);$i++) {
                    701: 				$trestr.=
                    702: 			       Apache::lonnet::plaintext(substr($restr,$i,1));
                    703: 				if ($i<length($restr)-1) { $trestr.=', '; }
                    704: 			    }
                    705: 			    $trestr.=')';
                    706: 			}
                    707: 			$r->print('<li>'.
                    708: 				  Apache::lonnet::plaintext($prv).$trestr.
                    709: 				  '</li>');
                    710: 		    }
                    711: 		}
                    712: 		$r->print('</ul>');
                    713: 	    }
                    714: 	}
1.4       www       715:     }
1.66      www       716:     $r->print(&Apache::lonnet::getannounce());
1.65      www       717:     if ($advanced) {
                    718: 	$r->print('<p><small><i>This is LON-CAPA '.
1.85      www       719: 		  $r->dir_config('lonVersion').'</i><br />'.
                    720: 		  '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65      www       721:     }
1.1       harris41  722:     $r->print("</body></html>\n");
                    723:     return OK;
1.102     raeburn   724: }
                    725: 
                    726: sub role_status {
                    727:     my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
                    728:     my @pwhere = ();
                    729:     if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') {
                    730:         (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
                    731:         unless (!defined($$role) || $$role eq '') {
                    732:             $$where=join('.',@pwhere);
                    733:             $$trolecode=$$role.'.'.$$where;
                    734:             ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
                    735:             $$tstatus='is';
1.105     raeburn   736:             if ($$tstart && $$tstart>$then) {
                    737: 		$$tstatus='future';
                    738: 		if ($$tstart<$now) { $$tstatus='will'; }
1.102     raeburn   739:             }
                    740:             if ($$tend) {
                    741:                 if ($$tend<$then) {
                    742:                     $$tstatus='expired';
1.103     raeburn   743:                 } elsif ($$tend<$now) {
1.104     raeburn   744:                     $$tstatus='will_not';
1.102     raeburn   745:                 }
                    746:             }
                    747:         }
                    748:     }
                    749: }
1.1       harris41  750: 
1.110     raeburn   751: sub build_roletext {
                    752:     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$ttype,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.112     raeburn   753:     my $roletext='<tr bgcolor="'.$tbg.'">';
1.110     raeburn   754:     unless ($nochoose) {
                    755:         if (!$button) {
                    756:             if ($switchserver) {
                    757:                 $roletext.='<td><a href="/adm/logout?handover='.
                    758:                 $switchserver.'">'.&mt('Switch Server').'</a></td>';
                    759:             } else {
                    760:                 $roletext.=('<td>&nbsp;</td>');
                    761:             }
                    762:         } elsif ($tstatus eq 'is') {
                    763:             $roletext.=('<td><input type=submit value="'.
                    764:                         &mt('Select').'" name="'.
                    765:                         $trolecode.'"></td>');
                    766:         } elsif ($tryagain) {
                    767:             $roletext.=
                    768:                 '<td><input type=submit value="'.
                    769:                 &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
                    770:         } elsif ($advanced) {
                    771:             $roletext.=
                    772:                 '<td><input type=submit value="'.
                    773:                 &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
                    774:         } else {
                    775:             $roletext.='<td>&nbsp;</td>';
                    776:         }
                    777:     }
                    778:     $tremark.=&Apache::lonannounce::showday(time,1,
                    779:                  &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
                    780: 
                    781: 
                    782:     $roletext.='<td><font color="'.$tfont.'">'.$trole.
                    783:                '</font></td><td><font color="'.$tfont.'">'.$ttype.
                    784:                '</font></td><td><font color="'.$tfont.'">'.$twhere.
                    785:                '</font></td><td><font color="'.$tfont.'">'.$tpstart.
                    786:                '</font></td><td><font color="'.$tfont.'">'.$tpend.
                    787:                '</font></td><td><font color="'.$tfont.'">'.$tremark.
                    788:                '&nbsp;</font></td></tr>'."\n";
                    789:     return $roletext;
                    790: }
                    791: 
                    792: sub check_privs {
                    793:     my ($cckey,$then,$now) = @_;
                    794:     if ($ENV{$cckey}) {
                    795:         my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
                    796:         &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
                    797:         unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
                    798:             &set_privileges($1,$2);
                    799:         }
                    800:     } else {
                    801:         &set_privileges($1,$2);
                    802:     }
                    803: }
                    804: 
1.104     raeburn   805: sub check_fordc {
                    806:     my ($dcroles,$then) = @_;
                    807:     my $numdc = 0;
                    808:     if ($ENV{'user.adv'}) {
                    809:         foreach my $envkey (sort keys %ENV) {
                    810:             if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
                    811:                 my $dcdom = $1;
                    812:                 my $livedc = 1;
                    813:                 my ($tstart,$tend)=split(/\./,$ENV{$envkey});
1.105     raeburn   814:                 if ($tstart && $tstart>$then) { $livedc = 0; }
                    815:                 if ($tend   && $tend  <$then) { $livedc = 0; }
1.104     raeburn   816:                 if ($livedc) {
                    817:                     $$dcroles{$dcdom} = $envkey;
1.105     raeburn   818:                     $numdc++;
1.104     raeburn   819:                 }
                    820:             }
                    821:         }
                    822:     }
                    823:     return $numdc;
                    824: }
                    825: 
1.108     raeburn   826: sub courselink {
                    827:     my ($dcdom) = @_;
1.109     raeburn   828:     my $courseform=&Apache::loncommon::selectcourse_link
1.112     raeburn   829:                      ('rolechoice','dccourse_'.$dcdom,'dcdomain_'.$dcdom,'coursedesc_'.$dcdom,$dcdom);
1.109     raeburn   830:     my $hiddenitems = '<input type="hidden" name="dcdomain_'.$dcdom.'" value="'.$dcdom.'" />'.
                    831:                       '<input type="hidden" name="origdom_'.$dcdom.'" value="'.$dcdom.'" />'.
                    832:                       '<input type="hidden" name="dccourse_'.$dcdom.'" value="" />'.
                    833:                       '<input type="hidden" name="coursedesc_'.$dcdom.'" value="" />';
1.112     raeburn   834:     return $courseform.$hiddenitems;
1.109     raeburn   835: }
                    836: 
                    837: sub coursepick_jscript {
1.104     raeburn   838:     my $verify_script = <<"END";
                    839: <script>
1.108     raeburn   840: function verifyCoursePick(caller) {
                    841:     var numbutton = getIndex(caller)
1.112     raeburn   842:     var pickedCourse = document.rolechoice.elements[numbutton+4].value
                    843:     var pickedDomain = document.rolechoice.elements[numbutton+2].value
                    844:     if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104     raeburn   845:         if (pickedCourse != '') {
1.108     raeburn   846:             if (numbutton != -1) {
                    847:                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
                    848:                 document.rolechoice.elements[numbutton+1].name = courseTarget
                    849:                 document.rolechoice.submit()
                    850:             }
1.104     raeburn   851:         }
                    852:         else {
1.114     raeburn   853:             alert("Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.");
1.104     raeburn   854:         }
                    855:     }
                    856:     else {
                    857:         alert("You can only use this screen to select courses in the current domain")
                    858:     }
                    859: }
1.109     raeburn   860: function getIndex(caller) {
1.108     raeburn   861:     for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109     raeburn   862:         if (document.rolechoice.elements[i] == caller) {
1.108     raeburn   863:             return i;
                    864:         }
                    865:     }
                    866:     return -1;
                    867: }
1.104     raeburn   868: </script>
                    869: END
1.109     raeburn   870:     return $verify_script;
1.104     raeburn   871: }
                    872: 
1.109     raeburn   873: sub processpick {
                    874:     my $dcdom = shift;
                    875:     my $process_pick = <<"END";
                    876: <script>
                    877: function process_pick(dom) {
                    878:     var numbutton = getIndex(dom)
                    879:     var pickedCourse = opener.document.rolechoice.dccourse_$dcdom.value
                    880:     var pickedDomain = opener.document.rolechoice.dcdomain_$dcdom.value
                    881:     if (opener.document.rolechoice.dcdomain_$dcdom.value == opener.document.rolechoice.origdom_$dcdom.value) {
                    882:         if (pickedCourse != '') {
                    883:             if (numbutton != -1) {
                    884:                 var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
                    885:                 opener.document.rolechoice.elements[numbutton+1].name = courseTarget
                    886:                 opener.document.rolechoice.submit()
                    887:             }
                    888:         }
                    889:     }
                    890: }
                    891:  
                    892: function getIndex(dom) {
                    893:     var callername = 'ccpick_'+dom
                    894:     for (var i=0;i<opener.document.rolechoice.elements.length;i++) {
                    895:         var elemname = opener.document.rolechoice.elements[i].name
                    896:         if (elemname == callername) {
                    897:             return i;
                    898:         }
                    899:     }
                    900:     return -1;
                    901: }
                    902: </script>
                    903: END
                    904:     return $process_pick;
                    905: }
1.108     raeburn   906: 
1.113     raeburn   907: sub display_cc_role {
                    908:     my $rolekey = shift;
                    909:     my $roletext;
1.104     raeburn   910:     my $advanced = $ENV{'user.adv'};
                    911:     my $tryagain = $ENV{'form.tryagain'};
1.113     raeburn   912:     unless ($rolekey =~/^error\:/) {
                    913:         if ($rolekey =~ m-^user\.role.cc\./(\w+)/(\w+)$-) {
                    914:             my $tcourseid = $1.'_'.$2;
                    915:             my $trolecode = 'cc./'.$1.'/'.$2;
                    916:             my $trole = Apache::lonnet::plaintext('cc');
                    917:             my $twhere;
                    918:             my $tbg='#77FF77';
                    919:             my $tfont='#003300';
                    920:             my %newhash=&Apache::lonnet::coursedescription($tcourseid);
                    921:             if (%newhash) {
                    922:                 $twhere=$newhash{'description'}.
                    923:                         ' <font size="-2">'.
                    924:                         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
                    925:                         '</font>';
                    926:             } else {
                    927:                 $twhere=&mt('Currently not available');
                    928:                 $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.110     raeburn   929:             }
1.113     raeburn   930:             $twhere.="<br />".&mt('Domain').":".$1;
                    931:             $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,&mt('Course'),$twhere,'','','',1,'');
1.104     raeburn   932:         }
                    933:     }
1.113     raeburn   934:     return $roletext;
1.104     raeburn   935: }
                    936: 
1.108     raeburn   937: sub allcourses_row {
1.109     raeburn   938:     my $dcdom = shift;
1.108     raeburn   939:     my $ccrole = Apache::lonnet::plaintext('cc');
                    940:     my $selectlink = &courselink($dcdom);
                    941:     my $output = '<tr bgcolor="#77FF77">'.
                    942:               '<td><input type="button" value="'.
1.109     raeburn   943:               &mt('Select').'" name="ccpick_'.$dcdom.'"'.
1.108     raeburn   944:               'onClick="verifyCoursePick(this)">'.
                    945:               '<input type="hidden" name="pick_'.$dcdom.'" value="1"></td>'.
                    946:               '<td><font color="#002200">'.
                    947:               $ccrole.'</font></td><td>'.&mt('Course').'</td>'.
                    948:               '<td><font color="#002200">'.&mt('All courses').':<b>&nbsp;'.
                    949:               $selectlink.'</b>'.
                    950:               '<br />'.&mt('Domain').':'.$dcdom.'</font>'.
                    951:               '<td colspan="4"><font color="#002200">'.
                    952:               &mt('Course Coordinator access to all courses in domain').
                    953:               ': <b>'.$dcdom.'</b></font></td></tr>'."\n";
                    954:     return $output;
                    955: }
                    956: 
1.104     raeburn   957: sub recent_filename {
                    958:     my $area=shift;
                    959:     return 'nohist_recent_'.&Apache::lonnet::escape($area);
                    960: }
                    961: 
1.106     raeburn   962: sub set_privileges {
                    963:     my ($dcdom,$pickedcourse) = @_;
                    964:     my $area = '/'.$dcdom.'/'.$pickedcourse;
                    965:     my $role = 'cc';
                    966:     my $spec = $role.'.'.$area;
                    967:     my $userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$ENV{'user.name'});
                    968:     my %ccrole = ();
                    969:     &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.107     raeburn   970:     my ($author,$adv)= &Apache::lonnet::set_userprivs(\$userroles,\%ccrole);
                    971:     my @newprivs = split/\n/,$userroles;
1.106     raeburn   972:     my %newccroles = ();
                    973:     foreach (@newprivs) {
                    974:         my ($key,$val) = split/=/,$_;
                    975:         $newccroles{$key} = $val;
                    976:     }
                    977:     &Apache::lonnet::appenv(%newccroles);
                    978:     &Apache::lonnet::log($ENV{'user.domain'},
                    979:                          $ENV{'user.name'},
                    980:                          $ENV{'user.home'},
                    981:                         "Role ".$role);
                    982:     &Apache::lonnet::appenv(
                    983:                           'request.role'        => $role,
                    984:                           'request.role.domain' => $dcdom,
                    985:                           'request.course.sec'  => '');
                    986:     my $tadv=0;
                    987:     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
                    988:     &Apache::lonnet::appenv('request.role.adv'    => $tadv);
                    989: }
                    990: 
1.1       harris41  991: 1;
                    992: __END__
1.32      harris41  993: 
                    994: =head1 NAME
                    995: 
                    996: Apache::lonroles - User Roles Screen
                    997: 
                    998: =head1 SYNOPSIS
                    999: 
                   1000: Invoked by /etc/httpd/conf/srm.conf:
                   1001: 
                   1002:  <Location /adm/roles>
                   1003:  PerlAccessHandler       Apache::lonacc
                   1004:  SetHandler perl-script
                   1005:  PerlHandler Apache::lonroles
                   1006:  ErrorDocument     403 /adm/login
                   1007:  ErrorDocument	  500 /adm/errorhandler
                   1008:  </Location>
1.64      bowersj2 1009: 
                   1010: =head1 OVERVIEW
                   1011: 
                   1012: =head2 Choosing Roles
                   1013: 
                   1014: C<lonroles> is a handler that allows a user to switch roles in
                   1015: mid-session. LON-CAPA attempts to work with "No Role Specified", the
                   1016: default role that a user has before selecting a role, as widely as
                   1017: possible, but certain handlers for example need specification which
                   1018: course they should act on, etc. Both in this scenario, and when the
                   1019: handler determines via C<lonnet>'s C<&allowed> function that a certain
                   1020: action is not allowed, C<lonroles> is used as error handler. This
                   1021: allows the user to select another role which may have permission to do
                   1022: what they were trying to do. C<lonroles> can also be accessed via the
                   1023: B<CRS> button in the Remote Control. 
                   1024: 
                   1025: =begin latex
                   1026: 
                   1027: \begin{figure}
                   1028: \begin{center}
                   1029: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
                   1030:   \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
                   1031: \end{center}
                   1032: \end{figure}
                   1033: 
                   1034: =end latex
                   1035: 
                   1036: =head2 Role Initialization
                   1037: 
                   1038: 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 1039: 
                   1040: =head1 INTRODUCTION
                   1041: 
                   1042: This module enables a user to select what role he wishes to
                   1043: operate under (instructor, student, teaching assistant, course
                   1044: coordinator, etc).  These roles are pre-established by the actions
                   1045: of upper-level users.
                   1046: 
                   1047: This is part of the LearningOnline Network with CAPA project
                   1048: described at http://www.lon-capa.org.
                   1049: 
                   1050: =head1 HANDLER SUBROUTINE
                   1051: 
                   1052: This routine is called by Apache and mod_perl.
                   1053: 
                   1054: =over 4
                   1055: 
                   1056: =item *
                   1057: 
                   1058: Roles Initialization (yes/no)
                   1059: 
                   1060: =item *
                   1061: 
                   1062: Get Error Message from Environment
                   1063: 
                   1064: =item *
                   1065: 
                   1066: Who is this?
                   1067: 
                   1068: =item *
                   1069: 
                   1070: Generate Page Output
                   1071: 
                   1072: =item *
                   1073: 
                   1074: Choice or no choice
                   1075: 
                   1076: =item *
                   1077: 
                   1078: Table
                   1079: 
                   1080: =item *
                   1081: 
                   1082: Privileges
                   1083: 
                   1084: =back
                   1085: 
                   1086: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.