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