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