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