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