[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm lonparmset.pm lonprintout.pm printout.pl

foxr foxr@source.lon-capa.org
Wed, 18 May 2011 11:26:45 -0000


This is a MIME encoded message

--foxr1305718005
Content-Type: text/plain

foxr		Wed May 18 11:26:45 2011 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm lonparmset.pm lonprintout.pm 
                     	printout.pl 
  Log:
  Only run the gs postscript cleanup if some PDF's were included in the 
  printout.  Purpose of this is to improve printout quality when PDF's
  are not included.
  
  
--foxr1305718005
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20110518112645.txt"

Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.458 loncom/interface/lonnavmaps.pm:1.459
--- loncom/interface/lonnavmaps.pm:1.458	Mon Mar 14 15:48:00 2011
+++ loncom/interface/lonnavmaps.pm	Wed May 18 11:26:44 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.458 2011/03/14 15:48:00 bisitz Exp $
+# $Id: lonnavmaps.pm,v 1.459 2011/05/18 11:26:44 foxr Exp $
 
 #
 # Copyright Michigan State University Board of Trustees
@@ -483,7 +483,7 @@
 use Time::HiRes qw( gettimeofday tv_interval );
 use LONCAPA;
 use DateTime();
-
+use Data::Dumper;
 # symbolic constants
 sub SYMB { return 1; }
 sub URL { return 2; }
@@ -2399,7 +2399,7 @@
     my $self = shift;
     my ($what,$symb,$recurse)=@_;
     my $hashkey = $what."|||".$symb;
-
+    my $cache = $self->{PARM_CACHE};
     if (defined($self->{PARM_CACHE}->{$hashkey})) {
         if (ref($self->{PARM_CACHE}->{$hashkey}) eq 'ARRAY') { 
             if (defined($self->{PARM_CACHE}->{$hashkey}->[0])) {
@@ -2414,6 +2414,7 @@
         }
     }
     my $result = $self->parmval_real($what, $symb, $recurse);
+    my $dumper = Data::Dumper->new([$result]);
     $self->{PARM_CACHE}->{$hashkey} = $result;
     if (wantarray) {
         return @{$result};
@@ -3743,9 +3744,7 @@
 sub is_incomplete {
     my $self = shift;
     if ($self->is_problem()) {
-	&Apache::lonnet::logthis('is problem');
 	foreach my $part (@{$self->parts()}) {
-	    &Apache::lonnet::logthis("$part status ".$self->status($part));
 	    if (exists($incomplete_hash{$self->status($part)})) {
 		return 1;
 	    }
@@ -3930,7 +3929,17 @@
 
 =over 4
 
-=item * B<acc>:
+=item * B<printable>
+
+returns true if the current date is such that the 
+specified resource part is printable.
+
+=item * B<resprintable>
+
+Returns true if all parts in the resource are printable making the
+entire resource printable.
+
+=item * B<acc>
 
 Get the Client IP/Name Access Control information.
 
@@ -3983,6 +3992,54 @@
 
 =cut
 
+sub printable {
+
+    &Apache::lonnet::logthis("Printable");
+    my ($self, $part) = @_;
+
+    # Get the print open/close dates for the resource.
+
+    my $start = $self->parmval("printopendate", $part);
+    my $end   = $self->parmval("printclosedate", $part);
+    my $dumper = Data::Dumper->new([$self, $part, $start, $end]);
+    &Apache::lonnet::logthis("Start for " . $dumper->Dump);
+
+    #  The following cases apply:
+    #  - No dates set: Printable.
+    #  - Start date set but no end date: Printable if now >= start date.
+    #  - End date set but no start date: Printable if now <= end date.
+    #  - both defined: printable if start <= now <= end
+    #
+    my $now  = time();
+
+    my $startok = 1;
+    my $endok   = 1;
+
+    if ($start ne '') {
+	$startok = $start <= $now;
+    }
+    if ($end  ne '') {
+	$endok = $end >= $now;
+    }
+    return $startok && $endok;
+}
+
+sub resprintable {
+    my $self = shift;
+
+    # get parts...or realize there are no parts.
+
+    my $parts = $self->parts();
+    if ($parts == 0) {
+	return $self->printable(0);
+    } else {
+	foreach my $part  (@$parts) {
+	    if (!$self->printable($part)) { return 0; }
+	}
+	return 1;
+    }
+}
+
 sub acc {
     (my $self, my $part) = @_;
     my $acc = $self->parmval("acc", $part);
@@ -4035,6 +4092,11 @@
     }
 }
 # this should work exactly like the copy in lonhomework.pm
+# Why is there a copy in lonhomework?  Why not centralized?
+#
+#  TODO: Centralize duedate.
+#
+
 sub duedate {
     (my $self, my $part) = @_;
     my $date;
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.511 loncom/interface/lonparmset.pm:1.512
--- loncom/interface/lonparmset.pm:1.511	Fri Mar 11 02:39:53 2011
+++ loncom/interface/lonparmset.pm	Wed May 18 11:26:44 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.511 2011/03/11 02:39:53 www Exp $
+# $Id: lonparmset.pm,v 1.512 2011/05/18 11:26:44 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -137,33 +137,41 @@
 
 =item extractResourceInformation() : 
 
-Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
+ extractResourceInformation extracts lots of information about all of the the course's resources into a variety of hashes.
 
 Input: See list below:
 
-=item * B<ids> : An array that will contain all of the ids in the course.
+=item * B<env{'user.name'}> : Current username
 
-=item * B<typep> : hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
+=item * B<env{'user.domain'}> : Domain of current user.
 
-=item * B<keyp> : hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
+=item * b<env{"request.course.fn"} : Course
 
-=item * B<allparms> : hash, name of parameter->display value (what is the display value?)
+Outputs: See list below:
 
-=item * B<allparts> : hash, part identification->text representation of part, where the text representation is "[Part $part]"
+=item * B<ids> (out) : An array that will contain all of the ids in the course.
 
-=item * B<allkeys> : hash, full key to part->display value (what's display value?)
+=item * B<typep>(out) : hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
 
-=item * B<allmaps> : hash, ???
+=item * B<keyp> (out) : hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
 
-=item * B<fcat> : ???
+=item * B<allparms> (out) : hash, name of parameter->display value (what is the display value?)
 
-=item * B<defp> : hash, ???
+=item * B<allparts> (out) : hash, part identification->text representation of part, where the text representation is "[Part $part]"
+
+=item * B<allmaps> (out) : hash, ???
 
 =item * B<mapp> : ??
 
 =item * B<symbp> : hash, id->full sym?
 
+=item * B<maptitles>
+
+=item * B<uris>
 
+=item * B<keyorder>
+
+=item * B<defkeytype>
 
 =item isdateparm()
 
@@ -1165,6 +1173,9 @@
         $$typep{$id}=$1;
         $$keyp{$id}='';
         $$uris{$id}=$srcf;
+	&Apache::lonnet::logthis("Invoking metadata $srcf");
+	&Apache::lonnet::logthis(&Apache::lonnet::metadata($srcf, 'allpossiblekeys'));
+
         foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
             next if ($key!~/^parameter_/);
 
@@ -1353,6 +1364,8 @@
         'contentopen' => 'time_settings',
         'contentclose' => 'time_settings',
         'discussend' => 'time_settings',
+	'printopendate' => 'time_settings',
+	'printclosedate' => 'time_settings',
         'weight' => 'grading',
         'handgrade' => 'grading',
         'maxtries' => 'tries',
@@ -1932,7 +1945,9 @@
         'parameter_0_sig' => 17,
         'parameter_0_turnoffunit' => 18,
             'parameter_0_discussend' => 19,
-            'parameter_0_discusshide' => 20);
+            'parameter_0_discusshide' => 20,
+	'parameter_0_printopendate'  =>  21,
+	'parameter_0_printclosedate' =>  22);
 }
 
 
@@ -1940,6 +1955,9 @@
 
     my $r=shift;
 
+
+
+# -------------------------------------------------------- Variable declaration
     my @ids=();
     my %symbp=();
     my %mapp=();
@@ -1947,9 +1965,6 @@
     my %keyp=();
     my %uris=();
     my %maptitles=();
-
-# -------------------------------------------------------- Variable declaration
-
     my %allmaps=();
     my %alllevs=();
 
@@ -1968,14 +1983,16 @@
 
     my %allparms;
     my %allparts;
+# ------------------------------------------------------------------------------
+
 #
 # Order in which these parameters will be displayed
 #
     my %keyorder=&standardkeyorder();
 
-    @ids=();
-    %symbp=();
-    %typep=();
+#    @ids=();
+#    %symbp=();       # These seem defined above already.
+#    %typep=();
 
     my $message='';
 
@@ -2097,6 +2114,8 @@
         my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
         my ($got_chostname,$chostname,$cmajor,$cminor);
         my $totalstored = 0;
+
+
         for (my $i=0;$i<=$#markers;$i++) {
             my ($needsrelease,$needsnewer);
             if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3)$/) {
@@ -2425,7 +2444,6 @@
                     my $uri=&Apache::lonnet::declutter($uris{$rid});
 
                     my $filter=$env{'form.filter'};
-
                     foreach (&keysplit($keyp{$rid})) {
                         my $tempkeyp = $_;
                         if (grep $_ eq $tempkeyp, @catmarker) {
@@ -2480,8 +2498,8 @@
                         $r->print('<td style="background-color:'.$defbgone.';"'.
                                       ' rowspan='.$totalparms.
                                       '>'.$maptitles{$mapp{$rid}}.'</td>');
-
                         foreach (&keysinorder_bytype(\%name,\%keyorder)) {
+
                             unless ($firstrow) {
                                 $r->print('<tr>');
                             } else {
@@ -3549,7 +3567,8 @@
               '<table><tr><td>'.&mt('Currently set date:').'</td><td>'.
               &Apache::lonlocal::locallocaltime($env{'form.timebase'}).'</td></tr>'.
               '<tr><td>'.&mt('Shifted date:').'</td><td>'.
-                    &Apache::lonhtmlcommon::date_setter('shiftform',
+                    &Apache::lonhtmlcommon::dshowerfuck.net
+ate_setter('shiftform',
                                                         'timeshifted',
                                                         $env{'form.timebase'},,
                                                         '').
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.587 loncom/interface/lonprintout.pm:1.588
--- loncom/interface/lonprintout.pm:1.587	Mon Apr 25 16:59:54 2011
+++ loncom/interface/lonprintout.pm	Wed May 18 11:26:44 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.587 2011/04/25 16:59:54 foxr Exp $
+# $Id: lonprintout.pm,v 1.588 2011/05/18 11:26:44 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,6 +52,7 @@
 use Carp;
 use LONCAPA;
 
+
 my %perm;
 my %parmhash;
 my $resources_printed;
@@ -3403,13 +3404,13 @@
     }
 
     # Useful filter strings
-    my $isProblem = '($res->is_problem()||$res->contains_problem||$res->is_practice()) ';
+    my $isProblem = '(($res->is_problem()||$res->contains_problem||$res->is_practice())) && $res->resprintable() ';
     $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
-    my $isProblemOrMap = '$res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice()';
-    my $isNotMap = '!$res->is_sequence()';
+    my $isProblemOrMap = '($res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice()) && $res->resprintable()';
+    my $isNotMap = '(!$res->is_sequence()) && $res->resprintable()';
     $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
-    my $isMap = '$res->is_map()';
-    my $symbFilter = '$res->shown_symb()';
+    my $isMap = '$res->is_map() && $res->resprintable()';
+    my $symbFilter = '$res->shown_symb() && $res->resprintable()';
     my $urlValue = '$res->link()';
 
     $helper->declareVar('SEQUENCE');
Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.148 loncom/interface/printout.pl:1.149
--- loncom/interface/printout.pl:1.148	Tue Apr 26 10:47:25 2011
+++ loncom/interface/printout.pl	Wed May 18 11:26:44 2011
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
 #
-# $Id: printout.pl,v 1.148 2011/04/26 10:47:25 foxr Exp $
+# $Id: printout.pl,v 1.149 2011/05/18 11:26:44 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -44,7 +44,7 @@
 use strict;
 
 my $busy_wait_timeout = 30; 
-
+my $pdfs_converted    = 0;	# non zero if PDF includes (need to fixps).
 
 my $debugging = 0;
 
@@ -490,15 +490,18 @@
 #  The code below uses gs to make pdf includes in sequences work
 
 	      # Use gs to fix the postscript -> level 1.5 
+	      # .. if pdfs were included
 
-	      $comma = "gs -sDEVICE=pswrite -dLanguageLevel=1.5 ";
-	      &busy_wait_command("$comma -o $tempo_file $new_name_file 2>/dev/null 1>/dev/null",
-				 "for $status_statement now validating PS",
-				 \%prog_state, $tempo_file);
-
+	      if ($pdfs_converted > 0) {
+		  $comma = "gs -sDEVICE=pswrite -dLanguageLevel=1.5 ";
+		  &busy_wait_command("$comma -o $tempo_file $new_name_file 2>/dev/null 1>/dev/null",
+				     "for $status_statement now validating PS",
+				     \%prog_state, $tempo_file);
+		  
 #---
-	      &busy_wait_command("mv $tempo_file $new_name_file",
-				 'File move', \%prog_state, $new_name_file);
+		  &busy_wait_command("mv $tempo_file $new_name_file",
+				     'File move', \%prog_state, $new_name_file);
+	      }
 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
 		  $comma = "psnup $papera -2 -s1.0 $new_name_file";
 		  &debug("PSNUP command: $comma");
@@ -948,6 +951,7 @@
 
 	    &debug("Converting pdf $not_eps to postscript: $eps_f");
 	    system("pdftops $not_eps $eps_f");
+	    $pdfs_converted++;	# Need to fix ps in last pass.
 	} else {
 	    system("convert $not_eps $eps_f");
         if($? and $advanced_role){

--foxr1305718005--