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