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