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