                                                


<?php
//-->-->-->-->-->-->-->-->
   $sLibraryPath = '/usr50/home/retrovox/public_html/manage/php-lib';
   include "$sLibraryPath/RETROVOX-CONSTANT-VARIABLES.php";
   include "$sLibraryPath/fnRetrovoxStartHtml.php";
   require "$sLibraryPath/fnRetrovoxParseXml.php";

   $sDataPath = "/usr50/home/retrovox/public_html/product-data";
   
   $sProductId = $_POST["product-id"];
   $sFilePath = "$sDataPath/product-$sProductId.xml";
   
   if ($sProductId == '')
   {
      echo fnRetrovoxStartHtml("Add Product: No product was specified");
      echo "
       <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 fnRetrovoxStartHtml("Add Product: No item already exists");
      echo "
	  <p>There is already a product on the Retrovox site 
             with the product-id which
             you just specified. 
          </p>
 
          <br>This possibly indicates an error is the script file
              add-product-form.php
          <br>To edit an existing product you should use the script
              edit-product-form.php
          <a href = '/product-data/'>View All Products</a>
      </body>
      </html>";
     exit; 
   } //-- if product already exists
 
   if (!is_writable(dirname($sFilePath)))
   {
      echo fnRetrovoxStartHtml("The product data directory is not writable");
      echo "
	  <p>The directory 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>";
      //-- exit;
   } //-- if product directory not writeable

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

   $sProductData = "<product> \n";
   
   foreach ($_POST as $key => $value)
   {
      
      $sCleanValue = stripslashes($value);
      $sCleanValue = preg_replace("#'#", '"', $sCleanValue);
      $sCleanValue = htmlspecialchars($sCleanValue);
      $sProductData = $sProductData."<$key>$sCleanValue</$key> \n";
   }
	   
   $sProductData = $sProductData."</product> \n";

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

   $aaProductData = fnRetrovoxParseXml($sProductData);

//--<--<--<--<--<
?>
<?= fnRetrovoxStartHtml("Retrovox Add a Product") ?>
   

   <table  border = "1" align = 'center'
           summary = 'fields and values saved into the database'>
   <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)
   {
      //-- no need to entitize these values since they are stored as
      //-- such in the xml database.
      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></li>
    <li>
    <a href = '/manage/categorize-product-form.php?product=<?=$sProductId?>'>
      Categorize this product</a></li>
    <li>
    <a href = '/manage/admin.php'>
    Retrovox Administration</a></li>

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