[LON-CAPA-cvs] cvs: loncom /homework randomlabel.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Tue, 27 Aug 2002 18:21:27 -0000


sakharuk		Tue Aug 27 14:21:27 2002 EDT

  Modified files:              
    /loncom/homework	randomlabel.pm 
  Log:
  Now 1. Checks either original eps file exist on the current library server
         and use it if exist.
      2. Replicates eps file from owner's library server if it is absent on
         current library server.
      3. If replication fails it tries to find ps file on current library
         server (Ed has a lot of such files) and use it.
      4. Replicates ps file from owner's library server.
      5. If replication fails eps is dynamically originated.
  
  
Index: loncom/homework/randomlabel.pm
diff -u loncom/homework/randomlabel.pm:1.35 loncom/homework/randomlabel.pm:1.36
--- loncom/homework/randomlabel.pm:1.35	Tue Aug 27 11:40:07 2002
+++ loncom/homework/randomlabel.pm	Tue Aug 27 14:21:27 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # random labelling tool
 #
-# $Id: randomlabel.pm,v 1.35 2002/08/27 15:40:07 sakharuk Exp $
+# $Id: randomlabel.pm,v 1.36 2002/08/27 18:21:27 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,6 +60,7 @@
 use Apache::lonnet;
 use strict;
 use Apache::edit;
+use Apache::File();
 
 BEGIN {
   &Apache::lonxml::register('Apache::randomlabel',('randomlabel','labelgroup','location','label'));
@@ -106,13 +107,32 @@
     $result.="<applet code=\"$code\" codebase=\"$codebase\" width=\"$w\" height=\"$h\">\n";
     $result.="<param name=\"bgimg\" value=\"$bgimg\">\n";
   } elsif ($target eq 'tex') {
+    my $newbgimg = $bgimg;
     $bgimg=~s/(.gif|.jpg)$/.eps/;
     $bgimg= &Apache::lonnet::filelocation($bgimg);
     if (not $ENV{'request.role'}=~/^au\./) {
 	$bgimg=~s/http:\/[^\/]*/\/home\/httpd\/html/;
 	$bgimg=~s/\/$//;
+        #if no eps file try to replicate it
 	if (not-e $bgimg) {
 	    my $response = &Apache::lonnet::repcopy($bgimg);
+            #if replication failed try to find ps file
+	    if (not-e $bgimg) {
+		$bgimg=~s/\.eps$/\.ps/;
+		#if no ps file try to replicate it
+		if (not-e $bgimg) {
+		    $response = &Apache::lonnet::repcopy($bgimg);
+		    #if replication failed try to produce eps file dynamically
+		    $bgimg=~s/\.ps$/\.eps/;
+		    my $temp_file;
+		    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
+		    $temp_file = Apache::File->new('>>'.$filename);
+		    $newbgimg =~ s/(.*)\/res\//\/home\/httpd\/html\/res\//;
+		    print $temp_file "$newbgimg\n";
+		    $bgimg =~ m/\/([^\/]+)$/;
+		    $bgimg = '/home/httpd/prtspool/'.$1;
+		}
+	    }
 	}
     } else {
 	$bgimg=~s/http:\/[^\/]*\/~([^\/]+)/\/home\/$1\/public_html/;