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