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