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