Annotation of loncom/auth/lonroles.pm, revision 1.273
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.273 ! raeburn 4: # $Id: lonroles.pm,v 1.272 2012/08/15 14:37:23 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'}) {
1.273 ! raeburn 802: unless (&Apache::loncoursequeueadmin::is_active_author()) {
1.270 raeburn 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.226 raeburn 1052: sub gather_roles {
1.260 raeburn 1053: my ($update,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
1.226 raeburn 1054: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1055: my $advanced = $env{'user.adv'};
1056: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1057: my @ids = &Apache::lonnet::current_machine_ids();
1.226 raeburn 1058: foreach my $envkey (sort(keys(%env))) {
1059: my $button = 1;
1060: my $switchserver='';
1.254 raeburn 1061: my $switchwarning;
1.226 raeburn 1062: my ($role_text,$role_text_end,$sortkey);
1063: if ($envkey=~/^user\.role\./) {
1064: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1065: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1066: \$trolecode,\$tstatus,\$tstart,\$tend);
1067: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1068: $tremark='';
1069: $tpstart=' ';
1070: $tpend=' ';
1071: if ($env{'request.role'} eq $trolecode) {
1072: $tstatus='selected';
1073: }
1074: my $tbg;
1075: if (($tstatus eq 'is')
1076: || ($tstatus eq 'selected')
1077: || ($tstatus eq 'future')
1078: || ($env{'form.showall'})) {
1.259 raeburn 1079: my $timezone = &role_timezone($where,$timezones);
1080: if ($tstart) {
1081: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1082: }
1083: if ($tend) {
1084: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1085: }
1.226 raeburn 1086: if ($tstatus eq 'is') {
1087: $tbg='LC_roles_is';
1088: $possiblerole=$trolecode;
1089: $countactive++;
1090: } elsif ($tstatus eq 'future') {
1091: $tbg='LC_roles_future';
1092: $button=0;
1093: $futureroles->{$trolecode} = $tstart.':'.$tend;
1094: $countfuture ++;
1095: } elsif ($tstatus eq 'expired') {
1096: $tbg='LC_roles_expired';
1097: $button=0;
1098: } elsif ($tstatus eq 'will_not') {
1099: $tbg='LC_roles_will_not';
1100: $tremark.=&mt('Expired after logout.').' ';
1101: } elsif ($tstatus eq 'selected') {
1102: $tbg='LC_roles_selected';
1103: $inrole=1;
1104: $countactive++;
1105: $tremark.=&mt('Currently selected.').' ';
1106: }
1107: my $trole;
1108: if ($role =~ /^cr\//) {
1109: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1110: if ($tremark) { $tremark.='<br />'; }
1.253 bisitz 1111: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1112: }
1113: $trole=Apache::lonnet::plaintext($role);
1114: my $ttype;
1115: my $twhere;
1116: my ($tdom,$trest,$tsection)=
1117: split(/\//,Apache::lonnet::declutter($where));
1118: # First, Co-Authorship roles
1119: if (($role eq 'ca') || ($role eq 'aa')) {
1120: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1121: my $allowed=0;
1122: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1123: if (!$allowed) {
1124: $button=0;
1.248 raeburn 1125: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1126: }
1127: #next if ($home eq 'no_host');
1128: $home = &Apache::lonnet::hostname($home);
1129: $ttype='Construction Space';
1130: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1131: ': '.$tdom.'<br />'.
1132: ' '.&mt('Server').': '.$home;
1133: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1134: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1135: $sortkey=$role."$trest:$tdom";
1136: } elsif ($role eq 'au') {
1137: # Authors
1138: my $home = &Apache::lonnet::homeserver
1139: ($env{'user.name'},$env{'user.domain'});
1140: my $allowed=0;
1141: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1142: if (!$allowed) {
1143: $button=0;
1.248 raeburn 1144: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1145: }
1146: #next if ($home eq 'no_host');
1147: $home = &Apache::lonnet::hostname($home);
1148: $ttype='Construction Space';
1149: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1150: ': '.$home;
1151: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1152: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1153: $sortkey=$role;
1154: } elsif ($trest) {
1155: my $tcourseid=$tdom.'_'.$trest;
1156: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1157: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1158: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1159: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1160: $twhere=$env{'course.'.$tcourseid.'.description'};
1161: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1162: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1163: unless ($twhere eq &mt('Currently not available')) {
1164: $twhere.=' <span class="LC_fontsize_small">'.
1165: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1166: '</span>';
1.254 raeburn 1167: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1168: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1169: if ($required ne '') {
1170: ($switchserver,$switchwarning) =
1171: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1172: if ($switchserver || $switchwarning) {
1173: $button = 0;
1174: }
1.254 raeburn 1175: }
1176: }
1.226 raeburn 1177: }
1178: } else {
1179: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1180: if (%newhash) {
1181: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1182: "\0".$envkey;
1.248 raeburn 1183: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1184: ' <span class="LC_fontsize_small">'.
1185: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1186: '</span>';
1.226 raeburn 1187: $ttype = $newhash{'type'};
1.243 raeburn 1188: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1189: my $home = $newhash{'home'};
1190: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1191: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1192: if ($required ne '') {
1193: ($switchserver,$switchwarning) =
1194: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1195: if ($switchserver || $switchwarning) {
1196: $button = 0;
1197: }
1.254 raeburn 1198: }
1199: }
1.226 raeburn 1200: } else {
1201: $twhere=&mt('Currently not available');
1202: $env{'course.'.$tcourseid.'.description'}=$twhere;
1203: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1204: $ttype = 'Unavailable';
1205: }
1206: }
1207: if ($tsection) {
1208: $twhere.='<br />'.&mt('Section').': '.$tsection;
1209: }
1210: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1211: } elsif ($tdom) {
1212: $ttype='Domain';
1213: $twhere=$tdom;
1214: $sortkey=$role.$twhere;
1215: } else {
1216: $ttype='System';
1217: $twhere=&mt('system wide');
1218: $sortkey=$role.$twhere;
1219: }
1220: ($role_text,$role_text_end) =
1221: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1222: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1223: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1224: $roletext->{$envkey}=[$role_text,$role_text_end];
1225: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1226: $sortrole->{$sortkey}=$envkey;
1227: $roleclass->{$envkey}=$ttype;
1228: }
1229: }
1230: }
1231: return ($countactive,$countfuture,$inrole,$possiblerole);
1232: }
1233:
1.215 raeburn 1234: sub role_timezone {
1235: my ($where,$timezones) = @_;
1236: my $timezone;
1237: if (ref($timezones) eq 'HASH') {
1238: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1239: my $cdom = $1;
1240: my $cnum = $2;
1241: if ($cdom && $cnum) {
1242: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1243: my $tz;
1244: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1245: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1246: } else {
1247: my %timehash =
1248: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1249: $tz = $timehash{'timezone'};
1250: }
1251: if ($tz eq '') {
1.215 raeburn 1252: if (!exists($timezones->{$cdom})) {
1253: my %domdefaults =
1254: &Apache::lonnet::get_domain_defaults($cdom);
1255: if ($domdefaults{'timezone_def'} eq '') {
1256: $timezones->{$cdom} = 'local';
1257: } else {
1258: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1259: }
1260: }
1261: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1262: } else {
1263: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1264: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1265: }
1266: }
1267: $timezone = $timezones->{$cdom.'_'.$cnum};
1268: }
1269: } else {
1270: my ($tdom) = ($where =~ m{^/($match_domain)});
1271: if ($tdom) {
1272: if (!exists($timezones->{$tdom})) {
1273: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1274: if ($domdefaults{'timezone_def'} eq '') {
1275: $timezones->{$tdom} = 'local';
1276: } else {
1277: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1278: }
1279: }
1280: $timezone = $timezones->{$tdom};
1281: }
1282: }
1283: if ($timezone eq 'local') {
1284: $timezone = undef;
1285: }
1286: }
1287: return $timezone;
1288: }
1289:
1.191 raeburn 1290: sub roletable_headers {
1291: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1292: my $doheaders;
1293: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1294: $r->print('<br />'
1295: .&Apache::loncommon::start_data_table()
1296: .&Apache::loncommon::start_data_table_header_row()
1297: );
1.191 raeburn 1298: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1299: $r->print('<th>'.&mt('User Role').'</th>'
1300: .'<th>'.&mt('Extent').'</th>'
1301: .'<th>'.&mt('Start').'</th>'
1302: .'<th>'.&mt('End').'</th>'
1303: .&Apache::loncommon::end_data_table_header_row()
1304: );
1.191 raeburn 1305: $doheaders=-1;
1306: my @roletypes = &roletypes();
1307: foreach my $type (@roletypes) {
1308: my $haverole=0;
1309: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1310: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1311: $haverole=1;
1312: }
1313: }
1314: if ($haverole) { $doheaders++; }
1315: }
1316: }
1317: return $doheaders;
1318: }
1319:
1320: sub roletypes {
1.237 raeburn 1321: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1.191 raeburn 1322: return @types;
1323: }
1324:
1325: sub print_rolerows {
1326: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1327: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1328: my @types = &roletypes();
1329: foreach my $type (@types) {
1330: my $output;
1331: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1332: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1333: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1334: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1335: $output.= &Apache::loncommon::start_data_table_row().
1336: $roletext->{$sortrole->{$which}}->[0].
1337: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1338: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1339: $output .= &Apache::loncommon::continue_data_table_row().
1340: $roletext->{$sortrole->{$which}}->[1].
1341: &Apache::loncommon::end_data_table_row();
1342: }
1.223 raeburn 1343: }
1.191 raeburn 1344: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1345: if (ref($dcroles) eq 'HASH') {
1346: if ($dcroles->{$1}) {
1.192 raeburn 1347: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1348: }
1349: }
1350: }
1351: }
1352: }
1353: }
1354: if ($output) {
1355: if ($doheaders > 0) {
1.212 bisitz 1356: $r->print(&Apache::loncommon::start_data_table_empty_row()
1357: .'<td align="center" colspan="5">'
1358: .&mt($type)
1359: .'</td>'
1360: .&Apache::loncommon::end_data_table_empty_row()
1361: );
1.191 raeburn 1362: }
1363: $r->print($output);
1364: }
1365: }
1366: }
1367: }
1368:
1369: sub findcourse_advice {
1370: my ($r) = @_;
1371: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1372: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1373: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1374: $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).'
1375: <ul>
1376: <li>'.&mt('The course has yet to be created.').'</li>
1377: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1378: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1379: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1380: <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>
1381: </ul>');
1382: } else {
1383: $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 />');
1384: }
1.235 bisitz 1385: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1.234 raeburn 1386: '<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 1387: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1388: &Apache::loncoursequeueadmin::queued_selfenrollment());
1.216 raeburn 1389: return;
1390: }
1391:
1.234 raeburn 1392: sub requestcourse_advice {
1393: my ($r) = @_;
1394: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1395: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1396: my (%can_request,%request_doms);
1397: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1398: if (keys(%request_doms) > 0) {
1399: my ($types,$typename) = &Apache::loncommon::course_types();
1400: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1401: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1402: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1403: my (@reqdoms,@reqtypes);
1404: foreach my $type (sort(keys(%request_doms))) {
1405: push(@reqtypes,$type);
1406: if (ref($request_doms{$type}) eq 'ARRAY') {
1407: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1408: $r->print(
1409: '<li>'
1410: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1411: '<i>',
1412: '</i>',
1413: '<b>'.$domstr.'</b>')
1414: .'</li>'
1415: );
1.234 raeburn 1416: foreach my $dom (@{$request_doms{$type}}) {
1417: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1418: push(@reqdoms,$dom);
1419: }
1420: }
1421: }
1422: }
1423: my @showtypes;
1424: foreach my $type (@{$types}) {
1425: if (grep(/^\Q$type\E$/,@reqtypes)) {
1426: push(@showtypes,$type);
1427: }
1428: }
1429: my $requrl = '/adm/requestcourse';
1430: if (@reqdoms == 1) {
1431: $requrl .= '?showdom='.$reqdoms[0];
1432: }
1433: if (@showtypes > 0) {
1434: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1435: }
1436: if (@reqdoms == 1 || @showtypes > 0) {
1437: $requrl .= '&state=crstype&action=new';
1438: }
1439: $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>');
1440: }
1441: }
1442: return;
1443: }
1444:
1.175 albertel 1445: sub privileges_info {
1446: my ($which) = @_;
1447: my $output;
1448:
1449: $which ||= $env{'request.role'};
1450:
1451: foreach my $envkey (sort(keys(%env))) {
1452: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1453:
1454: my $where=$1;
1455: my $ttype;
1456: my $twhere;
1457: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1458: if ($trest) {
1459: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1460: $ttype='Construction Space';
1461: $twhere='User: '.$trest.', Domain: '.$tdom;
1462: } else {
1463: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1464: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1465: if ($tsec) {
1466: my $sec_type = 'Section';
1467: if (exists($env{"user.role.gr.$where"})) {
1468: $sec_type = 'Group';
1469: }
1470: $twhere.=' ('.$sec_type.': '.$tsec.')';
1471: }
1472: }
1473: } elsif ($tdom) {
1474: $ttype='Domain';
1475: $twhere=$tdom;
1476: } else {
1477: $ttype='System';
1478: $twhere='/';
1479: }
1.204 bisitz 1480: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1481: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1482: next if (!$priv);
1483:
1484: my ($prv,$restr)=split(/\&/,$priv);
1485: my $trestr='';
1486: if ($restr ne 'F') {
1487: $trestr.=' ('.
1488: join(', ',
1489: map { &Apache::lonnet::plaintext($_) }
1490: (split('',$restr))).') ';
1491: }
1492: $output .= "\n\t".
1493: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1494: }
1495: $output .= "\n".'</ul>';
1496: }
1497: return $output;
1498: }
1499:
1.110 raeburn 1500: sub build_roletext {
1.254 raeburn 1501: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1502: my ($roletext,$roletext_end);
1.132 albertel 1503: my $is_dc=($trolecode =~ m/^dc\./);
1504: my $rowspan=($is_dc) ? ''
1505: : ' rowspan="2" ';
1506:
1.110 raeburn 1507: unless ($nochoose) {
1.134 www 1508: my $buttonname=$trolecode;
1509: $buttonname=~s/\W//g;
1.110 raeburn 1510: if (!$button) {
1511: if ($switchserver) {
1.212 bisitz 1512: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1513: .'<a href="/adm/switchserver?'.$switchserver.'">'
1514: .&mt('Switch Server')
1515: .'</a></td>';
1.110 raeburn 1516: } else {
1.212 bisitz 1517: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1518: }
1.255 raeburn 1519: if ($switchwarning) {
1520: if ($tremark eq '') {
1521: $tremark = $switchwarning;
1522: } else {
1523: $tremark .= '<br />'.$switchwarning;
1524: }
1525: }
1.110 raeburn 1526: } elsif ($tstatus eq 'is') {
1.212 bisitz 1527: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1528: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1529: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1530: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1531: } elsif ($tryagain) {
1532: $roletext.=
1.212 bisitz 1533: '<td'.$rowspan.' class="'.$tbg.'">'.
1534: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1535: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1536: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1537: } elsif ($advanced) {
1538: $roletext.=
1.212 bisitz 1539: '<td'.$rowspan.' class="'.$tbg.'">'.
1540: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1541: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1542: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1543: } elsif ($reinit) {
1544: $roletext.=
1.212 bisitz 1545: '<td'.$rowspan.' class="'.$tbg.'">'.
1546: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1547: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1548: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1549: } else {
1.209 raeburn 1550: $roletext.=
1.212 bisitz 1551: '<td'.$rowspan.' class="'.$tbg.'">'.
1552: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1553: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1554: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1555: }
1556: }
1.165 albertel 1557: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1558: $tremark.=&Apache::lonannounce::showday(time,1,
1559: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1560: }
1.212 bisitz 1561: $roletext.='<td>'.$trole.'</td>'
1562: .'<td>'.$twhere.'</td>'
1563: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1564: .'<td>'.$tpend.'</td>';
1.132 albertel 1565: if (!$is_dc) {
1.223 raeburn 1566: $roletext_end = '<td colspan="4">'.
1567: $tremark.' '.
1568: '</td>';
1.132 albertel 1569: }
1.223 raeburn 1570: return ($roletext,$roletext_end);
1.110 raeburn 1571: }
1572:
1.202 raeburn 1573: sub check_needs_switchserver {
1574: my ($possiblerole) = @_;
1575: my $needs_switchserver;
1576: my ($role,$where) = split(/\./,$possiblerole,2);
1577: my (undef,$tdom,$twho) = split(/\//,$where);
1578: my ($server_status,$home);
1579: if (($role eq 'ca') || ($role eq 'aa')) {
1580: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1581: } else {
1582: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1583: $env{'user.domain'});
1584: }
1585: if ($server_status eq 'switchserver') {
1586: $needs_switchserver = 1;
1587: }
1588: return $needs_switchserver;
1589: }
1590:
1.193 raeburn 1591: sub check_author_homeserver {
1.183 www 1592: my ($uname,$udom)=@_;
1.193 raeburn 1593: if (($uname eq '') || ($udom eq '')) {
1594: return ('fail','');
1595: }
1.183 www 1596: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1597: if (&Apache::lonnet::host_domain($home) ne $udom) {
1598: return ('fail',$home);
1599: }
1.183 www 1600: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1601: if (grep(/^\Q$home\E$/,@ids)) {
1602: return ('ok',$home);
1603: } else {
1604: return ('switchserver',$home);
1.183 www 1605: }
1606: }
1607:
1.104 raeburn 1608: sub check_fordc {
1.260 raeburn 1609: my ($dcroles,$update,$then) = @_;
1.104 raeburn 1610: my $numdc = 0;
1.118 albertel 1611: if ($env{'user.adv'}) {
1612: foreach my $envkey (sort keys %env) {
1.170 albertel 1613: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1614: my $dcdom = $1;
1615: my $livedc = 1;
1.118 albertel 1616: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1617: my $limit = $update;
1618: if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
1619: $limit = $then;
1620: }
1621: if ($tstart && $tstart>$limit) { $livedc = 0; }
1622: if ($tend && $tend <$limit) { $livedc = 0; }
1.104 raeburn 1623: if ($livedc) {
1624: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1625: $numdc++;
1.104 raeburn 1626: }
1627: }
1628: }
1629: }
1630: return $numdc;
1631: }
1632:
1.185 raeburn 1633: sub adhoc_course_role {
1.260 raeburn 1634: my ($refresh,$update,$then) = @_;
1.239 raeburn 1635: my ($cdom,$cnum,$crstype);
1.201 raeburn 1636: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1637: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1638: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1639: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1640: my $setprivs;
1.198 raeburn 1641: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1642: $setprivs = 1;
1643: } else {
1.198 raeburn 1644: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1645: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1646: ($end && $end<$update)) {
1.185 raeburn 1647: $setprivs = 1;
1648: }
1.232 raeburn 1649: }
1.185 raeburn 1650: if ($setprivs) {
1.198 raeburn 1651: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1652: my $role = $1;
1653: my $custom_role = $2;
1654: my $usec = $3;
1655: if ($role eq 'cr') {
1.199 raeburn 1656: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1657: $role .= $custom_role;
1658: } else {
1659: return;
1660: }
1661: }
1.208 raeburn 1662: my (%userroles,%newrole,%newgroups,%group_privs);
1663: my %cgroups =
1664: &Apache::lonnet::get_active_groups($env{'user.domain'},
1665: $env{'user.name'},$cdom,$cnum);
1666: foreach my $group (keys(%cgroups)) {
1667: $group_privs{$group} =
1668: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1669: }
1670: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1671: my $area = '/'.$cdom.'/'.$cnum;
1672: my $spec = $role.'.'.$area;
1673: if ($usec ne '') {
1674: $spec .= '/'.$usec;
1675: $area .= '/'.$usec;
1676: }
1677: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1678: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1679: my $adhocstart = $refresh-1;
1.185 raeburn 1680: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1681: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1682: }
1683: }
1684: }
1685: return;
1686: }
1687:
1688: sub check_forcc {
1.260 raeburn 1689: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1690: my ($is_cc,$ccrole);
1691: if ($crstype eq 'Community') {
1692: $ccrole = 'co';
1693: } else {
1694: $ccrole = 'cc';
1695: }
1.266 droeschl 1696: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1697: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1698: if (defined($env{$envkey})) {
1699: $is_cc = 1;
1700: my ($tstart,$tend)=split(/\./,$env{$envkey});
1701: my $limit = $update;
1702: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1703: $limit = $then;
1.185 raeburn 1704: }
1.266 droeschl 1705: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1706: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1707: }
1708: }
1709: return $is_cc;
1710: }
1711:
1.254 raeburn 1712: sub check_release_required {
1.255 raeburn 1713: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1714: my ($switchserver,$warning);
1.255 raeburn 1715: if ($required ne '') {
1716: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.257 raeburn 1717: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1718: if ($reqdmajor ne '' && $reqdminor ne '') {
1719: my $otherserver;
1720: if (($major eq '' && $minor eq '') ||
1721: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1722: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1723: my $switchlcrev =
1724: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1725: $userdomserver);
1.257 raeburn 1726: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1727: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1728: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1729: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1730: if ($cdom ne $env{'user.domain'}) {
1731: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1732: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1733: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1734: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1735: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1736: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1737: my $canhost =
1738: &Apache::lonnet::can_host_session($env{'user.domain'},
1739: $coursedomserver,
1740: $remoterev,
1741: $udomdefaults{'remotesessions'},
1742: $defdomdefaults{'hostedsessions'});
1743:
1744: if ($canhost) {
1745: $otherserver = $coursedomserver;
1746: } else {
1747: $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.");
1748: }
1749: } else {
1750: $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).");
1751: }
1752: } else {
1753: $otherserver = $userdomserver;
1754: }
1755: }
1756: if ($otherserver ne '') {
1757: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1758: }
1759: }
1760: }
1761: return ($switchserver,$warning);
1762: }
1763:
1.108 raeburn 1764: sub courselink {
1.193 raeburn 1765: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1766: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1767: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1768: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1769: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1770: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1771: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1772: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1773: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1774: return $courseform.$hiddenitems;
1.109 raeburn 1775: }
1776:
1777: sub coursepick_jscript {
1.184 raeburn 1778: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1779: 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 1780: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1781: );
1.104 raeburn 1782: my $verify_script = <<"END";
1.179 raeburn 1783: <script type="text/javascript">
1.225 bisitz 1784: // <![CDATA[
1.108 raeburn 1785: function verifyCoursePick(caller) {
1786: var numbutton = getIndex(caller)
1.112 raeburn 1787: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1788: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1789: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1790: if (pickedCourse != '') {
1.108 raeburn 1791: if (numbutton != -1) {
1792: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1793: document.rolechoice.elements[numbutton+1].name = courseTarget
1794: document.rolechoice.submit()
1795: }
1.104 raeburn 1796: }
1797: else {
1.184 raeburn 1798: alert("$lt{'plsu'}");
1.104 raeburn 1799: }
1800: }
1801: else {
1.184 raeburn 1802: alert("$lt{'youc'}")
1.104 raeburn 1803: }
1804: }
1.109 raeburn 1805: function getIndex(caller) {
1.108 raeburn 1806: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1807: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1808: return i;
1809: }
1810: }
1811: return -1;
1812: }
1.225 bisitz 1813: // ]]>
1.104 raeburn 1814: </script>
1815: END
1.109 raeburn 1816: return $verify_script;
1.104 raeburn 1817: }
1818:
1.193 raeburn 1819: sub coauthorlink {
1820: my ($dcdom,$rowtype) = @_;
1821: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1822: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1823: return $coauthorform.$hiddenitems;
1824: }
1825:
1.113 raeburn 1826: sub display_cc_role {
1827: my $rolekey = shift;
1.223 raeburn 1828: my ($roletext,$roletext_end);
1.118 albertel 1829: my $advanced = $env{'user.adv'};
1830: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1831: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1832: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1833: my $ccrole = $1;
1.249 raeburn 1834: my $tdom = $2;
1835: my $trest = $3;
1836: my $tcourseid = $tdom.'_'.$trest;
1837: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1838: my $twhere;
1.152 raeburn 1839: my $ttype;
1.212 bisitz 1840: my $tbg='LC_roles_is';
1.113 raeburn 1841: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1842: if (%newhash) {
1843: $twhere=$newhash{'description'}.
1.261 bisitz 1844: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1845: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1846: '</span>';
1.153 raeburn 1847: $ttype = $newhash{'type'};
1.113 raeburn 1848: } else {
1849: $twhere=&mt('Currently not available');
1.118 albertel 1850: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1851: }
1.242 raeburn 1852: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1853: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1854: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1855: }
1856: }
1.223 raeburn 1857: return ($roletext,$roletext_end);
1.104 raeburn 1858: }
1859:
1.192 raeburn 1860: sub adhoc_roles_row {
1.138 raeburn 1861: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1862: my $output = &Apache::loncommon::continue_data_table_row()
1863: .' <td colspan="5">'
1864: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1865: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1866: .' ';
1.193 raeburn 1867: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1868: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1869: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1870: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1871: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1872: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1873: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1874: return $output;
1875: }
1876:
1.104 raeburn 1877: sub recent_filename {
1878: my $area=shift;
1.149 www 1879: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1880: }
1881:
1.139 raeburn 1882: sub courseloadpage {
1883: my ($courseid) = @_;
1884: my $startpage;
1.144 albertel 1885: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1886: [$courseid.':courseinit']);
1.139 raeburn 1887: my ($tmp) = %entry_settings;
1.144 albertel 1888: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1889: $startpage = $entry_settings{$courseid.':courseinit'};
1890: }
1891: if ($startpage eq '') {
1892: if (exists($env{'environment.course_init_display'})) {
1893: $startpage = $env{'environment.course_init_display'};
1894: }
1895: }
1896: return $startpage;
1897: }
1898:
1.260 raeburn 1899: sub update_session_roles {
1900: my $then=$env{'user.login.time'};
1901: my $refresh=$env{'user.refresh.time'};
1902: if (!$refresh) {
1903: $refresh = $then;
1904: }
1905: my $update = $env{'user.update.time'};
1906: if (!$update) {
1907: $update = $then;
1908: }
1909: my $now = time;
1910: my %roleshash =
1911: &Apache::lonnet::get_my_roles('','','userroles',
1912: ['active','future','previous'],
1913: undef,undef,1);
1914: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1915: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1916: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1917: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1918: @rolecodes);
1919: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1920: my %courseroles;
1921: foreach my $item (keys(%roleshash)) {
1922: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1923: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1924: my ($section,$group,@group_privs);
1925: if ($role =~ m{^gr/(\w*)$}) {
1926: $role = 'gr';
1927: my $priv = $1;
1928: next if ($tstart eq '-1');
1929: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1930: if ($priv ne '') {
1931: push(@group_privs,$priv);
1932: }
1933: }
1934: if ($remainder =~ /:/) {
1935: (my $additional_privs,$group) =
1936: ($remainder =~ /^([\w:]+):([^:]+)$/);
1937: if ($additional_privs ne '') {
1938: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1939: push(@group_privs,split(/:/,$additional_privs));
1940: @group_privs = sort(@group_privs);
1941: }
1942: }
1943: } else {
1944: $group = $remainder;
1945: }
1946: } else {
1947: $section = $remainder;
1948: }
1949: my $where = "/$udom/$uname";
1950: if ($section ne '') {
1951: $where .= "/$section";
1952: } elsif ($group ne '') {
1953: $where .= "/$group";
1954: }
1955: my $rolekey = "$role.$where";
1956: my $envkey = "user.role.$rolekey";
1957: $dbroles{$envkey} = 1;
1958: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
1959: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
1960: $currrole_expired = 1;
1961: }
1962: }
1963: if ($env{$envkey} eq '') {
1964: my $status_in_db =
1.271 raeburn 1965: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 1966: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
1967: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
1968: if ($status_in_db eq 'active') {
1969: if ($section eq '') {
1970: push(@newsec,'none');
1971: } else {
1972: push(@newsec,$section);
1973: }
1974: }
1975: } else {
1976: unless (grep(/^\Q$role\E$/,@changed_roles)) {
1977: push(@changed_roles,$role);
1978: }
1979: if ($status_in_db ne 'previous') {
1980: if ($role eq 'gr') {
1981: $newgroup{$rolekey} = $status_in_db;
1982: if ($status_in_db eq 'active') {
1983: unless (ref($courseroles{$udom}) eq 'HASH') {
1984: %{$courseroles{$udom}} =
1985: &Apache::lonnet::get_my_roles('','','userroles',
1986: ['active'],\@possroles,
1987: [$udom],1);
1988: }
1989: &Apache::lonnet::get_groups_roles($udom,$uname,
1990: $courseroles{$udom},
1991: \@rolecodes,\%groups_roles);
1992: }
1993: } else {
1994: $newrole{$rolekey} = $status_in_db;
1995: }
1996: }
1997: }
1998: } else {
1999: my ($currstart,$currend) = split(/\./,$env{$envkey});
2000: if ($role eq 'gr') {
2001: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2002: $hasgroups = 1;
2003: }
2004: }
2005: if (($currstart ne $tstart) || ($currend ne $tend)) {
2006: my $status_in_env =
2007: &curr_role_status($currstart,$currend,$refresh,$update);
2008: my $status_in_db =
1.271 raeburn 2009: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2010: if ($status_in_env ne $status_in_db) {
2011: if ($status_in_env eq 'active') {
2012: if ($role eq 'st') {
2013: if ($env{'request.role'} eq $rolekey) {
2014: my $switchsection;
2015: unless (ref($courseroles{$udom}) eq 'HASH') {
2016: %{$courseroles{$udom}} =
2017: &Apache::lonnet::get_my_roles('','','userroles',
2018: ['active'],
2019: \@possroles,[$udom],1);
2020: }
2021: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2022: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2023: $switchsection = 1;
2024: last;
2025: }
2026: }
2027: if ($switchsection) {
2028: if ($section eq '') {
2029: $oldsec = 'none';
2030: } else {
2031: $oldsec = $section;
2032: }
2033: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2034: } else {
2035: $currrole_expired = 1;
2036: next;
2037: }
2038: }
2039: }
2040: unless ($rolekey eq $env{'request.role'}) {
2041: if ($role eq 'gr') {
2042: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2043: } else {
2044: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2045: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2046: }
2047: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2048: }
2049: } elsif ($status_in_db eq 'active') {
2050: if (($role eq 'st') &&
2051: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2052: if ($section eq '') {
2053: push(@newsec,'none');
2054: } else {
2055: push(@newsec,$section);
2056: }
2057: } elsif ($role eq 'gr') {
2058: unless (ref($courseroles{$udom}) eq 'HASH') {
2059: %{$courseroles{$udom}} =
2060: &Apache::lonnet::get_my_roles('','','userroles',
2061: ['active'],
2062: \@possroles,[$udom],1);
2063: }
2064: &Apache::lonnet::get_groups_roles($udom,$uname,
2065: $courseroles{$udom},
2066: \@rolecodes,\%groups_roles);
2067: }
2068: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2069: }
2070: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2071: push(@changed_roles,$role);
2072: }
2073: if ($role eq 'gr') {
2074: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2075: } else {
2076: $rolechange{$rolekey} = $status_in_db;
2077: }
2078: }
2079: } else {
2080: if ($role eq 'gr') {
2081: unless ($checkedgroup{$where}) {
2082: my $status_in_db =
2083: &curr_role_status($tstart,$tend,$refresh,$now);
2084: if ($tstart eq '-1') {
2085: $status_in_db = 'deleted';
2086: }
2087: unless (ref($courseroles{$udom}) eq 'HASH') {
2088: %{$courseroles{$udom}} =
2089: &Apache::lonnet::get_my_roles('','','userroles',
2090: ['active'],
2091: \@possroles,[$udom],1);
2092: }
2093: if (ref($courseroles{$udom}) eq 'HASH') {
2094: foreach my $item (keys(%{$courseroles{$udom}})) {
2095: next unless ($item =~ /^\Q$uname\E/);
2096: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2097: my $area = '/'.$cdom.'/'.$cnum;
2098: if ($crssec ne '') {
2099: $area .= '/'.$crssec;
2100: }
2101: my $crsrolekey = $crsrole.'.'.$area;
2102: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2103: $currprivs =~ s/^://;
2104: $currprivs =~ s/\&F$//;
2105: my @curr_grp_privs = split(/\&F:/,$currprivs);
2106: @curr_grp_privs = sort(@curr_grp_privs);
2107: my @diffs;
2108: if (@group_privs > 0 || @curr_grp_privs > 0) {
2109: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2110: }
2111: if (@diffs == 0) {
2112: last;
2113: } else {
2114: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2115: push(@rolecodes,'gr');
2116: }
2117: &gather_roleprivs(\%allroles,\%allgroups,
2118: \%userroles,$where,$role,
2119: $tstart,$tend,$status_in_db);
2120: if ($status_in_db eq 'active') {
2121: &Apache::lonnet::get_groups_roles($udom,$uname,
2122: $courseroles{$udom},
2123: \@rolecodes,\%groups_roles);
2124: }
2125: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2126: last;
2127: }
2128: }
2129: }
2130: $checkedgroup{$where} = 1;
2131: }
2132: } elsif ($role =~ /^cr/) {
2133: my $status_in_db =
2134: &curr_role_status($tstart,$tend,$refresh,$now);
2135: my ($rdummy,$rest) = split(/\//,$role,2);
2136: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
2137: my %currpriv;
2138: unless (exists($crprivs{$rest})) {
2139: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2140: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2141: if (&Apache::lonnet::hostname($homsvr) ne '') {
2142: my ($rdummy,$roledef)=
2143: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2144: $rdomain,$rauthor);
2145: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2146: my $i = 0;
2147: my @scopes = ('sys','dom','crs');
2148: my @privs = split(/\_/,$roledef);
2149: foreach my $priv (@privs) {
2150: my ($blank,@prv) = split(/:/,$priv);
2151: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2152: if (@prv) {
2153: $priv = ':'.join(':',sort(@prv));
2154: }
1.260 raeburn 2155: $crprivs{$rest}{$scopes[$i]} = $priv;
2156: $i++;
2157: }
2158: }
2159: }
2160: }
2161: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2162: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2163: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2164: if (keys(%crprivs)) {
2165: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2166: ($crprivs{$rest}{dom} ne $currpriv{dom})
2167: ||
2168: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2169: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2170: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2171: push(@changed_roles,$role);
2172: }
2173: my $status_in_env =
2174: &curr_role_status($currstart,$currend,$refresh,$update);
2175: if ($status_in_env eq 'active') {
2176: $customprivchg{$rolekey} = $status_in_env;
2177: }
2178: }
2179: }
2180: }
2181: }
2182: }
2183: }
2184: foreach my $envkey (keys(%env)) {
2185: next unless ($envkey =~ /^user\.role\./);
2186: next if ($dbroles{$envkey});
2187: next if ($envkey eq 'user.role.'.$env{'request.role'});
2188: my ($currstart,$currend) = split(/\./,$env{$envkey});
2189: my $status_in_env =
2190: &curr_role_status($currstart,$currend,$refresh,$update);
2191: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2192: my ($role,$rest)=split(/\./,$rolekey,2);
2193: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2194: if ($status_in_env eq 'active') {
2195: if ($role eq 'gr') {
2196: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2197: \@possroles);
2198: } else {
2199: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2200: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2201: }
2202: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2203: push(@changed_roles,$role);
2204: }
2205: $deletedroles{$rolekey} = 1;
2206: }
2207: }
2208: }
2209: if (($oldsec) && (@newsec > 0)) {
2210: if (@newsec > 1) {
2211: $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>';
2212: } else {
2213: my $newrole = $env{'request.role'};
2214: if ($newsec[0] eq 'none') {
2215: $newrole =~ s{(/[^/])$}{};
2216: } elsif ($oldsec eq 'none') {
2217: $newrole .= '/'.$newsec[0];
2218: } else {
2219: $newrole =~ s{([^/]+)$}{$newsec[0]};
2220: }
2221: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2222: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2223: my %temp=('logout_'.$env{'request.course.id'} => time);
2224: &Apache::lonnet::put('email_status',\%temp);
2225: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2226: &Apache::lonnet::appenv({"request.course.id" => '',
2227: "request.course.fn" => '',
2228: "request.course.uri" => '',
2229: "request.course.sec" => '',
2230: "request.role" => 'cm',
2231: "request.role.adv" => $env{'user.adv'},
2232: "request.role.domain" => $env{'user.domain'}});
2233: my $rolename = &Apache::loncommon::plainname($curr_role);
2234: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2235: '<input type="hidden" name="newrole" value="" />'.
2236: '<input type="hidden" name="selectrole" value="1" />'.
2237: '<span class="LC_info">'.
2238: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2239: my $button = '<input type="button" name="sectionchanged" value="'.
2240: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2241: if ($newsec[0] eq 'none') {
2242: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2243: } else {
2244: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2245: }
2246: $msg .= '</form></p>';
2247: }
2248: } elsif ($currrole_expired) {
2249: $msg .= '<div class="LC_warning">';
2250: if (&Apache::loncommon::show_course()) {
2251: $msg .= &mt('Your role in the current course has expired.');
2252: } else {
2253: $msg .= &mt('Your current role has expired.');
2254: }
2255: $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>';
2256: }
2257: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2258: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2259: if (!@changed_roles) {
2260: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2261: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2262: } else {
1.264 raeburn 2263: $rolesmsg = &mt('No role changes');
1.260 raeburn 2264: }
2265: }
2266: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2267: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2268: }
2269: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2270: if (($msg ne '') || ($groupsmsg ne '')) {
2271: $msg .= '<ul>';
2272: if ($rolesmsg) {
2273: $msg .= '<li>'.$rolesmsg.'</li>';
2274: }
2275: if ($groupsmsg) {
2276: $msg .= '<li>'.$groupsmsg.'</li>';
2277: }
2278: $msg .= '</ul>';
2279: } else {
1.270 raeburn 2280: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2281: }
1.260 raeburn 2282: return $msg;
2283: }
2284: }
2285: my $changemsg;
2286: if (@changed_roles > 0) {
2287: if (keys(%newgroup) > 0) {
2288: my $groupmsg;
2289: foreach my $item (sort(keys(%newgroup))) {
2290: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
2291: $groupmsg .= '<li>'.
2292: &mt('[_1] with status: [_2].',
2293: $item,$newgroup{$item}).'</li>';
2294: }
2295: }
2296: if ($groupmsg) {
2297: $changemsg .= '<li>'.
2298: &mt('Courses with new groups').'</li>'.
2299: '<ul>'.$groupmsg.'</ul></li>';
2300: }
2301: }
2302: if (keys(%newrole) > 0) {
2303: $changemsg .= '<li>'.&mt('New roles').
2304: '<ul>';
2305: foreach my $item (sort(keys(%newrole))) {
2306: $changemsg .= '<li>'.
2307: &mt('[_1] with status: [_2].',
2308: $item,$newrole{$item}).'</li>';
2309: }
2310: $changemsg .= '</ul></li>';
2311: }
2312: if (keys(%customprivchg) > 0) {
2313: $changemsg .= '<li>'.
2314: &mt('Custom roles with privilege changes').
2315: '<ul>';
2316: foreach my $item (sort(keys(%customprivchg))) {
2317: $changemsg .= '<li>'.$item.'</li>';
2318: }
2319: $changemsg .= '</ul></li>';
2320: }
2321: if (keys(%rolechange) > 0) {
2322: $changemsg .= '<li>'.
2323: &mt('Existing roles with status changes').'</li>'.
2324: '<ul>';
2325: foreach my $item (sort(keys(%rolechange))) {
2326: $changemsg .= '<li>'.
2327: &mt('[_1] status now: [_2].',$item,
2328: $rolechange{$item}).'</li>';
2329: }
2330: $changemsg .= '</ul></li>';
2331: }
2332: if (keys(%deletedroles) > 0) {
2333: $changemsg .= '<li>'.
1.268 raeburn 2334: &mt('Existing roles now expired').'</li>'.
1.260 raeburn 2335: '<ul>';
2336: foreach my $item (sort(keys(%deletedroles))) {
2337: $changemsg .= '<li>'.$item.'</li>';
2338: }
2339: $changemsg .= '</ul></li>';
2340: }
2341: }
2342: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2343: my $groupchgmsg;
2344: foreach my $key (sort(keys(%changed_groups))) {
2345: my $crs = 'gr/'.$key;
2346: $crs =~ s/_/\//;
2347: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2348: if (ref($changed_groups{$key}) eq 'HASH') {
2349: my @showgroups;
2350: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2351: if ($changed_groups{$key}{$group} eq 'active') {
2352: push(@showgroups,$group);
2353: }
2354: }
2355: if (@showgroups > 0) {
2356: $groupchgmsg .= '<li>'.
2357: &mt('Course: [_1], groups: [_2].',$key,
2358: join(', ',@showgroups)).
2359: '</li>';
2360: }
2361: }
2362: }
2363: }
2364: if (keys(%groupchange) > 0) {
2365: $groupchgmsg .= '<li>'.
2366: &mt('Existing course/community groups with status changes').'</li>'.
2367: '<ul>';
2368: foreach my $crs (sort(keys(%groupchange))) {
2369: if (ref($groupchange{$crs}) eq 'HASH') {
2370: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crs.'</b><ul>');
2371: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
2372: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$group.'</b>',$groupchange{$crs}{$group}).'</li>';
2373: }
2374: $groupchgmsg .= '</ul></li>';
2375: }
2376: }
2377: $groupchgmsg .= '</ul></li>';
2378: }
2379: if ($groupchgmsg) {
2380: $changemsg .= '<li>'.
2381: &mt('Courses with changes in groups').'</li>'.
2382: '<ul>'.$groupchgmsg.'</ul></li>';
2383: }
2384: }
2385: if ($changemsg) {
2386: $msg .= '<ul>'.$changemsg.'</ul>';
2387: }
2388: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2389: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2390: $curr_author = $env{'user.author'};
2391: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2392: ($env{'request.role'} =~/^aa/)) {
2393: $curr_role_author=1;
2394: }
2395: $curr_is_adv = $env{'user.adv'};
2396: $curr_role_adv = $env{'request.role.adv'};
2397: if (keys(%userroles) > 0) {
2398: foreach my $role (@changed_roles) {
2399: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2400: push(@rolecodes,$role);
2401: }
2402: }
2403: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2404: push(@rolecodes,'cm');
2405: }
2406: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2407: }
2408: my %newenv;
2409: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2410: unless ($curr_is_adv) {
2411: $newenv{'user.adv'} = 1;
2412: }
2413: } elsif ($curr_is_adv && !$curr_role_adv) {
2414: &Apache::lonnet::delenv('user.adv');
2415: }
2416: my %authorroleshash =
2417: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2418: if (keys(%authorroleshash)) {
2419: unless ($curr_author) {
2420: $newenv{'user.author'} = 1;
2421: }
2422: } elsif ($curr_author && !$curr_role_author) {
2423: &Apache::lonnet::delenv('user.author');
2424: }
2425: if ($env{'request.course.id'}) {
2426: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2427: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2428: my (@activecrsgroups,$crsgroupschanged);
2429: if ($env{'request.course.groups'}) {
2430: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2431: foreach my $item (keys(%deletedroles)) {
2432: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2433: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2434: $crsgroupschanged = 1;
2435: last;
2436: }
2437: }
2438: }
2439: }
2440: unless ($crsgroupschanged) {
2441: foreach my $item (keys(%newgroup)) {
2442: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2443: if ($newgroup{$item} eq 'active') {
2444: $crsgroupschanged = 1;
2445: last;
2446: }
2447: }
2448: }
2449: }
2450: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2451: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2452: ($crsgroupschanged)) {
2453: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2454: ['active'],['gr'],[$cdom],1);
2455: my @activegroups;
2456: foreach my $item (keys(%grouproles)) {
2457: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2458: my $group;
2459: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2460: if ($remainder =~ /:/) {
2461: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2462: } else {
2463: $group = $remainder;
2464: }
2465: if ($group ne '') {
2466: push(@activegroups,$group);
2467: }
2468: }
2469: $newenv{'request.course.groups'} = join(':',@activegroups);
2470: }
2471: }
2472: if (keys(%newenv)) {
2473: &Apache::lonnet::appenv(\%newenv);
2474: }
2475: return $msg;
2476: }
2477:
2478: sub curr_role_status {
2479: my ($start,$end,$refresh,$update) = @_;
2480: if (($start) && ($start<0)) { return 'deleted' };
2481: my $status = 'active';
2482: if (($end) && ($end<=$update)) {
2483: $status = 'previous';
2484: }
2485: if (($start) && ($refresh<$start)) {
2486: $status = 'future';
2487: }
2488: return $status;
2489: }
2490:
2491: sub gather_roleprivs {
2492: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2493: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2494: if (($area ne '') && ($role ne '')) {
2495: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2496: $area,$tstart,$tend);
2497: my $spec=$role.'.'.$area;
2498: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2499: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2500: if ($status eq 'active') {
2501: if ($role =~ /^cr\//) {
2502: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2503: } elsif ($role eq 'gr') {
2504: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2505: $env{'user.domain'},
2506: $env{'user.name'});
2507: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2508: (undef,my $group_privs) = split(/\//,$trole);
2509: $group_privs = &unescape($group_privs);
2510: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2511: } else {
2512: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2513: }
2514: }
2515: }
2516: return;
2517: }
2518:
2519: sub is_active_course {
2520: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2521: return unless(ref($roleshashref) eq 'HASH');
2522: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2523: my $is_active;
2524: foreach my $key (keys(%{$roleshashref})) {
2525: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2526: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2527: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2528: if ($status eq 'active') {
2529: $is_active = 1;
2530: last;
2531: }
2532: }
2533: }
2534: return $is_active;
2535: }
2536:
1.1 harris41 2537: 1;
2538: __END__
1.32 harris41 2539:
2540: =head1 NAME
2541:
2542: Apache::lonroles - User Roles Screen
2543:
2544: =head1 SYNOPSIS
2545:
2546: Invoked by /etc/httpd/conf/srm.conf:
2547:
2548: <Location /adm/roles>
2549: PerlAccessHandler Apache::lonacc
2550: SetHandler perl-script
2551: PerlHandler Apache::lonroles
2552: ErrorDocument 403 /adm/login
2553: ErrorDocument 500 /adm/errorhandler
2554: </Location>
1.64 bowersj2 2555:
2556: =head1 OVERVIEW
2557:
2558: =head2 Choosing Roles
2559:
2560: C<lonroles> is a handler that allows a user to switch roles in
2561: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2562: default role that a user has before selecting a role, as widely as
2563: possible, but certain handlers for example need specification which
2564: course they should act on, etc. Both in this scenario, and when the
2565: handler determines via C<lonnet>'s C<&allowed> function that a certain
2566: action is not allowed, C<lonroles> is used as error handler. This
2567: allows the user to select another role which may have permission to do
1.246 droeschl 2568: what they were trying to do.
1.64 bowersj2 2569:
2570: =begin latex
2571:
2572: \begin{figure}
2573: \begin{center}
2574: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2575: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2576: \end{center}
2577: \end{figure}
2578:
2579: =end latex
2580:
2581: =head2 Role Initialization
2582:
2583: 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 2584:
2585: =head1 INTRODUCTION
2586:
2587: This module enables a user to select what role he wishes to
2588: operate under (instructor, student, teaching assistant, course
2589: coordinator, etc). These roles are pre-established by the actions
2590: of upper-level users.
2591:
2592: This is part of the LearningOnline Network with CAPA project
2593: described at http://www.lon-capa.org.
2594:
2595: =head1 HANDLER SUBROUTINE
2596:
2597: This routine is called by Apache and mod_perl.
2598:
2599: =over 4
2600:
2601: =item *
2602:
2603: Roles Initialization (yes/no)
2604:
2605: =item *
2606:
2607: Get Error Message from Environment
2608:
2609: =item *
2610:
2611: Who is this?
2612:
2613: =item *
2614:
2615: Generate Page Output
2616:
2617: =item *
2618:
2619: Choice or no choice
2620:
2621: =item *
2622:
2623: Table
2624:
2625: =item *
2626:
2627: Privileges
2628:
2629: =back
2630:
2631: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>