Annotation of loncom/auth/lonroles.pm, revision 1.192
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.192 ! raeburn 4: # $Id: lonroles.pm,v 1.191 2008/05/14 23:52:52 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;
1.118 albertel 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.151 www 42: use Apache::lonpageflip();
1.167 albertel 43: use Apache::lonnavdisplay();
1.120 albertel 44: use GDBM_File;
1.170 albertel 45: use LONCAPA qw(:DEFAULT :match);
1.149 www 46:
1.1 harris41 47:
1.62 matthew 48: sub redirect_user {
1.95 albertel 49: my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62 matthew 50: $msg = $title if (! defined($msg));
1.73 www 51: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 52: &Apache::loncommon::no_cache($r);
53: $r->send_http_header;
54: my $swinfo=&Apache::lonmenu::rawconfig();
1.96 albertel 55: my $navwindow;
1.95 albertel 56: if ($launch_nav eq 'on') {
1.166 albertel 57: $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
58: ($url =~ m-^/adm/whatsnew-));
1.96 albertel 59: } else {
60: $navwindow.=&Apache::lonnavmaps::close();
1.95 albertel 61: }
1.147 albertel 62: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
63: {'redirect' => [1,$url],});
64: my $end_page = &Apache::loncommon::end_page();
65:
1.92 www 66: # Note to style police:
67: # This must only replace the spaces, nothing else, or it bombs elsewhere.
68: $url=~s/ /\%20/g;
1.93 albertel 69: $r->print(<<ENDREDIR);
1.147 albertel 70: $start_page
1.96 albertel 71: <script type="text/javascript">
1.62 matthew 72: $swinfo
73: </script>
1.96 albertel 74: $navwindow
1.62 matthew 75: <h1>$msg</h1>
1.147 albertel 76: $end_page
1.62 matthew 77: ENDREDIR
78: return;
79: }
80:
1.150 www 81: sub error_page {
82: my ($r,$error,$dest)=@_;
83: &Apache::loncommon::content_type($r,'text/html');
84: &Apache::loncommon::no_cache($r);
85: $r->send_http_header;
86: return OK if $r->header_only;
87: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').
88: '<script type="text/javascript">'.
89: &Apache::lonmenu::rawconfig().'</script>'.
90: '<p>'.&mt('The following problems occurred:').
91: $error.
1.156 albertel 92: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'.
1.150 www 93: &Apache::loncommon::end_page());
94: }
95:
1.1 harris41 96: sub handler {
1.10 www 97:
1.1 harris41 98: my $r = shift;
99:
1.6 www 100: my $now=time;
1.118 albertel 101: my $then=$env{'user.login.time'};
1.6 www 102: my $envkey;
1.107 raeburn 103: my %dcroles = ();
104: my $numdc = &check_fordc(\%dcroles,$then);
1.148 albertel 105: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.10 www 106:
1.6 www 107: # ================================================================== Roles Init
1.118 albertel 108: if ($env{'form.selectrole'}) {
1.188 www 109:
110: my $locknum=&Apache::lonnet::get_locks();
111: if ($locknum) { return 409; }
112:
1.134 www 113: if ($env{'form.newrole'}) {
114: $env{'form.'.$env{'form.newrole'}}=1;
115: }
1.118 albertel 116: if ($env{'request.course.id'}) {
1.185 raeburn 117: # Check if user is CC trying to select a course role
118: if ($env{'form.switchrole'}) {
119: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
120: &adhoc_course_role($then);
121: }
122: }
1.118 albertel 123: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 124: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 125: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 126: }
1.186 raeburn 127: &Apache::lonnet::appenv({"request.course.id" => '',
128: "request.course.fn" => '',
129: "request.course.uri" => '',
130: "request.course.sec" => '',
131: "request.role" => 'cm',
132: "request.role.adv" => $env{'user.adv'},
133: "request.role.domain" => $env{'user.domain'}});
1.182 www 134: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 135: if ($numdc > 0) {
1.118 albertel 136: foreach my $envkey (keys %env) {
1.182 www 137: # Is this an ad-hoc CC-role?
1.146 raeburn 138: if (my ($domain,$coursenum) =
1.171 albertel 139: ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
1.189 www 140: # See if that is even allowed
1.190 www 141: my %crsenv=&Apache::lonnet::get('environment',['internal.courseowner'],$domain,$coursenum);
142: # First find course owner
143: my ($owneruser,$ownerdomain)=split(/\:/,$crsenv{'internal.courseowner'});
144: # Check if course owner blocked cc-access
145: if (($owneruser) && ($ownerdomain)) {
146: my %blocked=&Apache::lonnet::get('environment',['domcoord.cc'],$ownerdomain,$owneruser);
147: if ($blocked{'domcoord.cc'} eq 'blocked') {
148: $env{'user.error.msg'}=':::1:Course owner '.$owneruser.' in domain '.$ownerdomain.' blocked domain coordinator access';
149: last;
150: }
151: }
1.146 raeburn 152: if ($dcroles{$domain}) {
1.182 www 153: &check_privs($domain,$coursenum,$then,$now,'cc');
154: }
155: last;
156: }
157: # Is this a recent ad-hoc CA-role?
1.183 www 158: if (my ($domain,$user) =
159: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.190 www 160: # See if still allowed
161: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
162: if ($blocked{'domcoord.author'} eq 'blocked') {
163: delete($env{$envkey});
164: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
165: last;
166: }
1.183 www 167: if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) {
168: &check_privs($domain,$user,$then,$now,'ca');
169: } else {
170: delete($env{$envkey});
1.182 www 171: }
172: last;
173: }
174: # Is this a new ad-hoc CA-role?
175: if (my ($domain) =
176: ($envkey =~ m-^form\.adhocca\./($match_domain)$-)) {
1.189 www 177: my $user=$env{'form.adhoccauname.'.$domain};
178: if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
179: # See if that is even allowed
180: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
181: if ($blocked{'domcoord.author'} eq 'blocked') {
182: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
183: last;
184: }
1.182 www 185: if ($dcroles{$domain}) {
1.183 www 186: if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) {
1.182 www 187: &check_privs($domain,$user,$then,$now,'ca');
188: $env{'form.ca./'.$domain.'/'.$user}=1;
189: }
1.107 raeburn 190: }
191: last;
192: }
193: }
194: }
195:
1.118 albertel 196: foreach $envkey (keys %env) {
1.40 matthew 197: next if ($envkey!~/^user\.role\./);
1.102 raeburn 198: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
199: &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 200: if ($env{'form.'.$trolecode}) {
1.55 albertel 201: if ($tstatus eq 'is') {
202: $where=~s/^\///;
203: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.137 raeburn 204: # check for course groups
205: my %coursegroups = &Apache::lonnet::get_active_groups(
206: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
207: my $cgrps = join(':',keys(%coursegroups));
208:
1.111 albertel 209: # store role if recent_role list being kept
1.118 albertel 210: if ($env{'environment.recentroles'}) {
1.158 albertel 211: my %frozen_roles =
212: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 213: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 214: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 215: }
216:
217:
1.53 www 218: # check for keyed access
1.55 albertel 219: if (($role eq 'st') &&
1.118 albertel 220: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 221: # who is key authority?
222: my $authdom=$cdom;
223: my $authnum=$cnum;
1.118 albertel 224: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 225: ($authnum,$authdom)=
1.172 albertel 226: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 227: }
228: # check with key authority
229: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 230: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 231: $authdom,$authnum)) {
1.53 www 232: # there is no valid key
1.118 albertel 233: if ($env{'form.newkey'}) {
1.53 www 234: # student attempts to register a new key
1.89 www 235: &Apache::loncommon::content_type($r,'text/html');
236: &Apache::loncommon::no_cache($r);
237: $r->send_http_header;
238: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 239: my $start_page=&Apache::loncommon::start_page
1.89 www 240: ('Verifying Access Key to Unlock this Course');
1.147 albertel 241: my $end_page=&Apache::loncommon::end_page();
1.90 www 242: my $buttontext=&mt('Enter Course');
243: my $message=&mt('Successfully registered key');
244: my $assignresult=
245: &Apache::lonnet::assign_access_key(
1.118 albertel 246: $env{'form.newkey'},
1.90 www 247: $authdom,$authnum,
1.91 www 248: $cdom,$cnum,
1.118 albertel 249: $env{'user.domain'},
250: $env{'user.name'},
1.90 www 251: 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
252: $trolecode);
253: unless ($assignresult eq 'ok') {
254: $assignresult=~s/^error\:\s*//;
255: $message=&mt($assignresult).
256: '<br /><a href="/adm/logout">'.
1.89 www 257: &mt('Logout').'</a>';
1.90 www 258: $buttontext=&mt('Re-Enter Key');
259: }
1.89 www 260: $r->print(<<ENDENTEREDKEY);
1.147 albertel 261: $start_page
1.179 raeburn 262: <script type="text/javascript">
1.89 www 263: $swinfo
264: </script>
265: <form method="post">
266: <input type="hidden" name="selectrole" value="1" />
267: <input type="hidden" name="$trolecode" value="1" />
1.90 www 268: <font size="+2">$message</font><br />
1.89 www 269: <input type="submit" value="$buttontext" />
270: </form>
1.147 albertel 271: $end_page
1.89 www 272: ENDENTEREDKEY
273: return OK;
1.55 albertel 274: } else {
1.53 www 275: # print form to enter a new key
1.73 www 276: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 277: &Apache::loncommon::no_cache($r);
278: $r->send_http_header;
279: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 280: my $start_page=&Apache::loncommon::start_page
1.55 albertel 281: ('Enter Access Key to Unlock this Course');
1.147 albertel 282: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 283: $r->print(<<ENDENTERKEY);
1.147 albertel 284: $start_page
1.179 raeburn 285: <script type="text/javascript">
1.53 www 286: $swinfo
287: </script>
288: <form method="post">
1.89 www 289: <input type="hidden" name="selectrole" value="1" />
290: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 291: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 292: <input type="submit" value="Enter key" />
293: </form>
1.147 albertel 294: $end_page
1.53 www 295: ENDENTERKEY
1.55 albertel 296: return OK;
297: }
298: }
299: }
1.118 albertel 300: &Apache::lonnet::log($env{'user.domain'},
301: $env{'user.name'},
302: $env{'user.home'},
1.87 www 303: "Role ".$trolecode);
1.101 albertel 304:
1.56 www 305: &Apache::lonnet::appenv(
1.186 raeburn 306: {'request.role' => $trolecode,
307: 'request.role.domain' => $cdom,
308: 'request.course.sec' => $csec,
309: 'request.course.groups' => $cgrps});
1.101 albertel 310: my $tadv=0;
1.62 matthew 311:
1.125 www 312: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 313: my $msg;
1.55 albertel 314: my ($furl,$ferr)=
315: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118 albertel 316: if (($env{'form.orgurl'}) &&
317: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
318: my $dest=$env{'form.orgurl'};
1.117 albertel 319: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 320: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 321: if (($ferr) && ($tadv)) {
322: &error_page($r,$ferr,$dest);
323: } else {
324: $r->internal_redirect($dest);
325: }
1.55 albertel 326: return OK;
327: } else {
1.155 albertel 328: if (!$env{'request.course.id'}) {
1.55 albertel 329: &Apache::lonnet::appenv(
1.186 raeburn 330: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 331: $furl='/adm/roles?tryagain=1';
1.55 albertel 332: $msg=
1.157 albertel 333: '<h1><span class="LC_error">'.
1.162 albertel 334: &mt('Could not initialize [_1] at this time.',
335: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
1.157 albertel 336: '</span></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
1.55 albertel 337: }
1.117 albertel 338: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 339: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 340:
1.150 www 341: if (($ferr) && ($tadv)) {
342: &error_page($r,$ferr,$furl);
343: } else {
344: # Check to see if the user is a CC entering a course
345: # for the first time
346: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
347: if (substr($courseid, 0, 1) eq '/') {
348: $courseid = substr($courseid, 1);
349: }
350: $courseid =~ s/\//_/;
351: if ($role eq 'cc' && $env{'course.' . $courseid .
352: '.course.helper.not.run'}) {
353: $furl = "/adm/helper/course.initialization.helper";
354: # Send the user to the course they selected
355: } elsif ($env{'request.course.id'}) {
1.185 raeburn 356: if ($env{'form.destinationurl'}) {
357: my $dest = $env{'form.destinationurl'};
358: &redirect_user($r,&mt('Entering [_1]',
359: $env{'course.'.$courseid.'.description'}),
360: $dest,$msg,
361: $env{'environment.remotenavmap'});
362: return OK;
363: }
1.150 www 364: if (&Apache::lonnet::allowed('whn',
365: $env{'request.course.id'})
366: || &Apache::lonnet::allowed('whn',
367: $env{'request.course.id'}.'/'
368: .$env{'request.course.sec'})
369: ) {
370: my $startpage = &courseloadpage($courseid);
371: unless ($startpage eq 'firstres') {
1.162 albertel 372: $msg = &mt('Entering [_1] ....',
373: $env{'course.'.$courseid.'.description'});
1.150 www 374: &redirect_user($r,&mt('New in course'),
375: '/adm/whatsnew?refpage=start',$msg,
376: $env{'environment.remotenavmap'});
377: return OK;
378: }
379: }
380: }
1.151 www 381: # Are we allowed to look at the first resource?
1.169 albertel 382: if ($furl !~ m|^/adm/|) {
1.151 www 383: # Guess not ...
384: $furl=&Apache::lonpageflip::first_accessible_resource();
385: }
1.162 albertel 386: $msg = &mt('Entering [_1] ...',
387: $env{'course.'.$courseid.'.description'});
388: &redirect_user($r,&mt('Entering [_1]',
389: $env{'course.'.$courseid.'.description'}),
1.150 www 390: $furl,$msg,
391: $env{'environment.remotenavmap'});
1.58 bowersj2 392: }
1.124 albertel 393: return OK;
1.55 albertel 394: }
395: }
1.62 matthew 396: #
397: # Send the user to the construction space they selected
1.125 www 398: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 399: my $redirect_url = '/priv/';
400: if ($role eq 'au') {
1.118 albertel 401: $redirect_url.=$env{'user.name'};
1.62 matthew 402: } else {
403: $where =~ /\/(.*)$/;
404: $redirect_url .= $1;
405: }
406: $redirect_url .= '/';
1.78 sakharuk 407: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 408: $redirect_url);
409: return OK;
410: }
1.104 raeburn 411: if ($role eq 'dc') {
1.108 raeburn 412: my $redirect_url = '/adm/menu/';
413: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 414: $redirect_url);
1.108 raeburn 415: return OK;
1.104 raeburn 416: }
1.55 albertel 417: }
418: }
1.6 www 419: }
1.40 matthew 420: }
1.44 www 421:
1.10 www 422:
1.6 www 423: # =============================================================== No Roles Init
1.10 www 424:
1.73 www 425: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 426: &Apache::loncommon::no_cache($r);
1.10 www 427: $r->send_http_header;
428: return OK if $r->header_only;
429:
1.52 www 430: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 431: my $start_page=&Apache::loncommon::start_page('User Roles');
1.134 www 432: my $standby=&mt('Role selected. Please stand by.');
1.135 albertel 433: $standby=~s/\n/\\n/g;
1.184 raeburn 434: my $noscript='<span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
1.163 www 435:
1.10 www 436: $r->print(<<ENDHEADER);
1.147 albertel 437: $start_page
1.163 www 438: <br />
1.179 raeburn 439: <noscript>
440: $noscript
441: </noscript>
442: <script type="text/javascript">
1.26 www 443: $swinfo
444: window.focus();
1.134 www 445:
446: active=true;
447:
448: function enterrole (thisform,rolecode,buttonname) {
449: if (active) {
450: active=false;
451: document.title='$standby';
452: window.status='$standby';
453: thisform.newrole.value=rolecode;
454: thisform.submit();
455: } else {
456: alert('$standby');
457: }
458: }
1.26 www 459: </script>
1.10 www 460: ENDHEADER
1.6 www 461:
1.2 www 462: # ------------------------------------------ Get Error Message from Environment
463:
1.118 albertel 464: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
465: if ($env{'user.error.msg'}) {
1.55 albertel 466: $r->log_reason(
1.118 albertel 467: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 468: }
1.1 harris41 469:
1.61 www 470: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 471:
1.118 albertel 472: my $advanced=$env{'user.adv'};
1.61 www 473: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 474: my $tryagain=$env{'form.tryagain'};
1.6 www 475:
1.2 www 476: # -------------------------------------------------------- Generate Page Output
1.6 www 477: # --------------------------------------------------------------- Error Header?
1.2 www 478: if ($error) {
1.187 bisitz 479: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 480: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
481: if ($priv ne '') {
1.187 bisitz 482: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 483: }
484: if ($fn ne '') {
1.187 bisitz 485: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 486: }
487: if ($msg ne '') {
1.187 bisitz 488: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 489: }
490: $r->print("</pre><hr />");
1.120 albertel 491: my $url=$fn;
492: my $last;
493: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
494: &GDBM_READER(),0640)) {
495: $last=$hash{'last_known'};
496: untie(%hash);
497: }
1.149 www 498: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 499:
500: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
501: &Apache::lonenc::check_encrypt($fn));
1.2 www 502: } else {
1.118 albertel 503: if ($env{'user.error.msg'}) {
1.25 www 504: $r->print(
1.157 albertel 505: '<h3><span class="LC_error">'.
506: &mt('You need to choose another user role or enter a specific course for this function').'</span></h3>');
1.25 www 507: }
1.2 www 508: }
1.6 www 509: # -------------------------------------------------------- Choice or no choice?
1.2 www 510: if ($nochoose) {
1.177 www 511: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
512: &mt('This action is currently not authorized.').'</span>'.
1.150 www 513: &Apache::loncommon::end_page());
514: return OK;
1.6 www 515: } else {
1.18 www 516: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
517: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 518: }
1.84 www 519: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 520: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
521: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 522: $r->print('<input type="hidden" name="newrole" value="" />');
1.6 www 523: }
1.118 albertel 524: if ($env{'user.adv'}) {
1.63 www 525: $r->print(
1.177 www 526: '<br /><span class="LC_rolesinfo"><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
1.118 albertel 527: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
1.177 www 528: $r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></span>');
1.63 www 529: }
1.4 www 530:
1.75 albertel 531: my (%roletext,%sortrole,%roleclass);
1.84 www 532: my $countactive=0;
1.191 raeburn 533: my $countfuture=0;
534: my $countwill=0;
1.84 www 535: my $inrole=0;
536: my $possiblerole='';
1.191 raeburn 537: my %futureroles;
538: my %roles_nextlogin;
1.118 albertel 539: foreach $envkey (sort keys %env) {
1.35 matthew 540: my $button = 1;
1.49 www 541: my $switchserver='';
1.75 albertel 542: my $roletext;
543: my $sortkey;
1.2 www 544: if ($envkey=~/^user\.role\./) {
1.102 raeburn 545: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
546: &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1.136 raeburn 547: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1.102 raeburn 548: $tremark='';
549: $tpstart=' ';
550: $tpend=' ';
551: $tfont='#000000';
1.4 www 552: if ($tstart) {
1.74 www 553: $tpstart=&Apache::lonlocal::locallocaltime($tstart);
1.4 www 554: }
555: if ($tend) {
1.74 www 556: $tpend=&Apache::lonlocal::locallocaltime($tend);
1.4 www 557: }
1.118 albertel 558: if ($env{'request.role'} eq $trolecode) {
1.6 www 559: $tstatus='selected';
560: }
1.4 www 561: my $tbg;
1.164 albertel 562: if (($tstatus eq 'is')
563: || ($tstatus eq 'selected')
564: || ($tstatus eq 'will')
565: || ($tstatus eq 'future')
566: || ($env{'form.showall'})) {
1.35 matthew 567: if ($tstatus eq 'is') {
568: $tbg='#77FF77';
1.47 www 569: $tfont='#003300';
1.84 www 570: $possiblerole=$trolecode;
571: $countactive++;
1.35 matthew 572: } elsif ($tstatus eq 'future') {
573: $tbg='#FFFF77';
1.49 www 574: $button=0;
1.191 raeburn 575: $futureroles{$trolecode} = $tstart.':'.$tend;
576: $countfuture ++;
1.35 matthew 577: } elsif ($tstatus eq 'will') {
578: $tbg='#FFAA77';
1.72 www 579: $tremark.=&mt('Active at next login. ');
1.191 raeburn 580: $roles_nextlogin{$trolecode} = $tstart.':'.$tend;
581: $countwill ++;
1.35 matthew 582: } elsif ($tstatus eq 'expired') {
583: $tbg='#FF7777';
1.47 www 584: $tfont='#330000';
1.49 www 585: $button=0;
1.35 matthew 586: } elsif ($tstatus eq 'will_not') {
587: $tbg='#AAFF77';
1.72 www 588: $tremark.=&mt('Expired after logout. ');
1.35 matthew 589: } elsif ($tstatus eq 'selected') {
590: $tbg='#11CC55';
1.47 www 591: $tfont='#002200';
1.84 www 592: $inrole=1;
1.86 albertel 593: $countactive++;
1.72 www 594: $tremark.=&mt('Currently selected. ');
1.35 matthew 595: }
596: my $trole;
597: if ($role =~ /^cr\//) {
598: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.132 albertel 599: if ($tremark) { $tremark.='<br />'; }
600: $tremark.=&mt('Defined by ').$rauthor.
1.72 www 601: &mt(' at ').$rdomain.'.';
1.159 albertel 602: }
603: $trole=Apache::lonnet::plaintext($role);
1.35 matthew 604: my $ttype;
605: my $twhere;
606: my ($tdom,$trest,$tsection)=
607: split(/\//,Apache::lonnet::declutter($where));
608: # First, Co-Authorship roles
1.125 www 609: if (($role eq 'ca') || ($role eq 'aa')) {
1.39 stredwic 610: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83 albertel 611: my $allowed=0;
612: my @ids=&Apache::lonnet::current_machine_ids();
613: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
614: if (!$allowed) {
1.49 www 615: $button=0;
1.130 albertel 616: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49 www 617: }
1.35 matthew 618: #next if ($home eq 'no_host');
1.176 albertel 619: $home = &Apache::lonnet::hostname($home);
1.78 sakharuk 620: $ttype='Construction Space';
1.72 www 621: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
622: ': '.$tdom.'<br />'.
623: ' '.&mt('Server').': '.$home;
1.118 albertel 624: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 625: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75 albertel 626: $sortkey=$role."$trest:$tdom";
1.35 matthew 627: } elsif ($role eq 'au') {
628: # Authors
629: my $home = &Apache::lonnet::homeserver
1.118 albertel 630: ($env{'user.name'},$env{'user.domain'});
1.83 albertel 631: my $allowed=0;
632: my @ids=&Apache::lonnet::current_machine_ids();
633: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
634: if (!$allowed) {
1.49 www 635: $button=0;
1.143 albertel 636: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49 www 637: }
1.35 matthew 638: #next if ($home eq 'no_host');
1.176 albertel 639: $home = &Apache::lonnet::hostname($home);
1.78 sakharuk 640: $ttype='Construction Space';
1.72 www 641: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
642: ': '.$home;
1.118 albertel 643: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
644: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1.75 albertel 645: $sortkey=$role;
1.35 matthew 646: } elsif ($trest) {
647: my $tcourseid=$tdom.'_'.$trest;
1.153 raeburn 648: $ttype = &Apache::loncommon::course_type($tcourseid);
649: $trole = &Apache::lonnet::plaintext($role,$ttype);
1.118 albertel 650: if ($env{'course.'.$tcourseid.'.description'}) {
651: $twhere=$env{'course.'.$tcourseid.'.description'};
1.80 albertel 652: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72 www 653: unless ($twhere eq &mt('Currently not available')) {
1.55 albertel 654: $twhere.=' <font size="-2">'.
1.72 www 655: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 656: '</font>';
1.55 albertel 657: }
1.8 www 658: } else {
1.105 raeburn 659: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1.35 matthew 660: if (%newhash) {
1.80 albertel 661: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77 albertel 662: "\0".$envkey;
1.49 www 663: $twhere=$newhash{'description'}.
664: ' <font size="-2">'.
1.72 www 665: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 666: '</font>';
1.152 raeburn 667: $ttype = $newhash{'type'};
1.153 raeburn 668: $trole = &Apache::lonnet::plaintext($role,$ttype);
1.35 matthew 669: } else {
1.72 www 670: $twhere=&mt('Currently not available');
1.118 albertel 671: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.80 albertel 672: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.152 raeburn 673: $ttype = 'Unavailable';
1.35 matthew 674: }
1.8 www 675: }
1.121 albertel 676: if ($tsection) {
1.175 albertel 677: $twhere.='<br />'.&mt('Section').': '.$tsection;
1.121 albertel 678: }
1.72 www 679: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35 matthew 680: } elsif ($tdom) {
1.78 sakharuk 681: $ttype='Domain';
1.35 matthew 682: $twhere=$tdom;
1.75 albertel 683: $sortkey=$role.$twhere;
1.35 matthew 684: } else {
1.78 sakharuk 685: $ttype='System';
1.72 www 686: $twhere=&mt('system wide');
1.75 albertel 687: $sortkey=$role.$twhere;
1.13 www 688: }
1.152 raeburn 689: $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
1.75 albertel 690: $roletext{$envkey}=$roletext;
691: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
692: $sortrole{$sortkey}=$envkey;
693: $roleclass{$envkey}=$ttype;
1.55 albertel 694: }
1.4 www 695: }
1.75 albertel 696: }
1.84 www 697: # No active roles
698: if ($countactive==0) {
699: if ($inrole) {
700: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
701: } else {
702: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
703: }
1.191 raeburn 704: &findcourse_advice($r);
705: $r->print('</form>');
706: if ($countfuture) {
707: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
708: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
709: $nochoose);
710: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
711: \%roletext);
712: my $tremark='';
713: my $tfont='#003300';
714: if ($env{'request.role'} eq 'cm') {
715: $r->print('<tr bgcolor="#11CC55">');
716: $tremark=&mt('Currently selected. ');
717: $tfont='#002200';
718: } else {
719: $r->print('<tr bgcolor="#77FF77">');
720: }
721: $r->print('<td></td><td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
1.192 ! raeburn 722: '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
1.191 raeburn 723: ' </font></td></tr>'."\n");
724:
725: $r->print('</table>');
726: }
727: $r->print(&Apache::loncommon::end_page());
1.84 www 728: return OK;
729: # Is there only one choice?
1.118 albertel 730: } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
1.84 www 731: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
1.179 raeburn 732: '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
733: '<noscript><br /><input type="submit" name="submit" value="'.&mt('Continue').'" /></noscript>');
1.84 www 734: $r->print("</form>\n");
735: $r->rflush();
1.179 raeburn 736: $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
1.147 albertel 737: $r->print(&Apache::loncommon::end_page());
1.84 www 738: return OK;
739: }
740: # More than one possible role
741: # ----------------------------------------------------------------------- Table
1.181 albertel 742: unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
1.173 albertel 743: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 744: }
1.191 raeburn 745: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 746: if ($env{'environment.recentroles'}) {
1.111 albertel 747: my %recent_roles =
1.118 albertel 748: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 749: my $output='';
750: foreach (sort(keys(%recent_roles))) {
751: if (defined($roletext{'user.role.'.$_})) {
752: $output.=$roletext{'user.role.'.$_};
1.170 albertel 753: if ($_ =~ m-dc\./($match_domain)/-
754: && $dcroles{$1}) {
1.192 ! raeburn 755: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 756: }
1.113 raeburn 757: } elsif ($numdc > 0) {
758: unless ($_ =~/^error\:/) {
759: $output.=&display_cc_role('user.role.'.$_);
760: }
761: }
1.111 albertel 762: }
763: if ($output) {
1.132 albertel 764: $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
1.192 ! raeburn 765: &mt('Recent Roles')."</font></td></tr>");
1.111 albertel 766: $r->print($output);
1.114 raeburn 767: $doheaders ++;
1.111 albertel 768: }
769: }
770:
1.104 raeburn 771: if ($numdc > 0) {
1.112 raeburn 772: $r->print(&coursepick_jscript());
773: $r->print(&Apache::loncommon::coursebrowser_javascript());
1.108 raeburn 774: }
1.191 raeburn 775: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.14 www 776: my $tremark='';
1.47 www 777: my $tfont='#003300';
1.118 albertel 778: if ($env{'request.role'} eq 'cm') {
1.19 www 779: $r->print('<tr bgcolor="#11CC55">');
1.72 www 780: $tremark=&mt('Currently selected. ');
1.47 www 781: $tfont='#002200';
1.14 www 782: } else {
783: $r->print('<tr bgcolor="#77FF77">');
784: }
785: unless ($nochoose) {
1.118 albertel 786: if ($env{'request.role'} ne 'cm') {
1.134 www 787: $r->print('<td><input type="submit" value="'.
1.192 ! raeburn 788: &mt('Select').'" name="cm" /></td>');
1.55 albertel 789: } else {
790: $r->print('<td> </td>');
791: }
1.14 www 792: }
1.177 www 793: $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
1.192 ! raeburn 794: '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
1.47 www 795: ' </font></td></tr>'."\n");
1.4 www 796:
797: $r->print('</table>');
798: unless ($nochoose) {
799: $r->print("</form>\n");
800: }
1.22 harris41 801: # ------------------------------------------------------------ Privileges Info
1.118 albertel 802: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.127 albertel 803: $r->print('<hr /><h2>Current Privileges</h2>');
1.175 albertel 804: $r->print(&privileges_info());
1.4 www 805: }
1.66 www 806: $r->print(&Apache::lonnet::getannounce());
1.65 www 807: if ($advanced) {
808: $r->print('<p><small><i>This is LON-CAPA '.
1.85 www 809: $r->dir_config('lonVersion').'</i><br />'.
810: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 811: }
1.147 albertel 812: $r->print(&Apache::loncommon::end_page());
1.1 harris41 813: return OK;
1.102 raeburn 814: }
815:
1.191 raeburn 816: sub roletable_headers {
817: my ($r,$roleclass,$sortrole,$nochoose) = @_;
818: my $doheaders;
819: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
820: $r->print('<br /><table id="LC_rolesmenu"><tr>');
821: if (!$nochoose) { $r->print('<th> </th>'); }
822: $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent')
823: .'</th><th>'.&mt('Start').'</th><th>'.&mt('End')
824: .'</th></tr>'."\n");
825: $doheaders=-1;
826: my @roletypes = &roletypes();
827: foreach my $type (@roletypes) {
828: my $haverole=0;
829: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
830: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
831: $haverole=1;
832: }
833: }
834: if ($haverole) { $doheaders++; }
835: }
836: }
837: return $doheaders;
838: }
839:
840: sub roletypes {
841: my @types = ('Domain','Construction Space','Course','Unavailable','System');
842: return @types;
843: }
844:
845: sub print_rolerows {
846: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
847: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
848: my @types = &roletypes();
849: foreach my $type (@types) {
850: my $output;
851: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
852: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
853: if (ref($roletext) eq 'HASH') {
854: $output.=$roletext->{$sortrole->{$which}};
855: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
856: if (ref($dcroles) eq 'HASH') {
857: if ($dcroles->{$1}) {
1.192 ! raeburn 858: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 859: }
860: }
861: }
862: }
863: }
864: }
865: if ($output) {
866: if ($doheaders > 0) {
867: $r->print("<tr>".
868: "<td align='center' colspan='5'><font face='arial'>".
869: &mt($type)."</font></td></tr>");
870: }
871: $r->print($output);
872: }
873: }
874: }
875: }
876:
877: sub findcourse_advice {
878: my ($r) = @_;
879: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
880: if (&check_autoenroll($env{'user.domain'})) {
881: $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
882: <ul>
883: <li>'.&mt('The course has yet to be created.').'</li>
884: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
885: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
886: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
887: <li>'.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'</li>
888: </ul>');
889: } else {
890: $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'<br />');
891: }
892: $r->print('<p>'.&mt('The [_1]Course Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created.','<a href="/adm/coursecatalog">','</a>',$domdesc).'<br />');
893: $r->print(&mt('You can search the course catalog for courses which permit self-enrollment, if you would like to enroll in a course.').'</p>');
894: return;
895: }
896:
1.175 albertel 897: sub privileges_info {
898: my ($which) = @_;
899: my $output;
900:
901: $which ||= $env{'request.role'};
902:
903: foreach my $envkey (sort(keys(%env))) {
904: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
905:
906: my $where=$1;
907: my $ttype;
908: my $twhere;
909: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
910: if ($trest) {
911: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
912: $ttype='Construction Space';
913: $twhere='User: '.$trest.', Domain: '.$tdom;
914: } else {
915: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
916: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
917: if ($tsec) {
918: my $sec_type = 'Section';
919: if (exists($env{"user.role.gr.$where"})) {
920: $sec_type = 'Group';
921: }
922: $twhere.=' ('.$sec_type.': '.$tsec.')';
923: }
924: }
925: } elsif ($tdom) {
926: $ttype='Domain';
927: $twhere=$tdom;
928: } else {
929: $ttype='System';
930: $twhere='/';
931: }
932: $output .= "\n<h3>".$ttype.': '.$twhere.'</h3>'."\n<ul>";
933: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
934: next if (!$priv);
935:
936: my ($prv,$restr)=split(/\&/,$priv);
937: my $trestr='';
938: if ($restr ne 'F') {
939: $trestr.=' ('.
940: join(', ',
941: map { &Apache::lonnet::plaintext($_) }
942: (split('',$restr))).') ';
943: }
944: $output .= "\n\t".
945: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
946: }
947: $output .= "\n".'</ul>';
948: }
949: return $output;
950: }
951:
1.102 raeburn 952: sub role_status {
953: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
954: my @pwhere = ();
1.118 albertel 955: if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
1.102 raeburn 956: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
957: unless (!defined($$role) || $$role eq '') {
958: $$where=join('.',@pwhere);
959: $$trolecode=$$role.'.'.$$where;
1.118 albertel 960: ($$tstart,$$tend)=split(/\./,$env{$rolekey});
1.102 raeburn 961: $$tstatus='is';
1.105 raeburn 962: if ($$tstart && $$tstart>$then) {
963: $$tstatus='future';
964: if ($$tstart<$now) { $$tstatus='will'; }
1.102 raeburn 965: }
966: if ($$tend) {
967: if ($$tend<$then) {
968: $$tstatus='expired';
1.103 raeburn 969: } elsif ($$tend<$now) {
1.104 raeburn 970: $$tstatus='will_not';
1.102 raeburn 971: }
972: }
973: }
974: }
975: }
1.1 harris41 976:
1.110 raeburn 977: sub build_roletext {
1.152 raeburn 978: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.177 www 979: my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
1.132 albertel 980: my $is_dc=($trolecode =~ m/^dc\./);
981: my $rowspan=($is_dc) ? ''
982: : ' rowspan="2" ';
983:
1.110 raeburn 984: unless ($nochoose) {
1.134 www 985: my $buttonname=$trolecode;
986: $buttonname=~s/\W//g;
1.110 raeburn 987: if (!$button) {
988: if ($switchserver) {
1.177 www 989: $roletext.='<td'.$rowspan.'><span class="LC_rolesinfo"><a href="/adm/switchserver?'.
990: $switchserver.'">'.&mt('Switch Server').'</a></span></td>';
1.110 raeburn 991: } else {
1.164 albertel 992: $roletext.=('<td'.$rowspan.'> </td>');
1.110 raeburn 993: }
994: } elsif ($tstatus eq 'is') {
1.134 www 995: $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
996: &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
1.192 ! raeburn 997: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 998: } elsif ($tryagain) {
999: $roletext.=
1.134 www 1000: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
1001: &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
1.192 ! raeburn 1002: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1003: } elsif ($advanced) {
1004: $roletext.=
1.134 www 1005: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
1006: &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
1.192 ! raeburn 1007: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1008: } else {
1.132 albertel 1009: $roletext.='<td'.$rowspan.'> </td>';
1.110 raeburn 1010: }
1011: }
1.165 albertel 1012: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1013: $tremark.=&Apache::lonannounce::showday(time,1,
1014: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1015: }
1.110 raeburn 1016: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.121 albertel 1017: '</font></td><td><font color="'.$tfont.'">'.$twhere.
1.110 raeburn 1018: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
1019: '</font></td><td><font color="'.$tfont.'">'.$tpend.
1.132 albertel 1020: '</font></td></tr>';
1021: if (!$is_dc) {
1.177 www 1022: $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.
1023: '</span> </font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1.132 albertel 1024: }
1.110 raeburn 1025: return $roletext;
1026: }
1027:
1.183 www 1028: sub is_author_homeserver {
1029: my ($uname,$udom)=@_;
1030: my $home = &Apache::lonnet::homeserver($uname,$udom);
1031: my @ids=&Apache::lonnet::current_machine_ids();
1032: foreach my $id (@ids) {
1033: if ($id eq $home) {
1034: if (-e "/home/".$uname."/public_html") {
1035: return 1;
1036: }
1037: }
1038: }
1039: return 0;
1040: }
1041:
1.110 raeburn 1042: sub check_privs {
1.182 www 1043: my ($cdom,$cnum,$then,$now,$checkrole) = @_;
1044: my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum;
1.118 albertel 1045: if ($env{$cckey}) {
1.110 raeburn 1046: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
1047: &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1048: unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
1.182 www 1049: &set_privileges($cdom,$cnum,$checkrole);
1.110 raeburn 1050: }
1051: } else {
1.182 www 1052: &set_privileges($cdom,$cnum,$checkrole);
1.110 raeburn 1053: }
1054: }
1055:
1.104 raeburn 1056: sub check_fordc {
1057: my ($dcroles,$then) = @_;
1058: my $numdc = 0;
1.118 albertel 1059: if ($env{'user.adv'}) {
1060: foreach my $envkey (sort keys %env) {
1.170 albertel 1061: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1062: my $dcdom = $1;
1063: my $livedc = 1;
1.118 albertel 1064: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 1065: if ($tstart && $tstart>$then) { $livedc = 0; }
1066: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 1067: if ($livedc) {
1068: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1069: $numdc++;
1.104 raeburn 1070: }
1071: }
1072: }
1073: }
1074: return $numdc;
1075: }
1076:
1.185 raeburn 1077: sub adhoc_course_role {
1078: my ($then) = @_;
1079: my ($cdom,$cnum);
1080: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1081: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1082: if (&check_forcc($cdom,$cnum,$then)) {
1083: my $setprivs;
1084: if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
1085: $setprivs = 1;
1086: } else {
1087: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
1088: if (($start && ($start>$then || $start == -1)) ||
1089: ($end && $end<$then)) {
1090: $setprivs = 1;
1091: }
1092: }
1093: if ($setprivs) {
1094: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
1095: my $role = $1;
1096: my $custom_role = $2;
1097: my $usec = $3;
1098: if ($role eq 'cr') {
1099: if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
1100: $role .= $custom_role;
1101: } else {
1102: return;
1103: }
1104: }
1105: my (%userroles,%newrole,%newgroups);
1106: my $area = '/'.$cdom.'/'.$cnum;
1107: my $spec = $role.'.'.$area;
1108: if ($usec ne '') {
1109: $spec .= '/'.$usec;
1110: $area .= '/'.$usec;
1111: }
1112: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1113: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
1114: my $adhocstart = $then-1;
1115: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1116: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1117: }
1118: }
1119: }
1120: return;
1121: }
1122:
1123: sub check_forcc {
1124: my ($cdom,$cnum,$then) = @_;
1125: my $is_cc;
1126: if ($cdom ne '' && $cnum ne '') {
1127: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1128: my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
1129: if (defined($env{$envkey})) {
1130: $is_cc = 1;
1131: my ($tstart,$tend)=split(/\./,$env{$envkey});
1132: if ($tstart && $tstart>$then) { $is_cc = 0; }
1133: if ($tend && $tend <$then) { $is_cc = 0; }
1134: }
1135: }
1136: }
1137: return $is_cc;
1138: }
1139:
1.108 raeburn 1140: sub courselink {
1.152 raeburn 1141: my ($dcdom,$rowtype,$selecttype) = @_;
1.109 raeburn 1142: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1143: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1144: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.173 albertel 1145: $dcdom,$dcdom,undef);
1.138 raeburn 1146: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1147: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1148: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1149: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1150: return $courseform.$hiddenitems;
1.109 raeburn 1151: }
1152:
1153: sub coursepick_jscript {
1.184 raeburn 1154: my %lt = &Apache::lonlocal::texthash(
1155: plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
1156: youc => 'You can only use this screen to select courses in the current domain.',
1157: );
1.104 raeburn 1158: my $verify_script = <<"END";
1.179 raeburn 1159: <script type="text/javascript">
1.108 raeburn 1160: function verifyCoursePick(caller) {
1161: var numbutton = getIndex(caller)
1.112 raeburn 1162: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1163: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1164: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1165: if (pickedCourse != '') {
1.108 raeburn 1166: if (numbutton != -1) {
1167: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1168: document.rolechoice.elements[numbutton+1].name = courseTarget
1169: document.rolechoice.submit()
1170: }
1.104 raeburn 1171: }
1172: else {
1.184 raeburn 1173: alert("$lt{'plsu'}");
1.104 raeburn 1174: }
1175: }
1176: else {
1.184 raeburn 1177: alert("$lt{'youc'}")
1.104 raeburn 1178: }
1179: }
1.109 raeburn 1180: function getIndex(caller) {
1.108 raeburn 1181: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1182: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1183: return i;
1184: }
1185: }
1186: return -1;
1187: }
1.104 raeburn 1188: </script>
1189: END
1.109 raeburn 1190: return $verify_script;
1.104 raeburn 1191: }
1192:
1.113 raeburn 1193: sub display_cc_role {
1194: my $rolekey = shift;
1195: my $roletext;
1.118 albertel 1196: my $advanced = $env{'user.adv'};
1197: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1198: unless ($rolekey =~/^error\:/) {
1.171 albertel 1199: if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1.113 raeburn 1200: my $tcourseid = $1.'_'.$2;
1201: my $trolecode = 'cc./'.$1.'/'.$2;
1202: my $twhere;
1.152 raeburn 1203: my $ttype;
1.113 raeburn 1204: my $tbg='#77FF77';
1205: my $tfont='#003300';
1206: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1207: if (%newhash) {
1208: $twhere=$newhash{'description'}.
1209: ' <font size="-2">'.
1210: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
1211: '</font>';
1.153 raeburn 1212: $ttype = $newhash{'type'};
1.113 raeburn 1213: } else {
1214: $twhere=&mt('Currently not available');
1.118 albertel 1215: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1216: }
1.153 raeburn 1217: my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1.113 raeburn 1218: $twhere.="<br />".&mt('Domain').":".$1;
1.152 raeburn 1219: $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
1.104 raeburn 1220: }
1221: }
1.152 raeburn 1222: return ($roletext);
1.104 raeburn 1223: }
1224:
1.192 ! raeburn 1225: sub adhoc_roles_row {
1.138 raeburn 1226: my ($dcdom,$rowtype) = @_;
1.132 albertel 1227: my $output = '<tr bgcolor="#77FF77">'.
1.192 ! raeburn 1228: ' <td colspan="5"><table><tr><td><span class="LC_rolesinfo">'
! 1229: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --',
! 1230: '<span class="LC_cusr_emph">','</span>',$dcdom).'</span></td><td>';
1.173 albertel 1231: my $selectlink = &courselink($dcdom,$rowtype);
1232: my $ccrole = &Apache::lonnet::plaintext('cc');
1.182 www 1233: my $carole = &Apache::lonnet::plaintext('ca');
1234: my $inputlink='<input type="text" size="10" name="adhoccauname'.$rowtype.'.'.$dcdom.'" />';
1235: my $gobutton='<input type="submit" name="adhocca./'.$dcdom.'" value="'.&mt('Go').'" />';
1236: $output.= '<span class="LC_rolesinfo">'.
1.192 ! raeburn 1237: &mt('[_1]: [_2]',$ccrole,$selectlink).
! 1238: '</span><br /></td><td> </td><td><span class="LC_rolesinfo">'.
! 1239: &mt('[_1]: [_2] [_3]',$carole,$inputlink,$gobutton).
! 1240: '</span><br /></td></tr></table></td></tr>'.
! 1241: '<tr><td colspan="5" height="3"></td></tr>'."\n";
1.108 raeburn 1242: return $output;
1243: }
1244:
1.104 raeburn 1245: sub recent_filename {
1246: my $area=shift;
1.149 www 1247: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1248: }
1249:
1.106 raeburn 1250: sub set_privileges {
1.182 www 1251: # role can be cc or ca
1252: my ($dcdom,$pickedcourse,$role) = @_;
1.106 raeburn 1253: my $area = '/'.$dcdom.'/'.$pickedcourse;
1254: my $spec = $role.'.'.$area;
1.168 albertel 1255: my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
1256: $env{'user.domain'},
1257: $env{'user.name'});
1.106 raeburn 1258: my %ccrole = ();
1259: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.154 albertel 1260: my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1.186 raeburn 1261: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.184 raeburn 1262:
1.118 albertel 1263: &Apache::lonnet::log($env{'user.domain'},
1264: $env{'user.name'},
1265: $env{'user.home'},
1.106 raeburn 1266: "Role ".$role);
1267: &Apache::lonnet::appenv(
1.186 raeburn 1268: {'request.role' => $spec,
1.106 raeburn 1269: 'request.role.domain' => $dcdom,
1.186 raeburn 1270: 'request.course.sec' => ''});
1.106 raeburn 1271: my $tadv=0;
1272: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 1273: &Apache::lonnet::appenv({'request.role.adv' => $tadv});
1.106 raeburn 1274: }
1275:
1.139 raeburn 1276: sub courseloadpage {
1277: my ($courseid) = @_;
1278: my $startpage;
1.144 albertel 1279: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1280: [$courseid.':courseinit']);
1.139 raeburn 1281: my ($tmp) = %entry_settings;
1.144 albertel 1282: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1283: $startpage = $entry_settings{$courseid.':courseinit'};
1284: }
1285: if ($startpage eq '') {
1286: if (exists($env{'environment.course_init_display'})) {
1287: $startpage = $env{'environment.course_init_display'};
1288: }
1289: }
1290: return $startpage;
1291: }
1292:
1.191 raeburn 1293: sub check_autoenroll {
1294: my ($dom) = @_;
1295: my $run_enroll = 0;
1296: my $settings;
1297: my %domconfig =
1298: &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
1299: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1300: $settings = $domconfig{'autoenroll'};
1301: if ($settings->{'run'} eq '1') {
1302: $run_enroll = 1;
1303: }
1304: } else {
1305: $run_enroll = &localenroll::run($dom);
1306: }
1307: return $run_enroll;
1308: }
1309:
1310:
1.1 harris41 1311: 1;
1312: __END__
1.32 harris41 1313:
1314: =head1 NAME
1315:
1316: Apache::lonroles - User Roles Screen
1317:
1318: =head1 SYNOPSIS
1319:
1320: Invoked by /etc/httpd/conf/srm.conf:
1321:
1322: <Location /adm/roles>
1323: PerlAccessHandler Apache::lonacc
1324: SetHandler perl-script
1325: PerlHandler Apache::lonroles
1326: ErrorDocument 403 /adm/login
1327: ErrorDocument 500 /adm/errorhandler
1328: </Location>
1.64 bowersj2 1329:
1330: =head1 OVERVIEW
1331:
1332: =head2 Choosing Roles
1333:
1334: C<lonroles> is a handler that allows a user to switch roles in
1335: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1336: default role that a user has before selecting a role, as widely as
1337: possible, but certain handlers for example need specification which
1338: course they should act on, etc. Both in this scenario, and when the
1339: handler determines via C<lonnet>'s C<&allowed> function that a certain
1340: action is not allowed, C<lonroles> is used as error handler. This
1341: allows the user to select another role which may have permission to do
1342: what they were trying to do. C<lonroles> can also be accessed via the
1343: B<CRS> button in the Remote Control.
1344:
1345: =begin latex
1346:
1347: \begin{figure}
1348: \begin{center}
1349: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1350: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1351: \end{center}
1352: \end{figure}
1353:
1354: =end latex
1355:
1356: =head2 Role Initialization
1357:
1358: 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 1359:
1360: =head1 INTRODUCTION
1361:
1362: This module enables a user to select what role he wishes to
1363: operate under (instructor, student, teaching assistant, course
1364: coordinator, etc). These roles are pre-established by the actions
1365: of upper-level users.
1366:
1367: This is part of the LearningOnline Network with CAPA project
1368: described at http://www.lon-capa.org.
1369:
1370: =head1 HANDLER SUBROUTINE
1371:
1372: This routine is called by Apache and mod_perl.
1373:
1374: =over 4
1375:
1376: =item *
1377:
1378: Roles Initialization (yes/no)
1379:
1380: =item *
1381:
1382: Get Error Message from Environment
1383:
1384: =item *
1385:
1386: Who is this?
1387:
1388: =item *
1389:
1390: Generate Page Output
1391:
1392: =item *
1393:
1394: Choice or no choice
1395:
1396: =item *
1397:
1398: Table
1399:
1400: =item *
1401:
1402: Privileges
1403:
1404: =back
1405:
1406: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>