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