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