[LON-CAPA-cvs] cvs: loncom /xml lonxml.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 08 Sep 2003 19:00:09 -0000


albertel		Mon Sep  8 15:00:09 2003 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
  Log:
  - Fixes 2128, (new sty file gets seeded with the contents for HTML pages.)
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.273 loncom/xml/lonxml.pm:1.274
--- loncom/xml/lonxml.pm:1.273	Thu Aug 21 11:51:41 2003
+++ loncom/xml/lonxml.pm	Mon Sep  8 15:00:09 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.273 2003/08/21 15:51:41 sakharuk Exp $
+# $Id: lonxml.pm,v 1.274 2003/09/08 19:00:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1164,16 +1164,35 @@
   return $filecontents;
 }
 
+sub createnewsty {
+  my $filecontents=(<<SIMPLECONTENT);
+<definetag name="">
+    <render>
+       <web></web>
+       <tex></tex>
+    </render>
+</definetag>
+SIMPLECONTENT
+  return $filecontents;
+}
+
 
 sub inserteditinfo {
-      my ($result,$filecontents)=@_;
+      my ($result,$filecontents,$filetype)=@_;
       $filecontents = &HTML::Entities::encode($filecontents);
 #      my $editheader='<a href="#editsection">Edit below</a><hr />';
-      my $xml_help = Apache::loncommon::helpLatexCheatsheet();
+      my $xml_help = '';
+      if ($filetype eq 'html') {
+	  $xml_help=Apache::loncommon::helpLatexCheatsheet();
+      }
+      my $cleanbut = '';
+      if ($filetype eq 'html') {
+	  $cleanbut='<input type="submit" name="attemptclean" 
+                       value="Save and then attempt to clean HTML" />';
+      }
       my $titledisplay=&display_title();
       my $buttons=(<<BUTTONS);
-<input type="submit" name="attemptclean" 
-       value="Save and then attempt to clean HTML" />
+$cleanbut
 <input type="submit" name="savethisfile" value="Save this" />
 <input type="submit" name="viewmode" value="View" />
 BUTTONS
@@ -1241,6 +1260,12 @@
 
 
     my $file=&Apache::lonnet::filelocation("",$request->uri);
+    my $filetype;
+    if ($file =~ /\.sty$/) {
+	$filetype='sty';
+    } else {
+	$filetype='html';
+    }
 #
 # Edit action? Save file.
 #
@@ -1267,7 +1292,11 @@
 ENDNOTFOUND
     $filecontents='';
 	if ($ENV{'request.state'} ne 'published') {
-	    $filecontents=&createnewhtml();
+	    if ($filetype eq 'sty') {
+		$filecontents=&createnewsty();
+	    } else {
+		$filecontents=&createnewhtml();
+	    }
 	    $ENV{'form.editmode'}='Edit'; #force edit mode
 	}
     } else {
@@ -1295,11 +1324,11 @@
 	    $displayfile=~s/^\/[^\/]*//;
 	    $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
 		'</h3></body></html>';
-	    $result=&inserteditinfo($result,$filecontents);
+	    $result=&inserteditinfo($result,$filecontents,$filetype);
 	}
     }
-    
-    writeallows($request->uri);
+    if ($filetype eq 'html') { writeallows($request->uri); }
+	
     
 
     $request->print($result);