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