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