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