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