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