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