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