1: # The LearningOnline Network with CAPA
2: # displays the blocking status table
3: #
4: # $Id: lonblockingstatus.pm,v 1.14.2.6 2021/12/24 21:32:03 raeburn Exp $
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: #
28: #
29: package Apache::lonblockingstatus;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon();
34: use Apache::lonnet;
35: use Apache::lonlocal;
36: use LONCAPA qw(:DEFAULT :match);
37:
38: sub handler {
39: my $r = shift;
40: &Apache::loncommon::no_cache($r);
41: &Apache::loncommon::content_type($r,'text/html');
42:
43: $r->send_http_header;
44: return OK if $r->header_only;
45:
46: my (%activities,$activity,$origurl,$origsymb);
47: map { $activities{$_} = 1; } ('boards','chat','com','blogs','about','groups','port','printout','docs','grades','passwd','search','wishlist','annotate');
48:
49: # determine what kind of blocking we want details for
50: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['activity','url','symb']);
51: $activity = $env{'form.activity'};
52:
53: my $title = 'Communication Blocking Status Information';
54:
55: if (($activity eq 'docs') || ($activity eq 'printout') ||
56: ($activity eq 'grades') || ($activity eq 'passwd') ||
57: ($activity eq 'search') || ($activity eq 'wishlist') ||
58: ($activity eq 'annotate')) {
59: $title = 'Blocking Status Information';
60: if ($activity eq 'docs') {
61: $origurl = $env{'form.url'};
62: $origsymb = $env{'form.symb'};
63: }
64: }
65: $r->print(&Apache::loncommon::start_page($title,undef,
66: {'only_body' => 1}));
67:
68: if (($activity eq '') || (!$activities{$activity})) {
69: $r->print('<p class="LC_error">'.&mt('Error: unknown activity type blocked').'</p>');
70: } elsif (($activity eq 'docs') && ($origurl eq '') && ($origsymb eq '')) {
71: $r->print('<p class="LC_error">'.&mt('Error: could not determine what content was blocked from access').'</p>');
72: } else {
73: my $clientip = &Apache::lonnet::get_requestor_ip($r);
74: $r->print(&blockpage($activity,$origurl,$origsymb,$clientip));
75: }
76:
77: $r->print(&Apache::loncommon::end_page());
78:
79: return OK;
80: }
81:
82: sub blockpage {
83: my ($activity,$origurl,$origsymb,$clientip) = @_;
84:
85: # in case of a portfolio block we need to determine the owner of the files
86: # we're trying to look at. This information is passed via query string.
87: my ($uname, $udom);
88:
89: if (($activity eq 'port') || ($activity eq 'about') ||
90: (($activity eq 'passwd') && ($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))) {
91: &Apache::loncommon::get_unprocessed_cgi(
92: $ENV{'QUERY_STRING'}, ['udom', 'uname'] );
93:
94: ($uname, $udom) = ($env{'form.uname'}, $env{'form.udom'});
95: if (($uname !~ /^$match_username$/) || ($udom !~ /^$match_domain$/)) {
96: if ($activity eq 'port') {
97: return '<span class="LC_error">'.
98: &mt('Information about the owner of the portfolio files you were trying to view was missing or invalid.').
99: '</span><br />'.
100: &mt('Without valid owner information, the reason why access is blocked can not be determined');
101: } elsif ($activity eq 'about') {
102: return '<span class="LC_error">'.
103: &mt('The username and/or domain for the User Information page you were trying to view was missing or invalid.').
104: '</span><br />'.
105: &mt('Without valid information, the reason why access is blocked can not be determined');
106: } else {
107: return '<span class="LC_error">'.
108: &mt('Information about the username and/or domain for which you were trying to reset a password was missing or invalid.').
109: '</span><br />'.
110: &mt('Without valid information, the reason why access is blocked can not be determined');
111: }
112: }
113: }
114:
115: # retrieve start/end of possible active blocking
116: my (%setters,$startblock,$endblock,$triggerblock,$by_ip,$blockdom);
117:
118: if ($activity eq 'docs') {
119: my ($cdom,$cnum);
120: if ($env{'request.course.id'}) {
121: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
122: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
123: }
124: my $cancheck;
125: if (($cdom ne '') && ($cnum ne '')) {
126: if ($origsymb =~ m{^uploaded/($match_domain)/($match_courseid)/}) {
127: my ($crsdom,$crsnum) = ($1,$2);
128: if (($cdom eq $crsdom) && ($cnum eq $crsnum)) {
129: $cancheck = 1;
130: }
131: } else {
132: $cancheck = 1;
133: }
134: }
135: if ($cancheck) {
136: ($startblock,$endblock,$triggerblock) =
137: &Apache::loncommon::blockcheck(\%setters,$activity,$clientip,$cnum,$cdom,$origurl,1,$origsymb,'blockingstatus');
138: } else {
139: return '<p class="LC_info">'.&mt('Could not determine why access is blocked.').'</p>';
140: }
141: } else {
142: ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
143: &Apache::loncommon::blockcheck(\%setters,$activity,$clientip,$uname,$udom,$origurl,undef,$origsymb,'blockingstatus');
144: }
145:
146: # nothing to do if there's no active blocking
147: unless (($startblock && $endblock) || ($by_ip)) {
148: if ($activity eq 'docs') {
149: return '<p class="LC_info">'.&mt('Content no longer blocked from access').'</p>';
150: }
151: return '<p class="LC_info">'.&mt('Access no longer blocked for this activity').'</p>';
152: }
153:
154: # lookup $activity -> description
155: #possible activity #corresponding description
156: my %descs = (
157: boards => 'Discussion posts in this course',
158: chat => 'Chat Room',
159: com => 'This message',
160: blogs => 'Blogs',
161: about => 'User information pages',
162: groups => 'Groups in this course',
163: printout => 'Printout generation',
164: docs => 'Course Content',
165: passwd => 'Changing of passwords',
166: grades => 'Course Gradebook',
167: search => 'Content Search',
168: wishlist => 'Stored Links',
169: annotate => 'Annotations',
170: );
171:
172: if ($activity eq 'groups' || $activity eq 'boards') {
173: if (&Apache::loncommon::course_type() eq 'Community') {
174: $descs{'boards'} = 'Discussion posts in this community';
175: $descs{'groups'} = 'Groups in this community';
176: $descs{'docs'} = 'Community Content';
177: $descs{'grades'} = 'Community Gradebook';
178: }
179: }
180:
181: my $description = $descs{$activity};
182: if ($activity eq 'port') {
183: $description = &get_portfolio_category($uname,$udom,$by_ip,\%setters);
184: }
185: if ($description eq '') {
186: $description = 'Communication';
187: }
188:
189: my ($showstart,$showend,$output);
190: unless ($by_ip) {
191: $showstart = Apache::lonlocal::locallocaltime($startblock);
192: $showend = Apache::lonlocal::locallocaltime($endblock);
193: }
194:
195: if ( ref($description) ne 'ARRAY' ) {
196: #default: $description is one of the above descriptions
197: if ($activity eq 'docs') {
198: $output=&mt( 'Access to the content page you are attempting to'
199: . ' view will be unavailable between [_1] and [_2] because'
200: . ' access to selected '.$description.' is being blocked.'
201: ,$showstart, $showend);
202: } elsif (($activity eq 'printout') || ($activity eq 'passwd') ||
203: ($activity eq 'grades') || ($activity eq 'search') ||
204: ($activity eq 'about') || ($activity eq 'wishlist') ||
205: ($activity eq 'annotate')) {
206: if ($by_ip) {
207: $output = mt( $description
208: . ' unavailable from your current IP address: [_1] '
209: . 'because this functionality is being blocked for certain IP address(es).'
210: ,$clientip);
211: } else {
212: $output = mt( $description
213: . ' will be unavailable between [_1] and [_2] because'
214: . ' this functionality is being blocked.'
215: ,$showstart, $showend);
216: }
217: } else {
218: if ($by_ip) {
219: $output = mt( $description
220: . ' unavailable from your current IP address: [_1] '
221: . 'because communication is being blocked for certain IP address(es).'
222: ,$clientip);
223: } else {
224: $output = mt( $description
225: . ' will be inaccessible between [_1] and [_2] because'
226: . ' communication is being blocked.'
227: ,$showstart, $showend);
228: }
229: }
230: } else {
231: # @$description is is the array returned from get_portfolio_category()
232: # and contains the description (e.g. "Portfolio files belonging to [_1]"
233: # and the value for [_1]
234: if ($by_ip) {
235: $output = mt( $$description[0]
236: . ' are inaccessible from your current IP address: [_2] '
237: . 'because communication is being blocked for certain IP address(es).'
238: , $$description[1], $clientip);
239: } else {
240: $output = mt( $$description[0]
241: . ' will be inaccessible between [_2] and [_3] because'
242: . ' communication is being blocked.'
243: ,$$description[1], $showstart, $showend);
244: }
245: }
246:
247: $output = "<p class=\"LC_info\">$output</p>";
248:
249: # show a table containing details, except if user is trying to look
250: # at a different user's portfolio files
251: if ( $activity ne 'port' # no portfolio
252: || ( $uname eq $env{'user.name'} # or own portfolio
253: && $udom eq $env{'user.domain'} )
254: || Apache::lonnet::is_course($udom, $uname) ) # or portfolio of a course
255: {
256: if ($by_ip) {
257: my $showdom = &Apache::lonnet::domain($blockdom);
258: if ($showdom eq '') {
259: $showdom = $blockdom;
260: }
261: $output .= '<br />'.
262: &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.'
263: ,$showdom);
264: } else {
265: $output .= &build_block_table(\%setters);
266: }
267: }
268:
269: return $output;
270: }
271:
272: sub build_block_table {
273: my ($setters) = @_;
274: my %lt = &Apache::lonlocal::texthash(
275: 'cacb' => 'Currently active communication/content blocks',
276: 'cour' => 'Course',
277: 'dura' => 'Duration',
278: 'blse' => 'Block set by'
279: );
280: my $output;
281: $output = Apache::loncommon::start_data_table()
282: . Apache::loncommon::data_table_caption($lt{'cacb'})
283: . Apache::loncommon::start_data_table_header_row()
284: . "<th>$lt{'cour'}</th> <th>$lt{'dura'}</th> <th>$lt{'blse'}</th>"
285: . Apache::loncommon::end_data_table_header_row();
286:
287: foreach my $course (keys(%{$setters})) {
288: my %courseinfo=&Apache::lonnet::coursedescription($course);
289: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
290: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
291: my $fullname = Apache::loncommon::plainname($uname,$udom);
292: if (defined($env{'user.name'}) && defined($env{'user.domain'})
293: && $env{'user.name'} ne 'public'
294: && $env{'user.domain'} ne 'public')
295: {
296: $fullname = Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
297: }
298: my $triggertype = $$setters{$course}{triggers}[$i];
299: if ($triggertype) {
300: $fullname .= &mt(' (triggered by you when starting timer)');
301: }
302: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
303: $openblock = &Apache::lonlocal::locallocaltime($openblock);
304: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
305: my $duration = mt('[_1] to [_2]', $openblock, $closeblock);
306: $output .= Apache::loncommon::start_data_table_row()
307: . "<td>$courseinfo{'description'}</td>"
308: . "<td>$duration</td>"
309: . "<td>$fullname</td>"
310: . Apache::loncommon::end_data_table_row();
311: }
312: }
313: $output .= Apache::loncommon::end_data_table();
314: }
315:
316: sub get_portfolio_category {
317: my ($uname, $udom, $by_ip, $setters) = @_;
318:
319: if ($uname eq $env{'user.name'} && $udom eq $env{'user.domain'}) {
320: # user's portolfio files
321:
322: return 'Your portfolio files';
323:
324: } elsif (Apache::lonnet::is_course($udom, $uname)) {
325: # group portfolio files
326:
327: my $coursedesc;
328:
329: if ($by_ip) {
330: my %courseinfo = Apache::lonnet::coursedescription($udom.'_'.$uname);
331: $coursedesc = $courseinfo{'description'};
332: } else {
333: foreach my $course (keys(%{$setters})) {
334: my %courseinfo = Apache::lonnet::coursedescription($course);
335: $coursedesc = $courseinfo{'description'};
336: }
337: }
338:
339: return ["Group portfolio files in the course '[_1]'", $coursedesc];
340:
341: } else {
342: # different user's portfolio files
343:
344: my $plainname = Apache::loncommon::plainname($uname, $udom);
345:
346: unless ( $env{'user.name'} eq 'public'
347: && $env{'user.domain'} eq 'public' )
348: {
349: $plainname = Apache::loncommon::aboutmewrapper(
350: $plainname, $uname, $udom);
351: }
352:
353: return ['Portfolio files belonging to [_1]', $plainname];
354: }
355: }
356:
357: 1;
358: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>