Annotation of loncom/auth/lonroles.pm, revision 1.106
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.106 ! raeburn 4: # $Id: lonroles.pm,v 1.105 2004/11/09 20:04:48 raeburn 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.104 raeburn 39: use Apache::lonhtmlcommon;
1.57 www 40: use Apache::lonannounce;
1.72 www 41: use Apache::lonlocal;
1.1 harris41 42:
1.62 matthew 43: sub redirect_user {
1.95 albertel 44: my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62 matthew 45: $msg = $title if (! defined($msg));
1.73 www 46: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 47: &Apache::loncommon::no_cache($r);
48: $r->send_http_header;
49: my $swinfo=&Apache::lonmenu::rawconfig();
1.96 albertel 50: my $navwindow;
1.95 albertel 51: if ($launch_nav eq 'on') {
1.96 albertel 52: $navwindow.=&Apache::lonnavmaps::launch_win('now');
53: } else {
54: $navwindow.=&Apache::lonnavmaps::close();
1.95 albertel 55: }
1.62 matthew 56: my $bodytag=&Apache::loncommon::bodytag('Switching Role');
1.92 www 57: # Note to style police:
58: # This must only replace the spaces, nothing else, or it bombs elsewhere.
59: $url=~s/ /\%20/g;
1.93 albertel 60: $r->print(<<ENDREDIR);
1.62 matthew 61: <head><title>$title</title>
62: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">
63: </head>
64: <html>
65: $bodytag
1.96 albertel 66: <script type="text/javascript">
1.62 matthew 67: $swinfo
68: </script>
1.96 albertel 69: $navwindow
1.62 matthew 70: <h1>$msg</h1>
1.95 albertel 71: <a href="$url">Continue</a>
1.62 matthew 72: </body>
73: </html>
74: ENDREDIR
75: return;
76: }
77:
1.1 harris41 78: sub handler {
1.10 www 79:
1.1 harris41 80: my $r = shift;
81:
1.6 www 82: my $now=time;
83: my $then=$ENV{'user.login.time'};
84: my $envkey;
1.104 raeburn 85: my $dcselect='';
1.6 www 86:
1.10 www 87:
1.6 www 88: # ================================================================== Roles Init
89: if ($ENV{'form.selectrole'}) {
1.104 raeburn 90: if ($ENV{'form.dcselected'}) {
91: my $dcdom = $ENV{'form.dcselected'};
92: my $dckey = 'user.role.dc./'.$dcdom.'/';
93: if ($ENV{$dckey}) {
94: my ($dcstart,$dcend)=split(/\./,$ENV{$dckey});
95: my $active_dc = 1;
96: if ($dcstart) {
97: if ($dcstart>$then) {
98: $active_dc = 0;
99: }
100: }
101: if ($dcend) {
102: if ($dcend < $then) {
103: $active_dc = 0;
104: }
105: }
106: if ($active_dc) {
107: $dcselect = $dcdom;
108: }
109: }
110: }
1.33 www 111: if ($ENV{'request.course.id'}) {
112: my %temp=('logout_'.$ENV{'request.course.id'} => time);
113: &Apache::lonnet::put('email_status',\%temp);
1.100 albertel 114: &Apache::lonnet::delenv('user.state.'.$ENV{'request.course.id'});
115: }
1.55 albertel 116: &Apache::lonnet::appenv("request.course.id" => '',
117: "request.course.fn" => '',
118: "request.course.uri" => '',
119: "request.course.sec" => '',
120: "request.role" => 'cm',
1.56 www 121: "request.role.adv" => $ENV{'user.adv'},
1.55 albertel 122: "request.role.domain" => $ENV{'user.domain'});
1.106 ! raeburn 123:
! 124: # Check to see if the user is a DC trying to enter a course
! 125: # course selection page
! 126: my $dcflag = 0;
! 127: if ($ENV{'form.dccourse'}) {
! 128: my $dcdom = $ENV{'form.dcdomain'};
! 129: my $pickedcourse = $ENV{'form.dccourse'};
! 130: if ($dcdom && $pickedcourse) {
! 131: unless ($ENV{'user.role.cc./'.$dcdom.'/'.$pickedcourse}) {
! 132: if ($ENV{'user.role.dc./'.$dcdom.'/'}) {
! 133: &set_privileges($dcdom,$pickedcourse);
! 134: my $msg=&mt('Entering course ...');
! 135: my ($furl,$ferr)=&Apache::lonuserstate::readmap($dcdom.'/'.$pickedcourse);
! 136: my $formaction = '/adm/roles/';
! 137: my $courseid = $dcdom.'_'.$pickedcourse;
! 138: &Apache::lonhtmlcommon::store_recent('cc_pickby_dc_'.$dcdom,
! 139: $courseid,$formaction);
! 140: # Send the user to the course they selected
! 141: &redirect_user($r,&mt('Entering Course'),
! 142: $furl,$msg,
! 143: $ENV{'environment.remotenavmap'});
! 144: return OK;
! 145: }
! 146: }
! 147: }
! 148: }
! 149:
1.13 www 150: foreach $envkey (keys %ENV) {
1.40 matthew 151: next if ($envkey!~/^user\.role\./);
1.102 raeburn 152: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
153: &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.6 www 154: if ($ENV{'form.'.$trolecode}) {
1.55 albertel 155: if ($tstatus eq 'is') {
156: $where=~s/^\///;
157: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.53 www 158: # check for keyed access
1.55 albertel 159: if (($role eq 'st') &&
160: ($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 161: # who is key authority?
162: my $authdom=$cdom;
163: my $authnum=$cnum;
164: if ($ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
165: ($authnum,$authdom)=
166: split(/\W/,$ENV{'course.'.$cdom.'_'.$cnum.'.keyauth'});
167: }
168: # check with key authority
169: unless (&Apache::lonnet::validate_access_key(
1.55 albertel 170: $ENV{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 171: $authdom,$authnum)) {
1.53 www 172: # there is no valid key
1.55 albertel 173: if ($ENV{'form.newkey'}) {
1.53 www 174: # student attempts to register a new key
1.89 www 175: &Apache::loncommon::content_type($r,'text/html');
176: &Apache::loncommon::no_cache($r);
177: $r->send_http_header;
178: my $swinfo=&Apache::lonmenu::rawconfig();
179: my $bodytag=&Apache::loncommon::bodytag
180: ('Verifying Access Key to Unlock this Course');
1.90 www 181: my $buttontext=&mt('Enter Course');
182: my $message=&mt('Successfully registered key');
183: my $assignresult=
184: &Apache::lonnet::assign_access_key(
185: $ENV{'form.newkey'},
186: $authdom,$authnum,
1.91 www 187: $cdom,$cnum,
1.90 www 188: $ENV{'user.domain'},
189: $ENV{'user.name'},
190: 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
191: $trolecode);
192: unless ($assignresult eq 'ok') {
193: $assignresult=~s/^error\:\s*//;
194: $message=&mt($assignresult).
195: '<br /><a href="/adm/logout">'.
1.89 www 196: &mt('Logout').'</a>';
1.90 www 197: $buttontext=&mt('Re-Enter Key');
198: }
1.89 www 199: $r->print(<<ENDENTEREDKEY);
200: <head><title>Verifying Course Access Key</title>
201: </head>
202: <html>
203: $bodytag
204: <script>
205: $swinfo
206: </script>
207: <form method="post">
208: <input type="hidden" name="selectrole" value="1" />
209: <input type="hidden" name="$trolecode" value="1" />
1.90 www 210: <font size="+2">$message</font><br />
1.89 www 211: <input type="submit" value="$buttontext" />
212: </form>
213: </body></html>
214: ENDENTEREDKEY
215: return OK;
1.55 albertel 216: } else {
1.53 www 217: # print form to enter a new key
1.73 www 218: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 219: &Apache::loncommon::no_cache($r);
220: $r->send_http_header;
221: my $swinfo=&Apache::lonmenu::rawconfig();
222: my $bodytag=&Apache::loncommon::bodytag
223: ('Enter Access Key to Unlock this Course');
224: $r->print(<<ENDENTERKEY);
1.53 www 225: <head><title>Entering Course Access Key</title>
226: </head>
227: <html>
228: $bodytag
229: <script>
230: $swinfo
231: </script>
232: <form method="post">
1.89 www 233: <input type="hidden" name="selectrole" value="1" />
234: <input type="hidden" name="$trolecode" value="1" />
1.53 www 235: <input type="text" size="20" name="newkey" value="$ENV{'form.newkey'}" />
236: <input type="submit" value="Enter key" />
237: </form>
238: </body></html>
239: ENDENTERKEY
1.55 albertel 240: return OK;
241: }
242: }
243: }
1.87 www 244: &Apache::lonnet::log($ENV{'user.domain'},
245: $ENV{'user.name'},
246: $ENV{'user.home'},
247: "Role ".$trolecode);
1.101 albertel 248:
1.56 www 249: &Apache::lonnet::appenv(
1.101 albertel 250: 'request.role' => $trolecode,
1.56 www 251: 'request.role.domain' => $cdom,
252: 'request.course.sec' => $csec);
1.101 albertel 253: my $tadv=0;
254: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
255: &Apache::lonnet::appenv('request.role.adv' => $tadv);
256:
1.72 www 257: my $msg=&mt('Entering course ...');
1.62 matthew 258:
1.55 albertel 259: if (($cnum) && ($role ne 'ca')) {
260: my ($furl,$ferr)=
261: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
262: if (($ENV{'form.orgurl'}) &&
263: ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.67 albertel 264: my $dest=$ENV{'form.orgurl'};
1.71 albertel 265: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.67 albertel 266: &Apache::lonnet::cleanenv();
1.69 albertel 267: }
1.67 albertel 268: $r->internal_redirect($dest);
1.55 albertel 269: return OK;
270: } else {
271: unless ($ENV{'request.course.id'}) {
272: &Apache::lonnet::appenv(
273: "request.course.id" => $cdom.'_'.$cnum);
1.61 www 274: $furl='/adm/roles?tryagain=1';
1.55 albertel 275: $msg=
1.72 www 276: '<h1><font color=red>'.
277: &mt('Could not initialize course at this time.').
278: '</font></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
1.55 albertel 279: }
1.58 bowersj2 280:
281: # Check to see if the user is a CC entering a course
282: # for the first time
283: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
284: if (substr($courseid, 0, 1) eq '/') {
285: $courseid = substr($courseid, 1);
286: }
287: $courseid =~ s/\//_/;
288: if ($role eq 'cc' && $ENV{'course.' . $courseid .
289: '.course.helper.not.run'}) {
290: $furl = "/adm/helper/course.initialization.helper";
291: }
1.104 raeburn 292: # Check to see if the user is a DC coming from the
293: # course selection page
294: my $dcflag = 0;
295: if ($ENV{'form.dccourse'}) {
296: my $formaction = '/adm/roles/';
297: my ($dcdom,$pickedcourse) = split/_/,$courseid;
298: if ($ENV{'user.role.dc./'.$dcdom.'/'}) {
299: &Apache::lonhtmlcommon::store_recent('cc_pickby_dc_'.$dcdom,
300: $courseid,$formaction);
301: }
302: }
1.62 matthew 303: #
304: # Send the user to the course they selected
1.78 sakharuk 305: &redirect_user($r,&mt('Entering Course'),
1.95 albertel 306: $furl,$msg,
307: $ENV{'environment.remotenavmap'});
1.20 www 308: return OK;
1.55 albertel 309: }
310: }
1.62 matthew 311: #
312: # Send the user to the construction space they selected
313: if ($role =~ /^(au|ca)$/) {
314: my $redirect_url = '/priv/';
315: if ($role eq 'au') {
316: $redirect_url.=$ENV{'user.name'};
317: } else {
318: $where =~ /\/(.*)$/;
319: $redirect_url .= $1;
320: }
321: $redirect_url .= '/';
1.78 sakharuk 322: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 323: $redirect_url);
324: return OK;
325: }
1.104 raeburn 326: if ($role eq 'dc') {
327: unless ($dcselect) {
328: my $redirect_url = '/adm/menu/';
329: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
330: $redirect_url);
331: return OK;
332: }
333: }
1.55 albertel 334: }
335: }
1.6 www 336: }
1.40 matthew 337: }
1.44 www 338:
1.10 www 339:
1.6 www 340: # =============================================================== No Roles Init
1.10 www 341:
1.73 www 342: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 343: &Apache::loncommon::no_cache($r);
1.10 www 344: $r->send_http_header;
345: return OK if $r->header_only;
346:
1.52 www 347: my $swinfo=&Apache::lonmenu::rawconfig();
1.104 raeburn 348: my $setDCchoice = &dc_script();
1.41 www 349: my $bodytag=&Apache::loncommon::bodytag('User Roles');
1.94 albertel 350: 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 351: $r->print(<<ENDHEADER);
352: <html>
353: <head>
354: <title>LON-CAPA User Roles</title>
1.41 www 355: </head>
356: $bodytag
1.45 www 357: $helptag<br />
1.26 www 358: <script>
359: $swinfo
360: window.focus();
1.104 raeburn 361: $setDCchoice
1.26 www 362: </script>
1.10 www 363: ENDHEADER
1.6 www 364:
1.2 www 365: # ------------------------------------------ Get Error Message from Environment
366:
367: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12 www 368: if ($ENV{'user.error.msg'}) {
1.55 albertel 369: $r->log_reason(
370: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
1.12 www 371: }
1.1 harris41 372:
1.61 www 373: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 374:
1.61 www 375: my $advanced=$ENV{'user.adv'};
376: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
377: my $tryagain=$ENV{'form.tryagain'};
1.6 www 378:
1.2 www 379: # -------------------------------------------------------- Generate Page Output
1.104 raeburn 380: # -------------------------------------------------------- Domain Coordinator?
381: if ($dcselect ne '') {
382: &choosecourse_display($r,$dcselect,$then,$now);
383: return OK;
384: }
385:
1.6 www 386: # --------------------------------------------------------------- Error Header?
1.2 www 387: if ($error) {
388: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 www 389: $r->print("<hr><pre>Access : ".
390: Apache::lonnet::plaintext($priv)."\n");
391: $r->print("Resource: $fn\n");
392: $r->print("Action : $msg\n</pre><hr>");
1.2 www 393: } else {
1.25 www 394: if ($ENV{'user.error.msg'}) {
395: $r->print(
1.72 www 396: '<h3><font color=red>'.
397: &mt('You need to choose another user role or enter a specific course for this function').'</font></h3>');
1.25 www 398: }
1.2 www 399: }
1.6 www 400: # -------------------------------------------------------- Choice or no choice?
1.2 www 401: if ($nochoose) {
1.6 www 402: if ($advanced) {
1.72 www 403: $r->print("<h2>".&mt('Assigned User Roles')."</h2>\n");
1.6 www 404: } else {
1.72 www 405: $r->print("<h2>".&mt('Sorry ...')."</h2>\n".
406: &mt('This resource might be part of'));
1.55 albertel 407: if ($ENV{'request.course.id'}) {
1.72 www 408: $r->print(&mt(' another'));
1.55 albertel 409: } else {
1.72 www 410: $r->print(&mt(' a certain'));
1.55 albertel 411: }
1.72 www 412: $r->print(&mt(' course.').'</body></html>');
1.55 albertel 413: return OK;
1.6 www 414: }
415: } else {
416: if ($advanced) {
1.72 www 417: $r->print(&mt("Your home server is ").
1.55 albertel 418: $Apache::lonnet::hostname{&Apache::lonnet::homeserver
419: ($ENV{'user.name'},$ENV{'user.domain'})}.
420: "<br />\n");
1.72 www 421: $r->print(&mt(
422: "Author and Co-Author roles may not be available on servers other than your home server."));
1.17 www 423: }
1.18 www 424: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
425: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 426: }
1.84 www 427: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.6 www 428: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
429: $r->print('<input type=hidden name=selectrole value=1>');
430: }
1.63 www 431: if ($ENV{'user.adv'}) {
432: $r->print(
1.72 www 433: '<br />'.&mt('Show all roles').': <input type="checkbox" name="showall"');
1.63 www 434: if ($ENV{'form.showall'}) { $r->print(' checked'); }
1.72 www 435: $r->print('><input type=submit value="'.&mt('Display').'">');
1.63 www 436: }
1.4 www 437:
1.104 raeburn 438: my %dcroles = ();
439: my $numdc = &check_fordc(\%dcroles,$then);
440:
1.75 albertel 441: my (%roletext,%sortrole,%roleclass);
1.84 www 442: my $countactive=0;
443: my $inrole=0;
444: my $possiblerole='';
1.3 albertel 445: foreach $envkey (sort keys %ENV) {
1.35 matthew 446: my $button = 1;
1.49 www 447: my $switchserver='';
1.75 albertel 448: my $roletext;
449: my $sortkey;
1.2 www 450: if ($envkey=~/^user\.role\./) {
1.102 raeburn 451: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
452: &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.46 matthew 453: next if (!defined($role) || $role eq '');
1.102 raeburn 454: $tremark='';
455: $tpstart=' ';
456: $tpend=' ';
457: $tfont='#000000';
1.4 www 458: if ($tstart) {
1.74 www 459: $tpstart=&Apache::lonlocal::locallocaltime($tstart);
1.4 www 460: }
461: if ($tend) {
1.74 www 462: $tpend=&Apache::lonlocal::locallocaltime($tend);
1.4 www 463: }
1.6 www 464: if ($ENV{'request.role'} eq $trolecode) {
465: $tstatus='selected';
466: }
1.4 www 467: my $tbg;
1.35 matthew 468: if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
469: ($ENV{'form.showall'})) {
470: if ($tstatus eq 'is') {
471: $tbg='#77FF77';
1.47 www 472: $tfont='#003300';
1.84 www 473: $possiblerole=$trolecode;
474: $countactive++;
1.35 matthew 475: } elsif ($tstatus eq 'future') {
476: $tbg='#FFFF77';
1.49 www 477: $button=0;
1.35 matthew 478: } elsif ($tstatus eq 'will') {
479: $tbg='#FFAA77';
1.72 www 480: $tremark.=&mt('Active at next login. ');
1.35 matthew 481: } elsif ($tstatus eq 'expired') {
482: $tbg='#FF7777';
1.47 www 483: $tfont='#330000';
1.49 www 484: $button=0;
1.35 matthew 485: } elsif ($tstatus eq 'will_not') {
486: $tbg='#AAFF77';
1.72 www 487: $tremark.=&mt('Expired after logout. ');
1.35 matthew 488: } elsif ($tstatus eq 'selected') {
489: $tbg='#11CC55';
1.47 www 490: $tfont='#002200';
1.84 www 491: $inrole=1;
1.86 albertel 492: $countactive++;
1.72 www 493: $tremark.=&mt('Currently selected. ');
1.35 matthew 494: }
495: my $trole;
496: if ($role =~ /^cr\//) {
497: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.72 www 498: $tremark.='<br>'.&mt('Defined by ').$rauthor.
499: &mt(' at ').$rdomain.'.';
1.35 matthew 500: $trole=$rrole;
1.8 www 501: } else {
1.35 matthew 502: $trole=Apache::lonnet::plaintext($role);
503: }
504: my $ttype;
505: my $twhere;
506: my ($tdom,$trest,$tsection)=
507: split(/\//,Apache::lonnet::declutter($where));
508: # First, Co-Authorship roles
509: if ($role eq 'ca') {
1.39 stredwic 510: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83 albertel 511: my $allowed=0;
512: my @ids=&Apache::lonnet::current_machine_ids();
513: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
514: if (!$allowed) {
1.49 www 515: $button=0;
1.51 www 516: $switchserver=&Apache::lonnet::escape('http://'.
517: $Apache::lonnet::hostname{$home}.
518: '/adm/login?domain='.$ENV{'user.domain'}.
519: '&username='.$ENV{'user.name'}.
1.97 albertel 520: '&firsturl=/priv/'.$trest.'/');
1.49 www 521: }
1.35 matthew 522: #next if ($home eq 'no_host');
523: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 524: $ttype='Construction Space';
1.72 www 525: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
526: ': '.$tdom.'<br />'.
527: ' '.&mt('Server').': '.$home;
1.35 matthew 528: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 529: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75 albertel 530: $sortkey=$role."$trest:$tdom";
1.35 matthew 531: } elsif ($role eq 'au') {
532: # Authors
533: my $home = &Apache::lonnet::homeserver
1.39 stredwic 534: ($ENV{'user.name'},$ENV{'user.domain'});
1.83 albertel 535: my $allowed=0;
536: my @ids=&Apache::lonnet::current_machine_ids();
537: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
538: if (!$allowed) {
1.49 www 539: $button=0;
1.51 www 540: $switchserver=&Apache::lonnet::escape('http://'.
541: $Apache::lonnet::hostname{$home}.
542: '/adm/login?domain='.$ENV{'user.domain'}.
543: '&username='.$ENV{'user.name'}.
1.97 albertel 544: '&firsturl=/priv/'.$ENV{'user.name'}.'/');
1.49 www 545: }
1.35 matthew 546: #next if ($home eq 'no_host');
547: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 548: $ttype='Construction Space';
1.72 www 549: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
550: ': '.$home;
1.35 matthew 551: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 552: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$ENV{'user.name'}.'/');
1.75 albertel 553: $sortkey=$role;
1.35 matthew 554: } elsif ($trest) {
1.78 sakharuk 555: $ttype='Course';
1.35 matthew 556: if ($tsection) {
1.72 www 557: $ttype.='<br>'.&mt('Section/Group').': '.$tsection;
1.37 albertel 558: }
1.35 matthew 559: my $tcourseid=$tdom.'_'.$trest;
560: if ($ENV{'course.'.$tcourseid.'.description'}) {
1.47 www 561: $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.80 albertel 562: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72 www 563: unless ($twhere eq &mt('Currently not available')) {
1.55 albertel 564: $twhere.=' <font size="-2">'.
1.72 www 565: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 566: '</font>';
1.55 albertel 567: }
1.8 www 568: } else {
1.105 raeburn 569: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1.35 matthew 570: if (%newhash) {
1.80 albertel 571: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77 albertel 572: "\0".$envkey;
1.49 www 573: $twhere=$newhash{'description'}.
574: ' <font size="-2">'.
1.72 www 575: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 576: '</font>';
1.35 matthew 577: } else {
1.72 www 578: $twhere=&mt('Currently not available');
1.35 matthew 579: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.80 albertel 580: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.35 matthew 581: }
1.8 www 582: }
1.72 www 583: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35 matthew 584: } elsif ($tdom) {
1.78 sakharuk 585: $ttype='Domain';
1.35 matthew 586: $twhere=$tdom;
1.75 albertel 587: $sortkey=$role.$twhere;
1.35 matthew 588: } else {
1.78 sakharuk 589: $ttype='System';
1.72 www 590: $twhere=&mt('system wide');
1.75 albertel 591: $sortkey=$role.$twhere;
1.13 www 592: }
1.35 matthew 593:
1.75 albertel 594: $roletext.='<tr bgcolor='.$tbg.'>';
1.35 matthew 595: unless ($nochoose) {
596: if (!$button) {
1.49 www 597: if ($switchserver) {
1.75 albertel 598: $roletext.='<td><a href="/adm/logout?handover='.
599: $switchserver.'">'.&mt('Switch Server').'</a></td>';
1.49 www 600: } else {
1.75 albertel 601: $roletext.=('<td> </td>');
1.49 www 602: }
1.35 matthew 603: } elsif ($tstatus eq 'is') {
1.75 albertel 604: $roletext.=('<td><input type=submit value="'.
1.72 www 605: &mt('Select').'" name="'.
1.35 matthew 606: $trolecode.'"></td>');
1.61 www 607: } elsif ($tryagain) {
1.75 albertel 608: $roletext.=
609: '<td><input type=submit value="'.
610: &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
1.61 www 611: } elsif ($advanced) {
1.75 albertel 612: $roletext.=
613: '<td><input type=submit value="'.
614: &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
1.35 matthew 615: } else {
1.75 albertel 616: $roletext.='<td> </td>';
1.35 matthew 617: }
1.6 www 618: }
1.57 www 619: $tremark.=&Apache::lonannounce::showday(time,1,
620: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
621:
1.75 albertel 622: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.47 www 623: '</font></td><td><font color="'.$tfont.'">'.$ttype.
624: '</font></td><td><font color="'.$tfont.'">'.$twhere.
625: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
626: '</font></td><td><font color="'.$tfont.'">'.$tpend.
627: '</font></td><td><font color="'.$tfont.'">'.$tremark.
1.75 albertel 628: ' </font></td></tr>'."\n";
629: $roletext{$envkey}=$roletext;
630: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
631: $sortrole{$sortkey}=$envkey;
632: $roleclass{$envkey}=$ttype;
1.55 albertel 633: }
1.4 www 634: }
1.75 albertel 635: }
1.84 www 636: # No active roles
637: if ($countactive==0) {
638: if ($inrole) {
639: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
640: } else {
641: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
642: }
643: $r->print('</form></body></html>');
644: return OK;
645: # Is there only one choice?
1.88 www 646: } elsif (($countactive==1) && ($ENV{'request.role'} eq 'cm')) {
1.84 www 647: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
648: '<input type="hidden" name="'.$possiblerole.'" value="1" />');
649: $r->print("</form>\n");
650: $r->rflush();
651: $r->print('<script>document.forms.rolechoice.submit();</script>');
652: $r->print('</body></html>');
653: return OK;
654: }
655: # More than one possible role
656: # ----------------------------------------------------------------------- Table
657: unless (($advanced) || ($nochoose)) {
658: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
659: }
660: $r->print('<br /><table><tr>');
661: unless ($nochoose) { $r->print('<th> </th>'); }
662: $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
663: '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
1.99 www 664: &mt('Remarks and Calendar Announcements').'</th></tr>'."\n");
1.76 albertel 665: my $doheaders=-1;
1.78 sakharuk 666: foreach my $type ('Construction Space','Course','Domain','System') {
1.76 albertel 667: my $haverole=0;
1.75 albertel 668: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
669: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.76 albertel 670: $haverole=1;
1.75 albertel 671: }
1.76 albertel 672: }
673: if ($haverole) { $doheaders++; }
674: }
1.104 raeburn 675: if ($numdc > 0) {
676: $r->print('<tr bgcolor="#BBffBB">'.
677: '<td align="center" colspan="7">'.
678: '<input type="hidden" name="all_cc_roles" value="1"/>'.
679: '<input type="hidden" name="dcselected" value=""/>'.
680: &mt('Domain').'</td>');
681: foreach my $dcdom (keys %dcroles) {
682: my $output = $roletext{$dcroles{$dcdom}};
683: my $ccrole = Apache::lonnet::plaintext('cc');
684: if ($ENV{'request.role'} =~ m-cc\./$dcdom/-) {
685: $output.=$roletext{'user.role.'.$ENV{'request.role'}};
686: }
687: $r->print($output);
688: $r->print('<tr bgcolor="#77FF77">');
689: $r->print('<td><input type="button" value="'.
690: &mt('Select').'" name="dcpick_'.$dcdom.'/" '.
691: 'onClick="setDCchoice('."'$dcdom'".')"></td>'.
692: '<td><font color="#002200">'.
693: $ccrole.'</font></td><td>'.&mt('Course').'</td>'.
694: '<td><font color="#002200"><b>'.&mt('All courses').'</b>'.
695: '<br />'.&mt('Domain').':'.$dcdom.'</font>'.
696: '<td colspan="4"><font color="#002200">'.
697: &mt('Course Coordinator access to all courses in domain').
698: ': <b>'.$dcdom.'</b></font></td></tr>'."\n");
699: }
700: foreach my $type ('Construction Space','Course','Domain','System') {
701: my $output;
702: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
703: my $skiprole = 0;
704: foreach my $dcdom (keys %dcroles) {
1.106 ! raeburn 705: if ($sortrole{$which} =~ m-(dc)\./$dcdom/-) {
1.104 raeburn 706: $skiprole = 1;
707: last;
708: }
709: }
710: if (($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) && (!$skiprole)) {
711: $output.=$roletext{$sortrole{$which}};
712: }
713: }
714: if ($output) {
715: if ($doheaders > 0) {
716: $r->print("<tr bgcolor='#BBffBB'>".
717: "<td align='center' colspan='7'>".&mt($type)."</td>
718: ");
719: }
720: $r->print($output);
721: }
722: }
723: } else {
724: foreach my $type ('Construction Space','Course','Domain','System') {
725: my $output;
726: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
727: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
728: $output.=$roletext{$sortrole{$which}};
729: }
1.76 albertel 730: }
1.104 raeburn 731: if ($output) {
732: if ($doheaders > 0) {
733: $r->print("<tr bgcolor='#BBffBB'>".
734: "<td align='center' colspan='7'>".&mt($type)."</td>");
735: }
1.106 ! raeburn 736: $r->print($output);
1.76 albertel 737: }
1.104 raeburn 738: }
1.4 www 739: }
1.14 www 740: my $tremark='';
1.47 www 741: my $tfont='#003300';
1.14 www 742: if ($ENV{'request.role'} eq 'cm') {
1.19 www 743: $r->print('<tr bgcolor="#11CC55">');
1.72 www 744: $tremark=&mt('Currently selected. ');
1.47 www 745: $tfont='#002200';
1.14 www 746: } else {
747: $r->print('<tr bgcolor="#77FF77">');
748: }
749: unless ($nochoose) {
1.55 albertel 750: if ($ENV{'request.role'} ne 'cm') {
1.72 www 751: $r->print('<td><input type=submit value="'.
752: &mt('Select').'" name="cm"></td>');
1.55 albertel 753: } else {
754: $r->print('<td> </td>');
755: }
1.14 www 756: }
1.72 www 757: $r->print('<td colspan=5><font color="'.$tfont.'">'.&mt('No role specified').
1.47 www 758: '</font></td><td><font color="'.$tfont.'">'.$tremark.
759: ' </font></td></tr>'."\n");
1.4 www 760:
761: $r->print('</table>');
762: unless ($nochoose) {
763: $r->print("</form>\n");
764: }
1.22 harris41 765: # ------------------------------------------------------------ Privileges Info
1.55 albertel 766: if (($advanced) && (($ENV{'user.error.msg'}) || ($error))) {
767: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 768:
1.55 albertel 769: foreach $envkey (sort keys %ENV) {
770: if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
771: my $where=$envkey;
772: $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
773: my $ttype;
774: my $twhere;
775: my ($tdom,$trest,$tsec)=
776: split(/\//,Apache::lonnet::declutter($where));
777: if ($trest) {
778: if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
779: $ttype='Construction Space';
780: $twhere='User: '.$trest.', Domain: '.$tdom;
781: } else {
782: $ttype='Course';
783: $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
784: if ($tsec) {
785: $twhere.=' (Section/Group: '.$tsec.')';
786: }
787: }
788: } elsif ($tdom) {
789: $ttype='Domain';
790: $twhere=$tdom;
791: } else {
792: $ttype='System';
793: $twhere='/';
794: }
795: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
796: foreach (sort split(/:/,$ENV{$envkey})) {
797: if ($_) {
798: my ($prv,$restr)=split(/\&/,$_);
799: my $trestr='';
800: if ($restr ne 'F') {
801: my $i;
802: $trestr.=' (';
803: for ($i=0;$i<length($restr);$i++) {
804: $trestr.=
805: Apache::lonnet::plaintext(substr($restr,$i,1));
806: if ($i<length($restr)-1) { $trestr.=', '; }
807: }
808: $trestr.=')';
809: }
810: $r->print('<li>'.
811: Apache::lonnet::plaintext($prv).$trestr.
812: '</li>');
813: }
814: }
815: $r->print('</ul>');
816: }
817: }
1.4 www 818: }
1.66 www 819: $r->print(&Apache::lonnet::getannounce());
1.65 www 820: if ($advanced) {
821: $r->print('<p><small><i>This is LON-CAPA '.
1.85 www 822: $r->dir_config('lonVersion').'</i><br />'.
823: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 824: }
1.1 harris41 825: $r->print("</body></html>\n");
826: return OK;
1.102 raeburn 827: }
828:
829: sub role_status {
830: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
831: my @pwhere = ();
832: if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') {
833: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
834: unless (!defined($$role) || $$role eq '') {
835: $$where=join('.',@pwhere);
836: $$trolecode=$$role.'.'.$$where;
837: ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
838: $$tstatus='is';
1.105 raeburn 839: if ($$tstart && $$tstart>$then) {
840: $$tstatus='future';
841: if ($$tstart<$now) { $$tstatus='will'; }
1.102 raeburn 842: }
843: if ($$tend) {
844: if ($$tend<$then) {
845: $$tstatus='expired';
1.103 raeburn 846: } elsif ($$tend<$now) {
1.104 raeburn 847: $$tstatus='will_not';
1.102 raeburn 848: }
849: }
850: }
851: }
852: }
1.1 harris41 853:
1.104 raeburn 854: sub dc_script {
855: my $response = (<<"END");
856: function setDCchoice(caller) {
857: var dcname = "dc./"+caller+"/"
858: document.rolechoice.dcselected.value = caller
859: document.rolechoice.elements[3].name = dcname
860: document.rolechoice.submit()
861: }
862: END
863: return $response;
864: }
865:
866: sub check_fordc {
867: my ($dcroles,$then) = @_;
868: my $numdc = 0;
869: if ($ENV{'user.adv'}) {
870: foreach my $envkey (sort keys %ENV) {
871: if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
872: my $dcdom = $1;
873: my $livedc = 1;
874: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
1.105 raeburn 875: if ($tstart && $tstart>$then) { $livedc = 0; }
876: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 877: if ($livedc) {
878: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 879: $numdc++;
1.104 raeburn 880: }
881: }
882: }
883: }
884: return $numdc;
885: }
886:
887: sub choosecourse_display {
888: my ($r,$dcdom,$then,$now) = @_;
889: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'dom');
890: my $verify_script = <<"END";
891: <script>
892: function verifyCoursePick() {
893: var pickedCourse = document.roles.dccourse.value
894: var pickedDomain = document.roles.dcdomain.value
895: if (document.roles.dcdomain.value == document.roles.origdom.value) {
896: if (pickedCourse != '') {
897: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
898: document.roles.elements[0].value = 1
899: document.roles.elements[0].name = courseTarget
900: document.roles.selectrole.value = 1
901: document.roles.submit()
902: }
903: else {
904: alert("You must use the 'Select Course' link to open a separate pick course window which you can use to select the course you wish to enter");
905: }
906: }
907: else {
908: alert("You can only use this screen to select courses in the current domain")
909: }
910: }
911: </script>
912: END
913: my $courseform=&Apache::loncommon::selectcourse_link
914: ('roles','dccourse','dcdomain','coursedesc');
915: $r->print($cb_jscript.$verify_script);
916: my $formaction='/adm/roles';
917: $formaction=~s/\/+/\//g;
918: my $crs;
919: &select_recent_courses($r,$dcdom,$then,$now);
920: $r->print('<br /><form name="roles" method="post" action="'.$formaction.'" />');
921: $r->print('<h3>'.&mt('Choose a course from domain').': '.$dcdom.'</h3><font size="+1">'.$courseform.'</font><br /><br />'.
922: '<input type="hidden" name="chosencourse" value=""/>'.
923: 'Course Title: <input type="text" size="20" name="coursedesc" value=""><br />'.
924: 'Course ID: <input type="text" size="15" name="dccourse" />'.
925: '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
926: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
927: '<input type="hidden" name="selectrole" value="" />'.
928: '<br /><br /><input type="button" name="proceed" value="'.&mt('Enter this course').'" onClick="verifyCoursePick()" />'.
929: '</form>');
930: return;
931: }
932:
933: sub select_recent_courses {
934: my ($r,$dcdom,$then,$now)=@_;
935: my $advanced = $ENV{'user.adv'};
936: my $tryagain = $ENV{'form.tryagain'};
937: my %recent=&Apache::lonnet::dump(&recent_filename('cc_pickby_dc_'.$dcdom));
938: my $numrecent = 0;
939: my $roletext = '<h3>'.&mt('Enter a recently visited course').'</h3>'.
940: '<form name="rolechoice" action="/adm/roles" method="post">'.
941: '<table><tr><th> </th>'.
942: '<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
943: '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
944: &mt('Remarks and Calendar Announcements').'</th></tr>'."\n".
945: '<tr bgcolor="#BBffBB">'.
946: '<td align="center" colspan="7">'.
947: &mt('Domain').' - '.&mt('Recent courses accessed in this domain').
948: '</td></tr>'."\n";
949: foreach my $courseid (sort keys %recent) {
950: unless ($courseid =~/^error\:/) {
951: my ($dom,$crs) = split/_/,$courseid;
952: if ($dom eq $dcdom) {
953: $numrecent ++;
954: my $crskey = 'user.role.cc./'.$dom.'/'.$crs;
955: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$tbg,$tfont,$tremark,$inrole,$tpstart,$tpend);
956: my $button = 1;
957: &role_status($crskey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
958: if ($tstart) {
959: $tpstart=&Apache::lonlocal::locallocaltime($tstart);
960: }
961: if ($tend) {
962: $tpend=&Apache::lonlocal::locallocaltime($tend);
963: }
964: my $ttype = &mt('Course');
965: my $twhere;
966: if ($ENV{'course.'.$courseid.'.description'}) {
967: $twhere=$ENV{'course.'.$courseid.'.description'};
968: }
969: my ($tdom,$trest,$tsection)=
970: split(/\//,Apache::lonnet::declutter($where));
971: if ($ENV{'request.role'} eq $trolecode) {
972: $tstatus='selected';
973: }
974: if ($tstatus eq 'is') {
975: $tbg='#77FF77';
976: $tfont='#003300';
977: } elsif ($tstatus eq 'future') {
978: $tbg='#FFFF77';
979: $button=0;
980: } elsif ($tstatus eq 'will') {
981: $tbg='#FFAA77';
982: $tremark.=&mt('Active at next login. ');
983: } elsif ($tstatus eq 'expired') {
984: $tbg='#FF7777';
985: $tfont='#330000';
986: $button=0;
987: } elsif ($tstatus eq 'will_not') {
988: $tbg='#AAFF77';
989: $tremark.=&mt('Expired after logout. ');
990: } elsif ($tstatus eq 'selected') {
991: $tbg='#11CC55';
992: $tfont='#002200';
993: $inrole=1;
994: $tremark.=&mt('Currently selected. ');
995: }
996: my $trole=Apache::lonnet::plaintext($role);
997: $roletext.='<tr bgcolor='.$tbg.'>';
998: if (!$button) {
999: $roletext.=('<td> </td>');
1000: } elsif ($tstatus eq 'is') {
1001: $roletext.=('<td><input type=submit value="'.
1002: &mt('Select').'" name="'.
1003: $trolecode.'"></td>');
1004: } elsif ($tryagain) {
1005: $roletext.=
1006: '<td><input type=submit value="'.
1007: &mt('Try Selecting Again').'" name="'.$trolecode.'"></td>';
1008: } elsif ($advanced) {
1009: $roletext.=
1010: '<td><input type=submit value="'.
1011: &mt('Re-Initialize').'" name="'.$trolecode.'"></td>';
1012: } else {
1013: $roletext.='<td> </td>';
1014: }
1015: $tremark.=&Apache::lonannounce::showday(time,1,
1016: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1017:
1018: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1019: '</font></td><td><font color="'.$tfont.'">'.$ttype.
1020: '</font></td><td><font color="'.$tfont.'">'.$twhere.
1021: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
1022: '</font></td><td><font color="'.$tfont.'">'.$tpend.
1023: '</font></td><td><font color="'.$tfont.'">'.$tremark.
1024: ' </font></td></tr>'."\n";
1025: }
1026: }
1027: }
1028: if ($numrecent > 0) {
1029: $r->print($roletext.'</table><input type="hidden" '.
1030: 'name="selectrole" value="1" /></form>'."\n");
1031: }
1032: }
1033:
1034: sub recent_filename {
1035: my $area=shift;
1036: return 'nohist_recent_'.&Apache::lonnet::escape($area);
1037: }
1038:
1.106 ! raeburn 1039: sub set_privileges {
! 1040: my ($dcdom,$pickedcourse) = @_;
! 1041: my $area = '/'.$dcdom.'/'.$pickedcourse;
! 1042: my $role = 'cc';
! 1043: my $spec = $role.'.'.$area;
! 1044: my $userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$ENV{'user.name'});
! 1045: my %ccrole = ();
! 1046: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
! 1047: $userroles .= &Apache::lonnet::set_userprivs(\$userroles,\%ccrole); my @newprivs = split/\n/,$userroles;
! 1048: my %newccroles = ();
! 1049: foreach (@newprivs) {
! 1050: my ($key,$val) = split/=/,$_;
! 1051: $newccroles{$key} = $val;
! 1052: }
! 1053: &Apache::lonnet::appenv(%newccroles);
! 1054: &Apache::lonnet::log($ENV{'user.domain'},
! 1055: $ENV{'user.name'},
! 1056: $ENV{'user.home'},
! 1057: "Role ".$role);
! 1058:
! 1059: &Apache::lonnet::appenv(
! 1060: 'request.role' => $role,
! 1061: 'request.role.domain' => $dcdom,
! 1062: 'request.course.sec' => '');
! 1063: my $tadv=0;
! 1064: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
! 1065: &Apache::lonnet::appenv('request.role.adv' => $tadv);
! 1066: }
! 1067:
1.1 harris41 1068: 1;
1069: __END__
1.32 harris41 1070:
1071: =head1 NAME
1072:
1073: Apache::lonroles - User Roles Screen
1074:
1075: =head1 SYNOPSIS
1076:
1077: Invoked by /etc/httpd/conf/srm.conf:
1078:
1079: <Location /adm/roles>
1080: PerlAccessHandler Apache::lonacc
1081: SetHandler perl-script
1082: PerlHandler Apache::lonroles
1083: ErrorDocument 403 /adm/login
1084: ErrorDocument 500 /adm/errorhandler
1085: </Location>
1.64 bowersj2 1086:
1087: =head1 OVERVIEW
1088:
1089: =head2 Choosing Roles
1090:
1091: C<lonroles> is a handler that allows a user to switch roles in
1092: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1093: default role that a user has before selecting a role, as widely as
1094: possible, but certain handlers for example need specification which
1095: course they should act on, etc. Both in this scenario, and when the
1096: handler determines via C<lonnet>'s C<&allowed> function that a certain
1097: action is not allowed, C<lonroles> is used as error handler. This
1098: allows the user to select another role which may have permission to do
1099: what they were trying to do. C<lonroles> can also be accessed via the
1100: B<CRS> button in the Remote Control.
1101:
1102: =begin latex
1103:
1104: \begin{figure}
1105: \begin{center}
1106: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1107: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1108: \end{center}
1109: \end{figure}
1110:
1111: =end latex
1112:
1113: =head2 Role Initialization
1114:
1115: 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 1116:
1117: =head1 INTRODUCTION
1118:
1119: This module enables a user to select what role he wishes to
1120: operate under (instructor, student, teaching assistant, course
1121: coordinator, etc). These roles are pre-established by the actions
1122: of upper-level users.
1123:
1124: This is part of the LearningOnline Network with CAPA project
1125: described at http://www.lon-capa.org.
1126:
1127: =head1 HANDLER SUBROUTINE
1128:
1129: This routine is called by Apache and mod_perl.
1130:
1131: =over 4
1132:
1133: =item *
1134:
1135: Roles Initialization (yes/no)
1136:
1137: =item *
1138:
1139: Get Error Message from Environment
1140:
1141: =item *
1142:
1143: Who is this?
1144:
1145: =item *
1146:
1147: Generate Page Output
1148:
1149: =item *
1150:
1151: Choice or no choice
1152:
1153: =item *
1154:
1155: Table
1156:
1157: =item *
1158:
1159: Privileges
1160:
1161: =back
1162:
1163: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>