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