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