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