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