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