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