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