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