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