[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom loncapa_apache.conf startup.pl loncom/interface lonblockingmenu.pm lonmsgdisplay.pm lonparmset.pm
raeburn
raeburn at source.lon-capa.org
Wed Dec 28 16:50:07 EST 2011
raeburn Wed Dec 28 21:50:07 2011 EDT
Added files:
/loncom/interface lonblockingmenu.pm
Modified files:
/loncom loncapa_apache.conf startup.pl
/loncom/interface lonparmset.pm lonmsgdisplay.pm
/doc/loncapafiles loncapafiles.lpml
Log:
- Move routines for configuration of blocking communication during an exam
from lonmsgdisplay.pm to separate handler -- lonblockingmenu.pm
- Access to corresponding URL: /adm/setblock from both Messages menu (as before)
and also from Content and Problem Settings menu.
-------------- next part --------------
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.207 loncom/loncapa_apache.conf:1.208
--- loncom/loncapa_apache.conf:1.207 Sun Dec 25 20:41:59 2011
+++ loncom/loncapa_apache.conf Wed Dec 28 21:49:41 2011
@@ -1,7 +1,7 @@
##
## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
##
-## $Id: loncapa_apache.conf,v 1.207 2011/12/25 20:41:59 raeburn Exp $
+## $Id: loncapa_apache.conf,v 1.208 2011/12/28 21:49:41 raeburn Exp $
##
#
@@ -1246,6 +1246,16 @@
ErrorDocument 500 /adm/errorhandler
</Location>
+<Location /adm/setblock>
+AuthType LONCAPA
+Require valid-user
+PerlAuthzHandler Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::lonblockingmenu
+ErrorDocument 403 /adm/login
+ErrorDocument 500 /adm/errorhandler
+</Location>
+
<Location /adm/blockingstatus>
PerlAccessHandler Apache::publiccheck
AuthType LONCAPA
Index: loncom/startup.pl
diff -u loncom/startup.pl:1.39 loncom/startup.pl:1.40
--- loncom/startup.pl:1.39 Mon Feb 7 21:10:59 2011
+++ loncom/startup.pl Wed Dec 28 21:49:41 2011
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $Id: startup.pl,v 1.39 2011/02/07 21:10:59 raeburn Exp $
+# $Id: startup.pl,v 1.40 2011/12/28 21:49:41 raeburn Exp $
BEGIN {
eval "use Apache2::compat();";
@@ -153,6 +153,7 @@
use Apache::lonconfigsettings();
use Apache::courseprefs();
use Apache::domainprefs();
+use Apache::lonblockingmenu();
1;
__END__
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.519 loncom/interface/lonparmset.pm:1.520
--- loncom/interface/lonparmset.pm:1.519 Thu Dec 15 01:21:41 2011
+++ loncom/interface/lonparmset.pm Wed Dec 28 21:49:54 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.519 2011/12/15 01:21:41 raeburn Exp $
+# $Id: lonparmset.pm,v 1.520 2011/12/28 21:49:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3673,6 +3673,11 @@
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
my $mgr = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
+ my $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'});
+ if ((!$dcm) && ($env{'request.course.sec'} ne '')) {
+ $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'});
+ }
my $crstype = &Apache::loncommon::course_type();
my $lc_crstype = lc($crstype);
@@ -3692,7 +3697,12 @@
linktitle => "Reset access times for folders/maps, resources or the $lc_crstype." ,
icon => 'start-here.png' ,
},
-
+ { linktext => 'Blocking Communication/Resource Access',
+ url => '/adm/setblock',
+ permission => $dcm,
+ linktitle => 'Configure blocking of communication/collaboration and access to resources during an exam',
+ icon => 'comblock.png',
+ },
{ linktext => 'Set Parameter Setting Default Actions',
url => '/adm/parmset?action=setdefaults',
permission => $parm_permission,
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.158 loncom/interface/lonmsgdisplay.pm:1.159
--- loncom/interface/lonmsgdisplay.pm:1.158 Wed Dec 28 14:28:47 2011
+++ loncom/interface/lonmsgdisplay.pm Wed Dec 28 21:49:54 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.158 2011/12/28 14:28:47 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.159 2011/12/28 21:49:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2057,317 +2057,6 @@
}
}
-# ----------------------------------------------------------- Blocking during exams
-
-sub examblock {
- my ($r,$action) = @_;
- unless ($env{'request.course.id'}) { return;}
- if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})
- && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
- '/'.$env{'request.course.sec'})) {
- $r->print('Not allowed');
- return;
- }
- my $usertype;
- my $crstype = &Apache::loncommon::course_type();
- if ($crstype eq 'Community') {
- $usertype = 'members';
- } else {
- $usertype = 'students';
- }
- my $lctype = lc($crstype);
- my %lt=&Apache::lonlocal::texthash(
- 'comb' => 'Communication Blocking',
- 'cbds' => 'Communication blocking during scheduled exams',
- 'desc' => "You can use communication blocking to prevent $usertype enrolled in this $lctype from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA course or community, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.",
- 'mecb' => 'Modify existing communication blocking periods',
- 'ncbc' => 'No communication blocks currently saved',
- 'stor' => 'Save',
- );
-
- my %ltext = &Apache::lonlocal::texthash(
- 'dura' => 'Duration',
- 'setb' => 'Set by',
- 'even' => 'Event',
- 'blck' => 'Blocked?',
- 'actn' => 'Action',
- 'star' => 'Start',
- 'endd' => 'End'
- );
-
- &printheader($r,'/adm/email?block=display',$lt{'comb'});
- $r->print('<h3>'.$lt{'cbds'}.'</h3>');
-
- if ($action eq 'store') {
- &blockstore($r);
- }
-
- $r->print($lt{'desc'}.'<br /><br />
- <form name="blockform" method="post" action="/adm/email?block=store">
- ');
-
- $r->print('<h4>'.$lt{'mecb'}.'</h4>');
- my %records = ();
- my $blockcount = 0;
- my $parmcount = 0;
- &get_blockdates(\%records,\$blockcount);
- if ($blockcount > 0) {
- $parmcount = &display_blocker_status($r,\%records,\%ltext);
- } else {
- $r->print($lt{'ncbc'}.'<br /><br />');
- }
- &display_addblocker_table($r,$parmcount,\%ltext);
- my $end_page=&Apache::loncommon::end_page();
- $r->print(<<"END");
-<br />
-<input type="hidden" name="blocktotal" value="$blockcount" />
-<input type ="submit" value="$lt{'stor'}" />
-</form>
-$end_page
-END
- return;
-}
-
-sub blockstore {
- my $r = shift;
- my %lt=&Apache::lonlocal::texthash(
- 'tfcm' => 'The following changes were made',
- 'ncwm' => 'No changes were made.'
- );
- my %adds = ();
- my %removals = ();
- my %cancels = ();
- my $modtotal = 0;
- my $canceltotal = 0;
- my $addtotal = 0;
- my %blocking = ();
- $r->print('<h3>'.$lt{'head'}.'</h3>');
- foreach my $envkey (keys(%env)) {
- if ($envkey =~ m/^form\.modify_(\d+)$/) {
- $adds{$1} = $1;
- $removals{$1} = $1;
- $modtotal ++;
- } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
- $cancels{$1} = $1;
- unless ( defined($removals{$1}) ) {
- $removals{$1} = $1;
- $canceltotal ++;
- }
- } elsif ($envkey =~ m/^form\.add_(\d+)$/) {
- $adds{$1} = $1;
- $addtotal ++;
- }
- }
-
- foreach my $key (keys(%removals)) {
- my $hashkey = $env{'form.key_'.$key};
- &Apache::lonnet::del('comm_block',["$hashkey"],
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}
- );
- }
- foreach my $key (keys(%adds)) {
- unless ( defined($cancels{$key}) ) {
- my ($newstart,$newend) = &get_dates_from_form($key);
- my $newkey = $newstart.'____'.$newend;
- my $blocktypes = &get_block_choices($key);
- $blocking{$newkey} = {
- setter => $env{'user.name'}.':'.$env{'user.domain'},
- event => &escape($env{'form.title_'.$key}),
- blocks => $blocktypes,
- };
- }
- }
- if ($addtotal + $modtotal > 0) {
- &Apache::lonnet::put('comm_block',\%blocking,
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}
- );
- }
- my $chgestotal = $canceltotal + $modtotal + $addtotal;
- if ($chgestotal > 0) {
- $r->print($lt{'tfcm'}.'<ul>');
- if ($canceltotal > 0) {
- $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
- }
- if ($modtotal > 0) {
- $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
- }
- if ($addtotal > 0) {
- $r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
- }
- $r->print('</ul>');
- } else {
- $r->print($lt{'ncwm'});
- }
- $r->print('<br />');
- return;
-}
-
-sub get_dates_from_form {
- my $item = shift;
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
- return ($startdate,$enddate);
-}
-
-sub get_blockdates {
- my ($records,$blockcount) = @_;
- $$blockcount = 0;
- %{$records} = &Apache::lonnet::dump('comm_block',
- $env{'course.'.$env{'request.course.id'}.'.domain'},
- $env{'course.'.$env{'request.course.id'}.'.num'}
- );
- $$blockcount = keys(%{$records});
-
- if ((keys(%{$records}))[0] =~ /^error: 2 /) {
- $records = {};
- $$blockcount = 0;
- }
-}
-
-sub get_block_choices {
- my $item = shift;
- my $blocklist;
- my ($typeorder,$types) = &blocktype_text();
- foreach my $type (@{$typeorder}) {
- if ($env{'form.'.$type.'_'.$item}) {
- $blocklist->{$type} = 'on';
- } else {
- $blocklist->{$type} = 'off';
- }
- }
- return $blocklist;
-}
-
-sub display_blocker_status {
- my ($r,$records,$ltext) = @_;
- my $parmcount = 0;
-
- my %lt = &Apache::lonlocal::texthash(
- 'modi' => 'Modify',
- 'canc' => 'Cancel',
- );
- my ($typeorder,$types) = &blocktype_text();
- $r->print(&Apache::loncommon::start_data_table());
- $r->print(<<"END");
- <tr>
- <th>$ltext->{'dura'}</th>
- <th>$ltext->{'setb'}</th>
- <th>$ltext->{'even'}</th>
- <th>$ltext->{'blck'}</th>
- <th>$ltext->{'actn'}</th>
- </tr>
-END
- foreach my $record (sort(keys(%{$records}))) {
- my $onchange = 'onFocus="javascript:window.document.forms['.
- "'blockform'].elements['modify_".$parmcount."'].".
- 'checked=true;"';
- my ($start,$end) = split(/____/,$record);
- my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
- my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
-
- my ($setuname,$setudom,$title,$blocks) =
- &Apache::loncommon::parse_block_record($$records{$record});
- $title = &HTML::Entities::encode($title,'"<>&');
- my $settername =
- &Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($setuname,$setudom),
- $setuname,$setudom);
- $r->print(&Apache::loncommon::start_data_table_row());
- $r->print(<<"END");
- <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
- <td>$settername</td>
- <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
- <td>
-END
- foreach my $block (@{$typeorder}) {
- my $blockstatus = '';
- if ($blocks->{$block} eq 'on') {
- $blockstatus = 'checked="checked"';
- }
- $r->print('<span class="LC_nobreak"><label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label></span><br />');
- }
- $r->print(<<"END");
- </td>
- <td><span class="LC_nobreak"><label>
- <input type="checkbox" name="modify_$parmcount" />$lt{'modi'}
- </label></span><br /><span class="LC_nobreak">
- <label>
- <input type="checkbox" name="cancel_$parmcount" />$lt{'canc'}
- </label></span>
-END
- $r->print(&Apache::loncommon::end_data_table_row());
- $parmcount++;
- }
- $r->print(<<"END");
-</table>
-<br />
-<br />
-END
- return $parmcount;
-}
-
-sub display_addblocker_table {
- my ($r,$parmcount,$ltext) = @_;
- my $start = time;
- my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
- my $onchange = 'onFocus="javascript:window.document.forms['.
- "'blockform'].elements['add_".$parmcount."'].".
- 'checked=true;"';
- my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
- my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
- my %lt = &Apache::lonlocal::texthash(
- 'addb' => 'Add block',
- 'exam' => 'e.g., Exam 1',
- 'addn' => 'Add new communication blocking periods'
- );
- my ($typeorder,$types) = &blocktype_text();
- $r->print(<<"END");
-<h4>$lt{'addn'}</h4>
-END
- $r->print(&Apache::loncommon::start_data_table());
- $r->print(<<"END");
- <tr>
- <th>$ltext->{'dura'}</th>
- <th>$ltext->{'even'} $lt{'exam'}</th>
- <th>$ltext->{'blck'}</th>
- <th>$ltext->{'actn'}</th>
- </tr>
-END
- $r->print(&Apache::loncommon::start_data_table_row());
- $r->print(<<"END");
- <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
- <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
- <td>
-END
- foreach my $block (@{$typeorder}) {
- $r->print('<span class="LC_nobreak"><label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label></span><br />');
- }
- $r->print(<<"END");
- </td>
- <td><span class="LC_nobreak"><label>
- <input type="checkbox" name="add_$parmcount" value="1" />$lt{'addb'}
- </label></span></td>
-END
- $r->print(&Apache::loncommon::end_data_table_row());
- $r->print(&Apache::loncommon::end_data_table());
- return;
-}
-
-sub blocktype_text {
- my %types = &Apache::lonlocal::texthash(
- 'com' => 'Messaging',
- 'chat' => 'Chat Room',
- 'boards' => 'Discussion',
- 'port' => 'Portfolio',
- 'groups' => 'Groups',
- 'blogs' => 'Blogs',
- );
- my $typeorder = ['com','chat','boards','port','groups','blogs'];
- return ($typeorder,\%types);
-}
-
# ----------------------------------------------------------- Display a message
sub displaymessage {
@@ -2384,7 +2073,6 @@
if ( $blocked{$msgid} eq 'ON' ) {
&printheader($r,'/adm/email',&mt('Display a Message'));
#$r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.'));
- #&build_block_table($r,$startblock,$endblock,\%setters);
my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com");
$r->print("<br />".$blocktext);
return;
@@ -3351,15 +3039,13 @@
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['display','replyto','forward','markread','markdel','markunread',
'sendreply','compose','sendmail','critical','recname','recdom',
- 'recordftf','sortedby','block','folder','startdis','interdis',
+ 'recordftf','sortedby','folder','startdis','interdis',
'showcommentbaseurl','dismode','group','subject','text','ref',
'msgstatus']);
$sqs='&sortedby='.$env{'form.sortedby'};
# ------------------------------------------------------ They checked for email
- unless ($env{'form.block'}) {
- &Apache::lonnet::put('email_status',{'recnewemail'=>0});
- }
+ &Apache::lonnet::put('email_status',{'recnewemail'=>0});
# ----------------------------------------------------------------- Breadcrumbs
@@ -3562,8 +3248,6 @@
&compout($r,'','',$env{'form.compose'});
} elsif ($env{'form.recordftf'}) {
&facetoface($r,$env{'form.recordftf'});
- } elsif ($env{'form.block'}) {
- &examblock($r,$env{'form.block'});
} elsif ($env{'form.sendmail'}) {
if ($env{'form.multiforward'}) {
&printheader($r,'','Messages being sent.');
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.778 doc/loncapafiles/loncapafiles.lpml:1.779
--- doc/loncapafiles/loncapafiles.lpml:1.778 Sun Dec 25 20:42:17 2011
+++ doc/loncapafiles/loncapafiles.lpml Wed Dec 28 21:50:07 2011
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.778 2011/12/25 20:42:17 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.779 2011/12/28 21:50:07 raeburn Exp $ -->
<!--
@@ -7721,6 +7721,15 @@
</description>
</file>
<file>
+ <source>loncom/interface/lonblockingmenu.pm</source>
+ <target dist='default'>home/httpd/lib/perl/Apache/lonblockingmenu.pm</target>
+ <categoryname>handler</categoryname>
+ <description>
+ Handler for configuration of blocking of access to collaborative tools and/or
+resources for the duration of an exam.
+ </description>
+</file>
+<file>
<source>loncom/interface/lonblockingstatus.pm</source>
<target dist='default'>home/httpd/lib/perl/Apache/lonblockingstatus.pm</target>
<categoryname>handler</categoryname>
Index: loncom/interface/lonblockingmenu.pm
+++ loncom/interface/lonblockingmenu.pm
# The LearningOnline Network with CAPA
# Routines for configuring blocking to collaborative functions, and specific
# resources during an exam
#
# $Id: lonblockingmenu.pm,v 1.1 2011/12/28 21:49:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###############################################################
##############################################################
=pod
=head1 NAME
lonblockingmenu - Handler to set/modify exam blocks in a course.
=head1 SYNOPSIS
lonblockingmenu provides an interface for setting exam blocks in a course.
=head1 DESCRIPTION
This module is used to configure blocking of access to collaborative tools
and/or resources during an exam.
=head1 INTERNAL SUBROUTINES
=over
=item &blockstore()
=item &get_dates_from_form()
=item &get_blockdates()
=item &get_block_choices()
=item &display_blocker_status()
=item &display_addblocker_table()
=item &blocktype_text()
=back
=cut;
package Apache::lonblockingmenu;
use strict;
use Apache::lonnet;
use Apache::Constants qw(:common :http);
use Apache::loncommon();
use Apache::lonhtmlcommon();
use HTML::Entities();
use Apache::lonlocal;
use lib '/home/httpd/lib/perl/';
use LONCAPA qw(:DEFAULT :match);
sub handler {
my $r=shift;
# ----------------------------------------------------------- Set document type
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
# Needs to be in a course
if (! ($env{'request.course.fn'})) {
# Not in a course
$env{'user.error.msg'}=
"/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course";
return HTTP_NOT_ACCEPTABLE;
}
# ----------------------------------------------------------- Permissions check
unless ((!&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) ||
(!&Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
'/'.$env{'request.course.sec'}))) {
return HTTP_NOT_ACCEPTABLE;
}
# -----------------------------Get action and calling context from query string
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','caller']);
# ----------------------------------------------------------------- Breadcrumbs
&Apache::lonhtmlcommon::clear_breadcrumbs();
if ($env{'form.caller'} eq 'email') {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/communicate',
text=>'Communication/Messages',
faq=>12,bug=>'Communication Tools',});
} else {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/parmset',
text=>'Content and Problem Settings'});
}
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/setblock',
text=>'Blocking communication/resource access'});
$r->print(&Apache::loncommon::start_page('Blocking communication/resource access').
&Apache::lonhtmlcommon::breadcrumbs('Blocking communication/resource access'));
# ----------------------------------------------------------- Permissions check
my $usertype;
my $crstype = &Apache::loncommon::course_type();
if ($crstype eq 'Community') {
$usertype = 'members';
} else {
$usertype = 'students';
}
my $lctype = lc($crstype);
my %lt=&Apache::lonlocal::texthash(
'cbds' => 'Communication blocking during scheduled exams',
'desc' => "You can use communication blocking to prevent $usertype enrolled in this $lctype from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA course or community, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.",
'mecb' => 'Modify existing communication blocking periods',
'ncbc' => 'No communication blocks currently saved',
'stor' => 'Save',
);
my %ltext = &Apache::lonlocal::texthash(
'dura' => 'Duration',
'setb' => 'Set by',
'even' => 'Event',
'blck' => 'Blocked?',
'actn' => 'Action',
'star' => 'Start',
'endd' => 'End'
);
$r->print('<h3>'.$lt{'cbds'}.'</h3>');
if ($env{'form.action'} eq 'store') {
&blockstore($r);
}
$r->print($lt{'desc'}.'<br /><br />
<form name="blockform" method="post" action="/adm/setblock?action=store">
');
$r->print('<h4>'.$lt{'mecb'}.'</h4>');
my %records = ();
my $blockcount = 0;
my $parmcount = 0;
&get_blockdates(\%records,\$blockcount);
if ($blockcount > 0) {
$parmcount = &display_blocker_status($r,\%records,\%ltext);
} else {
$r->print($lt{'ncbc'}.'<br /><br />');
}
&display_addblocker_table($r,$parmcount,\%ltext);
my $end_page=&Apache::loncommon::end_page();
$r->print(<<"END");
<br />
<input type="hidden" name="blocktotal" value="$blockcount" />
<input type ="submit" value="$lt{'stor'}" />
</form>
$end_page
END
$r->print(&Apache::loncommon::end_page());
return OK;
}
sub blockstore {
my $r = shift;
my %lt=&Apache::lonlocal::texthash(
'tfcm' => 'The following changes were made',
'ncwm' => 'No changes were made.'
);
my %adds = ();
my %removals = ();
my %cancels = ();
my $modtotal = 0;
my $canceltotal = 0;
my $addtotal = 0;
my %blocking = ();
$r->print('<h3>'.$lt{'head'}.'</h3>');
foreach my $envkey (keys(%env)) {
if ($envkey =~ m/^form\.modify_(\d+)$/) {
$adds{$1} = $1;
$removals{$1} = $1;
$modtotal ++;
} elsif ($envkey =~ m/^form\.cancel_(\d+)$/) {
$cancels{$1} = $1;
unless ( defined($removals{$1}) ) {
$removals{$1} = $1;
$canceltotal ++;
}
} elsif ($envkey =~ m/^form\.add_(\d+)$/) {
$adds{$1} = $1;
$addtotal ++;
}
}
foreach my $key (keys(%removals)) {
my $hashkey = $env{'form.key_'.$key};
&Apache::lonnet::del('comm_block',["$hashkey"],
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'}
);
}
foreach my $key (keys(%adds)) {
unless ( defined($cancels{$key}) ) {
my ($newstart,$newend) = &get_dates_from_form($key);
my $newkey = $newstart.'____'.$newend;
my $blocktypes = &get_block_choices($key);
$blocking{$newkey} = {
setter => $env{'user.name'}.':'.$env{'user.domain'},
event => &escape($env{'form.title_'.$key}),
blocks => $blocktypes,
};
}
}
if ($addtotal + $modtotal > 0) {
&Apache::lonnet::put('comm_block',\%blocking,
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'}
);
}
my $chgestotal = $canceltotal + $modtotal + $addtotal;
if ($chgestotal > 0) {
$r->print($lt{'tfcm'}.'<ul>');
if ($canceltotal > 0) {
$r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] removed.',$canceltotal).'</li>');
}
if ($modtotal > 0) {
$r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] modified.',$modtotal).'</li>');
}
if ($addtotal > 0) {
$r->print('<li>'.&mt('[quant,_1,communication blocking period was,communication blocking periods were] added.',$addtotal).'</li>');
}
$r->print('</ul>');
} else {
$r->print($lt{'ncwm'});
}
$r->print('<br />');
return;
}
sub get_dates_from_form {
my $item = shift;
my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
return ($startdate,$enddate);
}
sub get_blockdates {
my ($records,$blockcount) = @_;
$$blockcount = 0;
%{$records} = &Apache::lonnet::dump('comm_block',
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'}
);
$$blockcount = keys(%{$records});
if ((keys(%{$records}))[0] =~ /^error: 2 /) {
$$blockcount = 0;
}
}
sub get_block_choices {
my $item = shift;
my $blocklist;
my ($typeorder,$types) = &blocktype_text();
foreach my $type (@{$typeorder}) {
if ($env{'form.'.$type.'_'.$item}) {
$blocklist->{$type} = 'on';
} else {
$blocklist->{$type} = 'off';
}
}
return $blocklist;
}
sub display_blocker_status {
my ($r,$records,$ltext) = @_;
my $parmcount = 0;
my %lt = &Apache::lonlocal::texthash(
'modi' => 'Modify',
'canc' => 'Cancel',
);
my ($typeorder,$types) = &blocktype_text();
$r->print(&Apache::loncommon::start_data_table());
$r->print(<<"END");
<tr>
<th>$ltext->{'dura'}</th>
<th>$ltext->{'setb'}</th>
<th>$ltext->{'even'}</th>
<th>$ltext->{'blck'}</th>
<th>$ltext->{'actn'}</th>
</tr>
END
foreach my $record (sort(keys(%{$records}))) {
my $onchange = 'onFocus="javascript:window.document.forms['.
"'blockform'].elements['modify_".$parmcount."'].".
'checked=true;"';
my ($start,$end) = split(/____/,$record);
my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
my ($setuname,$setudom,$title,$blocks) =
&Apache::loncommon::parse_block_record($$records{$record});
$title = &HTML::Entities::encode($title,'"<>&');
my $settername =
&Apache::loncommon::aboutmewrapper(
&Apache::loncommon::plainname($setuname,$setudom),
$setuname,$setudom);
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
<td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
<td>$settername</td>
<td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td>
<td>
END
foreach my $block (@{$typeorder}) {
my $blockstatus = '';
if ($blocks->{$block} eq 'on') {
$blockstatus = 'checked="checked"';
}
$r->print('<span class="LC_nobreak"><label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label></span><br />');
}
$r->print(<<"END");
</td>
<td><span class="LC_nobreak"><label>
<input type="checkbox" name="modify_$parmcount" />$lt{'modi'}
</label></span><br /><span class="LC_nobreak">
<label>
<input type="checkbox" name="cancel_$parmcount" />$lt{'canc'}
</label></span>
END
$r->print(&Apache::loncommon::end_data_table_row());
$parmcount++;
}
$r->print(<<"END");
</table>
<br />
<br />
END
return $parmcount;
}
sub display_addblocker_table {
my ($r,$parmcount,$ltext) = @_;
my $start = time;
my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
my $onchange = 'onFocus="javascript:window.document.forms['.
"'blockform'].elements['add_".$parmcount."'].".
'checked=true;"';
my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
my %lt = &Apache::lonlocal::texthash(
'addb' => 'Add block',
'exam' => 'e.g., Exam 1',
'addn' => 'Add new communication blocking periods'
);
my ($typeorder,$types) = &blocktype_text();
$r->print(<<"END");
<h4>$lt{'addn'}</h4>
END
$r->print(&Apache::loncommon::start_data_table());
$r->print(<<"END");
<tr>
<th>$ltext->{'dura'}</th>
<th>$ltext->{'even'} $lt{'exam'}</th>
<th>$ltext->{'blck'}</th>
<th>$ltext->{'actn'}</th>
</tr>
END
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
<td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td>
<td><input type="text" name="title_$parmcount" size="15" value="" /></td>
<td>
END
foreach my $block (@{$typeorder}) {
$r->print('<span class="LC_nobreak"><label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label></span><br />');
}
$r->print(<<"END");
</td>
<td><span class="LC_nobreak"><label>
<input type="checkbox" name="add_$parmcount" value="1" />$lt{'addb'}
</label></span></td>
END
$r->print(&Apache::loncommon::end_data_table_row());
$r->print(&Apache::loncommon::end_data_table());
return;
}
sub blocktype_text {
my %types = &Apache::lonlocal::texthash(
'com' => 'Messaging',
'chat' => 'Chat Room',
'boards' => 'Discussion',
'port' => 'Portfolio',
'groups' => 'Groups',
'blogs' => 'Blogs',
);
my $typeorder = ['com','chat','boards','port','groups','blogs'];
return ($typeorder,\%types);
}
1;
__END__
More information about the LON-CAPA-cvs
mailing list