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