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