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