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