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