Annotation of loncom/auth/lonroles.pm, revision 1.267
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.267 ! bisitz 4: # $Id: lonroles.pm,v 1.266 2012/05/16 21:19:44 droeschl 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
1.246 droeschl 60: what they were trying to do.
1.210 jms 61:
62: =begin latex
63:
64: \begin{figure}
65: \begin{center}
66: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
67: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
68: \end{center}
69: \end{figure}
70:
71: =end latex
72:
73: =head2 Role Initialization
74:
75: 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.
76:
77: =head1 INTRODUCTION
78:
79: This module enables a user to select what role he wishes to
80: operate under (instructor, student, teaching assistant, course
81: coordinator, etc). These roles are pre-established by the actions
82: of upper-level users.
83:
84: This is part of the LearningOnline Network with CAPA project
85: described at http://www.lon-capa.org.
86:
87: =head1 HANDLER SUBROUTINE
88:
89: This routine is called by Apache and mod_perl.
90:
91: =over 4
92:
93: =item *
94:
95: Roles Initialization (yes/no)
96:
97: =item *
98:
99: Get Error Message from Environment
100:
101: =item *
102:
103: Who is this?
104:
105: =item *
106:
107: Generate Page Output
108:
109: =item *
110:
111: Choice or no choice
112:
113: =item *
114:
115: Table
116:
117: =item *
118:
119: Privileges
120:
121: =back
122:
123: =cut
124:
125:
1.1 harris41 126: package Apache::lonroles;
127:
128: use strict;
1.118 albertel 129: use Apache::lonnet;
1.7 www 130: use Apache::lonuserstate();
1.1 harris41 131: use Apache::Constants qw(:common);
1.2 www 132: use Apache::File();
1.26 www 133: use Apache::lonmenu;
1.29 albertel 134: use Apache::loncommon;
1.104 raeburn 135: use Apache::lonhtmlcommon;
1.57 www 136: use Apache::lonannounce;
1.72 www 137: use Apache::lonlocal;
1.151 www 138: use Apache::lonpageflip();
1.167 albertel 139: use Apache::lonnavdisplay();
1.241 raeburn 140: use Apache::loncoursequeueadmin;
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.245 droeschl 147: my ($r,$title,$url,$msg) = @_;
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;
1.228 bisitz 152:
153: # Breadcrumbs
154: my $brcrum = [{'href' => $url,
155: 'text' => 'Switching Role'},];
1.147 albertel 156: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
1.228 bisitz 157: {'redirect' => [1,$url],
158: 'bread_crumbs' => $brcrum,});
1.147 albertel 159: my $end_page = &Apache::loncommon::end_page();
160:
1.92 www 161: # Note to style police:
162: # This must only replace the spaces, nothing else, or it bombs elsewhere.
163: $url=~s/ /\%20/g;
1.93 albertel 164: $r->print(<<ENDREDIR);
1.147 albertel 165: $start_page
1.222 bisitz 166: <p>$msg</p>
1.147 albertel 167: $end_page
1.62 matthew 168: ENDREDIR
169: return;
170: }
171:
1.150 www 172: sub error_page {
173: my ($r,$error,$dest)=@_;
174: &Apache::loncommon::content_type($r,'text/html');
175: &Apache::loncommon::no_cache($r);
176: $r->send_http_header;
177: return OK if $r->header_only;
1.228 bisitz 178: # Breadcrumbs
179: my $brcrum = [{'href' => $dest,
180: 'text' => 'Problems during Course Initialization'},];
181: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
182: undef,
183: {'bread_crumbs' => $brcrum,})
184: );
185: $r->print(
1.225 bisitz 186: '<script type="text/javascript">'.
187: '// <![CDATA['.
188: &Apache::lonmenu::rawconfig().
189: '// ]]>'.
190: '</script>'.
191: '<p class="LC_error">'.&mt('The following problems occurred:').
1.228 bisitz 192: '<br />'.
1.150 www 193: $error.
1.228 bisitz 194: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
195: );
196: $r->print(&Apache::loncommon::end_page());
1.150 www 197: }
198:
1.1 harris41 199: sub handler {
1.10 www 200:
1.1 harris41 201: my $r = shift;
202:
1.6 www 203: my $now=time;
1.118 albertel 204: my $then=$env{'user.login.time'};
1.226 raeburn 205: my $refresh=$env{'user.refresh.time'};
1.260 raeburn 206: my $update=$env{'user.update.time'};
1.226 raeburn 207: if (!$refresh) {
208: $refresh = $then;
209: }
1.260 raeburn 210: if (!$update) {
211: $update = $then;
212: }
213:
214: # -------------------------------------------------------- Check for new roles
215: my $updateresult;
216: if ($env{'form.doupdate'}) {
217: my $show_course=&Apache::loncommon::show_course();
218: my $checkingtxt;
219: if ($show_course) {
220: $checkingtxt = &mt('Checking for new courses ...');
221: } else {
222: $checkingtxt = &mt('Checking for new roles ...');
223: }
1.264 raeburn 224: $updateresult = '<span class="LC_info">'.$checkingtxt.'</span>';
1.260 raeburn 225: $updateresult .= &update_session_roles();
226: &Apache::lonnet::appenv({'user.update.time' => $now});
227: $update = $now;
228: }
229:
1.6 www 230: my $envkey;
1.107 raeburn 231: my %dcroles = ();
1.260 raeburn 232: my $numdc = &check_fordc(\%dcroles,$update,$then);
1.148 albertel 233: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.255 raeburn 234: my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
1.10 www 235:
1.6 www 236: # ================================================================== Roles Init
1.118 albertel 237: if ($env{'form.selectrole'}) {
1.188 www 238:
239: my $locknum=&Apache::lonnet::get_locks();
240: if ($locknum) { return 409; }
241:
1.134 www 242: if ($env{'form.newrole'}) {
243: $env{'form.'.$env{'form.newrole'}}=1;
244: }
1.118 albertel 245: if ($env{'request.course.id'}) {
1.185 raeburn 246: # Check if user is CC trying to select a course role
247: if ($env{'form.switchrole'}) {
1.252 raeburn 248: my $switch_is_active;
249: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
250: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
251: if (!$end || $end > $now) {
1.260 raeburn 252: if (!$start || $start < $update) {
1.252 raeburn 253: $switch_is_active = 1;
254: }
255: }
256: }
257: unless ($switch_is_active) {
1.260 raeburn 258: &adhoc_course_role($refresh,$update,$then);
1.185 raeburn 259: }
260: }
1.118 albertel 261: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 262: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 263: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 264: }
1.186 raeburn 265: &Apache::lonnet::appenv({"request.course.id" => '',
266: "request.course.fn" => '',
267: "request.course.uri" => '',
268: "request.course.sec" => '',
269: "request.role" => 'cm',
270: "request.role.adv" => $env{'user.adv'},
271: "request.role.domain" => $env{'user.domain'}});
1.182 www 272: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 273: if ($numdc > 0) {
1.118 albertel 274: foreach my $envkey (keys %env) {
1.240 raeburn 275: # Is this an ad-hoc Coordinator role?
276: if (my ($ccrole,$domain,$coursenum) =
277: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 278: if ($dcroles{$domain}) {
1.218 raeburn 279: &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
1.260 raeburn 280: $update,$refresh,$now,$ccrole);
1.182 www 281: }
282: last;
283: }
1.193 raeburn 284: # Is this an ad-hoc CA-role?
1.183 www 285: if (my ($domain,$user) =
286: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 287: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
288: delete($env{$envkey});
289: $env{'form.au./'.$domain.'/'} = 1;
290: my ($server_status,$home) = &check_author_homeserver($user,$domain);
291: if ($server_status eq 'switchserver') {
292: my $trolecode = 'au./'.$domain.'/';
1.248 raeburn 293: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 294: $r->internal_redirect($switchserver);
295: }
296: last;
297: }
298: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
299: if (((($castart) && ($castart < $now)) || !$castart) &&
300: ((!$caend) || (($caend) && ($caend > $now)))) {
301: my ($server_status,$home) = &check_author_homeserver($user,$domain);
302: if ($server_status eq 'switchserver') {
303: my $trolecode = 'ca./'.$domain.'/'.$user;
1.248 raeburn 304: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 305: $r->internal_redirect($switchserver);
306: }
307: last;
308: }
309: }
310: # Check if author blocked ca-access
1.190 www 311: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
312: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 313: delete($env{$envkey});
314: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
315: last;
1.190 www 316: }
1.193 raeburn 317: if ($dcroles{$domain}) {
318: my ($server_status,$home) = &check_author_homeserver($user,$domain);
319: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.260 raeburn 320: &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
1.230 raeburn 321: $refresh,$now,'ca');
1.193 raeburn 322: if ($server_status eq 'switchserver') {
323: my $trolecode = 'ca./'.$domain.'/'.$user;
324: my $switchserver = '/adm/switchserver?'
1.248 raeburn 325: .'otherserver='.$home.'&role='.$trolecode;
1.193 raeburn 326: $r->internal_redirect($switchserver);
327: }
328: } else {
329: delete($env{$envkey});
330: }
1.183 www 331: } else {
332: delete($env{$envkey});
1.182 www 333: }
334: last;
335: }
1.107 raeburn 336: }
337: }
338:
1.118 albertel 339: foreach $envkey (keys %env) {
1.40 matthew 340: next if ($envkey!~/^user\.role\./);
1.102 raeburn 341: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.260 raeburn 342: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.218 raeburn 343: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 344: if ($env{'form.'.$trolecode}) {
1.55 albertel 345: if ($tstatus eq 'is') {
346: $where=~s/^\///;
347: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.255 raeburn 348: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
349: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
350: my @ids = &Apache::lonnet::current_machine_ids();
351: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
352: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1.256 raeburn 353: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
1.255 raeburn 354: my ($switchserver,$switchwarning) =
355: &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
1.256 raeburn 356: if ($switchwarning ne '' || $switchserver ne '') {
357: &Apache::loncommon::content_type($r,'text/html');
358: &Apache::loncommon::no_cache($r);
359: $r->send_http_header;
360: my $end_page=&Apache::loncommon::end_page();
361: $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
362: '<p class="LC_warning">');
363: if ($switchwarning) {
364: $r->print($switchwarning.'<br /><a href="/adm/roles">');
365: if (&Apache::loncommon::show_course()) {
366: $r->print(&mt('Display courses'));
367: } else {
368: $r->print(&mt('Display roles'));
369: }
370: $r->print('</a>');
371: } elsif ($switchserver) {
372: $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
373: '<br />'.
374: '<a href="/adm/switchserver?'.$switchserver.'">'.
375: &mt('Switch Server').
376: '</a>');
1.255 raeburn 377: }
1.256 raeburn 378: $r->print('</p>'.&Apache::loncommon::end_page());
379: return OK;
1.255 raeburn 380: }
381: }
382: }
383: }
1.137 raeburn 384: # check for course groups
385: my %coursegroups = &Apache::lonnet::get_active_groups(
386: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
387: my $cgrps = join(':',keys(%coursegroups));
388:
1.111 albertel 389: # store role if recent_role list being kept
1.118 albertel 390: if ($env{'environment.recentroles'}) {
1.158 albertel 391: my %frozen_roles =
392: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 393: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 394: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 395: }
396:
397:
1.53 www 398: # check for keyed access
1.55 albertel 399: if (($role eq 'st') &&
1.118 albertel 400: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 401: # who is key authority?
402: my $authdom=$cdom;
403: my $authnum=$cnum;
1.118 albertel 404: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 405: ($authnum,$authdom)=
1.172 albertel 406: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 407: }
408: # check with key authority
409: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 410: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 411: $authdom,$authnum)) {
1.53 www 412: # there is no valid key
1.118 albertel 413: if ($env{'form.newkey'}) {
1.53 www 414: # student attempts to register a new key
1.89 www 415: &Apache::loncommon::content_type($r,'text/html');
416: &Apache::loncommon::no_cache($r);
417: $r->send_http_header;
418: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 419: my $start_page=&Apache::loncommon::start_page
1.89 www 420: ('Verifying Access Key to Unlock this Course');
1.147 albertel 421: my $end_page=&Apache::loncommon::end_page();
1.90 www 422: my $buttontext=&mt('Enter Course');
423: my $message=&mt('Successfully registered key');
424: my $assignresult=
425: &Apache::lonnet::assign_access_key(
1.118 albertel 426: $env{'form.newkey'},
1.90 www 427: $authdom,$authnum,
1.91 www 428: $cdom,$cnum,
1.118 albertel 429: $env{'user.domain'},
430: $env{'user.name'},
1.204 bisitz 431: &mt('Assigned from [_1] at [_2] for [_3]'
432: ,$ENV{'REMOTE_ADDR'}
433: ,&Apache::lonlocal::locallocaltime()
434: ,$trolecode)
435: );
1.90 www 436: unless ($assignresult eq 'ok') {
437: $assignresult=~s/^error\:\s*//;
438: $message=&mt($assignresult).
439: '<br /><a href="/adm/logout">'.
1.89 www 440: &mt('Logout').'</a>';
1.90 www 441: $buttontext=&mt('Re-Enter Key');
442: }
1.89 www 443: $r->print(<<ENDENTEREDKEY);
1.147 albertel 444: $start_page
1.179 raeburn 445: <script type="text/javascript">
1.225 bisitz 446: // <![CDATA[
1.89 www 447: $swinfo
1.225 bisitz 448: // ]]>
1.89 www 449: </script>
1.225 bisitz 450: <form action="" method="post">
1.89 www 451: <input type="hidden" name="selectrole" value="1" />
452: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 453: <span class="LC_fontsize_large">$message</span><br />
1.89 www 454: <input type="submit" value="$buttontext" />
455: </form>
1.147 albertel 456: $end_page
1.89 www 457: ENDENTEREDKEY
458: return OK;
1.55 albertel 459: } else {
1.53 www 460: # print form to enter a new key
1.73 www 461: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 462: &Apache::loncommon::no_cache($r);
463: $r->send_http_header;
464: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 465: my $start_page=&Apache::loncommon::start_page
1.55 albertel 466: ('Enter Access Key to Unlock this Course');
1.147 albertel 467: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 468: $r->print(<<ENDENTERKEY);
1.147 albertel 469: $start_page
1.179 raeburn 470: <script type="text/javascript">
1.225 bisitz 471: // <![CDATA[
1.53 www 472: $swinfo
1.225 bisitz 473: // ]]>
1.53 www 474: </script>
1.225 bisitz 475: <form action="" method="post">
1.89 www 476: <input type="hidden" name="selectrole" value="1" />
477: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 478: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 479: <input type="submit" value="Enter key" />
480: </form>
1.147 albertel 481: $end_page
1.53 www 482: ENDENTERKEY
1.55 albertel 483: return OK;
484: }
485: }
486: }
1.118 albertel 487: &Apache::lonnet::log($env{'user.domain'},
488: $env{'user.name'},
489: $env{'user.home'},
1.87 www 490: "Role ".$trolecode);
1.101 albertel 491:
1.56 www 492: &Apache::lonnet::appenv(
1.186 raeburn 493: {'request.role' => $trolecode,
494: 'request.role.domain' => $cdom,
495: 'request.course.sec' => $csec,
496: 'request.course.groups' => $cgrps});
1.101 albertel 497: my $tadv=0;
1.62 matthew 498:
1.125 www 499: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 500: my $msg;
1.55 albertel 501: my ($furl,$ferr)=
502: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118 albertel 503: if (($env{'form.orgurl'}) &&
504: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
505: my $dest=$env{'form.orgurl'};
1.219 raeburn 506: if ($env{'form.symb'}) {
507: if ($dest =~ /\?/) {
508: $dest .= '&';
509: } else {
510: $dest .= '?'
511: }
512: $dest .= 'symb='.$env{'form.symb'};
513: }
1.117 albertel 514: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 515: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 516: if (($ferr) && ($tadv)) {
517: &error_page($r,$ferr,$dest);
518: } else {
1.255 raeburn 519: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
520: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
521: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
522: &update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
523: }
524: }
1.150 www 525: $r->internal_redirect($dest);
526: }
1.55 albertel 527: return OK;
528: } else {
1.155 albertel 529: if (!$env{'request.course.id'}) {
1.55 albertel 530: &Apache::lonnet::appenv(
1.186 raeburn 531: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 532: $furl='/adm/roles?tryagain=1';
1.221 bisitz 533: $msg='<p><span class="LC_error">'
534: .&mt('Could not initialize [_1] at this time.',
535: $env{'course.'.$cdom.'_'.$cnum.'.description'})
536: .'</span></p>'
537: .'<p>'.&mt('Please try again.').'</p>'
538: .'<p>'.$ferr.'</p>';
1.55 albertel 539: }
1.117 albertel 540: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 541: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 542:
1.150 www 543: if (($ferr) && ($tadv)) {
544: &error_page($r,$ferr,$furl);
545: } else {
546: # Check to see if the user is a CC entering a course
547: # for the first time
548: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
549: if (substr($courseid, 0, 1) eq '/') {
550: $courseid = substr($courseid, 1);
551: }
552: $courseid =~ s/\//_/;
1.240 raeburn 553: if ((($role eq 'cc') || ($role eq 'co'))
554: && ($env{'course.' . $courseid .'.course.helper.not.run'})) {
1.150 www 555: $furl = "/adm/helper/course.initialization.helper";
556: # Send the user to the course they selected
557: } elsif ($env{'request.course.id'}) {
1.185 raeburn 558: if ($env{'form.destinationurl'}) {
559: my $dest = $env{'form.destinationurl'};
1.203 raeburn 560: if ($env{'form.destsymb'} ne '') {
561: my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
562: $dest .= '?symb='.$esc_symb;
563: }
1.245 droeschl 564: &redirect_user($r, &mt('Entering [_1]',
565: $env{'course.'.$courseid.'.description'}),
566: $dest, $msg);
1.185 raeburn 567: return OK;
568: }
1.150 www 569: if (&Apache::lonnet::allowed('whn',
570: $env{'request.course.id'})
571: || &Apache::lonnet::allowed('whn',
572: $env{'request.course.id'}.'/'
573: .$env{'request.course.sec'})
574: ) {
575: my $startpage = &courseloadpage($courseid);
576: unless ($startpage eq 'firstres') {
1.204 bisitz 577: $msg = &mt('Entering [_1] ...',
1.162 albertel 578: $env{'course.'.$courseid.'.description'});
1.245 droeschl 579: &redirect_user($r, &mt('New in course'),
580: '/adm/whatsnew?refpage=start', $msg);
1.150 www 581: return OK;
582: }
583: }
584: }
1.151 www 585: # Are we allowed to look at the first resource?
1.169 albertel 586: if ($furl !~ m|^/adm/|) {
1.151 www 587: # Guess not ...
588: $furl=&Apache::lonpageflip::first_accessible_resource();
589: }
1.162 albertel 590: $msg = &mt('Entering [_1] ...',
591: $env{'course.'.$courseid.'.description'});
1.245 droeschl 592: &redirect_user($r, &mt('Entering [_1]',
593: $env{'course.'.$courseid.'.description'}),
594: $furl, $msg);
1.58 bowersj2 595: }
1.124 albertel 596: return OK;
1.55 albertel 597: }
598: }
1.62 matthew 599: #
600: # Send the user to the construction space they selected
1.125 www 601: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 602: my $redirect_url = '/priv/';
603: if ($role eq 'au') {
1.262 www 604: $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
1.62 matthew 605: } else {
1.263 www 606: $redirect_url .= $where;
1.62 matthew 607: }
608: $redirect_url .= '/';
1.78 sakharuk 609: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 610: $redirect_url);
611: return OK;
612: }
1.104 raeburn 613: if ($role eq 'dc') {
1.108 raeburn 614: my $redirect_url = '/adm/menu/';
615: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 616: $redirect_url);
1.108 raeburn 617: return OK;
1.104 raeburn 618: }
1.220 raeburn 619: if ($role eq 'sc') {
620: my $redirect_url = '/adm/grades?command=scantronupload';
621: &redirect_user($r,&mt('Loading Data Upload Page'),
622: $redirect_url);
623: return OK;
624: }
1.55 albertel 625: }
626: }
1.6 www 627: }
1.40 matthew 628: }
1.44 www 629:
1.10 www 630:
1.6 www 631: # =============================================================== No Roles Init
1.10 www 632:
1.73 www 633: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 634: &Apache::loncommon::no_cache($r);
1.10 www 635: $r->send_http_header;
636: return OK if $r->header_only;
637:
1.224 raeburn 638: my $crumbtext = 'User Roles';
639: my $pagetitle = 'My Roles';
640: my $recent = &mt('Recent Roles');
641: my $show_course=&Apache::loncommon::show_course();
642: if ($show_course) {
643: $crumbtext = 'Courses';
644: $pagetitle = 'My Courses';
645: $recent = &mt('Recent Courses');
646: }
647: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.52 www 648: my $swinfo=&Apache::lonmenu::rawconfig();
1.224 raeburn 649: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
1.134 www 650: my $standby=&mt('Role selected. Please stand by.');
1.135 albertel 651: $standby=~s/\n/\\n/g;
1.184 raeburn 652: 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 653:
1.10 www 654: $r->print(<<ENDHEADER);
1.147 albertel 655: $start_page
1.163 www 656: <br />
1.179 raeburn 657: <noscript>
658: $noscript
659: </noscript>
660: <script type="text/javascript">
1.225 bisitz 661: // <![CDATA[
1.26 www 662: $swinfo
663: window.focus();
1.134 www 664:
665: active=true;
666:
667: function enterrole (thisform,rolecode,buttonname) {
668: if (active) {
669: active=false;
670: document.title='$standby';
671: window.status='$standby';
672: thisform.newrole.value=rolecode;
673: thisform.submit();
674: } else {
675: alert('$standby');
1.260 raeburn 676: }
677: }
678:
679: function setToUpdate(thisform) {
680: thisform.doupdate.value='1';
681: thisform.selectrole.value='';
682: thisform.submit();
1.134 www 683: }
1.260 raeburn 684:
1.225 bisitz 685: // ]]>
1.26 www 686: </script>
1.10 www 687: ENDHEADER
1.6 www 688:
1.2 www 689: # ------------------------------------------ Get Error Message from Environment
690:
1.118 albertel 691: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
692: if ($env{'user.error.msg'}) {
1.55 albertel 693: $r->log_reason(
1.118 albertel 694: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 695: }
1.1 harris41 696:
1.61 www 697: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 698:
1.118 albertel 699: my $advanced=$env{'user.adv'};
1.61 www 700: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 701: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 702: my $reinit=$env{'user.reinit'};
703: delete $env{'user.reinit'};
1.6 www 704:
1.2 www 705: # -------------------------------------------------------- Generate Page Output
1.6 www 706: # --------------------------------------------------------------- Error Header?
1.2 www 707: if ($error) {
1.187 bisitz 708: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 709: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
710: if ($priv ne '') {
1.187 bisitz 711: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 712: }
713: if ($fn ne '') {
1.187 bisitz 714: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 715: }
716: if ($msg ne '') {
1.187 bisitz 717: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 718: }
719: $r->print("</pre><hr />");
1.120 albertel 720: my $url=$fn;
721: my $last;
722: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
723: &GDBM_READER(),0640)) {
724: $last=$hash{'last_known'};
725: untie(%hash);
726: }
1.149 www 727: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 728:
729: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
730: &Apache::lonenc::check_encrypt($fn));
1.2 www 731: } else {
1.118 albertel 732: if ($env{'user.error.msg'}) {
1.209 raeburn 733: if ($reinit) {
734: $r->print(
735: '<h3><span class="LC_error">'.
1.234 raeburn 736: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 737: } else {
738: $r->print(
1.157 albertel 739: '<h3><span class="LC_error">'.
1.235 bisitz 740: &mt('You need to choose another user role or enter a specific course or community for this function.').
741: '</span></h3>');
1.209 raeburn 742: }
743: }
1.2 www 744: }
745: if ($nochoose) {
1.177 www 746: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
747: &mt('This action is currently not authorized.').'</span>'.
1.150 www 748: &Apache::loncommon::end_page());
749: return OK;
1.6 www 750: } else {
1.260 raeburn 751: $r->print($updateresult);
1.18 www 752: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
753: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 754: }
1.84 www 755: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 756: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
757: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 758: $r->print('<input type="hidden" name="newrole" value="" />');
1.6 www 759: }
1.259 raeburn 760: $r->rflush();
1.226 raeburn 761:
762: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
763: my ($countactive,$countfuture,$inrole,$possiblerole) =
1.260 raeburn 764: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
1.254 raeburn 765: \%futureroles,\%timezones,$loncaparev);
1.226 raeburn 766: $refresh = $now;
767: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.260 raeburn 768: my $updatebutton = &mt('Check for role changes');
769: my $show_course=&Apache::loncommon::show_course();
770: if ($show_course) {
771: $updatebutton = &mt('Check for new courses');
772: }
773: my $do_update;
774: unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) {
775: $do_update = '<input type="hidden" name="doupdate" value="" />'.
776: '<input type="button" name="update" value="'.
777: $updatebutton.'" onclick="javascript:setToUpdate(this.form)" />';
778: }
1.196 raeburn 779: if ($env{'user.adv'}) {
1.260 raeburn 780: my $showall = '<label><input type="checkbox" name="showall"';
781: if ($env{'form.showall'}) {
782: $showall .= ' checked="checked" ';
783: }
1.264 raeburn 784: $showall .= ' />'.&mt('Show all roles').'</label> '.
1.260 raeburn 785: '<input type="submit" value="'.&mt('Update display').'" />';
786: if ($do_update) {
787: $r->print('<div class="LC_left_float"><fieldset>'.
788: '<legend>'. &mt('Display').'</legend>'.
789: $showall.'</fieldset></div>'.
790: '<div class="LC_left_float"><fieldset><legend>'.
791: &mt('Changes?').'</legend>'.
792: $do_update.'</fieldset></div><br clear="all" />');
793: } else {
794: $r->print($showall);
795: }
1.196 raeburn 796: } else {
1.260 raeburn 797: $r->print('<p>'.$do_update.'</p>');
1.196 raeburn 798: if ($countactive > 0) {
1.241 raeburn 799: $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
1.196 raeburn 800: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 801: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 802: $r->print(
803: '<p>'
804: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
805: .' to view all [_4] LON-CAPA courses and communities.'
806: ,'<b>'
807: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
808: ,'</a></b>',$domdesc)
809: .'<br />'
1.235 bisitz 810: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 811: .' you may be able to enroll if self-enrollment is permitted.'
812: ,'<b>','</b>')
813: .'</p>'
814: );
1.196 raeburn 815: }
816: }
817:
1.84 www 818: # No active roles
819: if ($countactive==0) {
820: if ($inrole) {
1.234 raeburn 821: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
1.84 www 822: } else {
1.234 raeburn 823: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
1.84 www 824: }
1.191 raeburn 825: &findcourse_advice($r);
1.234 raeburn 826: &requestcourse_advice($r);
1.191 raeburn 827: $r->print('</form>');
828: if ($countfuture) {
829: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
830: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
831: $nochoose);
832: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
833: \%roletext);
834: my $tremark='';
1.212 bisitz 835: my $tbg;
1.191 raeburn 836: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 837: $tbg="LC_roles_selected";
1.204 bisitz 838: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 839: } else {
1.212 bisitz 840: $tbg="LC_roles_is";
1.191 raeburn 841: }
1.212 bisitz 842: $r->print(&Apache::loncommon::start_data_table_row()
843: .'<td class="'.$tbg.'"> </td>'
844: .'<td colspan="3">'
845: .&mt('No role specified')
846: .'</td>'
847: .'<td>'.$tremark.' </td>'
848: .&Apache::loncommon::end_data_table_row()
849: );
1.191 raeburn 850:
1.212 bisitz 851: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 852: }
853: $r->print(&Apache::loncommon::end_page());
1.84 www 854: return OK;
855: }
856: # ----------------------------------------------------------------------- Table
1.247 raeburn 857:
858: if ($numdc > 0) {
859: $r->print(&coursepick_jscript());
860: $r->print(&Apache::loncommon::coursebrowser_javascript().
861: &Apache::loncommon::authorbrowser_javascript());
862: }
863:
1.224 raeburn 864: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 865: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 866: }
1.229 raeburn 867: if ($env{'form.destinationurl'}) {
868: $r->print('<input type="hidden" name="destinationurl" value="'.
869: $env{'form.destinationurl'}.'" />');
870: if ($env{'form.destsymb'} ne '') {
871: $r->print('<input type="hidden" name="destsymb" value="'.
872: $env{'form.destsymb'}.'" />');
873: }
874: }
1.247 raeburn 875:
1.191 raeburn 876: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 877: if ($env{'environment.recentroles'}) {
1.111 albertel 878: my %recent_roles =
1.118 albertel 879: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 880: my $output='';
1.247 raeburn 881: foreach my $role (sort(keys(%recent_roles))) {
882: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 883: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 884: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 885: &Apache::loncommon::end_data_table_row();
1.249 raeburn 886: if ($roletext{'user.role.'.$role}->[1] ne '') {
887: $output .= &Apache::loncommon::continue_data_table_row().
888: $roletext{'user.role.'.$role}->[1].
889: &Apache::loncommon::end_data_table_row();
890: }
1.247 raeburn 891: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 892: && $dcroles{$1}) {
1.192 raeburn 893: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 894: }
1.113 raeburn 895: } elsif ($numdc > 0) {
1.247 raeburn 896: unless ($role =~/^error\:/) {
1.249 raeburn 897: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 898: if ($roletext) {
899: $output.= &Apache::loncommon::start_data_table_row().
900: $roletext.
901: &Apache::loncommon::end_data_table_row();
902: if ($role_text_end) {
903: $output .= &Apache::loncommon::continue_data_table_row().
904: $role_text_end.
905: &Apache::loncommon::end_data_table_row();
906: }
907: }
1.113 raeburn 908: }
1.247 raeburn 909: }
1.111 albertel 910: }
911: if ($output) {
1.212 bisitz 912: $r->print(&Apache::loncommon::start_data_table_empty_row()
913: .'<td align="center" colspan="5">'
1.224 raeburn 914: .$recent
1.212 bisitz 915: .'</td>'
916: .&Apache::loncommon::end_data_table_empty_row()
917: );
1.111 albertel 918: $r->print($output);
1.114 raeburn 919: $doheaders ++;
1.111 albertel 920: }
921: }
1.191 raeburn 922: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 923: if ($countactive > 1) {
924: my $tremark='';
1.212 bisitz 925: my $tbg;
1.202 raeburn 926: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 927: $tbg="LC_roles_selected";
1.204 bisitz 928: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 929: } else {
1.212 bisitz 930: $tbg="LC_roles_is";
1.202 raeburn 931: }
1.212 bisitz 932: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 933: unless ($nochoose) {
934: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 935: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 936: &mt('Select').'" name="cm" /></td>');
937: } else {
1.212 bisitz 938: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 939: }
940: }
1.212 bisitz 941: $r->print('<td colspan="3">'
942: .&mt('No role specified')
943: .'</td>'
944: .'<td>'.$tremark.' </td>'
945: .&Apache::loncommon::end_data_table_row()
946: );
1.202 raeburn 947: }
1.212 bisitz 948: $r->print(&Apache::loncommon::end_data_table());
1.4 www 949: unless ($nochoose) {
950: $r->print("</form>\n");
951: }
1.22 harris41 952: # ------------------------------------------------------------ Privileges Info
1.118 albertel 953: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 954: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 955: $r->print(&privileges_info());
1.4 www 956: }
1.267 ! bisitz 957: my $announcements = &Apache::lonnet::getannounce();
! 958: $r->print(
! 959: '<br />'.
! 960: '<h2>'.&mt('Announcements').'</h2>'.
! 961: $announcements
! 962: ) unless (!$announcements);
1.65 www 963: if ($advanced) {
1.201 raeburn 964: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 965: $r->print('<p><small><i>'
966: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
967: .'</i><br />'
968: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 969: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 970: .&mt('Course/Community Catalog')
1.225 bisitz 971: .'</a></small></p>');
1.65 www 972: }
1.147 albertel 973: $r->print(&Apache::loncommon::end_page());
1.1 harris41 974: return OK;
1.102 raeburn 975: }
976:
1.226 raeburn 977: sub gather_roles {
1.260 raeburn 978: my ($update,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
1.226 raeburn 979: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
980: my $advanced = $env{'user.adv'};
981: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 982: my @ids = &Apache::lonnet::current_machine_ids();
1.226 raeburn 983: foreach my $envkey (sort(keys(%env))) {
984: my $button = 1;
985: my $switchserver='';
1.254 raeburn 986: my $switchwarning;
1.226 raeburn 987: my ($role_text,$role_text_end,$sortkey);
988: if ($envkey=~/^user\.role\./) {
989: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 990: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 991: \$trolecode,\$tstatus,\$tstart,\$tend);
992: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
993: $tremark='';
994: $tpstart=' ';
995: $tpend=' ';
996: if ($env{'request.role'} eq $trolecode) {
997: $tstatus='selected';
998: }
999: my $tbg;
1000: if (($tstatus eq 'is')
1001: || ($tstatus eq 'selected')
1002: || ($tstatus eq 'future')
1003: || ($env{'form.showall'})) {
1.259 raeburn 1004: my $timezone = &role_timezone($where,$timezones);
1005: if ($tstart) {
1006: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1007: }
1008: if ($tend) {
1009: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1010: }
1.226 raeburn 1011: if ($tstatus eq 'is') {
1012: $tbg='LC_roles_is';
1013: $possiblerole=$trolecode;
1014: $countactive++;
1015: } elsif ($tstatus eq 'future') {
1016: $tbg='LC_roles_future';
1017: $button=0;
1018: $futureroles->{$trolecode} = $tstart.':'.$tend;
1019: $countfuture ++;
1020: } elsif ($tstatus eq 'expired') {
1021: $tbg='LC_roles_expired';
1022: $button=0;
1023: } elsif ($tstatus eq 'will_not') {
1024: $tbg='LC_roles_will_not';
1025: $tremark.=&mt('Expired after logout.').' ';
1026: } elsif ($tstatus eq 'selected') {
1027: $tbg='LC_roles_selected';
1028: $inrole=1;
1029: $countactive++;
1030: $tremark.=&mt('Currently selected.').' ';
1031: }
1032: my $trole;
1033: if ($role =~ /^cr\//) {
1034: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1035: if ($tremark) { $tremark.='<br />'; }
1.253 bisitz 1036: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1037: }
1038: $trole=Apache::lonnet::plaintext($role);
1039: my $ttype;
1040: my $twhere;
1041: my ($tdom,$trest,$tsection)=
1042: split(/\//,Apache::lonnet::declutter($where));
1043: # First, Co-Authorship roles
1044: if (($role eq 'ca') || ($role eq 'aa')) {
1045: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1046: my $allowed=0;
1047: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1048: if (!$allowed) {
1049: $button=0;
1.248 raeburn 1050: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1051: }
1052: #next if ($home eq 'no_host');
1053: $home = &Apache::lonnet::hostname($home);
1054: $ttype='Construction Space';
1055: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1056: ': '.$tdom.'<br />'.
1057: ' '.&mt('Server').': '.$home;
1058: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1059: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1060: $sortkey=$role."$trest:$tdom";
1061: } elsif ($role eq 'au') {
1062: # Authors
1063: my $home = &Apache::lonnet::homeserver
1064: ($env{'user.name'},$env{'user.domain'});
1065: my $allowed=0;
1066: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1067: if (!$allowed) {
1068: $button=0;
1.248 raeburn 1069: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1070: }
1071: #next if ($home eq 'no_host');
1072: $home = &Apache::lonnet::hostname($home);
1073: $ttype='Construction Space';
1074: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1075: ': '.$home;
1076: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1077: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1078: $sortkey=$role;
1079: } elsif ($trest) {
1080: my $tcourseid=$tdom.'_'.$trest;
1081: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1082: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1083: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1084: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1085: $twhere=$env{'course.'.$tcourseid.'.description'};
1086: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1087: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1088: unless ($twhere eq &mt('Currently not available')) {
1089: $twhere.=' <span class="LC_fontsize_small">'.
1090: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1091: '</span>';
1.254 raeburn 1092: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1093: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1094: if ($required ne '') {
1095: ($switchserver,$switchwarning) =
1096: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1097: if ($switchserver || $switchwarning) {
1098: $button = 0;
1099: }
1.254 raeburn 1100: }
1101: }
1.226 raeburn 1102: }
1103: } else {
1104: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1105: if (%newhash) {
1106: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1107: "\0".$envkey;
1.248 raeburn 1108: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1109: ' <span class="LC_fontsize_small">'.
1110: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1111: '</span>';
1.226 raeburn 1112: $ttype = $newhash{'type'};
1.243 raeburn 1113: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1114: my $home = $newhash{'home'};
1115: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1116: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1117: if ($required ne '') {
1118: ($switchserver,$switchwarning) =
1119: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1120: if ($switchserver || $switchwarning) {
1121: $button = 0;
1122: }
1.254 raeburn 1123: }
1124: }
1.226 raeburn 1125: } else {
1126: $twhere=&mt('Currently not available');
1127: $env{'course.'.$tcourseid.'.description'}=$twhere;
1128: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1129: $ttype = 'Unavailable';
1130: }
1131: }
1132: if ($tsection) {
1133: $twhere.='<br />'.&mt('Section').': '.$tsection;
1134: }
1135: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1136: } elsif ($tdom) {
1137: $ttype='Domain';
1138: $twhere=$tdom;
1139: $sortkey=$role.$twhere;
1140: } else {
1141: $ttype='System';
1142: $twhere=&mt('system wide');
1143: $sortkey=$role.$twhere;
1144: }
1145: ($role_text,$role_text_end) =
1146: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1147: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1148: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1149: $roletext->{$envkey}=[$role_text,$role_text_end];
1150: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1151: $sortrole->{$sortkey}=$envkey;
1152: $roleclass->{$envkey}=$ttype;
1153: }
1154: }
1155: }
1156: return ($countactive,$countfuture,$inrole,$possiblerole);
1157: }
1158:
1.215 raeburn 1159: sub role_timezone {
1160: my ($where,$timezones) = @_;
1161: my $timezone;
1162: if (ref($timezones) eq 'HASH') {
1163: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1164: my $cdom = $1;
1165: my $cnum = $2;
1166: if ($cdom && $cnum) {
1167: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1168: my $tz;
1169: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1170: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1171: } else {
1172: my %timehash =
1173: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1174: $tz = $timehash{'timezone'};
1175: }
1176: if ($tz eq '') {
1.215 raeburn 1177: if (!exists($timezones->{$cdom})) {
1178: my %domdefaults =
1179: &Apache::lonnet::get_domain_defaults($cdom);
1180: if ($domdefaults{'timezone_def'} eq '') {
1181: $timezones->{$cdom} = 'local';
1182: } else {
1183: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1184: }
1185: }
1186: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1187: } else {
1188: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1189: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1190: }
1191: }
1192: $timezone = $timezones->{$cdom.'_'.$cnum};
1193: }
1194: } else {
1195: my ($tdom) = ($where =~ m{^/($match_domain)});
1196: if ($tdom) {
1197: if (!exists($timezones->{$tdom})) {
1198: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1199: if ($domdefaults{'timezone_def'} eq '') {
1200: $timezones->{$tdom} = 'local';
1201: } else {
1202: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1203: }
1204: }
1205: $timezone = $timezones->{$tdom};
1206: }
1207: }
1208: if ($timezone eq 'local') {
1209: $timezone = undef;
1210: }
1211: }
1212: return $timezone;
1213: }
1214:
1.191 raeburn 1215: sub roletable_headers {
1216: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1217: my $doheaders;
1218: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1219: $r->print('<br />'
1220: .&Apache::loncommon::start_data_table()
1221: .&Apache::loncommon::start_data_table_header_row()
1222: );
1.191 raeburn 1223: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1224: $r->print('<th>'.&mt('User Role').'</th>'
1225: .'<th>'.&mt('Extent').'</th>'
1226: .'<th>'.&mt('Start').'</th>'
1227: .'<th>'.&mt('End').'</th>'
1228: .&Apache::loncommon::end_data_table_header_row()
1229: );
1.191 raeburn 1230: $doheaders=-1;
1231: my @roletypes = &roletypes();
1232: foreach my $type (@roletypes) {
1233: my $haverole=0;
1234: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1235: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1236: $haverole=1;
1237: }
1238: }
1239: if ($haverole) { $doheaders++; }
1240: }
1241: }
1242: return $doheaders;
1243: }
1244:
1245: sub roletypes {
1.237 raeburn 1246: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1.191 raeburn 1247: return @types;
1248: }
1249:
1250: sub print_rolerows {
1251: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1252: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1253: my @types = &roletypes();
1254: foreach my $type (@types) {
1255: my $output;
1256: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1257: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1258: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1259: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1260: $output.= &Apache::loncommon::start_data_table_row().
1261: $roletext->{$sortrole->{$which}}->[0].
1262: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1263: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1264: $output .= &Apache::loncommon::continue_data_table_row().
1265: $roletext->{$sortrole->{$which}}->[1].
1266: &Apache::loncommon::end_data_table_row();
1267: }
1.223 raeburn 1268: }
1.191 raeburn 1269: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1270: if (ref($dcroles) eq 'HASH') {
1271: if ($dcroles->{$1}) {
1.192 raeburn 1272: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1273: }
1274: }
1275: }
1276: }
1277: }
1278: }
1279: if ($output) {
1280: if ($doheaders > 0) {
1.212 bisitz 1281: $r->print(&Apache::loncommon::start_data_table_empty_row()
1282: .'<td align="center" colspan="5">'
1283: .&mt($type)
1284: .'</td>'
1285: .&Apache::loncommon::end_data_table_empty_row()
1286: );
1.191 raeburn 1287: }
1288: $r->print($output);
1289: }
1290: }
1291: }
1292: }
1293:
1294: sub findcourse_advice {
1295: my ($r) = @_;
1296: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1297: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1298: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1299: $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).'
1300: <ul>
1301: <li>'.&mt('The course has yet to be created.').'</li>
1302: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1303: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1304: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1305: <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>
1306: </ul>');
1307: } else {
1308: $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 />');
1309: }
1.235 bisitz 1310: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1.234 raeburn 1311: '<p>'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a>',$domdesc).'<br />');
1.241 raeburn 1312: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1313: &Apache::loncoursequeueadmin::queued_selfenrollment());
1.216 raeburn 1314: return;
1315: }
1316:
1.234 raeburn 1317: sub requestcourse_advice {
1318: my ($r) = @_;
1319: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1320: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1321: my (%can_request,%request_doms);
1322: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1323: if (keys(%request_doms) > 0) {
1324: my ($types,$typename) = &Apache::loncommon::course_types();
1325: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1326: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1327: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1328: my (@reqdoms,@reqtypes);
1329: foreach my $type (sort(keys(%request_doms))) {
1330: push(@reqtypes,$type);
1331: if (ref($request_doms{$type}) eq 'ARRAY') {
1332: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1333: $r->print(
1334: '<li>'
1335: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1336: '<i>',
1337: '</i>',
1338: '<b>'.$domstr.'</b>')
1339: .'</li>'
1340: );
1.234 raeburn 1341: foreach my $dom (@{$request_doms{$type}}) {
1342: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1343: push(@reqdoms,$dom);
1344: }
1345: }
1346: }
1347: }
1348: my @showtypes;
1349: foreach my $type (@{$types}) {
1350: if (grep(/^\Q$type\E$/,@reqtypes)) {
1351: push(@showtypes,$type);
1352: }
1353: }
1354: my $requrl = '/adm/requestcourse';
1355: if (@reqdoms == 1) {
1356: $requrl .= '?showdom='.$reqdoms[0];
1357: }
1358: if (@showtypes > 0) {
1359: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1360: }
1361: if (@reqdoms == 1 || @showtypes > 0) {
1362: $requrl .= '&state=crstype&action=new';
1363: }
1364: $r->print('</ul>'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','<a href="'.$requrl.'">','</a>').'</p>');
1365: }
1366: }
1367: return;
1368: }
1369:
1.175 albertel 1370: sub privileges_info {
1371: my ($which) = @_;
1372: my $output;
1373:
1374: $which ||= $env{'request.role'};
1375:
1376: foreach my $envkey (sort(keys(%env))) {
1377: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1378:
1379: my $where=$1;
1380: my $ttype;
1381: my $twhere;
1382: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1383: if ($trest) {
1384: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1385: $ttype='Construction Space';
1386: $twhere='User: '.$trest.', Domain: '.$tdom;
1387: } else {
1388: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1389: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1390: if ($tsec) {
1391: my $sec_type = 'Section';
1392: if (exists($env{"user.role.gr.$where"})) {
1393: $sec_type = 'Group';
1394: }
1395: $twhere.=' ('.$sec_type.': '.$tsec.')';
1396: }
1397: }
1398: } elsif ($tdom) {
1399: $ttype='Domain';
1400: $twhere=$tdom;
1401: } else {
1402: $ttype='System';
1403: $twhere='/';
1404: }
1.204 bisitz 1405: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1406: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1407: next if (!$priv);
1408:
1409: my ($prv,$restr)=split(/\&/,$priv);
1410: my $trestr='';
1411: if ($restr ne 'F') {
1412: $trestr.=' ('.
1413: join(', ',
1414: map { &Apache::lonnet::plaintext($_) }
1415: (split('',$restr))).') ';
1416: }
1417: $output .= "\n\t".
1418: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1419: }
1420: $output .= "\n".'</ul>';
1421: }
1422: return $output;
1423: }
1424:
1.110 raeburn 1425: sub build_roletext {
1.254 raeburn 1426: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1427: my ($roletext,$roletext_end);
1.132 albertel 1428: my $is_dc=($trolecode =~ m/^dc\./);
1429: my $rowspan=($is_dc) ? ''
1430: : ' rowspan="2" ';
1431:
1.110 raeburn 1432: unless ($nochoose) {
1.134 www 1433: my $buttonname=$trolecode;
1434: $buttonname=~s/\W//g;
1.110 raeburn 1435: if (!$button) {
1436: if ($switchserver) {
1.212 bisitz 1437: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1438: .'<a href="/adm/switchserver?'.$switchserver.'">'
1439: .&mt('Switch Server')
1440: .'</a></td>';
1.110 raeburn 1441: } else {
1.212 bisitz 1442: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1443: }
1.255 raeburn 1444: if ($switchwarning) {
1445: if ($tremark eq '') {
1446: $tremark = $switchwarning;
1447: } else {
1448: $tremark .= '<br />'.$switchwarning;
1449: }
1450: }
1.110 raeburn 1451: } elsif ($tstatus eq 'is') {
1.212 bisitz 1452: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1453: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1454: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1455: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1456: } elsif ($tryagain) {
1457: $roletext.=
1.212 bisitz 1458: '<td'.$rowspan.' class="'.$tbg.'">'.
1459: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1460: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1461: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1462: } elsif ($advanced) {
1463: $roletext.=
1.212 bisitz 1464: '<td'.$rowspan.' class="'.$tbg.'">'.
1465: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1466: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1467: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1468: } elsif ($reinit) {
1469: $roletext.=
1.212 bisitz 1470: '<td'.$rowspan.' class="'.$tbg.'">'.
1471: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1472: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1473: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1474: } else {
1.209 raeburn 1475: $roletext.=
1.212 bisitz 1476: '<td'.$rowspan.' class="'.$tbg.'">'.
1477: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1478: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1479: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1480: }
1481: }
1.165 albertel 1482: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1483: $tremark.=&Apache::lonannounce::showday(time,1,
1484: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1485: }
1.212 bisitz 1486: $roletext.='<td>'.$trole.'</td>'
1487: .'<td>'.$twhere.'</td>'
1488: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1489: .'<td>'.$tpend.'</td>';
1.132 albertel 1490: if (!$is_dc) {
1.223 raeburn 1491: $roletext_end = '<td colspan="4">'.
1492: $tremark.' '.
1493: '</td>';
1.132 albertel 1494: }
1.223 raeburn 1495: return ($roletext,$roletext_end);
1.110 raeburn 1496: }
1497:
1.202 raeburn 1498: sub check_needs_switchserver {
1499: my ($possiblerole) = @_;
1500: my $needs_switchserver;
1501: my ($role,$where) = split(/\./,$possiblerole,2);
1502: my (undef,$tdom,$twho) = split(/\//,$where);
1503: my ($server_status,$home);
1504: if (($role eq 'ca') || ($role eq 'aa')) {
1505: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1506: } else {
1507: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1508: $env{'user.domain'});
1509: }
1510: if ($server_status eq 'switchserver') {
1511: $needs_switchserver = 1;
1512: }
1513: return $needs_switchserver;
1514: }
1515:
1.193 raeburn 1516: sub check_author_homeserver {
1.183 www 1517: my ($uname,$udom)=@_;
1.193 raeburn 1518: if (($uname eq '') || ($udom eq '')) {
1519: return ('fail','');
1520: }
1.183 www 1521: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1522: if (&Apache::lonnet::host_domain($home) ne $udom) {
1523: return ('fail',$home);
1524: }
1.183 www 1525: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1526: if (grep(/^\Q$home\E$/,@ids)) {
1527: return ('ok',$home);
1528: } else {
1529: return ('switchserver',$home);
1.183 www 1530: }
1531: }
1532:
1.104 raeburn 1533: sub check_fordc {
1.260 raeburn 1534: my ($dcroles,$update,$then) = @_;
1.104 raeburn 1535: my $numdc = 0;
1.118 albertel 1536: if ($env{'user.adv'}) {
1537: foreach my $envkey (sort keys %env) {
1.170 albertel 1538: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1539: my $dcdom = $1;
1540: my $livedc = 1;
1.118 albertel 1541: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1542: my $limit = $update;
1543: if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
1544: $limit = $then;
1545: }
1546: if ($tstart && $tstart>$limit) { $livedc = 0; }
1547: if ($tend && $tend <$limit) { $livedc = 0; }
1.104 raeburn 1548: if ($livedc) {
1549: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1550: $numdc++;
1.104 raeburn 1551: }
1552: }
1553: }
1554: }
1555: return $numdc;
1556: }
1557:
1.185 raeburn 1558: sub adhoc_course_role {
1.260 raeburn 1559: my ($refresh,$update,$then) = @_;
1.239 raeburn 1560: my ($cdom,$cnum,$crstype);
1.201 raeburn 1561: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1562: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1563: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1564: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1565: my $setprivs;
1.198 raeburn 1566: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1567: $setprivs = 1;
1568: } else {
1.198 raeburn 1569: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1570: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1571: ($end && $end<$update)) {
1.185 raeburn 1572: $setprivs = 1;
1573: }
1.232 raeburn 1574: }
1.185 raeburn 1575: if ($setprivs) {
1.198 raeburn 1576: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1577: my $role = $1;
1578: my $custom_role = $2;
1579: my $usec = $3;
1580: if ($role eq 'cr') {
1.199 raeburn 1581: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1582: $role .= $custom_role;
1583: } else {
1584: return;
1585: }
1586: }
1.208 raeburn 1587: my (%userroles,%newrole,%newgroups,%group_privs);
1588: my %cgroups =
1589: &Apache::lonnet::get_active_groups($env{'user.domain'},
1590: $env{'user.name'},$cdom,$cnum);
1591: foreach my $group (keys(%cgroups)) {
1592: $group_privs{$group} =
1593: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1594: }
1595: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1596: my $area = '/'.$cdom.'/'.$cnum;
1597: my $spec = $role.'.'.$area;
1598: if ($usec ne '') {
1599: $spec .= '/'.$usec;
1600: $area .= '/'.$usec;
1601: }
1602: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1603: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1604: my $adhocstart = $refresh-1;
1.185 raeburn 1605: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1606: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1607: }
1608: }
1609: }
1610: return;
1611: }
1612:
1613: sub check_forcc {
1.260 raeburn 1614: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1615: my ($is_cc,$ccrole);
1616: if ($crstype eq 'Community') {
1617: $ccrole = 'co';
1618: } else {
1619: $ccrole = 'cc';
1620: }
1.266 droeschl 1621: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1622: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1623: if (defined($env{$envkey})) {
1624: $is_cc = 1;
1625: my ($tstart,$tend)=split(/\./,$env{$envkey});
1626: my $limit = $update;
1627: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1628: $limit = $then;
1.185 raeburn 1629: }
1.266 droeschl 1630: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1631: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1632: }
1633: }
1634: return $is_cc;
1635: }
1636:
1.254 raeburn 1637: sub check_release_required {
1.255 raeburn 1638: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1639: my ($switchserver,$warning);
1.255 raeburn 1640: if ($required ne '') {
1641: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.257 raeburn 1642: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1643: if ($reqdmajor ne '' && $reqdminor ne '') {
1644: my $otherserver;
1645: if (($major eq '' && $minor eq '') ||
1646: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1647: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1648: my $switchlcrev =
1649: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1650: $userdomserver);
1.257 raeburn 1651: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1652: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1653: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1654: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1655: if ($cdom ne $env{'user.domain'}) {
1656: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1657: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1658: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1659: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1660: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1661: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1662: my $canhost =
1663: &Apache::lonnet::can_host_session($env{'user.domain'},
1664: $coursedomserver,
1665: $remoterev,
1666: $udomdefaults{'remotesessions'},
1667: $defdomdefaults{'hostedsessions'});
1668:
1669: if ($canhost) {
1670: $otherserver = $coursedomserver;
1671: } else {
1672: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
1673: }
1674: } else {
1675: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
1676: }
1677: } else {
1678: $otherserver = $userdomserver;
1679: }
1680: }
1681: if ($otherserver ne '') {
1682: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1683: }
1684: }
1685: }
1686: return ($switchserver,$warning);
1687: }
1688:
1.255 raeburn 1689: sub update_content_constraints {
1690: my ($cdom,$cnum,$chome,$cid) = @_;
1691: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1692: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1693: my %checkresponsetypes;
1694: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1695: my ($item,$name,$value) = split(/:/,$key);
1696: if ($item eq 'resourcetag') {
1697: if ($name eq 'responsetype') {
1698: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
1699: }
1700: }
1701: }
1702: my $navmap = Apache::lonnavmaps::navmap->new();
1703: if (defined($navmap)) {
1704: my %allresponses;
1705: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
1706: my %responses = $res->responseTypes();
1707: foreach my $key (keys(%responses)) {
1708: next unless(exists($checkresponsetypes{$key}));
1709: $allresponses{$key} += $responses{$key};
1710: }
1711: }
1712: foreach my $key (keys(%allresponses)) {
1713: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
1714: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
1715: ($reqdmajor,$reqdminor) = ($major,$minor);
1716: }
1717: }
1718: undef($navmap);
1719: }
1720: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
1721: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
1722: }
1723: return;
1724: }
1725:
1.108 raeburn 1726: sub courselink {
1.193 raeburn 1727: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1728: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1729: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1730: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1731: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1732: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1733: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1734: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1735: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1736: return $courseform.$hiddenitems;
1.109 raeburn 1737: }
1738:
1739: sub coursepick_jscript {
1.184 raeburn 1740: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1741: plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",
1.234 raeburn 1742: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1743: );
1.104 raeburn 1744: my $verify_script = <<"END";
1.179 raeburn 1745: <script type="text/javascript">
1.225 bisitz 1746: // <![CDATA[
1.108 raeburn 1747: function verifyCoursePick(caller) {
1748: var numbutton = getIndex(caller)
1.112 raeburn 1749: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1750: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1751: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1752: if (pickedCourse != '') {
1.108 raeburn 1753: if (numbutton != -1) {
1754: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1755: document.rolechoice.elements[numbutton+1].name = courseTarget
1756: document.rolechoice.submit()
1757: }
1.104 raeburn 1758: }
1759: else {
1.184 raeburn 1760: alert("$lt{'plsu'}");
1.104 raeburn 1761: }
1762: }
1763: else {
1.184 raeburn 1764: alert("$lt{'youc'}")
1.104 raeburn 1765: }
1766: }
1.109 raeburn 1767: function getIndex(caller) {
1.108 raeburn 1768: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1769: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1770: return i;
1771: }
1772: }
1773: return -1;
1774: }
1.225 bisitz 1775: // ]]>
1.104 raeburn 1776: </script>
1777: END
1.109 raeburn 1778: return $verify_script;
1.104 raeburn 1779: }
1780:
1.193 raeburn 1781: sub coauthorlink {
1782: my ($dcdom,$rowtype) = @_;
1783: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1784: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1785: return $coauthorform.$hiddenitems;
1786: }
1787:
1.113 raeburn 1788: sub display_cc_role {
1789: my $rolekey = shift;
1.223 raeburn 1790: my ($roletext,$roletext_end);
1.118 albertel 1791: my $advanced = $env{'user.adv'};
1792: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1793: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1794: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1795: my $ccrole = $1;
1.249 raeburn 1796: my $tdom = $2;
1797: my $trest = $3;
1798: my $tcourseid = $tdom.'_'.$trest;
1799: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1800: my $twhere;
1.152 raeburn 1801: my $ttype;
1.212 bisitz 1802: my $tbg='LC_roles_is';
1.113 raeburn 1803: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1804: if (%newhash) {
1805: $twhere=$newhash{'description'}.
1.261 bisitz 1806: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1807: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1808: '</span>';
1.153 raeburn 1809: $ttype = $newhash{'type'};
1.113 raeburn 1810: } else {
1811: $twhere=&mt('Currently not available');
1.118 albertel 1812: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1813: }
1.242 raeburn 1814: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1815: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1816: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1817: }
1818: }
1.223 raeburn 1819: return ($roletext,$roletext_end);
1.104 raeburn 1820: }
1821:
1.192 raeburn 1822: sub adhoc_roles_row {
1.138 raeburn 1823: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1824: my $output = &Apache::loncommon::continue_data_table_row()
1825: .' <td colspan="5">'
1826: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1827: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1828: .' ';
1.193 raeburn 1829: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1830: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1831: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1832: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1833: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1834: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1835: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1836: return $output;
1837: }
1838:
1.104 raeburn 1839: sub recent_filename {
1840: my $area=shift;
1.149 www 1841: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1842: }
1843:
1.139 raeburn 1844: sub courseloadpage {
1845: my ($courseid) = @_;
1846: my $startpage;
1.144 albertel 1847: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1848: [$courseid.':courseinit']);
1.139 raeburn 1849: my ($tmp) = %entry_settings;
1.144 albertel 1850: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1851: $startpage = $entry_settings{$courseid.':courseinit'};
1852: }
1853: if ($startpage eq '') {
1854: if (exists($env{'environment.course_init_display'})) {
1855: $startpage = $env{'environment.course_init_display'};
1856: }
1857: }
1858: return $startpage;
1859: }
1860:
1.260 raeburn 1861: sub update_session_roles {
1862: my $then=$env{'user.login.time'};
1863: my $refresh=$env{'user.refresh.time'};
1864: if (!$refresh) {
1865: $refresh = $then;
1866: }
1867: my $update = $env{'user.update.time'};
1868: if (!$update) {
1869: $update = $then;
1870: }
1871: my $now = time;
1872: my %roleshash =
1873: &Apache::lonnet::get_my_roles('','','userroles',
1874: ['active','future','previous'],
1875: undef,undef,1);
1876: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1877: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1878: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1879: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1880: @rolecodes);
1881: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1882: my %courseroles;
1883: foreach my $item (keys(%roleshash)) {
1884: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1885: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1886: my ($section,$group,@group_privs);
1887: if ($role =~ m{^gr/(\w*)$}) {
1888: $role = 'gr';
1889: my $priv = $1;
1890: next if ($tstart eq '-1');
1891: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1892: if ($priv ne '') {
1893: push(@group_privs,$priv);
1894: }
1895: }
1896: if ($remainder =~ /:/) {
1897: (my $additional_privs,$group) =
1898: ($remainder =~ /^([\w:]+):([^:]+)$/);
1899: if ($additional_privs ne '') {
1900: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1901: push(@group_privs,split(/:/,$additional_privs));
1902: @group_privs = sort(@group_privs);
1903: }
1904: }
1905: } else {
1906: $group = $remainder;
1907: }
1908: } else {
1909: $section = $remainder;
1910: }
1911: my $where = "/$udom/$uname";
1912: if ($section ne '') {
1913: $where .= "/$section";
1914: } elsif ($group ne '') {
1915: $where .= "/$group";
1916: }
1917: my $rolekey = "$role.$where";
1918: my $envkey = "user.role.$rolekey";
1919: $dbroles{$envkey} = 1;
1920: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
1921: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
1922: $currrole_expired = 1;
1923: }
1924: }
1925: if ($env{$envkey} eq '') {
1926: my $status_in_db =
1927: &curr_role_status($tstart,$tend,$refresh,$now);
1928: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
1929: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
1930: if ($status_in_db eq 'active') {
1931: if ($section eq '') {
1932: push(@newsec,'none');
1933: } else {
1934: push(@newsec,$section);
1935: }
1936: }
1937: } else {
1938: unless (grep(/^\Q$role\E$/,@changed_roles)) {
1939: push(@changed_roles,$role);
1940: }
1941: if ($status_in_db ne 'previous') {
1942: if ($role eq 'gr') {
1943: $newgroup{$rolekey} = $status_in_db;
1944: if ($status_in_db eq 'active') {
1945: unless (ref($courseroles{$udom}) eq 'HASH') {
1946: %{$courseroles{$udom}} =
1947: &Apache::lonnet::get_my_roles('','','userroles',
1948: ['active'],\@possroles,
1949: [$udom],1);
1950: }
1951: &Apache::lonnet::get_groups_roles($udom,$uname,
1952: $courseroles{$udom},
1953: \@rolecodes,\%groups_roles);
1954: }
1955: } else {
1956: $newrole{$rolekey} = $status_in_db;
1957: }
1958: }
1959: }
1960: } else {
1961: my ($currstart,$currend) = split(/\./,$env{$envkey});
1962: if ($role eq 'gr') {
1963: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
1964: $hasgroups = 1;
1965: }
1966: }
1967: if (($currstart ne $tstart) || ($currend ne $tend)) {
1968: my $status_in_env =
1969: &curr_role_status($currstart,$currend,$refresh,$update);
1970: my $status_in_db =
1971: &curr_role_status($tstart,$tend,$refresh,$now);
1972: if ($status_in_env ne $status_in_db) {
1973: if ($status_in_env eq 'active') {
1974: if ($role eq 'st') {
1975: if ($env{'request.role'} eq $rolekey) {
1976: my $switchsection;
1977: unless (ref($courseroles{$udom}) eq 'HASH') {
1978: %{$courseroles{$udom}} =
1979: &Apache::lonnet::get_my_roles('','','userroles',
1980: ['active'],
1981: \@possroles,[$udom],1);
1982: }
1983: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
1984: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
1985: $switchsection = 1;
1986: last;
1987: }
1988: }
1989: if ($switchsection) {
1990: if ($section eq '') {
1991: $oldsec = 'none';
1992: } else {
1993: $oldsec = $section;
1994: }
1995: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
1996: } else {
1997: $currrole_expired = 1;
1998: next;
1999: }
2000: }
2001: }
2002: unless ($rolekey eq $env{'request.role'}) {
2003: if ($role eq 'gr') {
2004: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2005: } else {
2006: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2007: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2008: }
2009: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2010: }
2011: } elsif ($status_in_db eq 'active') {
2012: if (($role eq 'st') &&
2013: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2014: if ($section eq '') {
2015: push(@newsec,'none');
2016: } else {
2017: push(@newsec,$section);
2018: }
2019: } elsif ($role eq 'gr') {
2020: unless (ref($courseroles{$udom}) eq 'HASH') {
2021: %{$courseroles{$udom}} =
2022: &Apache::lonnet::get_my_roles('','','userroles',
2023: ['active'],
2024: \@possroles,[$udom],1);
2025: }
2026: &Apache::lonnet::get_groups_roles($udom,$uname,
2027: $courseroles{$udom},
2028: \@rolecodes,\%groups_roles);
2029: }
2030: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2031: }
2032: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2033: push(@changed_roles,$role);
2034: }
2035: if ($role eq 'gr') {
2036: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2037: } else {
2038: $rolechange{$rolekey} = $status_in_db;
2039: }
2040: }
2041: } else {
2042: if ($role eq 'gr') {
2043: unless ($checkedgroup{$where}) {
2044: my $status_in_db =
2045: &curr_role_status($tstart,$tend,$refresh,$now);
2046: if ($tstart eq '-1') {
2047: $status_in_db = 'deleted';
2048: }
2049: unless (ref($courseroles{$udom}) eq 'HASH') {
2050: %{$courseroles{$udom}} =
2051: &Apache::lonnet::get_my_roles('','','userroles',
2052: ['active'],
2053: \@possroles,[$udom],1);
2054: }
2055: if (ref($courseroles{$udom}) eq 'HASH') {
2056: foreach my $item (keys(%{$courseroles{$udom}})) {
2057: next unless ($item =~ /^\Q$uname\E/);
2058: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2059: my $area = '/'.$cdom.'/'.$cnum;
2060: if ($crssec ne '') {
2061: $area .= '/'.$crssec;
2062: }
2063: my $crsrolekey = $crsrole.'.'.$area;
2064: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2065: $currprivs =~ s/^://;
2066: $currprivs =~ s/\&F$//;
2067: my @curr_grp_privs = split(/\&F:/,$currprivs);
2068: @curr_grp_privs = sort(@curr_grp_privs);
2069: my @diffs;
2070: if (@group_privs > 0 || @curr_grp_privs > 0) {
2071: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2072: }
2073: if (@diffs == 0) {
2074: last;
2075: } else {
2076: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2077: push(@rolecodes,'gr');
2078: }
2079: &gather_roleprivs(\%allroles,\%allgroups,
2080: \%userroles,$where,$role,
2081: $tstart,$tend,$status_in_db);
2082: if ($status_in_db eq 'active') {
2083: &Apache::lonnet::get_groups_roles($udom,$uname,
2084: $courseroles{$udom},
2085: \@rolecodes,\%groups_roles);
2086: }
2087: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2088: last;
2089: }
2090: }
2091: }
2092: $checkedgroup{$where} = 1;
2093: }
2094: } elsif ($role =~ /^cr/) {
2095: my $status_in_db =
2096: &curr_role_status($tstart,$tend,$refresh,$now);
2097: my ($rdummy,$rest) = split(/\//,$role,2);
2098: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
2099: my %currpriv;
2100: unless (exists($crprivs{$rest})) {
2101: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2102: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2103: if (&Apache::lonnet::hostname($homsvr) ne '') {
2104: my ($rdummy,$roledef)=
2105: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2106: $rdomain,$rauthor);
2107: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2108: my $i = 0;
2109: my @scopes = ('sys','dom','crs');
2110: my @privs = split(/\_/,$roledef);
2111: foreach my $priv (@privs) {
2112: my ($blank,@prv) = split(/:/,$priv);
2113: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2114: if (@prv) {
2115: $priv = ':'.join(':',sort(@prv));
2116: }
1.260 raeburn 2117: $crprivs{$rest}{$scopes[$i]} = $priv;
2118: $i++;
2119: }
2120: }
2121: }
2122: }
2123: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2124: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2125: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2126: if (keys(%crprivs)) {
2127: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2128: ($crprivs{$rest}{dom} ne $currpriv{dom})
2129: ||
2130: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2131: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2132: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2133: push(@changed_roles,$role);
2134: }
2135: my $status_in_env =
2136: &curr_role_status($currstart,$currend,$refresh,$update);
2137: if ($status_in_env eq 'active') {
2138: $customprivchg{$rolekey} = $status_in_env;
2139: }
2140: }
2141: }
2142: }
2143: }
2144: }
2145: }
2146: foreach my $envkey (keys(%env)) {
2147: next unless ($envkey =~ /^user\.role\./);
2148: next if ($dbroles{$envkey});
2149: next if ($envkey eq 'user.role.'.$env{'request.role'});
2150: my ($currstart,$currend) = split(/\./,$env{$envkey});
2151: my $status_in_env =
2152: &curr_role_status($currstart,$currend,$refresh,$update);
2153: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2154: my ($role,$rest)=split(/\./,$rolekey,2);
2155: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2156: if ($status_in_env eq 'active') {
2157: if ($role eq 'gr') {
2158: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2159: \@possroles);
2160: } else {
2161: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2162: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2163: }
2164: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2165: push(@changed_roles,$role);
2166: }
2167: $deletedroles{$rolekey} = 1;
2168: }
2169: }
2170: }
2171: if (($oldsec) && (@newsec > 0)) {
2172: if (@newsec > 1) {
2173: $msg = '<div class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</div>';
2174: } else {
2175: my $newrole = $env{'request.role'};
2176: if ($newsec[0] eq 'none') {
2177: $newrole =~ s{(/[^/])$}{};
2178: } elsif ($oldsec eq 'none') {
2179: $newrole .= '/'.$newsec[0];
2180: } else {
2181: $newrole =~ s{([^/]+)$}{$newsec[0]};
2182: }
2183: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2184: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2185: my %temp=('logout_'.$env{'request.course.id'} => time);
2186: &Apache::lonnet::put('email_status',\%temp);
2187: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2188: &Apache::lonnet::appenv({"request.course.id" => '',
2189: "request.course.fn" => '',
2190: "request.course.uri" => '',
2191: "request.course.sec" => '',
2192: "request.role" => 'cm',
2193: "request.role.adv" => $env{'user.adv'},
2194: "request.role.domain" => $env{'user.domain'}});
2195: my $rolename = &Apache::loncommon::plainname($curr_role);
2196: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2197: '<input type="hidden" name="newrole" value="" />'.
2198: '<input type="hidden" name="selectrole" value="1" />'.
2199: '<span class="LC_info">'.
2200: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2201: my $button = '<input type="button" name="sectionchanged" value="'.
2202: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2203: if ($newsec[0] eq 'none') {
2204: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2205: } else {
2206: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2207: }
2208: $msg .= '</form></p>';
2209: }
2210: } elsif ($currrole_expired) {
2211: $msg .= '<div class="LC_warning">';
2212: if (&Apache::loncommon::show_course()) {
2213: $msg .= &mt('Your role in the current course has expired.');
2214: } else {
2215: $msg .= &mt('Your current role has expired.');
2216: }
2217: $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</div>';
2218: }
2219: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2220: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2221: if (!@changed_roles) {
2222: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2223: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2224: } else {
1.264 raeburn 2225: $rolesmsg = &mt('No role changes');
1.260 raeburn 2226: }
2227: }
2228: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2229: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2230: }
2231: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2232: if (($msg ne '') || ($groupsmsg ne '')) {
2233: $msg .= '<ul>';
2234: if ($rolesmsg) {
2235: $msg .= '<li>'.$rolesmsg.'</li>';
2236: }
2237: if ($groupsmsg) {
2238: $msg .= '<li>'.$groupsmsg.'</li>';
2239: }
2240: $msg .= '</ul>';
2241: } else {
1.265 raeburn 2242: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br /><br />';
1.264 raeburn 2243: }
1.260 raeburn 2244: return $msg;
2245: }
2246: }
2247: my $changemsg;
2248: if (@changed_roles > 0) {
2249: if (keys(%newgroup) > 0) {
2250: my $groupmsg;
2251: foreach my $item (sort(keys(%newgroup))) {
2252: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
2253: $groupmsg .= '<li>'.
2254: &mt('[_1] with status: [_2].',
2255: $item,$newgroup{$item}).'</li>';
2256: }
2257: }
2258: if ($groupmsg) {
2259: $changemsg .= '<li>'.
2260: &mt('Courses with new groups').'</li>'.
2261: '<ul>'.$groupmsg.'</ul></li>';
2262: }
2263: }
2264: if (keys(%newrole) > 0) {
2265: $changemsg .= '<li>'.&mt('New roles').
2266: '<ul>';
2267: foreach my $item (sort(keys(%newrole))) {
2268: $changemsg .= '<li>'.
2269: &mt('[_1] with status: [_2].',
2270: $item,$newrole{$item}).'</li>';
2271: }
2272: $changemsg .= '</ul></li>';
2273: }
2274: if (keys(%customprivchg) > 0) {
2275: $changemsg .= '<li>'.
2276: &mt('Custom roles with privilege changes').
2277: '<ul>';
2278: foreach my $item (sort(keys(%customprivchg))) {
2279: $changemsg .= '<li>'.$item.'</li>';
2280: }
2281: $changemsg .= '</ul></li>';
2282: }
2283: if (keys(%rolechange) > 0) {
2284: $changemsg .= '<li>'.
2285: &mt('Existing roles with status changes').'</li>'.
2286: '<ul>';
2287: foreach my $item (sort(keys(%rolechange))) {
2288: $changemsg .= '<li>'.
2289: &mt('[_1] status now: [_2].',$item,
2290: $rolechange{$item}).'</li>';
2291: }
2292: $changemsg .= '</ul></li>';
2293: }
2294: if (keys(%deletedroles) > 0) {
2295: $changemsg .= '<li>'.
2296: &mt('Existing roles deleted').'</li>'.
2297: '<ul>';
2298: foreach my $item (sort(keys(%deletedroles))) {
2299: $changemsg .= '<li>'.$item.'</li>';
2300: }
2301: $changemsg .= '</ul></li>';
2302: }
2303: }
2304: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2305: my $groupchgmsg;
2306: foreach my $key (sort(keys(%changed_groups))) {
2307: my $crs = 'gr/'.$key;
2308: $crs =~ s/_/\//;
2309: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2310: if (ref($changed_groups{$key}) eq 'HASH') {
2311: my @showgroups;
2312: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2313: if ($changed_groups{$key}{$group} eq 'active') {
2314: push(@showgroups,$group);
2315: }
2316: }
2317: if (@showgroups > 0) {
2318: $groupchgmsg .= '<li>'.
2319: &mt('Course: [_1], groups: [_2].',$key,
2320: join(', ',@showgroups)).
2321: '</li>';
2322: }
2323: }
2324: }
2325: }
2326: if (keys(%groupchange) > 0) {
2327: $groupchgmsg .= '<li>'.
2328: &mt('Existing course/community groups with status changes').'</li>'.
2329: '<ul>';
2330: foreach my $crs (sort(keys(%groupchange))) {
2331: if (ref($groupchange{$crs}) eq 'HASH') {
2332: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crs.'</b><ul>');
2333: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
2334: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$group.'</b>',$groupchange{$crs}{$group}).'</li>';
2335: }
2336: $groupchgmsg .= '</ul></li>';
2337: }
2338: }
2339: $groupchgmsg .= '</ul></li>';
2340: }
2341: if ($groupchgmsg) {
2342: $changemsg .= '<li>'.
2343: &mt('Courses with changes in groups').'</li>'.
2344: '<ul>'.$groupchgmsg.'</ul></li>';
2345: }
2346: }
2347: if ($changemsg) {
2348: $msg .= '<ul>'.$changemsg.'</ul>';
2349: }
2350: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2351: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2352: $curr_author = $env{'user.author'};
2353: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2354: ($env{'request.role'} =~/^aa/)) {
2355: $curr_role_author=1;
2356: }
2357: $curr_is_adv = $env{'user.adv'};
2358: $curr_role_adv = $env{'request.role.adv'};
2359: if (keys(%userroles) > 0) {
2360: foreach my $role (@changed_roles) {
2361: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2362: push(@rolecodes,$role);
2363: }
2364: }
2365: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2366: push(@rolecodes,'cm');
2367: }
2368: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2369: }
2370: my %newenv;
2371: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2372: unless ($curr_is_adv) {
2373: $newenv{'user.adv'} = 1;
2374: }
2375: } elsif ($curr_is_adv && !$curr_role_adv) {
2376: &Apache::lonnet::delenv('user.adv');
2377: }
2378: my %authorroleshash =
2379: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2380: if (keys(%authorroleshash)) {
2381: unless ($curr_author) {
2382: $newenv{'user.author'} = 1;
2383: }
2384: } elsif ($curr_author && !$curr_role_author) {
2385: &Apache::lonnet::delenv('user.author');
2386: }
2387: if ($env{'request.course.id'}) {
2388: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2389: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2390: my (@activecrsgroups,$crsgroupschanged);
2391: if ($env{'request.course.groups'}) {
2392: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2393: foreach my $item (keys(%deletedroles)) {
2394: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2395: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2396: $crsgroupschanged = 1;
2397: last;
2398: }
2399: }
2400: }
2401: }
2402: unless ($crsgroupschanged) {
2403: foreach my $item (keys(%newgroup)) {
2404: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2405: if ($newgroup{$item} eq 'active') {
2406: $crsgroupschanged = 1;
2407: last;
2408: }
2409: }
2410: }
2411: }
2412: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2413: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2414: ($crsgroupschanged)) {
2415: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2416: ['active'],['gr'],[$cdom],1);
2417: my @activegroups;
2418: foreach my $item (keys(%grouproles)) {
2419: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2420: my $group;
2421: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2422: if ($remainder =~ /:/) {
2423: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2424: } else {
2425: $group = $remainder;
2426: }
2427: if ($group ne '') {
2428: push(@activegroups,$group);
2429: }
2430: }
2431: $newenv{'request.course.groups'} = join(':',@activegroups);
2432: }
2433: }
2434: if (keys(%newenv)) {
2435: &Apache::lonnet::appenv(\%newenv);
2436: }
2437: return $msg;
2438: }
2439:
2440: sub curr_role_status {
2441: my ($start,$end,$refresh,$update) = @_;
2442: if (($start) && ($start<0)) { return 'deleted' };
2443: my $status = 'active';
2444: if (($end) && ($end<=$update)) {
2445: $status = 'previous';
2446: }
2447: if (($start) && ($refresh<$start)) {
2448: $status = 'future';
2449: }
2450: return $status;
2451: }
2452:
2453: sub gather_roleprivs {
2454: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2455: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2456: if (($area ne '') && ($role ne '')) {
2457: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2458: $area,$tstart,$tend);
2459: my $spec=$role.'.'.$area;
2460: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2461: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2462: if ($status eq 'active') {
2463: if ($role =~ /^cr\//) {
2464: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2465: } elsif ($role eq 'gr') {
2466: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2467: $env{'user.domain'},
2468: $env{'user.name'});
2469: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2470: (undef,my $group_privs) = split(/\//,$trole);
2471: $group_privs = &unescape($group_privs);
2472: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2473: } else {
2474: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2475: }
2476: }
2477: }
2478: return;
2479: }
2480:
2481: sub is_active_course {
2482: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2483: return unless(ref($roleshashref) eq 'HASH');
2484: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2485: my $is_active;
2486: foreach my $key (keys(%{$roleshashref})) {
2487: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2488: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2489: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2490: if ($status eq 'active') {
2491: $is_active = 1;
2492: last;
2493: }
2494: }
2495: }
2496: return $is_active;
2497: }
2498:
1.1 harris41 2499: 1;
2500: __END__
1.32 harris41 2501:
2502: =head1 NAME
2503:
2504: Apache::lonroles - User Roles Screen
2505:
2506: =head1 SYNOPSIS
2507:
2508: Invoked by /etc/httpd/conf/srm.conf:
2509:
2510: <Location /adm/roles>
2511: PerlAccessHandler Apache::lonacc
2512: SetHandler perl-script
2513: PerlHandler Apache::lonroles
2514: ErrorDocument 403 /adm/login
2515: ErrorDocument 500 /adm/errorhandler
2516: </Location>
1.64 bowersj2 2517:
2518: =head1 OVERVIEW
2519:
2520: =head2 Choosing Roles
2521:
2522: C<lonroles> is a handler that allows a user to switch roles in
2523: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2524: default role that a user has before selecting a role, as widely as
2525: possible, but certain handlers for example need specification which
2526: course they should act on, etc. Both in this scenario, and when the
2527: handler determines via C<lonnet>'s C<&allowed> function that a certain
2528: action is not allowed, C<lonroles> is used as error handler. This
2529: allows the user to select another role which may have permission to do
1.246 droeschl 2530: what they were trying to do.
1.64 bowersj2 2531:
2532: =begin latex
2533:
2534: \begin{figure}
2535: \begin{center}
2536: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2537: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2538: \end{center}
2539: \end{figure}
2540:
2541: =end latex
2542:
2543: =head2 Role Initialization
2544:
2545: 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 2546:
2547: =head1 INTRODUCTION
2548:
2549: This module enables a user to select what role he wishes to
2550: operate under (instructor, student, teaching assistant, course
2551: coordinator, etc). These roles are pre-established by the actions
2552: of upper-level users.
2553:
2554: This is part of the LearningOnline Network with CAPA project
2555: described at http://www.lon-capa.org.
2556:
2557: =head1 HANDLER SUBROUTINE
2558:
2559: This routine is called by Apache and mod_perl.
2560:
2561: =over 4
2562:
2563: =item *
2564:
2565: Roles Initialization (yes/no)
2566:
2567: =item *
2568:
2569: Get Error Message from Environment
2570:
2571: =item *
2572:
2573: Who is this?
2574:
2575: =item *
2576:
2577: Generate Page Output
2578:
2579: =item *
2580:
2581: Choice or no choice
2582:
2583: =item *
2584:
2585: Table
2586:
2587: =item *
2588:
2589: Privileges
2590:
2591: =back
2592:
2593: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>