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