Annotation of loncom/auth/lonroles.pm, revision 1.269.2.3
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.269.2.3! raeburn 4: # $Id: lonroles.pm,v 1.269.2.2 2012/08/27 11:48:24 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 '') {
! 604: ($destsymb) = ($dest =~ /\?symb=([^\&]*)/);
! 605: $destsymb = &unescape($destsymb);
! 606: }
! 607: }
! 608: } else {
! 609: if ($destsymb eq '') {
! 610: ($destsymb) = ($dest =~ /\?symb=([^\&]+)/);
! 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: }
! 629: unless (($dest =~ m{^/enc/}) || ($dest =~ /\?symb=.+___\d+___.+/)) {
! 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.185 raeburn 1665: if ($setprivs) {
1.198 raeburn 1666: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1667: my $role = $1;
1668: my $custom_role = $2;
1669: my $usec = $3;
1670: if ($role eq 'cr') {
1.199 raeburn 1671: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1672: $role .= $custom_role;
1673: } else {
1674: return;
1675: }
1676: }
1.208 raeburn 1677: my (%userroles,%newrole,%newgroups,%group_privs);
1678: my %cgroups =
1679: &Apache::lonnet::get_active_groups($env{'user.domain'},
1680: $env{'user.name'},$cdom,$cnum);
1681: foreach my $group (keys(%cgroups)) {
1682: $group_privs{$group} =
1683: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1684: }
1685: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1686: my $area = '/'.$cdom.'/'.$cnum;
1687: my $spec = $role.'.'.$area;
1688: if ($usec ne '') {
1689: $spec .= '/'.$usec;
1690: $area .= '/'.$usec;
1691: }
1692: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1693: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1694: my $adhocstart = $refresh-1;
1.185 raeburn 1695: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1696: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1697: }
1698: }
1699: }
1700: return;
1701: }
1702:
1703: sub check_forcc {
1.260 raeburn 1704: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1705: my ($is_cc,$ccrole);
1706: if ($crstype eq 'Community') {
1707: $ccrole = 'co';
1708: } else {
1709: $ccrole = 'cc';
1710: }
1.266 droeschl 1711: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1712: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1713: if (defined($env{$envkey})) {
1714: $is_cc = 1;
1715: my ($tstart,$tend)=split(/\./,$env{$envkey});
1716: my $limit = $update;
1717: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1718: $limit = $then;
1.185 raeburn 1719: }
1.266 droeschl 1720: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1721: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1722: }
1723: }
1724: return $is_cc;
1725: }
1726:
1.254 raeburn 1727: sub check_release_required {
1.255 raeburn 1728: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1729: my ($switchserver,$warning);
1.255 raeburn 1730: if ($required ne '') {
1731: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.257 raeburn 1732: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1733: if ($reqdmajor ne '' && $reqdminor ne '') {
1734: my $otherserver;
1735: if (($major eq '' && $minor eq '') ||
1736: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1737: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1738: my $switchlcrev =
1739: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1740: $userdomserver);
1.257 raeburn 1741: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1742: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1743: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1744: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1745: if ($cdom ne $env{'user.domain'}) {
1746: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1747: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1748: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1749: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1750: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1751: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1752: my $canhost =
1753: &Apache::lonnet::can_host_session($env{'user.domain'},
1754: $coursedomserver,
1755: $remoterev,
1756: $udomdefaults{'remotesessions'},
1757: $defdomdefaults{'hostedsessions'});
1758:
1759: if ($canhost) {
1760: $otherserver = $coursedomserver;
1761: } else {
1762: $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.");
1763: }
1764: } else {
1765: $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).");
1766: }
1767: } else {
1768: $otherserver = $userdomserver;
1769: }
1770: }
1771: if ($otherserver ne '') {
1772: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1773: }
1774: }
1775: }
1776: return ($switchserver,$warning);
1777: }
1778:
1.108 raeburn 1779: sub courselink {
1.193 raeburn 1780: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1781: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1782: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1783: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1784: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1785: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1786: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1787: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1788: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1789: return $courseform.$hiddenitems;
1.109 raeburn 1790: }
1791:
1792: sub coursepick_jscript {
1.184 raeburn 1793: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1794: 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 1795: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1796: );
1.104 raeburn 1797: my $verify_script = <<"END";
1.179 raeburn 1798: <script type="text/javascript">
1.225 bisitz 1799: // <![CDATA[
1.108 raeburn 1800: function verifyCoursePick(caller) {
1801: var numbutton = getIndex(caller)
1.112 raeburn 1802: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1803: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1804: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1805: if (pickedCourse != '') {
1.108 raeburn 1806: if (numbutton != -1) {
1807: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1808: document.rolechoice.elements[numbutton+1].name = courseTarget
1809: document.rolechoice.submit()
1810: }
1.104 raeburn 1811: }
1812: else {
1.184 raeburn 1813: alert("$lt{'plsu'}");
1.104 raeburn 1814: }
1815: }
1816: else {
1.184 raeburn 1817: alert("$lt{'youc'}")
1.104 raeburn 1818: }
1819: }
1.109 raeburn 1820: function getIndex(caller) {
1.108 raeburn 1821: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1822: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1823: return i;
1824: }
1825: }
1826: return -1;
1827: }
1.225 bisitz 1828: // ]]>
1.104 raeburn 1829: </script>
1830: END
1.109 raeburn 1831: return $verify_script;
1.104 raeburn 1832: }
1833:
1.193 raeburn 1834: sub coauthorlink {
1835: my ($dcdom,$rowtype) = @_;
1836: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1837: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1838: return $coauthorform.$hiddenitems;
1839: }
1840:
1.113 raeburn 1841: sub display_cc_role {
1842: my $rolekey = shift;
1.223 raeburn 1843: my ($roletext,$roletext_end);
1.118 albertel 1844: my $advanced = $env{'user.adv'};
1845: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1846: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1847: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1848: my $ccrole = $1;
1.249 raeburn 1849: my $tdom = $2;
1850: my $trest = $3;
1851: my $tcourseid = $tdom.'_'.$trest;
1852: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1853: my $twhere;
1.152 raeburn 1854: my $ttype;
1.212 bisitz 1855: my $tbg='LC_roles_is';
1.113 raeburn 1856: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1857: if (%newhash) {
1858: $twhere=$newhash{'description'}.
1.261 bisitz 1859: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1860: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1861: '</span>';
1.153 raeburn 1862: $ttype = $newhash{'type'};
1.113 raeburn 1863: } else {
1864: $twhere=&mt('Currently not available');
1.118 albertel 1865: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1866: }
1.242 raeburn 1867: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1868: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1869: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1870: }
1871: }
1.223 raeburn 1872: return ($roletext,$roletext_end);
1.104 raeburn 1873: }
1874:
1.192 raeburn 1875: sub adhoc_roles_row {
1.138 raeburn 1876: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1877: my $output = &Apache::loncommon::continue_data_table_row()
1878: .' <td colspan="5">'
1879: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1880: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1881: .' ';
1.193 raeburn 1882: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1883: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1884: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1885: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1886: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1887: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1888: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1889: return $output;
1890: }
1891:
1.104 raeburn 1892: sub recent_filename {
1893: my $area=shift;
1.149 www 1894: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1895: }
1896:
1.139 raeburn 1897: sub courseloadpage {
1898: my ($courseid) = @_;
1899: my $startpage;
1.144 albertel 1900: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1901: [$courseid.':courseinit']);
1.139 raeburn 1902: my ($tmp) = %entry_settings;
1.144 albertel 1903: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1904: $startpage = $entry_settings{$courseid.':courseinit'};
1905: }
1906: if ($startpage eq '') {
1907: if (exists($env{'environment.course_init_display'})) {
1908: $startpage = $env{'environment.course_init_display'};
1909: }
1910: }
1911: return $startpage;
1912: }
1913:
1.260 raeburn 1914: sub update_session_roles {
1915: my $then=$env{'user.login.time'};
1916: my $refresh=$env{'user.refresh.time'};
1917: if (!$refresh) {
1918: $refresh = $then;
1919: }
1920: my $update = $env{'user.update.time'};
1921: if (!$update) {
1922: $update = $then;
1923: }
1924: my $now = time;
1925: my %roleshash =
1926: &Apache::lonnet::get_my_roles('','','userroles',
1927: ['active','future','previous'],
1928: undef,undef,1);
1929: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1930: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1931: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1932: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1933: @rolecodes);
1934: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1935: my %courseroles;
1936: foreach my $item (keys(%roleshash)) {
1937: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1938: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1939: my ($section,$group,@group_privs);
1940: if ($role =~ m{^gr/(\w*)$}) {
1941: $role = 'gr';
1942: my $priv = $1;
1943: next if ($tstart eq '-1');
1944: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1945: if ($priv ne '') {
1946: push(@group_privs,$priv);
1947: }
1948: }
1949: if ($remainder =~ /:/) {
1950: (my $additional_privs,$group) =
1951: ($remainder =~ /^([\w:]+):([^:]+)$/);
1952: if ($additional_privs ne '') {
1953: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1954: push(@group_privs,split(/:/,$additional_privs));
1955: @group_privs = sort(@group_privs);
1956: }
1957: }
1958: } else {
1959: $group = $remainder;
1960: }
1961: } else {
1962: $section = $remainder;
1963: }
1964: my $where = "/$udom/$uname";
1965: if ($section ne '') {
1966: $where .= "/$section";
1967: } elsif ($group ne '') {
1968: $where .= "/$group";
1969: }
1970: my $rolekey = "$role.$where";
1971: my $envkey = "user.role.$rolekey";
1972: $dbroles{$envkey} = 1;
1973: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
1974: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
1975: $currrole_expired = 1;
1976: }
1977: }
1978: if ($env{$envkey} eq '') {
1979: my $status_in_db =
1.269.2.2 raeburn 1980: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 1981: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
1982: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
1983: if ($status_in_db eq 'active') {
1984: if ($section eq '') {
1985: push(@newsec,'none');
1986: } else {
1987: push(@newsec,$section);
1988: }
1989: }
1990: } else {
1991: unless (grep(/^\Q$role\E$/,@changed_roles)) {
1992: push(@changed_roles,$role);
1993: }
1994: if ($status_in_db ne 'previous') {
1995: if ($role eq 'gr') {
1996: $newgroup{$rolekey} = $status_in_db;
1997: if ($status_in_db eq 'active') {
1998: unless (ref($courseroles{$udom}) eq 'HASH') {
1999: %{$courseroles{$udom}} =
2000: &Apache::lonnet::get_my_roles('','','userroles',
2001: ['active'],\@possroles,
2002: [$udom],1);
2003: }
2004: &Apache::lonnet::get_groups_roles($udom,$uname,
2005: $courseroles{$udom},
2006: \@rolecodes,\%groups_roles);
2007: }
2008: } else {
2009: $newrole{$rolekey} = $status_in_db;
2010: }
2011: }
2012: }
2013: } else {
2014: my ($currstart,$currend) = split(/\./,$env{$envkey});
2015: if ($role eq 'gr') {
2016: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2017: $hasgroups = 1;
2018: }
2019: }
2020: if (($currstart ne $tstart) || ($currend ne $tend)) {
2021: my $status_in_env =
2022: &curr_role_status($currstart,$currend,$refresh,$update);
2023: my $status_in_db =
1.269.2.2 raeburn 2024: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2025: if ($status_in_env ne $status_in_db) {
2026: if ($status_in_env eq 'active') {
2027: if ($role eq 'st') {
2028: if ($env{'request.role'} eq $rolekey) {
2029: my $switchsection;
2030: unless (ref($courseroles{$udom}) eq 'HASH') {
2031: %{$courseroles{$udom}} =
2032: &Apache::lonnet::get_my_roles('','','userroles',
2033: ['active'],
2034: \@possroles,[$udom],1);
2035: }
2036: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2037: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2038: $switchsection = 1;
2039: last;
2040: }
2041: }
2042: if ($switchsection) {
2043: if ($section eq '') {
2044: $oldsec = 'none';
2045: } else {
2046: $oldsec = $section;
2047: }
2048: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2049: } else {
2050: $currrole_expired = 1;
2051: next;
2052: }
2053: }
2054: }
2055: unless ($rolekey eq $env{'request.role'}) {
2056: if ($role eq 'gr') {
2057: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2058: } else {
2059: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2060: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2061: }
2062: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2063: }
2064: } elsif ($status_in_db eq 'active') {
2065: if (($role eq 'st') &&
2066: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2067: if ($section eq '') {
2068: push(@newsec,'none');
2069: } else {
2070: push(@newsec,$section);
2071: }
2072: } elsif ($role eq 'gr') {
2073: unless (ref($courseroles{$udom}) eq 'HASH') {
2074: %{$courseroles{$udom}} =
2075: &Apache::lonnet::get_my_roles('','','userroles',
2076: ['active'],
2077: \@possroles,[$udom],1);
2078: }
2079: &Apache::lonnet::get_groups_roles($udom,$uname,
2080: $courseroles{$udom},
2081: \@rolecodes,\%groups_roles);
2082: }
2083: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2084: }
2085: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2086: push(@changed_roles,$role);
2087: }
2088: if ($role eq 'gr') {
2089: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2090: } else {
2091: $rolechange{$rolekey} = $status_in_db;
2092: }
2093: }
2094: } else {
2095: if ($role eq 'gr') {
2096: unless ($checkedgroup{$where}) {
2097: my $status_in_db =
2098: &curr_role_status($tstart,$tend,$refresh,$now);
2099: if ($tstart eq '-1') {
2100: $status_in_db = 'deleted';
2101: }
2102: unless (ref($courseroles{$udom}) eq 'HASH') {
2103: %{$courseroles{$udom}} =
2104: &Apache::lonnet::get_my_roles('','','userroles',
2105: ['active'],
2106: \@possroles,[$udom],1);
2107: }
2108: if (ref($courseroles{$udom}) eq 'HASH') {
2109: foreach my $item (keys(%{$courseroles{$udom}})) {
2110: next unless ($item =~ /^\Q$uname\E/);
2111: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2112: my $area = '/'.$cdom.'/'.$cnum;
2113: if ($crssec ne '') {
2114: $area .= '/'.$crssec;
2115: }
2116: my $crsrolekey = $crsrole.'.'.$area;
2117: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2118: $currprivs =~ s/^://;
2119: $currprivs =~ s/\&F$//;
2120: my @curr_grp_privs = split(/\&F:/,$currprivs);
2121: @curr_grp_privs = sort(@curr_grp_privs);
2122: my @diffs;
2123: if (@group_privs > 0 || @curr_grp_privs > 0) {
2124: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2125: }
2126: if (@diffs == 0) {
2127: last;
2128: } else {
2129: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2130: push(@rolecodes,'gr');
2131: }
2132: &gather_roleprivs(\%allroles,\%allgroups,
2133: \%userroles,$where,$role,
2134: $tstart,$tend,$status_in_db);
2135: if ($status_in_db eq 'active') {
2136: &Apache::lonnet::get_groups_roles($udom,$uname,
2137: $courseroles{$udom},
2138: \@rolecodes,\%groups_roles);
2139: }
2140: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2141: last;
2142: }
2143: }
2144: }
2145: $checkedgroup{$where} = 1;
2146: }
2147: } elsif ($role =~ /^cr/) {
2148: my $status_in_db =
2149: &curr_role_status($tstart,$tend,$refresh,$now);
2150: my ($rdummy,$rest) = split(/\//,$role,2);
2151: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
2152: my %currpriv;
2153: unless (exists($crprivs{$rest})) {
2154: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2155: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2156: if (&Apache::lonnet::hostname($homsvr) ne '') {
2157: my ($rdummy,$roledef)=
2158: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2159: $rdomain,$rauthor);
2160: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2161: my $i = 0;
2162: my @scopes = ('sys','dom','crs');
2163: my @privs = split(/\_/,$roledef);
2164: foreach my $priv (@privs) {
2165: my ($blank,@prv) = split(/:/,$priv);
2166: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2167: if (@prv) {
2168: $priv = ':'.join(':',sort(@prv));
2169: }
1.260 raeburn 2170: $crprivs{$rest}{$scopes[$i]} = $priv;
2171: $i++;
2172: }
2173: }
2174: }
2175: }
2176: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2177: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2178: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2179: if (keys(%crprivs)) {
2180: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2181: ($crprivs{$rest}{dom} ne $currpriv{dom})
2182: ||
2183: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2184: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2185: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2186: push(@changed_roles,$role);
2187: }
2188: my $status_in_env =
2189: &curr_role_status($currstart,$currend,$refresh,$update);
2190: if ($status_in_env eq 'active') {
2191: $customprivchg{$rolekey} = $status_in_env;
2192: }
2193: }
2194: }
2195: }
2196: }
2197: }
2198: }
2199: foreach my $envkey (keys(%env)) {
2200: next unless ($envkey =~ /^user\.role\./);
2201: next if ($dbroles{$envkey});
2202: next if ($envkey eq 'user.role.'.$env{'request.role'});
2203: my ($currstart,$currend) = split(/\./,$env{$envkey});
2204: my $status_in_env =
2205: &curr_role_status($currstart,$currend,$refresh,$update);
2206: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2207: my ($role,$rest)=split(/\./,$rolekey,2);
2208: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2209: if ($status_in_env eq 'active') {
2210: if ($role eq 'gr') {
2211: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2212: \@possroles);
2213: } else {
2214: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2215: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2216: }
2217: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2218: push(@changed_roles,$role);
2219: }
2220: $deletedroles{$rolekey} = 1;
2221: }
2222: }
2223: }
2224: if (($oldsec) && (@newsec > 0)) {
2225: if (@newsec > 1) {
1.269.2.2 raeburn 2226: $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 2227: } else {
2228: my $newrole = $env{'request.role'};
2229: if ($newsec[0] eq 'none') {
2230: $newrole =~ s{(/[^/])$}{};
2231: } elsif ($oldsec eq 'none') {
2232: $newrole .= '/'.$newsec[0];
2233: } else {
2234: $newrole =~ s{([^/]+)$}{$newsec[0]};
2235: }
2236: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2237: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2238: my %temp=('logout_'.$env{'request.course.id'} => time);
2239: &Apache::lonnet::put('email_status',\%temp);
2240: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2241: &Apache::lonnet::appenv({"request.course.id" => '',
2242: "request.course.fn" => '',
2243: "request.course.uri" => '',
2244: "request.course.sec" => '',
2245: "request.role" => 'cm',
2246: "request.role.adv" => $env{'user.adv'},
2247: "request.role.domain" => $env{'user.domain'}});
2248: my $rolename = &Apache::loncommon::plainname($curr_role);
2249: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2250: '<input type="hidden" name="newrole" value="" />'.
2251: '<input type="hidden" name="selectrole" value="1" />'.
2252: '<span class="LC_info">'.
2253: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2254: my $button = '<input type="button" name="sectionchanged" value="'.
2255: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2256: if ($newsec[0] eq 'none') {
2257: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2258: } else {
2259: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2260: }
2261: $msg .= '</form></p>';
2262: }
2263: } elsif ($currrole_expired) {
1.269.2.2 raeburn 2264: $msg .= '<p class="LC_warning">';
1.260 raeburn 2265: if (&Apache::loncommon::show_course()) {
2266: $msg .= &mt('Your role in the current course has expired.');
2267: } else {
2268: $msg .= &mt('Your current role has expired.');
2269: }
1.269.2.2 raeburn 2270: $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 2271: }
2272: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2273: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2274: if (!@changed_roles) {
2275: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2276: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2277: } else {
1.264 raeburn 2278: $rolesmsg = &mt('No role changes');
1.260 raeburn 2279: }
2280: }
2281: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2282: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2283: }
2284: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2285: if (($msg ne '') || ($groupsmsg ne '')) {
2286: $msg .= '<ul>';
2287: if ($rolesmsg) {
2288: $msg .= '<li>'.$rolesmsg.'</li>';
2289: }
2290: if ($groupsmsg) {
2291: $msg .= '<li>'.$groupsmsg.'</li>';
2292: }
2293: $msg .= '</ul>';
2294: } else {
1.269.2.2 raeburn 2295: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2296: }
1.260 raeburn 2297: return $msg;
2298: }
2299: }
2300: my $changemsg;
2301: if (@changed_roles > 0) {
2302: if (keys(%newgroup) > 0) {
2303: my $groupmsg;
2304: foreach my $item (sort(keys(%newgroup))) {
2305: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
2306: $groupmsg .= '<li>'.
2307: &mt('[_1] with status: [_2].',
2308: $item,$newgroup{$item}).'</li>';
2309: }
2310: }
2311: if ($groupmsg) {
2312: $changemsg .= '<li>'.
2313: &mt('Courses with new groups').'</li>'.
2314: '<ul>'.$groupmsg.'</ul></li>';
2315: }
2316: }
2317: if (keys(%newrole) > 0) {
2318: $changemsg .= '<li>'.&mt('New roles').
2319: '<ul>';
2320: foreach my $item (sort(keys(%newrole))) {
2321: $changemsg .= '<li>'.
2322: &mt('[_1] with status: [_2].',
2323: $item,$newrole{$item}).'</li>';
2324: }
2325: $changemsg .= '</ul></li>';
2326: }
2327: if (keys(%customprivchg) > 0) {
2328: $changemsg .= '<li>'.
2329: &mt('Custom roles with privilege changes').
2330: '<ul>';
2331: foreach my $item (sort(keys(%customprivchg))) {
2332: $changemsg .= '<li>'.$item.'</li>';
2333: }
2334: $changemsg .= '</ul></li>';
2335: }
2336: if (keys(%rolechange) > 0) {
2337: $changemsg .= '<li>'.
2338: &mt('Existing roles with status changes').'</li>'.
2339: '<ul>';
2340: foreach my $item (sort(keys(%rolechange))) {
2341: $changemsg .= '<li>'.
2342: &mt('[_1] status now: [_2].',$item,
2343: $rolechange{$item}).'</li>';
2344: }
2345: $changemsg .= '</ul></li>';
2346: }
2347: if (keys(%deletedroles) > 0) {
2348: $changemsg .= '<li>'.
1.268 raeburn 2349: &mt('Existing roles now expired').'</li>'.
1.260 raeburn 2350: '<ul>';
2351: foreach my $item (sort(keys(%deletedroles))) {
2352: $changemsg .= '<li>'.$item.'</li>';
2353: }
2354: $changemsg .= '</ul></li>';
2355: }
2356: }
2357: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2358: my $groupchgmsg;
2359: foreach my $key (sort(keys(%changed_groups))) {
2360: my $crs = 'gr/'.$key;
2361: $crs =~ s/_/\//;
2362: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2363: if (ref($changed_groups{$key}) eq 'HASH') {
2364: my @showgroups;
2365: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2366: if ($changed_groups{$key}{$group} eq 'active') {
2367: push(@showgroups,$group);
2368: }
2369: }
2370: if (@showgroups > 0) {
2371: $groupchgmsg .= '<li>'.
2372: &mt('Course: [_1], groups: [_2].',$key,
2373: join(', ',@showgroups)).
2374: '</li>';
2375: }
2376: }
2377: }
2378: }
2379: if (keys(%groupchange) > 0) {
2380: $groupchgmsg .= '<li>'.
2381: &mt('Existing course/community groups with status changes').'</li>'.
2382: '<ul>';
2383: foreach my $crs (sort(keys(%groupchange))) {
2384: if (ref($groupchange{$crs}) eq 'HASH') {
2385: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crs.'</b><ul>');
2386: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
2387: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$group.'</b>',$groupchange{$crs}{$group}).'</li>';
2388: }
2389: $groupchgmsg .= '</ul></li>';
2390: }
2391: }
2392: $groupchgmsg .= '</ul></li>';
2393: }
2394: if ($groupchgmsg) {
2395: $changemsg .= '<li>'.
2396: &mt('Courses with changes in groups').'</li>'.
2397: '<ul>'.$groupchgmsg.'</ul></li>';
2398: }
2399: }
2400: if ($changemsg) {
2401: $msg .= '<ul>'.$changemsg.'</ul>';
2402: }
2403: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2404: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2405: $curr_author = $env{'user.author'};
2406: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2407: ($env{'request.role'} =~/^aa/)) {
2408: $curr_role_author=1;
2409: }
2410: $curr_is_adv = $env{'user.adv'};
2411: $curr_role_adv = $env{'request.role.adv'};
2412: if (keys(%userroles) > 0) {
2413: foreach my $role (@changed_roles) {
2414: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2415: push(@rolecodes,$role);
2416: }
2417: }
2418: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2419: push(@rolecodes,'cm');
2420: }
2421: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2422: }
2423: my %newenv;
2424: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2425: unless ($curr_is_adv) {
2426: $newenv{'user.adv'} = 1;
2427: }
2428: } elsif ($curr_is_adv && !$curr_role_adv) {
2429: &Apache::lonnet::delenv('user.adv');
2430: }
2431: my %authorroleshash =
2432: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2433: if (keys(%authorroleshash)) {
2434: unless ($curr_author) {
2435: $newenv{'user.author'} = 1;
2436: }
2437: } elsif ($curr_author && !$curr_role_author) {
2438: &Apache::lonnet::delenv('user.author');
2439: }
2440: if ($env{'request.course.id'}) {
2441: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2442: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2443: my (@activecrsgroups,$crsgroupschanged);
2444: if ($env{'request.course.groups'}) {
2445: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2446: foreach my $item (keys(%deletedroles)) {
2447: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2448: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2449: $crsgroupschanged = 1;
2450: last;
2451: }
2452: }
2453: }
2454: }
2455: unless ($crsgroupschanged) {
2456: foreach my $item (keys(%newgroup)) {
2457: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2458: if ($newgroup{$item} eq 'active') {
2459: $crsgroupschanged = 1;
2460: last;
2461: }
2462: }
2463: }
2464: }
2465: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2466: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2467: ($crsgroupschanged)) {
2468: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2469: ['active'],['gr'],[$cdom],1);
2470: my @activegroups;
2471: foreach my $item (keys(%grouproles)) {
2472: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2473: my $group;
2474: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2475: if ($remainder =~ /:/) {
2476: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2477: } else {
2478: $group = $remainder;
2479: }
2480: if ($group ne '') {
2481: push(@activegroups,$group);
2482: }
2483: }
2484: $newenv{'request.course.groups'} = join(':',@activegroups);
2485: }
2486: }
2487: if (keys(%newenv)) {
2488: &Apache::lonnet::appenv(\%newenv);
2489: }
2490: return $msg;
2491: }
2492:
2493: sub curr_role_status {
2494: my ($start,$end,$refresh,$update) = @_;
2495: if (($start) && ($start<0)) { return 'deleted' };
2496: my $status = 'active';
2497: if (($end) && ($end<=$update)) {
2498: $status = 'previous';
2499: }
2500: if (($start) && ($refresh<$start)) {
2501: $status = 'future';
2502: }
2503: return $status;
2504: }
2505:
2506: sub gather_roleprivs {
2507: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2508: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2509: if (($area ne '') && ($role ne '')) {
2510: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2511: $area,$tstart,$tend);
2512: my $spec=$role.'.'.$area;
2513: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2514: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2515: if ($status eq 'active') {
2516: if ($role =~ /^cr\//) {
2517: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2518: } elsif ($role eq 'gr') {
2519: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2520: $env{'user.domain'},
2521: $env{'user.name'});
2522: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2523: (undef,my $group_privs) = split(/\//,$trole);
2524: $group_privs = &unescape($group_privs);
2525: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2526: } else {
2527: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2528: }
2529: }
2530: }
2531: return;
2532: }
2533:
2534: sub is_active_course {
2535: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2536: return unless(ref($roleshashref) eq 'HASH');
2537: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2538: my $is_active;
2539: foreach my $key (keys(%{$roleshashref})) {
2540: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2541: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2542: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2543: if ($status eq 'active') {
2544: $is_active = 1;
2545: last;
2546: }
2547: }
2548: }
2549: return $is_active;
2550: }
2551:
1.269.2.2 raeburn 2552: sub get_roles_functions {
2553: my ($rolescount) = @_;
2554: my @links;
2555: if ($env{'user.adv'}) {
2556: if ($env{'form.display'} eq 'showall') {
2557: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired roles')]);
2558: } else {
2559: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired roles')]);
2560: }
2561: }
2562: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
2563: if ($env{'environment.canrequest.author'}) {
2564: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2565: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
2566: }
2567: }
2568: if (&Apache::lonmenu::check_for_rcrs()) {
2569: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
2570: }
2571: if ($env{'form.state'} eq 'queued') {
2572: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
2573: } else {
2574: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
2575: }
2576: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
2577: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
2578: }
2579:
2580: my $funcs = &Apache::lonhtmlcommon::start_funclist();
2581: foreach my $link (@links) {
2582: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
2583: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
2584: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
2585: $link->[2].'</a>');
2586: }
2587: $funcs .= &Apache::lonhtmlcommon::end_funclist();
2588: return &Apache::loncommon::head_subbox($funcs);
2589: }
2590:
2591: sub get_queued {
2592: my ($output,%reqcrs);
2593: my ($types,$typenames) = &Apache::loncommon::course_types();
2594: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2595: $env{'user.name'},'^status:');
2596: foreach my $key (keys(%statusinfo)) {
2597: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
2598: (undef,my($cdom,$cnum)) = split(':',$key);
2599: my $requestkey = $cdom.'_'.$cnum;
2600: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2601: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2602: $env{'user.domain'},$env{'user.name'});
2603: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2604: my $reqtime = $history{'reqtime'};
2605: my $lastupdate = $history{'timestamp'};
2606: my $showtype = $history{'crstype'};
2607: if (defined($typenames->{$history{'crstype'}})) {
2608: $showtype = $typenames->{$history{'crstype'}};
2609: }
2610: my $description;
2611: if (ref($history{'details'}) eq 'HASH') {
2612: $description = $history{details}{'cdescr'};
2613: }
2614: @{$reqcrs{$reqtime}} = ($description,$showtype);
2615: }
2616: }
2617: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
2618: if (@sortedtimes > 0) {
2619: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
2620: &Apache::loncommon::start_data_table().
2621: &Apache::loncommon::start_data_table_header_row().
2622: '<th>'.&mt('Date requested').'</th>'.
2623: '<th>'.&mt('Course title').'</th>'.
2624: '<th>'.&mt('Course type').'</th>';
2625: &Apache::loncommon::end_data_table_header_row();
2626: foreach my $reqtime (@sortedtimes) {
2627: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
2628: $output .= &Apache::loncommon::start_data_table_row().
2629: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
2630: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
2631: &Apache::loncommon::end_data_table_row();
2632: }
2633: $output .= &Apache::loncommon::end_data_table().
2634: '<br /></p>';
2635: }
2636: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
2637: if ($queuedselfenroll) {
2638: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
2639: $queuedselfenroll.'<br /></p>';
2640: }
2641: if ($env{'environment.canrequest.author'}) {
2642: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2643: my $requestauthor;
2644: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
2645: if (($status eq 'approval') || ($status eq 'approved')) {
2646: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
2647: if ($status eq 'approval') {
2648: $output .= &mt('A request for authoring space submitted on [_1] is awaiting approval',
2649: &Apache::lonlocal::locallocaltime($timestamp));
2650: } elsif ($status eq 'approved') {
2651: my %roleshash =
2652: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2653: ['active'],['au'],[$env{'user.domain'}]);
2654: if (keys(%roleshash)) {
2655: $output .= '<span class="LC_info">'.
2656: &mt('Your request for an author role has been approved.').'<br />'.
2657: &mt('Use the "Check for changes" link to update your list of roles.').
2658: '</span>';
2659: }
2660: }
2661: $output .= '</p>';
2662: }
2663: }
2664: }
2665: unless ($output) {
2666: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
2667: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
2668: $output = &mt('No requests for courses, communities or authoring currently queued');
2669: } else {
2670: $output = &mt('No enrollment requests currently queued awaiting approval');
2671: }
2672: }
2673: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
2674: $output.'</fieldset></div><br clear="all" />';
2675: }
2676:
1.1 harris41 2677: 1;
2678: __END__
1.32 harris41 2679:
2680: =head1 NAME
2681:
2682: Apache::lonroles - User Roles Screen
2683:
2684: =head1 SYNOPSIS
2685:
2686: Invoked by /etc/httpd/conf/srm.conf:
2687:
2688: <Location /adm/roles>
2689: PerlAccessHandler Apache::lonacc
2690: SetHandler perl-script
2691: PerlHandler Apache::lonroles
2692: ErrorDocument 403 /adm/login
2693: ErrorDocument 500 /adm/errorhandler
2694: </Location>
1.64 bowersj2 2695:
2696: =head1 OVERVIEW
2697:
2698: =head2 Choosing Roles
2699:
2700: C<lonroles> is a handler that allows a user to switch roles in
2701: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2702: default role that a user has before selecting a role, as widely as
2703: possible, but certain handlers for example need specification which
2704: course they should act on, etc. Both in this scenario, and when the
2705: handler determines via C<lonnet>'s C<&allowed> function that a certain
2706: action is not allowed, C<lonroles> is used as error handler. This
2707: allows the user to select another role which may have permission to do
1.246 droeschl 2708: what they were trying to do.
1.64 bowersj2 2709:
2710: =begin latex
2711:
2712: \begin{figure}
2713: \begin{center}
2714: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2715: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2716: \end{center}
2717: \end{figure}
2718:
2719: =end latex
2720:
2721: =head2 Role Initialization
2722:
2723: 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 2724:
2725: =head1 INTRODUCTION
2726:
2727: This module enables a user to select what role he wishes to
2728: operate under (instructor, student, teaching assistant, course
2729: coordinator, etc). These roles are pre-established by the actions
2730: of upper-level users.
2731:
2732: This is part of the LearningOnline Network with CAPA project
2733: described at http://www.lon-capa.org.
2734:
2735: =head1 HANDLER SUBROUTINE
2736:
2737: This routine is called by Apache and mod_perl.
2738:
2739: =over 4
2740:
2741: =item *
2742:
2743: Roles Initialization (yes/no)
2744:
2745: =item *
2746:
2747: Get Error Message from Environment
2748:
2749: =item *
2750:
2751: Who is this?
2752:
2753: =item *
2754:
2755: Generate Page Output
2756:
2757: =item *
2758:
2759: Choice or no choice
2760:
2761: =item *
2762:
2763: Table
2764:
2765: =item *
2766:
2767: Privileges
2768:
2769: =back
2770:
2771: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>