1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.85 2004/01/31 00:46:45 www Exp $
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: #
28: ###
29:
30: package Apache::lonroles;
31:
32: use strict;
33: use Apache::lonnet();
34: use Apache::lonuserstate();
35: use Apache::Constants qw(:common);
36: use Apache::File();
37: use Apache::lonmenu;
38: use Apache::loncommon;
39: use Apache::lonannounce;
40: use Apache::lonlocal;
41:
42: sub redirect_user {
43: my ($r,$title,$url,$msg) = @_;
44: $msg = $title if (! defined($msg));
45: &Apache::loncommon::content_type($r,'text/html');
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:
66: sub handler {
67:
68: my $r = shift;
69:
70: my $now=time;
71: my $then=$ENV{'user.login.time'};
72: my $envkey;
73:
74:
75: # ================================================================== Roles Init
76:
77: if ($ENV{'form.selectrole'}) {
78: if ($ENV{'request.course.id'}) {
79: my %temp=('logout_'.$ENV{'request.course.id'} => time);
80: &Apache::lonnet::put('email_status',\%temp);
81: }
82: &Apache::lonnet::appenv("request.course.id" => '',
83: "request.course.fn" => '',
84: "request.course.uri" => '',
85: "request.course.sec" => '',
86: "request.role" => 'cm',
87: "request.role.adv" => $ENV{'user.adv'},
88: "request.role.domain" => $ENV{'user.domain'});
89: foreach $envkey (keys %ENV) {
90: next if ($envkey!~/^user\.role\./);
91: my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
92: my $where=join('.',@pwhere);
93: my $trolecode=$role.'.'.$where;
94: if ($ENV{'form.'.$trolecode}) {
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);
109: # check for keyed access
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)) {
115: # there is no valid key
116: if ($ENV{'form.newkey'}) {
117: # student attempts to register a new key
118: } else {
119: # print form to enter a new key
120: &Apache::loncommon::content_type($r,'text/html');
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);
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
141: return OK;
142: }
143: }
144: }
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);
154: my $msg=&mt('Entering course ...');
155:
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/)) {
161: my $dest=$ENV{'form.orgurl'};
162: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
163: &Apache::lonnet::cleanenv();
164: }
165: $r->internal_redirect($dest);
166: return OK;
167: } else {
168: unless ($ENV{'request.course.id'}) {
169: &Apache::lonnet::appenv(
170: "request.course.id" => $cdom.'_'.$cnum);
171: $furl='/adm/roles?tryagain=1';
172: $msg=
173: '<h1><font color=red>'.
174: &mt('Could not initialize course at this time.').
175: '</font></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
176: }
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: }
189: #
190: # Send the user to the course they selected
191: &redirect_user($r,&mt('Entering Course'),
192: $furl,$msg);
193: return OK;
194: }
195: }
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 .= '/';
207: &redirect_user($r,&mt('Entering Construction Space'),
208: $redirect_url);
209: return OK;
210: }
211: }
212: }
213: }
214: }
215:
216:
217: # =============================================================== No Roles Init
218:
219: &Apache::loncommon::content_type($r,'text/html');
220: &Apache::loncommon::no_cache($r);
221: $r->send_http_header;
222: return OK if $r->header_only;
223:
224: my $swinfo=&Apache::lonmenu::rawconfig();
225: my $bodytag=&Apache::loncommon::bodytag('User Roles');
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>';
230: $r->print(<<ENDHEADER);
231: <html>
232: <head>
233: <title>LON-CAPA User Roles</title>
234: </head>
235: $bodytag
236: $helptag<br />
237: <script>
238: $swinfo
239: window.focus();
240: </script>
241: ENDHEADER
242:
243: # ------------------------------------------ Get Error Message from Environment
244:
245: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
246: if ($ENV{'user.error.msg'}) {
247: $r->log_reason(
248: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
249: }
250:
251: # ------------------------------------------------- Can this user re-init, etc?
252:
253: my $advanced=$ENV{'user.adv'};
254: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
255: my $tryagain=$ENV{'form.tryagain'};
256:
257: # -------------------------------------------------------- Generate Page Output
258: # --------------------------------------------------------------- Error Header?
259: if ($error) {
260: $r->print("<h1>LON-CAPA Access Control</h1>");
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>");
265: } else {
266: if ($ENV{'user.error.msg'}) {
267: $r->print(
268: '<h3><font color=red>'.
269: &mt('You need to choose another user role or enter a specific course for this function').'</font></h3>');
270: }
271: }
272: # -------------------------------------------------------- Choice or no choice?
273: if ($nochoose) {
274: if ($advanced) {
275: $r->print("<h2>".&mt('Assigned User Roles')."</h2>\n");
276: } else {
277: $r->print("<h2>".&mt('Sorry ...')."</h2>\n".
278: &mt('This resource might be part of'));
279: if ($ENV{'request.course.id'}) {
280: $r->print(&mt(' another'));
281: } else {
282: $r->print(&mt(' a certain'));
283: }
284: $r->print(&mt(' course.').'</body></html>');
285: return OK;
286: }
287: } else {
288: if ($advanced) {
289: $r->print(&mt("Your home server is ").
290: $Apache::lonnet::hostname{&Apache::lonnet::homeserver
291: ($ENV{'user.name'},$ENV{'user.domain'})}.
292: "<br />\n");
293: $r->print(&mt(
294: "Author and Co-Author roles may not be available on servers other than your home server."));
295: }
296: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
297: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
298: }
299: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
300: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
301: $r->print('<input type=hidden name=selectrole value=1>');
302: }
303: if ($ENV{'user.adv'}) {
304: $r->print(
305: '<br />'.&mt('Show all roles').': <input type="checkbox" name="showall"');
306: if ($ENV{'form.showall'}) { $r->print(' checked'); }
307: $r->print('><input type=submit value="'.&mt('Display').'">');
308: }
309:
310: my (%roletext,%sortrole,%roleclass);
311: my $countactive=0;
312: my $inrole=0;
313: my $possiblerole='';
314: foreach $envkey (sort keys %ENV) {
315: my $button = 1;
316: my $switchserver='';
317: my $roletext;
318: my $sortkey;
319: if ($envkey=~/^user\.role\./) {
320: my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
321: next if (!defined($role) || $role eq '');
322: my $where=join('.',@pwhere);
323: my $trolecode=$role.'.'.$where;
324: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
325: my $tremark='';
326: my $tstatus='is';
327: my $tpstart=' ';
328: my $tpend=' ';
329: my $tfont='#000000';
330: if ($tstart) {
331: if ($tstart>$then) {
332: $tstatus='future';
333: if ($tstart<$now) { $tstatus='will'; }
334: }
335: $tpstart=&Apache::lonlocal::locallocaltime($tstart);
336: }
337: if ($tend) {
338: if ($tend<$then) {
339: $tstatus='expired';
340: } elsif ($tend<$now) {
341: $tstatus='will_not';
342: }
343: $tpend=&Apache::lonlocal::locallocaltime($tend);
344: }
345: if ($ENV{'request.role'} eq $trolecode) {
346: $tstatus='selected';
347: }
348: my $tbg;
349: if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
350: ($ENV{'form.showall'})) {
351: if ($tstatus eq 'is') {
352: $tbg='#77FF77';
353: $tfont='#003300';
354: $possiblerole=$trolecode;
355: $countactive++;
356: } elsif ($tstatus eq 'future') {
357: $tbg='#FFFF77';
358: $button=0;
359: } elsif ($tstatus eq 'will') {
360: $tbg='#FFAA77';
361: $tremark.=&mt('Active at next login. ');
362: } elsif ($tstatus eq 'expired') {
363: $tbg='#FF7777';
364: $tfont='#330000';
365: $button=0;
366: } elsif ($tstatus eq 'will_not') {
367: $tbg='#AAFF77';
368: $tremark.=&mt('Expired after logout. ');
369: } elsif ($tstatus eq 'selected') {
370: $tbg='#11CC55';
371: $tfont='#002200';
372: $inrole=1;
373: $tremark.=&mt('Currently selected. ');
374: }
375: my $trole;
376: if ($role =~ /^cr\//) {
377: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
378: $tremark.='<br>'.&mt('Defined by ').$rauthor.
379: &mt(' at ').$rdomain.'.';
380: $trole=$rrole;
381: } else {
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') {
390: my $home = &Apache::lonnet::homeserver($trest,$tdom);
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) {
395: $button=0;
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);
401: }
402: #next if ($home eq 'no_host');
403: $home = $Apache::lonnet::hostname{$home};
404: $ttype='Construction Space';
405: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
406: ': '.$tdom.'<br />'.
407: ' '.&mt('Server').': '.$home;
408: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
409: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
410: $sortkey=$role."$trest:$tdom";
411: } elsif ($role eq 'au') {
412: # Authors
413: my $home = &Apache::lonnet::homeserver
414: ($ENV{'user.name'},$ENV{'user.domain'});
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) {
419: $button=0;
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'});
425: }
426: #next if ($home eq 'no_host');
427: $home = $Apache::lonnet::hostname{$home};
428: $ttype='Construction Space';
429: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
430: ': '.$home;
431: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
432: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/');
433: $sortkey=$role;
434: } elsif ($trest) {
435: $ttype='Course';
436: if ($tsection) {
437: $ttype.='<br>'.&mt('Section/Group').': '.$tsection;
438: }
439: my $tcourseid=$tdom.'_'.$trest;
440: if ($ENV{'course.'.$tcourseid.'.description'}) {
441: $twhere=$ENV{'course.'.$tcourseid.'.description'};
442: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
443: unless ($twhere eq &mt('Currently not available')) {
444: $twhere.=' <font size="-2">'.
445: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
446: '</font>';
447: }
448: } else {
449: my %newhash=Apache::lonnet::coursedescription
450: ($tcourseid);
451: if (%newhash) {
452: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
453: "\0".$envkey;
454: $twhere=$newhash{'description'}.
455: ' <font size="-2">'.
456: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
457: '</font>';
458: } else {
459: $twhere=&mt('Currently not available');
460: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
461: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
462: }
463: }
464: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
465: } elsif ($tdom) {
466: $ttype='Domain';
467: $twhere=$tdom;
468: $sortkey=$role.$twhere;
469: } else {
470: $ttype='System';
471: $twhere=&mt('system wide');
472: $sortkey=$role.$twhere;
473: }
474:
475: $roletext.='<tr bgcolor='.$tbg.'>';
476: unless ($nochoose) {
477: if (!$button) {
478: if ($switchserver) {
479: $roletext.='<td><a href="/adm/logout?handover='.
480: $switchserver.'">'.&mt('Switch Server').'</a></td>';
481: } else {
482: $roletext.=('<td> </td>');
483: }
484: } elsif ($tstatus eq 'is') {
485: $roletext.=('<td><input type=submit value="'.
486: &mt('Select').'" name="'.
487: $trolecode.'"></td>');
488: } elsif ($tryagain) {
489: $roletext.=
490: '<td><input type=submit value="'.
491: &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
492: } elsif ($advanced) {
493: $roletext.=
494: '<td><input type=submit value="'.
495: &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
496: } else {
497: $roletext.='<td> </td>';
498: }
499: }
500: $tremark.=&Apache::lonannounce::showday(time,1,
501: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
502:
503: $roletext.='<td><font color="'.$tfont.'">'.$trole.
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.
509: ' </font></td></tr>'."\n";
510: $roletext{$envkey}=$roletext;
511: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
512: $sortrole{$sortkey}=$envkey;
513: $roleclass{$envkey}=$ttype;
514: }
515: }
516: }
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");
546: my $doheaders=-1;
547: foreach my $type ('Construction Space','Course','Domain','System') {
548: my $haverole=0;
549: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
550: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
551: $haverole=1;
552: }
553: }
554: if ($haverole) { $doheaders++; }
555: }
556: foreach my $type ('Construction Space','Course','Domain','System') {
557: my $output;
558: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
559: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
560: $output.=&mt($roletext{$sortrole{$which}});
561: }
562: }
563: if ($output) {
564: if ($doheaders > 0) {
565: $r->print("<tr bgcolor='#BBffBB'>".
566: "<td align='center' colspan='7'>".&mt($type)."</td>");
567: }
568: $r->print($output);
569: }
570: }
571: my $tremark='';
572: my $tfont='#003300';
573: if ($ENV{'request.role'} eq 'cm') {
574: $r->print('<tr bgcolor="#11CC55">');
575: $tremark=&mt('Currently selected. ');
576: $tfont='#002200';
577: } else {
578: $r->print('<tr bgcolor="#77FF77">');
579: }
580: unless ($nochoose) {
581: if ($ENV{'request.role'} ne 'cm') {
582: $r->print('<td><input type=submit value="'.
583: &mt('Select').'" name="cm"></td>');
584: } else {
585: $r->print('<td> </td>');
586: }
587: }
588: $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
589: '</font></td><td><font color="'.$tfont.'">'.$tremark.
590: ' </font></td></tr>'."\n");
591:
592: $r->print('</table>');
593: unless ($nochoose) {
594: $r->print("</form>\n");
595: }
596: # ------------------------------------------------------------ Privileges Info
597: if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
598: $r->print('<hr><h2>Current Privileges</h2>');
599:
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: }
649: }
650: $r->print(&Apache::lonnet::getannounce());
651: if ($advanced) {
652: $r->print('<p><small><i>This is LON-CAPA '.
653: $r->dir_config('lonVersion').'</i><br />'.
654: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
655: }
656: $r->print("</body></html>\n");
657: return OK;
658: }
659:
660: 1;
661: __END__
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>
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.
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>