-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsaveItem.php
125 lines (110 loc) · 4.11 KB
/
saveItem.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
Student ID : 1784765
Name: Vivek S Patil
Functonality : This page Saves the item details in an xml file.
*/
session_start();
header('Content-Type: text/xml');
?>
<?php
$ItemName = $_POST['ItemName'];
$Category = $_POST['Category'];
$Description = $_POST['Description'];
$StartPrice = $_POST['StartPrice'];
$ReservePrice = $_POST['ReservePrice'];
$BuyItNowPrice = $_POST['BuyItNowPrice'];
$Duration = $_POST['Duration'];
$ItemNumber = 1;
$StartDate = date('Y-m-j');
$StartTime = date('H:i');
$Status = "in-progress";
$ListedBy = "Lister";
$ListedBy = $_SESSION["CustomerfName"];
$Bidder = "";
$CurrentBidPrice = $StartPrice;
$xmlFile = "../../data/auction.xml";
//Check if the file exists
if(file_exists($xmlFile))
{
$ItemNumber = fnGetItemNumber($xmlFile);
fnAppendItem($ItemName,$Category,$Description,$StartPrice,$ReservePrice,$BuyItNowPrice,$Duration,
$ItemNumber,$StartDate,$StartTime,$Status,$ListedBy,$Bidder,$CurrentBidPrice,$xmlFile);
}
else
{
CreateXMLDocItems($ItemName,$Category,$Description,$StartPrice,$ReservePrice,$BuyItNowPrice,$Duration,
$ItemNumber,$StartDate,$StartTime,$Status,$ListedBy,$Bidder,$CurrentBidPrice,$xmlFile);
}
ECHO "Thank you! Your item has been listed in ShopOnline.The item number is ".$ItemNumber.", and the bidding starts now: ".$StartTime." on ".$StartDate;
//generate item number
function fnGetItemNumber($xmlFile)
{
$count = 1;
$doc = DOMDocument::load($xmlFile);
$items = $doc->getElementsByTagName("item");
foreach($items as $item)
{
$count = $count + 1;
}
return $count;
}
//Create an xml doc for new item
function CreateXMLDocItems($ItemName,$Category,$Description,$StartPrice,$ReservePrice,$BuyItNowPrice,$Duration,
$ItemNumber,$StartDate,$StartTime,$Status,$ListedBy,$Bidder,$CurrentBidPrice,$xmlFile)
{
$doc = new DomDocument;//('1.0');
$Items = $doc->createElement('Items');
$Items = $doc->appendChild($Items);
$item = $doc->createElement('item');
$item = $Items->appendChild($item);
fnAppendChild("Number",$doc,$ItemNumber,$item);
fnAppendChild("Name",$doc,$ItemName,$item);
fnAppendChild("Category",$doc,$Category,$item);
fnAppendChild("Description",$doc,$Description,$item);
fnAppendChild("StartPrice",$doc,$StartPrice,$item);
fnAppendChild("ReservePrice",$doc,$ReservePrice,$item);
fnAppendChild("BuyItNowPrice",$doc,$BuyItNowPrice,$item);
fnAppendChild("Duration",$doc,$Duration,$item);
fnAppendChild("StartDate",$doc,$StartDate,$item);
fnAppendChild("StartTime",$doc,$StartTime,$item);
fnAppendChild("Status",$doc,$Status,$item);
fnAppendChild("ListedBy",$doc,$ListedBy,$item);
fnAppendChild("Bidder",$doc,$Bidder,$item);
fnAppendChild("CurrentBidPrice",$doc,$CurrentBidPrice,$item);
//$strXML = $doc->saveXML();
$doc->save($xmlFile);
}
//Generic function to append new child
function fnAppendChild($tagName,$doc,$value,$ParentNode)
{
$Element = $doc->createElement($tagName);
$Element = $ParentNode->appendChild($Element);
$nodevalue = $doc->createTextNode($value);
$nodevalue = $Element->appendChild($nodevalue);
}
function fnAppendItem($ItemName,$Category,$Description,$StartPrice,$ReservePrice,$BuyItNowPrice,$Duration,
$ItemNumber,$StartDate,$StartTime,$Status,$ListedBy,$Bidder,$CurrentBidPrice,$xmlFile)
{
$doc = DOMDocument::load($xmlFile);
$Items = $doc->getElementsByTagName("Items");
$item = $doc->createElement('item');
$item = $Items->item(0)->appendChild($item);
fnAppendChild("Number",$doc,$ItemNumber,$item);
fnAppendChild("Name",$doc,$ItemName,$item);
fnAppendChild("Category",$doc,$Category,$item);
fnAppendChild("Description",$doc,$Description,$item);
fnAppendChild("StartPrice",$doc,$StartPrice,$item);
fnAppendChild("ReservePrice",$doc,$ReservePrice,$item);
fnAppendChild("BuyItNowPrice",$doc,$BuyItNowPrice,$item);
fnAppendChild("Duration",$doc,$Duration,$item);
fnAppendChild("StartDate",$doc,$StartDate,$item);
fnAppendChild("StartTime",$doc,$StartTime,$item);
fnAppendChild("Status",$doc,$Status,$item);
fnAppendChild("ListedBy",$doc,$ListedBy,$item);
fnAppendChild("Bidder",$doc,$Bidder,$item);
fnAppendChild("CurrentBidPrice",$doc,$CurrentBidPrice,$item);
//$strXML = $doc->saveXML();
$doc->save($xmlFile);
}
?>