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