-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodify.php
More file actions
91 lines (78 loc) · 2.86 KB
/
modify.php
File metadata and controls
91 lines (78 loc) · 2.86 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
include 'Storage.php';
$document= new Storage('./storage.xml','./schema.xsd');
$text='Submit';
$value=0;
if (isset($_GET['index'])&&(($_GET['index'])<$document->length)) {
$value = $_GET['index']; $document->getItemElbyIndex($value);
$Name=$document->mItem->mName;
$Weight=$document->mItem->mWeight;
$Category=$document->mItem->mCategory;
$Location=$document->mItem->mLocation;
}
elseif (isset($_POST['index'])&&(($_POST['index'])<$document->length)) {
$value = $_POST['index']; $document->getItemElbyIndex($value);
$Name=$document->mItem->mName;
$Weight=$document->mItem->mWeight;
$Category=$document->mItem->mCategory;
$Location=$document->mItem->mLocation;
} else{
$Name='';
$Weight='';
$Category='';
$Location='';
$text='Add';
}
// modifing or adding
if ( isset($_POST['formSubmit'])){
$Name = $_POST['name'];
$Weight = $_POST['weight'];
$Category = $_POST['category'];
$Location = $_POST['location'];
if ($_POST['formSubmit'] == "Submit")
{ //modify
$document->modSet($Name, $Weight, $Category, $Location);
if ($document->validate('./schema.xsd')) $document->save();
else echo '<h1> Do not match Shcema</h1>';
} //add
elseif ( $_POST['formSubmit'] == "Add"){
$id='new_id'.$value;
$document->mItem->newItem(); // ($id,$Name,$Weight,$Category,$Location);
$document->modSet($Name, $Weight, $Category, $Location);
if ($document->validate('./schema.xsd')) $document->save();
else echo '<h1> Do not match Shcema</h1>';
}
}
if (isset($_POST['formRemove'])){
$document->getItemElbyIndex($value);
$document->removeItem();
$document->save();
header("Location: modify.php?index=".++$value."");
}
?>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify Element</title>
</head>
<body>
<form action="modify.php" method="post" >
<div class="input">
<input type="hidden" name="index" type="text" value="<?=$value?>"/>
<p>Name: <input name="name" type="text" value="<?=$Name?>" /> </p>
<p>Weight: <input name="weight" type="text" value="<?=$Weight?>" /></p>
<p>Category: <input name="category" type="text" value="<?=$Category?>" /></p>
<p>Location: <input name="location" type="text" value="<?=$Location?>" /></p>
</div>
<input type="Submit" name="formSubmit" value="<?=$text?>"/>
<input type="Submit" name="formRemove" value="remove"/>
</form>
<div id="button">
<br>
<a href="modify.php?index=0">Prev</a>
<a href="modify.php?index=<?=++$value?>">Next</a>
</div>
</body>
</html>