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