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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 17 Feb 2004 00:26:20 -0000


This is a MIME encoded message

--albertel1076977580
Content-Type: text/plain

albertel		Mon Feb 16 19:26:20 2004 EDT

  Modified files:              
    /loncom/interface	printout.pl lonprintout.pm 
  Log:
  - generally cleaning the printout screens up
  
  - lonprintout.pm
      - printout files have shorter unique names
      - printout files when doing multiple  students are all sequentially numbered
      - cgi ids use loncommon's get_cgi_id
  
  - printout.pl
      - only request.role.adv users get popup status windows
      - turn on autoflush
      - only update the conversion popup if actually converting
      - use a pretty version of the image name when updating the progress window
      - use updated counting system for multiple output files
      - Updated the English on the various status outputs to read better (probably need more help still)
      - <pre> the zip output
       
  - yeah I probably should have made some of these seperate commits
  
  
--albertel1076977580
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040216192620.txt"

Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.48 loncom/interface/printout.pl:1.49
--- loncom/interface/printout.pl:1.48	Mon Feb 16 17:32:59 2004
+++ loncom/interface/printout.pl	Mon Feb 16 19:26:20 2004
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
 #
-# $Id: printout.pl,v 1.48 2004/02/16 22:32:59 albertel Exp $
+# $Id: printout.pl,v 1.49 2004/02/17 00:26:20 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -34,7 +34,7 @@
 use Image::Magick;
 use Apache::lonhtmlcommon;
 
-
+$|=1;
 my %origENV=%ENV;
 if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
     print <<END;
@@ -66,6 +66,8 @@
   my $student_names = $ENV{'cgi.'.$identifier.'studentnames'};
   my $backref = $ENV{'cgi.'.$identifier.'backref'};
 
+  my $adv = $ENV{'request.role.adv'};
+  
   my @names_pack=();
   if ($student_names=~/_END_/) {  
       @names_pack=split(/_ENDPERSON_/,$student_names);
@@ -84,11 +86,12 @@
       my @content_of_file = <$temporary_file>;
       close $temporary_file;  
       my $noteps;
-      my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Pictures CreationPrint Status','Pictires Status window',$#content_of_file);
+      my %prog_state;
+      if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Coverting Images to EPS','Picture Conversion Status',$#content_of_file);  }
       foreach $not_eps (@content_of_file) {
+	  chomp($not_eps);
 	  if ($not_eps ne '') {
               my $status_statement='EPS picture for '.$not_eps;
-	      &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'last PDF file '.$not_eps); 
 	      $not_eps=~s|\/\.\/|\/|g;
 	      my $eps_f = $not_eps;
 	      $eps_f =~ s/\.[^.]*$/\.eps/i;
@@ -108,6 +111,11 @@
 	      if ( exists($done_conversion{$not_eps})) {
 		  next;
 	      }
+	      if ($adv) {
+		  my $prettyname=$not_eps;
+		  $prettyname=~s|/home/([^/]+)/public_html|/priv/$1|;
+		  $prettyname=~s|/home/httpd/html/|/|;
+		  &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Converting to EPS '.$prettyname); }
 	      $done_conversion{$not_eps}=1;
 	      $status = $image->Read($not_eps);
 	      if ($status) {print "  $status  ";}
@@ -125,46 +133,48 @@
 	      }  
 	  }
       }
-      &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state);
+      if ($adv) { &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); }
   }
   #print "$texfile\n"; #name of the tex file for debugging only   
   my @texfile=($texfile);
   if ($number_of_files>1) {
-      for (my $i=1;$i<=$number_of_files-1;$i++) {
+      @texfile=();
+      for (my $i=1;$i<=$number_of_files;$i++) {
 	  my $new_texfile=$texfile;
-	  $new_texfile=~s/\.tex/_add$i\.tex/;
+	  $new_texfile=~s/\.tex/_$i\.tex/;
 	  push @texfile,$new_texfile;
       } 
   }
+
 my $ind=-1;
-my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status','Class Print Status',$number_of_files);
+my %prog_state;
+if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status','Class Print Status',$number_of_files); }
+my $final_statement="<a href=\"$backref\"><b>Return</b</a> to last resource.<br /><br />Generated PDF File for:<br />";
 foreach $texfile (@texfile) {
-  my $final_statement="<a href=\"$backref\"><b>Back to where you started</b></a><br /><br /><b>Link to your PDF document:</b> ";
-  my $status_statement='PDF document for ';
-  if ($number_of_files>1) {
-      $ind++;
-      my @stud_info=split(/_END_/,$names_pack[$ind]);
-      my @tempo_array=split(/:/,$stud_info[0]);
-      my $name;
+  my $status_statement='';
+  my $link_text='download PDF';
+  $ind++;
+  my @stud_info=split(/_END_/,$names_pack[$ind]);
+  my @tempo_array=split(/:/,$stud_info[0]);
+  my $name;
+  if ($tempo_array[3]) {
+      $name=$tempo_array[3];
+  } else {
+      $name=$tempo_array[0].'@'.$tempo_array[1];
+  }
+  $link_text='<b>'.$name.'</b> ';
+  $status_statement.=$name;
+  if ($#stud_info>0) {
+      @tempo_array=split(/:/,$stud_info[-1]);
       if ($tempo_array[3]) {
 	  $name=$tempo_array[3];
       } else {
 	  $name=$tempo_array[0].'@'.$tempo_array[1];
       }
-      $final_statement='Link to PDF document for <b>'.$name.'</b> ';
-      $status_statement.=$name;
-      if ($#stud_info>0) {
-	  @tempo_array=split(/:/,$stud_info[-1]);
-	  if ($tempo_array[3]) {
-	      $name=$tempo_array[3];
-	  } else {
-	      $name=$tempo_array[0].'@'.$tempo_array[1];
-	  }
-	  $final_statement.='- <b>'.$name.':</b>  ';
-	  $status_statement.=' -  '.$name;
-      } 
-  }
-&Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'last PDF file '.$status_statement); 
+      $link_text.='- <b>'.$name.':</b>  ';
+      $status_statement.=' -  '.$name;
+  } 
+  if ($adv) { &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Creating PDF for '.$status_statement); }
   if (-e $texfile) {
       $texfile =~ m/^(.*)\/([^\/]+)$/; 
       my $name_file = $2;
@@ -306,6 +316,7 @@
 	  system("$comma $name_file 1>/dev/null 2>/dev/null");
 	  if (-e $new_name_file) {
 	      print "<br />$final_statement ";
+	      $final_statement='';
 	      $new_name_file =~ m/^(.*)\./;
 	      my $tempo_file = $1.'temporar.ps';
 	      my $name_file = $1.'.pdf';
@@ -331,7 +342,7 @@
 	      my @garb = ($texlog,$texaux,$texdvi,$texps);
 #	  unlink @garb;
 	      unlink $duefile;
-	      print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
+	      print "<a href=\"/prtspool/$name_file\">$link_text</a>";
 	      print "\n";
 	  }
       }
@@ -348,11 +359,13 @@
 	$file=~s/\.tex/.\pdf/;
 	$statement.=' '.$file; 
     }
-    system("$statement");
+    print("<pre>Zip Output:\n");
+    system($statement);
+    print("</pre>");
     $zipfile=~s/\/home\/httpd//;
-    print "<br /> <a href=\"$zipfile\">Your ZIP file is here</a>";
+    print "<br /> A <a href=\"$zipfile\">ZIP file</a> of all the PDFs.";
 }
-&Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state);
+if ($adv) { &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); }
 
 
 
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.276 loncom/interface/lonprintout.pm:1.277
--- loncom/interface/lonprintout.pm:1.276	Fri Feb 13 16:13:21 2004
+++ loncom/interface/lonprintout.pm	Mon Feb 16 19:26:20 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.276 2004/02/13 21:13:21 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.277 2004/02/17 00:26:20 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1155,35 +1155,48 @@
     }
 #-- writing .tex file in prtspool 
     my $temp_file;
-    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
-    unless ($temp_file = Apache::File->new('>'.$filename)) {
-	$r->log_error("Couldn't open $filename for output $!");
-	return SERVER_ERROR; 
-    }
-    print $temp_file $result;
-    my $begin=index($result,'\begin{document}',0);
-    my $inc=substr($result,0,$begin+16);
-    if ($#print_array>0) {
-        for (my $i=1;$i<=$#print_array;$i++) {
-            my $anobegin=index($print_array[$i],'\setcounter{page}',0);
-	    substr($print_array[$i],0,$anobegin)='';
-	    $print_array[$i]=$inc.$print_array[$i].'\end{document}';
+    my $identifier = &Apache::loncommon::get_cgi_id();
+    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".$identifier.".tex";
+    if (!($#print_array>0)) { 
+	unless ($temp_file = Apache::File->new('>'.$filename)) {
+	    $r->log_error("Couldn't open $filename for output $!");
+	    return SERVER_ERROR; 
+	}
+	print $temp_file $result;
+	my $begin=index($result,'\begin{document}',0);
+	my $inc=substr($result,0,$begin+16);
+    } else {
+	my $begin=index($result,'\begin{document}',0);
+	my $inc=substr($result,0,$begin+16);
+        for (my $i=0;$i<=$#print_array;$i++) {
+	    if ($i==0) {
+		$print_array[$i]=$result;
+	    } else {
+		my $anobegin=index($print_array[$i],'\setcounter{page}',0);
+		substr($print_array[$i],0,$anobegin)='';
+		$print_array[$i]=$inc.$print_array[$i].'\end{document}';
+	    }
 	    my $temp_file;
 	    my $newfilename=$filename;
-	    $newfilename =~s/\.tex$/_add$i\.tex/; 
+	    my $num=$i+1;
+	    $newfilename =~s/\.tex$/_$num\.tex/; 
 	    unless ($temp_file = Apache::File->new('>'.$newfilename)) {
 		$r->log_error("Couldn't open $newfilename for output $!");
 		return SERVER_ERROR; 
 	    }
 	    print $temp_file $print_array[$i];
 	}
-
     }
     my $student_names='';
     if ($#print_array>0) {
 	for (my $i=0;$i<=$#print_array;$i++) {
 	    $student_names.=$student_names[$i].'_ENDPERSON_';
 	}
+    } else {
+	my $fullname = &get_name($ENV{'user.name'},$ENV{'user.domain'});
+	$student_names=join(':',$ENV{'user.name'},$ENV{'user.domain'},
+			    $ENV{'request.course.sec'},$fullname).
+				'_ENDPERSON_'.'_END_';
     }
 
     my $URLback=''; #link to original document
@@ -1196,7 +1209,6 @@
 	if ($URLback=~/([^?]+)/) {$URLback=$1;}
     }
 
-    my $identifier = time.'_'.int(rand(1000));
     &Apache::lonnet::appenv('cgi.'.$identifier.'.file'   => $filename,
                             'cgi.'.$identifier.'.layout'  => $laystyle,
                             'cgi.'.$identifier.'.numcol'  => $numberofcolumns,

--albertel1076977580--