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