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