--- loncom/interface/lonblockingmenu.pm 2014/02/28 19:20:05 1.11 +++ loncom/interface/lonblockingmenu.pm 2014/06/07 19:13:42 1.12 @@ -2,7 +2,7 @@ # Routines for configuring blocking of access to collaborative functions, # and specific resources during an exam # -# $Id: lonblockingmenu.pm,v 1.11 2014/02/28 19:20:05 bisitz Exp $ +# $Id: lonblockingmenu.pm,v 1.12 2014/06/07 19:13:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -57,6 +57,9 @@ into this category. (b) those which a student could use to access materials prepared by the student in advance of an exam, (e.g., for use during an online exam, to gain an unfair advantage). Blogs and portfolio fall into this category. +(c) those which a student could use to display or save content within +the course itself (outside the exam folder). Printouts and resources +fall into this category. For communication blocking to be truly effective in preventing unwanted communication, or access to online materials, online testing needs to @@ -64,7 +67,7 @@ take place in a lab setting where use of of web sites beyond LON-CAPA are unavailable. Access to specified folder(s) and/or resources in the course contents -can also be restricted for the duration of an exam. +can be restricted for the duration of an exam. Exam blocks are of two types: (a) Blocks with a defined start and end date. @@ -124,11 +127,15 @@ Output: 1 Hash Stores changes to exam blocks in comm_block.db file for course. Processes deletions, modifications and additions. -Inputs: 2 +Inputs: 4 + $r = request object + $crstype - Container type: Course or Community. $blockcount - Total number of blocking events in course. + $currblockrecs - Ref to hash of current blocks in course. + Outputs: 2 $changestotal - Total number of changes made. @@ -160,7 +167,7 @@ Side Effects: populates records hashref. =item &get_block_choices() Extract information from web form about which communication/ -collaboration features are to be blocked, for a partilcuar event, +collaboration features are to be blocked, for a particular event, and also which content areas will have access blocked for the duration of the block. @@ -184,12 +191,30 @@ Update LON-CAPA version requirements for (content) or blocking type (triggered by student starting timer) require specific LON-CAPA version (i.e., 2.11). -Inputs: 1 - type of constraint (currently: 'docs' or 'timer'). +Inputs: 3 - $value - type of constraint (currently: 'docs', 'printout' or 'timer'), + $chomemajor - course's home server LON-CAPA major version number. + $chomeminor - course's home server LON-CAPA minor version number. -Outputs: None +Outputs: 2 - status ('ok' or 'fail') and LON-CAPA version needed. + +=over + + A status of 'fail' will be returned if the + LON-CAPA version installed on the course's + home server is older than the version + requirement for the blocking type. + For a trigger type event, the requested + blocking event will not be added if + the course's home server version is old to + support that type of block. + +=back Side Effects: &update_released_required() called in lonnet, if - needed to update version requirements for course. + course's home server version is requied version or + newer; will update version requirements for course to + a more recent version requirement than currently in + effect. =item &display_blocker_status() @@ -337,7 +362,8 @@ Output: 2 Create Javascript used to launch pop-up used for content selection, and to toggle visibility of a number of expandable/collapsible divs. -Inputs: 1 - $blockcount - +Inputs: 1 - $blockcount - Total number of blocks in course's comm_block.db + database file. Output: 1 - Javascript (with tags) for functions used to: (a) launch pop-up window for selection of course content to which @@ -373,6 +399,9 @@ use Apache::lonlocal; use lib '/home/httpd/lib/perl/'; use LONCAPA qw(:DEFAULT :match); +my $registered_cleanup; +my $modified_courses; + sub handler { my $r=shift; @@ -403,6 +432,9 @@ sub handler { # -----------------------------Get action and calling context from query string + $registered_cleanup=0; + @{$modified_courses}=(); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['action','caller','block']); @@ -449,7 +481,7 @@ sub handler { # -------------------------- Store changes and retrieve latest block information my $storeresult; if ($env{'form.action'} eq 'store') { - (my $numchanges,$storeresult) = &blockstore($crstype,$blockcount); + (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records); if ($numchanges > 0) { $blockcount = &get_blockdates(\%records); } @@ -629,7 +661,7 @@ sub get_timed_items { } sub blockstore { - my ($crstype,$blockcount) = @_; + my ($r,$crstype,$blockcount,$currblockrecs) = @_; my %lt=&Apache::lonlocal::texthash( 'tfcm' => 'The following changes were made', 'ncwm' => 'No changes were made.', @@ -671,16 +703,42 @@ sub blockstore { return ($changestotal,$output); } &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock'); + my $do_releasereq_update; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; + my $chostname = &Apache::lonnet::hostname($chome); + my ($chomemajor,$chomeminor) = + split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome)); + + 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'} - ); + if ($hashkey =~ /firstaccess____/) { + $do_releasereq_update = 1; + } + if (ref($currblockrecs->{$hashkey}) eq 'HASH') { + if (ref($currblockrecs->{$hashkey}->{'blocks'}) eq 'HASH') { + foreach my $type ('docs','printout') { + if (exists($currblockrecs->{$hashkey}->{'blocks'}->{$type})) { + $do_releasereq_update = 1; + } + } + } + } + &Apache::lonnet::del('comm_block',["$hashkey"],$cdom,$cnum); + } + if ($do_releasereq_update) { + push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]); + unless ($registered_cleanup) { + my $handlers = $r->get_handlers('PerlCleanupHandler'); + $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]); + $registered_cleanup=1; + } } foreach my $key (keys(%adds)) { unless ( defined($cancels{$key}) ) { - my $newkey; + my ($newkey,$status,$needsrelease);; if ($env{'form.firstaccess_'.$key}) { my $interval = &HTML::Entities::decode($env{'form.firstaccess_'.$key}); @@ -698,7 +756,13 @@ sub blockstore { } if ($newkey ne '') { unless (defined($removals{$key})) { - $addtimer ++; + ($status,$needsrelease) = &check_release_required('timer',$chomemajor,$chomeminor); + if ($status eq 'fail') { + $newkey = ''; + $output .= '

'. + &mt('Triggering of blocking events not allowed for [_1]', + &escape($env{'form.title_'.$key})).'
'; + } } } } @@ -706,22 +770,38 @@ sub blockstore { my ($newstart,$newend) = &get_dates_from_form($key); $newkey = $newstart.'____'.$newend; } + if ($status eq 'fail') { + $output .= &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).', + $chomemajor.'.'.$chomeminor,$chostname,$needsrelease).'

'; + } if ($newkey ne '') { my ($blocktypes,$blockdocs) = &get_block_choices($key,\%map_url,\%resource_symb); + if (ref($blocktypes) eq 'HASH') { + if ($blocktypes->{'printout'} eq 'on') { + ($status,$needsrelease) = &check_release_required('printout',$chomemajor,$chomeminor); + if ($status eq 'fail') { + $blocktypes->{'printout'} = 'off'; + $output .= '

'. + &mt('Printout blocking not allowed for [_1]', + &escape($env{'form.title_'.$key})).'
'; + } + } + } + if ($blockdocs) { + ($status,$needsrelease) = &check_release_required('docs',$chomemajor,$chomeminor); + if ($status eq 'fail') { + delete($blocktypes->{'docs'}); + $output .= '

'. + &mt('Content blocking not allowed for [_1]', + &escape($env{'form.title_'.$key})).'
'; + } + } $blocking{$newkey} = { setter => $env{'user.name'}.':'.$env{'user.domain'}, event => &escape($env{'form.title_'.$key}), blocks => $blocktypes, }; - if ($blockdocs) { - &check_release_required('docs'); - } - if (ref($blocktypes) eq 'HASH') { - if ($blocktypes->{'printout'} eq 'on') { - &check_release_required('printout'); - } - } if (exists($removals{$key})) { $modtotal ++; } else { @@ -729,9 +809,11 @@ sub blockstore { } } else { if ($env{'form.toggle_'.$key} eq 'timer') { - $output .= '

'. - &mt('Invalid trigger for new blocking event'). - '

'; + unless ($status eq 'fail') { + $output .= '

'. + &mt('Invalid trigger for new blocking event'). + '

'; + } } else { $output .= '

'. &mt('No date range found for new blocking event'). @@ -745,9 +827,6 @@ sub blockstore { $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'} ); - if ($addtimer) { - &check_release_required('timer'); - } } $changestotal = $canceltotal + $modtotal + $addtotal; if ($changestotal > 0) { @@ -780,6 +859,24 @@ sub blockstore { return ($changestotal,$output); } +sub update_releasereq { + my $readmap = 1; + my $getrelreq = 1; + if (ref($modified_courses) eq 'ARRAY') { + foreach my $item (@{$modified_courses}) { + if (ref($item) eq 'ARRAY') { + my ($cdom,$cnum,$chome,$crstype) = @{$item}; + &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom, + $chome,$crstype,$cdom.'_'.$cnum, + $readmap,$getrelreq); + } + } + $modified_courses = []; + } + undef($registered_cleanup); + return; +} + sub get_dates_from_form { my $item = shift; my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item); @@ -846,10 +943,15 @@ sub get_block_choices { } sub check_release_required { - my ($value) = @_; + my ($value,$chomemajor,$chomeminor) = @_; my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value}; if ($needsrelease) { - my $curr_required = + my ($needsmajor,$needsminor) = split(/\./,$needsrelease); + if (($chomemajor < $needsmajor) || + (($chomemajor == $needsmajor) && ($chomeminor < $needsminor))) { + return ('fail',$needsrelease); + } + my $curr_required = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'}; if ($curr_required eq '') { &Apache::lonnet::update_released_required($needsrelease); @@ -862,7 +964,7 @@ sub check_release_required { } } } - return; + return ('ok',$needsrelease); } sub display_blocker_status {