-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting.php
82 lines (67 loc) · 2.42 KB
/
listing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
header('Content-Type: text/xml');
if(isset($_GET["itemname"]) && isset($_GET["itemprice"]) && isset($_GET["itemquantity"]) && isset($_GET["itemdescription"]))
{
$itemnumber = uniqid();
$itemname = $_GET["itemname"];
$itemprice = $_GET["itemprice"];
$itemquantity = $_GET["itemquantity"];
$itemdescription = $_GET["itemdescription"];
//echo("Reached listing.php");
$xmlfile = '../../data/goods.xml';
$doc = new DomDocument();
if (!file_exists($xmlfile))
{ // if the xml file does not exist, create a root node $goods
$goods = $doc->createElement('goods');
$doc->appendChild($goods);
}
else
{ // load the xml file
$doc->preserveWhiteSpace = FALSE;
$doc->load($xmlfile);
}
$goods = $doc->getElementsByTagName('goods')->item(0);
$item = $doc->createElement('item');
$goods->appendChild($item);
//create a itemnumber node ....
$itemnumber1 = $doc->createElement('itemnumber');
$item->appendChild($itemnumber1);
$Value = $doc->createTextNode($itemnumber);
$itemnumber1->appendChild($Value);
//create a quantityonhold node ....
$Quantityonhold = $doc->createElement('quantityonhold');
$item->appendChild($Quantityonhold);
$Value = $doc->createTextNode(0);
$Quantityonhold->appendChild($Value);
//create a quantitysold ID node ....
$Quantitysold = $doc->createElement('quantitysold');
$item->appendChild($Quantitysold);
$Value = $doc->createTextNode(0);
$Quantitysold->appendChild($Value);
//create a itemname node ....
$Itemname1 = $doc->createElement('itemname');
$item->appendChild($Itemname1);
$Value = $doc->createTextNode($itemname);
$Itemname1->appendChild($Value);
//create a itemprice node ....
$Itemprice1 = $doc->createElement('itemprice');
$item->appendChild($Itemprice1);
$Value = $doc->createTextNode($itemprice);
$Itemprice1->appendChild($Value);
//create a itemquantity node ....
$Itemquantity1 = $doc->createElement('itemquantity');
$item->appendChild($Itemquantity1);
$Value = $doc->createTextNode($itemquantity);
$Itemquantity1->appendChild($Value);
//create a itemdescription node ....
$Itemdescription1 = $doc->createElement('itemdescription');
$item->appendChild($Itemdescription1);
$Value = $doc->createTextNode($itemdescription);
$Itemdescription1->appendChild($Value);
//save the xml file
$doc->formatOutput = true;
$doc->save($xmlfile);
echo "The item has been listed in the system, and the item number is ".$itemnumber."";
//echo $itemprice;
}
?>