[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface courseprefs.pm

raeburn raeburn at source.lon-capa.org
Mon Jun 9 16:36:57 EDT 2014


raeburn		Mon Jun  9 20:36:57 2014 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	courseprefs.pm 
  Log:
  - For 2.11
    - Backport 1.66.
  
  
-------------- next part --------------
Index: loncom/interface/courseprefs.pm
diff -u loncom/interface/courseprefs.pm:1.49.2.13 loncom/interface/courseprefs.pm:1.49.2.14
--- loncom/interface/courseprefs.pm:1.49.2.13	Fri May 16 19:19:01 2014
+++ loncom/interface/courseprefs.pm	Mon Jun  9 20:36:56 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.49.2.13 2014/05/16 19:19:01 raeburn Exp $
+# $Id: courseprefs.pm,v 1.49.2.14 2014/06/09 20:36:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -215,10 +215,14 @@
 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 @@
     }
     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 @@
         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 @@
     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 @@
     }
     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 {
@@ -2285,6 +2300,7 @@
 
 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,21 @@
                                            '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 .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
-                              $checkcrstypes{$crstype}).'</h4>';
+                              $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
     }
     my (%fromparam,%rowspan,%bymap,%byresource, at scopeorder,%toshow,%allmaps,
-        %byresponsetype,%bysubmission);
+        %byresponsetype,%bysubmission,%fromblocks);
     @scopeorder = ('all','section/group','user');
     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)) {
@@ -2319,7 +2334,7 @@
                              }
                          }
                          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 +2426,9 @@
                        '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
                        &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().
                             '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
                 my $newrow;
@@ -2441,6 +2459,75 @@
         }
     }
 
+    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 .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
+                       &Apache::loncommon::start_data_table().
+                       &Apache::loncommon::start_data_table_header_row().
+                       '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
+                       '<th>'.&mt('Event(s)').'</th>'.
+                       &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().
+                                   '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
+                        foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
+                            $output .= $event.'<br />';
+                        }
+                        $output =~ s{\Q<br />\E$}{};
+                        $output .= '</td>'.&Apache::loncommon::end_data_table_row();
+                    }
+                }
+            }
+            $output .= &Apache::loncommon::end_data_table().'<br />';
+        }
+    }
+
     if (defined($navmap)) {
         my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
         my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'};
@@ -2450,7 +2537,7 @@
         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 +2554,13 @@
                         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 +2573,27 @@
                         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 +2654,10 @@
                   '</p>'); 
     }
     $r->print(&Apache::loncommon::end_page());
+    my ($currmajor,$currminor) = split(/\./,$loncaparev);
+    if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
+        return 1;
+    }
     return;
 }
 
@@ -2686,6 +2799,7 @@
         }
         $r->print(&Apache::loncommon::end_data_table());
     }
+    return;
 }
 
 sub releases_by_map {
@@ -2739,6 +2853,24 @@
     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 = '<i><span class="LC_nobreak">'.&mt('Co-ownership is set automatically when a Course Coordinator role[_1] is assigned to official course personnel (from institutional data).','</span><br /><span class="LC_nobreak">').'</span></i>';


More information about the LON-CAPA-cvs mailing list