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