Annotation of loncom/auth/lonroles.pm, revision 1.85
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.85 ! www 4: # $Id: lonroles.pm,v 1.84 2004/01/29 00:44:06 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.72 www 373: $tremark.=&mt('Currently selected. ');
1.35 matthew 374: }
375: my $trole;
376: if ($role =~ /^cr\//) {
377: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.72 www 378: $tremark.='<br>'.&mt('Defined by ').$rauthor.
379: &mt(' at ').$rdomain.'.';
1.35 matthew 380: $trole=$rrole;
1.8 www 381: } else {
1.35 matthew 382: $trole=Apache::lonnet::plaintext($role);
383: }
384: my $ttype;
385: my $twhere;
386: my ($tdom,$trest,$tsection)=
387: split(/\//,Apache::lonnet::declutter($where));
388: # First, Co-Authorship roles
389: if ($role eq 'ca') {
1.39 stredwic 390: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83 albertel 391: my $allowed=0;
392: my @ids=&Apache::lonnet::current_machine_ids();
393: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
394: if (!$allowed) {
1.49 www 395: $button=0;
1.51 www 396: $switchserver=&Apache::lonnet::escape('http://'.
397: $Apache::lonnet::hostname{$home}.
398: '/adm/login?domain='.$ENV{'user.domain'}.
399: '&username='.$ENV{'user.name'}.
400: '&firsturl=/priv/'.$trest);
1.49 www 401: }
1.35 matthew 402: #next if ($home eq 'no_host');
403: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 404: $ttype='Construction Space';
1.72 www 405: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
406: ': '.$tdom.'<br />'.
407: ' '.&mt('Server').': '.$home;
1.35 matthew 408: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 409: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75 albertel 410: $sortkey=$role."$trest:$tdom";
1.35 matthew 411: } elsif ($role eq 'au') {
412: # Authors
413: my $home = &Apache::lonnet::homeserver
1.39 stredwic 414: ($ENV{'user.name'},$ENV{'user.domain'});
1.83 albertel 415: my $allowed=0;
416: my @ids=&Apache::lonnet::current_machine_ids();
417: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
418: if (!$allowed) {
1.49 www 419: $button=0;
1.51 www 420: $switchserver=&Apache::lonnet::escape('http://'.
421: $Apache::lonnet::hostname{$home}.
422: '/adm/login?domain='.$ENV{'user.domain'}.
423: '&username='.$ENV{'user.name'}.
424: '&firsturl=/priv/'.$ENV{'user.name'});
1.49 www 425: }
1.35 matthew 426: #next if ($home eq 'no_host');
427: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 428: $ttype='Construction Space';
1.72 www 429: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
430: ': '.$home;
1.35 matthew 431: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 432: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/');
1.75 albertel 433: $sortkey=$role;
1.35 matthew 434: } elsif ($trest) {
1.78 sakharuk 435: $ttype='Course';
1.35 matthew 436: if ($tsection) {
1.72 www 437: $ttype.='<br>'.&mt('Section/Group').': '.$tsection;
1.37 albertel 438: }
1.35 matthew 439: my $tcourseid=$tdom.'_'.$trest;
440: if ($ENV{'course.'.$tcourseid.'.description'}) {
1.47 www 441: $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.80 albertel 442: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72 www 443: unless ($twhere eq &mt('Currently not available')) {
1.55 albertel 444: $twhere.=' <font size="-2">'.
1.72 www 445: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 446: '</font>';
1.55 albertel 447: }
1.8 www 448: } else {
1.35 matthew 449: my %newhash=Apache::lonnet::coursedescription
450: ($tcourseid);
451: if (%newhash) {
1.80 albertel 452: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77 albertel 453: "\0".$envkey;
1.49 www 454: $twhere=$newhash{'description'}.
455: ' <font size="-2">'.
1.72 www 456: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 457: '</font>';
1.35 matthew 458: } else {
1.72 www 459: $twhere=&mt('Currently not available');
1.35 matthew 460: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.80 albertel 461: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.35 matthew 462: }
1.8 www 463: }
1.72 www 464: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35 matthew 465: } elsif ($tdom) {
1.78 sakharuk 466: $ttype='Domain';
1.35 matthew 467: $twhere=$tdom;
1.75 albertel 468: $sortkey=$role.$twhere;
1.35 matthew 469: } else {
1.78 sakharuk 470: $ttype='System';
1.72 www 471: $twhere=&mt('system wide');
1.75 albertel 472: $sortkey=$role.$twhere;
1.13 www 473: }
1.35 matthew 474:
1.75 albertel 475: $roletext.='<tr bgcolor='.$tbg.'>';
1.35 matthew 476: unless ($nochoose) {
477: if (!$button) {
1.49 www 478: if ($switchserver) {
1.75 albertel 479: $roletext.='<td><a href="/adm/logout?handover='.
480: $switchserver.'">'.&mt('Switch Server').'</a></td>';
1.49 www 481: } else {
1.75 albertel 482: $roletext.=('<td> </td>');
1.49 www 483: }
1.35 matthew 484: } elsif ($tstatus eq 'is') {
1.75 albertel 485: $roletext.=('<td><input type=submit value="'.
1.72 www 486: &mt('Select').'" name="'.
1.35 matthew 487: $trolecode.'"></td>');
1.61 www 488: } elsif ($tryagain) {
1.75 albertel 489: $roletext.=
490: '<td><input type=submit value="'.
491: &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
1.61 www 492: } elsif ($advanced) {
1.75 albertel 493: $roletext.=
494: '<td><input type=submit value="'.
495: &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
1.35 matthew 496: } else {
1.75 albertel 497: $roletext.='<td> </td>';
1.35 matthew 498: }
1.6 www 499: }
1.57 www 500: $tremark.=&Apache::lonannounce::showday(time,1,
501: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
502:
1.75 albertel 503: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.47 www 504: '</font></td><td><font color="'.$tfont.'">'.$ttype.
505: '</font></td><td><font color="'.$tfont.'">'.$twhere.
506: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
507: '</font></td><td><font color="'.$tfont.'">'.$tpend.
508: '</font></td><td><font color="'.$tfont.'">'.$tremark.
1.75 albertel 509: ' </font></td></tr>'."\n";
510: $roletext{$envkey}=$roletext;
511: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
512: $sortrole{$sortkey}=$envkey;
513: $roleclass{$envkey}=$ttype;
1.55 albertel 514: }
1.4 www 515: }
1.75 albertel 516: }
1.84 www 517: # No active roles
518: if ($countactive==0) {
519: if ($inrole) {
520: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
521: } else {
522: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
523: }
524: $r->print('</form></body></html>');
525: return OK;
526: # Is there only one choice?
527: } elsif ($countactive==1) {
528: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
529: '<input type="hidden" name="'.$possiblerole.'" value="1" />');
530: $r->print("</form>\n");
531: $r->rflush();
532: $r->print('<script>document.forms.rolechoice.submit();</script>');
533: $r->print('</body></html>');
534: return OK;
535: }
536: # More than one possible role
537: # ----------------------------------------------------------------------- Table
538: unless (($advanced) || ($nochoose)) {
539: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
540: }
541: $r->print('<br /><table><tr>');
542: unless ($nochoose) { $r->print('<th> </th>'); }
543: $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
544: '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
545: &mt('Remark').'</th></tr>'."\n");
1.76 albertel 546: my $doheaders=-1;
1.78 sakharuk 547: foreach my $type ('Construction Space','Course','Domain','System') {
1.76 albertel 548: my $haverole=0;
1.75 albertel 549: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
550: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.76 albertel 551: $haverole=1;
1.75 albertel 552: }
1.76 albertel 553: }
554: if ($haverole) { $doheaders++; }
555: }
1.78 sakharuk 556: foreach my $type ('Construction Space','Course','Domain','System') {
1.76 albertel 557: my $output;
558: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
559: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.78 sakharuk 560: $output.=&mt($roletext{$sortrole{$which}});
1.76 albertel 561: }
562: }
563: if ($output) {
564: if ($doheaders > 0) {
1.77 albertel 565: $r->print("<tr bgcolor='#BBffBB'>".
1.79 sakharuk 566: "<td align='center' colspan='7'>".&mt($type)."</td>");
1.76 albertel 567: }
568: $r->print($output);
1.75 albertel 569: }
1.4 www 570: }
1.14 www 571: my $tremark='';
1.47 www 572: my $tfont='#003300';
1.14 www 573: if ($ENV{'request.role'} eq 'cm') {
1.19 www 574: $r->print('<tr bgcolor="#11CC55">');
1.72 www 575: $tremark=&mt('Currently selected. ');
1.47 www 576: $tfont='#002200';
1.14 www 577: } else {
578: $r->print('<tr bgcolor="#77FF77">');
579: }
580: unless ($nochoose) {
1.55 albertel 581: if ($ENV{'request.role'} ne 'cm') {
1.72 www 582: $r->print('<td><input type=submit value="'.
583: &mt('Select').'" name="cm"></td>');
1.55 albertel 584: } else {
585: $r->print('<td> </td>');
586: }
1.14 www 587: }
1.72 www 588: $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
1.47 www 589: '</font></td><td><font color="'.$tfont.'">'.$tremark.
590: ' </font></td></tr>'."\n");
1.4 www 591:
592: $r->print('</table>');
593: unless ($nochoose) {
594: $r->print("</form>\n");
595: }
1.22 harris41 596: # ------------------------------------------------------------ Privileges Info
1.55 albertel 597: if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
598: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 599:
1.55 albertel 600: foreach $envkey (sort keys %ENV) {
601: if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
602: my $where=$envkey;
603: $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
604: my $ttype;
605: my $twhere;
606: my ($tdom,$trest,$tsec)=
607: split(/\//,Apache::lonnet::declutter($where));
608: if ($trest) {
609: if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
610: $ttype='Construction Space';
611: $twhere='User: '.$trest.', Domain: '.$tdom;
612: } else {
613: $ttype='Course';
614: $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
615: if ($tsec) {
616: $twhere.=' (Section/Group: '.$tsec.')';
617: }
618: }
619: } elsif ($tdom) {
620: $ttype='Domain';
621: $twhere=$tdom;
622: } else {
623: $ttype='System';
624: $twhere='/';
625: }
626: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
627: foreach (sort split(/:/,$ENV{$envkey})) {
628: if ($_) {
629: my ($prv,$restr)=split(/\&/,$_);
630: my $trestr='';
631: if ($restr ne 'F') {
632: my $i;
633: $trestr.=' (';
634: for ($i=0;$i<length($restr);$i++) {
635: $trestr.=
636: Apache::lonnet::plaintext(substr($restr,$i,1));
637: if ($i<length($restr)-1) { $trestr.=', '; }
638: }
639: $trestr.=')';
640: }
641: $r->print('<li>'.
642: Apache::lonnet::plaintext($prv).$trestr.
643: '</li>');
644: }
645: }
646: $r->print('</ul>');
647: }
648: }
1.4 www 649: }
1.66 www 650: $r->print(&Apache::lonnet::getannounce());
1.65 www 651: if ($advanced) {
652: $r->print('<p><small><i>This is LON-CAPA '.
1.85 ! www 653: $r->dir_config('lonVersion').'</i><br />'.
! 654: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 655: }
1.1 harris41 656: $r->print("</body></html>\n");
657: return OK;
658: }
659:
660: 1;
661: __END__
1.32 harris41 662:
663: =head1 NAME
664:
665: Apache::lonroles - User Roles Screen
666:
667: =head1 SYNOPSIS
668:
669: Invoked by /etc/httpd/conf/srm.conf:
670:
671: <Location /adm/roles>
672: PerlAccessHandler Apache::lonacc
673: SetHandler perl-script
674: PerlHandler Apache::lonroles
675: ErrorDocument 403 /adm/login
676: ErrorDocument 500 /adm/errorhandler
677: </Location>
1.64 bowersj2 678:
679: =head1 OVERVIEW
680:
681: =head2 Choosing Roles
682:
683: C<lonroles> is a handler that allows a user to switch roles in
684: mid-session. LON-CAPA attempts to work with "No Role Specified", the
685: default role that a user has before selecting a role, as widely as
686: possible, but certain handlers for example need specification which
687: course they should act on, etc. Both in this scenario, and when the
688: handler determines via C<lonnet>'s C<&allowed> function that a certain
689: action is not allowed, C<lonroles> is used as error handler. This
690: allows the user to select another role which may have permission to do
691: what they were trying to do. C<lonroles> can also be accessed via the
692: B<CRS> button in the Remote Control.
693:
694: =begin latex
695:
696: \begin{figure}
697: \begin{center}
698: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
699: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
700: \end{center}
701: \end{figure}
702:
703: =end latex
704:
705: =head2 Role Initialization
706:
707: 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 708:
709: =head1 INTRODUCTION
710:
711: This module enables a user to select what role he wishes to
712: operate under (instructor, student, teaching assistant, course
713: coordinator, etc). These roles are pre-established by the actions
714: of upper-level users.
715:
716: This is part of the LearningOnline Network with CAPA project
717: described at http://www.lon-capa.org.
718:
719: =head1 HANDLER SUBROUTINE
720:
721: This routine is called by Apache and mod_perl.
722:
723: =over 4
724:
725: =item *
726:
727: Roles Initialization (yes/no)
728:
729: =item *
730:
731: Get Error Message from Environment
732:
733: =item *
734:
735: Who is this?
736:
737: =item *
738:
739: Generate Page Output
740:
741: =item *
742:
743: Choice or no choice
744:
745: =item *
746:
747: Table
748:
749: =item *
750:
751: Privileges
752:
753: =back
754:
755: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>