Annotation of loncom/auth/lonroles.pm, revision 1.191
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.191 ! raeburn 4: # $Id: lonroles.pm,v 1.190 2008/05/14 22:26:48 www 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').
! 722: '</font></span></td><td><font color="'.$tfont.'">'.$tremark.
! 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.182 www 755: $output .= &allcourses_row($1,'recent').
756: &allcoauthors_row($1,'recent');
1.133 albertel 757: }
1.113 raeburn 758: } elsif ($numdc > 0) {
759: unless ($_ =~/^error\:/) {
760: $output.=&display_cc_role('user.role.'.$_);
761: }
762: }
1.111 albertel 763: }
764: if ($output) {
1.132 albertel 765: $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
1.126 www 766: &mt('Recent Roles')."</font></td>");
1.111 albertel 767: $r->print($output);
768: $r->print("</tr>");
1.114 raeburn 769: $doheaders ++;
1.111 albertel 770: }
771: }
772:
1.104 raeburn 773: if ($numdc > 0) {
1.112 raeburn 774: $r->print(&coursepick_jscript());
775: $r->print(&Apache::loncommon::coursebrowser_javascript());
1.108 raeburn 776: }
1.191 ! raeburn 777: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.14 www 778: my $tremark='';
1.47 www 779: my $tfont='#003300';
1.118 albertel 780: if ($env{'request.role'} eq 'cm') {
1.19 www 781: $r->print('<tr bgcolor="#11CC55">');
1.72 www 782: $tremark=&mt('Currently selected. ');
1.47 www 783: $tfont='#002200';
1.14 www 784: } else {
785: $r->print('<tr bgcolor="#77FF77">');
786: }
787: unless ($nochoose) {
1.118 albertel 788: if ($env{'request.role'} ne 'cm') {
1.134 www 789: $r->print('<td><input type="submit" value="'.
1.72 www 790: &mt('Select').'" name="cm"></td>');
1.55 albertel 791: } else {
792: $r->print('<td> </td>');
793: }
1.14 www 794: }
1.177 www 795: $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
796: '</font></span></td><td><font color="'.$tfont.'">'.$tremark.
1.47 www 797: ' </font></td></tr>'."\n");
1.4 www 798:
799: $r->print('</table>');
800: unless ($nochoose) {
801: $r->print("</form>\n");
802: }
1.22 harris41 803: # ------------------------------------------------------------ Privileges Info
1.118 albertel 804: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.127 albertel 805: $r->print('<hr /><h2>Current Privileges</h2>');
1.175 albertel 806: $r->print(&privileges_info());
1.4 www 807: }
1.66 www 808: $r->print(&Apache::lonnet::getannounce());
1.65 www 809: if ($advanced) {
810: $r->print('<p><small><i>This is LON-CAPA '.
1.85 www 811: $r->dir_config('lonVersion').'</i><br />'.
812: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 813: }
1.147 albertel 814: $r->print(&Apache::loncommon::end_page());
1.1 harris41 815: return OK;
1.102 raeburn 816: }
817:
1.191 ! raeburn 818: sub roletable_headers {
! 819: my ($r,$roleclass,$sortrole,$nochoose) = @_;
! 820: my $doheaders;
! 821: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
! 822: $r->print('<br /><table id="LC_rolesmenu"><tr>');
! 823: if (!$nochoose) { $r->print('<th> </th>'); }
! 824: $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent')
! 825: .'</th><th>'.&mt('Start').'</th><th>'.&mt('End')
! 826: .'</th></tr>'."\n");
! 827: $doheaders=-1;
! 828: my @roletypes = &roletypes();
! 829: foreach my $type (@roletypes) {
! 830: my $haverole=0;
! 831: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
! 832: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
! 833: $haverole=1;
! 834: }
! 835: }
! 836: if ($haverole) { $doheaders++; }
! 837: }
! 838: }
! 839: return $doheaders;
! 840: }
! 841:
! 842: sub roletypes {
! 843: my @types = ('Domain','Construction Space','Course','Unavailable','System');
! 844: return @types;
! 845: }
! 846:
! 847: sub print_rolerows {
! 848: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
! 849: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
! 850: my @types = &roletypes();
! 851: foreach my $type (@types) {
! 852: my $output;
! 853: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
! 854: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
! 855: if (ref($roletext) eq 'HASH') {
! 856: $output.=$roletext->{$sortrole->{$which}};
! 857: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
! 858: if (ref($dcroles) eq 'HASH') {
! 859: if ($dcroles->{$1}) {
! 860: $output .= &allcourses_row($1,'').
! 861: &allcoauthors_row($1,'');
! 862: }
! 863: }
! 864: }
! 865: }
! 866: }
! 867: }
! 868: if ($output) {
! 869: if ($doheaders > 0) {
! 870: $r->print("<tr>".
! 871: "<td align='center' colspan='5'><font face='arial'>".
! 872: &mt($type)."</font></td></tr>");
! 873: }
! 874: $r->print($output);
! 875: }
! 876: }
! 877: }
! 878: }
! 879:
! 880: sub findcourse_advice {
! 881: my ($r) = @_;
! 882: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
! 883: if (&check_autoenroll($env{'user.domain'})) {
! 884: $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).'
! 885: <ul>
! 886: <li>'.&mt('The course has yet to be created.').'</li>
! 887: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
! 888: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
! 889: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
! 890: <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>
! 891: </ul>');
! 892: } else {
! 893: $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 />');
! 894: }
! 895: $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 />');
! 896: $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>');
! 897: return;
! 898: }
! 899:
1.175 albertel 900: sub privileges_info {
901: my ($which) = @_;
902: my $output;
903:
904: $which ||= $env{'request.role'};
905:
906: foreach my $envkey (sort(keys(%env))) {
907: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
908:
909: my $where=$1;
910: my $ttype;
911: my $twhere;
912: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
913: if ($trest) {
914: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
915: $ttype='Construction Space';
916: $twhere='User: '.$trest.', Domain: '.$tdom;
917: } else {
918: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
919: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
920: if ($tsec) {
921: my $sec_type = 'Section';
922: if (exists($env{"user.role.gr.$where"})) {
923: $sec_type = 'Group';
924: }
925: $twhere.=' ('.$sec_type.': '.$tsec.')';
926: }
927: }
928: } elsif ($tdom) {
929: $ttype='Domain';
930: $twhere=$tdom;
931: } else {
932: $ttype='System';
933: $twhere='/';
934: }
935: $output .= "\n<h3>".$ttype.': '.$twhere.'</h3>'."\n<ul>";
936: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
937: next if (!$priv);
938:
939: my ($prv,$restr)=split(/\&/,$priv);
940: my $trestr='';
941: if ($restr ne 'F') {
942: $trestr.=' ('.
943: join(', ',
944: map { &Apache::lonnet::plaintext($_) }
945: (split('',$restr))).') ';
946: }
947: $output .= "\n\t".
948: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
949: }
950: $output .= "\n".'</ul>';
951: }
952: return $output;
953: }
954:
1.102 raeburn 955: sub role_status {
956: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
957: my @pwhere = ();
1.118 albertel 958: if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
1.102 raeburn 959: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
960: unless (!defined($$role) || $$role eq '') {
961: $$where=join('.',@pwhere);
962: $$trolecode=$$role.'.'.$$where;
1.118 albertel 963: ($$tstart,$$tend)=split(/\./,$env{$rolekey});
1.102 raeburn 964: $$tstatus='is';
1.105 raeburn 965: if ($$tstart && $$tstart>$then) {
966: $$tstatus='future';
967: if ($$tstart<$now) { $$tstatus='will'; }
1.102 raeburn 968: }
969: if ($$tend) {
970: if ($$tend<$then) {
971: $$tstatus='expired';
1.103 raeburn 972: } elsif ($$tend<$now) {
1.104 raeburn 973: $$tstatus='will_not';
1.102 raeburn 974: }
975: }
976: }
977: }
978: }
1.1 harris41 979:
1.110 raeburn 980: sub build_roletext {
1.152 raeburn 981: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.177 www 982: my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
1.132 albertel 983: my $is_dc=($trolecode =~ m/^dc\./);
984: my $rowspan=($is_dc) ? ''
985: : ' rowspan="2" ';
986:
1.110 raeburn 987: unless ($nochoose) {
1.134 www 988: my $buttonname=$trolecode;
989: $buttonname=~s/\W//g;
1.110 raeburn 990: if (!$button) {
991: if ($switchserver) {
1.177 www 992: $roletext.='<td'.$rowspan.'><span class="LC_rolesinfo"><a href="/adm/switchserver?'.
993: $switchserver.'">'.&mt('Switch Server').'</a></span></td>';
1.110 raeburn 994: } else {
1.164 albertel 995: $roletext.=('<td'.$rowspan.'> </td>');
1.110 raeburn 996: }
997: } elsif ($tstatus eq 'is') {
1.134 www 998: $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
999: &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
1000: $trolecode."','".$buttonname.'\');"></td>';
1.110 raeburn 1001: } elsif ($tryagain) {
1002: $roletext.=
1.134 www 1003: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
1004: &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
1005: $trolecode."','".$buttonname.'\');"></td>';
1.110 raeburn 1006: } elsif ($advanced) {
1007: $roletext.=
1.134 www 1008: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
1009: &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
1010: $trolecode."','".$buttonname.'\');"></td>';
1.110 raeburn 1011: } else {
1.132 albertel 1012: $roletext.='<td'.$rowspan.'> </td>';
1.110 raeburn 1013: }
1014: }
1.165 albertel 1015: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1016: $tremark.=&Apache::lonannounce::showday(time,1,
1017: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1018: }
1.110 raeburn 1019: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.121 albertel 1020: '</font></td><td><font color="'.$tfont.'">'.$twhere.
1.110 raeburn 1021: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
1022: '</font></td><td><font color="'.$tfont.'">'.$tpend.
1.132 albertel 1023: '</font></td></tr>';
1024: if (!$is_dc) {
1.177 www 1025: $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.
1026: '</span> </font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1.132 albertel 1027: }
1.110 raeburn 1028: return $roletext;
1029: }
1030:
1.183 www 1031: sub is_author_homeserver {
1032: my ($uname,$udom)=@_;
1033: my $home = &Apache::lonnet::homeserver($uname,$udom);
1034: my @ids=&Apache::lonnet::current_machine_ids();
1035: foreach my $id (@ids) {
1036: if ($id eq $home) {
1037: if (-e "/home/".$uname."/public_html") {
1038: return 1;
1039: }
1040: }
1041: }
1042: return 0;
1043: }
1044:
1.110 raeburn 1045: sub check_privs {
1.182 www 1046: my ($cdom,$cnum,$then,$now,$checkrole) = @_;
1047: my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum;
1.118 albertel 1048: if ($env{$cckey}) {
1.110 raeburn 1049: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
1050: &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1051: unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
1.182 www 1052: &set_privileges($cdom,$cnum,$checkrole);
1.110 raeburn 1053: }
1054: } else {
1.182 www 1055: &set_privileges($cdom,$cnum,$checkrole);
1.110 raeburn 1056: }
1057: }
1058:
1.104 raeburn 1059: sub check_fordc {
1060: my ($dcroles,$then) = @_;
1061: my $numdc = 0;
1.118 albertel 1062: if ($env{'user.adv'}) {
1063: foreach my $envkey (sort keys %env) {
1.170 albertel 1064: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1065: my $dcdom = $1;
1066: my $livedc = 1;
1.118 albertel 1067: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 1068: if ($tstart && $tstart>$then) { $livedc = 0; }
1069: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 1070: if ($livedc) {
1071: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1072: $numdc++;
1.104 raeburn 1073: }
1074: }
1075: }
1076: }
1077: return $numdc;
1078: }
1079:
1.185 raeburn 1080: sub adhoc_course_role {
1081: my ($then) = @_;
1082: my ($cdom,$cnum);
1083: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1084: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1085: if (&check_forcc($cdom,$cnum,$then)) {
1086: my $setprivs;
1087: if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
1088: $setprivs = 1;
1089: } else {
1090: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
1091: if (($start && ($start>$then || $start == -1)) ||
1092: ($end && $end<$then)) {
1093: $setprivs = 1;
1094: }
1095: }
1096: if ($setprivs) {
1097: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
1098: my $role = $1;
1099: my $custom_role = $2;
1100: my $usec = $3;
1101: if ($role eq 'cr') {
1102: if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
1103: $role .= $custom_role;
1104: } else {
1105: return;
1106: }
1107: }
1108: my (%userroles,%newrole,%newgroups);
1109: my $area = '/'.$cdom.'/'.$cnum;
1110: my $spec = $role.'.'.$area;
1111: if ($usec ne '') {
1112: $spec .= '/'.$usec;
1113: $area .= '/'.$usec;
1114: }
1115: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1116: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
1117: my $adhocstart = $then-1;
1118: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1119: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1120: }
1121: }
1122: }
1123: return;
1124: }
1125:
1126: sub check_forcc {
1127: my ($cdom,$cnum,$then) = @_;
1128: my $is_cc;
1129: if ($cdom ne '' && $cnum ne '') {
1130: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1131: my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
1132: if (defined($env{$envkey})) {
1133: $is_cc = 1;
1134: my ($tstart,$tend)=split(/\./,$env{$envkey});
1135: if ($tstart && $tstart>$then) { $is_cc = 0; }
1136: if ($tend && $tend <$then) { $is_cc = 0; }
1137: }
1138: }
1139: }
1140: return $is_cc;
1141: }
1142:
1.108 raeburn 1143: sub courselink {
1.152 raeburn 1144: my ($dcdom,$rowtype,$selecttype) = @_;
1.109 raeburn 1145: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1146: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1147: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.173 albertel 1148: $dcdom,$dcdom,undef);
1.138 raeburn 1149: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1150: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1151: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1152: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1153: return $courseform.$hiddenitems;
1.109 raeburn 1154: }
1155:
1156: sub coursepick_jscript {
1.184 raeburn 1157: my %lt = &Apache::lonlocal::texthash(
1158: plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
1159: youc => 'You can only use this screen to select courses in the current domain.',
1160: );
1.104 raeburn 1161: my $verify_script = <<"END";
1.179 raeburn 1162: <script type="text/javascript">
1.108 raeburn 1163: function verifyCoursePick(caller) {
1164: var numbutton = getIndex(caller)
1.112 raeburn 1165: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1166: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1167: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1168: if (pickedCourse != '') {
1.108 raeburn 1169: if (numbutton != -1) {
1170: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1171: document.rolechoice.elements[numbutton+1].name = courseTarget
1172: document.rolechoice.submit()
1173: }
1.104 raeburn 1174: }
1175: else {
1.184 raeburn 1176: alert("$lt{'plsu'}");
1.104 raeburn 1177: }
1178: }
1179: else {
1.184 raeburn 1180: alert("$lt{'youc'}")
1.104 raeburn 1181: }
1182: }
1.109 raeburn 1183: function getIndex(caller) {
1.108 raeburn 1184: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1185: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1186: return i;
1187: }
1188: }
1189: return -1;
1190: }
1.104 raeburn 1191: </script>
1192: END
1.109 raeburn 1193: return $verify_script;
1.104 raeburn 1194: }
1195:
1.113 raeburn 1196: sub display_cc_role {
1197: my $rolekey = shift;
1198: my $roletext;
1.118 albertel 1199: my $advanced = $env{'user.adv'};
1200: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1201: unless ($rolekey =~/^error\:/) {
1.171 albertel 1202: if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1.113 raeburn 1203: my $tcourseid = $1.'_'.$2;
1204: my $trolecode = 'cc./'.$1.'/'.$2;
1205: my $twhere;
1.152 raeburn 1206: my $ttype;
1.113 raeburn 1207: my $tbg='#77FF77';
1208: my $tfont='#003300';
1209: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1210: if (%newhash) {
1211: $twhere=$newhash{'description'}.
1212: ' <font size="-2">'.
1213: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
1214: '</font>';
1.153 raeburn 1215: $ttype = $newhash{'type'};
1.113 raeburn 1216: } else {
1217: $twhere=&mt('Currently not available');
1.118 albertel 1218: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1219: }
1.153 raeburn 1220: my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1.113 raeburn 1221: $twhere.="<br />".&mt('Domain').":".$1;
1.152 raeburn 1222: $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
1.104 raeburn 1223: }
1224: }
1.152 raeburn 1225: return ($roletext);
1.104 raeburn 1226: }
1227:
1.108 raeburn 1228: sub allcourses_row {
1.138 raeburn 1229: my ($dcdom,$rowtype) = @_;
1.132 albertel 1230: my $output = '<tr bgcolor="#77FF77">'.
1.152 raeburn 1231: ' <td colspan="5">';
1.173 albertel 1232: my $selectlink = &courselink($dcdom,$rowtype);
1233: my $ccrole = &Apache::lonnet::plaintext('cc');
1.177 www 1234: $output.= '<span class="LC_rolesinfo">'.
1235: &mt('[_1]: [_2] from domain [_3]',$ccrole,$selectlink,$dcdom).
1.182 www 1236: '</span><br /></tr>'."\n";
1237: return $output;
1238: }
1239:
1240: sub allcoauthors_row {
1241: my ($dcdom,$rowtype) = @_;
1242: my $output = '<tr bgcolor="#77FF77">'.
1243: ' <td colspan="5">';
1244: my $carole = &Apache::lonnet::plaintext('ca');
1245: my $inputlink='<input type="text" size="10" name="adhoccauname'.$rowtype.'.'.$dcdom.'" />';
1246: my $gobutton='<input type="submit" name="adhocca./'.$dcdom.'" value="'.&mt('Go').'" />';
1247: $output.= '<span class="LC_rolesinfo">'.
1248: &mt('[_1]: [_2] in domain [_3] [_4]',$carole,$inputlink,$dcdom,$gobutton).
1.177 www 1249: '</span><br /></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1.108 raeburn 1250: return $output;
1251: }
1252:
1.104 raeburn 1253: sub recent_filename {
1254: my $area=shift;
1.149 www 1255: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1256: }
1257:
1.106 raeburn 1258: sub set_privileges {
1.182 www 1259: # role can be cc or ca
1260: my ($dcdom,$pickedcourse,$role) = @_;
1.106 raeburn 1261: my $area = '/'.$dcdom.'/'.$pickedcourse;
1262: my $spec = $role.'.'.$area;
1.168 albertel 1263: my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
1264: $env{'user.domain'},
1265: $env{'user.name'});
1.106 raeburn 1266: my %ccrole = ();
1267: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.154 albertel 1268: my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1.186 raeburn 1269: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.184 raeburn 1270:
1.118 albertel 1271: &Apache::lonnet::log($env{'user.domain'},
1272: $env{'user.name'},
1273: $env{'user.home'},
1.106 raeburn 1274: "Role ".$role);
1275: &Apache::lonnet::appenv(
1.186 raeburn 1276: {'request.role' => $spec,
1.106 raeburn 1277: 'request.role.domain' => $dcdom,
1.186 raeburn 1278: 'request.course.sec' => ''});
1.106 raeburn 1279: my $tadv=0;
1280: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 1281: &Apache::lonnet::appenv({'request.role.adv' => $tadv});
1.106 raeburn 1282: }
1283:
1.139 raeburn 1284: sub courseloadpage {
1285: my ($courseid) = @_;
1286: my $startpage;
1.144 albertel 1287: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1288: [$courseid.':courseinit']);
1.139 raeburn 1289: my ($tmp) = %entry_settings;
1.144 albertel 1290: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1291: $startpage = $entry_settings{$courseid.':courseinit'};
1292: }
1293: if ($startpage eq '') {
1294: if (exists($env{'environment.course_init_display'})) {
1295: $startpage = $env{'environment.course_init_display'};
1296: }
1297: }
1298: return $startpage;
1299: }
1300:
1.191 ! raeburn 1301: sub check_autoenroll {
! 1302: my ($dom) = @_;
! 1303: my $run_enroll = 0;
! 1304: my $settings;
! 1305: my %domconfig =
! 1306: &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
! 1307: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
! 1308: $settings = $domconfig{'autoenroll'};
! 1309: if ($settings->{'run'} eq '1') {
! 1310: $run_enroll = 1;
! 1311: }
! 1312: } else {
! 1313: $run_enroll = &localenroll::run($dom);
! 1314: }
! 1315: return $run_enroll;
! 1316: }
! 1317:
! 1318:
1.1 harris41 1319: 1;
1320: __END__
1.32 harris41 1321:
1322: =head1 NAME
1323:
1324: Apache::lonroles - User Roles Screen
1325:
1326: =head1 SYNOPSIS
1327:
1328: Invoked by /etc/httpd/conf/srm.conf:
1329:
1330: <Location /adm/roles>
1331: PerlAccessHandler Apache::lonacc
1332: SetHandler perl-script
1333: PerlHandler Apache::lonroles
1334: ErrorDocument 403 /adm/login
1335: ErrorDocument 500 /adm/errorhandler
1336: </Location>
1.64 bowersj2 1337:
1338: =head1 OVERVIEW
1339:
1340: =head2 Choosing Roles
1341:
1342: C<lonroles> is a handler that allows a user to switch roles in
1343: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1344: default role that a user has before selecting a role, as widely as
1345: possible, but certain handlers for example need specification which
1346: course they should act on, etc. Both in this scenario, and when the
1347: handler determines via C<lonnet>'s C<&allowed> function that a certain
1348: action is not allowed, C<lonroles> is used as error handler. This
1349: allows the user to select another role which may have permission to do
1350: what they were trying to do. C<lonroles> can also be accessed via the
1351: B<CRS> button in the Remote Control.
1352:
1353: =begin latex
1354:
1355: \begin{figure}
1356: \begin{center}
1357: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1358: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1359: \end{center}
1360: \end{figure}
1361:
1362: =end latex
1363:
1364: =head2 Role Initialization
1365:
1366: 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 1367:
1368: =head1 INTRODUCTION
1369:
1370: This module enables a user to select what role he wishes to
1371: operate under (instructor, student, teaching assistant, course
1372: coordinator, etc). These roles are pre-established by the actions
1373: of upper-level users.
1374:
1375: This is part of the LearningOnline Network with CAPA project
1376: described at http://www.lon-capa.org.
1377:
1378: =head1 HANDLER SUBROUTINE
1379:
1380: This routine is called by Apache and mod_perl.
1381:
1382: =over 4
1383:
1384: =item *
1385:
1386: Roles Initialization (yes/no)
1387:
1388: =item *
1389:
1390: Get Error Message from Environment
1391:
1392: =item *
1393:
1394: Who is this?
1395:
1396: =item *
1397:
1398: Generate Page Output
1399:
1400: =item *
1401:
1402: Choice or no choice
1403:
1404: =item *
1405:
1406: Table
1407:
1408: =item *
1409:
1410: Privileges
1411:
1412: =back
1413:
1414: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>