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