Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function updateInfo() { // Save new input info to XML file
- $catTitle = $_POST['catTitle']; // Category title
- $cid = $_POST['catNr']; // Category ID
- $pid = $_POST['prodid']; // Array with product IDs
- $pName = $_POST['prodname']; // Array with product Names
- $pPrice = $_POST['prodprice']; // Array with product Prices
- $deleteProd = $_POST['deleteProduct']; // Array with product IDs for product removal
- $deleteCat = $_POST['deleteCategory']; // If checked - delete category
- /** Manage new info and add it to the XML file **/
- global $xmldoc;
- $category = $xmldoc->getElementsByTagName("products")->item($cid-1); // Get the current category
- if(isset($deleteCat)) { // If user chose to delete the category, delete it
- $category->parentNode->removeChild($category);
- return;
- }
- // Create new elements for the new content
- $newCat = $xmldoc->createElement("products");
- $newTitle = $xmldoc->createElement("title", $catTitle);
- $newCat->appendChild($newTitle);
- print_r($deleteProd);
- $delCount = count($deleteProd) - 1; // Felar inte!
- echo "<br />".count($deleteProd)."<br />".$delCount;
- $k=0; // Increases whenever a product is found and "deleted"
- for($i=0;$i<count($pid);$i++) { // Add all the new product data to the new products element
- if(($deleteProd[$k] == $pid[$i]) || $deleteProd[$delCount] == false) $k++; // If the current product was chosen to be deleted, skip re-creating it
- else {
- $newProd = $xmldoc->createElement("product");
- $newCat->appendChild($newProd);
- $newElem = $xmldoc->createElement("id",$pid[$i]);
- $newProd->appendChild($newElem);
- $newElem = $xmldoc->createElement("name",$pName[$i]);
- $newProd->appendChild($newElem);
- $newElem = $xmldoc->createElement("price",$pPrice[$i]);
- $newProd->appendChild($newElem);
- }
- }
- $category->parentNode->replaceChild($newCat,$category); // Replace the old category info with the new info
- $xmldoc->save('prod.xml'); // Save the file with the new content
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement