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