<?php
//-->-->-->-->-->-->-->-->
  
   require '/usr50/home/retrovox/public_html/manage/php-lib/fnRetrovoxParseXml.php';
   $sDataPath = "/usr50/home/retrovox/public_html/product-data";
   
   $sProductId = $_POST["product-id"];
   $sFilePath = "$sDataPath/product-$sProductId.xml";
   
   if ($sProductId == '')
   {
    echo "
      <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>
      <html>
       <META HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET='iso-8859-1'>
       <META HTTP-EQUIV='Keywords'
		CONTENT='Retrovox Products'>
       <META HTTP-EQUIV='Description'
		CONTENT='Retrovox Product, no item'>
	      <LINK REV='made' HREF='mailto:matth3wbishop@yahoo.com'>

      <head><title>Retrovox Product Display, (No product specified)</title>
      </head>
      <body>
      <center><h1>No product was specified</h1></center>
	<p>
       You did not specify any product to update (using the product-id)
       </p>
       This situation probably indicates an error in the script
       edit-product-form.php
          <br>
          <a href = '/product-data/'>View All Product Files (XML)</a>
      </body>
      </html>";
     exit; 
   } //-- if no product

   if (!file_exists($sFilePath))
   {
    echo "
      <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>
      <html>
       <META HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET='iso-8859-1'>
       <META HTTP-EQUIV='Keywords'
		CONTENT='Retrovox'>
       <META HTTP-EQUIV='Description'
		CONTENT='Retrovox notepad, item doesnt exist'>
	      <LINK REV='made' HREF='mailto:matth3wbishop@yahoo.com'>

      <head><title>Retrovox Product Edit, (The item doesn't exist)</title>
      </head>
      <body>
      <center><h1>The item doesn't exist</h1></center>
	  <p>There is no product on the Retrovox site with the product-id which
             you just specified. For this reason the data for this product
             cannot be updated</p>
 
          <br>This probably indicates an error is the script file
              edit-product-form.php
          <br>To create a new product you should use the script
              add-product-form.php
          <a href = 'product-data/'>View All Products</a>
      </body>
      </html>";
     return; 
   } //-- if product doesnt exist
 
   if (!is_readable($sFilePath))
   {
    echo "
      <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>
      <html>
       <META HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET='iso-8859-1'>
       <META HTTP-EQUIV='Keywords'
		CONTENT='Retrovox'>
       <META HTTP-EQUIV='Description'
		CONTENT='Retrovox, product file not readable'>
	      <LINK REV='made' HREF='mailto:matth3wbishop@yahoo.com'>

      <head><title>Retrovox Product Display, (The product file is not readable)</title>
      </head>
      <body>
      <center><h1>The product file is not readable</h1></center>
	  <p>The file containing the data for the product which you specified
             is not readable. The permissions for this file will need to be 
             altered by the system administrator
            </p>
          <br>
      </body>
      </html>";
     return; 
   } //-- if product file not readable 

   if (!is_writable($sFilePath))
   {
    echo "
      <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>
      <html>
       <META HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET='iso-8859-1'>
       <META HTTP-EQUIV='Keywords'
		CONTENT='Retrovox'>
       <META HTTP-EQUIV='Description'
		CONTENT='Retrovox, product file not writable'>
	      <LINK REV='made' HREF='mailto:matth3wbishop@yahoo.com'>

      <head><title>Retrovox Product Display, (The product file is not writable)</title>
      </head>
      <body>
      <center><h1>The product file is not writeable</h1></center>
	  <p>The file containing the data for the product which you specified
             is not writable. The permissions for this file will need to be 
             altered by the system administrator
            </p>
          <br>
      </body>
      </html>";
     return; 
   } //-- if product file not writeable

   //-- Construct the XML and write the data to file
   //

   $sProductData = "<product> \n";
   
   foreach ($_POST as $key => $value)
   {
      $sProductData = $sProductData."<$key>".htmlspecialchars($value)."</$key> \n";
   }
	   
   $sProductData = $sProductData."</product> \n";

   $fileHandle = fopen($sFilePath, "w");
   fwrite($fileHandle, $sProductData);
   fclose($fileHandle);

   $aaProductData = fnRetrovoxParseXml($sProductData);

//--<--<--<--<--<
?>

<HTML>
<HEAD>
   <TITLE>Retrovox Update Product</TITLE>
</HEAD>


<body>

 <center>
   <img src="/Images/retrovox150.jpg" width=150 height=81 align=bottom><br>
   <h2>The product was updated</h2>
 </center>
   

   <table  border = "1" align = 'center'>
   <tr><td colspan = '2'><em>The following data was saved</em></td></tr>

<?php
//-->-->-->-->-->-->-->-->
   //-- for debugging
   // <pre><?=htmlspecialchars($sProductData)?</pre>


   foreach ($aaProductData as $key => $value)
   {
      echo "<tr><td><strong><em>$key</em></strong></td><td>$value</td></tr> \n";
   } //-- foreach
//--<--<--<--<--<--<--<--<
?>
   </table>
  </center>
  <ol type = 'a'>
    <li><a href = '/product-data/display-product.php?product=<?=$sProductId?>'>
      View the web-page for this product</a></li>
    <li><a href = '/product-data/product-<?=$sProductId?>.xml'>
      View the raw XML data for this product</a></li>
    <li><a href = '/product-data/display-product-xml.php?product=<?=$sProductId?>'>
      View the XML data for this product in a web-page</a></li>
    <li><a href = '/manage/edit-product-form.php?product=<?=$sProductId?>'>
      Edit the data for this product</a> (Administrators Only)</li>
    <li><a href = '/manage/add-product-form.php'>
      Add a new product</a> (Administrators Only)</li>

  </ol>
</body>
</html>