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