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