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