--- loncom/interface/courseprefs.pm 2013/12/27 15:06:40 1.49.2.12
+++ loncom/interface/courseprefs.pm 2014/06/13 02:03:41 1.49.2.15
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set configuration settings for a course
#
-# $Id: courseprefs.pm,v 1.49.2.12 2013/12/27 15:06:40 raeburn Exp $
+# $Id: courseprefs.pm,v 1.49.2.15 2014/06/13 02:03:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -215,10 +215,14 @@ use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::lonconfigsettings;
+use Apache::lonrelrequtils;
use Apache::lonparmset;
use Apache::lonlocal;
use LONCAPA qw(:DEFAULT :match);
+my $registered_cleanup;
+my $modified_courses;
+
sub handler {
my $r=shift;
if ($r->header_only) {
@@ -228,7 +232,7 @@ sub handler {
}
my $context = 'course';
my $cid = $env{'request.course.id'};
- my ($cnum,$cdom) = &get_course($cid);
+ my ($cnum,$cdom,$chome) = &get_course($cid);
my $crstype = &Apache::loncommon::course_type();
my $parm_permission = &Apache::lonnet::allowed('opa',$cid);
my $navmap = Apache::lonnavmaps::navmap->new();
@@ -257,6 +261,9 @@ sub handler {
return HTTP_NOT_ACCEPTABLE;
}
+ $registered_cleanup=0;
+ @{$modified_courses}=();
+
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['phase','actions','origin']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -344,7 +351,14 @@ sub handler {
if ($phase eq 'releaseinfo') {
my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
if ($loncaparev) {
- &display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype);
+ if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
+ 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;
+ }
+ }
return OK;
}
}
@@ -1663,7 +1677,8 @@ sub get_course {
}
my $cdom=$env{'course.'.$courseid.'.domain'};
my $cnum=$env{'course.'.$courseid.'.num'};
- return ($cnum,$cdom);
+ my $chome=$env{'course.'.$courseid.'.home'};
+ return ($cnum,$cdom,$chome);
}
sub get_jscript {
@@ -2056,7 +2071,7 @@ sub print_courseinfo {
my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
my $clonedfrom = &mt('None');
if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
- my %clonesrcinfo = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
+ my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
if ($clonesrcinfo{'description'}) {
$clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
}
@@ -2285,6 +2300,7 @@ ENDSCRIPT
sub display_loncaparev_constraints {
my ($r,$navmap,$loncaparev,$crstype) = @_;
+ my ($reqdmajor,$reqdminor);
my $cid = $env{'request.course.id'};
my $cdom = $env{'course.'.$cid.'.domain'};
my $cnum = $env{'course.'.$cid.'.num'};
@@ -2294,22 +2310,22 @@ sub display_loncaparev_constraints {
'section/group' => 'section/group',
'user' => 'user',
);
- my (%checkparms,%checkresponsetypes,%checkcrstypes,%anonsurvey,%randomizetry);
- &Apache::loncommon::build_release_hashes(\%checkparms,\%checkresponsetypes,
- \%checkcrstypes,\%anonsurvey,\%randomizetry);
- if (defined($checkcrstypes{$crstype})) {
+ &Apache::lonrelrequtils::init_global_hashes();
+ if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
+ ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
$output .= '
'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
- $checkcrstypes{$crstype}).'
';
+ $Apache::lonrelrequtils::checkcrstypes{$crstype}).'';
}
my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
- %byresponsetype,%bysubmission);
+ %byresponsetype,%bysubmission,%fromblocks);
@scopeorder = ('all','section/group','user');
+ my $now = time;
my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
if (ref($resourcedata) eq 'HASH') {
foreach my $key (keys(%{$resourcedata})) {
- foreach my $item (keys(%checkparms)) {
+ foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
if ($key =~ /(\Q$item\E)$/) {
- if (ref($checkparms{$item}) eq 'ARRAY') {
+ if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
my $value = $resourcedata->{$key};
if ($item eq 'examcode') {
if (&Apache::lonnet::validCODE($value)) {
@@ -2317,9 +2333,22 @@ sub display_loncaparev_constraints {
} else {
$value = '';
}
+ } elsif ($item eq 'printstartdate') {
+ if ($value =~ /^\d+$/) {
+ if ($value > $now) {
+ $value = 'future';
+ }
+ }
+ } elsif ($item eq 'printenddate') {
+ if ($value =~ /^\d+$/) {
+ if ($value < $now) {
+ $value = 'past';
+ }
+ }
+
}
my ($middle,$scope,$which,$level,$map,$resource);
- if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) {
+ if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
my $stdname = &Apache::lonparmset::standard_parameter_names($item);
my $valname = &get_param_description($stdtype,$value);
@@ -2411,6 +2440,9 @@ sub display_loncaparev_constraints {
''.&mt('Extent').' | '.&mt('Setting').' | '.
&Apache::loncommon::end_data_table_header_row();
foreach my $rev (keys(%fromparam)) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
$output .= &Apache::loncommon::start_data_table_row().
''.$rev.' | ';
my $newrow;
@@ -2441,6 +2473,75 @@ sub display_loncaparev_constraints {
}
}
+ my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
+ my $now = time;
+ if (keys(%comm_blocks) > 0) {
+ foreach my $block (keys(%comm_blocks)) {
+ if ($block =~ /^firstaccess____(.+)$/) {
+ my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
+ if (ref($comm_blocks{$block}) eq 'HASH') {
+ push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
+ ' '.&mt('set by [_1]',
+ &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
+ }
+ next;
+ } elsif ($block =~ /^(\d+)____(\d+)$/) {
+ my ($start,$end) = ($1,$2);
+ next if ($end < $now);
+ }
+ if (ref($comm_blocks{$block}) eq 'HASH') {
+ if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
+ if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
+ if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
+ my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
+ push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
+ ' '.
+ &mt('set by [_1]',
+ &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
+ }
+ } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
+ my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
+ push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
+ ' '.
+ &mt('set by [_1]',
+ &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
+
+ }
+ }
+ }
+ }
+ if (keys(%fromblocks)) {
+ my %lt = (
+ docs => 'Content blocking',
+ printout => 'Printout generation',
+ timer => 'Timed quiz trigger',
+ );
+ $output .= ''.&mt('Requirements from exam blocking').'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Release').' | '.&mt('Setting').' | '.
+ ''.&mt('Event(s)').' | '.
+ &Apache::loncommon::end_data_table_header_row();
+ foreach my $type ('docs','printout','timer') {
+ if (ref($fromblocks{$type}) eq 'HASH') {
+ foreach my $rev (keys(%{$fromblocks{$type}})) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
+ $output .= &Apache::loncommon::start_data_table_row().
+ ''.$rev.' | '.$lt{$type}.' | ';
+ foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
+ $output .= $event.' ';
+ }
+ $output =~ s{\Q \E$}{};
+ $output .= ' | '.&Apache::loncommon::end_data_table_row();
+ }
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table().'
';
+ }
+ }
+
if (defined($navmap)) {
my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'};
@@ -2450,7 +2551,7 @@ sub display_loncaparev_constraints {
my $stdname=&Apache::lonparmset::standard_parameter_names('type');
my $valanon=&get_param_description($stdtype,'anonsurvey');
my $valrandtry=&get_param_description($stdtype,'randomizetry');
-
+ my %checkedrev;
foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
my @parts = @{$res->parts()};
my $symb = $res->symb();
@@ -2467,6 +2568,13 @@ sub display_loncaparev_constraints {
push(@{$bysubmission{$symb}{$rev}},$what);
}
$allmaps{$enclosing_map} = 1;
+ unless ($checkedrev{'anonsurvey'}) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
+ $reqdmajor,$reqdminor);
+ $checkedrev{'anonsurvey'} = 1;
+ }
}
if (exists($randtrysubms{$symb."\0".$part})) {
my $rev = $rev_randtry;
@@ -2479,12 +2587,27 @@ sub display_loncaparev_constraints {
push(@{$bysubmission{$symb}{$rev}},$what);
}
$allmaps{$enclosing_map} = 1;
+ unless ($checkedrev{'randomizetry'}) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
+ $reqdmajor,$reqdminor);
+ $checkedrev{'randomizetry'} = 1;
+ }
}
}
my %responses = $res->responseTypes();
foreach my $key (keys(%responses)) {
- if (exists($checkresponsetypes{$key})) {
- push(@{$byresponsetype{$symb}{$checkresponsetypes{$key}}},$key);
+ if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
+ my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
+ unless ($checkedrev{$key}) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
+ $reqdmajor,$reqdminor);
+ $checkedrev{$key} = 1;
+ }
+ push(@{$byresponsetype{$symb}{$rev}},$key);
$allmaps{$enclosing_map} = 1;
}
}
@@ -2545,6 +2668,10 @@ sub display_loncaparev_constraints {
'');
}
$r->print(&Apache::loncommon::end_page());
+ my ($currmajor,$currminor) = split(/\./,$loncaparev);
+ if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
+ return 1;
+ }
return;
}
@@ -2686,6 +2813,7 @@ sub show_contents_view {
}
$r->print(&Apache::loncommon::end_data_table());
}
+ return;
}
sub releases_by_map {
@@ -2739,6 +2867,24 @@ sub get_param_description {
return $name;
}
+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 show_autocoowners {
my (@currcoown) = @_;
my $output = ''.&mt('Co-ownership is set automatically when a Course Coordinator role[_1] is assigned to official course personnel (from institutional data).','
').'';