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