File:
[LON-CAPA] /
loncom /
auth /
lonroles.pm
Revision
1.369:
download - view:
text,
annotated -
select for diffs
Sat Oct 29 18:13:29 2022 UTC (21 months, 3 weeks ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6975
- &get_supplemental() routine moved from lonnet.pm to loncommon.pm
- use LONCAPA::map() moved out of conditional block in loncommon.pm
- $keeporder arg for update_content_constraints() no longer needed
1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.369 2022/10/29 18:13:29 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 REDIRECT);
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 Apache::longroup;
142: use Apache::lonrss;
143: use Apache::lonplacementtest;
144: use GDBM_File;
145: use LONCAPA qw(:DEFAULT :match);
146: use HTML::Entities;
147:
148: my $registered_cleanup;
149: my $rosterupdates;
150:
151: sub start_loading_course {
152: my ($r,$title,$only_body) = @_;
153: &Apache::loncommon::content_type($r,'text/html');
154: &Apache::loncommon::no_cache($r);
155: $r->send_http_header;
156: if ($only_body) {
157: $r->print(&Apache::loncommon::start_page($title,undef,{'only_body' => 1,
158: 'add_progressbar' => 1}));
159: } else {
160: my $swinfo=&Apache::lonmenu::rawconfig();
161: # Breadcrumbs
162: my $brcrum = [{'href' => '',
163: 'text' => $title},];
164: my $start_page = &Apache::loncommon::start_page($title,undef,
165: {'bread_crumbs' => $brcrum,
166: 'bread_crumbs_nomenu' => 1,
167: 'links_disabled' => 1});
168: $r->print(<<ENDREDIR);
169: $start_page
170: <script type="text/javascript">
171: // <![CDATA[
172: $swinfo
173:
174: document.body.addEventListener('click', function (event) {
175: // filter out clicks on any other elements
176: if (event.target.nodeName == 'A' && event.target.getAttribute('aria-disabled') == 'true') {
177: event.preventDefault();
178: }
179: });
180: // ]]>
181: </script>
182: ENDREDIR
183: }
184: return;
185: }
186:
187: sub finish_loading_course {
188: my ($r,$msg,$url,$only_body) = @_;
189: my $link = '<div id="LC_course_loaded" style="display:none"><a href="'.
190: &HTML::Entities::encode($url,'"<>&').'">'.&mt('Continue').'</a></div>';
191: my $end_page = &Apache::loncommon::end_page();
192: my $js_url = &js_escape($url);
193: my $reenable;
194: unless ($only_body) {
195: $reenable = <<REENABLE;
196: \$('.isDisabled > a').removeAttr("aria-disabled");
197: \$('.isDisabled').removeClass("isDisabled");
198: REENABLE
199: }
200: $r->print(<<END);
201: $msg
202: <script type="text/javascript">
203: // <![CDATA[
204: \$(document).ready(function() {
205: \$("#LC_course_loaded").css("display","block");
206: $reenable
207: var url = "$js_url";
208: \$(location).attr('href',url);
209: });
210: // ]]>
211: </script>
212: $link
213: $end_page
214: END
215: return;
216: }
217:
218: sub redirect_user {
219: my ($r,$title,$url,$msg) = @_;
220: $msg = $title if (! defined($msg));
221: &Apache::loncommon::content_type($r,'text/html');
222: &Apache::loncommon::no_cache($r);
223: $r->send_http_header;
224:
225: my $start_page;
226: if ($env{'request.lti.login'}) {
227: $start_page = &Apache::loncommon::start_page(undef,undef,
228: {'redirect' => [0,$url],}).$msg;
229: } else {
230: # Breadcrumbs
231: my $brcrum = [{'href' => $url,
232: 'text' => 'Switching Role'},];
233: $start_page = &Apache::loncommon::start_page('Switching Role',undef,
234: {'redirect' => [1,$url],
235: 'bread_crumbs' => $brcrum,}).
236: "\n<p>$msg</p>";
237: }
238: my $end_page = &Apache::loncommon::end_page();
239:
240: # Note to style police:
241: # This must only replace the spaces, nothing else, or it bombs elsewhere.
242: $url=~s/ /\%20/g;
243: $r->print(<<ENDREDIR);
244: $start_page
245: $end_page
246: ENDREDIR
247: return;
248: }
249:
250: sub error_page {
251: my ($r,$error,$dest)=@_;
252: my %lt = &Apache::lonlocal::texthash(
253: pdc => 'Problems during Course Initialization',
254: tfp => 'The following problems occurred:',
255: con => 'Continue',
256: );
257: my $end_page = &Apache::loncommon::end_page();
258: $dest = &HTML::Entities::encode($dest,'"<>&');
259: $r->print(<<END);
260: <h3>$lt{'pdc'}</h3>
261: <p class="LC_error">$lt{'tfp'}
262: <br />
263: $error
264: </p><br /><a href="$dest">$lt{'con'}</a>
265: $end_page
266: END
267: return;
268: }
269:
270: sub handler {
271:
272: my $r = shift;
273:
274: # Check for critical messages and redirect if present.
275: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'roles');
276: if ($redirect) {
277: &Apache::loncommon::content_type($r,'text/html');
278: $r->header_out(Location => $url);
279: return REDIRECT;
280: }
281:
282: my $now=time;
283: my $then=$env{'user.login.time'};
284: my $refresh=$env{'user.refresh.time'};
285: my $update=$env{'user.update.time'};
286: if (!$refresh) {
287: $refresh = $then;
288: }
289: if (!$update) {
290: $update = $then;
291: }
292:
293: my ($norolelist,$blocked_by_ip,$blocked_type,$clientip);
294: $clientip = &Apache::lonnet::get_requestor_ip($r);
295: if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
296: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
297: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
298: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
299: my $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
300: if ($deeplink_symb) {
301: my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect();
302: if (ref($menuref) eq 'HASH') {
303: unless (($menuref->{'role'}) || ($env{'request.role.adv'})) {
304: foreach my $envkey (keys(%env)) {
305: next unless ($envkey =~ /^form\./);
306: if ($envkey =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
307: unless (($1 eq $cdom) && ($2 eq $cnum)) {
308: delete($env{$envkey});
309: }
310: }
311: }
312: if ($env{'form.selectrole'}) {
313: if ($env{'form.switchrole'} =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
314: unless (($1 eq $cdom) && ($2 eq $cnum)) {
315: delete($env{'form.selectrole'});
316: delete($env{'form.switchrole'});
317: }
318: } elsif ($env{'form.newrole'} =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
319: unless (($1 eq $cdom) && ($2 eq $cnum)) {
320: delete($env{'form.selectrole'});
321: delete($env{'form.newrole'});
322: }
323: }
324: }
325: $norolelist = 1;
326: }
327: }
328: }
329: }
330:
331: if ($env{'form.selectrole'}) {
332: my ($role,$cdom,$cnum,$rest);
333: if ($env{'form.switchrole'} =~ m{^(co|cc|in|ta|ep|ad|st|cr).*?\./($match_domain)/($match_courseid)(/(\w+)|$)}) {
334: ($role,$cdom,$cnum,$rest) = ($1,$2,$3,$4);
335: } elsif ($env{'form.newrole'} =~ m{^(co|cc|in|ta|ep|ad|st|cr).*?\./($match_domain)/($match_courseid)(/(\w+)|$)}) {
336: ($role,$cdom,$cnum,$rest) = ($1,$2,$3,$4);
337: }
338: if ($cdom ne '') {
339: my ($has_evb,$check_ipaccess,$showrole);
340: $showrole = 1;
341: my $checkrole = "cm./$cdom/$cnum";
342: if ($rest ne '') {
343: $checkrole .= "/$rest";
344: }
345: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
346: ($role ne 'st')) {
347: $has_evb = 1;
348: }
349: unless ($has_evb) {
350: my @machinedoms = &Apache::lonnet::current_machine_domains();
351: my $udom = $env{'user.domain'};
352: if ($udom eq $cdom) {
353: $check_ipaccess = 1;
354: } elsif (($udom ne '') && (grep(/^\Q$udom\E$/,@machinedoms))) {
355: $check_ipaccess = 1;
356: } else {
357: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
358: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
359: my $cprim = &Apache::lonnet::domain($cdom,'primary');
360: my $cintdom = &Apache::lonnet::internet_dom($cprim);
361: if (($cintdom ne '') && (ref($internet_names) eq 'ARRAY')) {
362: if (grep(/^\Q$cintdom\E$/,@{$internet_names})) {
363: $check_ipaccess = 1;
364: }
365: }
366: }
367: if ($check_ipaccess) {
368: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$cdom);
369: unless (defined($cached)) {
370: my %domconfig =
371: &Apache::lonnet::get_dom('configuration',['ipaccess'],$cdom);
372: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$cdom,$domconfig{'ipaccess'},1800);
373: }
374: if (ref($ipaccessref) eq 'HASH') {
375: foreach my $id (keys(%{$ipaccessref})) {
376: if (ref($ipaccessref->{$id}) eq 'HASH') {
377: my $range = $ipaccessref->{$id}->{'ip'};
378: if ($range) {
379: my $type = 'exclude';
380: if (&Apache::lonnet::ip_match($clientip,$range)) {
381: $type = 'include';
382: }
383: if (ref($ipaccessref->{$id}->{'courses'}) eq 'HASH') {
384: if ($ipaccessref->{$id}->{'courses'}{$cdom.'_'.$cnum}) {
385: if ($type eq 'include') {
386: $showrole = 1;
387: last;
388: } else {
389: $showrole = 0;
390: }
391: } else {
392: if ($type eq 'include') {
393: $showrole = 0;
394: } else {
395: $showrole = 1;
396: }
397: }
398: }
399: }
400: }
401: }
402: }
403: }
404: }
405: unless ($showrole) {
406: $blocked_by_ip = 1;
407: $blocked_type = &Apache::loncommon::course_type($cdom.'_'.$cnum);
408: delete($env{'form.selectrole'});
409: delete($env{'form.newrole'});
410: }
411: }
412: }
413:
414: $registered_cleanup=0;
415: @{$rosterupdates}=();
416: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
417:
418: # -------------------------------------------------- Check if setting hot list
419: my $hotlist;
420: if ($env{'form.action'} eq 'verify_and_change_rolespref') {
421: $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
422: }
423:
424: # -------------------------------------------------------- Check for new roles
425: my $updateresult;
426: if ($env{'form.state'} eq 'doupdate') {
427: my $show_course=&Apache::loncommon::show_course();
428: my $checkingtxt;
429: if ($show_course) {
430: $checkingtxt = &mt('Checking for new courses ...');
431: } else {
432: $checkingtxt = &mt('Checking for new roles ...');
433: }
434: $updateresult = $checkingtxt;
435: $updateresult .= &update_session_roles();
436: &Apache::lonnet::appenv({'user.update.time' => $now});
437: $update = $now;
438: &Apache::loncoursequeueadmin::reqauthor_check();
439: }
440:
441: # -------------------------------------------------- Check for author requests
442: my $reqauthor;
443: if ($env{'form.state'} eq 'requestauthor') {
444: $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
445: }
446:
447: my $envkey;
448: my %dcroles = ();
449: my %helpdeskroles = ();
450: my ($numdc,$numhelpdesk,$numadhoc) =
451: &check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then);
452: my $loncaparev = $r->dir_config('lonVersion');
453:
454: # ================================================================== Roles Init
455: if ($env{'form.selectrole'}) {
456: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq '')) {
457: if ($env{'form.ltitarget'} eq 'iframe') {
458: &Apache::lonnet::appenv({'request.lti.target' => 'iframe'});
459: delete($env{'form.ltitarget'});
460: }
461: }
462:
463: my $locknum=&Apache::lonnet::get_locks();
464: if ($locknum) { return 409; }
465:
466: my $custom_adhoc;
467: if ($env{'form.newrole'}) {
468: $env{'form.'.$env{'form.newrole'}}=1;
469: # Check if this is a Domain Helpdesk or Domain Helpdesk Assistant role trying to enter a course
470: if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
471: if ($helpdeskroles{$1}) {
472: $custom_adhoc = 1;
473: }
474: }
475: }
476: if ($env{'request.course.id'}) {
477: # Check if user is CC trying to select a course role
478: if ($env{'form.switchrole'}) {
479: my $switch_is_active;
480: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
481: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
482: if (!$end || $end > $now) {
483: if (!$start || $start < $update) {
484: $switch_is_active = 1;
485: }
486: }
487: }
488: unless ($switch_is_active) {
489: &adhoc_course_role($refresh,$update,$then);
490: }
491: }
492: my %temp=('logout_'.$env{'request.course.id'} => time);
493: &Apache::lonnet::put('email_status',\%temp);
494: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
495: }
496: &Apache::lonnet::appenv({"request.course.id" => '',
497: "request.course.fn" => '',
498: "request.course.uri" => '',
499: "request.course.sec" => '',
500: "request.course.tied" => '',
501: "request.course.timechecked" => '',
502: "request.course.suppupdated" => '',
503: "request.role" => 'cm',
504: "request.role.adv" => $env{'user.adv'},
505: "request.role.domain" => $env{'user.domain'}});
506: # Check if Domain Helpdesk role trying to enter a course needs privs to be created
507: if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)}) {
508: my $cdom = $1;
509: my $rolename = $2;
510: my $cnum = $3;
511: my $sec = $4;
512: if ($custom_adhoc) {
513: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1);
514: if (ref($possroles) eq 'ARRAY') {
515: if (grep(/^\Q$rolename\E$/,@{$possroles})) {
516: if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
517: "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) {
518: &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
519: }
520: }
521: }
522: }
523: } elsif (($numdc > 0) || ($numhelpdesk > 0)) {
524: # Check if user is a DC trying to enter a course or author space and needs privs to be created
525: # Check if user is a DH or DA trying to enter a course and needs privs to be created
526: foreach my $envkey (keys(%env)) {
527: # Is this an ad-hoc Coordinator role?
528: if ($numdc) {
529: if (my ($ccrole,$domain,$coursenum) =
530: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
531: if ($dcroles{$domain}) {
532: if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
533: $update,$refresh,$now,$ccrole)) {
534: &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
535: }
536: }
537: last;
538: }
539: # Is this an ad-hoc CA-role?
540: if (my ($domain,$user) =
541: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
542: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
543: delete($env{$envkey});
544: $env{'form.au./'.$domain.'/'} = 1;
545: my ($server_status,$home) = &check_author_homeserver($user,$domain);
546: if ($server_status eq 'switchserver') {
547: my $trolecode = 'au./'.$domain.'/';
548: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
549: $r->internal_redirect($switchserver);
550: return OK;
551: }
552: last;
553: }
554: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
555: if (((($castart) && ($castart < $now)) || !$castart) &&
556: ((!$caend) || (($caend) && ($caend > $now)))) {
557: my ($server_status,$home) = &check_author_homeserver($user,$domain);
558: if ($server_status eq 'switchserver') {
559: my $trolecode = 'ca./'.$domain.'/'.$user;
560: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
561: $r->internal_redirect($switchserver);
562: return OK;
563: }
564: last;
565: }
566: }
567: # Check if author blocked ca-access
568: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
569: if ($blocked{'domcoord.author'} eq 'blocked') {
570: delete($env{$envkey});
571: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
572: last;
573: }
574: if ($dcroles{$domain}) {
575: my ($server_status,$home) = &check_author_homeserver($user,$domain);
576: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
577: &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
578: $refresh,$now,'ca');
579: if ($server_status eq 'switchserver') {
580: my $trolecode = 'ca./'.$domain.'/'.$user;
581: my $switchserver = '/adm/switchserver?'
582: .'otherserver='.$home.'&role='.$trolecode;
583: $r->internal_redirect($switchserver);
584: return OK;
585: }
586: } else {
587: delete($env{$envkey});
588: }
589: } else {
590: delete($env{$envkey});
591: }
592: last;
593: }
594: }
595: if ($numhelpdesk) {
596: # Is this an ad hoc custom role in a course/community?
597: if (my ($domain,$rolename,$coursenum,$sec) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)})) {
598: if ($helpdeskroles{$domain}) {
599: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($domain.'_'.$coursenum,1);
600: if (ref($possroles) eq 'ARRAY') {
601: if (grep(/^\Q$rolename\E$/,@{$possroles})) {
602: if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now,
603: "cr/$domain/$domain".'-domainconfig/'.$rolename,
604: undef,$sec)) {
605: &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.cr/$domain/$domain".
606: '-domainconfig/'."$rolename.adhoc" => time});
607: }
608: } else {
609: delete($env{$envkey});
610: }
611: } else {
612: delete($env{$envkey});
613: }
614: } else {
615: delete($env{$envkey});
616: }
617: last;
618: }
619: }
620: }
621: }
622: foreach $envkey (keys(%env)) {
623: next if ($envkey!~/^user\.role\./);
624: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
625: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
626: \$trolecode,\$tstatus,\$tstart,\$tend);
627: if ($env{'form.'.$trolecode}) {
628: if ($tstatus eq 'is') {
629: $where=~s/^\///;
630: my ($cdom,$cnum,$csec)=split(/\//,$where);
631: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
632: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
633: my @ids = &Apache::lonnet::current_machine_ids();
634: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
635: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
636: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
637: my ($switchserver,$switchwarning) =
638: &Apache::loncommon::check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,
639: $curr_reqd_hash{'internal.releaserequired'});
640: if ($switchwarning ne '' || $switchserver ne '') {
641: &Apache::loncommon::content_type($r,'text/html');
642: &Apache::loncommon::no_cache($r);
643: $r->send_http_header;
644: $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver));
645: return OK;
646: }
647: }
648: }
649: }
650: # check for course groups
651: my %coursegroups = &Apache::lonnet::get_active_groups(
652: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
653: my $cgrps = join(':',keys(%coursegroups));
654:
655: # store role if recent_role list being kept
656: if ($env{'environment.recentroles'}) {
657: my %frozen_roles =
658: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
659: &Apache::lonhtmlcommon::store_recent('roles',
660: $trolecode,' ',$frozen_roles{$trolecode});
661: }
662:
663:
664: # check for keyed access
665: if (($role eq 'st') &&
666: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
667: # who is key authority?
668: my $authdom=$cdom;
669: my $authnum=$cnum;
670: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
671: ($authnum,$authdom)=
672: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
673: }
674: # check with key authority
675: unless (&Apache::lonnet::validate_access_key(
676: $env{'environment.key.'.$cdom.'_'.$cnum},
677: $authdom,$authnum)) {
678: # there is no valid key
679: if ($env{'form.newkey'}) {
680: # student attempts to register a new key
681: &Apache::loncommon::content_type($r,'text/html');
682: &Apache::loncommon::no_cache($r);
683: $r->send_http_header;
684: my $swinfo=&Apache::lonmenu::rawconfig();
685: my $start_page=&Apache::loncommon::start_page
686: ('Verifying Access Key to Unlock this Course');
687: my $end_page=&Apache::loncommon::end_page();
688: my $buttontext=&mt('Enter Course');
689: my $message=&mt('Successfully registered key');
690: my $ip = &Apache::lonnet::get_requestor_ip();
691: my $assignresult=
692: &Apache::lonnet::assign_access_key(
693: $env{'form.newkey'},
694: $authdom,$authnum,
695: $cdom,$cnum,
696: $env{'user.domain'},
697: $env{'user.name'},
698: &mt('Assigned from [_1] at [_2] for [_3]'
699: ,$ip
700: ,&Apache::lonlocal::locallocaltime()
701: ,$trolecode)
702: );
703: unless ($assignresult eq 'ok') {
704: $assignresult=~s/^error\:\s*//;
705: $message=&mt($assignresult).
706: '<br /><a href="/adm/logout">'.
707: &mt('Logout').'</a>';
708: $buttontext=&mt('Re-Enter Key');
709: }
710: $r->print(<<ENDENTEREDKEY);
711: $start_page
712: <script type="text/javascript">
713: // <![CDATA[
714: $swinfo
715: // ]]>
716: </script>
717: <form action="" method="post">
718: <input type="hidden" name="selectrole" value="1" />
719: <input type="hidden" name="$trolecode" value="1" />
720: <span class="LC_fontsize_large">$message</span><br />
721: <input type="submit" value="$buttontext" />
722: </form>
723: $end_page
724: ENDENTEREDKEY
725: return OK;
726: } else {
727: # print form to enter a new key
728: &Apache::loncommon::content_type($r,'text/html');
729: &Apache::loncommon::no_cache($r);
730: $r->send_http_header;
731: my $swinfo=&Apache::lonmenu::rawconfig();
732: my $start_page=&Apache::loncommon::start_page
733: ('Enter Access Key to Unlock this Course');
734: my $end_page=&Apache::loncommon::end_page();
735: $r->print(<<ENDENTERKEY);
736: $start_page
737: <script type="text/javascript">
738: // <![CDATA[
739: $swinfo
740: // ]]>
741: </script>
742: <form action="" method="post">
743: <input type="hidden" name="selectrole" value="1" />
744: <input type="hidden" name="$trolecode" value="1" />
745: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
746: <input type="submit" value="Enter key" />
747: </form>
748: $end_page
749: ENDENTERKEY
750: return OK;
751: }
752: }
753: }
754: &Apache::lonnet::log($env{'user.domain'},
755: $env{'user.name'},
756: $env{'user.home'},
757: "Role ".$trolecode);
758:
759: &Apache::lonnet::appenv(
760: {'request.role' => $trolecode,
761: 'request.role.domain' => $cdom,
762: 'request.course.sec' => $csec,
763: 'request.course.groups' => $cgrps});
764: my $tadv=0;
765:
766: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
767: if ($role =~ m{^\Qcr/$cdom/$cdom\E\-domainconfig/(\w+)$}) {
768: my $rolename = $1;
769: my %domdef = &Apache::lonnet::get_domain_defaults($cdom);
770: if (ref($domdef{'adhocroles'}) eq 'HASH') {
771: if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
772: &Apache::lonnet::appenv({'request.role.desc' => $domdef{'adhocroles'}{$rolename}{'desc'}});
773: }
774: }
775: }
776: my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
777: $crstype = lc($crstype);
778: my ($msg,$critmsg_check,$title,$loadmsg,$only_body);
779: $critmsg_check = 1;
780: $title = &mt("Loading $crstype");
781: $loadmsg = &mt("Please be patient while your $crstype loads");
782: if (($env{'request.deeplink.login'}) && ($env{'request.linkprot'})) {
783: if ($env{'request.linkprot'} =~ /^\d+(c|d):\Q$env{'form.destinationurl'}\E$/) {
784: $title = &mt('Loading LON-CAPA session');
785: $loadmsg = &mt('Please be patient while LON-CAPA loads');
786: $only_body = 1;
787: $critmsg_check = 0;
788: }
789: }
790: my $preamble = '<div id="LC_update_'.$cdom.'_'.$cnum.'" class="LC_info">'.
791: '<br />'.
792: $loadmsg.
793: '<br /></div>'.
794: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
795: my $closure = <<ENDCLOSE;
796: <script type="text/javascript">
797: // <![CDATA[
798: \$("#LC_update_${cdom}_${cnum}").hide('slow');
799: // ]]>
800: </script>
801: ENDCLOSE
802: &start_loading_course($r,$title,$only_body);
803: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
804: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Loading ...'));
805: $r->rflush();
806: if ($critmsg_check) {
807: my $blockcrit = &Apache::loncommon::blocking_status('alert',$clientip,$cnum,$cdom,undef,1);
808: if ($blockcrit) {
809: my $checkrole = "cm./$cdom/$cnum";
810: if ($csec ne '') {
811: $checkrole .= "/$csec";
812: }
813: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
814: ($trolecode !~ m{^st\./$cdom/$cnum})) {
815: $critmsg_check = 0;
816: }
817: }
818: }
819: my ($furl,$ferr)=
820: &Apache::lonuserstate::readmap($cdom.'/'.$cnum,$critmsg_check);
821: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
822: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
823: $r->print($closure);
824: $r->rflush();
825: if ($ferr) {
826: $furl = '/adm/roles?tryagain=1';
827: } else {
828: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
829: unless (($env{'form.switchrole'}) ||
830: ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
831: &Apache::lonnet::put('nohist_crslastlogin',
832: {$env{'user.name'}.':'.$env{'user.domain'}.
833: ':'.$csec.':'.$role => $now},$cdom,$cnum);
834: }
835: if (($env{"environment.internal.$cdom.$cnum.$role.adhoc"}) &&
836: (&Apache::lonnet::allowed('vxc',$cdom.'_'.$cnum))) {
837: my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'};
838: my @coowners = split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'});
839: my %auaccess;
840: foreach my $user ($owner,@coowners) {
841: my ($cpname,$cpdom) = split(/:/,$user);
842: my %auroles = &Apache::lonnet::get_my_roles($cpname,$cpdom,'userroles',undef,['au','ca','aa'],[$cdom]);
843: foreach my $key (keys(%auroles)) {
844: my ($auname,$audom,$aurole) = split(/:/,$key);
845: if ($aurole eq 'au') {
846: $auaccess{$cpname} = 1;
847: } else {
848: $auaccess{$auname} = 1;
849: }
850: }
851: }
852: &Apache::lonnet::appenv({'request.course.adhocsrcaccess' => join(',',sort(keys(%auaccess))) });
853: }
854: my ($feeds,$syllabus_time);
855: &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
856: &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
857: unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) {
858: unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) ||
859: ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) {
860: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
861: $syllabus_time = $syllabus{'uploaded.lastmodified'};
862: if ($syllabus_time) {
863: &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time});
864: }
865: }
866: }
867: }
868: if (($env{'form.orgurl'}) &&
869: ($env{'form.orgurl'}!~/^\/adm\/flip/) &&
870: ($env{'form.orgurl'} ne '/adm/roles')) {
871: my $dest=$env{'form.orgurl'};
872: if ($env{'form.symb'}) {
873: if ($dest =~ /\?/) {
874: $dest .= '&';
875: } else {
876: $dest .= '?';
877: }
878: $dest .= 'symb='.$env{'form.symb'};
879: }
880: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
881: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
882: if ($ferr) {
883: if ($env{'form.orgurl'}) {
884: $furl .= '&orgurl='.&HTML::Entities::encode($env{'form.orgurl'},'<>&"');
885: }
886: if ($env{'form.symb'}) {
887: $furl .= '&symb='.&HTML::Entities::encode($env{'form.symb'},'<>&"');
888: }
889: } else {
890: &set_supplemental_access($cnum,$cdom);
891: }
892: if (($ferr) && ($tadv)) {
893: &error_page($r,$ferr,$furl);
894: } else {
895: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
896: if (($env{'form.orgurl'} ne '') && ($env{'form.symb'} ne '')) {
897: unless (&Apache::lonnet::symbverify($env{'form.symb'},$env{'form.orgurl'})) {
898: $dest=$env{'form.orgurl'};
899: }
900: }
901: }
902: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
903: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
904: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
905: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
906: $cdom.'_'.$cnum);
907: }
908: }
909: if ($ferr) {
910: if (!$env{'request.course.id'}) {
911: &Apache::lonnet::appenv(
912: {"request.course.id" => $cdom.'_'.$cnum});
913: $r->print('<p class="LC_error">'.
914: &mt('Could not initialize [_1] at this time.',
915: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
916: '</p>'.
917: '<p><a href="'.$furl.'">'.
918: &mt('Please try again.').'</a></p>'.
919: &Apache::loncommon::end_page());
920: }
921: } else {
922: if (($env{'request.lti.login'}) &&
923: ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) {
924: &process_lti($r,$cdom,$cnum);
925: }
926: if ($env{'request.deeplink.login'}) {
927: &set_deeplink_target($cnum,$cdom);
928: }
929: $msg = '<p>'.&mt('Entering [_1] ...',
930: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
931: '</p>';
932: &finish_loading_course($r,$msg,$dest,$only_body);
933: }
934: }
935: $r->rflush();
936: return OK;
937: } else {
938: if (!$env{'request.course.id'}) {
939: &Apache::lonnet::appenv(
940: {"request.course.id" => $cdom.'_'.$cnum});
941: }
942: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
943: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
944: if ($ferr) {
945: if ($tadv) {
946: &error_page($r,$ferr,$furl);
947: } else {
948: $r->print('<p class="LC_error">'.
949: &mt('Could not initialize [_1] at this time.',
950: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
951: '</p>'.
952: '<p><a href="'.$furl.'">'.&mt('Please try again.').'</a></p>'.
953: &Apache::loncommon::end_page());
954: }
955: } else {
956: &set_supplemental_access($cnum,$cdom);
957: if (($env{'request.lti.login'}) &&
958: ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) {
959: &process_lti($r,$cdom,$cnum);
960: }
961: if ($env{'request.deeplink.login'}) {
962: &set_deeplink_target($cnum,$cdom);
963: }
964: # Check to see if the user is a CC entering a course
965: # for the first time
966: if ((($role eq 'cc') || ($role eq 'co'))
967: && ($env{'course.'.$cdom.'_'.$cnum.'.course.helper.not.run'})) {
968: $furl = "/adm/helper/course.initialization.helper";
969: # Send the user to the course they selected
970: } elsif ($env{'request.course.id'}) {
971: if ((&Apache::loncommon::course_type() eq 'Placement') &&
972: (!$env{'request.role.adv'})) {
973: my ($score,$incomplete) =
974: &Apache::lonplacementtest::check_completion(undef,undef,1);
975: if (($incomplete) && ($incomplete < 100)) {
976: $msg = '<p>'.&mt('Entering [_1] ...',
977: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
978: '</p>';
979: &finish_loading_course($r,$msg,'/adm/placement',$only_body);
980: $r->rflush();
981: return OK;
982: }
983: }
984: my ($dest,$destsymb,$checkenc);
985: $dest = $env{'form.destinationurl'};
986: $destsymb = $env{'form.destsymb'};
987: if ($dest ne '') {
988: if ($env{'form.switchrole'}) {
989: if ($destsymb ne '') {
990: if ($destsymb !~ m{^/enc/}) {
991: unless ($env{'request.role.adv'}) {
992: $checkenc = 1;
993: }
994: }
995: }
996: if (($dest =~ m{^\Q/public/$cdom/$cnum/syllabus\E.*(\?|\&)usehttp=1}) ||
997: ($dest =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) {
998: if ($ENV{'SERVER_PORT'} == 443) {
999: my $hostname = $r->hostname();
1000: unless ((&Apache::lonnet::uses_sts()) ||
1001: (&Apache::lonnet::waf_allssl($hostname))) {
1002: if ($hostname ne '') {
1003: $dest = 'http://'.$hostname.$dest;
1004: }
1005: }
1006: }
1007: }
1008: if ($dest =~ m{^/enc/}) {
1009: if ($env{'request.role.adv'}) {
1010: $dest = &Apache::lonenc::unencrypted($dest);
1011: if ($destsymb eq '') {
1012: ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
1013: $destsymb = &unescape($destsymb);
1014: }
1015: }
1016: } else {
1017: if ($destsymb eq '') {
1018: ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
1019: $destsymb = &unescape($destsymb);
1020: }
1021: unless ($env{'request.role.adv'}) {
1022: $checkenc = 1;
1023: }
1024: }
1025: if (($checkenc) && ($destsymb ne '')) {
1026: my ($encstate,$unencsymb,$res);
1027: $unencsymb = &Apache::lonnet::symbclean($destsymb);
1028: (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
1029: &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
1030: if ($encstate) {
1031: if (($dest ne '') && ($dest !~ m{^/enc/})) {
1032: $dest=&Apache::lonenc::encrypted($dest);
1033: }
1034: }
1035: }
1036: }
1037: unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
1038: if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
1039: my $esc_symb = &escape($destsymb);
1040: $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb;
1041: }
1042: }
1043: if ($env{'form.ttoken'}) {
1044: $dest .= (($dest =~/\?/)? '&':'?').'ttoken='.$env{'form.ttoken'};
1045: }
1046: unless (($env{'request.lti.login'}) || ($env{'request.deeplink.login'})) {
1047: $msg = '<p>'.&mt('Entering [_1] ...',
1048: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
1049: '</p>';
1050: }
1051: &finish_loading_course($r,$msg,$dest,$only_body);
1052: $r->rflush();
1053: return OK;
1054: }
1055: if (&Apache::lonnet::allowed('whn',
1056: $env{'request.course.id'})
1057: || &Apache::lonnet::allowed('whn',
1058: $env{'request.course.id'}.'/'
1059: .$env{'request.course.sec'})
1060: ) {
1061: my $startpage = &courseloadpage($env{'request.course.id'});
1062: unless ($startpage eq 'firstres') {
1063: $msg = '<p>'.&mt('Entering [_1] ...',
1064: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
1065: '</p>';
1066: &finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start',$only_body);
1067: $r->rflush();
1068: return OK;
1069: }
1070: }
1071: }
1072: # Are we allowed to look at the first resource?
1073: #
1074: # $furl returned by lonuserstate::readmap() has format:
1075: # $url?symb=escaped($symb). If the resource has the
1076: # encrypturl parameter in effect, the entire string
1077: # $url?symb=escaped($symb) is encrypted as a string
1078: # beginning /enc/.
1079: #
1080: my ($access,$unencfurl,$unencsymb);
1081: if ($furl =~ m{^(.+)(?:\?|\&)symb=([^&]+)(?:$|&)}) {
1082: my ($poss_url,$poss_symb) = ($1,$2);
1083: $unencsymb = &unescape($poss_symb);
1084: $unencfurl = $poss_url;
1085: } elsif ($furl =~ m{^/enc/}) {
1086: my $unenc = &Apache::lonenc::unencrypted($furl);
1087: if ($unenc =~ m{^(.+)(?:\?|\&)symb=([^&]+)(?:$|&)}) {
1088: ($unencfurl,$unencsymb) = ($1,$2);
1089: $unencsymb = &unescape($unencsymb);
1090: } else {
1091: $unencfurl = $unenc;
1092: }
1093: } else {
1094: $unencfurl = $furl;
1095: }
1096: if ($unencsymb) {
1097: my $symb = &Apache::lonnet::symbclean($unencsymb);
1098: if (($symb ne '') && (&Apache::lonnet::symbverify($symb,$unencfurl))) {
1099: $access = &Apache::lonnet::allowed('bre',$unencfurl,$symb);
1100: } else {
1101: $access = &Apache::lonnet::allowed('bre',$unencfurl);
1102: }
1103: } else {
1104: $access = &Apache::lonnet::allowed('bre',$unencfurl);
1105: }
1106: if ((!$access) || ($access eq 'B') || ($access eq 'D')) {
1107: $furl = &Apache::lonpageflip::first_accessible_resource();
1108: if ($furl eq '') {
1109: $furl = '/adm/navmaps?showOnlyHomework=1';
1110: }
1111: }
1112: if ($env{'request.lti.login'}) {
1113: undef($msg);
1114: &finish_loading_course($r,$msg,$furl,$only_body);
1115: } else {
1116: $msg = '<p>'.&mt('Entering [_1] ...',
1117: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
1118: '</p>';
1119: &finish_loading_course($r,$msg,$furl,$only_body);
1120: }
1121: }
1122: $r->rflush();
1123: return OK;
1124: }
1125: }
1126: #
1127: # Send the user to the construction space they selected
1128: if ($role =~ /^(au|ca|aa)$/) {
1129: my $redirect_url = '/priv/';
1130: if ($role eq 'au') {
1131: $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
1132: } else {
1133: $redirect_url .= $where;
1134: }
1135: $redirect_url .= '/';
1136: if ($env{'form.orgurl'} =~ /^\Q$redirect_url\E/) {
1137: my ($path) = ($env{'form.orgurl'} =~ m{^(.+)/[^/]+$});
1138: if (($path ne '') && (-e $Apache::lonnet::perlvar{'lonDocRoot'}.$path)) {
1139: $redirect_url = $env{'form.orgurl'};
1140: }
1141: }
1142: &redirect_user($r,&mt('Entering Authoring Space'),
1143: $redirect_url);
1144: return OK;
1145: }
1146: if ($role eq 'dc') {
1147: my $redirect_url = '/adm/menu/';
1148: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1149: $redirect_url);
1150: return OK;
1151: }
1152: if ($role eq 'dh') {
1153: my $redirect_url = '/adm/menu/';
1154: &redirect_user($r,&mt('Loading Domain Helpdesk Menu'),
1155: $redirect_url);
1156: return OK;
1157: }
1158: if ($role eq 'da') {
1159: my $redirect_url = '/adm/menu/';
1160: &redirect_user($r,&mt('Loading Domain Helpdesk Assistant Menu'),
1161: $redirect_url);
1162: return OK;
1163: }
1164: if ($role eq 'sc') {
1165: my $redirect_url = '/adm/grades?command=scantronupload';
1166: &redirect_user($r,&mt('Loading Data Upload Page'),
1167: $redirect_url);
1168: return OK;
1169: }
1170: }
1171: }
1172: }
1173: }
1174:
1175:
1176: # =============================================================== No Roles Init
1177:
1178: &Apache::loncommon::content_type($r,'text/html');
1179: &Apache::loncommon::no_cache($r);
1180: $r->send_http_header;
1181: return OK if $r->header_only;
1182:
1183: my $crumbtext = 'User Roles';
1184: my $pagetitle = 'My Roles';
1185: my $recent = &mt('Recent Roles');
1186: my $standby = &mt('Role selected. Please stand by.');
1187: my $show_course=&Apache::loncommon::show_course();
1188: if ($show_course) {
1189: $crumbtext = 'Courses';
1190: $pagetitle = 'My Courses';
1191: $recent = &mt('Recent Courses');
1192: $standby = &mt('Course selected. Please stand by.');
1193: }
1194: if (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) {
1195: $crumbtext = 'Access Denied';
1196: $pagetitle = 'Unauthorized';
1197: }
1198: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1199:
1200: my %roles_in_env;
1201: my $showcount = &roles_from_env(\%roles_in_env,$update);
1202:
1203: my $swinfo=&Apache::lonmenu::rawconfig();
1204: my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});
1205: my $cattype = 'std';
1206: if ($domdefs{'catauth'}) {
1207: $cattype = $domdefs{'catauth'};
1208: }
1209: my $placementonly;
1210: if ($showcount == 1) {
1211: if ($env{'request.course.id'}) {
1212: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
1213: $placementonly = 1;
1214: }
1215: } else {
1216: foreach my $rolecode (keys(%roles_in_env)) {
1217: my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
1218: if ($cid) {
1219: my %coursedescription =
1220: &Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
1221: if ($coursedescription{'type'} eq 'Placement') {
1222: $placementonly = 1;
1223: }
1224: last;
1225: }
1226: }
1227: }
1228: }
1229: my ($start_page,$funcs);
1230: if ($placementonly) {
1231: $start_page=&Apache::loncommon::start_page($pagetitle,undef,
1232: {bread_crumbs=>$brcrum,crstype=>'Placement'});
1233: } else {
1234: my $crumbsright;
1235: unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) {
1236: $funcs = &get_roles_functions($showcount,$cattype);
1237: if ($env{'browser.mobile'}) {
1238: $crumbsright = $funcs;
1239: undef($funcs);
1240: }
1241: }
1242: $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
1243: bread_crumbs_component=>$crumbsright});
1244: }
1245: &js_escape(\$standby);
1246: 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 />';
1247:
1248: $r->print(<<ENDHEADER);
1249: $start_page
1250: $funcs
1251: <noscript>
1252: $noscript
1253: </noscript>
1254: <script type="text/javascript">
1255: // <![CDATA[
1256: $swinfo
1257: window.focus();
1258:
1259: active=true;
1260:
1261: function enterrole (thisform,rolecode,buttonname) {
1262: if (active) {
1263: active=false;
1264: document.title='$standby';
1265: window.status='$standby';
1266: thisform.newrole.value=rolecode;
1267: thisform.submit();
1268: } else {
1269: alert('$standby');
1270: }
1271: }
1272:
1273: function rolesView (caller) {
1274: if ((caller == 'showall') || (caller == 'noshowall')) {
1275: document.rolechoice.display.value = caller;
1276: } else {
1277: if ((caller == 'doupdate') || (caller == 'requestauthor') ||
1278: (caller == 'queued')) {
1279: document.rolechoice.state.value = caller;
1280: }
1281: }
1282: document.rolechoice.selectrole.value='';
1283: document.rolechoice.submit();
1284: }
1285:
1286: // ]]>
1287: </script>
1288: ENDHEADER
1289:
1290: # ------------------------------------------ Get Error Message from Environment
1291:
1292: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
1293: if ($env{'user.error.msg'}) {
1294: $r->log_reason(
1295: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1296: }
1297:
1298: # ------------------------------------------------- Can this user re-init, etc?
1299:
1300: my $advanced=$env{'user.adv'};
1301: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1302: my $tryagain=$env{'form.tryagain'};
1303: my $reinit=$env{'user.reinit'};
1304: delete $env{'user.reinit'};
1305:
1306: # -------------------------------------------------------- Generate Page Output
1307: # --------------------------------------------------------------- Error Header?
1308: if ($error) {
1309: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1310: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
1311: if ($priv ne '') {
1312: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1313: }
1314: if ($fn ne '') {
1315: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1316: }
1317: if ($msg ne '') {
1318: $r->print(&mt('Action : ').$msg."\n");
1319: }
1320: $r->print("</pre><hr />");
1321: my $url=$fn;
1322: my $last;
1323: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1324: &GDBM_READER(),0640)) {
1325: $last=$hash{'last_known'};
1326: untie(%hash);
1327: }
1328: if ($last) { $fn.='?symb='.&escape($last); }
1329:
1330: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
1331: &Apache::lonenc::check_encrypt($fn));
1332: } else {
1333: if ($env{'user.error.msg'}) {
1334: if ($reinit) {
1335: $r->print(
1336: '<h3><span class="LC_error">'.
1337: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1338: } else {
1339: $r->print(
1340: '<h3><span class="LC_error">'.
1341: &mt('You need to choose another user role or enter a specific course or community for this function.').
1342: '</span></h3>');
1343: }
1344: }
1345: }
1346: if ($nochoose) {
1347: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
1348: &mt('This action is currently not authorized.').'</span>');
1349: if ($error && $norolelist) {
1350: $r->print('<br /><br /><h4><span class="LC_error">'.
1351: &mt('As your session was launched from a web page external to LON-CAPA some course content may be unavailable, including the resource you were trying to access.').
1352: '</span></h4>'.
1353: '<h4><span class="LC_error">'.
1354: &mt('You may need to login to LON-CAPA directly, or re-launch from a different external system.').
1355: '</span></h4>');
1356: }
1357: $r->print(&Apache::loncommon::end_page());
1358: return OK;
1359: } else {
1360: if ($updateresult || $reqauthor || $hotlist) {
1361: my $showresult = '<div>';
1362: if ($updateresult) {
1363: $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
1364: }
1365: if ($reqauthor) {
1366: $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
1367: }
1368: if ($hotlist) {
1369: $showresult .= $hotlist;
1370: }
1371: $showresult .= '</div>';
1372: $r->print($showresult);
1373: } elsif ($env{'form.state'} eq 'queued') {
1374: $r->print(&get_queued());
1375: }
1376: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
1377: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1378: }
1379: my $display = ($env{'form.display'} =~ /^(showall)$/);
1380: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1381: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
1382: $r->print('<input type="hidden" name="selectrole" value="1" />');
1383: $r->print('<input type="hidden" name="newrole" value="" />');
1384: $r->print('<input type="hidden" name="display" value="'.$display.'" />');
1385: $r->print('<input type="hidden" name="state" value="" />');
1386: if ($blocked_by_ip) {
1387: my $blocked_role = 'student';
1388: if ($blocked_type eq 'Community') {
1389: $blocked_role = 'member';
1390: }
1391: $r->print('<h3><span class="LC_error">'.
1392: &mt('The [_1] you selected is not available for access with a [_2] role from your current IP address: [_3].',
1393: lc($blocked_type),$blocked_role,$clientip).
1394: '</span></h3>');
1395: }
1396: }
1397: $r->rflush();
1398:
1399: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
1400: my ($countactive,$countfuture,$inrole,$possiblerole) =
1401: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
1402: \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
1403: $refresh = $now;
1404: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1405: if ($countactive == 1) {
1406: if ($env{'request.course.id'}) {
1407: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
1408: $placementonly = 1;
1409: }
1410: } elsif ($possiblerole) {
1411: if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) {
1412: if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') {
1413: $placementonly = 1;
1414: }
1415: }
1416: }
1417: }
1418: if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) &&
1419: (!$placementonly)) {
1420: if ($countactive > 0) {
1421: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1422: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1423: $r->print(
1424: '<p>'
1425: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
1426: .' to view all [_5] LON-CAPA courses and communities.'
1427: ,'<b>'
1428: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1429: ,'</a>'
1430: ,'</b>'
1431: ,'"'.$domdesc.'"')
1432: .'<br />'
1433: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1434: .' you may be able to enroll if self-enrollment is permitted.'
1435: ,'<b>','</b>')
1436: .'</p>'
1437: );
1438: }
1439: }
1440:
1441: if ($norolelist) {
1442: if ($env{'request.role'}) {
1443: my ($roletext,$role_text_end) = &display_curr_role($env{'request.role'});
1444: if ($roletext) {
1445: $r->print(&Apache::loncommon::start_data_table('LC_textsize_mobile').
1446: &Apache::loncommon::start_data_table_row().
1447: $roletext.
1448: &Apache::loncommon::end_data_table_row());
1449: if ($role_text_end) {
1450: $r->print(&Apache::loncommon::continue_data_table_row().
1451: $role_text_end.
1452: &Apache::loncommon::end_data_table_row());
1453: }
1454: $r->print(&Apache::loncommon::end_data_table());
1455: }
1456: }
1457: $r->print(&Apache::loncommon::end_page());
1458: return OK;
1459: }
1460:
1461: # No active roles
1462: if ($countactive==0) {
1463: my $elapsed = 0;
1464: if ($now && $update) {
1465: $elapsed = $now - $update;
1466: }
1467: &requestcourse_advice($r,$cattype,$inrole,$elapsed);
1468: $r->print('</form>');
1469: if ($countfuture) {
1470: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
1471: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
1472: $nochoose);
1473: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
1474: \%roletext,$update,$then);
1475: my $tremark='';
1476: my $tbg;
1477: if ($env{'request.role'} eq 'cm') {
1478: $tbg="LC_roles_selected";
1479: $tremark=&mt('Currently selected.').' ';
1480: } else {
1481: $tbg="LC_roles_is";
1482: }
1483: $r->print(&Apache::loncommon::start_data_table_row()
1484: .'<td class="'.$tbg.'"> </td>'
1485: .'<td colspan="3">'
1486: .&mt('No role specified')
1487: .'</td>'
1488: .'<td>'.$tremark.' </td>'
1489: .&Apache::loncommon::end_data_table_row()
1490: );
1491:
1492: $r->print(&Apache::loncommon::end_data_table());
1493: }
1494: $r->print(&Apache::loncommon::end_page());
1495: return OK;
1496: } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) {
1497: $r->print('<h3>'.&mt('Please stand by.').'</h3>
1498: <input type="hidden" name="'.$possiblerole.'" value="1" />
1499: <noscript><br />
1500: <input type="submit" name="submit" value="'.&mt('Continue').'" />
1501: </noscript></form>');
1502: $r->rflush();
1503: $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
1504: $r->print(&Apache::loncommon::end_page());
1505: return OK;
1506: }
1507: # ----------------------------------------------------------------------- Table
1508:
1509: if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) {
1510: $r->print(&coursepick_jscript().
1511: &Apache::loncommon::coursebrowser_javascript());
1512: }
1513: if ($numdc > 0) {
1514: $r->print(&Apache::loncommon::authorbrowser_javascript());
1515: }
1516:
1517: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1518: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1519: }
1520: if ($env{'form.destinationurl'}) {
1521: $r->print('<input type="hidden" name="destinationurl" value="'.
1522: $env{'form.destinationurl'}.'" />');
1523: if ($env{'form.destsymb'} ne '') {
1524: $r->print('<input type="hidden" name="destsymb" value="'.
1525: $env{'form.destsymb'}.'" />');
1526: }
1527: }
1528:
1529: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1530: if ($env{'environment.recentroles'}) {
1531: my %recent_roles =
1532: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1533: my $output='';
1534: foreach my $role (sort(keys(%recent_roles))) {
1535: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1536: $output.= &Apache::loncommon::start_data_table_row().
1537: $roletext{'user.role.'.$role}->[0].
1538: &Apache::loncommon::end_data_table_row();
1539: if ($roletext{'user.role.'.$role}->[1] ne '') {
1540: $output .= &Apache::loncommon::continue_data_table_row().
1541: $roletext{'user.role.'.$role}->[1].
1542: &Apache::loncommon::end_data_table_row();
1543: }
1544: if ($role =~ m{^dc\./($match_domain)/$}
1545: && $dcroles{$1}) {
1546: $output .= &adhoc_roles_row($1,'recent');
1547: } elsif ($role =~ m{^(dh|da)\./($match_domain)/$}) {
1548: $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then);
1549: }
1550: } elsif ($numdc > 0) {
1551: unless ($role =~/^error\:/) {
1552: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1553: if ($roletext) {
1554: $output.= &Apache::loncommon::start_data_table_row().
1555: $roletext.
1556: &Apache::loncommon::end_data_table_row();
1557: if ($role_text_end) {
1558: $output .= &Apache::loncommon::continue_data_table_row().
1559: $role_text_end.
1560: &Apache::loncommon::end_data_table_row();
1561: }
1562: }
1563: }
1564: }
1565: }
1566: if ($output) {
1567: $r->print(&Apache::loncommon::start_data_table_empty_row()
1568: .'<td align="center" colspan="5">'
1569: .$recent
1570: .'</td>'
1571: .&Apache::loncommon::end_data_table_empty_row()
1572: );
1573: $r->print($output);
1574: $doheaders ++;
1575: }
1576: }
1577: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then);
1578: if ($countactive > 1) {
1579: my $tremark='';
1580: my $tbg;
1581: if ($env{'request.role'} eq 'cm') {
1582: $tbg="LC_roles_selected";
1583: $tremark=&mt('Currently selected.').' ';
1584: } else {
1585: $tbg="LC_roles_is";
1586: }
1587: $r->print(&Apache::loncommon::start_data_table_row());
1588: unless ($nochoose) {
1589: if ($env{'request.role'} ne 'cm') {
1590: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1591: &mt('Select').'" name="cm" /></td>');
1592: } else {
1593: $r->print('<td class="'.$tbg.'"> </td>');
1594: }
1595: }
1596: $r->print('<td colspan="3">'
1597: .&mt('No role specified')
1598: .'</td>'
1599: .'<td>'.$tremark.' </td>'
1600: .&Apache::loncommon::end_data_table_row()
1601: );
1602: }
1603: $r->print(&Apache::loncommon::end_data_table());
1604: unless ($nochoose) {
1605: $r->print("</form>\n");
1606: }
1607: # ------------------------------------------------------------ Privileges Info
1608: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1609: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1610: $r->print(&privileges_info());
1611: }
1612: my $announcements = &Apache::lonnet::getannounce();
1613: $r->print(
1614: '<br />'.
1615: '<h2>'.&mt('Announcements').'</h2>'.
1616: $announcements
1617: ) unless (!$announcements);
1618: if ($advanced) {
1619: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1620: $r->print('<p><small><i>'
1621: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1622: .'</i></small></p>');
1623: }
1624: $r->print(&Apache::loncommon::end_page());
1625: return OK;
1626: }
1627:
1628: sub roles_from_env {
1629: my ($roleshash,$update) = @_;
1630: my $count = 0;
1631: if (ref($roleshash) eq 'HASH') {
1632: foreach my $envkey (keys(%env)) {
1633: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1634: next if ($1 eq 'gr');
1635: $roleshash->{$envkey} = $env{$envkey};
1636: my ($start,$end) = split(/\./,$env{$envkey});
1637: unless ($end && $end<$update) {
1638: $count ++;
1639: }
1640: }
1641: }
1642: }
1643: return $count;
1644: }
1645:
1646: sub gather_roles {
1647: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1648: $timezones,$loncaparev) = @_;
1649: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1650: my $advanced = $env{'user.adv'};
1651: my $tryagain = $env{'form.tryagain'};
1652: my @ids = &Apache::lonnet::current_machine_ids();
1653: my (%willtrust,%trustchecked);
1654: if (ref($roles_in_env) eq 'HASH') {
1655: my %adhocdesc;
1656: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1657: my $button = 1;
1658: my $switchserver='';
1659: my $switchwarning;
1660: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1661: $tend,$tremark,$tstatus,$tpstart,$tpend);
1662: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1663: \$trolecode,\$tstatus,\$tstart,\$tend);
1664: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1665: $tremark='';
1666: $tpstart=' ';
1667: $tpend=' ';
1668: if ($env{'request.role'} eq $trolecode) {
1669: $tstatus='selected';
1670: }
1671: my $tbg;
1672: if (($tstatus eq 'is')
1673: || ($tstatus eq 'selected')
1674: || ($tstatus eq 'future')
1675: || ($env{'form.display'} eq 'showall')) {
1676: my $timezone = &role_timezone($where,$timezones);
1677: if ($tstart) {
1678: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1679: }
1680: if ($tend) {
1681: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1682: }
1683: if ($tstatus eq 'is') {
1684: $tbg='LC_roles_is';
1685: $possiblerole=$trolecode;
1686: $countactive++;
1687: } elsif ($tstatus eq 'future') {
1688: $tbg='LC_roles_future';
1689: $button=0;
1690: $futureroles->{$trolecode} = $tstart.':'.$tend;
1691: $countfuture ++;
1692: } elsif ($tstatus eq 'expired') {
1693: $tbg='LC_roles_expired';
1694: $button=0;
1695: } elsif ($tstatus eq 'will_not') {
1696: $tbg='LC_roles_will_not';
1697: $tremark.=&mt('Expired after logout.').' ';
1698: } elsif ($tstatus eq 'selected') {
1699: $tbg='LC_roles_selected';
1700: $inrole=1;
1701: $countactive++;
1702: $tremark.=&mt('Currently selected.').' ';
1703: }
1704: my $trole;
1705: if ($role =~ /^cr\//) {
1706: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1707: unless ($rauthor eq $rdomain.'-domainconfig') {
1708: if ($tremark) { $tremark.='<br />'; }
1709: $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1710: }
1711: }
1712: $trole=Apache::lonnet::plaintext($role);
1713: my $ttype;
1714: my $twhere;
1715: my $skipcal;
1716: my ($tdom,$trest,$tsection)=
1717: split(/\//,Apache::lonnet::declutter($where));
1718: # First, Co-Authorship roles
1719: if (($role eq 'ca') || ($role eq 'aa')) {
1720: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1721: my $allowed=0;
1722: my $prohibited;
1723: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1724: if (!$allowed) {
1725: $button=0;
1726: unless ($trustchecked{$tdom}) {
1727: if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$tdom)) &&
1728: (&Apache::lonnet::will_trust('coaurem',$tdom,$env{'user.domain'}))) {
1729: $willtrust{$tdom} = 1;
1730: $trustchecked{$tdom} = 1;
1731: }
1732: }
1733: if ($willtrust{$tdom}) {
1734: $switchserver='otherserver='.$home.'&role='.$trolecode;
1735: } else {
1736: $prohibited = 1;
1737: $tremark .= &mt('Session switch required but prohibited.');
1738: }
1739: }
1740: #next if ($home eq 'no_host');
1741: $home = &Apache::lonnet::hostname($home);
1742: $ttype='Authoring Space';
1743: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1744: ': '.$tdom.'<br />'.
1745: ' '.&mt('Server').': '.$home;
1746: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1747: unless ($prohibited) {
1748: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1749: }
1750: $sortkey=$role."$trest:$tdom";
1751: } elsif ($role eq 'au') {
1752: # Authors
1753: my $home = &Apache::lonnet::homeserver
1754: ($env{'user.name'},$env{'user.domain'});
1755: my $allowed=0;
1756: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1757: if (!$allowed) {
1758: $button=0;
1759: $switchserver='otherserver='.$home.'&role='.$trolecode;
1760: }
1761: #next if ($home eq 'no_host');
1762: $home = &Apache::lonnet::hostname($home);
1763: $ttype='Authoring Space';
1764: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1765: ': '.$home;
1766: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1767: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1768: $sortkey=$role;
1769: } elsif ($trest) {
1770: my $tcourseid=$tdom.'_'.$trest;
1771: $ttype = &Apache::loncommon::course_type($tcourseid);
1772: if ($role !~ /^cr/) {
1773: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1774: } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) {
1775: my $rolename = $1;
1776: my $desc;
1777: if (ref($adhocdesc{$tdom}) eq 'HASH') {
1778: $desc = $adhocdesc{$tdom}{$rolename};
1779: } else {
1780: my %domdef = &Apache::lonnet::get_domain_defaults($tdom);
1781: if (ref($domdef{'adhocroles'}) eq 'HASH') {
1782: foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
1783: if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
1784: $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
1785: $desc = $adhocdesc{$tdom}{$rolename};
1786: }
1787: }
1788: }
1789: }
1790: if ($desc ne '') {
1791: $trole = $desc;
1792: } else {
1793: $trole = &mt('Helpdesk[_1]',' '.$rolename);
1794: }
1795: } else {
1796: $trole = (split(/\//,$role,4))[-1];
1797: }
1798: if ($env{'course.'.$tcourseid.'.description'}) {
1799: my $home=$env{'course.'.$tcourseid.'.home'};
1800: $twhere=$env{'course.'.$tcourseid.'.description'};
1801: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1802: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1803: unless ($twhere eq &mt('Currently not available')) {
1804: $twhere.=' <span class="LC_fontsize_small">'.
1805: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1806: '</span>';
1807: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1808: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1809: if ($required ne '') {
1810: ($switchserver,$switchwarning) =
1811: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1812: if ($switchserver || $switchwarning) {
1813: $button = 0;
1814: }
1815: }
1816: }
1817: }
1818: } else {
1819: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1820: if (%newhash) {
1821: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1822: "\0".$envkey;
1823: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1824: ' <span class="LC_fontsize_small">'.
1825: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1826: '</span>';
1827: $ttype = $newhash{'type'};
1828: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1829: my $home = $newhash{'home'};
1830: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1831: my $required = $newhash{'internal.releaserequired'};
1832: if ($required ne '') {
1833: ($switchserver,$switchwarning) =
1834: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1835: if ($switchserver || $switchwarning) {
1836: $button = 0;
1837: }
1838: }
1839: }
1840: } else {
1841: $twhere=&mt('Currently not available');
1842: $env{'course.'.$tcourseid.'.description'}=$twhere;
1843: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1844: $ttype = 'Unavailable';
1845: $skipcal = 1;
1846: }
1847: }
1848: if ($ttype eq 'Placement') {
1849: $ttype = 'Placement Test';
1850: }
1851: if ($tsection) {
1852: $twhere.='<br />'.&mt('Section').': '.$tsection;
1853: }
1854: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1855: } elsif ($tdom) {
1856: $ttype='Domain';
1857: $twhere=$tdom;
1858: $sortkey=$role.$twhere;
1859: } else {
1860: $ttype='System';
1861: $twhere=&mt('system wide');
1862: $sortkey=$role.$twhere;
1863: }
1864: ($role_text,$role_text_end) =
1865: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1866: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1867: $tpend,$nochoose,$button,$switchserver,$reinit,
1868: $switchwarning,$skipcal);
1869: $roletext->{$envkey}=[$role_text,$role_text_end];
1870: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1871: $sortrole->{$sortkey}=$envkey;
1872: $roleclass->{$envkey}=$ttype;
1873: }
1874: }
1875: }
1876: return ($countactive,$countfuture,$inrole,$possiblerole);
1877: }
1878:
1879: sub role_timezone {
1880: my ($where,$timezones) = @_;
1881: my $timezone;
1882: if (ref($timezones) eq 'HASH') {
1883: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1884: my $cdom = $1;
1885: my $cnum = $2;
1886: if ($cdom && $cnum) {
1887: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1888: my $tz;
1889: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1890: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1891: } else {
1892: my %timehash =
1893: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1894: $tz = $timehash{'timezone'};
1895: }
1896: if ($tz eq '') {
1897: if (!exists($timezones->{$cdom})) {
1898: my %domdefaults =
1899: &Apache::lonnet::get_domain_defaults($cdom);
1900: if ($domdefaults{'timezone_def'} eq '') {
1901: $timezones->{$cdom} = 'local';
1902: } else {
1903: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1904: }
1905: }
1906: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1907: } else {
1908: $timezones->{$cdom.'_'.$cnum} =
1909: &Apache::lonlocal::gettimezone($tz);
1910: }
1911: }
1912: $timezone = $timezones->{$cdom.'_'.$cnum};
1913: }
1914: } else {
1915: my ($tdom) = ($where =~ m{^/($match_domain)});
1916: if ($tdom) {
1917: if (!exists($timezones->{$tdom})) {
1918: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1919: if ($domdefaults{'timezone_def'} eq '') {
1920: $timezones->{$tdom} = 'local';
1921: } else {
1922: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1923: }
1924: }
1925: $timezone = $timezones->{$tdom};
1926: }
1927: }
1928: if ($timezone eq 'local') {
1929: $timezone = undef;
1930: }
1931: }
1932: return $timezone;
1933: }
1934:
1935: sub roletable_headers {
1936: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1937: my $doheaders;
1938: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1939: $r->print('<br />'
1940: .&Apache::loncommon::start_data_table('LC_textsize_mobile')
1941: .&Apache::loncommon::start_data_table_header_row()
1942: );
1943: if (!$nochoose) { $r->print('<th> </th>'); }
1944: $r->print('<th>'.&mt('User Role').'</th>'
1945: .'<th>'.&mt('Extent').'</th>'
1946: .'<th>'.&mt('Start').'</th>'
1947: .'<th>'.&mt('End').'</th>'
1948: .&Apache::loncommon::end_data_table_header_row()
1949: );
1950: $doheaders=-1;
1951: my @roletypes = &roletypes();
1952: foreach my $type (@roletypes) {
1953: my $haverole=0;
1954: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1955: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1956: $haverole=1;
1957: }
1958: }
1959: if ($haverole) { $doheaders++; }
1960: }
1961: }
1962: return $doheaders;
1963: }
1964:
1965: sub roletypes {
1966: my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System');
1967: return @types;
1968: }
1969:
1970: sub print_rolerows {
1971: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_;
1972: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1973: my @types = &roletypes();
1974: foreach my $type (@types) {
1975: my $output;
1976: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1977: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1978: if (ref($roletext) eq 'HASH') {
1979: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1980: $output.= &Apache::loncommon::start_data_table_row().
1981: $roletext->{$sortrole->{$which}}->[0].
1982: &Apache::loncommon::end_data_table_row();
1983: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1984: $output .= &Apache::loncommon::continue_data_table_row().
1985: $roletext->{$sortrole->{$which}}->[1].
1986: &Apache::loncommon::end_data_table_row();
1987: }
1988: }
1989: if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
1990: if (ref($dcroles) eq 'HASH') {
1991: if ($dcroles->{$1}) {
1992: $output .= &adhoc_roles_row($1,'');
1993: }
1994: }
1995: } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) {
1996: $output .= &adhoc_customroles_row($1,$2,'',$update,$then);
1997: }
1998: }
1999: }
2000: }
2001: if ($output) {
2002: if ($doheaders > 0) {
2003: $r->print(&Apache::loncommon::start_data_table_empty_row()
2004: .'<td align="center" colspan="5">'
2005: .&mt($type)
2006: .'</td>'
2007: .&Apache::loncommon::end_data_table_empty_row()
2008: );
2009: }
2010: $r->print($output);
2011: }
2012: }
2013: }
2014: }
2015:
2016: sub findcourse_advice {
2017: my ($r,$cattype,$elapsed) = @_;
2018: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
2019: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
2020: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
2021: $r->print('<p>'.&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).'
2022: <ul>
2023: <li>'.&mt('The course has yet to be created.').'</li>
2024: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
2025: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
2026: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
2027: <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>
2028: <li>'.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'</li>
2029: </ul></p>');
2030: } else {
2031: $r->print('<p>'.&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'</p>');
2032: if ($elapsed > 600) {
2033: $r->print('<p>'.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes.').
2034: '<br />'.
2035: &mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'</p>');
2036: }
2037: }
2038: if (($cattype eq 'std') || ($cattype eq 'domonly')) {
2039: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
2040: '<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 />');
2041: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
2042: &Apache::loncoursequeueadmin::queued_selfenrollment());
2043: }
2044: return;
2045: }
2046:
2047: sub requestcourse_advice {
2048: my ($r,$cattype,$inrole,$elapsed) = @_;
2049: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
2050: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
2051: my (%can_request,%request_doms,$output);
2052: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
2053: if (keys(%request_doms) > 0) {
2054: my ($types,$typename) = &Apache::loncommon::course_types();
2055: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
2056: my (@reqdoms,@reqtypes);
2057: foreach my $type (sort(keys(%request_doms))) {
2058: push(@reqtypes,$type);
2059: if (ref($request_doms{$type}) eq 'ARRAY') {
2060: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
2061: $output .=
2062: '<li>'
2063: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
2064: '<i>',
2065: '</i>',
2066: '<b>'.$domstr.'</b>')
2067: .'</li>';
2068: foreach my $dom (@{$request_doms{$type}}) {
2069: unless (grep(/^\Q$dom\E/,@reqdoms)) {
2070: push(@reqdoms,$dom);
2071: }
2072: }
2073: }
2074: }
2075: my @showtypes;
2076: foreach my $type (@{$types}) {
2077: if (grep(/^\Q$type\E$/,@reqtypes)) {
2078: push(@showtypes,$type);
2079: }
2080: }
2081: my $requrl = '/adm/requestcourse';
2082: if (@reqdoms == 1) {
2083: $requrl .= '?showdom='.$reqdoms[0];
2084: }
2085: if (@showtypes > 0) {
2086: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
2087: }
2088: if (@reqdoms == 1 || @showtypes > 0) {
2089: $requrl .= '&state=crstype&action=new';
2090: }
2091: if ($output) {
2092: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
2093: '<p>'.
2094: &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
2095: '<ul>'.
2096: $output.
2097: '</ul>'.
2098: &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
2099: '<a href="'.$requrl.'">','</a>').
2100: '</p>');
2101: }
2102: }
2103: } elsif (!$env{'user.adv'}) {
2104: if ($inrole) {
2105: $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
2106: } else {
2107: $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
2108: }
2109: &findcourse_advice($r,$cattype,$elapsed);
2110: }
2111: return;
2112: }
2113:
2114: sub privileges_info {
2115: my ($which) = @_;
2116: my $output;
2117:
2118: $which ||= $env{'request.role'};
2119:
2120: foreach my $envkey (sort(keys(%env))) {
2121: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
2122:
2123: my $where=$1;
2124: my $ttype;
2125: my $twhere;
2126: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
2127: if ($trest) {
2128: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
2129: $ttype='Authoring Space';
2130: $twhere='User: '.$trest.', Domain: '.$tdom;
2131: } else {
2132: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
2133: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
2134: if ($tsec) {
2135: my $sec_type = 'Section';
2136: if (exists($env{"user.role.gr.$where"})) {
2137: $sec_type = 'Group';
2138: }
2139: $twhere.=' ('.$sec_type.': '.$tsec.')';
2140: }
2141: }
2142: } elsif ($tdom) {
2143: $ttype='Domain';
2144: $twhere=$tdom;
2145: } else {
2146: $ttype='System';
2147: $twhere='/';
2148: }
2149: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
2150: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
2151: next if (!$priv);
2152:
2153: my ($prv,$restr)=split(/\&/,$priv);
2154: my $trestr='';
2155: if ($restr ne 'F') {
2156: $trestr.=' ('.
2157: join(', ',
2158: map { &Apache::lonnet::plaintext($_) }
2159: (split('',$restr))).') ';
2160: }
2161: $output .= "\n\t".
2162: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
2163: }
2164: $output .= "\n".'</ul>';
2165: }
2166: return $output;
2167: }
2168:
2169: sub build_roletext {
2170: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
2171: $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_;
2172: my ($roletext,$roletext_end,$poss_adhoc);
2173: if ($trolecode =~ m/^d(c|h|a)\./) {
2174: $poss_adhoc = 1;
2175: }
2176: my $rowspan=($poss_adhoc) ? ''
2177: : ' rowspan="2" ';
2178:
2179: unless ($nochoose) {
2180: my $buttonname=$trolecode;
2181: $buttonname=~s/\W//g;
2182: if (!$button) {
2183: if ($switchserver) {
2184: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
2185: .'<a href="/adm/switchserver?'.$switchserver.'">'
2186: .&mt('Switch Server')
2187: .'</a></td>';
2188: } else {
2189: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
2190: }
2191: if ($switchwarning) {
2192: if ($tremark eq '') {
2193: $tremark = $switchwarning;
2194: } else {
2195: $tremark .= '<br />'.$switchwarning;
2196: }
2197: }
2198: } elsif ($tstatus eq 'is') {
2199: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
2200: '<input name="'.$buttonname.'" type="button" value="'.
2201: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
2202: $trolecode."','".$buttonname.'\');" /></td>';
2203: } elsif ($tryagain) {
2204: $roletext.=
2205: '<td'.$rowspan.' class="'.$tbg.'">'.
2206: '<input name="'.$buttonname.'" type="button" value="'.
2207: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
2208: $trolecode."','".$buttonname.'\');" /></td>';
2209: } elsif ($advanced) {
2210: $roletext.=
2211: '<td'.$rowspan.' class="'.$tbg.'">'.
2212: '<input name="'.$buttonname.'" type="button" value="'.
2213: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
2214: $trolecode."','".$buttonname.'\');" /></td>';
2215: } elsif ($reinit) {
2216: $roletext.=
2217: '<td'.$rowspan.' class="'.$tbg.'">'.
2218: '<input name="'.$buttonname.'" type="button" value="'.
2219: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
2220: $trolecode."','".$buttonname.'\');" /></td>';
2221: } else {
2222: $roletext.=
2223: '<td'.$rowspan.' class="'.$tbg.'">'.
2224: '<input name="'.$buttonname.'" type="button" value="'.
2225: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
2226: $trolecode."','".$buttonname.'\');" /></td>';
2227: }
2228: }
2229: if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) {
2230: $tremark.=&Apache::lonannounce::showday(time,1,
2231: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
2232: }
2233: $roletext.='<td>'.$trole.'</td>'
2234: .'<td>'.$twhere.'</td>'
2235: .'<td>'.$tpstart.'</td>'
2236: .'<td>'.$tpend.'</td>';
2237: unless ($poss_adhoc) {
2238: $roletext_end = '<td colspan="4">'.
2239: $tremark.' '.
2240: '</td>';
2241: }
2242: return ($roletext,$roletext_end);
2243: }
2244:
2245: sub check_author_homeserver {
2246: my ($uname,$udom)=@_;
2247: if (($uname eq '') || ($udom eq '')) {
2248: return ('fail','');
2249: }
2250: my $home = &Apache::lonnet::homeserver($uname,$udom);
2251: if (&Apache::lonnet::host_domain($home) ne $udom) {
2252: return ('fail',$home);
2253: }
2254: my @ids=&Apache::lonnet::current_machine_ids();
2255: if (grep(/^\Q$home\E$/,@ids)) {
2256: return ('ok',$home);
2257: } else {
2258: return ('switchserver',$home);
2259: }
2260: }
2261:
2262: sub check_for_adhoc {
2263: my ($dcroles,$helpdeskroles,$update,$then) = @_;
2264: my $numdc = 0;
2265: my $numhelpdesk = 0;
2266: my $numadhoc = 0;
2267: my $num_custom_adhoc = 0;
2268: if (($env{'user.adv'}) || ($env{'user.rar'})) {
2269: foreach my $envkey (sort(keys(%env))) {
2270: if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) {
2271: my $role = $1;
2272: my $roledom = $2;
2273: my $liverole = 1;
2274: my ($tstart,$tend)=split(/\./,$env{$envkey});
2275: my $limit = $update;
2276: if ($env{'request.role'} eq "$role./$roledom/") {
2277: $limit = $then;
2278: }
2279: if ($tstart && $tstart>$limit) { $liverole = 0; }
2280: if ($tend && $tend <$limit) { $liverole = 0; }
2281: if ($liverole) {
2282: if ($role eq 'dc') {
2283: $dcroles->{$roledom} = $envkey;
2284: $numdc++;
2285: } else {
2286: $helpdeskroles->{$roledom} = $envkey;
2287: my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom);
2288: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2289: if (keys(%{$domdefaults{'adhocroles'}})) {
2290: $numadhoc ++;
2291: }
2292: }
2293: $numhelpdesk++;
2294: }
2295: }
2296: }
2297: }
2298: }
2299: return ($numdc,$numhelpdesk,$numadhoc);
2300: }
2301:
2302: sub adhoc_course_role {
2303: my ($refresh,$update,$then) = @_;
2304: my ($cdom,$cnum,$crstype);
2305: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2306: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2307: $crstype = &Apache::loncommon::course_type();
2308: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
2309: my $setprivs;
2310: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
2311: $setprivs = 1;
2312: } else {
2313: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
2314: if (($start && ($start>$refresh || $start == -1)) ||
2315: ($end && $end<$update)) {
2316: $setprivs = 1;
2317: }
2318: }
2319: unless ($setprivs) {
2320: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
2321: $setprivs = 1;
2322: }
2323: }
2324: if ($setprivs) {
2325: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
2326: my $role = $1;
2327: my $custom_role = $2;
2328: my $usec = $3;
2329: if ($role eq 'cr') {
2330: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
2331: $role .= $custom_role;
2332: } else {
2333: return;
2334: }
2335: }
2336: my (%userroles,%newrole,%newgroups,%group_privs);
2337: my %cgroups =
2338: &Apache::lonnet::get_active_groups($env{'user.domain'},
2339: $env{'user.name'},$cdom,$cnum);
2340: my $ccrole;
2341: if ($crstype eq 'Community') {
2342: $ccrole = 'co';
2343: } else {
2344: $ccrole = 'cc';
2345: }
2346: foreach my $group (keys(%cgroups)) {
2347: $group_privs{$group} =
2348: $env{'user.priv.'.$ccrole.'./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
2349: }
2350: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
2351: my $area = '/'.$cdom.'/'.$cnum;
2352: my $spec = $role.'.'.$area;
2353: if ($usec ne '') {
2354: $spec .= '/'.$usec;
2355: $area .= '/'.$usec;
2356: }
2357: if ($role =~ /^cr/) {
2358: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
2359: } else {
2360: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
2361: }
2362: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
2363: my $adhocstart = $refresh-1;
2364: $userroles{'user.role.'.$spec} = $adhocstart.'.';
2365: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
2366: }
2367: }
2368: }
2369: return;
2370: }
2371:
2372: sub check_forcc {
2373: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
2374: my ($is_cc,$ccrole);
2375: if ($crstype eq 'Community') {
2376: $ccrole = 'co';
2377: } else {
2378: $ccrole = 'cc';
2379: }
2380: if (&Apache::lonnet::is_course($cdom,$cnum)) {
2381: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
2382: if (defined($env{$envkey})) {
2383: $is_cc = 1;
2384: my ($tstart,$tend)=split(/\./,$env{$envkey});
2385: my $limit = $update;
2386: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
2387: $limit = $then;
2388: }
2389: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
2390: if ($tend && $tend <$limit) { $is_cc = 0; }
2391: }
2392: }
2393: return $is_cc;
2394: }
2395:
2396: sub courselink {
2397: my ($roledom,$rowtype,$role) = @_;
2398: my $courseform=&Apache::loncommon::selectcourse_link
2399: ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
2400: 'domain'.$rowtype.'_'.$roledom.'_'.$role,
2401: 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
2402: $roledom.':'.$role,undef,'Course/Community');
2403: my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
2404: '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
2405: '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
2406: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
2407: return $courseform.$hiddenitems;
2408: }
2409:
2410: sub coursepick_jscript {
2411: my %js_lt = &Apache::lonlocal::texthash(
2412: 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.",
2413: youc => 'You can only use this screen to select courses and communities in the current domain.',
2414: );
2415: &js_escape(\%js_lt);
2416: my $verify_script = <<"END";
2417: <script type="text/javascript">
2418: // <![CDATA[
2419: function verifyCoursePick(caller) {
2420: var numbutton = getIndex(caller)
2421: var pickedCourse = document.rolechoice.elements[numbutton+4].value
2422: var pickedDomain = document.rolechoice.elements[numbutton+2].value
2423: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
2424: if (pickedCourse != '') {
2425: if (numbutton != -1) {
2426: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
2427: document.rolechoice.elements[numbutton+1].name = courseTarget
2428: document.rolechoice.submit()
2429: }
2430: }
2431: else {
2432: alert("$js_lt{'plsu'}");
2433: }
2434: }
2435: else {
2436: alert("$js_lt{'youc'}")
2437: }
2438: }
2439: function getIndex(caller) {
2440: for (var i=0;i<document.rolechoice.elements.length;i++) {
2441: if (document.rolechoice.elements[i] == caller) {
2442: return i;
2443: }
2444: }
2445: return -1;
2446: }
2447: // ]]>
2448: </script>
2449: END
2450: return $verify_script;
2451: }
2452:
2453: sub coauthorlink {
2454: my ($dcdom,$rowtype) = @_;
2455: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
2456: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
2457: return $coauthorform.$hiddenitems;
2458: }
2459:
2460: sub display_cc_role {
2461: my $rolekey = shift;
2462: my ($roletext,$roletext_end);
2463: my $advanced = $env{'user.adv'};
2464: my $tryagain = $env{'form.tryagain'};
2465: unless ($rolekey =~/^error\:/) {
2466: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
2467: my $ccrole = $1;
2468: my $tdom = $2;
2469: my $trest = $3;
2470: my $tcourseid = $tdom.'_'.$trest;
2471: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
2472: my $twhere;
2473: my $ttype;
2474: my $skipcal;
2475: my $tbg='LC_roles_is';
2476: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2477: if (%newhash) {
2478: $twhere=$newhash{'description'}.
2479: ' <span class="LC_fontsize_small">'.
2480: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
2481: '</span>';
2482: $ttype = $newhash{'type'};
2483: } else {
2484: $twhere=&mt('Currently not available');
2485: $env{'course.'.$tcourseid.'.description'}=$twhere;
2486: $skipcal = 1;
2487: }
2488: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
2489: $twhere.="<br />".&mt('Domain').":".$tdom;
2490: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
2491: }
2492: }
2493: return ($roletext,$roletext_end);
2494: }
2495:
2496: sub display_curr_role {
2497: my ($currentrole) = @_;
2498: my ($roletext,$roletext_end);
2499: my $advanced = $env{'user.adv'};
2500: my $tryagain = $env{'form.tryagain'};
2501: my ($role,$rest) = split(m{\./},$currentrole,2);
2502: unless (!defined($role) || $role eq '') {
2503: if ($rest =~ m{^($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
2504: my $cdom = $1;
2505: my $cnum = $2;
2506: my $csec = $3;
2507: my $cid = $cdom.'_'.$cnum;
2508: my $ttype = $env{'course.'.$cid.'.type'};
2509: my $skipcal = 1;
2510: my $tbg='LC_roles_is';
2511: my $twhere = $env{'course.'.$cid.'.description'}.
2512: ' <span class="LC_fontsize_small">'.
2513: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom).
2514: '</span>';
2515: my $trole = &Apache::lonnet::plaintext($role,$ttype,$cid);
2516: if ($csec) {
2517: $twhere.= ' '.&mt('Section').': '.$csec;
2518: }
2519: if ($role ne 'st') {
2520: $twhere.= ' '.&mt('Domain').': '.$cdom;
2521: }
2522: ($roletext,$roletext_end) = &build_roletext($currentrole,$cdom,$cnum,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
2523: }
2524: }
2525: return ($roletext,$roletext_end);
2526: }
2527:
2528: sub adhoc_roles_row {
2529: my ($dcdom,$rowtype) = @_;
2530: my $output = &Apache::loncommon::continue_data_table_row()
2531: .' <td colspan="5" class="LC_textsize_mobile">'
2532: .&mt('[_1]Ad hoc[_2] roles in domain [_3]'
2533: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
2534: .' -- ';
2535: my $role = 'cc';
2536: my $selectcclink = &courselink($dcdom,$rowtype,$role);
2537: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
2538: my $carole = &Apache::lonnet::plaintext('ca');
2539: my $selectcalink = &coauthorlink($dcdom,$rowtype);
2540: $output.=$ccrole.': '.$selectcclink
2541: .' | '.$carole.': '.$selectcalink.'</td>'
2542: .&Apache::loncommon::end_data_table_row();
2543: return $output;
2544: }
2545:
2546: sub adhoc_customroles_row {
2547: my ($role,$dhdom,$rowtype,$update,$then) = @_;
2548: my $liverole = 1;
2549: my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"});
2550: my $limit = $update;
2551: if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) {
2552: $limit = $then;
2553: }
2554: if ($tstart && $tstart>$limit) { $liverole = 0; }
2555: if ($tend && $tend <$limit) { $liverole = 0; }
2556: return unless ($liverole);
2557: my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom);
2558: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2559: if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) {
2560: return &Apache::loncommon::continue_data_table_row()
2561: .' <td colspan="5" class="LC_textsize_mobile">'
2562: .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]',
2563: '<span class="LC_cusr_emph">','</span>',$dhdom)
2564: .' -- '.&courselink($dhdom,$rowtype,$role);
2565: }
2566: }
2567: return;
2568: }
2569:
2570: sub recent_filename {
2571: my $area=shift;
2572: return 'nohist_recent_'.&escape($area);
2573: }
2574:
2575: sub courseloadpage {
2576: my ($courseid) = @_;
2577: my $startpage;
2578: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
2579: [$courseid.':courseinit']);
2580: my ($tmp) = %entry_settings;
2581: unless ($tmp =~ /^error: 2 /) {
2582: $startpage = $entry_settings{$courseid.':courseinit'};
2583: }
2584: if ($startpage eq '') {
2585: if (exists($env{'environment.course_init_display'})) {
2586: $startpage = $env{'environment.course_init_display'};
2587: }
2588: }
2589: return $startpage;
2590: }
2591:
2592: sub update_session_roles {
2593: my $then=$env{'user.login.time'};
2594: my $refresh=$env{'user.refresh.time'};
2595: if (!$refresh) {
2596: $refresh = $then;
2597: }
2598: my $update = $env{'user.update.time'};
2599: if (!$update) {
2600: $update = $then;
2601: }
2602: my $now = time;
2603: my %roleshash =
2604: &Apache::lonnet::get_my_roles('','','userroles',
2605: ['active','future','previous'],
2606: undef,undef,1);
2607: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
2608: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
2609: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
2610: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
2611: @rolecodes);
2612: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
2613: my %courseroles;
2614: foreach my $item (keys(%roleshash)) {
2615: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
2616: my ($tstart,$tend) = split(/:/,$roleshash{$item});
2617: my ($section,$group,@group_privs);
2618: if ($role =~ m{^gr/(\w*)$}) {
2619: $role = 'gr';
2620: my $priv = $1;
2621: next if ($tstart eq '-1');
2622: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2623: if ($priv ne '') {
2624: push(@group_privs,$priv);
2625: }
2626: }
2627: if ($remainder =~ /:/) {
2628: (my $additional_privs,$group) =
2629: ($remainder =~ /^([\w:]+):([^:]+)$/);
2630: if ($additional_privs ne '') {
2631: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2632: push(@group_privs,split(/:/,$additional_privs));
2633: @group_privs = sort(@group_privs);
2634: }
2635: }
2636: } else {
2637: $group = $remainder;
2638: }
2639: } else {
2640: $section = $remainder;
2641: }
2642: my $where = "/$udom/$uname";
2643: if ($section ne '') {
2644: $where .= "/$section";
2645: } elsif ($group ne '') {
2646: $where .= "/$group";
2647: }
2648: my $rolekey = "$role.$where";
2649: my $envkey = "user.role.$rolekey";
2650: $dbroles{$envkey} = 1;
2651: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2652: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2653: $currrole_expired = 1;
2654: }
2655: }
2656: if ($env{$envkey} eq '') {
2657: my $status_in_db =
2658: &curr_role_status($tstart,$tend,$now,$now);
2659: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2660: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2661: if ($status_in_db eq 'active') {
2662: if ($section eq '') {
2663: push(@newsec,'none');
2664: } else {
2665: push(@newsec,$section);
2666: }
2667: }
2668: } else {
2669: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2670: push(@changed_roles,$role);
2671: }
2672: if ($status_in_db ne 'previous') {
2673: if ($role eq 'gr') {
2674: $newgroup{$rolekey} = $status_in_db;
2675: if ($status_in_db eq 'active') {
2676: unless (ref($courseroles{$udom}) eq 'HASH') {
2677: %{$courseroles{$udom}} =
2678: &Apache::lonnet::get_my_roles('','','userroles',
2679: ['active'],\@possroles,
2680: [$udom],1);
2681: }
2682: &Apache::lonnet::get_groups_roles($udom,$uname,
2683: $courseroles{$udom},
2684: \@rolecodes,\%groups_roles);
2685: }
2686: } else {
2687: $newrole{$rolekey} = $status_in_db;
2688: }
2689: }
2690: }
2691: } else {
2692: my ($currstart,$currend) = split(/\./,$env{$envkey});
2693: if ($role eq 'gr') {
2694: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2695: $hasgroups = 1;
2696: }
2697: }
2698: if (($currstart ne $tstart) || ($currend ne $tend)) {
2699: my $status_in_env =
2700: &curr_role_status($currstart,$currend,$refresh,$update);
2701: my $status_in_db =
2702: &curr_role_status($tstart,$tend,$now,$now);
2703: if ($status_in_env ne $status_in_db) {
2704: if ($status_in_env eq 'active') {
2705: if ($role eq 'st') {
2706: if ($env{'request.role'} eq $rolekey) {
2707: my $switchsection;
2708: unless (ref($courseroles{$udom}) eq 'HASH') {
2709: %{$courseroles{$udom}} =
2710: &Apache::lonnet::get_my_roles('','','userroles',
2711: ['active'],
2712: \@possroles,[$udom],1);
2713: }
2714: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2715: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2716: $switchsection = 1;
2717: last;
2718: }
2719: }
2720: if ($switchsection) {
2721: if ($section eq '') {
2722: $oldsec = 'none';
2723: } else {
2724: $oldsec = $section;
2725: }
2726: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2727: } else {
2728: $currrole_expired = 1;
2729: next;
2730: }
2731: }
2732: }
2733: unless ($rolekey eq $env{'request.role'}) {
2734: if ($role eq 'gr') {
2735: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2736: } else {
2737: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2738: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2739: }
2740: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2741: }
2742: } elsif ($status_in_db eq 'active') {
2743: if (($role eq 'st') &&
2744: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2745: if ($section eq '') {
2746: push(@newsec,'none');
2747: } else {
2748: push(@newsec,$section);
2749: }
2750: } elsif ($role eq 'gr') {
2751: unless (ref($courseroles{$udom}) eq 'HASH') {
2752: %{$courseroles{$udom}} =
2753: &Apache::lonnet::get_my_roles('','','userroles',
2754: ['active'],
2755: \@possroles,[$udom],1);
2756: }
2757: &Apache::lonnet::get_groups_roles($udom,$uname,
2758: $courseroles{$udom},
2759: \@rolecodes,\%groups_roles);
2760: }
2761: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2762: }
2763: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2764: push(@changed_roles,$role);
2765: }
2766: if ($role eq 'gr') {
2767: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2768: } else {
2769: $rolechange{$rolekey} = $status_in_db;
2770: }
2771: }
2772: } else {
2773: if ($role eq 'gr') {
2774: unless ($checkedgroup{$where}) {
2775: my $status_in_db =
2776: &curr_role_status($tstart,$tend,$refresh,$now);
2777: if ($tstart eq '-1') {
2778: $status_in_db = 'deleted';
2779: }
2780: unless (ref($courseroles{$udom}) eq 'HASH') {
2781: %{$courseroles{$udom}} =
2782: &Apache::lonnet::get_my_roles('','','userroles',
2783: ['active'],
2784: \@possroles,[$udom],1);
2785: }
2786: if (ref($courseroles{$udom}) eq 'HASH') {
2787: foreach my $item (keys(%{$courseroles{$udom}})) {
2788: next unless ($item =~ /^\Q$uname\E/);
2789: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2790: my $area = '/'.$cdom.'/'.$cnum;
2791: if ($crssec ne '') {
2792: $area .= '/'.$crssec;
2793: }
2794: my $crsrolekey = $crsrole.'.'.$area;
2795: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2796: $currprivs =~ s/^://;
2797: $currprivs =~ s/\&F$//;
2798: my @curr_grp_privs = split(/\&F:/,$currprivs);
2799: @curr_grp_privs = sort(@curr_grp_privs);
2800: my @diffs;
2801: if (@group_privs > 0 || @curr_grp_privs > 0) {
2802: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2803: }
2804: if (@diffs == 0) {
2805: last;
2806: } else {
2807: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2808: push(@rolecodes,'gr');
2809: }
2810: &gather_roleprivs(\%allroles,\%allgroups,
2811: \%userroles,$where,$role,
2812: $tstart,$tend,$status_in_db);
2813: if ($status_in_db eq 'active') {
2814: &Apache::lonnet::get_groups_roles($udom,$uname,
2815: $courseroles{$udom},
2816: \@rolecodes,\%groups_roles);
2817: }
2818: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2819: last;
2820: }
2821: }
2822: }
2823: $checkedgroup{$where} = 1;
2824: }
2825: } elsif ($role =~ /^cr/) {
2826: my $status_in_db =
2827: &curr_role_status($tstart,$tend,$refresh,$now);
2828: my ($rdummy,$rest) = split(/\//,$role,2);
2829: my %currpriv;
2830: unless (exists($crprivs{$rest})) {
2831: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2832: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2833: if (&Apache::lonnet::hostname($homsvr) ne '') {
2834: my ($rdummy,$roledef)=
2835: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2836: $rdomain,$rauthor);
2837: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2838: my $i = 0;
2839: my @scopes = ('sys','dom','crs');
2840: my @privs = split(/\_/,$roledef);
2841: foreach my $priv (@privs) {
2842: my ($blank,@prv) = split(/:/,$priv);
2843: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
2844: if (@prv) {
2845: $priv = ':'.join(':',sort(@prv));
2846: }
2847: $crprivs{$rest}{$scopes[$i]} = $priv;
2848: $i++;
2849: }
2850: }
2851: }
2852: }
2853: my $status_in_env =
2854: &curr_role_status($currstart,$currend,$refresh,$update);
2855: if ($status_in_env eq 'active') {
2856: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2857: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2858: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2859: if (keys(%crprivs)) {
2860: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2861: ($crprivs{$rest}{dom} ne $currpriv{dom})
2862: ||
2863: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2864: &gather_roleprivs(\%allroles,\%allgroups,
2865: \%userroles,$where,$role,
2866: $tstart,$tend,$status_in_db);
2867: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2868: push(@changed_roles,$role);
2869: }
2870: $customprivchg{$rolekey} = $status_in_env;
2871: }
2872: }
2873: }
2874: }
2875: }
2876: }
2877: }
2878: foreach my $envkey (keys(%env)) {
2879: next unless ($envkey =~ /^user\.role\./);
2880: next if ($dbroles{$envkey});
2881: next if ($envkey eq 'user.role.'.$env{'request.role'});
2882: my ($currstart,$currend) = split(/\./,$env{$envkey});
2883: my $status_in_env =
2884: &curr_role_status($currstart,$currend,$refresh,$update);
2885: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2886: my ($role,$rest)=split(m{\./},$rolekey,2);
2887: $rest = '/'.$rest;
2888: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2889: if ($status_in_env eq 'active') {
2890: if ($role eq 'gr') {
2891: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2892: \@possroles);
2893: } else {
2894: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2895: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2896: }
2897: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2898: push(@changed_roles,$role);
2899: }
2900: $deletedroles{$rolekey} = 1;
2901: }
2902: }
2903: }
2904: if (($oldsec) && (@newsec > 0)) {
2905: if (@newsec > 1) {
2906: $msg = '<p class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</p>';
2907: } else {
2908: my $newrole = $env{'request.role'};
2909: if ($newsec[0] eq 'none') {
2910: $newrole =~ s{(/[^/])$}{};
2911: } elsif ($oldsec eq 'none') {
2912: $newrole .= '/'.$newsec[0];
2913: } else {
2914: $newrole =~ s{([^/]+)$}{$newsec[0]};
2915: }
2916: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2917: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2918: my %temp=('logout_'.$env{'request.course.id'} => time);
2919: &Apache::lonnet::put('email_status',\%temp);
2920: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2921: &Apache::lonnet::appenv({"request.course.id" => '',
2922: "request.course.fn" => '',
2923: "request.course.uri" => '',
2924: "request.course.sec" => '',
2925: "request.role" => 'cm',
2926: "request.role.adv" => $env{'user.adv'},
2927: "request.role.domain" => $env{'user.domain'}});
2928: my $rolename = &Apache::loncommon::plainname($curr_role);
2929: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2930: '<input type="hidden" name="newrole" value="" />'.
2931: '<input type="hidden" name="selectrole" value="1" />'.
2932: '<span class="LC_info">'.
2933: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2934: my $button = '<input type="button" name="sectionchanged" value="'.
2935: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2936: if ($newsec[0] eq 'none') {
2937: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2938: } else {
2939: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2940: }
2941: $msg .= '</form></p>';
2942: }
2943: } elsif ($currrole_expired) {
2944: $msg .= '<p class="LC_warning">';
2945: if (&Apache::loncommon::show_course()) {
2946: $msg .= &mt('Your role in the current course has expired.');
2947: } else {
2948: $msg .= &mt('Your current role has expired.');
2949: }
2950: $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</p>';
2951: }
2952: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2953: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2954: $curr_author = $env{'user.author'};
2955: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2956: ($env{'request.role'} =~/^aa/)) {
2957: $curr_role_author=1;
2958: }
2959: $curr_is_adv = $env{'user.adv'};
2960: $curr_role_adv = $env{'request.role.adv'};
2961: if (keys(%userroles) > 0) {
2962: foreach my $role (@changed_roles) {
2963: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2964: push(@rolecodes,$role);
2965: }
2966: }
2967: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2968: push(@rolecodes,'cm');
2969: }
2970: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2971: }
2972: my %newenv;
2973: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2974: unless ($curr_is_adv) {
2975: $newenv{'user.adv'} = 1;
2976: }
2977: } elsif ($curr_is_adv && !$curr_role_adv) {
2978: &Apache::lonnet::delenv('user.adv');
2979: }
2980: my %authorroleshash =
2981: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2982: if (keys(%authorroleshash)) {
2983: unless ($curr_author) {
2984: $newenv{'user.author'} = 1;
2985: }
2986: } elsif ($curr_author && !$curr_role_author) {
2987: &Apache::lonnet::delenv('user.author');
2988: }
2989: if ($env{'request.course.id'}) {
2990: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2991: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2992: my (@activecrsgroups,$crsgroupschanged);
2993: if ($env{'request.course.groups'}) {
2994: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2995: foreach my $item (keys(%deletedroles)) {
2996: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2997: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2998: $crsgroupschanged = 1;
2999: last;
3000: }
3001: }
3002: }
3003: }
3004: unless ($crsgroupschanged) {
3005: foreach my $item (keys(%newgroup)) {
3006: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
3007: if ($newgroup{$item} eq 'active') {
3008: $crsgroupschanged = 1;
3009: last;
3010: }
3011: }
3012: }
3013: }
3014: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
3015: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
3016: ($crsgroupschanged)) {
3017: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
3018: ['active'],['gr'],[$cdom],1);
3019: my @activegroups;
3020: foreach my $item (keys(%grouproles)) {
3021: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
3022: my $group;
3023: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
3024: if ($remainder =~ /:/) {
3025: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
3026: } else {
3027: $group = $remainder;
3028: }
3029: if ($group ne '') {
3030: push(@activegroups,$group);
3031: }
3032: }
3033: $newenv{'request.course.groups'} = join(':',@activegroups);
3034: }
3035: }
3036: if (keys(%newenv)) {
3037: &Apache::lonnet::appenv(\%newenv);
3038: }
3039: if (!@changed_roles || !(keys(%changed_groups))) {
3040: my ($rolesmsg,$groupsmsg);
3041: if (!@changed_roles) {
3042: if (&Apache::loncommon::show_course()) {
3043: $rolesmsg = &mt('No new courses or communities');
3044: } else {
3045: $rolesmsg = &mt('No role changes');
3046: }
3047: }
3048: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
3049: $groupsmsg = &mt('No changes in course/community groups');
3050: }
3051: if (!@changed_roles && !(keys(%changed_groups))) {
3052: if (($msg ne '') || ($groupsmsg ne '')) {
3053: $msg .= '<ul>';
3054: if ($rolesmsg) {
3055: $msg .= '<li>'.$rolesmsg.'</li>';
3056: }
3057: if ($groupsmsg) {
3058: $msg .= '<li>'.$groupsmsg.'</li>';
3059: }
3060: $msg .= '</ul>';
3061: } else {
3062: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
3063: }
3064: return $msg;
3065: }
3066: }
3067: my $changemsg;
3068: if (@changed_roles > 0) {
3069: if (keys(%newgroup) > 0) {
3070: my $groupmsg;
3071: my (%curr_groups,%groupdescs,$currcrs);
3072: foreach my $item (sort(keys(%newgroup))) {
3073: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
3074: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
3075: my ($cdom,$cnum) = split(/\//,$1);
3076: my $group = $2;
3077: if ($currcrs ne $cdom.'_'.$cnum) {
3078: if ($currcrs) {
3079: $groupmsg .= '</ul><li>';
3080: }
3081: $groupmsg .= '<li><b>'.
3082: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
3083: $currcrs = $cdom.'_'.$cnum;
3084: }
3085: my $groupdesc;
3086: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
3087: %{$curr_groups{$cdom.'_'.$cnum}} =
3088: &Apache::longroup::coursegroups($cdom,$cnum);
3089: }
3090: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
3091: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
3092:
3093: my %groupinfo =
3094: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
3095: $groupdescs{$cdom.'_'.$cnum}{$group} =
3096: &unescape($groupinfo{'description'});
3097: }
3098: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
3099: if ($groupdesc) {
3100: $groupmsg .= '<li>'.
3101: &mt('[_1] with status: [_2].',
3102: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
3103: }
3104: }
3105: }
3106: if ($groupmsg) {
3107: $groupmsg .= '</ul></li>';
3108: }
3109: }
3110: if ($groupmsg) {
3111: $changemsg .= '<li>'.
3112: &mt('Courses with new groups').'</li>'.
3113: '<ul>'.$groupmsg.'</ul></li>';
3114: }
3115: }
3116: if (keys(%newrole) > 0) {
3117: my $newmsg;
3118: foreach my $item (sort(keys(%newrole))) {
3119: my $desc = &role_desc($item,$update,$refresh,$now);
3120: if ($desc) {
3121: $newmsg .= '<li>'.
3122: &mt('[_1] with status: [_2].',
3123: $desc,&mt($newrole{$item})).'</li>';
3124: }
3125: }
3126: if ($newmsg) {
3127: $changemsg .= '<li>'.&mt('New roles').
3128: '<ul>'.$newmsg.'</ul>'.
3129: '</li>';
3130: }
3131: }
3132: if (keys(%customprivchg) > 0) {
3133: my $privmsg;
3134: foreach my $item (sort(keys(%customprivchg))) {
3135: my $desc = &role_desc($item,$update,$refresh,$now);
3136: if ($desc) {
3137: $privmsg .= '<li>'.$desc.'</li>';
3138: }
3139: }
3140: if ($privmsg) {
3141: $changemsg .= '<li>'.
3142: &mt('Custom roles with privilege changes').
3143: '<ul>'.$privmsg.'</ul>'.
3144: '</li>';
3145: }
3146: }
3147: if (keys(%rolechange) > 0) {
3148: my $rolemsg;
3149: foreach my $item (sort(keys(%rolechange))) {
3150: my $desc = &role_desc($item,$update,$refresh,$now);
3151: if ($desc) {
3152: $rolemsg .= '<li>'.
3153: &mt('[_1] status now: [_2].',$desc,
3154: $rolechange{$item}).'</li>';
3155: }
3156: }
3157: if ($rolemsg) {
3158: $changemsg .= '<li>'.
3159: &mt('Existing roles with status changes').'</li>'.
3160: '<ul>'.$rolemsg.'</ul>'.
3161: '</li>';
3162: }
3163: }
3164: if (keys(%deletedroles) > 0) {
3165: my $delmsg;
3166: foreach my $item (sort(keys(%deletedroles))) {
3167: my $desc = &role_desc($item,$update,$refresh,$now);
3168: if ($desc) {
3169: $delmsg .= '<li>'.$desc.'</li>';
3170: }
3171: }
3172: if ($delmsg) {
3173: $changemsg .= '<li>'.
3174: &mt('Existing roles now expired').'</li>'.
3175: '<ul>'.$delmsg.'</ul>'.
3176: '</li>';
3177: }
3178: }
3179: }
3180: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
3181: my $groupchgmsg;
3182: foreach my $key (sort(keys(%changed_groups))) {
3183: my $crs = 'gr/'.$key;
3184: $crs =~ s/_/\//;
3185: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
3186: if (ref($changed_groups{$key}) eq 'HASH') {
3187: my @showgroups;
3188: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
3189: if ($changed_groups{$key}{$group} eq 'active') {
3190: push(@showgroups,$group);
3191: }
3192: }
3193: if (@showgroups > 0) {
3194: $groupchgmsg .= '<li>'.
3195: &mt('Course: [_1], groups: [_2].',$key,
3196: join(', ',@showgroups)).
3197: '</li>';
3198: }
3199: }
3200: }
3201: }
3202: if (keys(%groupchange) > 0) {
3203: $groupchgmsg .= '<li>'.
3204: &mt('Existing course/community groups with status changes').'</li>'.
3205: '<ul>';
3206: foreach my $crs (sort(keys(%groupchange))) {
3207: my $cid = $crs;
3208: $cid=~s{^/}{};
3209: $cid=~s{/}{_};
3210: my $crsdesc = $env{'course.'.$cid.'.description'};
3211: my $cdom = $env{'course.'.$cid.'.domain'};
3212: my $cnum = $env{'course.'.$cid.'.num'};
3213: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
3214: my %groupdesc;
3215: if (ref($groupchange{$crs}) eq 'HASH') {
3216: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
3217: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
3218: unless ($groupdesc{$group}) {
3219: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
3220: $groupdesc{$group} = &unescape($groupinfo{'description'});
3221: }
3222: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
3223: }
3224: $groupchgmsg .= '</ul></li>';
3225: }
3226: }
3227: $groupchgmsg .= '</ul></li>';
3228: }
3229: if ($groupchgmsg) {
3230: $changemsg .= '<li>'.
3231: &mt('Courses with changes in groups').'</li>'.
3232: '<ul>'.$groupchgmsg.'</ul></li>';
3233: }
3234: }
3235: if ($changemsg) {
3236: $msg .= '<ul>'.$changemsg.'</ul>';
3237: } else {
3238: if (&Apache::loncommon::show_course()) {
3239: $msg = &mt('No new courses or communities');
3240: } else {
3241: $msg = &mt('No role changes');
3242: }
3243: }
3244: return $msg;
3245: }
3246:
3247: sub role_desc {
3248: my ($item,$update,$refresh,$now) = @_;
3249: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
3250: $trole,$tremark);
3251: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
3252: $now,\$role,\$where,\$trolecode,
3253: \$tstatus,\$tstart,\$tend);
3254: return unless ($role);
3255: if ($role =~ /^cr\//) {
3256: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
3257: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
3258: }
3259: $trole=Apache::lonnet::plaintext($role);
3260: my ($tdom,$trest,$tsection)=
3261: split(/\//,Apache::lonnet::declutter($where));
3262: if (($role eq 'ca') || ($role eq 'aa')) {
3263: my $home = &Apache::lonnet::homeserver($trest,$tdom);
3264: $home = &Apache::lonnet::hostname($home);
3265: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
3266: ': '.$tdom.' '.&mt('Server').': '.$home;
3267: } elsif ($role eq 'au') {
3268: my $home = &Apache::lonnet::homeserver
3269: ($env{'user.name'},$env{'user.domain'});
3270: $home = &Apache::lonnet::hostname($home);
3271: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
3272: ': '.$home;
3273: } elsif ($trest) {
3274: my $tcourseid=$tdom.'_'.$trest;
3275: my $crstype = &Apache::loncommon::course_type($tcourseid);
3276: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
3277: if ($env{'course.'.$tcourseid.'.description'}) {
3278: $twhere=$env{'course.'.$tcourseid.'.description'};
3279: } else {
3280: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
3281: if (%newhash) {
3282: $twhere=$newhash{'description'};
3283: } else {
3284: $twhere=&mt('Currently not available');
3285: }
3286: }
3287: if ($tsection) {
3288: $twhere.= ' '.&mt('Section').': '.$tsection;
3289: }
3290: if ($role ne 'st') {
3291: $twhere.= ' '.&mt('Domain').': '.$tdom;
3292: }
3293: } elsif ($tdom) {
3294: $twhere = &mt('Domain').': '.$tdom;
3295: }
3296: my $output;
3297: if ($trole) {
3298: $output = $trole;
3299: if ($twhere) {
3300: $output .= " -- $twhere";
3301: }
3302: if ($tremark) {
3303: $output .= '<br />'.$tremark;
3304: }
3305: }
3306: return $output;
3307: }
3308:
3309: sub curr_role_status {
3310: my ($start,$end,$refresh,$update) = @_;
3311: if (($start) && ($start<0)) { return 'deleted' };
3312: my $status = 'active';
3313: if (($end) && ($end<=$update)) {
3314: $status = 'previous';
3315: }
3316: if (($start) && ($refresh<$start)) {
3317: $status = 'future';
3318: }
3319: return $status;
3320: }
3321:
3322: sub gather_roleprivs {
3323: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
3324: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
3325: if (($area ne '') && ($role ne '')) {
3326: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
3327: $area,$tstart,$tend);
3328: my $spec=$role.'.'.$area;
3329: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
3330: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
3331: if ($status eq 'active') {
3332: if ($role =~ /^cr\//) {
3333: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
3334: } elsif ($role eq 'gr') {
3335: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
3336: $env{'user.domain'},
3337: $env{'user.name'});
3338: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
3339: (undef,my $group_privs) = split(/\//,$trole);
3340: $group_privs = &unescape($group_privs);
3341: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
3342: } else {
3343: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
3344: }
3345: }
3346: }
3347: return;
3348: }
3349:
3350: sub is_active_course {
3351: my ($rolekey,$refresh,$update,$roleshashref) = @_;
3352: return unless(ref($roleshashref) eq 'HASH');
3353: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
3354: my $is_active;
3355: foreach my $key (keys(%{$roleshashref})) {
3356: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
3357: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
3358: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
3359: if ($status eq 'active') {
3360: $is_active = 1;
3361: last;
3362: }
3363: }
3364: }
3365: return $is_active;
3366: }
3367:
3368: sub get_roles_functions {
3369: my ($rolescount,$cattype) = @_;
3370: my @links;
3371: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
3372: if ($env{'environment.canrequest.author'}) {
3373: unless (&Apache::loncoursequeueadmin::is_active_author()) {
3374: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
3375: }
3376: }
3377: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
3378: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
3379: }
3380: if (&Apache::lonmenu::check_for_rcrs()) {
3381: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
3382: }
3383: if ($env{'form.state'} eq 'queued') {
3384: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
3385: } else {
3386: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
3387: }
3388: if ($env{'user.adv'}) {
3389: if ($env{'form.display'} eq 'showall') {
3390: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
3391: } else {
3392: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
3393: }
3394: }
3395: unless ($cattype eq 'none') {
3396: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
3397: }
3398: my $funcs;
3399: if ($env{'browser.mobile'}) {
3400: my @functions;
3401: foreach my $link (@links) {
3402: push(@functions,[$link->[0],$link->[2]]);
3403: }
3404: my $title = 'Display options';
3405: if ($env{'user.adv'}) {
3406: $title = 'Roles options';
3407: }
3408: $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
3409: $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
3410: } else {
3411: $funcs = &Apache::lonhtmlcommon::start_funclist();
3412: foreach my $link (@links) {
3413: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
3414: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
3415: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
3416: $link->[2].'</a>');
3417: }
3418: $funcs .= &Apache::lonhtmlcommon::end_funclist();
3419: $funcs = &Apache::loncommon::head_subbox($funcs);
3420: }
3421: return $funcs;
3422: }
3423:
3424: sub get_queued {
3425: my ($output,%reqcrs);
3426: my ($types,$typenames) = &Apache::loncommon::course_types();
3427: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
3428: $env{'user.name'},'^status:');
3429: foreach my $key (keys(%statusinfo)) {
3430: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
3431: (undef,my($cdom,$cnum)) = split(/:/,$key);
3432: my $requestkey = $cdom.'_'.$cnum;
3433: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3434: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
3435: $env{'user.domain'},$env{'user.name'});
3436: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
3437: my $reqtime = $history{'reqtime'};
3438: my $lastupdate = $history{'timestamp'};
3439: my $showtype = $history{'crstype'};
3440: if (defined($typenames->{$history{'crstype'}})) {
3441: $showtype = $typenames->{$history{'crstype'}};
3442: }
3443: my $description;
3444: if (ref($history{'details'}) eq 'HASH') {
3445: $description = $history{details}{'cdescr'};
3446: }
3447: @{$reqcrs{$reqtime}} = ($description,$showtype);
3448: }
3449: }
3450: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
3451: if (@sortedtimes > 0) {
3452: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
3453: &Apache::loncommon::start_data_table().
3454: &Apache::loncommon::start_data_table_header_row().
3455: '<th>'.&mt('Date requested').'</th>'.
3456: '<th>'.&mt('Course title').'</th>'.
3457: '<th>'.&mt('Course type').'</th>';
3458: &Apache::loncommon::end_data_table_header_row();
3459: foreach my $reqtime (@sortedtimes) {
3460: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
3461: $output .= &Apache::loncommon::start_data_table_row().
3462: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
3463: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
3464: &Apache::loncommon::end_data_table_row();
3465: }
3466: $output .= &Apache::loncommon::end_data_table().
3467: '<br /></p>';
3468: }
3469: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
3470: if ($queuedselfenroll) {
3471: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
3472: $queuedselfenroll.'<br /></p>';
3473: }
3474: if ($env{'environment.canrequest.author'}) {
3475: unless (&Apache::loncoursequeueadmin::is_active_author()) {
3476: my $requestauthor;
3477: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
3478: if (($status eq 'approval') || ($status eq 'approved')) {
3479: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
3480: if ($status eq 'approval') {
3481: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
3482: &Apache::lonlocal::locallocaltime($timestamp));
3483: } elsif ($status eq 'approved') {
3484: my %roleshash =
3485: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
3486: ['active'],['au'],[$env{'user.domain'}]);
3487: if (keys(%roleshash)) {
3488: $output .= '<span class="LC_info">'.
3489: &mt('Your request for an author role has been approved.').'<br />'.
3490: &mt('Use the "Check for changes" link to update your list of roles.').
3491: '</span>';
3492: }
3493: }
3494: $output .= '</p>';
3495: }
3496: }
3497: }
3498: unless ($output) {
3499: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
3500: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
3501: $output = &mt('No requests for courses, communities or authoring currently queued');
3502: } else {
3503: $output = &mt('No enrollment requests currently queued awaiting approval');
3504: }
3505: }
3506: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
3507: $output.'</fieldset></div><br clear="all" />';
3508: }
3509:
3510: sub process_lti {
3511: my ($r,$cdom,$cnum) = @_;
3512: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
3513: my $uriscope = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
3514: $cdom,$cnum);
3515: my $lonhost = $r->dir_config('lonHostID');
3516: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
3517: if ($env{'request.lti.rosterid'} &&
3518: $env{'request.lti.rosterurl'}) {
3519: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
3520: if ($lti{$env{'request.lti.login'}}{'roster'}) {
3521: my @lcroles = ('in','ta','ep','st');
3522: my @possibleroles;
3523: foreach my $role (@lcroles) {
3524: if (&Apache::lonnet::allowed('c'.$role,"$cdom/$cnum")) {
3525: push(@possibleroles,$role);
3526: }
3527: }
3528: my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'};
3529: if ($owner eq $env{'user.name'}.':'.$env{'user.domain'}) {
3530: my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
3531: if ($crstype eq 'Community') {
3532: unshift(@possibleroles,'co');
3533: } else {
3534: unshift(@possibleroles,'cc');
3535: }
3536: }
3537: if (@possibleroles) {
3538: push(@{$rosterupdates},{cid => $cdom.'_'.$cnum,
3539: lti => $env{'request.lti.login'},
3540: ltiref => $lti{$env{'request.lti.login'}},
3541: id => $env{'request.lti.rosterid'},
3542: url => $env{'request.lti.rosterurl'},
3543: sourcecrs => $env{'request.lti.sourcecrs'},
3544: uriscope => $uriscope,
3545: possroles => \@possibleroles,
3546: intdoms => $internet_names,
3547: });
3548: unless ($registered_cleanup) {
3549: my $handlers = $r->get_handlers('PerlCleanupHandler');
3550: $r->set_handlers('PerlCleanupHandler' =>
3551: [\<ienroll,@{$handlers}]);
3552: $registered_cleanup=1;
3553: }
3554: }
3555: }
3556: }
3557: }
3558: if ($env{'request.lti.passbackid'} &&
3559: $env{'request.lti.passbackurl'}) {
3560: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
3561: if ($lti{$env{'request.lti.login'}}{'passback'}) {
3562: my ($pbnum,$error) =
3563: &LONCAPA::ltiutils::store_passbackurl($env{'request.lti.login'},
3564: $env{'request.lti.passbackurl'},
3565: $cdom,$cnum);
3566: if ($pbnum eq '') {
3567: $pbnum = $env{'request.lti.passbackurl'};
3568: }
3569: &Apache::lonnet::put('nohist_'.$cdom.'_'.$cnum.'_passback',
3570: {"$uriscope\0$env{'request.lti.sourcecrs'}\0$env{'request.lti.login'}" =>
3571: "$pbnum\0$env{'request.lti.passbackid'}"});
3572: }
3573: }
3574: }
3575: return;
3576: }
3577:
3578: sub ltienroll {
3579: if (ref($rosterupdates) eq 'ARRAY') {
3580: foreach my $item (@{$rosterupdates}) {
3581: if (ref($item) eq 'HASH') {
3582: &LONCAPA::ltiutils::batchaddroster($item);
3583: }
3584: }
3585: }
3586: }
3587:
3588: sub set_deeplink_target {
3589: my ($cnum,$cdom) = @_;
3590: if (($cnum ne '') && ($cdom ne '')) {
3591: my $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
3592: if ($deeplink_symb ne '') {
3593: my $deeplink;
3594: if ($deeplink_symb =~ /\.(page|sequence)$/) {
3595: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
3596: my $navmap = Apache::lonnavmaps::navmap->new();
3597: if (ref($navmap)) {
3598: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
3599: }
3600: } elsif ($deeplink_symb ne '') {
3601: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
3602: }
3603: if ($deeplink ne '') {
3604: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
3605: if ($target ne '') {
3606: &Apache::lonnet::appenv({'request.deeplink.target' => $target});
3607: } elsif (exists($env{'request.deeplink.target'})) {
3608: &Apache::lonnet::delenv('request.deeplink.target');
3609: }
3610: }
3611: }
3612: }
3613: return;
3614: }
3615:
3616: sub set_supplemental_access {
3617: my ($cnum,$cdom) = @_;
3618: my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom);
3619: unless ($refs_updated) {
3620: &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental);
3621: }
3622: }
3623:
3624: 1;
3625: __END__
3626:
3627: =head1 NAME
3628:
3629: Apache::lonroles - User Roles Screen
3630:
3631: =head1 SYNOPSIS
3632:
3633: Invoked by /etc/httpd/conf/srm.conf:
3634:
3635: <Location /adm/roles>
3636: PerlAccessHandler Apache::lonacc
3637: SetHandler perl-script
3638: PerlHandler Apache::lonroles
3639: ErrorDocument 403 /adm/login
3640: ErrorDocument 500 /adm/errorhandler
3641: </Location>
3642:
3643: =head1 OVERVIEW
3644:
3645: =head2 Choosing Roles
3646:
3647: C<lonroles> is a handler that allows a user to switch roles in
3648: mid-session. LON-CAPA attempts to work with "No Role Specified", the
3649: default role that a user has before selecting a role, as widely as
3650: possible, but certain handlers for example need specification which
3651: course they should act on, etc. Both in this scenario, and when the
3652: handler determines via C<lonnet>'s C<&allowed> function that a certain
3653: action is not allowed, C<lonroles> is used as error handler. This
3654: allows the user to select another role which may have permission to do
3655: what they were trying to do.
3656:
3657: =begin latex
3658:
3659: \begin{figure}
3660: \begin{center}
3661: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
3662: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
3663: \end{center}
3664: \end{figure}
3665:
3666: =end latex
3667:
3668: =head2 Role Initialization
3669:
3670: 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.
3671:
3672: =head1 INTRODUCTION
3673:
3674: This module enables a user to select what role he wishes to
3675: operate under (instructor, student, teaching assistant, course
3676: coordinator, etc). These roles are pre-established by the actions
3677: of upper-level users.
3678:
3679: This is part of the LearningOnline Network with CAPA project
3680: described at http://www.lon-capa.org.
3681:
3682: =head1 HANDLER SUBROUTINE
3683:
3684: This routine is called by Apache and mod_perl.
3685:
3686: =over 4
3687:
3688: =item *
3689:
3690: Roles Initialization (yes/no)
3691:
3692: =item *
3693:
3694: Get Error Message from Environment
3695:
3696: =item *
3697:
3698: Who is this?
3699:
3700: =item *
3701:
3702: Generate Page Output
3703:
3704: =item *
3705:
3706: Choice or no choice
3707:
3708: =item *
3709:
3710: Table
3711:
3712: =item *
3713:
3714: Privileges
3715:
3716: =back
3717:
3718: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>