Annotation of loncom/auth/lonroles.pm, revision 1.98
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.98 ! albertel 4: # $Id: lonroles.pm,v 1.97 2004/08/03 18:53:27 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.32 harris41 28: ###
1.22 harris41 29:
1.1 harris41 30: package Apache::lonroles;
31:
32: use strict;
33: use Apache::lonnet();
1.7 www 34: use Apache::lonuserstate();
1.1 harris41 35: use Apache::Constants qw(:common);
1.2 www 36: use Apache::File();
1.26 www 37: use Apache::lonmenu;
1.29 albertel 38: use Apache::loncommon;
1.57 www 39: use Apache::lonannounce;
1.72 www 40: use Apache::lonlocal;
1.1 harris41 41:
1.62 matthew 42: sub redirect_user {
1.95 albertel 43: my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62 matthew 44: $msg = $title if (! defined($msg));
1.73 www 45: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 46: &Apache::loncommon::no_cache($r);
47: $r->send_http_header;
48: my $swinfo=&Apache::lonmenu::rawconfig();
1.96 albertel 49: my $navwindow;
1.95 albertel 50: if ($launch_nav eq 'on') {
1.96 albertel 51: $navwindow.=&Apache::lonnavmaps::launch_win('now');
52: } else {
53: $navwindow.=&Apache::lonnavmaps::close();
1.95 albertel 54: }
1.62 matthew 55: my $bodytag=&Apache::loncommon::bodytag('Switching Role');
1.92 www 56: # Note to style police:
57: # This must only replace the spaces, nothing else, or it bombs elsewhere.
58: $url=~s/ /\%20/g;
1.93 albertel 59: $r->print(<<ENDREDIR);
1.62 matthew 60: <head><title>$title</title>
61: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">
62: </head>
63: <html>
64: $bodytag
1.96 albertel 65: <script type="text/javascript">
1.62 matthew 66: $swinfo
67: </script>
1.96 albertel 68: $navwindow
1.62 matthew 69: <h1>$msg</h1>
1.95 albertel 70: <a href="$url">Continue</a>
1.62 matthew 71: </body>
72: </html>
73: ENDREDIR
74: return;
75: }
76:
1.1 harris41 77: sub handler {
1.10 www 78:
1.1 harris41 79: my $r = shift;
80:
1.6 www 81: my $now=time;
82: my $then=$ENV{'user.login.time'};
83: my $envkey;
84:
1.10 www 85:
1.6 www 86: # ================================================================== Roles Init
87: if ($ENV{'form.selectrole'}) {
1.33 www 88: if ($ENV{'request.course.id'}) {
89: my %temp=('logout_'.$ENV{'request.course.id'} => time);
90: &Apache::lonnet::put('email_status',\%temp);
91: }
1.55 albertel 92: &Apache::lonnet::appenv("request.course.id" => '',
93: "request.course.fn" => '',
94: "request.course.uri" => '',
95: "request.course.sec" => '',
96: "request.role" => 'cm',
1.56 www 97: "request.role.adv" => $ENV{'user.adv'},
1.55 albertel 98: "request.role.domain" => $ENV{'user.domain'});
1.13 www 99: foreach $envkey (keys %ENV) {
1.40 matthew 100: next if ($envkey!~/^user\.role\./);
101: my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
1.6 www 102: my $where=join('.',@pwhere);
103: my $trolecode=$role.'.'.$where;
104: if ($ENV{'form.'.$trolecode}) {
1.55 albertel 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);
1.53 www 119: # check for keyed access
1.55 albertel 120: if (($role eq 'st') &&
121: ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 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(
1.55 albertel 131: $ENV{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 132: $authdom,$authnum)) {
1.53 www 133: # there is no valid key
1.55 albertel 134: if ($ENV{'form.newkey'}) {
1.53 www 135: # student attempts to register a new key
1.89 www 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');
1.90 www 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,
1.91 www 148: $cdom,$cnum,
1.90 www 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">'.
1.89 www 157: &mt('Logout').'</a>';
1.90 www 158: $buttontext=&mt('Re-Enter Key');
159: }
1.89 www 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" />
1.90 www 171: <font size="+2">$message</font><br />
1.89 www 172: <input type="submit" value="$buttontext" />
173: </form>
174: </body></html>
175: ENDENTEREDKEY
176: return OK;
1.55 albertel 177: } else {
1.53 www 178: # print form to enter a new key
1.73 www 179: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 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);
1.53 www 186: <head><title>Entering Course Access Key</title>
187: </head>
188: <html>
189: $bodytag
190: <script>
191: $swinfo
192: </script>
193: <form method="post">
1.89 www 194: <input type="hidden" name="selectrole" value="1" />
195: <input type="hidden" name="$trolecode" value="1" />
1.53 www 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
1.55 albertel 201: return OK;
202: }
203: }
204: }
1.87 www 205: &Apache::lonnet::log($ENV{'user.domain'},
206: $ENV{'user.name'},
207: $ENV{'user.home'},
208: "Role ".$trolecode);
1.56 www 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);
1.72 www 218: my $msg=&mt('Entering course ...');
1.62 matthew 219:
1.55 albertel 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/)) {
1.67 albertel 225: my $dest=$ENV{'form.orgurl'};
1.71 albertel 226: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.67 albertel 227: &Apache::lonnet::cleanenv();
1.69 albertel 228: }
1.67 albertel 229: $r->internal_redirect($dest);
1.55 albertel 230: return OK;
231: } else {
232: unless ($ENV{'request.course.id'}) {
233: &Apache::lonnet::appenv(
234: "request.course.id" => $cdom.'_'.$cnum);
1.61 www 235: $furl='/adm/roles?tryagain=1';
1.55 albertel 236: $msg=
1.72 www 237: '<h1><font color=red>'.
238: &mt('Could not initialize course at this time.').
239: '</font></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
1.55 albertel 240: }
1.58 bowersj2 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: }
1.62 matthew 253: #
254: # Send the user to the course they selected
1.78 sakharuk 255: &redirect_user($r,&mt('Entering Course'),
1.95 albertel 256: $furl,$msg,
257: $ENV{'environment.remotenavmap'});
1.20 www 258: return OK;
1.55 albertel 259: }
260: }
1.62 matthew 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 .= '/';
1.78 sakharuk 272: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 273: $redirect_url);
274: return OK;
275: }
1.55 albertel 276: }
277: }
1.6 www 278: }
1.40 matthew 279: }
1.44 www 280:
1.10 www 281:
1.6 www 282: # =============================================================== No Roles Init
1.10 www 283:
1.73 www 284: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 285: &Apache::loncommon::no_cache($r);
1.10 www 286: $r->send_http_header;
287: return OK if $r->header_only;
288:
1.52 www 289: my $swinfo=&Apache::lonmenu::rawconfig();
1.41 www 290: my $bodytag=&Apache::loncommon::bodytag('User Roles');
1.94 albertel 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>';
1.10 www 292: $r->print(<<ENDHEADER);
293: <html>
294: <head>
295: <title>LON-CAPA User Roles</title>
1.41 www 296: </head>
297: $bodytag
1.45 www 298: $helptag<br />
1.26 www 299: <script>
300: $swinfo
301: window.focus();
302: </script>
1.10 www 303: ENDHEADER
1.6 www 304:
1.2 www 305: # ------------------------------------------ Get Error Message from Environment
306:
307: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12 www 308: if ($ENV{'user.error.msg'}) {
1.55 albertel 309: $r->log_reason(
310: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
1.12 www 311: }
1.1 harris41 312:
1.61 www 313: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 314:
1.61 www 315: my $advanced=$ENV{'user.adv'};
316: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
317: my $tryagain=$ENV{'form.tryagain'};
1.6 www 318:
1.2 www 319: # -------------------------------------------------------- Generate Page Output
1.6 www 320: # --------------------------------------------------------------- Error Header?
1.2 www 321: if ($error) {
322: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 www 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>");
1.2 www 327: } else {
1.25 www 328: if ($ENV{'user.error.msg'}) {
329: $r->print(
1.72 www 330: '<h3><font color=red>'.
331: &mt('You need to choose another user role or enter a specific course for this function').'</font></h3>');
1.25 www 332: }
1.2 www 333: }
1.6 www 334: # -------------------------------------------------------- Choice or no choice?
1.2 www 335: if ($nochoose) {
1.6 www 336: if ($advanced) {
1.72 www 337: $r->print("<h2>".&mt('Assigned User Roles')."</h2>\n");
1.6 www 338: } else {
1.72 www 339: $r->print("<h2>".&mt('Sorry ...')."</h2>\n".
340: &mt('This resource might be part of'));
1.55 albertel 341: if ($ENV{'request.course.id'}) {
1.72 www 342: $r->print(&mt(' another'));
1.55 albertel 343: } else {
1.72 www 344: $r->print(&mt(' a certain'));
1.55 albertel 345: }
1.72 www 346: $r->print(&mt(' course.').'</body></html>');
1.55 albertel 347: return OK;
1.6 www 348: }
349: } else {
350: if ($advanced) {
1.72 www 351: $r->print(&mt("Your home server is ").
1.55 albertel 352: $Apache::lonnet::hostname{&Apache::lonnet::homeserver
353: ($ENV{'user.name'},$ENV{'user.domain'})}.
354: "<br />\n");
1.72 www 355: $r->print(&mt(
356: "Author and Co-Author roles may not be available on servers other than your home server."));
1.17 www 357: }
1.18 www 358: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
359: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 360: }
1.84 www 361: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.6 www 362: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
363: $r->print('<input type=hidden name=selectrole value=1>');
364: }
1.63 www 365: if ($ENV{'user.adv'}) {
366: $r->print(
1.72 www 367: '<br />'.&mt('Show all roles').': <input type="checkbox" name="showall"');
1.63 www 368: if ($ENV{'form.showall'}) { $r->print(' checked'); }
1.72 www 369: $r->print('><input type=submit value="'.&mt('Display').'">');
1.63 www 370: }
1.4 www 371:
1.75 albertel 372: my (%roletext,%sortrole,%roleclass);
1.84 www 373: my $countactive=0;
374: my $inrole=0;
375: my $possiblerole='';
1.3 albertel 376: foreach $envkey (sort keys %ENV) {
1.35 matthew 377: my $button = 1;
1.49 www 378: my $switchserver='';
1.75 albertel 379: my $roletext;
380: my $sortkey;
1.2 www 381: if ($envkey=~/^user\.role\./) {
1.40 matthew 382: my (undef,undef,$role,@pwhere)=split(/\./,$envkey);
1.46 matthew 383: next if (!defined($role) || $role eq '');
1.4 www 384: my $where=join('.',@pwhere);
1.6 www 385: my $trolecode=$role.'.'.$where;
1.4 www 386: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
387: my $tremark='';
388: my $tstatus='is';
389: my $tpstart=' ';
390: my $tpend=' ';
1.47 www 391: my $tfont='#000000';
1.4 www 392: if ($tstart) {
393: if ($tstart>$then) {
1.35 matthew 394: $tstatus='future';
395: if ($tstart<$now) { $tstatus='will'; }
1.4 www 396: }
1.74 www 397: $tpstart=&Apache::lonlocal::locallocaltime($tstart);
1.4 www 398: }
399: if ($tend) {
1.23 www 400: if ($tend<$then) {
1.35 matthew 401: $tstatus='expired';
1.23 www 402: } elsif ($tend<$now) {
1.35 matthew 403: $tstatus='will_not';
1.23 www 404: }
1.74 www 405: $tpend=&Apache::lonlocal::locallocaltime($tend);
1.4 www 406: }
1.6 www 407: if ($ENV{'request.role'} eq $trolecode) {
408: $tstatus='selected';
409: }
1.4 www 410: my $tbg;
1.35 matthew 411: if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
412: ($ENV{'form.showall'})) {
413: if ($tstatus eq 'is') {
414: $tbg='#77FF77';
1.47 www 415: $tfont='#003300';
1.84 www 416: $possiblerole=$trolecode;
417: $countactive++;
1.35 matthew 418: } elsif ($tstatus eq 'future') {
419: $tbg='#FFFF77';
1.49 www 420: $button=0;
1.35 matthew 421: } elsif ($tstatus eq 'will') {
422: $tbg='#FFAA77';
1.72 www 423: $tremark.=&mt('Active at next login. ');
1.35 matthew 424: } elsif ($tstatus eq 'expired') {
425: $tbg='#FF7777';
1.47 www 426: $tfont='#330000';
1.49 www 427: $button=0;
1.35 matthew 428: } elsif ($tstatus eq 'will_not') {
429: $tbg='#AAFF77';
1.72 www 430: $tremark.=&mt('Expired after logout. ');
1.35 matthew 431: } elsif ($tstatus eq 'selected') {
432: $tbg='#11CC55';
1.47 www 433: $tfont='#002200';
1.84 www 434: $inrole=1;
1.86 albertel 435: $countactive++;
1.72 www 436: $tremark.=&mt('Currently selected. ');
1.35 matthew 437: }
438: my $trole;
439: if ($role =~ /^cr\//) {
440: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.72 www 441: $tremark.='<br>'.&mt('Defined by ').$rauthor.
442: &mt(' at ').$rdomain.'.';
1.35 matthew 443: $trole=$rrole;
1.8 www 444: } else {
1.35 matthew 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') {
1.39 stredwic 453: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83 albertel 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) {
1.49 www 458: $button=0;
1.51 www 459: $switchserver=&Apache::lonnet::escape('http://'.
460: $Apache::lonnet::hostname{$home}.
461: '/adm/login?domain='.$ENV{'user.domain'}.
462: '&username='.$ENV{'user.name'}.
1.97 albertel 463: '&firsturl=/priv/'.$trest.'/');
1.49 www 464: }
1.35 matthew 465: #next if ($home eq 'no_host');
466: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 467: $ttype='Construction Space';
1.72 www 468: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
469: ': '.$tdom.'<br />'.
470: ' '.&mt('Server').': '.$home;
1.35 matthew 471: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 472: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75 albertel 473: $sortkey=$role."$trest:$tdom";
1.35 matthew 474: } elsif ($role eq 'au') {
475: # Authors
476: my $home = &Apache::lonnet::homeserver
1.39 stredwic 477: ($ENV{'user.name'},$ENV{'user.domain'});
1.83 albertel 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) {
1.49 www 482: $button=0;
1.51 www 483: $switchserver=&Apache::lonnet::escape('http://'.
484: $Apache::lonnet::hostname{$home}.
485: '/adm/login?domain='.$ENV{'user.domain'}.
486: '&username='.$ENV{'user.name'}.
1.97 albertel 487: '&firsturl=/priv/'.$ENV{'user.name'}.'/');
1.49 www 488: }
1.35 matthew 489: #next if ($home eq 'no_host');
490: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 491: $ttype='Construction Space';
1.72 www 492: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
493: ': '.$home;
1.35 matthew 494: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 495: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/');
1.75 albertel 496: $sortkey=$role;
1.35 matthew 497: } elsif ($trest) {
1.78 sakharuk 498: $ttype='Course';
1.35 matthew 499: if ($tsection) {
1.72 www 500: $ttype.='<br>'.&mt('Section/Group').': '.$tsection;
1.37 albertel 501: }
1.35 matthew 502: my $tcourseid=$tdom.'_'.$trest;
503: if ($ENV{'course.'.$tcourseid.'.description'}) {
1.47 www 504: $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.80 albertel 505: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72 www 506: unless ($twhere eq &mt('Currently not available')) {
1.55 albertel 507: $twhere.=' <font size="-2">'.
1.72 www 508: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 509: '</font>';
1.55 albertel 510: }
1.8 www 511: } else {
1.35 matthew 512: my %newhash=Apache::lonnet::coursedescription
513: ($tcourseid);
514: if (%newhash) {
1.80 albertel 515: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77 albertel 516: "\0".$envkey;
1.49 www 517: $twhere=$newhash{'description'}.
518: ' <font size="-2">'.
1.72 www 519: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 520: '</font>';
1.35 matthew 521: } else {
1.72 www 522: $twhere=&mt('Currently not available');
1.35 matthew 523: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.80 albertel 524: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.35 matthew 525: }
1.8 www 526: }
1.72 www 527: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35 matthew 528: } elsif ($tdom) {
1.78 sakharuk 529: $ttype='Domain';
1.35 matthew 530: $twhere=$tdom;
1.75 albertel 531: $sortkey=$role.$twhere;
1.35 matthew 532: } else {
1.78 sakharuk 533: $ttype='System';
1.72 www 534: $twhere=&mt('system wide');
1.75 albertel 535: $sortkey=$role.$twhere;
1.13 www 536: }
1.35 matthew 537:
1.75 albertel 538: $roletext.='<tr bgcolor='.$tbg.'>';
1.35 matthew 539: unless ($nochoose) {
540: if (!$button) {
1.49 www 541: if ($switchserver) {
1.75 albertel 542: $roletext.='<td><a href="/adm/logout?handover='.
543: $switchserver.'">'.&mt('Switch Server').'</a></td>';
1.49 www 544: } else {
1.75 albertel 545: $roletext.=('<td> </td>');
1.49 www 546: }
1.35 matthew 547: } elsif ($tstatus eq 'is') {
1.75 albertel 548: $roletext.=('<td><input type=submit value="'.
1.72 www 549: &mt('Select').'" name="'.
1.35 matthew 550: $trolecode.'"></td>');
1.61 www 551: } elsif ($tryagain) {
1.75 albertel 552: $roletext.=
553: '<td><input type=submit value="'.
554: &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
1.61 www 555: } elsif ($advanced) {
1.75 albertel 556: $roletext.=
557: '<td><input type=submit value="'.
558: &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
1.35 matthew 559: } else {
1.75 albertel 560: $roletext.='<td> </td>';
1.35 matthew 561: }
1.6 www 562: }
1.57 www 563: $tremark.=&Apache::lonannounce::showday(time,1,
564: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
565:
1.75 albertel 566: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.47 www 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.
1.75 albertel 572: ' </font></td></tr>'."\n";
573: $roletext{$envkey}=$roletext;
574: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
575: $sortrole{$sortkey}=$envkey;
576: $roleclass{$envkey}=$ttype;
1.55 albertel 577: }
1.4 www 578: }
1.75 albertel 579: }
1.84 www 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?
1.88 www 590: } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) {
1.84 www 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");
1.76 albertel 609: my $doheaders=-1;
1.78 sakharuk 610: foreach my $type ('Construction Space','Course','Domain','System') {
1.76 albertel 611: my $haverole=0;
1.75 albertel 612: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
613: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.76 albertel 614: $haverole=1;
1.75 albertel 615: }
1.76 albertel 616: }
617: if ($haverole) { $doheaders++; }
618: }
1.78 sakharuk 619: foreach my $type ('Construction Space','Course','Domain','System') {
1.76 albertel 620: my $output;
621: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
622: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.78 sakharuk 623: $output.=&mt($roletext{$sortrole{$which}});
1.76 albertel 624: }
625: }
626: if ($output) {
627: if ($doheaders > 0) {
1.77 albertel 628: $r->print("<tr bgcolor='#BBffBB'>".
1.79 sakharuk 629: "<td align='center' colspan='7'>".&mt($type)."</td>");
1.76 albertel 630: }
631: $r->print($output);
1.75 albertel 632: }
1.4 www 633: }
1.14 www 634: my $tremark='';
1.47 www 635: my $tfont='#003300';
1.14 www 636: if ($ENV{'request.role'} eq 'cm') {
1.19 www 637: $r->print('<tr bgcolor="#11CC55">');
1.72 www 638: $tremark=&mt('Currently selected. ');
1.47 www 639: $tfont='#002200';
1.14 www 640: } else {
641: $r->print('<tr bgcolor="#77FF77">');
642: }
643: unless ($nochoose) {
1.55 albertel 644: if ($ENV{'request.role'} ne 'cm') {
1.72 www 645: $r->print('<td><input type=submit value="'.
646: &mt('Select').'" name="cm"></td>');
1.55 albertel 647: } else {
648: $r->print('<td> </td>');
649: }
1.14 www 650: }
1.72 www 651: $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
1.47 www 652: '</font></td><td><font color="'.$tfont.'">'.$tremark.
653: ' </font></td></tr>'."\n");
1.4 www 654:
655: $r->print('</table>');
656: unless ($nochoose) {
657: $r->print("</form>\n");
658: }
1.22 harris41 659: # ------------------------------------------------------------ Privileges Info
1.55 albertel 660: if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
661: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 662:
1.55 albertel 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: }
1.4 www 712: }
1.66 www 713: $r->print(&Apache::lonnet::getannounce());
1.65 www 714: if ($advanced) {
715: $r->print('<p><small><i>This is LON-CAPA '.
1.85 www 716: $r->dir_config('lonVersion').'</i><br />'.
717: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 718: }
1.1 harris41 719: $r->print("</body></html>\n");
720: return OK;
721: }
722:
723: 1;
724: __END__
1.32 harris41 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>
1.64 bowersj2 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.
1.32 harris41 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>