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