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