File:
[LON-CAPA] /
loncom /
auth /
lonroles.pm
Revision
1.354:
download - view:
text,
annotated -
select for diffs
Mon Nov 15 22:36:38 2021 UTC (2 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Menu links on page displaying progress indicator while course role loads
set to be unclickable until course is loaded.
- "Continue" link shown on page once course is loaded.
1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.354 2021/11/15 22:36:38 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: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1072:
1073: my %roles_in_env;
1074: my $showcount = &roles_from_env(\%roles_in_env,$update);
1075:
1076: my $swinfo=&Apache::lonmenu::rawconfig();
1077: my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});
1078: my $cattype = 'std';
1079: if ($domdefs{'catauth'}) {
1080: $cattype = $domdefs{'catauth'};
1081: }
1082: my $placementonly;
1083: if ($showcount == 1) {
1084: if ($env{'request.course.id'}) {
1085: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
1086: $placementonly = 1;
1087: }
1088: } else {
1089: foreach my $rolecode (keys(%roles_in_env)) {
1090: my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
1091: if ($cid) {
1092: my %coursedescription =
1093: &Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
1094: if ($coursedescription{'type'} eq 'Placement') {
1095: $placementonly = 1;
1096: }
1097: last;
1098: }
1099: }
1100: }
1101: }
1102: my ($start_page,$funcs);
1103: if ($placementonly) {
1104: $start_page=&Apache::loncommon::start_page($pagetitle,undef,
1105: {bread_crumbs=>$brcrum,crstype=>'Placement'});
1106: } else {
1107: $funcs = &get_roles_functions($showcount,$cattype);
1108: my $crumbsright;
1109: if ($env{'browser.mobile'}) {
1110: $crumbsright = $funcs;
1111: undef($funcs);
1112: }
1113: $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
1114: bread_crumbs_component=>$crumbsright});
1115: }
1116: &js_escape(\$standby);
1117: 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 />';
1118:
1119: $r->print(<<ENDHEADER);
1120: $start_page
1121: $funcs
1122: <noscript>
1123: $noscript
1124: </noscript>
1125: <script type="text/javascript">
1126: // <![CDATA[
1127: $swinfo
1128: window.focus();
1129:
1130: active=true;
1131:
1132: function enterrole (thisform,rolecode,buttonname) {
1133: if (active) {
1134: active=false;
1135: document.title='$standby';
1136: window.status='$standby';
1137: thisform.newrole.value=rolecode;
1138: thisform.submit();
1139: } else {
1140: alert('$standby');
1141: }
1142: }
1143:
1144: function rolesView (caller) {
1145: if ((caller == 'showall') || (caller == 'noshowall')) {
1146: document.rolechoice.display.value = caller;
1147: } else {
1148: if ((caller == 'doupdate') || (caller == 'requestauthor') ||
1149: (caller == 'queued')) {
1150: document.rolechoice.state.value = caller;
1151: }
1152: }
1153: document.rolechoice.selectrole.value='';
1154: document.rolechoice.submit();
1155: }
1156:
1157: // ]]>
1158: </script>
1159: ENDHEADER
1160:
1161: # ------------------------------------------ Get Error Message from Environment
1162:
1163: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
1164: if ($env{'user.error.msg'}) {
1165: $r->log_reason(
1166: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1167: }
1168:
1169: # ------------------------------------------------- Can this user re-init, etc?
1170:
1171: my $advanced=$env{'user.adv'};
1172: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1173: my $tryagain=$env{'form.tryagain'};
1174: my $reinit=$env{'user.reinit'};
1175: delete $env{'user.reinit'};
1176:
1177: # -------------------------------------------------------- Generate Page Output
1178: # --------------------------------------------------------------- Error Header?
1179: if ($error) {
1180: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1181: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
1182: if ($priv ne '') {
1183: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1184: }
1185: if ($fn ne '') {
1186: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1187: }
1188: if ($msg ne '') {
1189: $r->print(&mt('Action : ').$msg."\n");
1190: }
1191: $r->print("</pre><hr />");
1192: my $url=$fn;
1193: my $last;
1194: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1195: &GDBM_READER(),0640)) {
1196: $last=$hash{'last_known'};
1197: untie(%hash);
1198: }
1199: if ($last) { $fn.='?symb='.&escape($last); }
1200:
1201: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
1202: &Apache::lonenc::check_encrypt($fn));
1203: } else {
1204: if ($env{'user.error.msg'}) {
1205: if ($reinit) {
1206: $r->print(
1207: '<h3><span class="LC_error">'.
1208: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1209: } else {
1210: $r->print(
1211: '<h3><span class="LC_error">'.
1212: &mt('You need to choose another user role or enter a specific course or community for this function.').
1213: '</span></h3>');
1214: }
1215: }
1216: }
1217: if ($nochoose) {
1218: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
1219: &mt('This action is currently not authorized.').'</span>'.
1220: &Apache::loncommon::end_page());
1221: return OK;
1222: } else {
1223: if ($updateresult || $reqauthor || $hotlist) {
1224: my $showresult = '<div>';
1225: if ($updateresult) {
1226: $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
1227: }
1228: if ($reqauthor) {
1229: $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
1230: }
1231: if ($hotlist) {
1232: $showresult .= $hotlist;
1233: }
1234: $showresult .= '</div>';
1235: $r->print($showresult);
1236: } elsif ($env{'form.state'} eq 'queued') {
1237: $r->print(&get_queued());
1238: }
1239: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
1240: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1241: }
1242: my $display = ($env{'form.display'} =~ /^(showall)$/);
1243: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1244: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
1245: $r->print('<input type="hidden" name="selectrole" value="1" />');
1246: $r->print('<input type="hidden" name="newrole" value="" />');
1247: $r->print('<input type="hidden" name="display" value="'.$display.'" />');
1248: $r->print('<input type="hidden" name="state" value="" />');
1249: }
1250: $r->rflush();
1251:
1252: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
1253: my ($countactive,$countfuture,$inrole,$possiblerole) =
1254: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
1255: \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
1256: $refresh = $now;
1257: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1258: if ($countactive == 1) {
1259: if ($env{'request.course.id'}) {
1260: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
1261: $placementonly = 1;
1262: }
1263: } elsif ($possiblerole) {
1264: if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) {
1265: if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') {
1266: $placementonly = 1;
1267: }
1268: }
1269: }
1270: }
1271: if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) &&
1272: (!$placementonly)) {
1273: if ($countactive > 0) {
1274: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1275: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1276: $r->print(
1277: '<p>'
1278: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
1279: .' to view all [_5] LON-CAPA courses and communities.'
1280: ,'<b>'
1281: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1282: ,'</a>'
1283: ,'</b>'
1284: ,'"'.$domdesc.'"')
1285: .'<br />'
1286: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1287: .' you may be able to enroll if self-enrollment is permitted.'
1288: ,'<b>','</b>')
1289: .'</p>'
1290: );
1291: }
1292: }
1293:
1294: if ($norolelist) {
1295: if ($env{'request.role'}) {
1296: my ($roletext,$role_text_end) = &display_curr_role($env{'request.role'});
1297: if ($roletext) {
1298: $r->print(&Apache::loncommon::start_data_table('LC_textsize_mobile').
1299: &Apache::loncommon::start_data_table_row().
1300: $roletext.
1301: &Apache::loncommon::end_data_table_row());
1302: if ($role_text_end) {
1303: $r->print(&Apache::loncommon::continue_data_table_row().
1304: $role_text_end.
1305: &Apache::loncommon::end_data_table_row());
1306: }
1307: $r->print(&Apache::loncommon::end_data_table());
1308: }
1309: }
1310: $r->print(&Apache::loncommon::end_page());
1311: return OK;
1312: }
1313:
1314: # No active roles
1315: if ($countactive==0) {
1316: my $elapsed = 0;
1317: if ($now && $update) {
1318: $elapsed = $now - $update;
1319: }
1320: &requestcourse_advice($r,$cattype,$inrole,$elapsed);
1321: $r->print('</form>');
1322: if ($countfuture) {
1323: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
1324: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
1325: $nochoose);
1326: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
1327: \%roletext,$update,$then);
1328: my $tremark='';
1329: my $tbg;
1330: if ($env{'request.role'} eq 'cm') {
1331: $tbg="LC_roles_selected";
1332: $tremark=&mt('Currently selected.').' ';
1333: } else {
1334: $tbg="LC_roles_is";
1335: }
1336: $r->print(&Apache::loncommon::start_data_table_row()
1337: .'<td class="'.$tbg.'"> </td>'
1338: .'<td colspan="3">'
1339: .&mt('No role specified')
1340: .'</td>'
1341: .'<td>'.$tremark.' </td>'
1342: .&Apache::loncommon::end_data_table_row()
1343: );
1344:
1345: $r->print(&Apache::loncommon::end_data_table());
1346: }
1347: $r->print(&Apache::loncommon::end_page());
1348: return OK;
1349: } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) {
1350: $r->print('<h3>'.&mt('Please stand by.').'</h3>
1351: <input type="hidden" name="'.$possiblerole.'" value="1" />
1352: <noscript><br />
1353: <input type="submit" name="submit" value="'.&mt('Continue').'" />
1354: </noscript></form>');
1355: $r->rflush();
1356: $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
1357: $r->print(&Apache::loncommon::end_page());
1358: return OK;
1359: }
1360: # ----------------------------------------------------------------------- Table
1361:
1362: if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) {
1363: $r->print(&coursepick_jscript().
1364: &Apache::loncommon::coursebrowser_javascript());
1365: }
1366: if ($numdc > 0) {
1367: $r->print(&Apache::loncommon::authorbrowser_javascript());
1368: }
1369:
1370: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1371: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1372: }
1373: if ($env{'form.destinationurl'}) {
1374: $r->print('<input type="hidden" name="destinationurl" value="'.
1375: $env{'form.destinationurl'}.'" />');
1376: if ($env{'form.destsymb'} ne '') {
1377: $r->print('<input type="hidden" name="destsymb" value="'.
1378: $env{'form.destsymb'}.'" />');
1379: }
1380: }
1381:
1382: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1383: if ($env{'environment.recentroles'}) {
1384: my %recent_roles =
1385: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1386: my $output='';
1387: foreach my $role (sort(keys(%recent_roles))) {
1388: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1389: $output.= &Apache::loncommon::start_data_table_row().
1390: $roletext{'user.role.'.$role}->[0].
1391: &Apache::loncommon::end_data_table_row();
1392: if ($roletext{'user.role.'.$role}->[1] ne '') {
1393: $output .= &Apache::loncommon::continue_data_table_row().
1394: $roletext{'user.role.'.$role}->[1].
1395: &Apache::loncommon::end_data_table_row();
1396: }
1397: if ($role =~ m{^dc\./($match_domain)/$}
1398: && $dcroles{$1}) {
1399: $output .= &adhoc_roles_row($1,'recent');
1400: } elsif ($role =~ m{^(dh|da)\./($match_domain)/$}) {
1401: $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then);
1402: }
1403: } elsif ($numdc > 0) {
1404: unless ($role =~/^error\:/) {
1405: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1406: if ($roletext) {
1407: $output.= &Apache::loncommon::start_data_table_row().
1408: $roletext.
1409: &Apache::loncommon::end_data_table_row();
1410: if ($role_text_end) {
1411: $output .= &Apache::loncommon::continue_data_table_row().
1412: $role_text_end.
1413: &Apache::loncommon::end_data_table_row();
1414: }
1415: }
1416: }
1417: }
1418: }
1419: if ($output) {
1420: $r->print(&Apache::loncommon::start_data_table_empty_row()
1421: .'<td align="center" colspan="5">'
1422: .$recent
1423: .'</td>'
1424: .&Apache::loncommon::end_data_table_empty_row()
1425: );
1426: $r->print($output);
1427: $doheaders ++;
1428: }
1429: }
1430: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then);
1431: if ($countactive > 1) {
1432: my $tremark='';
1433: my $tbg;
1434: if ($env{'request.role'} eq 'cm') {
1435: $tbg="LC_roles_selected";
1436: $tremark=&mt('Currently selected.').' ';
1437: } else {
1438: $tbg="LC_roles_is";
1439: }
1440: $r->print(&Apache::loncommon::start_data_table_row());
1441: unless ($nochoose) {
1442: if ($env{'request.role'} ne 'cm') {
1443: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1444: &mt('Select').'" name="cm" /></td>');
1445: } else {
1446: $r->print('<td class="'.$tbg.'"> </td>');
1447: }
1448: }
1449: $r->print('<td colspan="3">'
1450: .&mt('No role specified')
1451: .'</td>'
1452: .'<td>'.$tremark.' </td>'
1453: .&Apache::loncommon::end_data_table_row()
1454: );
1455: }
1456: $r->print(&Apache::loncommon::end_data_table());
1457: unless ($nochoose) {
1458: $r->print("</form>\n");
1459: }
1460: # ------------------------------------------------------------ Privileges Info
1461: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1462: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1463: $r->print(&privileges_info());
1464: }
1465: my $announcements = &Apache::lonnet::getannounce();
1466: $r->print(
1467: '<br />'.
1468: '<h2>'.&mt('Announcements').'</h2>'.
1469: $announcements
1470: ) unless (!$announcements);
1471: if ($advanced) {
1472: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1473: $r->print('<p><small><i>'
1474: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1475: .'</i></small></p>');
1476: }
1477: $r->print(&Apache::loncommon::end_page());
1478: return OK;
1479: }
1480:
1481: sub roles_from_env {
1482: my ($roleshash,$update) = @_;
1483: my $count = 0;
1484: if (ref($roleshash) eq 'HASH') {
1485: foreach my $envkey (keys(%env)) {
1486: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1487: next if ($1 eq 'gr');
1488: $roleshash->{$envkey} = $env{$envkey};
1489: my ($start,$end) = split(/\./,$env{$envkey});
1490: unless ($end && $end<$update) {
1491: $count ++;
1492: }
1493: }
1494: }
1495: }
1496: return $count;
1497: }
1498:
1499: sub gather_roles {
1500: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1501: $timezones,$loncaparev) = @_;
1502: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1503: my $advanced = $env{'user.adv'};
1504: my $tryagain = $env{'form.tryagain'};
1505: my @ids = &Apache::lonnet::current_machine_ids();
1506: my (%willtrust,%trustchecked);
1507: if (ref($roles_in_env) eq 'HASH') {
1508: my %adhocdesc;
1509: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1510: my $button = 1;
1511: my $switchserver='';
1512: my $switchwarning;
1513: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1514: $tend,$tremark,$tstatus,$tpstart,$tpend);
1515: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1516: \$trolecode,\$tstatus,\$tstart,\$tend);
1517: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1518: $tremark='';
1519: $tpstart=' ';
1520: $tpend=' ';
1521: if ($env{'request.role'} eq $trolecode) {
1522: $tstatus='selected';
1523: }
1524: my $tbg;
1525: if (($tstatus eq 'is')
1526: || ($tstatus eq 'selected')
1527: || ($tstatus eq 'future')
1528: || ($env{'form.display'} eq 'showall')) {
1529: my $timezone = &role_timezone($where,$timezones);
1530: if ($tstart) {
1531: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1532: }
1533: if ($tend) {
1534: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1535: }
1536: if ($tstatus eq 'is') {
1537: $tbg='LC_roles_is';
1538: $possiblerole=$trolecode;
1539: $countactive++;
1540: } elsif ($tstatus eq 'future') {
1541: $tbg='LC_roles_future';
1542: $button=0;
1543: $futureroles->{$trolecode} = $tstart.':'.$tend;
1544: $countfuture ++;
1545: } elsif ($tstatus eq 'expired') {
1546: $tbg='LC_roles_expired';
1547: $button=0;
1548: } elsif ($tstatus eq 'will_not') {
1549: $tbg='LC_roles_will_not';
1550: $tremark.=&mt('Expired after logout.').' ';
1551: } elsif ($tstatus eq 'selected') {
1552: $tbg='LC_roles_selected';
1553: $inrole=1;
1554: $countactive++;
1555: $tremark.=&mt('Currently selected.').' ';
1556: }
1557: my $trole;
1558: if ($role =~ /^cr\//) {
1559: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1560: unless ($rauthor eq $rdomain.'-domainconfig') {
1561: if ($tremark) { $tremark.='<br />'; }
1562: $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1563: }
1564: }
1565: $trole=Apache::lonnet::plaintext($role);
1566: my $ttype;
1567: my $twhere;
1568: my $skipcal;
1569: my ($tdom,$trest,$tsection)=
1570: split(/\//,Apache::lonnet::declutter($where));
1571: # First, Co-Authorship roles
1572: if (($role eq 'ca') || ($role eq 'aa')) {
1573: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1574: my $allowed=0;
1575: my $prohibited;
1576: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1577: if (!$allowed) {
1578: $button=0;
1579: unless ($trustchecked{$tdom}) {
1580: if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$tdom)) &&
1581: (&Apache::lonnet::will_trust('coaurem',$tdom,$env{'user.domain'}))) {
1582: $willtrust{$tdom} = 1;
1583: $trustchecked{$tdom} = 1;
1584: }
1585: }
1586: if ($willtrust{$tdom}) {
1587: $switchserver='otherserver='.$home.'&role='.$trolecode;
1588: } else {
1589: $prohibited = 1;
1590: $tremark .= &mt('Session switch required but prohibited.');
1591: }
1592: }
1593: #next if ($home eq 'no_host');
1594: $home = &Apache::lonnet::hostname($home);
1595: $ttype='Authoring Space';
1596: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1597: ': '.$tdom.'<br />'.
1598: ' '.&mt('Server').': '.$home;
1599: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1600: unless ($prohibited) {
1601: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1602: }
1603: $sortkey=$role."$trest:$tdom";
1604: } elsif ($role eq 'au') {
1605: # Authors
1606: my $home = &Apache::lonnet::homeserver
1607: ($env{'user.name'},$env{'user.domain'});
1608: my $allowed=0;
1609: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1610: if (!$allowed) {
1611: $button=0;
1612: $switchserver='otherserver='.$home.'&role='.$trolecode;
1613: }
1614: #next if ($home eq 'no_host');
1615: $home = &Apache::lonnet::hostname($home);
1616: $ttype='Authoring Space';
1617: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1618: ': '.$home;
1619: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1620: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1621: $sortkey=$role;
1622: } elsif ($trest) {
1623: my $tcourseid=$tdom.'_'.$trest;
1624: $ttype = &Apache::loncommon::course_type($tcourseid);
1625: if ($role !~ /^cr/) {
1626: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1627: } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) {
1628: my $rolename = $1;
1629: my $desc;
1630: if (ref($adhocdesc{$tdom}) eq 'HASH') {
1631: $desc = $adhocdesc{$tdom}{$rolename};
1632: } else {
1633: my %domdef = &Apache::lonnet::get_domain_defaults($tdom);
1634: if (ref($domdef{'adhocroles'}) eq 'HASH') {
1635: foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
1636: if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
1637: $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
1638: $desc = $adhocdesc{$tdom}{$rolename};
1639: }
1640: }
1641: }
1642: }
1643: if ($desc ne '') {
1644: $trole = $desc;
1645: } else {
1646: $trole = &mt('Helpdesk[_1]',' '.$rolename);
1647: }
1648: } else {
1649: $trole = (split(/\//,$role,4))[-1];
1650: }
1651: if ($env{'course.'.$tcourseid.'.description'}) {
1652: my $home=$env{'course.'.$tcourseid.'.home'};
1653: $twhere=$env{'course.'.$tcourseid.'.description'};
1654: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1655: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1656: unless ($twhere eq &mt('Currently not available')) {
1657: $twhere.=' <span class="LC_fontsize_small">'.
1658: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1659: '</span>';
1660: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1661: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1662: if ($required ne '') {
1663: ($switchserver,$switchwarning) =
1664: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1665: if ($switchserver || $switchwarning) {
1666: $button = 0;
1667: }
1668: }
1669: }
1670: }
1671: } else {
1672: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1673: if (%newhash) {
1674: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1675: "\0".$envkey;
1676: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1677: ' <span class="LC_fontsize_small">'.
1678: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1679: '</span>';
1680: $ttype = $newhash{'type'};
1681: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1682: my $home = $newhash{'home'};
1683: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1684: my $required = $newhash{'internal.releaserequired'};
1685: if ($required ne '') {
1686: ($switchserver,$switchwarning) =
1687: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1688: if ($switchserver || $switchwarning) {
1689: $button = 0;
1690: }
1691: }
1692: }
1693: } else {
1694: $twhere=&mt('Currently not available');
1695: $env{'course.'.$tcourseid.'.description'}=$twhere;
1696: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1697: $ttype = 'Unavailable';
1698: $skipcal = 1;
1699: }
1700: }
1701: if ($ttype eq 'Placement') {
1702: $ttype = 'Placement Test';
1703: }
1704: if ($tsection) {
1705: $twhere.='<br />'.&mt('Section').': '.$tsection;
1706: }
1707: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1708: } elsif ($tdom) {
1709: $ttype='Domain';
1710: $twhere=$tdom;
1711: $sortkey=$role.$twhere;
1712: } else {
1713: $ttype='System';
1714: $twhere=&mt('system wide');
1715: $sortkey=$role.$twhere;
1716: }
1717: ($role_text,$role_text_end) =
1718: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1719: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1720: $tpend,$nochoose,$button,$switchserver,$reinit,
1721: $switchwarning,$skipcal);
1722: $roletext->{$envkey}=[$role_text,$role_text_end];
1723: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1724: $sortrole->{$sortkey}=$envkey;
1725: $roleclass->{$envkey}=$ttype;
1726: }
1727: }
1728: }
1729: return ($countactive,$countfuture,$inrole,$possiblerole);
1730: }
1731:
1732: sub role_timezone {
1733: my ($where,$timezones) = @_;
1734: my $timezone;
1735: if (ref($timezones) eq 'HASH') {
1736: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1737: my $cdom = $1;
1738: my $cnum = $2;
1739: if ($cdom && $cnum) {
1740: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1741: my $tz;
1742: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1743: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1744: } else {
1745: my %timehash =
1746: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1747: $tz = $timehash{'timezone'};
1748: }
1749: if ($tz eq '') {
1750: if (!exists($timezones->{$cdom})) {
1751: my %domdefaults =
1752: &Apache::lonnet::get_domain_defaults($cdom);
1753: if ($domdefaults{'timezone_def'} eq '') {
1754: $timezones->{$cdom} = 'local';
1755: } else {
1756: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1757: }
1758: }
1759: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1760: } else {
1761: $timezones->{$cdom.'_'.$cnum} =
1762: &Apache::lonlocal::gettimezone($tz);
1763: }
1764: }
1765: $timezone = $timezones->{$cdom.'_'.$cnum};
1766: }
1767: } else {
1768: my ($tdom) = ($where =~ m{^/($match_domain)});
1769: if ($tdom) {
1770: if (!exists($timezones->{$tdom})) {
1771: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1772: if ($domdefaults{'timezone_def'} eq '') {
1773: $timezones->{$tdom} = 'local';
1774: } else {
1775: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1776: }
1777: }
1778: $timezone = $timezones->{$tdom};
1779: }
1780: }
1781: if ($timezone eq 'local') {
1782: $timezone = undef;
1783: }
1784: }
1785: return $timezone;
1786: }
1787:
1788: sub roletable_headers {
1789: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1790: my $doheaders;
1791: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1792: $r->print('<br />'
1793: .&Apache::loncommon::start_data_table('LC_textsize_mobile')
1794: .&Apache::loncommon::start_data_table_header_row()
1795: );
1796: if (!$nochoose) { $r->print('<th> </th>'); }
1797: $r->print('<th>'.&mt('User Role').'</th>'
1798: .'<th>'.&mt('Extent').'</th>'
1799: .'<th>'.&mt('Start').'</th>'
1800: .'<th>'.&mt('End').'</th>'
1801: .&Apache::loncommon::end_data_table_header_row()
1802: );
1803: $doheaders=-1;
1804: my @roletypes = &roletypes();
1805: foreach my $type (@roletypes) {
1806: my $haverole=0;
1807: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1808: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1809: $haverole=1;
1810: }
1811: }
1812: if ($haverole) { $doheaders++; }
1813: }
1814: }
1815: return $doheaders;
1816: }
1817:
1818: sub roletypes {
1819: my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System');
1820: return @types;
1821: }
1822:
1823: sub print_rolerows {
1824: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_;
1825: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1826: my @types = &roletypes();
1827: foreach my $type (@types) {
1828: my $output;
1829: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1830: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1831: if (ref($roletext) eq 'HASH') {
1832: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1833: $output.= &Apache::loncommon::start_data_table_row().
1834: $roletext->{$sortrole->{$which}}->[0].
1835: &Apache::loncommon::end_data_table_row();
1836: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1837: $output .= &Apache::loncommon::continue_data_table_row().
1838: $roletext->{$sortrole->{$which}}->[1].
1839: &Apache::loncommon::end_data_table_row();
1840: }
1841: }
1842: if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
1843: if (ref($dcroles) eq 'HASH') {
1844: if ($dcroles->{$1}) {
1845: $output .= &adhoc_roles_row($1,'');
1846: }
1847: }
1848: } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) {
1849: $output .= &adhoc_customroles_row($1,$2,'',$update,$then);
1850: }
1851: }
1852: }
1853: }
1854: if ($output) {
1855: if ($doheaders > 0) {
1856: $r->print(&Apache::loncommon::start_data_table_empty_row()
1857: .'<td align="center" colspan="5">'
1858: .&mt($type)
1859: .'</td>'
1860: .&Apache::loncommon::end_data_table_empty_row()
1861: );
1862: }
1863: $r->print($output);
1864: }
1865: }
1866: }
1867: }
1868:
1869: sub findcourse_advice {
1870: my ($r,$cattype,$elapsed) = @_;
1871: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1872: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1873: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1874: $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).'
1875: <ul>
1876: <li>'.&mt('The course has yet to be created.').'</li>
1877: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1878: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1879: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1880: <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>
1881: <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>
1882: </ul></p>');
1883: } else {
1884: $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>');
1885: if ($elapsed > 600) {
1886: $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').
1887: '<br />'.
1888: &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>');
1889: }
1890: }
1891: if (($cattype eq 'std') || ($cattype eq 'domonly')) {
1892: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1893: '<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 />');
1894: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1895: &Apache::loncoursequeueadmin::queued_selfenrollment());
1896: }
1897: return;
1898: }
1899:
1900: sub requestcourse_advice {
1901: my ($r,$cattype,$inrole,$elapsed) = @_;
1902: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1903: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1904: my (%can_request,%request_doms,$output);
1905: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1906: if (keys(%request_doms) > 0) {
1907: my ($types,$typename) = &Apache::loncommon::course_types();
1908: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1909: my (@reqdoms,@reqtypes);
1910: foreach my $type (sort(keys(%request_doms))) {
1911: push(@reqtypes,$type);
1912: if (ref($request_doms{$type}) eq 'ARRAY') {
1913: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1914: $output .=
1915: '<li>'
1916: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1917: '<i>',
1918: '</i>',
1919: '<b>'.$domstr.'</b>')
1920: .'</li>';
1921: foreach my $dom (@{$request_doms{$type}}) {
1922: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1923: push(@reqdoms,$dom);
1924: }
1925: }
1926: }
1927: }
1928: my @showtypes;
1929: foreach my $type (@{$types}) {
1930: if (grep(/^\Q$type\E$/,@reqtypes)) {
1931: push(@showtypes,$type);
1932: }
1933: }
1934: my $requrl = '/adm/requestcourse';
1935: if (@reqdoms == 1) {
1936: $requrl .= '?showdom='.$reqdoms[0];
1937: }
1938: if (@showtypes > 0) {
1939: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1940: }
1941: if (@reqdoms == 1 || @showtypes > 0) {
1942: $requrl .= '&state=crstype&action=new';
1943: }
1944: if ($output) {
1945: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1946: '<p>'.
1947: &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
1948: '<ul>'.
1949: $output.
1950: '</ul>'.
1951: &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
1952: '<a href="'.$requrl.'">','</a>').
1953: '</p>');
1954: }
1955: }
1956: } elsif (!$env{'user.adv'}) {
1957: if ($inrole) {
1958: $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
1959: } else {
1960: $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
1961: }
1962: &findcourse_advice($r,$cattype,$elapsed);
1963: }
1964: return;
1965: }
1966:
1967: sub privileges_info {
1968: my ($which) = @_;
1969: my $output;
1970:
1971: $which ||= $env{'request.role'};
1972:
1973: foreach my $envkey (sort(keys(%env))) {
1974: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1975:
1976: my $where=$1;
1977: my $ttype;
1978: my $twhere;
1979: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1980: if ($trest) {
1981: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1982: $ttype='Authoring Space';
1983: $twhere='User: '.$trest.', Domain: '.$tdom;
1984: } else {
1985: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1986: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1987: if ($tsec) {
1988: my $sec_type = 'Section';
1989: if (exists($env{"user.role.gr.$where"})) {
1990: $sec_type = 'Group';
1991: }
1992: $twhere.=' ('.$sec_type.': '.$tsec.')';
1993: }
1994: }
1995: } elsif ($tdom) {
1996: $ttype='Domain';
1997: $twhere=$tdom;
1998: } else {
1999: $ttype='System';
2000: $twhere='/';
2001: }
2002: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
2003: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
2004: next if (!$priv);
2005:
2006: my ($prv,$restr)=split(/\&/,$priv);
2007: my $trestr='';
2008: if ($restr ne 'F') {
2009: $trestr.=' ('.
2010: join(', ',
2011: map { &Apache::lonnet::plaintext($_) }
2012: (split('',$restr))).') ';
2013: }
2014: $output .= "\n\t".
2015: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
2016: }
2017: $output .= "\n".'</ul>';
2018: }
2019: return $output;
2020: }
2021:
2022: sub build_roletext {
2023: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
2024: $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_;
2025: my ($roletext,$roletext_end,$poss_adhoc);
2026: if ($trolecode =~ m/^d(c|h|a)\./) {
2027: $poss_adhoc = 1;
2028: }
2029: my $rowspan=($poss_adhoc) ? ''
2030: : ' rowspan="2" ';
2031:
2032: unless ($nochoose) {
2033: my $buttonname=$trolecode;
2034: $buttonname=~s/\W//g;
2035: if (!$button) {
2036: if ($switchserver) {
2037: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
2038: .'<a href="/adm/switchserver?'.$switchserver.'">'
2039: .&mt('Switch Server')
2040: .'</a></td>';
2041: } else {
2042: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
2043: }
2044: if ($switchwarning) {
2045: if ($tremark eq '') {
2046: $tremark = $switchwarning;
2047: } else {
2048: $tremark .= '<br />'.$switchwarning;
2049: }
2050: }
2051: } elsif ($tstatus eq 'is') {
2052: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
2053: '<input name="'.$buttonname.'" type="button" value="'.
2054: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
2055: $trolecode."','".$buttonname.'\');" /></td>';
2056: } elsif ($tryagain) {
2057: $roletext.=
2058: '<td'.$rowspan.' class="'.$tbg.'">'.
2059: '<input name="'.$buttonname.'" type="button" value="'.
2060: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
2061: $trolecode."','".$buttonname.'\');" /></td>';
2062: } elsif ($advanced) {
2063: $roletext.=
2064: '<td'.$rowspan.' class="'.$tbg.'">'.
2065: '<input name="'.$buttonname.'" type="button" value="'.
2066: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
2067: $trolecode."','".$buttonname.'\');" /></td>';
2068: } elsif ($reinit) {
2069: $roletext.=
2070: '<td'.$rowspan.' class="'.$tbg.'">'.
2071: '<input name="'.$buttonname.'" type="button" value="'.
2072: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
2073: $trolecode."','".$buttonname.'\');" /></td>';
2074: } else {
2075: $roletext.=
2076: '<td'.$rowspan.' class="'.$tbg.'">'.
2077: '<input name="'.$buttonname.'" type="button" value="'.
2078: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
2079: $trolecode."','".$buttonname.'\');" /></td>';
2080: }
2081: }
2082: if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) {
2083: $tremark.=&Apache::lonannounce::showday(time,1,
2084: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
2085: }
2086: $roletext.='<td>'.$trole.'</td>'
2087: .'<td>'.$twhere.'</td>'
2088: .'<td>'.$tpstart.'</td>'
2089: .'<td>'.$tpend.'</td>';
2090: unless ($poss_adhoc) {
2091: $roletext_end = '<td colspan="4">'.
2092: $tremark.' '.
2093: '</td>';
2094: }
2095: return ($roletext,$roletext_end);
2096: }
2097:
2098: sub check_author_homeserver {
2099: my ($uname,$udom)=@_;
2100: if (($uname eq '') || ($udom eq '')) {
2101: return ('fail','');
2102: }
2103: my $home = &Apache::lonnet::homeserver($uname,$udom);
2104: if (&Apache::lonnet::host_domain($home) ne $udom) {
2105: return ('fail',$home);
2106: }
2107: my @ids=&Apache::lonnet::current_machine_ids();
2108: if (grep(/^\Q$home\E$/,@ids)) {
2109: return ('ok',$home);
2110: } else {
2111: return ('switchserver',$home);
2112: }
2113: }
2114:
2115: sub check_for_adhoc {
2116: my ($dcroles,$helpdeskroles,$update,$then) = @_;
2117: my $numdc = 0;
2118: my $numhelpdesk = 0;
2119: my $numadhoc = 0;
2120: my $num_custom_adhoc = 0;
2121: if (($env{'user.adv'}) || ($env{'user.rar'})) {
2122: foreach my $envkey (sort(keys(%env))) {
2123: if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) {
2124: my $role = $1;
2125: my $roledom = $2;
2126: my $liverole = 1;
2127: my ($tstart,$tend)=split(/\./,$env{$envkey});
2128: my $limit = $update;
2129: if ($env{'request.role'} eq "$role./$roledom/") {
2130: $limit = $then;
2131: }
2132: if ($tstart && $tstart>$limit) { $liverole = 0; }
2133: if ($tend && $tend <$limit) { $liverole = 0; }
2134: if ($liverole) {
2135: if ($role eq 'dc') {
2136: $dcroles->{$roledom} = $envkey;
2137: $numdc++;
2138: } else {
2139: $helpdeskroles->{$roledom} = $envkey;
2140: my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom);
2141: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2142: if (keys(%{$domdefaults{'adhocroles'}})) {
2143: $numadhoc ++;
2144: }
2145: }
2146: $numhelpdesk++;
2147: }
2148: }
2149: }
2150: }
2151: }
2152: return ($numdc,$numhelpdesk,$numadhoc);
2153: }
2154:
2155: sub adhoc_course_role {
2156: my ($refresh,$update,$then) = @_;
2157: my ($cdom,$cnum,$crstype);
2158: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2159: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2160: $crstype = &Apache::loncommon::course_type();
2161: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
2162: my $setprivs;
2163: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
2164: $setprivs = 1;
2165: } else {
2166: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
2167: if (($start && ($start>$refresh || $start == -1)) ||
2168: ($end && $end<$update)) {
2169: $setprivs = 1;
2170: }
2171: }
2172: unless ($setprivs) {
2173: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
2174: $setprivs = 1;
2175: }
2176: }
2177: if ($setprivs) {
2178: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
2179: my $role = $1;
2180: my $custom_role = $2;
2181: my $usec = $3;
2182: if ($role eq 'cr') {
2183: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
2184: $role .= $custom_role;
2185: } else {
2186: return;
2187: }
2188: }
2189: my (%userroles,%newrole,%newgroups,%group_privs);
2190: my %cgroups =
2191: &Apache::lonnet::get_active_groups($env{'user.domain'},
2192: $env{'user.name'},$cdom,$cnum);
2193: my $ccrole;
2194: if ($crstype eq 'Community') {
2195: $ccrole = 'co';
2196: } else {
2197: $ccrole = 'cc';
2198: }
2199: foreach my $group (keys(%cgroups)) {
2200: $group_privs{$group} =
2201: $env{'user.priv.'.$ccrole.'./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
2202: }
2203: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
2204: my $area = '/'.$cdom.'/'.$cnum;
2205: my $spec = $role.'.'.$area;
2206: if ($usec ne '') {
2207: $spec .= '/'.$usec;
2208: $area .= '/'.$usec;
2209: }
2210: if ($role =~ /^cr/) {
2211: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
2212: } else {
2213: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
2214: }
2215: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
2216: my $adhocstart = $refresh-1;
2217: $userroles{'user.role.'.$spec} = $adhocstart.'.';
2218: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
2219: }
2220: }
2221: }
2222: return;
2223: }
2224:
2225: sub check_forcc {
2226: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
2227: my ($is_cc,$ccrole);
2228: if ($crstype eq 'Community') {
2229: $ccrole = 'co';
2230: } else {
2231: $ccrole = 'cc';
2232: }
2233: if (&Apache::lonnet::is_course($cdom,$cnum)) {
2234: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
2235: if (defined($env{$envkey})) {
2236: $is_cc = 1;
2237: my ($tstart,$tend)=split(/\./,$env{$envkey});
2238: my $limit = $update;
2239: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
2240: $limit = $then;
2241: }
2242: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
2243: if ($tend && $tend <$limit) { $is_cc = 0; }
2244: }
2245: }
2246: return $is_cc;
2247: }
2248:
2249: sub courselink {
2250: my ($roledom,$rowtype,$role) = @_;
2251: my $courseform=&Apache::loncommon::selectcourse_link
2252: ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
2253: 'domain'.$rowtype.'_'.$roledom.'_'.$role,
2254: 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
2255: $roledom.':'.$role,undef,'Course/Community');
2256: my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
2257: '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
2258: '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
2259: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
2260: return $courseform.$hiddenitems;
2261: }
2262:
2263: sub coursepick_jscript {
2264: my %js_lt = &Apache::lonlocal::texthash(
2265: 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.",
2266: youc => 'You can only use this screen to select courses and communities in the current domain.',
2267: );
2268: &js_escape(\%js_lt);
2269: my $verify_script = <<"END";
2270: <script type="text/javascript">
2271: // <![CDATA[
2272: function verifyCoursePick(caller) {
2273: var numbutton = getIndex(caller)
2274: var pickedCourse = document.rolechoice.elements[numbutton+4].value
2275: var pickedDomain = document.rolechoice.elements[numbutton+2].value
2276: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
2277: if (pickedCourse != '') {
2278: if (numbutton != -1) {
2279: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
2280: document.rolechoice.elements[numbutton+1].name = courseTarget
2281: document.rolechoice.submit()
2282: }
2283: }
2284: else {
2285: alert("$js_lt{'plsu'}");
2286: }
2287: }
2288: else {
2289: alert("$js_lt{'youc'}")
2290: }
2291: }
2292: function getIndex(caller) {
2293: for (var i=0;i<document.rolechoice.elements.length;i++) {
2294: if (document.rolechoice.elements[i] == caller) {
2295: return i;
2296: }
2297: }
2298: return -1;
2299: }
2300: // ]]>
2301: </script>
2302: END
2303: return $verify_script;
2304: }
2305:
2306: sub coauthorlink {
2307: my ($dcdom,$rowtype) = @_;
2308: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
2309: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
2310: return $coauthorform.$hiddenitems;
2311: }
2312:
2313: sub display_cc_role {
2314: my $rolekey = shift;
2315: my ($roletext,$roletext_end);
2316: my $advanced = $env{'user.adv'};
2317: my $tryagain = $env{'form.tryagain'};
2318: unless ($rolekey =~/^error\:/) {
2319: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
2320: my $ccrole = $1;
2321: my $tdom = $2;
2322: my $trest = $3;
2323: my $tcourseid = $tdom.'_'.$trest;
2324: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
2325: my $twhere;
2326: my $ttype;
2327: my $skipcal;
2328: my $tbg='LC_roles_is';
2329: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2330: if (%newhash) {
2331: $twhere=$newhash{'description'}.
2332: ' <span class="LC_fontsize_small">'.
2333: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
2334: '</span>';
2335: $ttype = $newhash{'type'};
2336: } else {
2337: $twhere=&mt('Currently not available');
2338: $env{'course.'.$tcourseid.'.description'}=$twhere;
2339: $skipcal = 1;
2340: }
2341: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
2342: $twhere.="<br />".&mt('Domain').":".$tdom;
2343: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
2344: }
2345: }
2346: return ($roletext,$roletext_end);
2347: }
2348:
2349: sub display_curr_role {
2350: my ($currentrole) = @_;
2351: my ($roletext,$roletext_end);
2352: my $advanced = $env{'user.adv'};
2353: my $tryagain = $env{'form.tryagain'};
2354: my ($role,$rest) = split(m{\./},$currentrole,2);
2355: unless (!defined($role) || $role eq '') {
2356: if ($rest =~ m{^($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
2357: my $cdom = $1;
2358: my $cnum = $2;
2359: my $csec = $3;
2360: my $cid = $cdom.'_'.$cnum;
2361: my $ttype = $env{'course.'.$cid.'.type'};
2362: my $skipcal = 1;
2363: my $tbg='LC_roles_is';
2364: my $twhere = $env{'course.'.$cid.'.description'}.
2365: ' <span class="LC_fontsize_small">'.
2366: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom).
2367: '</span>';
2368: my $trole = &Apache::lonnet::plaintext($role,$ttype,$cid);
2369: if ($csec) {
2370: $twhere.= ' '.&mt('Section').': '.$csec;
2371: }
2372: if ($role ne 'st') {
2373: $twhere.= ' '.&mt('Domain').': '.$cdom;
2374: }
2375: ($roletext,$roletext_end) = &build_roletext($currentrole,$cdom,$cnum,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
2376: }
2377: }
2378: return ($roletext,$roletext_end);
2379: }
2380:
2381: sub adhoc_roles_row {
2382: my ($dcdom,$rowtype) = @_;
2383: my $output = &Apache::loncommon::continue_data_table_row()
2384: .' <td colspan="5" class="LC_textsize_mobile">'
2385: .&mt('[_1]Ad hoc[_2] roles in domain [_3]'
2386: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
2387: .' -- ';
2388: my $role = 'cc';
2389: my $selectcclink = &courselink($dcdom,$rowtype,$role);
2390: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
2391: my $carole = &Apache::lonnet::plaintext('ca');
2392: my $selectcalink = &coauthorlink($dcdom,$rowtype);
2393: $output.=$ccrole.': '.$selectcclink
2394: .' | '.$carole.': '.$selectcalink.'</td>'
2395: .&Apache::loncommon::end_data_table_row();
2396: return $output;
2397: }
2398:
2399: sub adhoc_customroles_row {
2400: my ($role,$dhdom,$rowtype,$update,$then) = @_;
2401: my $liverole = 1;
2402: my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"});
2403: my $limit = $update;
2404: if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) {
2405: $limit = $then;
2406: }
2407: if ($tstart && $tstart>$limit) { $liverole = 0; }
2408: if ($tend && $tend <$limit) { $liverole = 0; }
2409: return unless ($liverole);
2410: my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom);
2411: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2412: if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) {
2413: return &Apache::loncommon::continue_data_table_row()
2414: .' <td colspan="5" class="LC_textsize_mobile">'
2415: .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]',
2416: '<span class="LC_cusr_emph">','</span>',$dhdom)
2417: .' -- '.&courselink($dhdom,$rowtype,$role);
2418: }
2419: }
2420: return;
2421: }
2422:
2423: sub recent_filename {
2424: my $area=shift;
2425: return 'nohist_recent_'.&escape($area);
2426: }
2427:
2428: sub courseloadpage {
2429: my ($courseid) = @_;
2430: my $startpage;
2431: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
2432: [$courseid.':courseinit']);
2433: my ($tmp) = %entry_settings;
2434: unless ($tmp =~ /^error: 2 /) {
2435: $startpage = $entry_settings{$courseid.':courseinit'};
2436: }
2437: if ($startpage eq '') {
2438: if (exists($env{'environment.course_init_display'})) {
2439: $startpage = $env{'environment.course_init_display'};
2440: }
2441: }
2442: return $startpage;
2443: }
2444:
2445: sub update_session_roles {
2446: my $then=$env{'user.login.time'};
2447: my $refresh=$env{'user.refresh.time'};
2448: if (!$refresh) {
2449: $refresh = $then;
2450: }
2451: my $update = $env{'user.update.time'};
2452: if (!$update) {
2453: $update = $then;
2454: }
2455: my $now = time;
2456: my %roleshash =
2457: &Apache::lonnet::get_my_roles('','','userroles',
2458: ['active','future','previous'],
2459: undef,undef,1);
2460: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
2461: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
2462: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
2463: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
2464: @rolecodes);
2465: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
2466: my %courseroles;
2467: foreach my $item (keys(%roleshash)) {
2468: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
2469: my ($tstart,$tend) = split(/:/,$roleshash{$item});
2470: my ($section,$group,@group_privs);
2471: if ($role =~ m{^gr/(\w*)$}) {
2472: $role = 'gr';
2473: my $priv = $1;
2474: next if ($tstart eq '-1');
2475: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2476: if ($priv ne '') {
2477: push(@group_privs,$priv);
2478: }
2479: }
2480: if ($remainder =~ /:/) {
2481: (my $additional_privs,$group) =
2482: ($remainder =~ /^([\w:]+):([^:]+)$/);
2483: if ($additional_privs ne '') {
2484: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2485: push(@group_privs,split(/:/,$additional_privs));
2486: @group_privs = sort(@group_privs);
2487: }
2488: }
2489: } else {
2490: $group = $remainder;
2491: }
2492: } else {
2493: $section = $remainder;
2494: }
2495: my $where = "/$udom/$uname";
2496: if ($section ne '') {
2497: $where .= "/$section";
2498: } elsif ($group ne '') {
2499: $where .= "/$group";
2500: }
2501: my $rolekey = "$role.$where";
2502: my $envkey = "user.role.$rolekey";
2503: $dbroles{$envkey} = 1;
2504: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2505: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2506: $currrole_expired = 1;
2507: }
2508: }
2509: if ($env{$envkey} eq '') {
2510: my $status_in_db =
2511: &curr_role_status($tstart,$tend,$now,$now);
2512: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2513: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2514: if ($status_in_db eq 'active') {
2515: if ($section eq '') {
2516: push(@newsec,'none');
2517: } else {
2518: push(@newsec,$section);
2519: }
2520: }
2521: } else {
2522: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2523: push(@changed_roles,$role);
2524: }
2525: if ($status_in_db ne 'previous') {
2526: if ($role eq 'gr') {
2527: $newgroup{$rolekey} = $status_in_db;
2528: if ($status_in_db eq 'active') {
2529: unless (ref($courseroles{$udom}) eq 'HASH') {
2530: %{$courseroles{$udom}} =
2531: &Apache::lonnet::get_my_roles('','','userroles',
2532: ['active'],\@possroles,
2533: [$udom],1);
2534: }
2535: &Apache::lonnet::get_groups_roles($udom,$uname,
2536: $courseroles{$udom},
2537: \@rolecodes,\%groups_roles);
2538: }
2539: } else {
2540: $newrole{$rolekey} = $status_in_db;
2541: }
2542: }
2543: }
2544: } else {
2545: my ($currstart,$currend) = split(/\./,$env{$envkey});
2546: if ($role eq 'gr') {
2547: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2548: $hasgroups = 1;
2549: }
2550: }
2551: if (($currstart ne $tstart) || ($currend ne $tend)) {
2552: my $status_in_env =
2553: &curr_role_status($currstart,$currend,$refresh,$update);
2554: my $status_in_db =
2555: &curr_role_status($tstart,$tend,$now,$now);
2556: if ($status_in_env ne $status_in_db) {
2557: if ($status_in_env eq 'active') {
2558: if ($role eq 'st') {
2559: if ($env{'request.role'} eq $rolekey) {
2560: my $switchsection;
2561: unless (ref($courseroles{$udom}) eq 'HASH') {
2562: %{$courseroles{$udom}} =
2563: &Apache::lonnet::get_my_roles('','','userroles',
2564: ['active'],
2565: \@possroles,[$udom],1);
2566: }
2567: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2568: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2569: $switchsection = 1;
2570: last;
2571: }
2572: }
2573: if ($switchsection) {
2574: if ($section eq '') {
2575: $oldsec = 'none';
2576: } else {
2577: $oldsec = $section;
2578: }
2579: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2580: } else {
2581: $currrole_expired = 1;
2582: next;
2583: }
2584: }
2585: }
2586: unless ($rolekey eq $env{'request.role'}) {
2587: if ($role eq 'gr') {
2588: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2589: } else {
2590: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2591: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2592: }
2593: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2594: }
2595: } elsif ($status_in_db eq 'active') {
2596: if (($role eq 'st') &&
2597: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2598: if ($section eq '') {
2599: push(@newsec,'none');
2600: } else {
2601: push(@newsec,$section);
2602: }
2603: } elsif ($role eq 'gr') {
2604: unless (ref($courseroles{$udom}) eq 'HASH') {
2605: %{$courseroles{$udom}} =
2606: &Apache::lonnet::get_my_roles('','','userroles',
2607: ['active'],
2608: \@possroles,[$udom],1);
2609: }
2610: &Apache::lonnet::get_groups_roles($udom,$uname,
2611: $courseroles{$udom},
2612: \@rolecodes,\%groups_roles);
2613: }
2614: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2615: }
2616: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2617: push(@changed_roles,$role);
2618: }
2619: if ($role eq 'gr') {
2620: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2621: } else {
2622: $rolechange{$rolekey} = $status_in_db;
2623: }
2624: }
2625: } else {
2626: if ($role eq 'gr') {
2627: unless ($checkedgroup{$where}) {
2628: my $status_in_db =
2629: &curr_role_status($tstart,$tend,$refresh,$now);
2630: if ($tstart eq '-1') {
2631: $status_in_db = 'deleted';
2632: }
2633: unless (ref($courseroles{$udom}) eq 'HASH') {
2634: %{$courseroles{$udom}} =
2635: &Apache::lonnet::get_my_roles('','','userroles',
2636: ['active'],
2637: \@possroles,[$udom],1);
2638: }
2639: if (ref($courseroles{$udom}) eq 'HASH') {
2640: foreach my $item (keys(%{$courseroles{$udom}})) {
2641: next unless ($item =~ /^\Q$uname\E/);
2642: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2643: my $area = '/'.$cdom.'/'.$cnum;
2644: if ($crssec ne '') {
2645: $area .= '/'.$crssec;
2646: }
2647: my $crsrolekey = $crsrole.'.'.$area;
2648: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2649: $currprivs =~ s/^://;
2650: $currprivs =~ s/\&F$//;
2651: my @curr_grp_privs = split(/\&F:/,$currprivs);
2652: @curr_grp_privs = sort(@curr_grp_privs);
2653: my @diffs;
2654: if (@group_privs > 0 || @curr_grp_privs > 0) {
2655: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2656: }
2657: if (@diffs == 0) {
2658: last;
2659: } else {
2660: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2661: push(@rolecodes,'gr');
2662: }
2663: &gather_roleprivs(\%allroles,\%allgroups,
2664: \%userroles,$where,$role,
2665: $tstart,$tend,$status_in_db);
2666: if ($status_in_db eq 'active') {
2667: &Apache::lonnet::get_groups_roles($udom,$uname,
2668: $courseroles{$udom},
2669: \@rolecodes,\%groups_roles);
2670: }
2671: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2672: last;
2673: }
2674: }
2675: }
2676: $checkedgroup{$where} = 1;
2677: }
2678: } elsif ($role =~ /^cr/) {
2679: my $status_in_db =
2680: &curr_role_status($tstart,$tend,$refresh,$now);
2681: my ($rdummy,$rest) = split(/\//,$role,2);
2682: my %currpriv;
2683: unless (exists($crprivs{$rest})) {
2684: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2685: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2686: if (&Apache::lonnet::hostname($homsvr) ne '') {
2687: my ($rdummy,$roledef)=
2688: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2689: $rdomain,$rauthor);
2690: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2691: my $i = 0;
2692: my @scopes = ('sys','dom','crs');
2693: my @privs = split(/\_/,$roledef);
2694: foreach my $priv (@privs) {
2695: my ($blank,@prv) = split(/:/,$priv);
2696: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
2697: if (@prv) {
2698: $priv = ':'.join(':',sort(@prv));
2699: }
2700: $crprivs{$rest}{$scopes[$i]} = $priv;
2701: $i++;
2702: }
2703: }
2704: }
2705: }
2706: my $status_in_env =
2707: &curr_role_status($currstart,$currend,$refresh,$update);
2708: if ($status_in_env eq 'active') {
2709: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2710: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2711: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2712: if (keys(%crprivs)) {
2713: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2714: ($crprivs{$rest}{dom} ne $currpriv{dom})
2715: ||
2716: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2717: &gather_roleprivs(\%allroles,\%allgroups,
2718: \%userroles,$where,$role,
2719: $tstart,$tend,$status_in_db);
2720: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2721: push(@changed_roles,$role);
2722: }
2723: $customprivchg{$rolekey} = $status_in_env;
2724: }
2725: }
2726: }
2727: }
2728: }
2729: }
2730: }
2731: foreach my $envkey (keys(%env)) {
2732: next unless ($envkey =~ /^user\.role\./);
2733: next if ($dbroles{$envkey});
2734: next if ($envkey eq 'user.role.'.$env{'request.role'});
2735: my ($currstart,$currend) = split(/\./,$env{$envkey});
2736: my $status_in_env =
2737: &curr_role_status($currstart,$currend,$refresh,$update);
2738: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2739: my ($role,$rest)=split(m{\./},$rolekey,2);
2740: $rest = '/'.$rest;
2741: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2742: if ($status_in_env eq 'active') {
2743: if ($role eq 'gr') {
2744: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2745: \@possroles);
2746: } else {
2747: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2748: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2749: }
2750: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2751: push(@changed_roles,$role);
2752: }
2753: $deletedroles{$rolekey} = 1;
2754: }
2755: }
2756: }
2757: if (($oldsec) && (@newsec > 0)) {
2758: if (@newsec > 1) {
2759: $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>';
2760: } else {
2761: my $newrole = $env{'request.role'};
2762: if ($newsec[0] eq 'none') {
2763: $newrole =~ s{(/[^/])$}{};
2764: } elsif ($oldsec eq 'none') {
2765: $newrole .= '/'.$newsec[0];
2766: } else {
2767: $newrole =~ s{([^/]+)$}{$newsec[0]};
2768: }
2769: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2770: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2771: my %temp=('logout_'.$env{'request.course.id'} => time);
2772: &Apache::lonnet::put('email_status',\%temp);
2773: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2774: &Apache::lonnet::appenv({"request.course.id" => '',
2775: "request.course.fn" => '',
2776: "request.course.uri" => '',
2777: "request.course.sec" => '',
2778: "request.role" => 'cm',
2779: "request.role.adv" => $env{'user.adv'},
2780: "request.role.domain" => $env{'user.domain'}});
2781: my $rolename = &Apache::loncommon::plainname($curr_role);
2782: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2783: '<input type="hidden" name="newrole" value="" />'.
2784: '<input type="hidden" name="selectrole" value="1" />'.
2785: '<span class="LC_info">'.
2786: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2787: my $button = '<input type="button" name="sectionchanged" value="'.
2788: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2789: if ($newsec[0] eq 'none') {
2790: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2791: } else {
2792: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2793: }
2794: $msg .= '</form></p>';
2795: }
2796: } elsif ($currrole_expired) {
2797: $msg .= '<p class="LC_warning">';
2798: if (&Apache::loncommon::show_course()) {
2799: $msg .= &mt('Your role in the current course has expired.');
2800: } else {
2801: $msg .= &mt('Your current role has expired.');
2802: }
2803: $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>';
2804: }
2805: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2806: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2807: $curr_author = $env{'user.author'};
2808: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2809: ($env{'request.role'} =~/^aa/)) {
2810: $curr_role_author=1;
2811: }
2812: $curr_is_adv = $env{'user.adv'};
2813: $curr_role_adv = $env{'request.role.adv'};
2814: if (keys(%userroles) > 0) {
2815: foreach my $role (@changed_roles) {
2816: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2817: push(@rolecodes,$role);
2818: }
2819: }
2820: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2821: push(@rolecodes,'cm');
2822: }
2823: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2824: }
2825: my %newenv;
2826: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2827: unless ($curr_is_adv) {
2828: $newenv{'user.adv'} = 1;
2829: }
2830: } elsif ($curr_is_adv && !$curr_role_adv) {
2831: &Apache::lonnet::delenv('user.adv');
2832: }
2833: my %authorroleshash =
2834: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2835: if (keys(%authorroleshash)) {
2836: unless ($curr_author) {
2837: $newenv{'user.author'} = 1;
2838: }
2839: } elsif ($curr_author && !$curr_role_author) {
2840: &Apache::lonnet::delenv('user.author');
2841: }
2842: if ($env{'request.course.id'}) {
2843: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2844: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2845: my (@activecrsgroups,$crsgroupschanged);
2846: if ($env{'request.course.groups'}) {
2847: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2848: foreach my $item (keys(%deletedroles)) {
2849: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2850: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2851: $crsgroupschanged = 1;
2852: last;
2853: }
2854: }
2855: }
2856: }
2857: unless ($crsgroupschanged) {
2858: foreach my $item (keys(%newgroup)) {
2859: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2860: if ($newgroup{$item} eq 'active') {
2861: $crsgroupschanged = 1;
2862: last;
2863: }
2864: }
2865: }
2866: }
2867: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2868: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2869: ($crsgroupschanged)) {
2870: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2871: ['active'],['gr'],[$cdom],1);
2872: my @activegroups;
2873: foreach my $item (keys(%grouproles)) {
2874: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2875: my $group;
2876: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2877: if ($remainder =~ /:/) {
2878: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2879: } else {
2880: $group = $remainder;
2881: }
2882: if ($group ne '') {
2883: push(@activegroups,$group);
2884: }
2885: }
2886: $newenv{'request.course.groups'} = join(':',@activegroups);
2887: }
2888: }
2889: if (keys(%newenv)) {
2890: &Apache::lonnet::appenv(\%newenv);
2891: }
2892: if (!@changed_roles || !(keys(%changed_groups))) {
2893: my ($rolesmsg,$groupsmsg);
2894: if (!@changed_roles) {
2895: if (&Apache::loncommon::show_course()) {
2896: $rolesmsg = &mt('No new courses or communities');
2897: } else {
2898: $rolesmsg = &mt('No role changes');
2899: }
2900: }
2901: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
2902: $groupsmsg = &mt('No changes in course/community groups');
2903: }
2904: if (!@changed_roles && !(keys(%changed_groups))) {
2905: if (($msg ne '') || ($groupsmsg ne '')) {
2906: $msg .= '<ul>';
2907: if ($rolesmsg) {
2908: $msg .= '<li>'.$rolesmsg.'</li>';
2909: }
2910: if ($groupsmsg) {
2911: $msg .= '<li>'.$groupsmsg.'</li>';
2912: }
2913: $msg .= '</ul>';
2914: } else {
2915: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
2916: }
2917: return $msg;
2918: }
2919: }
2920: my $changemsg;
2921: if (@changed_roles > 0) {
2922: if (keys(%newgroup) > 0) {
2923: my $groupmsg;
2924: my (%curr_groups,%groupdescs,$currcrs);
2925: foreach my $item (sort(keys(%newgroup))) {
2926: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
2927: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2928: my ($cdom,$cnum) = split(/\//,$1);
2929: my $group = $2;
2930: if ($currcrs ne $cdom.'_'.$cnum) {
2931: if ($currcrs) {
2932: $groupmsg .= '</ul><li>';
2933: }
2934: $groupmsg .= '<li><b>'.
2935: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
2936: $currcrs = $cdom.'_'.$cnum;
2937: }
2938: my $groupdesc;
2939: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2940: %{$curr_groups{$cdom.'_'.$cnum}} =
2941: &Apache::longroup::coursegroups($cdom,$cnum);
2942: }
2943: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2944: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2945:
2946: my %groupinfo =
2947: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
2948: $groupdescs{$cdom.'_'.$cnum}{$group} =
2949: &unescape($groupinfo{'description'});
2950: }
2951: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
2952: if ($groupdesc) {
2953: $groupmsg .= '<li>'.
2954: &mt('[_1] with status: [_2].',
2955: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
2956: }
2957: }
2958: }
2959: if ($groupmsg) {
2960: $groupmsg .= '</ul></li>';
2961: }
2962: }
2963: if ($groupmsg) {
2964: $changemsg .= '<li>'.
2965: &mt('Courses with new groups').'</li>'.
2966: '<ul>'.$groupmsg.'</ul></li>';
2967: }
2968: }
2969: if (keys(%newrole) > 0) {
2970: my $newmsg;
2971: foreach my $item (sort(keys(%newrole))) {
2972: my $desc = &role_desc($item,$update,$refresh,$now);
2973: if ($desc) {
2974: $newmsg .= '<li>'.
2975: &mt('[_1] with status: [_2].',
2976: $desc,&mt($newrole{$item})).'</li>';
2977: }
2978: }
2979: if ($newmsg) {
2980: $changemsg .= '<li>'.&mt('New roles').
2981: '<ul>'.$newmsg.'</ul>'.
2982: '</li>';
2983: }
2984: }
2985: if (keys(%customprivchg) > 0) {
2986: my $privmsg;
2987: foreach my $item (sort(keys(%customprivchg))) {
2988: my $desc = &role_desc($item,$update,$refresh,$now);
2989: if ($desc) {
2990: $privmsg .= '<li>'.$desc.'</li>';
2991: }
2992: }
2993: if ($privmsg) {
2994: $changemsg .= '<li>'.
2995: &mt('Custom roles with privilege changes').
2996: '<ul>'.$privmsg.'</ul>'.
2997: '</li>';
2998: }
2999: }
3000: if (keys(%rolechange) > 0) {
3001: my $rolemsg;
3002: foreach my $item (sort(keys(%rolechange))) {
3003: my $desc = &role_desc($item,$update,$refresh,$now);
3004: if ($desc) {
3005: $rolemsg .= '<li>'.
3006: &mt('[_1] status now: [_2].',$desc,
3007: $rolechange{$item}).'</li>';
3008: }
3009: }
3010: if ($rolemsg) {
3011: $changemsg .= '<li>'.
3012: &mt('Existing roles with status changes').'</li>'.
3013: '<ul>'.$rolemsg.'</ul>'.
3014: '</li>';
3015: }
3016: }
3017: if (keys(%deletedroles) > 0) {
3018: my $delmsg;
3019: foreach my $item (sort(keys(%deletedroles))) {
3020: my $desc = &role_desc($item,$update,$refresh,$now);
3021: if ($desc) {
3022: $delmsg .= '<li>'.$desc.'</li>';
3023: }
3024: }
3025: if ($delmsg) {
3026: $changemsg .= '<li>'.
3027: &mt('Existing roles now expired').'</li>'.
3028: '<ul>'.$delmsg.'</ul>'.
3029: '</li>';
3030: }
3031: }
3032: }
3033: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
3034: my $groupchgmsg;
3035: foreach my $key (sort(keys(%changed_groups))) {
3036: my $crs = 'gr/'.$key;
3037: $crs =~ s/_/\//;
3038: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
3039: if (ref($changed_groups{$key}) eq 'HASH') {
3040: my @showgroups;
3041: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
3042: if ($changed_groups{$key}{$group} eq 'active') {
3043: push(@showgroups,$group);
3044: }
3045: }
3046: if (@showgroups > 0) {
3047: $groupchgmsg .= '<li>'.
3048: &mt('Course: [_1], groups: [_2].',$key,
3049: join(', ',@showgroups)).
3050: '</li>';
3051: }
3052: }
3053: }
3054: }
3055: if (keys(%groupchange) > 0) {
3056: $groupchgmsg .= '<li>'.
3057: &mt('Existing course/community groups with status changes').'</li>'.
3058: '<ul>';
3059: foreach my $crs (sort(keys(%groupchange))) {
3060: my $cid = $crs;
3061: $cid=~s{^/}{};
3062: $cid=~s{/}{_};
3063: my $crsdesc = $env{'course.'.$cid.'.description'};
3064: my $cdom = $env{'course.'.$cid.'.domain'};
3065: my $cnum = $env{'course.'.$cid.'.num'};
3066: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
3067: my %groupdesc;
3068: if (ref($groupchange{$crs}) eq 'HASH') {
3069: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
3070: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
3071: unless ($groupdesc{$group}) {
3072: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
3073: $groupdesc{$group} = &unescape($groupinfo{'description'});
3074: }
3075: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
3076: }
3077: $groupchgmsg .= '</ul></li>';
3078: }
3079: }
3080: $groupchgmsg .= '</ul></li>';
3081: }
3082: if ($groupchgmsg) {
3083: $changemsg .= '<li>'.
3084: &mt('Courses with changes in groups').'</li>'.
3085: '<ul>'.$groupchgmsg.'</ul></li>';
3086: }
3087: }
3088: if ($changemsg) {
3089: $msg .= '<ul>'.$changemsg.'</ul>';
3090: } else {
3091: if (&Apache::loncommon::show_course()) {
3092: $msg = &mt('No new courses or communities');
3093: } else {
3094: $msg = &mt('No role changes');
3095: }
3096: }
3097: return $msg;
3098: }
3099:
3100: sub role_desc {
3101: my ($item,$update,$refresh,$now) = @_;
3102: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
3103: $trole,$tremark);
3104: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
3105: $now,\$role,\$where,\$trolecode,
3106: \$tstatus,\$tstart,\$tend);
3107: return unless ($role);
3108: if ($role =~ /^cr\//) {
3109: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
3110: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
3111: }
3112: $trole=Apache::lonnet::plaintext($role);
3113: my ($tdom,$trest,$tsection)=
3114: split(/\//,Apache::lonnet::declutter($where));
3115: if (($role eq 'ca') || ($role eq 'aa')) {
3116: my $home = &Apache::lonnet::homeserver($trest,$tdom);
3117: $home = &Apache::lonnet::hostname($home);
3118: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
3119: ': '.$tdom.' '.&mt('Server').': '.$home;
3120: } elsif ($role eq 'au') {
3121: my $home = &Apache::lonnet::homeserver
3122: ($env{'user.name'},$env{'user.domain'});
3123: $home = &Apache::lonnet::hostname($home);
3124: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
3125: ': '.$home;
3126: } elsif ($trest) {
3127: my $tcourseid=$tdom.'_'.$trest;
3128: my $crstype = &Apache::loncommon::course_type($tcourseid);
3129: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
3130: if ($env{'course.'.$tcourseid.'.description'}) {
3131: $twhere=$env{'course.'.$tcourseid.'.description'};
3132: } else {
3133: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
3134: if (%newhash) {
3135: $twhere=$newhash{'description'};
3136: } else {
3137: $twhere=&mt('Currently not available');
3138: }
3139: }
3140: if ($tsection) {
3141: $twhere.= ' '.&mt('Section').': '.$tsection;
3142: }
3143: if ($role ne 'st') {
3144: $twhere.= ' '.&mt('Domain').': '.$tdom;
3145: }
3146: } elsif ($tdom) {
3147: $twhere = &mt('Domain').': '.$tdom;
3148: }
3149: my $output;
3150: if ($trole) {
3151: $output = $trole;
3152: if ($twhere) {
3153: $output .= " -- $twhere";
3154: }
3155: if ($tremark) {
3156: $output .= '<br />'.$tremark;
3157: }
3158: }
3159: return $output;
3160: }
3161:
3162: sub curr_role_status {
3163: my ($start,$end,$refresh,$update) = @_;
3164: if (($start) && ($start<0)) { return 'deleted' };
3165: my $status = 'active';
3166: if (($end) && ($end<=$update)) {
3167: $status = 'previous';
3168: }
3169: if (($start) && ($refresh<$start)) {
3170: $status = 'future';
3171: }
3172: return $status;
3173: }
3174:
3175: sub gather_roleprivs {
3176: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
3177: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
3178: if (($area ne '') && ($role ne '')) {
3179: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
3180: $area,$tstart,$tend);
3181: my $spec=$role.'.'.$area;
3182: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
3183: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
3184: if ($status eq 'active') {
3185: if ($role =~ /^cr\//) {
3186: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
3187: } elsif ($role eq 'gr') {
3188: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
3189: $env{'user.domain'},
3190: $env{'user.name'});
3191: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
3192: (undef,my $group_privs) = split(/\//,$trole);
3193: $group_privs = &unescape($group_privs);
3194: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
3195: } else {
3196: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
3197: }
3198: }
3199: }
3200: return;
3201: }
3202:
3203: sub is_active_course {
3204: my ($rolekey,$refresh,$update,$roleshashref) = @_;
3205: return unless(ref($roleshashref) eq 'HASH');
3206: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
3207: my $is_active;
3208: foreach my $key (keys(%{$roleshashref})) {
3209: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
3210: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
3211: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
3212: if ($status eq 'active') {
3213: $is_active = 1;
3214: last;
3215: }
3216: }
3217: }
3218: return $is_active;
3219: }
3220:
3221: sub get_roles_functions {
3222: my ($rolescount,$cattype) = @_;
3223: my @links;
3224: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
3225: if ($env{'environment.canrequest.author'}) {
3226: unless (&Apache::loncoursequeueadmin::is_active_author()) {
3227: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
3228: }
3229: }
3230: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
3231: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
3232: }
3233: if (&Apache::lonmenu::check_for_rcrs()) {
3234: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
3235: }
3236: if ($env{'form.state'} eq 'queued') {
3237: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
3238: } else {
3239: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
3240: }
3241: if ($env{'user.adv'}) {
3242: if ($env{'form.display'} eq 'showall') {
3243: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
3244: } else {
3245: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
3246: }
3247: }
3248: unless ($cattype eq 'none') {
3249: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
3250: }
3251: my $funcs;
3252: if ($env{'browser.mobile'}) {
3253: my @functions;
3254: foreach my $link (@links) {
3255: push(@functions,[$link->[0],$link->[2]]);
3256: }
3257: my $title = 'Display options';
3258: if ($env{'user.adv'}) {
3259: $title = 'Roles options';
3260: }
3261: $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
3262: $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
3263: } else {
3264: $funcs = &Apache::lonhtmlcommon::start_funclist();
3265: foreach my $link (@links) {
3266: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
3267: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
3268: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
3269: $link->[2].'</a>');
3270: }
3271: $funcs .= &Apache::lonhtmlcommon::end_funclist();
3272: $funcs = &Apache::loncommon::head_subbox($funcs);
3273: }
3274: return $funcs;
3275: }
3276:
3277: sub get_queued {
3278: my ($output,%reqcrs);
3279: my ($types,$typenames) = &Apache::loncommon::course_types();
3280: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
3281: $env{'user.name'},'^status:');
3282: foreach my $key (keys(%statusinfo)) {
3283: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
3284: (undef,my($cdom,$cnum)) = split(/:/,$key);
3285: my $requestkey = $cdom.'_'.$cnum;
3286: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3287: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
3288: $env{'user.domain'},$env{'user.name'});
3289: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
3290: my $reqtime = $history{'reqtime'};
3291: my $lastupdate = $history{'timestamp'};
3292: my $showtype = $history{'crstype'};
3293: if (defined($typenames->{$history{'crstype'}})) {
3294: $showtype = $typenames->{$history{'crstype'}};
3295: }
3296: my $description;
3297: if (ref($history{'details'}) eq 'HASH') {
3298: $description = $history{details}{'cdescr'};
3299: }
3300: @{$reqcrs{$reqtime}} = ($description,$showtype);
3301: }
3302: }
3303: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
3304: if (@sortedtimes > 0) {
3305: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
3306: &Apache::loncommon::start_data_table().
3307: &Apache::loncommon::start_data_table_header_row().
3308: '<th>'.&mt('Date requested').'</th>'.
3309: '<th>'.&mt('Course title').'</th>'.
3310: '<th>'.&mt('Course type').'</th>';
3311: &Apache::loncommon::end_data_table_header_row();
3312: foreach my $reqtime (@sortedtimes) {
3313: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
3314: $output .= &Apache::loncommon::start_data_table_row().
3315: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
3316: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
3317: &Apache::loncommon::end_data_table_row();
3318: }
3319: $output .= &Apache::loncommon::end_data_table().
3320: '<br /></p>';
3321: }
3322: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
3323: if ($queuedselfenroll) {
3324: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
3325: $queuedselfenroll.'<br /></p>';
3326: }
3327: if ($env{'environment.canrequest.author'}) {
3328: unless (&Apache::loncoursequeueadmin::is_active_author()) {
3329: my $requestauthor;
3330: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
3331: if (($status eq 'approval') || ($status eq 'approved')) {
3332: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
3333: if ($status eq 'approval') {
3334: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
3335: &Apache::lonlocal::locallocaltime($timestamp));
3336: } elsif ($status eq 'approved') {
3337: my %roleshash =
3338: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
3339: ['active'],['au'],[$env{'user.domain'}]);
3340: if (keys(%roleshash)) {
3341: $output .= '<span class="LC_info">'.
3342: &mt('Your request for an author role has been approved.').'<br />'.
3343: &mt('Use the "Check for changes" link to update your list of roles.').
3344: '</span>';
3345: }
3346: }
3347: $output .= '</p>';
3348: }
3349: }
3350: }
3351: unless ($output) {
3352: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
3353: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
3354: $output = &mt('No requests for courses, communities or authoring currently queued');
3355: } else {
3356: $output = &mt('No enrollment requests currently queued awaiting approval');
3357: }
3358: }
3359: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
3360: $output.'</fieldset></div><br clear="all" />';
3361: }
3362:
3363: sub process_lti {
3364: my ($r,$cdom,$cnum) = @_;
3365: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
3366: my $uriscope = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
3367: $cdom,$cnum);
3368: my $lonhost = $r->dir_config('lonHostID');
3369: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
3370: if ($env{'request.lti.rosterid'} &&
3371: $env{'request.lti.rosterurl'}) {
3372: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
3373: if ($lti{$env{'request.lti.login'}}{'roster'}) {
3374: my @lcroles = ('in','ta','ep','st');
3375: my @possibleroles;
3376: foreach my $role (@lcroles) {
3377: if (&Apache::lonnet::allowed('c'.$role,"$cdom/$cnum")) {
3378: push(@possibleroles,$role);
3379: }
3380: }
3381: my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'};
3382: if ($owner eq $env{'user.name'}.':'.$env{'user.domain'}) {
3383: my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
3384: if ($crstype eq 'Community') {
3385: unshift(@possibleroles,'co');
3386: } else {
3387: unshift(@possibleroles,'cc');
3388: }
3389: }
3390: if (@possibleroles) {
3391: push(@{$rosterupdates},{cid => $cdom.'_'.$cnum,
3392: lti => $env{'request.lti.login'},
3393: ltiref => $lti{$env{'request.lti.login'}},
3394: id => $env{'request.lti.rosterid'},
3395: url => $env{'request.lti.rosterurl'},
3396: sourcecrs => $env{'request.lti.sourcecrs'},
3397: uriscope => $uriscope,
3398: possroles => \@possibleroles,
3399: intdoms => $internet_names,
3400: });
3401: unless ($registered_cleanup) {
3402: my $handlers = $r->get_handlers('PerlCleanupHandler');
3403: $r->set_handlers('PerlCleanupHandler' =>
3404: [\<ienroll,@{$handlers}]);
3405: $registered_cleanup=1;
3406: }
3407: }
3408: }
3409: }
3410: }
3411: if ($env{'request.lti.passbackid'} &&
3412: $env{'request.lti.passbackurl'}) {
3413: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
3414: if ($lti{$env{'request.lti.login'}}{'passback'}) {
3415: my ($pbnum,$error) =
3416: &LONCAPA::ltiutils::store_passbackurl($env{'request.lti.login'},
3417: $env{'request.lti.passbackurl'},
3418: $cdom,$cnum);
3419: if ($pbnum eq '') {
3420: $pbnum = $env{'request.lti.passbackurl'};
3421: }
3422: &Apache::lonnet::put('nohist_'.$cdom.'_'.$cnum.'_passback',
3423: {"$uriscope\0$env{'request.lti.sourcecrs'}\0$env{'request.lti.login'}" =>
3424: "$pbnum\0$env{'request.lti.passbackid'}"});
3425: }
3426: }
3427: }
3428: return;
3429: }
3430:
3431: sub ltienroll {
3432: if (ref($rosterupdates) eq 'ARRAY') {
3433: foreach my $item (@{$rosterupdates}) {
3434: if (ref($item) eq 'HASH') {
3435: &LONCAPA::ltiutils::batchaddroster($item);
3436: }
3437: }
3438: }
3439: }
3440:
3441: 1;
3442: __END__
3443:
3444: =head1 NAME
3445:
3446: Apache::lonroles - User Roles Screen
3447:
3448: =head1 SYNOPSIS
3449:
3450: Invoked by /etc/httpd/conf/srm.conf:
3451:
3452: <Location /adm/roles>
3453: PerlAccessHandler Apache::lonacc
3454: SetHandler perl-script
3455: PerlHandler Apache::lonroles
3456: ErrorDocument 403 /adm/login
3457: ErrorDocument 500 /adm/errorhandler
3458: </Location>
3459:
3460: =head1 OVERVIEW
3461:
3462: =head2 Choosing Roles
3463:
3464: C<lonroles> is a handler that allows a user to switch roles in
3465: mid-session. LON-CAPA attempts to work with "No Role Specified", the
3466: default role that a user has before selecting a role, as widely as
3467: possible, but certain handlers for example need specification which
3468: course they should act on, etc. Both in this scenario, and when the
3469: handler determines via C<lonnet>'s C<&allowed> function that a certain
3470: action is not allowed, C<lonroles> is used as error handler. This
3471: allows the user to select another role which may have permission to do
3472: what they were trying to do.
3473:
3474: =begin latex
3475:
3476: \begin{figure}
3477: \begin{center}
3478: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
3479: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
3480: \end{center}
3481: \end{figure}
3482:
3483: =end latex
3484:
3485: =head2 Role Initialization
3486:
3487: 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.
3488:
3489: =head1 INTRODUCTION
3490:
3491: This module enables a user to select what role he wishes to
3492: operate under (instructor, student, teaching assistant, course
3493: coordinator, etc). These roles are pre-established by the actions
3494: of upper-level users.
3495:
3496: This is part of the LearningOnline Network with CAPA project
3497: described at http://www.lon-capa.org.
3498:
3499: =head1 HANDLER SUBROUTINE
3500:
3501: This routine is called by Apache and mod_perl.
3502:
3503: =over 4
3504:
3505: =item *
3506:
3507: Roles Initialization (yes/no)
3508:
3509: =item *
3510:
3511: Get Error Message from Environment
3512:
3513: =item *
3514:
3515: Who is this?
3516:
3517: =item *
3518:
3519: Generate Page Output
3520:
3521: =item *
3522:
3523: Choice or no choice
3524:
3525: =item *
3526:
3527: Table
3528:
3529: =item *
3530:
3531: Privileges
3532:
3533: =back
3534:
3535: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>