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