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