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