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