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