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