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