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