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