-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
42 lines (42 loc) · 1.19 KB
/
index.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
<?php
if(isset($_GET['action'])) {
$Items = simplexml_load_file('product.xml'); #you could use any url of your choice, given it is a url leading to an xml files
$id = $_GET['id'];
$index = 0;
$i = 0;
foreach($Items->Item as $Item){
if($Item['id']==$id){
$index = $i;
break;
}
$i++;
}
unset($Items->Item[$index]);
file_put_contents('product.xml', $Items->asXML());
}
$Items = simplexml_load_file('product.xml');
echo 'Number of products: '.count($Items);
echo '<br>List Product Information';
?>
<br>
<a href="add.php">Add new product</a> #The add functionality, also known as Create in "CRUD" has not been implemented yet.
<br>
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<th>ean</th>
<th>Code</th>
<th>Price</th>
<th>Stock</th>
<th>Option</th>
</tr>
<?php foreach($Items->Item as $Item) { ?>
<tr>
<td><?php echo $Item->ean; ?></td>
<td><?php echo $Item->name; ?></td>
<td><?php echo $Item->code; ?></td>
<td><?php echo $Item->stock; ?></td>
<td><a href="edit.php?ean=<?php echo $Item->ean; ?>">Edit</a> |
<a href="index.php?action=delete&ean=<?php echo $Item->ean; ?>" onclick="return confirm('Are you sure?')">Delete</a></td>
</tr>
<?php } ?>
</table>