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