File:
[LON-CAPA] /
loncom /
auth /
lonroles.pm
Revision
1.234:
download - view:
text,
annotated -
select for diffs
Sun Oct 25 14:48:43 2009 UTC (14 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Link to course request page if user has no active roles, and has rights to request creation of courses.
- Some wording changes to accommodate communities as well as courses.
- Additional argument for &lonnet::check_can_request() -
hashref: $request_domains used to accumulate domains for each course
type for which user has course request rights.
- New subroutine: &requestcourse_advice() in lonroles.pm
1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.234 2009/10/25 14:48:43 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 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($refresh,$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 or community has expired, you will need to re-select it.').'</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 or community 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(
716: '<p>'
717: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
718: .' to view all [_4] LON-CAPA courses and communities.'
719: ,'<b>'
720: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
721: ,'</a></b>',$domdesc)
722: .'<br />'
723: .&mt('If a course or community is [_1]not[_2] in your list of current courses below,'
724: .' you may be able to enroll if self-enrollment is permitted.'
725: ,'<b>','</b>')
726: .'</p>'
727: );
728: }
729: }
730:
731: # No active roles
732: if ($countactive==0) {
733: if ($inrole) {
734: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
735: } else {
736: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
737: }
738: &findcourse_advice($r);
739: &requestcourse_advice($r);
740: $r->print('</form>');
741: if ($countfuture) {
742: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
743: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
744: $nochoose);
745: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
746: \%roletext);
747: my $tremark='';
748: my $tbg;
749: if ($env{'request.role'} eq 'cm') {
750: $tbg="LC_roles_selected";
751: $tremark=&mt('Currently selected.').' ';
752: } else {
753: $tbg="LC_roles_is";
754: }
755: $r->print(&Apache::loncommon::start_data_table_row()
756: .'<td class="'.$tbg.'"> </td>'
757: .'<td colspan="3">'
758: .&mt('No role specified')
759: .'</td>'
760: .'<td>'.$tremark.' </td>'
761: .&Apache::loncommon::end_data_table_row()
762: );
763:
764: $r->print(&Apache::loncommon::end_data_table());
765: }
766: $r->print(&Apache::loncommon::end_page());
767: return OK;
768: }
769: # ----------------------------------------------------------------------- Table
770: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
771: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
772: }
773: if ($env{'form.destinationurl'}) {
774: $r->print('<input type="hidden" name="destinationurl" value="'.
775: $env{'form.destinationurl'}.'" />');
776: if ($env{'form.destsymb'} ne '') {
777: $r->print('<input type="hidden" name="destsymb" value="'.
778: $env{'form.destsymb'}.'" />');
779: }
780: }
781: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
782: if ($env{'environment.recentroles'}) {
783: my %recent_roles =
784: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
785: my $output='';
786: foreach (sort(keys(%recent_roles))) {
787: if (ref($roletext{'user.role.'.$_}) eq 'ARRAY') {
788: $output.= &Apache::loncommon::start_data_table_row().
789: $roletext{'user.role.'.$_}->[0].
790: &Apache::loncommon::end_data_table_row().
791: &Apache::loncommon::continue_data_table_row().
792: $roletext{'user.role.'.$_}->[1].
793: &Apache::loncommon::end_data_table_row();
794: if ($_ =~ m-dc\./($match_domain)/-
795: && $dcroles{$1}) {
796: $output .= &adhoc_roles_row($1,'recent');
797: }
798: } elsif ($numdc > 0) {
799: unless ($_ =~/^error\:/) {
800: $output.=&display_cc_role('user.role.'.$_);
801: }
802: }
803: }
804: if ($output) {
805: $r->print(&Apache::loncommon::start_data_table_empty_row()
806: .'<td align="center" colspan="5">'
807: .$recent
808: .'</td>'
809: .&Apache::loncommon::end_data_table_empty_row()
810: );
811: $r->print($output);
812: $doheaders ++;
813: }
814: }
815:
816: if ($numdc > 0) {
817: $r->print(&coursepick_jscript());
818: $r->print(&Apache::loncommon::coursebrowser_javascript().
819: &Apache::loncommon::authorbrowser_javascript());
820: }
821: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
822: if ($countactive > 1) {
823: my $tremark='';
824: my $tbg;
825: if ($env{'request.role'} eq 'cm') {
826: $tbg="LC_roles_selected";
827: $tremark=&mt('Currently selected.').' ';
828: } else {
829: $tbg="LC_roles_is";
830: }
831: $r->print(&Apache::loncommon::start_data_table_row());
832: unless ($nochoose) {
833: if ($env{'request.role'} ne 'cm') {
834: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
835: &mt('Select').'" name="cm" /></td>');
836: } else {
837: $r->print('<td class="'.$tbg.'"> </td>');
838: }
839: }
840: $r->print('<td colspan="3">'
841: .&mt('No role specified')
842: .'</td>'
843: .'<td>'.$tremark.' </td>'
844: .&Apache::loncommon::end_data_table_row()
845: );
846: }
847: $r->print(&Apache::loncommon::end_data_table());
848: unless ($nochoose) {
849: $r->print("</form>\n");
850: }
851: # ------------------------------------------------------------ Privileges Info
852: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
853: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
854: $r->print(&privileges_info());
855: }
856: $r->print(&Apache::lonnet::getannounce());
857: if ($advanced) {
858: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
859: $r->print('<p><small><i>'
860: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
861: .'</i><br />'
862: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
863: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
864: .&mt('Course/Community Catalog')
865: .'</a></small></p>');
866: }
867: $r->print(&Apache::loncommon::end_page());
868: return OK;
869: }
870:
871: sub gather_roles {
872: my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones) = @_;
873: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
874: my $advanced = $env{'user.adv'};
875: my $tryagain = $env{'form.tryagain'};
876: foreach my $envkey (sort(keys(%env))) {
877: my $button = 1;
878: my $switchserver='';
879: my ($role_text,$role_text_end,$sortkey);
880: if ($envkey=~/^user\.role\./) {
881: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
882: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
883: \$trolecode,\$tstatus,\$tstart,\$tend);
884: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
885: my $timezone = &role_timezone($where,$timezones);
886: $tremark='';
887: $tpstart=' ';
888: $tpend=' ';
889: if ($tstart) {
890: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
891: }
892: if ($tend) {
893: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
894: }
895: if ($env{'request.role'} eq $trolecode) {
896: $tstatus='selected';
897: }
898: my $tbg;
899: if (($tstatus eq 'is')
900: || ($tstatus eq 'selected')
901: || ($tstatus eq 'future')
902: || ($env{'form.showall'})) {
903: if ($tstatus eq 'is') {
904: $tbg='LC_roles_is';
905: $possiblerole=$trolecode;
906: $countactive++;
907: } elsif ($tstatus eq 'future') {
908: $tbg='LC_roles_future';
909: $button=0;
910: $futureroles->{$trolecode} = $tstart.':'.$tend;
911: $countfuture ++;
912: } elsif ($tstatus eq 'expired') {
913: $tbg='LC_roles_expired';
914: $button=0;
915: } elsif ($tstatus eq 'will_not') {
916: $tbg='LC_roles_will_not';
917: $tremark.=&mt('Expired after logout.').' ';
918: } elsif ($tstatus eq 'selected') {
919: $tbg='LC_roles_selected';
920: $inrole=1;
921: $countactive++;
922: $tremark.=&mt('Currently selected.').' ';
923: }
924: my $trole;
925: if ($role =~ /^cr\//) {
926: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
927: if ($tremark) { $tremark.='<br />'; }
928: $tremark.=&mt('Defined by [_1] at [_2].',$rauthor,$rdomain);
929: }
930: $trole=Apache::lonnet::plaintext($role);
931: my $ttype;
932: my $twhere;
933: my ($tdom,$trest,$tsection)=
934: split(/\//,Apache::lonnet::declutter($where));
935: # First, Co-Authorship roles
936: if (($role eq 'ca') || ($role eq 'aa')) {
937: my $home = &Apache::lonnet::homeserver($trest,$tdom);
938: my $allowed=0;
939: my @ids=&Apache::lonnet::current_machine_ids();
940: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
941: if (!$allowed) {
942: $button=0;
943: $switchserver='otherserver='.$home.'&role='.$trolecode;
944: }
945: #next if ($home eq 'no_host');
946: $home = &Apache::lonnet::hostname($home);
947: $ttype='Construction Space';
948: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
949: ': '.$tdom.'<br />'.
950: ' '.&mt('Server').': '.$home;
951: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
952: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
953: $sortkey=$role."$trest:$tdom";
954: } elsif ($role eq 'au') {
955: # Authors
956: my $home = &Apache::lonnet::homeserver
957: ($env{'user.name'},$env{'user.domain'});
958: my $allowed=0;
959: my @ids=&Apache::lonnet::current_machine_ids();
960: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
961: if (!$allowed) {
962: $button=0;
963: $switchserver='otherserver='.$home.'&role='.$trolecode;
964: }
965: #next if ($home eq 'no_host');
966: $home = &Apache::lonnet::hostname($home);
967: $ttype='Construction Space';
968: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
969: ': '.$home;
970: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
971: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
972: $sortkey=$role;
973: } elsif ($trest) {
974: my $tcourseid=$tdom.'_'.$trest;
975: $ttype = &Apache::loncommon::course_type($tcourseid);
976: $trole = &Apache::lonnet::plaintext($role,$ttype);
977: if ($env{'course.'.$tcourseid.'.description'}) {
978: $twhere=$env{'course.'.$tcourseid.'.description'};
979: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
980: unless ($twhere eq &mt('Currently not available')) {
981: $twhere.=' <span class="LC_fontsize_small">'.
982: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
983: '</span>';
984: }
985: } else {
986: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
987: if (%newhash) {
988: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
989: "\0".$envkey;
990: $twhere=$newhash{'description'}.
991: ' <span class="LC_fontsize_small">'.
992: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
993: '</span>';
994: $ttype = $newhash{'type'};
995: $trole = &Apache::lonnet::plaintext($role,$ttype);
996: } else {
997: $twhere=&mt('Currently not available');
998: $env{'course.'.$tcourseid.'.description'}=$twhere;
999: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1000: $ttype = 'Unavailable';
1001: }
1002: }
1003: if ($tsection) {
1004: $twhere.='<br />'.&mt('Section').': '.$tsection;
1005: }
1006: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1007: } elsif ($tdom) {
1008: $ttype='Domain';
1009: $twhere=$tdom;
1010: $sortkey=$role.$twhere;
1011: } else {
1012: $ttype='System';
1013: $twhere=&mt('system wide');
1014: $sortkey=$role.$twhere;
1015: }
1016: ($role_text,$role_text_end) =
1017: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1018: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1019: $tpend,$nochoose,$button,$switchserver,$reinit);
1020: $roletext->{$envkey}=[$role_text,$role_text_end];
1021: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1022: $sortrole->{$sortkey}=$envkey;
1023: $roleclass->{$envkey}=$ttype;
1024: }
1025: }
1026: }
1027: return ($countactive,$countfuture,$inrole,$possiblerole);
1028: }
1029:
1030: sub role_timezone {
1031: my ($where,$timezones) = @_;
1032: my $timezone;
1033: if (ref($timezones) eq 'HASH') {
1034: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1035: my $cdom = $1;
1036: my $cnum = $2;
1037: if ($cdom && $cnum) {
1038: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1039: my %timehash =
1040: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1041: if ($timehash{'timezone'} eq '') {
1042: if (!exists($timezones->{$cdom})) {
1043: my %domdefaults =
1044: &Apache::lonnet::get_domain_defaults($cdom);
1045: if ($domdefaults{'timezone_def'} eq '') {
1046: $timezones->{$cdom} = 'local';
1047: } else {
1048: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1049: }
1050: }
1051: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1052: } else {
1053: $timezones->{$cdom.'_'.$cnum} =
1054: &Apache::lonlocal::gettimezone($timehash{'timezone'});
1055: }
1056: }
1057: $timezone = $timezones->{$cdom.'_'.$cnum};
1058: }
1059: } else {
1060: my ($tdom) = ($where =~ m{^/($match_domain)});
1061: if ($tdom) {
1062: if (!exists($timezones->{$tdom})) {
1063: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1064: if ($domdefaults{'timezone_def'} eq '') {
1065: $timezones->{$tdom} = 'local';
1066: } else {
1067: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1068: }
1069: }
1070: $timezone = $timezones->{$tdom};
1071: }
1072: }
1073: if ($timezone eq 'local') {
1074: $timezone = undef;
1075: }
1076: }
1077: return $timezone;
1078: }
1079:
1080: sub roletable_headers {
1081: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1082: my $doheaders;
1083: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1084: $r->print('<br />'
1085: .&Apache::loncommon::start_data_table()
1086: .&Apache::loncommon::start_data_table_header_row()
1087: );
1088: if (!$nochoose) { $r->print('<th> </th>'); }
1089: $r->print('<th>'.&mt('User Role').'</th>'
1090: .'<th>'.&mt('Extent').'</th>'
1091: .'<th>'.&mt('Start').'</th>'
1092: .'<th>'.&mt('End').'</th>'
1093: .&Apache::loncommon::end_data_table_header_row()
1094: );
1095: $doheaders=-1;
1096: my @roletypes = &roletypes();
1097: foreach my $type (@roletypes) {
1098: my $haverole=0;
1099: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1100: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1101: $haverole=1;
1102: }
1103: }
1104: if ($haverole) { $doheaders++; }
1105: }
1106: }
1107: return $doheaders;
1108: }
1109:
1110: sub roletypes {
1111: my @types = ('Domain','Construction Space','Course','Unavailable','System');
1112: return @types;
1113: }
1114:
1115: sub print_rolerows {
1116: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1117: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1118: my @types = &roletypes();
1119: foreach my $type (@types) {
1120: my $output;
1121: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1122: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1123: if (ref($roletext) eq 'HASH') {
1124: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1125: $output.= &Apache::loncommon::start_data_table_row().
1126: $roletext->{$sortrole->{$which}}->[0].
1127: &Apache::loncommon::end_data_table_row().
1128: &Apache::loncommon::continue_data_table_row().
1129: $roletext->{$sortrole->{$which}}->[1].
1130: &Apache::loncommon::end_data_table_row();
1131: }
1132: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1133: if (ref($dcroles) eq 'HASH') {
1134: if ($dcroles->{$1}) {
1135: $output .= &adhoc_roles_row($1,'');
1136: }
1137: }
1138: }
1139: }
1140: }
1141: }
1142: if ($output) {
1143: if ($doheaders > 0) {
1144: $r->print(&Apache::loncommon::start_data_table_empty_row()
1145: .'<td align="center" colspan="5">'
1146: .&mt($type)
1147: .'</td>'
1148: .&Apache::loncommon::end_data_table_empty_row()
1149: );
1150: }
1151: $r->print($output);
1152: }
1153: }
1154: }
1155: }
1156:
1157: sub findcourse_advice {
1158: my ($r) = @_;
1159: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1160: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1161: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1162: $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).'
1163: <ul>
1164: <li>'.&mt('The course has yet to be created.').'</li>
1165: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1166: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1167: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1168: <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>
1169: </ul>');
1170: } else {
1171: $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 />');
1172: }
1173: $r->print('<h3>'.&mt('Self Enrollment').'</h3>'.
1174: '<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 />');
1175: $r->print(&mt('You can search the course catalog for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>');
1176: &queued_selfenrollment($r);
1177: return;
1178: }
1179:
1180: sub requestcourse_advice {
1181: my ($r) = @_;
1182: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1183: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1184: my (%can_request,%request_doms);
1185: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1186: if (keys(%request_doms) > 0) {
1187: my ($types,$typename) = &Apache::loncommon::course_types();
1188: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1189: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1190: '<p>'.&mt('You have rights to create courses and/or communities in the following domain(s):').'<ul>');
1191: my (@reqdoms,@reqtypes);
1192: foreach my $type (sort(keys(%request_doms))) {
1193: push(@reqtypes,$type);
1194: if (ref($request_doms{$type}) eq 'ARRAY') {
1195: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1196: $r->print(&mt('[_1] in domain: [_2]',
1197: '<li><i>'.$typename->{$type}.'</i>','<b>'.$domstr.'</b></li>'));
1198: foreach my $dom (@{$request_doms{$type}}) {
1199: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1200: push(@reqdoms,$dom);
1201: }
1202: }
1203: }
1204: }
1205: my @showtypes;
1206: foreach my $type (@{$types}) {
1207: if (grep(/^\Q$type\E$/,@reqtypes)) {
1208: push(@showtypes,$type);
1209: }
1210: }
1211: my $requrl = '/adm/requestcourse';
1212: if (@reqdoms == 1) {
1213: $requrl .= '?showdom='.$reqdoms[0];
1214: }
1215: if (@showtypes > 0) {
1216: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1217: }
1218: if (@reqdoms == 1 || @showtypes > 0) {
1219: $requrl .= '&state=crstype&action=new';
1220: }
1221: $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>');
1222: }
1223: }
1224: return;
1225: }
1226:
1227: sub queued_selfenrollment {
1228: my ($r) = @_;
1229: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1230: my %reqs_by_date;
1231: foreach my $item (keys(%selfenrollrequests)) {
1232: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1233: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1234: if ($selfenrollrequests{$item}{'timestamp'}) {
1235: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1236: }
1237: }
1238: }
1239: }
1240: if (keys(%reqs_by_date)) {
1241: my $rolename = &Apache::lonnet::plaintext('st');
1242: $r->print('<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />'.
1243: &Apache::loncommon::start_data_table().
1244: &Apache::loncommon::start_data_table_header_row().
1245: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1246: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1247: &Apache::loncommon::end_data_table_header_row());
1248: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1249: foreach my $item (@sorted) {
1250: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1251: foreach my $crs (@{$reqs_by_date{$item}}) {
1252: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1253: my $usec = $selfenrollrequests{$crs}{'section'};
1254: if ($usec eq '') {
1255: $usec = &mt('No section');
1256: }
1257: $r->print(&Apache::loncommon::start_data_table_row().
1258: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1259: '<td>'.$courseinfo{'description'}.'</td>'.
1260: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1261: &Apache::loncommon::end_data_table_row());
1262: }
1263: }
1264: }
1265: $r->print(&Apache::loncommon::end_data_table());
1266: }
1267: return;
1268: }
1269:
1270: sub privileges_info {
1271: my ($which) = @_;
1272: my $output;
1273:
1274: $which ||= $env{'request.role'};
1275:
1276: foreach my $envkey (sort(keys(%env))) {
1277: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1278:
1279: my $where=$1;
1280: my $ttype;
1281: my $twhere;
1282: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1283: if ($trest) {
1284: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1285: $ttype='Construction Space';
1286: $twhere='User: '.$trest.', Domain: '.$tdom;
1287: } else {
1288: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1289: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1290: if ($tsec) {
1291: my $sec_type = 'Section';
1292: if (exists($env{"user.role.gr.$where"})) {
1293: $sec_type = 'Group';
1294: }
1295: $twhere.=' ('.$sec_type.': '.$tsec.')';
1296: }
1297: }
1298: } elsif ($tdom) {
1299: $ttype='Domain';
1300: $twhere=$tdom;
1301: } else {
1302: $ttype='System';
1303: $twhere='/';
1304: }
1305: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1306: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1307: next if (!$priv);
1308:
1309: my ($prv,$restr)=split(/\&/,$priv);
1310: my $trestr='';
1311: if ($restr ne 'F') {
1312: $trestr.=' ('.
1313: join(', ',
1314: map { &Apache::lonnet::plaintext($_) }
1315: (split('',$restr))).') ';
1316: }
1317: $output .= "\n\t".
1318: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1319: }
1320: $output .= "\n".'</ul>';
1321: }
1322: return $output;
1323: }
1324:
1325: sub build_roletext {
1326: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit) = @_;
1327: my ($roletext,$roletext_end);
1328: my $is_dc=($trolecode =~ m/^dc\./);
1329: my $rowspan=($is_dc) ? ''
1330: : ' rowspan="2" ';
1331:
1332: unless ($nochoose) {
1333: my $buttonname=$trolecode;
1334: $buttonname=~s/\W//g;
1335: if (!$button) {
1336: if ($switchserver) {
1337: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1338: .'<a href="/adm/switchserver?'.$switchserver.'">'
1339: .&mt('Switch Server')
1340: .'</a></td>';
1341: } else {
1342: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1343: }
1344: } elsif ($tstatus eq 'is') {
1345: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1346: '<input name="'.$buttonname.'" type="button" value="'.
1347: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1348: $trolecode."','".$buttonname.'\');" /></td>';
1349: } elsif ($tryagain) {
1350: $roletext.=
1351: '<td'.$rowspan.' class="'.$tbg.'">'.
1352: '<input name="'.$buttonname.'" type="button" value="'.
1353: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1354: $trolecode."','".$buttonname.'\');" /></td>';
1355: } elsif ($advanced) {
1356: $roletext.=
1357: '<td'.$rowspan.' class="'.$tbg.'">'.
1358: '<input name="'.$buttonname.'" type="button" value="'.
1359: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1360: $trolecode."','".$buttonname.'\');" /></td>';
1361: } elsif ($reinit) {
1362: $roletext.=
1363: '<td'.$rowspan.' class="'.$tbg.'">'.
1364: '<input name="'.$buttonname.'" type="button" value="'.
1365: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1366: $trolecode."','".$buttonname.'\');" /></td>';
1367: } else {
1368: $roletext.=
1369: '<td'.$rowspan.' class="'.$tbg.'">'.
1370: '<input name="'.$buttonname.'" type="button" value="'.
1371: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1372: $trolecode."','".$buttonname.'\');" /></td>';
1373: }
1374: }
1375: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1376: $tremark.=&Apache::lonannounce::showday(time,1,
1377: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1378: }
1379: $roletext.='<td>'.$trole.'</td>'
1380: .'<td>'.$twhere.'</td>'
1381: .'<td>'.$tpstart.'</td>'
1382: .'<td>'.$tpend.'</td>';
1383: if (!$is_dc) {
1384: $roletext_end = '<td colspan="4">'.
1385: $tremark.' '.
1386: '</td>';
1387: }
1388: return ($roletext,$roletext_end);
1389: }
1390:
1391: sub check_needs_switchserver {
1392: my ($possiblerole) = @_;
1393: my $needs_switchserver;
1394: my ($role,$where) = split(/\./,$possiblerole,2);
1395: my (undef,$tdom,$twho) = split(/\//,$where);
1396: my ($server_status,$home);
1397: if (($role eq 'ca') || ($role eq 'aa')) {
1398: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1399: } else {
1400: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1401: $env{'user.domain'});
1402: }
1403: if ($server_status eq 'switchserver') {
1404: $needs_switchserver = 1;
1405: }
1406: return $needs_switchserver;
1407: }
1408:
1409: sub check_author_homeserver {
1410: my ($uname,$udom)=@_;
1411: if (($uname eq '') || ($udom eq '')) {
1412: return ('fail','');
1413: }
1414: my $home = &Apache::lonnet::homeserver($uname,$udom);
1415: if (&Apache::lonnet::host_domain($home) ne $udom) {
1416: return ('fail',$home);
1417: }
1418: my @ids=&Apache::lonnet::current_machine_ids();
1419: if (grep(/^\Q$home\E$/,@ids)) {
1420: return ('ok',$home);
1421: } else {
1422: return ('switchserver',$home);
1423: }
1424: }
1425:
1426: sub check_fordc {
1427: my ($dcroles,$then) = @_;
1428: my $numdc = 0;
1429: if ($env{'user.adv'}) {
1430: foreach my $envkey (sort keys %env) {
1431: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1432: my $dcdom = $1;
1433: my $livedc = 1;
1434: my ($tstart,$tend)=split(/\./,$env{$envkey});
1435: if ($tstart && $tstart>$then) { $livedc = 0; }
1436: if ($tend && $tend <$then) { $livedc = 0; }
1437: if ($livedc) {
1438: $$dcroles{$dcdom} = $envkey;
1439: $numdc++;
1440: }
1441: }
1442: }
1443: }
1444: return $numdc;
1445: }
1446:
1447: sub adhoc_course_role {
1448: my ($refresh,$then) = @_;
1449: my ($cdom,$cnum);
1450: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1451: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1452: if (&check_forcc($cdom,$cnum,$refresh,$then)) {
1453: my $setprivs;
1454: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1455: $setprivs = 1;
1456: } else {
1457: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1458: if (($start && ($start>$refresh || $start == -1)) ||
1459: ($end && $end<$then)) {
1460: $setprivs = 1;
1461: }
1462: }
1463: if ($setprivs) {
1464: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1465: my $role = $1;
1466: my $custom_role = $2;
1467: my $usec = $3;
1468: if ($role eq 'cr') {
1469: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1470: $role .= $custom_role;
1471: } else {
1472: return;
1473: }
1474: }
1475: my (%userroles,%newrole,%newgroups,%group_privs);
1476: my %cgroups =
1477: &Apache::lonnet::get_active_groups($env{'user.domain'},
1478: $env{'user.name'},$cdom,$cnum);
1479: foreach my $group (keys(%cgroups)) {
1480: $group_privs{$group} =
1481: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1482: }
1483: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1484: my $area = '/'.$cdom.'/'.$cnum;
1485: my $spec = $role.'.'.$area;
1486: if ($usec ne '') {
1487: $spec .= '/'.$usec;
1488: $area .= '/'.$usec;
1489: }
1490: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1491: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1492: my $adhocstart = $refresh-1;
1493: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1494: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1495: }
1496: }
1497: }
1498: return;
1499: }
1500:
1501: sub check_forcc {
1502: my ($cdom,$cnum,$refresh,$then) = @_;
1503: my $is_cc;
1504: if ($cdom ne '' && $cnum ne '') {
1505: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1506: my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
1507: if (defined($env{$envkey})) {
1508: $is_cc = 1;
1509: my ($tstart,$tend)=split(/\./,$env{$envkey});
1510: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1511: if ($tend && $tend <$then) { $is_cc = 0; }
1512: }
1513: }
1514: }
1515: return $is_cc;
1516: }
1517:
1518: sub courselink {
1519: my ($dcdom,$rowtype) = @_;
1520: my $courseform=&Apache::loncommon::selectcourse_link
1521: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1522: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1523: $dcdom,$dcdom,undef);
1524: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1525: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1526: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1527: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1528: return $courseform.$hiddenitems;
1529: }
1530:
1531: sub coursepick_jscript {
1532: my %lt = &Apache::lonlocal::texthash(
1533: plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course or community you wish to enter.",
1534: youc => 'You can only use this screen to select courses and communities in the current domain.',
1535: );
1536: my $verify_script = <<"END";
1537: <script type="text/javascript">
1538: // <![CDATA[
1539: function verifyCoursePick(caller) {
1540: var numbutton = getIndex(caller)
1541: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1542: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1543: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1544: if (pickedCourse != '') {
1545: if (numbutton != -1) {
1546: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1547: document.rolechoice.elements[numbutton+1].name = courseTarget
1548: document.rolechoice.submit()
1549: }
1550: }
1551: else {
1552: alert("$lt{'plsu'}");
1553: }
1554: }
1555: else {
1556: alert("$lt{'youc'}")
1557: }
1558: }
1559: function getIndex(caller) {
1560: for (var i=0;i<document.rolechoice.elements.length;i++) {
1561: if (document.rolechoice.elements[i] == caller) {
1562: return i;
1563: }
1564: }
1565: return -1;
1566: }
1567: // ]]>
1568: </script>
1569: END
1570: return $verify_script;
1571: }
1572:
1573: sub coauthorlink {
1574: my ($dcdom,$rowtype) = @_;
1575: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1576: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1577: return $coauthorform.$hiddenitems;
1578: }
1579:
1580: sub display_cc_role {
1581: my $rolekey = shift;
1582: my ($roletext,$roletext_end);
1583: my $advanced = $env{'user.adv'};
1584: my $tryagain = $env{'form.tryagain'};
1585: unless ($rolekey =~/^error\:/) {
1586: if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1587: my $tcourseid = $1.'_'.$2;
1588: my $trolecode = 'cc./'.$1.'/'.$2;
1589: my $twhere;
1590: my $ttype;
1591: my $tbg='LC_roles_is';
1592: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1593: if (%newhash) {
1594: $twhere=$newhash{'description'}.
1595: ' <span style="LC_fontsize_small">'.
1596: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1).
1597: '</span>';
1598: $ttype = $newhash{'type'};
1599: } else {
1600: $twhere=&mt('Currently not available');
1601: $env{'course.'.$tcourseid.'.description'}=$twhere;
1602: }
1603: my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1604: $twhere.="<br />".&mt('Domain').":".$1;
1605: ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1606: }
1607: }
1608: return ($roletext,$roletext_end);
1609: }
1610:
1611: sub adhoc_roles_row {
1612: my ($dcdom,$rowtype) = @_;
1613: my $output = &Apache::loncommon::continue_data_table_row()
1614: .' <td colspan="5">'
1615: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1616: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1617: .' ';
1618: my $selectcclink = &courselink($dcdom,$rowtype);
1619: my $ccrole = &Apache::lonnet::plaintext('cc');
1620: my $carole = &Apache::lonnet::plaintext('ca');
1621: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1622: $output.=$ccrole.': '.$selectcclink
1623: .' | '.$carole.': '.$selectcalink
1624: .&Apache::loncommon::end_data_table_row();
1625: return $output;
1626: }
1627:
1628: sub recent_filename {
1629: my $area=shift;
1630: return 'nohist_recent_'.&escape($area);
1631: }
1632:
1633: sub courseloadpage {
1634: my ($courseid) = @_;
1635: my $startpage;
1636: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1637: [$courseid.':courseinit']);
1638: my ($tmp) = %entry_settings;
1639: unless ($tmp =~ /^error: 2 /) {
1640: $startpage = $entry_settings{$courseid.':courseinit'};
1641: }
1642: if ($startpage eq '') {
1643: if (exists($env{'environment.course_init_display'})) {
1644: $startpage = $env{'environment.course_init_display'};
1645: }
1646: }
1647: return $startpage;
1648: }
1649:
1650: 1;
1651: __END__
1652:
1653: =head1 NAME
1654:
1655: Apache::lonroles - User Roles Screen
1656:
1657: =head1 SYNOPSIS
1658:
1659: Invoked by /etc/httpd/conf/srm.conf:
1660:
1661: <Location /adm/roles>
1662: PerlAccessHandler Apache::lonacc
1663: SetHandler perl-script
1664: PerlHandler Apache::lonroles
1665: ErrorDocument 403 /adm/login
1666: ErrorDocument 500 /adm/errorhandler
1667: </Location>
1668:
1669: =head1 OVERVIEW
1670:
1671: =head2 Choosing Roles
1672:
1673: C<lonroles> is a handler that allows a user to switch roles in
1674: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1675: default role that a user has before selecting a role, as widely as
1676: possible, but certain handlers for example need specification which
1677: course they should act on, etc. Both in this scenario, and when the
1678: handler determines via C<lonnet>'s C<&allowed> function that a certain
1679: action is not allowed, C<lonroles> is used as error handler. This
1680: allows the user to select another role which may have permission to do
1681: what they were trying to do. C<lonroles> can also be accessed via the
1682: B<CRS> button in the Remote Control.
1683:
1684: =begin latex
1685:
1686: \begin{figure}
1687: \begin{center}
1688: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1689: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1690: \end{center}
1691: \end{figure}
1692:
1693: =end latex
1694:
1695: =head2 Role Initialization
1696:
1697: 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.
1698:
1699: =head1 INTRODUCTION
1700:
1701: This module enables a user to select what role he wishes to
1702: operate under (instructor, student, teaching assistant, course
1703: coordinator, etc). These roles are pre-established by the actions
1704: of upper-level users.
1705:
1706: This is part of the LearningOnline Network with CAPA project
1707: described at http://www.lon-capa.org.
1708:
1709: =head1 HANDLER SUBROUTINE
1710:
1711: This routine is called by Apache and mod_perl.
1712:
1713: =over 4
1714:
1715: =item *
1716:
1717: Roles Initialization (yes/no)
1718:
1719: =item *
1720:
1721: Get Error Message from Environment
1722:
1723: =item *
1724:
1725: Who is this?
1726:
1727: =item *
1728:
1729: Generate Page Output
1730:
1731: =item *
1732:
1733: Choice or no choice
1734:
1735: =item *
1736:
1737: Table
1738:
1739: =item *
1740:
1741: Privileges
1742:
1743: =back
1744:
1745: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>