-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbclass.php
More file actions
222 lines (163 loc) · 5.14 KB
/
dbclass.php
File metadata and controls
222 lines (163 loc) · 5.14 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
class MyDB extends SQLITE3
{
public $result;
function __construct()
{
$this->open("dbfilee.db");
}
function NewData() {
$id=rand(1, 100000);
$item=$_POST['itemid'];
$describe=$_POST['describe'];
$quantity=$_POST['quantity'];
$acquired=$_POST['acquired'];
$span=$_POST['span'];
$depreciate=$_POST['depreciate'];
$money=$_POST['money'];
$money=preg_replace("/[^0-9]/", "", $money);
$span=preg_replace("/[^0-9]/", "", $span);
$depreciate=preg_replace("/[^0-9]/", "", $depreciate);
$ch="SELECT count(*) as rownum FROM `inventory` WHERE itemid='$item'";
$check=$this->query($ch);
$nb=$check->fetchArray();
$count=$nb['rownum'];
if($count>0){
$itemid=rand(1, 100000);
}
else {
$itemid=$item;
}
$sql="INSERT INTO `inventory` VALUES('$id', '$itemid', '$describe', '$quantity', '$acquired', '$span', '$depreciate', '$money')";
$run=$this->exec($sql);
if($run) {
echo "<p style='color:#fff;font-size:20px;'>Item Added To Inventory Successfully!</p>";
}
else
echo "<p style='color:red;'>Sorry!!! An Error Occurred. Try Again!</p>";
}
function EditItem() {
$editid=$_POST['editid'];
$editwhat=$_POST['editwhat'];
$newvalue=$_POST['newvalue'];
$newvalue=preg_replace("/[^0-9]/", "", $newvalue);
$ch="SELECT count(*) as rownum FROM `inventory` WHERE itemid='$editid'";
$check=$this->query($ch);
$rn=$check->fetchArray();
$rownum=$rn['rownum'];
if($rownum>0) {
$sql="UPDATE `inventory` SET $editwhat='$newvalue' WHERE itemid='$editid'";
$run=$this->exec($sql);
if($run) {
echo "<h2>Inventory Updated Successfully!</h2>";
}
else
echo "<h2 style='color:red;'>An Error Occured. Try Again!</h2>";
}
else
echo "<h2 style='color:red;'>No Match Found For that ID</h2>";
}
function UpdateItem() {
$updid=$_POST['updid'];
$what=$_POST['what'];
$updqty=$_POST['updqty'];
$updvalue=$_POST['updvalue'];
$updvalue=preg_replace("/[^0-9]/", "", $updvalue);
$ch="SELECT count(*) as rownum FROM `inventory` WHERE itemid='$updid'";
$check=$this->query($ch);
$rn=$check->fetchArray();
$rownum=$rn['rownum'];
if($rownum>0){
$first="SELECT * FROM `inventory` WHERE itemid='$updid'";
$chfirst=$this->query($first);
$vls=$chfirst->fetchArray();
$qty=$vls['quantity'];
$amt=$vls['amount'];
if($what=="Add") {
$newqty=$qty + $updqty;
$newamt=$amt + $updvalue;
}
if($what=="Remove") {
$newqty=$qty - $updqty;
$newamt=$amt - $updvalue;
}
$sql="UPDATE `inventory` SET quantity='$newqty', amount='$newamt' WHERE itemid='$updid'";
$run=$this->exec($sql);
if($run) {
echo "<h2>Item Updated Successfully!</h2>";
}
else
echo "<h2 style='color:red;'>An Error Occured. Try Again!</h2>";
}
else
echo "<h2 style='color:red;'>No Match Found For that ID</h2>";
}
function View() {
$ch="SELECT count(*) as rownum FROM `inventory`";
$rn=$this->query($ch);
$rw=$rn->fetchArray();
$size=$rw['rownum'];
if($size>0) {
$sql="SELECT * FROM `inventory` WHERE amount>0 ORDER BY itemid";
$run=$this->query($sql);
while($row=$run->fetchArray()) {
$itemid=$row['itemid'];
$describe=$row['description'];
$quantity=$row['quantity'];
$acquired=$row['acquired'];
$span=$row['lifespan'];
$depreciate=$row['depreciate'];
$amount=$row['amount'];
$amount=number_format($amount, "2", ".", ",");
echo "<tr>
<td>$itemid</td>
<td>$describe</td>
<td>$quantity</td>
<td>$acquired</td>
<td>$span Yrs</td>
<td>$depreciate%</td>
<td>N $amount</td>
</tr>";
}
}
else
echo "<tr><td colspan=7>There is no Item on the Inventory. Use the Add New Item Button to add an item.</td></tr>";
}
function DeleteItem() {
$delid=$_POST['delid'];
$ch="SELECT count(*) as rownum FROM `inventory` WHERE itemid='$delid'";
$check=$this->query($ch);
$rn=$check->fetchArray();
$rownum=$rn['rownum'];
if($rownum>0) {
$sql="DELETE FROM `inventory` WHERE itemid='$delid'";
$run=$this->exec($sql);
if($run) {
echo "<h2>Item Removed Successfully!</h2>";
}
else
echo "<h2 style='color:red;'>An Error Occured. Try Again!</h2>";
}
else
echo "<h2 style='color:red;'>No Match Found For that ID</h2>";
}
function DeleteMore() {
$ch="SELECT count(*) as rownum FROM `inventory` WHERE amount<=0";
$check=$this->query($ch);
$nb=$check->fetchArray();
$count=$nb['rownum'];
if($count>0) {
$sql="DELETE FROM `inventory` WHERE amount<=0";
$run=$this-exec($sql);
if($run) {
echo "<h2>Zero Valued Item Removed Successfully!</h2>";
}
else
echo "<h2 style='color:red;'>An Error Occured. Try Again!</h2>";
}
else
echo "<h2 style='color:red;'>No Zero Valued Item Found!!!</h2>";
}
}
$conn=new MyDB();
?>