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