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