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