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