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