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