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