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