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