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