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