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