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