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