File:
[LON-CAPA] /
loncom /
auth /
lonroles.pm
Revision
1.255:
download - view:
text,
annotated -
select for diffs
Fri Jul 30 20:35:16 2010 UTC (14 years ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Check if required LON-CAPA release needs updating
when re-initializing course after editing course.
- When processing selected role in a course, check if
server's LON-CAPA version is compatible with version
required for course.
1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.255 2010/07/30 20:35:16 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: if (!$refresh) {
207: $refresh = $then;
208: }
209: my $envkey;
210: my %dcroles = ();
211: my $numdc = &check_fordc(\%dcroles,$then);
212: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
213: my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
214:
215: # ================================================================== Roles Init
216: if ($env{'form.selectrole'}) {
217:
218: my $locknum=&Apache::lonnet::get_locks();
219: if ($locknum) { return 409; }
220:
221: if ($env{'form.newrole'}) {
222: $env{'form.'.$env{'form.newrole'}}=1;
223: }
224: if ($env{'request.course.id'}) {
225: # Check if user is CC trying to select a course role
226: if ($env{'form.switchrole'}) {
227: my $switch_is_active;
228: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
229: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
230: if (!$end || $end > $now) {
231: if (!$start || $start < $refresh) {
232: $switch_is_active = 1;
233: }
234: }
235: }
236: unless ($switch_is_active) {
237: &adhoc_course_role($refresh,$then);
238: }
239: }
240: my %temp=('logout_'.$env{'request.course.id'} => time);
241: &Apache::lonnet::put('email_status',\%temp);
242: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
243: }
244: &Apache::lonnet::appenv({"request.course.id" => '',
245: "request.course.fn" => '',
246: "request.course.uri" => '',
247: "request.course.sec" => '',
248: "request.role" => 'cm',
249: "request.role.adv" => $env{'user.adv'},
250: "request.role.domain" => $env{'user.domain'}});
251: # Check if user is a DC trying to enter a course or author space and needs privs to be created
252: if ($numdc > 0) {
253: foreach my $envkey (keys %env) {
254: # Is this an ad-hoc Coordinator role?
255: if (my ($ccrole,$domain,$coursenum) =
256: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
257: if ($dcroles{$domain}) {
258: &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
259: $then,$refresh,$now,$ccrole);
260: }
261: last;
262: }
263: # Is this an ad-hoc CA-role?
264: if (my ($domain,$user) =
265: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
266: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
267: delete($env{$envkey});
268: $env{'form.au./'.$domain.'/'} = 1;
269: my ($server_status,$home) = &check_author_homeserver($user,$domain);
270: if ($server_status eq 'switchserver') {
271: my $trolecode = 'au./'.$domain.'/';
272: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
273: $r->internal_redirect($switchserver);
274: }
275: last;
276: }
277: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
278: if (((($castart) && ($castart < $now)) || !$castart) &&
279: ((!$caend) || (($caend) && ($caend > $now)))) {
280: my ($server_status,$home) = &check_author_homeserver($user,$domain);
281: if ($server_status eq 'switchserver') {
282: my $trolecode = 'ca./'.$domain.'/'.$user;
283: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
284: $r->internal_redirect($switchserver);
285: }
286: last;
287: }
288: }
289: # Check if author blocked ca-access
290: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
291: if ($blocked{'domcoord.author'} eq 'blocked') {
292: delete($env{$envkey});
293: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
294: last;
295: }
296: if ($dcroles{$domain}) {
297: my ($server_status,$home) = &check_author_homeserver($user,$domain);
298: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
299: &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
300: $refresh,$now,'ca');
301: if ($server_status eq 'switchserver') {
302: my $trolecode = 'ca./'.$domain.'/'.$user;
303: my $switchserver = '/adm/switchserver?'
304: .'otherserver='.$home.'&role='.$trolecode;
305: $r->internal_redirect($switchserver);
306: }
307: } else {
308: delete($env{$envkey});
309: }
310: } else {
311: delete($env{$envkey});
312: }
313: last;
314: }
315: }
316: }
317:
318: foreach $envkey (keys %env) {
319: next if ($envkey!~/^user\.role\./);
320: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
321: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
322: \$trolecode,\$tstatus,\$tstart,\$tend);
323: if ($env{'form.'.$trolecode}) {
324: if ($tstatus eq 'is') {
325: $where=~s/^\///;
326: my ($cdom,$cnum,$csec)=split(/\//,$where);
327: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
328: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
329: my @ids = &Apache::lonnet::current_machine_ids();
330: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
331: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
332: if ($curr_reqd_hash{'internal.releaserequired'} &&
333: $curr_reqd_hash{'internal.releaserequired'} > $loncaparev) {
334: my ($switchserver,$switchwarning) =
335: &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
336: &Apache::loncommon::content_type($r,'text/html');
337: &Apache::loncommon::no_cache($r);
338: $r->send_http_header;
339: my $end_page=&Apache::loncommon::end_page();
340: $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
341: '<p class="LC_warning">');
342: if ($switchwarning) {
343: $r->print($switchwarning.'<br /><a href="/adm/roles">');
344: if (&Apache::loncommon::show_course()) {
345: $r->print(&mt('Display courses'));
346: } else {
347: $r->print(&mt('Display roles'));
348: }
349: $r->print('</a>');
350: } elsif ($switchserver) {
351: $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
352: '<br />'.
353: '<a href="/adm/switchserver?'.$switchserver.'">'.
354: &mt('Switch Server').
355: '</a>');
356: }
357: $r->print('</p>'.&Apache::loncommon::end_page());
358: return OK;
359: }
360: }
361: }
362: # check for course groups
363: my %coursegroups = &Apache::lonnet::get_active_groups(
364: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
365: my $cgrps = join(':',keys(%coursegroups));
366:
367: # store role if recent_role list being kept
368: if ($env{'environment.recentroles'}) {
369: my %frozen_roles =
370: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
371: &Apache::lonhtmlcommon::store_recent('roles',
372: $trolecode,' ',$frozen_roles{$trolecode});
373: }
374:
375:
376: # check for keyed access
377: if (($role eq 'st') &&
378: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
379: # who is key authority?
380: my $authdom=$cdom;
381: my $authnum=$cnum;
382: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
383: ($authnum,$authdom)=
384: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
385: }
386: # check with key authority
387: unless (&Apache::lonnet::validate_access_key(
388: $env{'environment.key.'.$cdom.'_'.$cnum},
389: $authdom,$authnum)) {
390: # there is no valid key
391: if ($env{'form.newkey'}) {
392: # student attempts to register a new key
393: &Apache::loncommon::content_type($r,'text/html');
394: &Apache::loncommon::no_cache($r);
395: $r->send_http_header;
396: my $swinfo=&Apache::lonmenu::rawconfig();
397: my $start_page=&Apache::loncommon::start_page
398: ('Verifying Access Key to Unlock this Course');
399: my $end_page=&Apache::loncommon::end_page();
400: my $buttontext=&mt('Enter Course');
401: my $message=&mt('Successfully registered key');
402: my $assignresult=
403: &Apache::lonnet::assign_access_key(
404: $env{'form.newkey'},
405: $authdom,$authnum,
406: $cdom,$cnum,
407: $env{'user.domain'},
408: $env{'user.name'},
409: &mt('Assigned from [_1] at [_2] for [_3]'
410: ,$ENV{'REMOTE_ADDR'}
411: ,&Apache::lonlocal::locallocaltime()
412: ,$trolecode)
413: );
414: unless ($assignresult eq 'ok') {
415: $assignresult=~s/^error\:\s*//;
416: $message=&mt($assignresult).
417: '<br /><a href="/adm/logout">'.
418: &mt('Logout').'</a>';
419: $buttontext=&mt('Re-Enter Key');
420: }
421: $r->print(<<ENDENTEREDKEY);
422: $start_page
423: <script type="text/javascript">
424: // <![CDATA[
425: $swinfo
426: // ]]>
427: </script>
428: <form action="" method="post">
429: <input type="hidden" name="selectrole" value="1" />
430: <input type="hidden" name="$trolecode" value="1" />
431: <span class="LC_fontsize_large">$message</span><br />
432: <input type="submit" value="$buttontext" />
433: </form>
434: $end_page
435: ENDENTEREDKEY
436: return OK;
437: } else {
438: # print form to enter a new key
439: &Apache::loncommon::content_type($r,'text/html');
440: &Apache::loncommon::no_cache($r);
441: $r->send_http_header;
442: my $swinfo=&Apache::lonmenu::rawconfig();
443: my $start_page=&Apache::loncommon::start_page
444: ('Enter Access Key to Unlock this Course');
445: my $end_page=&Apache::loncommon::end_page();
446: $r->print(<<ENDENTERKEY);
447: $start_page
448: <script type="text/javascript">
449: // <![CDATA[
450: $swinfo
451: // ]]>
452: </script>
453: <form action="" method="post">
454: <input type="hidden" name="selectrole" value="1" />
455: <input type="hidden" name="$trolecode" value="1" />
456: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
457: <input type="submit" value="Enter key" />
458: </form>
459: $end_page
460: ENDENTERKEY
461: return OK;
462: }
463: }
464: }
465: &Apache::lonnet::log($env{'user.domain'},
466: $env{'user.name'},
467: $env{'user.home'},
468: "Role ".$trolecode);
469:
470: &Apache::lonnet::appenv(
471: {'request.role' => $trolecode,
472: 'request.role.domain' => $cdom,
473: 'request.course.sec' => $csec,
474: 'request.course.groups' => $cgrps});
475: my $tadv=0;
476:
477: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
478: my $msg;
479: my ($furl,$ferr)=
480: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
481: if (($env{'form.orgurl'}) &&
482: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
483: my $dest=$env{'form.orgurl'};
484: if ($env{'form.symb'}) {
485: if ($dest =~ /\?/) {
486: $dest .= '&';
487: } else {
488: $dest .= '?'
489: }
490: $dest .= 'symb='.$env{'form.symb'};
491: }
492: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
493: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
494: if (($ferr) && ($tadv)) {
495: &error_page($r,$ferr,$dest);
496: } else {
497: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
498: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
499: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
500: &update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
501: }
502: }
503: $r->internal_redirect($dest);
504: }
505: return OK;
506: } else {
507: if (!$env{'request.course.id'}) {
508: &Apache::lonnet::appenv(
509: {"request.course.id" => $cdom.'_'.$cnum});
510: $furl='/adm/roles?tryagain=1';
511: $msg='<p><span class="LC_error">'
512: .&mt('Could not initialize [_1] at this time.',
513: $env{'course.'.$cdom.'_'.$cnum.'.description'})
514: .'</span></p>'
515: .'<p>'.&mt('Please try again.').'</p>'
516: .'<p>'.$ferr.'</p>';
517: }
518: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
519: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
520:
521: if (($ferr) && ($tadv)) {
522: &error_page($r,$ferr,$furl);
523: } else {
524: # Check to see if the user is a CC entering a course
525: # for the first time
526: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
527: if (substr($courseid, 0, 1) eq '/') {
528: $courseid = substr($courseid, 1);
529: }
530: $courseid =~ s/\//_/;
531: if ((($role eq 'cc') || ($role eq 'co'))
532: && ($env{'course.' . $courseid .'.course.helper.not.run'})) {
533: $furl = "/adm/helper/course.initialization.helper";
534: # Send the user to the course they selected
535: } elsif ($env{'request.course.id'}) {
536: if ($env{'form.destinationurl'}) {
537: my $dest = $env{'form.destinationurl'};
538: if ($env{'form.destsymb'} ne '') {
539: my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
540: $dest .= '?symb='.$esc_symb;
541: }
542: &redirect_user($r, &mt('Entering [_1]',
543: $env{'course.'.$courseid.'.description'}),
544: $dest, $msg);
545: return OK;
546: }
547: if (&Apache::lonnet::allowed('whn',
548: $env{'request.course.id'})
549: || &Apache::lonnet::allowed('whn',
550: $env{'request.course.id'}.'/'
551: .$env{'request.course.sec'})
552: ) {
553: my $startpage = &courseloadpage($courseid);
554: unless ($startpage eq 'firstres') {
555: $msg = &mt('Entering [_1] ...',
556: $env{'course.'.$courseid.'.description'});
557: &redirect_user($r, &mt('New in course'),
558: '/adm/whatsnew?refpage=start', $msg);
559: return OK;
560: }
561: }
562: }
563: # Are we allowed to look at the first resource?
564: if ($furl !~ m|^/adm/|) {
565: # Guess not ...
566: $furl=&Apache::lonpageflip::first_accessible_resource();
567: }
568: $msg = &mt('Entering [_1] ...',
569: $env{'course.'.$courseid.'.description'});
570: &redirect_user($r, &mt('Entering [_1]',
571: $env{'course.'.$courseid.'.description'}),
572: $furl, $msg);
573: }
574: return OK;
575: }
576: }
577: #
578: # Send the user to the construction space they selected
579: if ($role =~ /^(au|ca|aa)$/) {
580: my $redirect_url = '/priv/';
581: if ($role eq 'au') {
582: $redirect_url.=$env{'user.name'};
583: } else {
584: $where =~ /\/(.*)$/;
585: $redirect_url .= $1;
586: }
587: $redirect_url .= '/';
588: &redirect_user($r,&mt('Entering Construction Space'),
589: $redirect_url);
590: return OK;
591: }
592: if ($role eq 'dc') {
593: my $redirect_url = '/adm/menu/';
594: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
595: $redirect_url);
596: return OK;
597: }
598: if ($role eq 'sc') {
599: my $redirect_url = '/adm/grades?command=scantronupload';
600: &redirect_user($r,&mt('Loading Data Upload Page'),
601: $redirect_url);
602: return OK;
603: }
604: }
605: }
606: }
607: }
608:
609:
610: # =============================================================== No Roles Init
611:
612: &Apache::loncommon::content_type($r,'text/html');
613: &Apache::loncommon::no_cache($r);
614: $r->send_http_header;
615: return OK if $r->header_only;
616:
617: my $crumbtext = 'User Roles';
618: my $pagetitle = 'My Roles';
619: my $recent = &mt('Recent Roles');
620: my $show_course=&Apache::loncommon::show_course();
621: if ($show_course) {
622: $crumbtext = 'Courses';
623: $pagetitle = 'My Courses';
624: $recent = &mt('Recent Courses');
625: }
626: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
627: my $swinfo=&Apache::lonmenu::rawconfig();
628: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
629: my $standby=&mt('Role selected. Please stand by.');
630: $standby=~s/\n/\\n/g;
631: my $noscript='<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 />';
632:
633: $r->print(<<ENDHEADER);
634: $start_page
635: <br />
636: <noscript>
637: $noscript
638: </noscript>
639: <script type="text/javascript">
640: // <![CDATA[
641: $swinfo
642: window.focus();
643:
644: active=true;
645:
646: function enterrole (thisform,rolecode,buttonname) {
647: if (active) {
648: active=false;
649: document.title='$standby';
650: window.status='$standby';
651: thisform.newrole.value=rolecode;
652: thisform.submit();
653: } else {
654: alert('$standby');
655: }
656: }
657: // ]]>
658: </script>
659: ENDHEADER
660:
661: # ------------------------------------------ Get Error Message from Environment
662:
663: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
664: if ($env{'user.error.msg'}) {
665: $r->log_reason(
666: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
667: }
668:
669: # ------------------------------------------------- Can this user re-init, etc?
670:
671: my $advanced=$env{'user.adv'};
672: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
673: my $tryagain=$env{'form.tryagain'};
674: my $reinit=$env{'user.reinit'};
675: delete $env{'user.reinit'};
676:
677: # -------------------------------------------------------- Generate Page Output
678: # --------------------------------------------------------------- Error Header?
679: if ($error) {
680: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
681: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
682: if ($priv ne '') {
683: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
684: }
685: if ($fn ne '') {
686: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
687: }
688: if ($msg ne '') {
689: $r->print(&mt('Action : ').$msg."\n");
690: }
691: $r->print("</pre><hr />");
692: my $url=$fn;
693: my $last;
694: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
695: &GDBM_READER(),0640)) {
696: $last=$hash{'last_known'};
697: untie(%hash);
698: }
699: if ($last) { $fn.='?symb='.&escape($last); }
700:
701: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
702: &Apache::lonenc::check_encrypt($fn));
703: } else {
704: if ($env{'user.error.msg'}) {
705: if ($reinit) {
706: $r->print(
707: '<h3><span class="LC_error">'.
708: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
709: } else {
710: $r->print(
711: '<h3><span class="LC_error">'.
712: &mt('You need to choose another user role or enter a specific course or community for this function.').
713: '</span></h3>');
714: }
715: }
716: }
717: # -------------------------------------------------------- Choice or no choice?
718: if ($nochoose) {
719: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
720: &mt('This action is currently not authorized.').'</span>'.
721: &Apache::loncommon::end_page());
722: return OK;
723: } else {
724: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
725: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
726: }
727: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
728: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
729: $r->print('<input type="hidden" name="selectrole" value="1" />');
730: $r->print('<input type="hidden" name="newrole" value="" />');
731: }
732:
733: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
734: my ($countactive,$countfuture,$inrole,$possiblerole) =
735: &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
736: \%futureroles,\%timezones,$loncaparev);
737:
738: $refresh = $now;
739: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
740: if ($env{'user.adv'}) {
741: $r->print('<p><label><input type="checkbox" name="showall"');
742: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
743: $r->print(' />'.&mt('Show all roles').'</label>'
744: .' <input type="submit" value="'.&mt('Update display').'" />'
745: .'</p>');
746: } else {
747: if ($countactive > 0) {
748: $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
749: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
750: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
751: $r->print(
752: '<p>'
753: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
754: .' to view all [_4] LON-CAPA courses and communities.'
755: ,'<b>'
756: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
757: ,'</a></b>',$domdesc)
758: .'<br />'
759: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
760: .' you may be able to enroll if self-enrollment is permitted.'
761: ,'<b>','</b>')
762: .'</p>'
763: );
764: }
765: }
766:
767: # No active roles
768: if ($countactive==0) {
769: if ($inrole) {
770: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
771: } else {
772: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
773: }
774: &findcourse_advice($r);
775: &requestcourse_advice($r);
776: $r->print('</form>');
777: if ($countfuture) {
778: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
779: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
780: $nochoose);
781: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
782: \%roletext);
783: my $tremark='';
784: my $tbg;
785: if ($env{'request.role'} eq 'cm') {
786: $tbg="LC_roles_selected";
787: $tremark=&mt('Currently selected.').' ';
788: } else {
789: $tbg="LC_roles_is";
790: }
791: $r->print(&Apache::loncommon::start_data_table_row()
792: .'<td class="'.$tbg.'"> </td>'
793: .'<td colspan="3">'
794: .&mt('No role specified')
795: .'</td>'
796: .'<td>'.$tremark.' </td>'
797: .&Apache::loncommon::end_data_table_row()
798: );
799:
800: $r->print(&Apache::loncommon::end_data_table());
801: }
802: $r->print(&Apache::loncommon::end_page());
803: return OK;
804: }
805: # ----------------------------------------------------------------------- Table
806:
807: if ($numdc > 0) {
808: $r->print(&coursepick_jscript());
809: $r->print(&Apache::loncommon::coursebrowser_javascript().
810: &Apache::loncommon::authorbrowser_javascript());
811: }
812:
813: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
814: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
815: }
816: if ($env{'form.destinationurl'}) {
817: $r->print('<input type="hidden" name="destinationurl" value="'.
818: $env{'form.destinationurl'}.'" />');
819: if ($env{'form.destsymb'} ne '') {
820: $r->print('<input type="hidden" name="destsymb" value="'.
821: $env{'form.destsymb'}.'" />');
822: }
823: }
824:
825: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
826: if ($env{'environment.recentroles'}) {
827: my %recent_roles =
828: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
829: my $output='';
830: foreach my $role (sort(keys(%recent_roles))) {
831: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
832: $output.= &Apache::loncommon::start_data_table_row().
833: $roletext{'user.role.'.$role}->[0].
834: &Apache::loncommon::end_data_table_row();
835: if ($roletext{'user.role.'.$role}->[1] ne '') {
836: $output .= &Apache::loncommon::continue_data_table_row().
837: $roletext{'user.role.'.$role}->[1].
838: &Apache::loncommon::end_data_table_row();
839: }
840: if ($role =~ m{dc\./($match_domain)/}
841: && $dcroles{$1}) {
842: $output .= &adhoc_roles_row($1,'recent');
843: }
844: } elsif ($numdc > 0) {
845: unless ($role =~/^error\:/) {
846: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
847: $output.= &Apache::loncommon::start_data_table_row().
848: $roletext.
849: &Apache::loncommon::end_data_table_row().
850: &Apache::loncommon::continue_data_table_row().
851: $role_text_end.
852: &Apache::loncommon::end_data_table_row();
853: }
854: }
855: }
856: if ($output) {
857: $r->print(&Apache::loncommon::start_data_table_empty_row()
858: .'<td align="center" colspan="5">'
859: .$recent
860: .'</td>'
861: .&Apache::loncommon::end_data_table_empty_row()
862: );
863: $r->print($output);
864: $doheaders ++;
865: }
866: }
867: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
868: if ($countactive > 1) {
869: my $tremark='';
870: my $tbg;
871: if ($env{'request.role'} eq 'cm') {
872: $tbg="LC_roles_selected";
873: $tremark=&mt('Currently selected.').' ';
874: } else {
875: $tbg="LC_roles_is";
876: }
877: $r->print(&Apache::loncommon::start_data_table_row());
878: unless ($nochoose) {
879: if ($env{'request.role'} ne 'cm') {
880: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
881: &mt('Select').'" name="cm" /></td>');
882: } else {
883: $r->print('<td class="'.$tbg.'"> </td>');
884: }
885: }
886: $r->print('<td colspan="3">'
887: .&mt('No role specified')
888: .'</td>'
889: .'<td>'.$tremark.' </td>'
890: .&Apache::loncommon::end_data_table_row()
891: );
892: }
893: $r->print(&Apache::loncommon::end_data_table());
894: unless ($nochoose) {
895: $r->print("</form>\n");
896: }
897: # ------------------------------------------------------------ Privileges Info
898: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
899: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
900: $r->print(&privileges_info());
901: }
902: $r->print(&Apache::lonnet::getannounce());
903: if ($advanced) {
904: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
905: $r->print('<p><small><i>'
906: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
907: .'</i><br />'
908: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
909: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
910: .&mt('Course/Community Catalog')
911: .'</a></small></p>');
912: }
913: $r->print(&Apache::loncommon::end_page());
914: return OK;
915: }
916:
917: sub gather_roles {
918: my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
919: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
920: my $advanced = $env{'user.adv'};
921: my $tryagain = $env{'form.tryagain'};
922: my @ids = &Apache::lonnet::current_machine_ids();
923: foreach my $envkey (sort(keys(%env))) {
924: my $button = 1;
925: my $switchserver='';
926: my $switchwarning;
927: my ($role_text,$role_text_end,$sortkey);
928: if ($envkey=~/^user\.role\./) {
929: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
930: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
931: \$trolecode,\$tstatus,\$tstart,\$tend);
932: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
933: my $timezone = &role_timezone($where,$timezones);
934: $tremark='';
935: $tpstart=' ';
936: $tpend=' ';
937: if ($tstart) {
938: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
939: }
940: if ($tend) {
941: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
942: }
943: if ($env{'request.role'} eq $trolecode) {
944: $tstatus='selected';
945: }
946: my $tbg;
947: if (($tstatus eq 'is')
948: || ($tstatus eq 'selected')
949: || ($tstatus eq 'future')
950: || ($env{'form.showall'})) {
951: if ($tstatus eq 'is') {
952: $tbg='LC_roles_is';
953: $possiblerole=$trolecode;
954: $countactive++;
955: } elsif ($tstatus eq 'future') {
956: $tbg='LC_roles_future';
957: $button=0;
958: $futureroles->{$trolecode} = $tstart.':'.$tend;
959: $countfuture ++;
960: } elsif ($tstatus eq 'expired') {
961: $tbg='LC_roles_expired';
962: $button=0;
963: } elsif ($tstatus eq 'will_not') {
964: $tbg='LC_roles_will_not';
965: $tremark.=&mt('Expired after logout.').' ';
966: } elsif ($tstatus eq 'selected') {
967: $tbg='LC_roles_selected';
968: $inrole=1;
969: $countactive++;
970: $tremark.=&mt('Currently selected.').' ';
971: }
972: my $trole;
973: if ($role =~ /^cr\//) {
974: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
975: if ($tremark) { $tremark.='<br />'; }
976: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
977: }
978: $trole=Apache::lonnet::plaintext($role);
979: my $ttype;
980: my $twhere;
981: my ($tdom,$trest,$tsection)=
982: split(/\//,Apache::lonnet::declutter($where));
983: # First, Co-Authorship roles
984: if (($role eq 'ca') || ($role eq 'aa')) {
985: my $home = &Apache::lonnet::homeserver($trest,$tdom);
986: my $allowed=0;
987: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
988: if (!$allowed) {
989: $button=0;
990: $switchserver='otherserver='.$home.'&role='.$trolecode;
991: }
992: #next if ($home eq 'no_host');
993: $home = &Apache::lonnet::hostname($home);
994: $ttype='Construction Space';
995: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
996: ': '.$tdom.'<br />'.
997: ' '.&mt('Server').': '.$home;
998: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
999: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1000: $sortkey=$role."$trest:$tdom";
1001: } elsif ($role eq 'au') {
1002: # Authors
1003: my $home = &Apache::lonnet::homeserver
1004: ($env{'user.name'},$env{'user.domain'});
1005: my $allowed=0;
1006: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1007: if (!$allowed) {
1008: $button=0;
1009: $switchserver='otherserver='.$home.'&role='.$trolecode;
1010: }
1011: #next if ($home eq 'no_host');
1012: $home = &Apache::lonnet::hostname($home);
1013: $ttype='Construction Space';
1014: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1015: ': '.$home;
1016: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1017: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1018: $sortkey=$role;
1019: } elsif ($trest) {
1020: my $tcourseid=$tdom.'_'.$trest;
1021: $ttype = &Apache::loncommon::course_type($tcourseid);
1022: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1023: if ($env{'course.'.$tcourseid.'.description'}) {
1024: my $home=$env{'course.'.$tcourseid.'.home'};
1025: $twhere=$env{'course.'.$tcourseid.'.description'};
1026: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1027: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1028: unless ($twhere eq &mt('Currently not available')) {
1029: $twhere.=' <span class="LC_fontsize_small">'.
1030: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1031: '</span>';
1032: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1033: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1034: ($switchserver,$switchwarning) =
1035: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1036: if ($switchserver || $switchwarning) {
1037: $button = 0;
1038: }
1039: }
1040: }
1041: } else {
1042: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1043: if (%newhash) {
1044: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1045: "\0".$envkey;
1046: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1047: ' <span class="LC_fontsize_small">'.
1048: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1049: '</span>';
1050: $ttype = $newhash{'type'};
1051: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1052: my $home = $newhash{'home'};
1053: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1054: my $required = $newhash{'internal.releaserequired'};
1055: ($switchserver,$switchwarning) =
1056: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1057: if ($switchserver || $switchwarning) {
1058: $button = 0;
1059: }
1060: }
1061: } else {
1062: $twhere=&mt('Currently not available');
1063: $env{'course.'.$tcourseid.'.description'}=$twhere;
1064: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1065: $ttype = 'Unavailable';
1066: }
1067: }
1068: if ($tsection) {
1069: $twhere.='<br />'.&mt('Section').': '.$tsection;
1070: }
1071: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1072: } elsif ($tdom) {
1073: $ttype='Domain';
1074: $twhere=$tdom;
1075: $sortkey=$role.$twhere;
1076: } else {
1077: $ttype='System';
1078: $twhere=&mt('system wide');
1079: $sortkey=$role.$twhere;
1080: }
1081: ($role_text,$role_text_end) =
1082: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1083: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1084: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1085: $roletext->{$envkey}=[$role_text,$role_text_end];
1086: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1087: $sortrole->{$sortkey}=$envkey;
1088: $roleclass->{$envkey}=$ttype;
1089: }
1090: }
1091: }
1092: return ($countactive,$countfuture,$inrole,$possiblerole);
1093: }
1094:
1095: sub role_timezone {
1096: my ($where,$timezones) = @_;
1097: my $timezone;
1098: if (ref($timezones) eq 'HASH') {
1099: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1100: my $cdom = $1;
1101: my $cnum = $2;
1102: if ($cdom && $cnum) {
1103: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1104: my %timehash =
1105: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1106: if ($timehash{'timezone'} eq '') {
1107: if (!exists($timezones->{$cdom})) {
1108: my %domdefaults =
1109: &Apache::lonnet::get_domain_defaults($cdom);
1110: if ($domdefaults{'timezone_def'} eq '') {
1111: $timezones->{$cdom} = 'local';
1112: } else {
1113: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1114: }
1115: }
1116: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1117: } else {
1118: $timezones->{$cdom.'_'.$cnum} =
1119: &Apache::lonlocal::gettimezone($timehash{'timezone'});
1120: }
1121: }
1122: $timezone = $timezones->{$cdom.'_'.$cnum};
1123: }
1124: } else {
1125: my ($tdom) = ($where =~ m{^/($match_domain)});
1126: if ($tdom) {
1127: if (!exists($timezones->{$tdom})) {
1128: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1129: if ($domdefaults{'timezone_def'} eq '') {
1130: $timezones->{$tdom} = 'local';
1131: } else {
1132: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1133: }
1134: }
1135: $timezone = $timezones->{$tdom};
1136: }
1137: }
1138: if ($timezone eq 'local') {
1139: $timezone = undef;
1140: }
1141: }
1142: return $timezone;
1143: }
1144:
1145: sub roletable_headers {
1146: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1147: my $doheaders;
1148: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1149: $r->print('<br />'
1150: .&Apache::loncommon::start_data_table()
1151: .&Apache::loncommon::start_data_table_header_row()
1152: );
1153: if (!$nochoose) { $r->print('<th> </th>'); }
1154: $r->print('<th>'.&mt('User Role').'</th>'
1155: .'<th>'.&mt('Extent').'</th>'
1156: .'<th>'.&mt('Start').'</th>'
1157: .'<th>'.&mt('End').'</th>'
1158: .&Apache::loncommon::end_data_table_header_row()
1159: );
1160: $doheaders=-1;
1161: my @roletypes = &roletypes();
1162: foreach my $type (@roletypes) {
1163: my $haverole=0;
1164: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1165: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1166: $haverole=1;
1167: }
1168: }
1169: if ($haverole) { $doheaders++; }
1170: }
1171: }
1172: return $doheaders;
1173: }
1174:
1175: sub roletypes {
1176: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1177: return @types;
1178: }
1179:
1180: sub print_rolerows {
1181: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1182: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1183: my @types = &roletypes();
1184: foreach my $type (@types) {
1185: my $output;
1186: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1187: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1188: if (ref($roletext) eq 'HASH') {
1189: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1190: $output.= &Apache::loncommon::start_data_table_row().
1191: $roletext->{$sortrole->{$which}}->[0].
1192: &Apache::loncommon::end_data_table_row();
1193: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1194: $output .= &Apache::loncommon::continue_data_table_row().
1195: $roletext->{$sortrole->{$which}}->[1].
1196: &Apache::loncommon::end_data_table_row();
1197: }
1198: }
1199: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1200: if (ref($dcroles) eq 'HASH') {
1201: if ($dcroles->{$1}) {
1202: $output .= &adhoc_roles_row($1,'');
1203: }
1204: }
1205: }
1206: }
1207: }
1208: }
1209: if ($output) {
1210: if ($doheaders > 0) {
1211: $r->print(&Apache::loncommon::start_data_table_empty_row()
1212: .'<td align="center" colspan="5">'
1213: .&mt($type)
1214: .'</td>'
1215: .&Apache::loncommon::end_data_table_empty_row()
1216: );
1217: }
1218: $r->print($output);
1219: }
1220: }
1221: }
1222: }
1223:
1224: sub findcourse_advice {
1225: my ($r) = @_;
1226: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1227: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1228: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1229: $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).'
1230: <ul>
1231: <li>'.&mt('The course has yet to be created.').'</li>
1232: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1233: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1234: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1235: <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>
1236: </ul>');
1237: } else {
1238: $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 />');
1239: }
1240: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1241: '<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 />');
1242: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1243: &Apache::loncoursequeueadmin::queued_selfenrollment());
1244: return;
1245: }
1246:
1247: sub requestcourse_advice {
1248: my ($r) = @_;
1249: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1250: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1251: my (%can_request,%request_doms);
1252: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1253: if (keys(%request_doms) > 0) {
1254: my ($types,$typename) = &Apache::loncommon::course_types();
1255: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1256: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1257: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1258: my (@reqdoms,@reqtypes);
1259: foreach my $type (sort(keys(%request_doms))) {
1260: push(@reqtypes,$type);
1261: if (ref($request_doms{$type}) eq 'ARRAY') {
1262: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1263: $r->print(
1264: '<li>'
1265: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1266: '<i>',
1267: '</i>',
1268: '<b>'.$domstr.'</b>')
1269: .'</li>'
1270: );
1271: foreach my $dom (@{$request_doms{$type}}) {
1272: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1273: push(@reqdoms,$dom);
1274: }
1275: }
1276: }
1277: }
1278: my @showtypes;
1279: foreach my $type (@{$types}) {
1280: if (grep(/^\Q$type\E$/,@reqtypes)) {
1281: push(@showtypes,$type);
1282: }
1283: }
1284: my $requrl = '/adm/requestcourse';
1285: if (@reqdoms == 1) {
1286: $requrl .= '?showdom='.$reqdoms[0];
1287: }
1288: if (@showtypes > 0) {
1289: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1290: }
1291: if (@reqdoms == 1 || @showtypes > 0) {
1292: $requrl .= '&state=crstype&action=new';
1293: }
1294: $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>');
1295: }
1296: }
1297: return;
1298: }
1299:
1300: sub privileges_info {
1301: my ($which) = @_;
1302: my $output;
1303:
1304: $which ||= $env{'request.role'};
1305:
1306: foreach my $envkey (sort(keys(%env))) {
1307: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1308:
1309: my $where=$1;
1310: my $ttype;
1311: my $twhere;
1312: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1313: if ($trest) {
1314: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1315: $ttype='Construction Space';
1316: $twhere='User: '.$trest.', Domain: '.$tdom;
1317: } else {
1318: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1319: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1320: if ($tsec) {
1321: my $sec_type = 'Section';
1322: if (exists($env{"user.role.gr.$where"})) {
1323: $sec_type = 'Group';
1324: }
1325: $twhere.=' ('.$sec_type.': '.$tsec.')';
1326: }
1327: }
1328: } elsif ($tdom) {
1329: $ttype='Domain';
1330: $twhere=$tdom;
1331: } else {
1332: $ttype='System';
1333: $twhere='/';
1334: }
1335: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1336: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1337: next if (!$priv);
1338:
1339: my ($prv,$restr)=split(/\&/,$priv);
1340: my $trestr='';
1341: if ($restr ne 'F') {
1342: $trestr.=' ('.
1343: join(', ',
1344: map { &Apache::lonnet::plaintext($_) }
1345: (split('',$restr))).') ';
1346: }
1347: $output .= "\n\t".
1348: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1349: }
1350: $output .= "\n".'</ul>';
1351: }
1352: return $output;
1353: }
1354:
1355: sub build_roletext {
1356: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1357: my ($roletext,$roletext_end);
1358: my $is_dc=($trolecode =~ m/^dc\./);
1359: my $rowspan=($is_dc) ? ''
1360: : ' rowspan="2" ';
1361:
1362: unless ($nochoose) {
1363: my $buttonname=$trolecode;
1364: $buttonname=~s/\W//g;
1365: if (!$button) {
1366: if ($switchserver) {
1367: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1368: .'<a href="/adm/switchserver?'.$switchserver.'">'
1369: .&mt('Switch Server')
1370: .'</a></td>';
1371: } else {
1372: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1373: }
1374: if ($switchwarning) {
1375: if ($tremark eq '') {
1376: $tremark = $switchwarning;
1377: } else {
1378: $tremark .= '<br />'.$switchwarning;
1379: }
1380: }
1381: } elsif ($tstatus eq 'is') {
1382: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1383: '<input name="'.$buttonname.'" type="button" value="'.
1384: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1385: $trolecode."','".$buttonname.'\');" /></td>';
1386: } elsif ($tryagain) {
1387: $roletext.=
1388: '<td'.$rowspan.' class="'.$tbg.'">'.
1389: '<input name="'.$buttonname.'" type="button" value="'.
1390: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1391: $trolecode."','".$buttonname.'\');" /></td>';
1392: } elsif ($advanced) {
1393: $roletext.=
1394: '<td'.$rowspan.' class="'.$tbg.'">'.
1395: '<input name="'.$buttonname.'" type="button" value="'.
1396: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1397: $trolecode."','".$buttonname.'\');" /></td>';
1398: } elsif ($reinit) {
1399: $roletext.=
1400: '<td'.$rowspan.' class="'.$tbg.'">'.
1401: '<input name="'.$buttonname.'" type="button" value="'.
1402: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1403: $trolecode."','".$buttonname.'\');" /></td>';
1404: } else {
1405: $roletext.=
1406: '<td'.$rowspan.' class="'.$tbg.'">'.
1407: '<input name="'.$buttonname.'" type="button" value="'.
1408: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1409: $trolecode."','".$buttonname.'\');" /></td>';
1410: }
1411: }
1412: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1413: $tremark.=&Apache::lonannounce::showday(time,1,
1414: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1415: }
1416: $roletext.='<td>'.$trole.'</td>'
1417: .'<td>'.$twhere.'</td>'
1418: .'<td>'.$tpstart.'</td>'
1419: .'<td>'.$tpend.'</td>';
1420: if (!$is_dc) {
1421: $roletext_end = '<td colspan="4">'.
1422: $tremark.' '.
1423: '</td>';
1424: }
1425: return ($roletext,$roletext_end);
1426: }
1427:
1428: sub check_needs_switchserver {
1429: my ($possiblerole) = @_;
1430: my $needs_switchserver;
1431: my ($role,$where) = split(/\./,$possiblerole,2);
1432: my (undef,$tdom,$twho) = split(/\//,$where);
1433: my ($server_status,$home);
1434: if (($role eq 'ca') || ($role eq 'aa')) {
1435: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1436: } else {
1437: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1438: $env{'user.domain'});
1439: }
1440: if ($server_status eq 'switchserver') {
1441: $needs_switchserver = 1;
1442: }
1443: return $needs_switchserver;
1444: }
1445:
1446: sub check_author_homeserver {
1447: my ($uname,$udom)=@_;
1448: if (($uname eq '') || ($udom eq '')) {
1449: return ('fail','');
1450: }
1451: my $home = &Apache::lonnet::homeserver($uname,$udom);
1452: if (&Apache::lonnet::host_domain($home) ne $udom) {
1453: return ('fail',$home);
1454: }
1455: my @ids=&Apache::lonnet::current_machine_ids();
1456: if (grep(/^\Q$home\E$/,@ids)) {
1457: return ('ok',$home);
1458: } else {
1459: return ('switchserver',$home);
1460: }
1461: }
1462:
1463: sub check_fordc {
1464: my ($dcroles,$then) = @_;
1465: my $numdc = 0;
1466: if ($env{'user.adv'}) {
1467: foreach my $envkey (sort keys %env) {
1468: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1469: my $dcdom = $1;
1470: my $livedc = 1;
1471: my ($tstart,$tend)=split(/\./,$env{$envkey});
1472: if ($tstart && $tstart>$then) { $livedc = 0; }
1473: if ($tend && $tend <$then) { $livedc = 0; }
1474: if ($livedc) {
1475: $$dcroles{$dcdom} = $envkey;
1476: $numdc++;
1477: }
1478: }
1479: }
1480: }
1481: return $numdc;
1482: }
1483:
1484: sub adhoc_course_role {
1485: my ($refresh,$then) = @_;
1486: my ($cdom,$cnum,$crstype);
1487: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1488: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1489: $crstype = &Apache::loncommon::course_type();
1490: if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
1491: my $setprivs;
1492: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1493: $setprivs = 1;
1494: } else {
1495: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1496: if (($start && ($start>$refresh || $start == -1)) ||
1497: ($end && $end<$then)) {
1498: $setprivs = 1;
1499: }
1500: }
1501: if ($setprivs) {
1502: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1503: my $role = $1;
1504: my $custom_role = $2;
1505: my $usec = $3;
1506: if ($role eq 'cr') {
1507: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1508: $role .= $custom_role;
1509: } else {
1510: return;
1511: }
1512: }
1513: my (%userroles,%newrole,%newgroups,%group_privs);
1514: my %cgroups =
1515: &Apache::lonnet::get_active_groups($env{'user.domain'},
1516: $env{'user.name'},$cdom,$cnum);
1517: foreach my $group (keys(%cgroups)) {
1518: $group_privs{$group} =
1519: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1520: }
1521: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1522: my $area = '/'.$cdom.'/'.$cnum;
1523: my $spec = $role.'.'.$area;
1524: if ($usec ne '') {
1525: $spec .= '/'.$usec;
1526: $area .= '/'.$usec;
1527: }
1528: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1529: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1530: my $adhocstart = $refresh-1;
1531: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1532: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1533: }
1534: }
1535: }
1536: return;
1537: }
1538:
1539: sub check_forcc {
1540: my ($cdom,$cnum,$refresh,$then,$crstype) = @_;
1541: my ($is_cc,$ccrole);
1542: if ($crstype eq 'Community') {
1543: $ccrole = 'co';
1544: } else {
1545: $ccrole = 'cc';
1546: }
1547: if ($cdom ne '' && $cnum ne '') {
1548: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1549: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1550: if (defined($env{$envkey})) {
1551: $is_cc = 1;
1552: my ($tstart,$tend)=split(/\./,$env{$envkey});
1553: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1554: if ($tend && $tend <$then) { $is_cc = 0; }
1555: }
1556: }
1557: }
1558: return $is_cc;
1559: }
1560:
1561: sub check_release_required {
1562: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1563: my ($switchserver,$warning);
1564: if ($required ne '') {
1565: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1566: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\d.\-]+\'?$/);
1567: if ($reqdmajor ne '' && $reqdminor ne '') {
1568: my $otherserver;
1569: if (($major eq '' && $minor eq '') ||
1570: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1571: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1572: my $switchlcrev =
1573: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1574: $userdomserver);
1575: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\d.\-]+\'?$/);
1576: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1577: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1578: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1579: if ($cdom ne $env{'user.domain'}) {
1580: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1581: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1582: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1583: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1584: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1585: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1586: my $canhost =
1587: &Apache::lonnet::can_host_session($env{'user.domain'},
1588: $coursedomserver,
1589: $remoterev,
1590: $udomdefaults{'remotesessions'},
1591: $defdomdefaults{'hostedsessions'});
1592:
1593: if ($canhost) {
1594: $otherserver = $coursedomserver;
1595: } else {
1596: $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.");
1597: }
1598: } else {
1599: $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).");
1600: }
1601: } else {
1602: $otherserver = $userdomserver;
1603: }
1604: }
1605: if ($otherserver ne '') {
1606: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1607: }
1608: }
1609: }
1610: return ($switchserver,$warning);
1611: }
1612:
1613: sub update_content_constraints {
1614: my ($cdom,$cnum,$chome,$cid) = @_;
1615: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1616: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1617: my %checkresponsetypes;
1618: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1619: my ($item,$name,$value) = split(/:/,$key);
1620: if ($item eq 'resourcetag') {
1621: if ($name eq 'responsetype') {
1622: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
1623: }
1624: }
1625: }
1626: my $navmap = Apache::lonnavmaps::navmap->new();
1627: if (defined($navmap)) {
1628: my %allresponses;
1629: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
1630: my %responses = $res->responseTypes();
1631: foreach my $key (keys(%responses)) {
1632: next unless(exists($checkresponsetypes{$key}));
1633: $allresponses{$key} += $responses{$key};
1634: }
1635: }
1636: foreach my $key (keys(%allresponses)) {
1637: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
1638: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
1639: ($reqdmajor,$reqdminor) = ($major,$minor);
1640: }
1641: }
1642: undef($navmap);
1643: }
1644: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
1645: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
1646: }
1647: return;
1648: }
1649:
1650: sub courselink {
1651: my ($dcdom,$rowtype) = @_;
1652: my $courseform=&Apache::loncommon::selectcourse_link
1653: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1654: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1655: $dcdom,$dcdom,undef,'Course/Community');
1656: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1657: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1658: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1659: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1660: return $courseform.$hiddenitems;
1661: }
1662:
1663: sub coursepick_jscript {
1664: my %lt = &Apache::lonlocal::texthash(
1665: 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.",
1666: youc => 'You can only use this screen to select courses and communities in the current domain.',
1667: );
1668: my $verify_script = <<"END";
1669: <script type="text/javascript">
1670: // <![CDATA[
1671: function verifyCoursePick(caller) {
1672: var numbutton = getIndex(caller)
1673: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1674: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1675: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1676: if (pickedCourse != '') {
1677: if (numbutton != -1) {
1678: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1679: document.rolechoice.elements[numbutton+1].name = courseTarget
1680: document.rolechoice.submit()
1681: }
1682: }
1683: else {
1684: alert("$lt{'plsu'}");
1685: }
1686: }
1687: else {
1688: alert("$lt{'youc'}")
1689: }
1690: }
1691: function getIndex(caller) {
1692: for (var i=0;i<document.rolechoice.elements.length;i++) {
1693: if (document.rolechoice.elements[i] == caller) {
1694: return i;
1695: }
1696: }
1697: return -1;
1698: }
1699: // ]]>
1700: </script>
1701: END
1702: return $verify_script;
1703: }
1704:
1705: sub coauthorlink {
1706: my ($dcdom,$rowtype) = @_;
1707: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1708: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1709: return $coauthorform.$hiddenitems;
1710: }
1711:
1712: sub display_cc_role {
1713: my $rolekey = shift;
1714: my ($roletext,$roletext_end);
1715: my $advanced = $env{'user.adv'};
1716: my $tryagain = $env{'form.tryagain'};
1717: unless ($rolekey =~/^error\:/) {
1718: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1719: my $ccrole = $1;
1720: my $tdom = $2;
1721: my $trest = $3;
1722: my $tcourseid = $tdom.'_'.$trest;
1723: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1724: my $twhere;
1725: my $ttype;
1726: my $tbg='LC_roles_is';
1727: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1728: if (%newhash) {
1729: $twhere=$newhash{'description'}.
1730: ' <span style="LC_fontsize_small">'.
1731: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1732: '</span>';
1733: $ttype = $newhash{'type'};
1734: } else {
1735: $twhere=&mt('Currently not available');
1736: $env{'course.'.$tcourseid.'.description'}=$twhere;
1737: }
1738: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1739: $twhere.="<br />".&mt('Domain').":".$1;
1740: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1741: }
1742: }
1743: return ($roletext,$roletext_end);
1744: }
1745:
1746: sub adhoc_roles_row {
1747: my ($dcdom,$rowtype) = @_;
1748: my $output = &Apache::loncommon::continue_data_table_row()
1749: .' <td colspan="5">'
1750: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1751: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1752: .' ';
1753: my $selectcclink = &courselink($dcdom,$rowtype);
1754: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1755: my $carole = &Apache::lonnet::plaintext('ca');
1756: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1757: $output.=$ccrole.': '.$selectcclink
1758: .' | '.$carole.': '.$selectcalink.'</td>'
1759: .&Apache::loncommon::end_data_table_row();
1760: return $output;
1761: }
1762:
1763: sub recent_filename {
1764: my $area=shift;
1765: return 'nohist_recent_'.&escape($area);
1766: }
1767:
1768: sub courseloadpage {
1769: my ($courseid) = @_;
1770: my $startpage;
1771: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1772: [$courseid.':courseinit']);
1773: my ($tmp) = %entry_settings;
1774: unless ($tmp =~ /^error: 2 /) {
1775: $startpage = $entry_settings{$courseid.':courseinit'};
1776: }
1777: if ($startpage eq '') {
1778: if (exists($env{'environment.course_init_display'})) {
1779: $startpage = $env{'environment.course_init_display'};
1780: }
1781: }
1782: return $startpage;
1783: }
1784:
1785: 1;
1786: __END__
1787:
1788: =head1 NAME
1789:
1790: Apache::lonroles - User Roles Screen
1791:
1792: =head1 SYNOPSIS
1793:
1794: Invoked by /etc/httpd/conf/srm.conf:
1795:
1796: <Location /adm/roles>
1797: PerlAccessHandler Apache::lonacc
1798: SetHandler perl-script
1799: PerlHandler Apache::lonroles
1800: ErrorDocument 403 /adm/login
1801: ErrorDocument 500 /adm/errorhandler
1802: </Location>
1803:
1804: =head1 OVERVIEW
1805:
1806: =head2 Choosing Roles
1807:
1808: C<lonroles> is a handler that allows a user to switch roles in
1809: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1810: default role that a user has before selecting a role, as widely as
1811: possible, but certain handlers for example need specification which
1812: course they should act on, etc. Both in this scenario, and when the
1813: handler determines via C<lonnet>'s C<&allowed> function that a certain
1814: action is not allowed, C<lonroles> is used as error handler. This
1815: allows the user to select another role which may have permission to do
1816: what they were trying to do.
1817:
1818: =begin latex
1819:
1820: \begin{figure}
1821: \begin{center}
1822: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1823: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1824: \end{center}
1825: \end{figure}
1826:
1827: =end latex
1828:
1829: =head2 Role Initialization
1830:
1831: 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.
1832:
1833: =head1 INTRODUCTION
1834:
1835: This module enables a user to select what role he wishes to
1836: operate under (instructor, student, teaching assistant, course
1837: coordinator, etc). These roles are pre-established by the actions
1838: of upper-level users.
1839:
1840: This is part of the LearningOnline Network with CAPA project
1841: described at http://www.lon-capa.org.
1842:
1843: =head1 HANDLER SUBROUTINE
1844:
1845: This routine is called by Apache and mod_perl.
1846:
1847: =over 4
1848:
1849: =item *
1850:
1851: Roles Initialization (yes/no)
1852:
1853: =item *
1854:
1855: Get Error Message from Environment
1856:
1857: =item *
1858:
1859: Who is this?
1860:
1861: =item *
1862:
1863: Generate Page Output
1864:
1865: =item *
1866:
1867: Choice or no choice
1868:
1869: =item *
1870:
1871: Table
1872:
1873: =item *
1874:
1875: Privileges
1876:
1877: =back
1878:
1879: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>