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