Annotation of loncom/auth/lonroles.pm, revision 1.112
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.112 ! raeburn 4: # $Id: lonroles.pm,v 1.111 2004/11/19 20:17:52 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.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.110 raeburn 566: $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$ttype,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
1.75 albertel 567: $roletext{$envkey}=$roletext;
568: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
569: $sortrole{$sortkey}=$envkey;
570: $roleclass{$envkey}=$ttype;
1.55 albertel 571: }
1.4 www 572: }
1.75 albertel 573: }
1.84 www 574: # No active roles
575: if ($countactive==0) {
576: if ($inrole) {
577: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
578: } else {
579: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
580: }
581: $r->print('</form></body></html>');
582: return OK;
583: # Is there only one choice?
1.88 www 584: } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) {
1.84 www 585: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
586: '<input type="hidden" name="'.$possiblerole.'" value="1" />');
587: $r->print("</form>\n");
588: $r->rflush();
589: $r->print('<script>document.forms.rolechoice.submit();</script>');
590: $r->print('</body></html>');
591: return OK;
592: }
593: # More than one possible role
594: # ----------------------------------------------------------------------- Table
595: unless (($advanced) || ($nochoose)) {
596: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
597: }
598: $r->print('<br /><table><tr>');
599: unless ($nochoose) { $r->print('<th> </th>'); }
600: $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
601: '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
1.99 www 602: &mt('Remarks and Calendar Announcements').'</th></tr>'."\n");
1.76 albertel 603: my $doheaders=-1;
1.78 sakharuk 604: foreach my $type ('Construction Space','Course','Domain','System') {
1.76 albertel 605: my $haverole=0;
1.75 albertel 606: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
607: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.76 albertel 608: $haverole=1;
1.75 albertel 609: }
1.76 albertel 610: }
611: if ($haverole) { $doheaders++; }
612: }
1.111 albertel 613:
614: if ($ENV{'environment.recentroles'}) {
615: my %recent_roles =
616: &Apache::lonhtmlcommon::get_recent('roles',$ENV{'environment.recentrolesn'});
617: my $output='';
618: foreach (sort(keys(%recent_roles))) {
619: if (defined($roletext{'user.role.'.$_})) {
620: $output.=$roletext{'user.role.'.$_};
621: }
622: }
623: if ($output) {
624: $r->print("<tr bgcolor='#BBffBB'><td align='center' colspan='7'>".
625: &mt('Recent Roles')."</td>");
626: $r->print($output);
627: $r->print("</tr>");
628: }
629: }
630:
1.104 raeburn 631: if ($numdc > 0) {
1.110 raeburn 632: &display_recent_roles($r,\%roletext,\%recentroles);
1.112 ! raeburn 633: $r->print(&coursepick_jscript());
! 634: $r->print(&Apache::loncommon::coursebrowser_javascript());
1.108 raeburn 635: }
636: foreach my $type ('Construction Space','Course','Domain','System') {
637: my $output;
638: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
639: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
640: $output.=$roletext{$sortrole{$which}};
641: if ($sortrole{$which} =~ m-dc\./(\w+)/-) {
642: if ($dcroles{$1}) {
643: $output .= &allcourses_row($1);
1.104 raeburn 644: }
645: }
1.76 albertel 646: }
1.108 raeburn 647: }
648: if ($output) {
649: if ($doheaders > 0) {
650: $r->print("<tr bgcolor='#BBffBB'>".
1.112 ! raeburn 651: "<td align='center' colspan='7'>".&mt($type)."</td></tr>");
1.76 albertel 652: }
1.108 raeburn 653: $r->print($output);
654: }
1.4 www 655: }
1.14 www 656: my $tremark='';
1.47 www 657: my $tfont='#003300';
1.14 www 658: if ($ENV{'request.role'} eq 'cm') {
1.19 www 659: $r->print('<tr bgcolor="#11CC55">');
1.72 www 660: $tremark=&mt('Currently selected. ');
1.47 www 661: $tfont='#002200';
1.14 www 662: } else {
663: $r->print('<tr bgcolor="#77FF77">');
664: }
665: unless ($nochoose) {
1.55 albertel 666: if ($ENV{'request.role'} ne 'cm') {
1.72 www 667: $r->print('<td><input type=submit value="'.
668: &mt('Select').'" name="cm"></td>');
1.55 albertel 669: } else {
670: $r->print('<td> </td>');
671: }
1.14 www 672: }
1.72 www 673: $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
1.47 www 674: '</font></td><td><font color="'.$tfont.'">'.$tremark.
675: ' </font></td></tr>'."\n");
1.4 www 676:
677: $r->print('</table>');
678: unless ($nochoose) {
679: $r->print("</form>\n");
680: }
1.22 harris41 681: # ------------------------------------------------------------ Privileges Info
1.55 albertel 682: if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
683: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 684:
1.55 albertel 685: foreach $envkey (sort keys %ENV) {
686: if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
687: my $where=$envkey;
688: $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
689: my $ttype;
690: my $twhere;
691: my ($tdom,$trest,$tsec)=
692: split(/\//,Apache::lonnet::declutter($where));
693: if ($trest) {
694: if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
695: $ttype='Construction Space';
696: $twhere='User: '.$trest.', Domain: '.$tdom;
697: } else {
698: $ttype='Course';
699: $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
700: if ($tsec) {
701: $twhere.=' (Section/Group: '.$tsec.')';
702: }
703: }
704: } elsif ($tdom) {
705: $ttype='Domain';
706: $twhere=$tdom;
707: } else {
708: $ttype='System';
709: $twhere='/';
710: }
711: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
712: foreach (sort split(/:/,$ENV{$envkey})) {
713: if ($_) {
714: my ($prv,$restr)=split(/\&/,$_);
715: my $trestr='';
716: if ($restr ne 'F') {
717: my $i;
718: $trestr.=' (';
719: for ($i=0;$i<length($restr);$i++) {
720: $trestr.=
721: Apache::lonnet::plaintext(substr($restr,$i,1));
722: if ($i<length($restr)-1) { $trestr.=', '; }
723: }
724: $trestr.=')';
725: }
726: $r->print('<li>'.
727: Apache::lonnet::plaintext($prv).$trestr.
728: '</li>');
729: }
730: }
731: $r->print('</ul>');
732: }
733: }
1.4 www 734: }
1.66 www 735: $r->print(&Apache::lonnet::getannounce());
1.65 www 736: if ($advanced) {
737: $r->print('<p><small><i>This is LON-CAPA '.
1.85 www 738: $r->dir_config('lonVersion').'</i><br />'.
739: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 740: }
1.1 harris41 741: $r->print("</body></html>\n");
742: return OK;
1.102 raeburn 743: }
744:
745: sub role_status {
746: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
747: my @pwhere = ();
748: if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') {
749: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
750: unless (!defined($$role) || $$role eq '') {
751: $$where=join('.',@pwhere);
752: $$trolecode=$$role.'.'.$$where;
753: ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
754: $$tstatus='is';
1.105 raeburn 755: if ($$tstart && $$tstart>$then) {
756: $$tstatus='future';
757: if ($$tstart<$now) { $$tstatus='will'; }
1.102 raeburn 758: }
759: if ($$tend) {
760: if ($$tend<$then) {
761: $$tstatus='expired';
1.103 raeburn 762: } elsif ($$tend<$now) {
1.104 raeburn 763: $$tstatus='will_not';
1.102 raeburn 764: }
765: }
766: }
767: }
768: }
1.1 harris41 769:
1.110 raeburn 770: sub build_roletext {
771: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$ttype,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.112 ! raeburn 772: my $roletext='<tr bgcolor="'.$tbg.'">';
1.110 raeburn 773: unless ($nochoose) {
774: if (!$button) {
775: if ($switchserver) {
776: $roletext.='<td><a href="/adm/logout?handover='.
777: $switchserver.'">'.&mt('Switch Server').'</a></td>';
778: } else {
779: $roletext.=('<td> </td>');
780: }
781: } elsif ($tstatus eq 'is') {
782: $roletext.=('<td><input type=submit value="'.
783: &mt('Select').'" name="'.
784: $trolecode.'"></td>');
785: } elsif ($tryagain) {
786: $roletext.=
787: '<td><input type=submit value="'.
788: &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
789: } elsif ($advanced) {
790: $roletext.=
791: '<td><input type=submit value="'.
792: &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
793: } else {
794: $roletext.='<td> </td>';
795: }
796: }
797: $tremark.=&Apache::lonannounce::showday(time,1,
798: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
799:
800:
801: $roletext.='<td><font color="'.$tfont.'">'.$trole.
802: '</font></td><td><font color="'.$tfont.'">'.$ttype.
803: '</font></td><td><font color="'.$tfont.'">'.$twhere.
804: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
805: '</font></td><td><font color="'.$tfont.'">'.$tpend.
806: '</font></td><td><font color="'.$tfont.'">'.$tremark.
807: ' </font></td></tr>'."\n";
808: return $roletext;
809: }
810:
811: sub check_privs {
812: my ($cckey,$then,$now) = @_;
813: if ($ENV{$cckey}) {
814: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
815: &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
816: unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
817: &set_privileges($1,$2);
818: }
819: } else {
820: &set_privileges($1,$2);
821: }
822: }
823:
1.104 raeburn 824: sub check_fordc {
825: my ($dcroles,$then) = @_;
826: my $numdc = 0;
827: if ($ENV{'user.adv'}) {
828: foreach my $envkey (sort keys %ENV) {
829: if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
830: my $dcdom = $1;
831: my $livedc = 1;
832: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
1.105 raeburn 833: if ($tstart && $tstart>$then) { $livedc = 0; }
834: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 835: if ($livedc) {
836: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 837: $numdc++;
1.104 raeburn 838: }
839: }
840: }
841: }
842: return $numdc;
843: }
844:
1.108 raeburn 845: sub courselink {
846: my ($dcdom) = @_;
1.109 raeburn 847: my $courseform=&Apache::loncommon::selectcourse_link
1.112 ! raeburn 848: ('rolechoice','dccourse_'.$dcdom,'dcdomain_'.$dcdom,'coursedesc_'.$dcdom,$dcdom);
1.109 raeburn 849: my $hiddenitems = '<input type="hidden" name="dcdomain_'.$dcdom.'" value="'.$dcdom.'" />'.
850: '<input type="hidden" name="origdom_'.$dcdom.'" value="'.$dcdom.'" />'.
851: '<input type="hidden" name="dccourse_'.$dcdom.'" value="" />'.
852: '<input type="hidden" name="coursedesc_'.$dcdom.'" value="" />';
1.112 ! raeburn 853: return $courseform.$hiddenitems;
1.109 raeburn 854: }
855:
856: sub coursepick_jscript {
1.104 raeburn 857: my $verify_script = <<"END";
858: <script>
1.108 raeburn 859: function verifyCoursePick(caller) {
860: var numbutton = getIndex(caller)
1.112 ! raeburn 861: var pickedCourse = document.rolechoice.elements[numbutton+4].value
! 862: var pickedDomain = document.rolechoice.elements[numbutton+2].value
! 863: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 864: if (pickedCourse != '') {
1.108 raeburn 865: if (numbutton != -1) {
866: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
867: document.rolechoice.elements[numbutton+1].name = courseTarget
868: document.rolechoice.submit()
869: }
1.104 raeburn 870: }
871: else {
872: 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");
873: }
874: }
875: else {
876: alert("You can only use this screen to select courses in the current domain")
877: }
878: }
1.109 raeburn 879: function getIndex(caller) {
1.108 raeburn 880: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 881: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 882: return i;
883: }
884: }
885: return -1;
886: }
1.104 raeburn 887: </script>
888: END
1.109 raeburn 889: return $verify_script;
1.104 raeburn 890: }
891:
1.109 raeburn 892: sub processpick {
893: my $dcdom = shift;
894: my $process_pick = <<"END";
895: <script>
896: function process_pick(dom) {
897: var numbutton = getIndex(dom)
898: var pickedCourse = opener.document.rolechoice.dccourse_$dcdom.value
899: var pickedDomain = opener.document.rolechoice.dcdomain_$dcdom.value
900: if (opener.document.rolechoice.dcdomain_$dcdom.value == opener.document.rolechoice.origdom_$dcdom.value) {
901: if (pickedCourse != '') {
902: if (numbutton != -1) {
903: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
904: opener.document.rolechoice.elements[numbutton+1].name = courseTarget
905: opener.document.rolechoice.submit()
906: }
907: }
908: }
909: }
910:
911: function getIndex(dom) {
912: var callername = 'ccpick_'+dom
913: for (var i=0;i<opener.document.rolechoice.elements.length;i++) {
914: var elemname = opener.document.rolechoice.elements[i].name
915: if (elemname == callername) {
916: return i;
917: }
918: }
919: return -1;
920: }
921: </script>
922: END
923: return $process_pick;
924: }
1.108 raeburn 925:
1.110 raeburn 926: sub display_recent_roles {
927: my ($r,$roletext,$recentroles)=@_;
1.104 raeburn 928: my $advanced = $ENV{'user.adv'};
929: my $tryagain = $ENV{'form.tryagain'};
930: my $numrecent = 0;
1.108 raeburn 931: my $roledisplay = '<tr bgcolor="#BBffBB">'.
1.104 raeburn 932: '<td align="center" colspan="7">'.
1.108 raeburn 933: &mt('Recent courses accessed by DC').
1.104 raeburn 934: '</td></tr>'."\n";
1.110 raeburn 935: foreach my $rolekey (sort keys %{$recentroles}) {
936: unless ($rolekey =~/^error\:/) {
937: unless ($$roletext{$rolekey}) {
938: if ($rolekey =~ m-^user\.role.cc\./(\w+)/(\w+)$-) {
939: my $tcourseid = $1.'_'.$2;
940: my $trolecode = 'cc./'.$1.'/'.$2;
941: my $trole = Apache::lonnet::plaintext('cc');
942: my $twhere;
943: my $tbg='#77FF77';
944: my $tfont='#003300';
945: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
946: if (%newhash) {
947: $twhere=$newhash{'description'}.
948: ' <font size="-2">'.
949: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
950: '</font>';
951: } else {
952: $twhere=&mt('Currently not available');
953: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
954: }
955: $twhere.="<br />".&mt('Domain').":".$1;
956: $$roletext{$rolekey} = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,&mt('Course'),$twhere,'','','',1,'');
957: }
958: }
959: $roledisplay.=$$roletext{$rolekey};
1.108 raeburn 960: $numrecent ++;
1.104 raeburn 961: }
962: }
963: if ($numrecent > 0) {
1.108 raeburn 964: $r->print("$roledisplay\n");
1.104 raeburn 965: }
966: }
967:
1.108 raeburn 968: sub allcourses_row {
1.109 raeburn 969: my $dcdom = shift;
1.108 raeburn 970: my $ccrole = Apache::lonnet::plaintext('cc');
971: my $selectlink = &courselink($dcdom);
972: my $output = '<tr bgcolor="#77FF77">'.
973: '<td><input type="button" value="'.
1.109 raeburn 974: &mt('Select').'" name="ccpick_'.$dcdom.'"'.
1.108 raeburn 975: 'onClick="verifyCoursePick(this)">'.
976: '<input type="hidden" name="pick_'.$dcdom.'" value="1"></td>'.
977: '<td><font color="#002200">'.
978: $ccrole.'</font></td><td>'.&mt('Course').'</td>'.
979: '<td><font color="#002200">'.&mt('All courses').':<b> '.
980: $selectlink.'</b>'.
981: '<br />'.&mt('Domain').':'.$dcdom.'</font>'.
982: '<td colspan="4"><font color="#002200">'.
983: &mt('Course Coordinator access to all courses in domain').
984: ': <b>'.$dcdom.'</b></font></td></tr>'."\n";
985: return $output;
986: }
987:
1.104 raeburn 988: sub recent_filename {
989: my $area=shift;
990: return 'nohist_recent_'.&Apache::lonnet::escape($area);
991: }
992:
1.106 raeburn 993: sub set_privileges {
994: my ($dcdom,$pickedcourse) = @_;
995: my $area = '/'.$dcdom.'/'.$pickedcourse;
996: my $role = 'cc';
997: my $spec = $role.'.'.$area;
998: my $userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$ENV{'user.name'});
999: my %ccrole = ();
1000: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.107 raeburn 1001: my ($author,$adv)= &Apache::lonnet::set_userprivs(\$userroles,\%ccrole);
1002: my @newprivs = split/\n/,$userroles;
1.106 raeburn 1003: my %newccroles = ();
1004: foreach (@newprivs) {
1005: my ($key,$val) = split/=/,$_;
1006: $newccroles{$key} = $val;
1007: }
1008: &Apache::lonnet::appenv(%newccroles);
1009: &Apache::lonnet::log($ENV{'user.domain'},
1010: $ENV{'user.name'},
1011: $ENV{'user.home'},
1012: "Role ".$role);
1013: &Apache::lonnet::appenv(
1014: 'request.role' => $role,
1015: 'request.role.domain' => $dcdom,
1016: 'request.course.sec' => '');
1017: my $tadv=0;
1018: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1019: &Apache::lonnet::appenv('request.role.adv' => $tadv);
1020: }
1021:
1.1 harris41 1022: 1;
1023: __END__
1.32 harris41 1024:
1025: =head1 NAME
1026:
1027: Apache::lonroles - User Roles Screen
1028:
1029: =head1 SYNOPSIS
1030:
1031: Invoked by /etc/httpd/conf/srm.conf:
1032:
1033: <Location /adm/roles>
1034: PerlAccessHandler Apache::lonacc
1035: SetHandler perl-script
1036: PerlHandler Apache::lonroles
1037: ErrorDocument 403 /adm/login
1038: ErrorDocument 500 /adm/errorhandler
1039: </Location>
1.64 bowersj2 1040:
1041: =head1 OVERVIEW
1042:
1043: =head2 Choosing Roles
1044:
1045: C<lonroles> is a handler that allows a user to switch roles in
1046: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1047: default role that a user has before selecting a role, as widely as
1048: possible, but certain handlers for example need specification which
1049: course they should act on, etc. Both in this scenario, and when the
1050: handler determines via C<lonnet>'s C<&allowed> function that a certain
1051: action is not allowed, C<lonroles> is used as error handler. This
1052: allows the user to select another role which may have permission to do
1053: what they were trying to do. C<lonroles> can also be accessed via the
1054: B<CRS> button in the Remote Control.
1055:
1056: =begin latex
1057:
1058: \begin{figure}
1059: \begin{center}
1060: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1061: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1062: \end{center}
1063: \end{figure}
1064:
1065: =end latex
1066:
1067: =head2 Role Initialization
1068:
1069: 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 1070:
1071: =head1 INTRODUCTION
1072:
1073: This module enables a user to select what role he wishes to
1074: operate under (instructor, student, teaching assistant, course
1075: coordinator, etc). These roles are pre-established by the actions
1076: of upper-level users.
1077:
1078: This is part of the LearningOnline Network with CAPA project
1079: described at http://www.lon-capa.org.
1080:
1081: =head1 HANDLER SUBROUTINE
1082:
1083: This routine is called by Apache and mod_perl.
1084:
1085: =over 4
1086:
1087: =item *
1088:
1089: Roles Initialization (yes/no)
1090:
1091: =item *
1092:
1093: Get Error Message from Environment
1094:
1095: =item *
1096:
1097: Who is this?
1098:
1099: =item *
1100:
1101: Generate Page Output
1102:
1103: =item *
1104:
1105: Choice or no choice
1106:
1107: =item *
1108:
1109: Table
1110:
1111: =item *
1112:
1113: Privileges
1114:
1115: =back
1116:
1117: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>