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