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