-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_component.php
executable file
·368 lines (339 loc) · 18.3 KB
/
edit_component.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
require_once 'include/Class_DB.php';
require_once 'include/login/auth.php';
require_once 'include/debug.php';
$owner = $_SESSION['SESS_MEMBER_ID'];
$id = (int)$_REQUEST['edit'];
$GetDataComponent = $db->query('SELECT * FROM data WHERE id = ' .$id. ' AND owner = ' .$owner);
$executesql = $db->fetch_assoc($GetDataComponent);
$GetPersonal = $db->query('SELECT currency, measurement FROM members WHERE member_id = ' .$owner);
$personal = $db->fetch_assoc($GetPersonal);
if ($executesql['owner'] !== $owner) {
header('Location: error.php?id=2');
}
if ($executesql['category'] < 999) {
$head_cat_id = substr($executesql['category'], -3, 1);
}
else {
$head_cat_id = substr($executesql['category'], -4, 2);
}
$GetHeadCatName = $db->query('SELECT * FROM category_head WHERE id = ' . (int)$head_cat_id);
$executesql_head_catname = $db->fetch_assoc($GetHeadCatName);
$sub_cat_id = $executesql['category'];
$GetSubCatName = $db->query('SELECT * FROM category_sub WHERE id = ' . (int)$sub_cat_id);
$executesql_sub_catname = $db->fetch_assoc($GetSubCatName);
$GetDataComponentsAll = 'SELECT * FROM category_sub';
$sql_exec = $db->query($GetDataComponentsAll);
if(isset($_POST['delete'])) {
$sqlDeleteComopnent = 'DELETE FROM data WHERE id = ' . $id . ' LIMIT 1';
$sql_exec_component_delete = $db->query($sqlDeleteComopnent);
$sqlDeleteProject = "DELETE FROM projects_data WHERE projects_data_component_id = '$id'";
$sql_exec_project_delete = $db->query($sqlDeleteProject);
header('Location: .');
}
if(isset($_POST['based'])) {
header("Location: add_based.php?based=$id");
}
if (isset($_POST['quantity_increase'])) {
$quantity_before = $_POST['quantity'];
$quantity_after = $quantity_before + 1;
$sql = "UPDATE data SET quantity = '".$quantity_after."' WHERE id = ".$id." ";
$sql_exec = $db->query($sql);
header("location: " . $_SERVER['REQUEST_URI']);
}
if (isset($_POST['quantity_decrease'])) {
$quantity_before = $_POST['quantity'];
$quantity_after = $quantity_before - 1;
$sql = "UPDATE data SET quantity = '".$quantity_after."' WHERE id = ".$id." ";
$sql_exec = $db->query($sql);
header("location: " . $_SERVER['REQUEST_URI']);
}
if (isset($_POST['orderquant_increase'])) {
$quantity_before = $_POST['orderquant'];
$quantity_after = $quantity_before + 1;
$sql = "UPDATE data SET order_quantity = '".$quantity_after."' WHERE id = ".$id." ";
$sql_exec = $db->query($sql);
header("location: " . $_SERVER['REQUEST_URI']);
}
if (isset($_POST['orderquant_decrease'])) {
$quantity_before = $_POST['orderquant'];
$quantity_after = $quantity_before - 1;
$sql = "UPDATE data SET order_quantity = '".$quantity_after."' WHERE id = ".$id;
$sql_exec = $db->query($sql);
header("location: " . $_SERVER['REQUEST_URI']);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="include/style.css" media="screen"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="description" content="If you wany to edit something of the component, do it here."/>
<meta name="keywords" content="electronics, components, database, project, inventory"/>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="apple-touch-icon" href="img/apple.png" />
<title>Edit component - <?php echo $executesql['name']; ?> - ecDB</title>
<?php include_once "include/analytics.php" ?>
</head>
<body>
<div id="wrapper">
<!-- Header -->
<?php include 'include/header.php'; ?>
<!-- END -->
<!-- Main menu -->
<?php include 'include/menu.php'; ?>
<!-- END -->
<!-- Main content -->
<div id="content">
<h1>
<a href="category.php?cat=<?php echo $executesql_head_catname['id'];?>"><?php echo $executesql_head_catname['name'];?></a>
<a href="category.php?subcat=<?php echo $executesql_sub_catname['id'];?>"><?php echo $executesql_sub_catname['name'];?></a>
/
<a href="component.php?view=<?php echo $executesql['id']; ?>"><?php echo $executesql['name']; ?></a>
</h1>
<?php
include 'include/include.php';
$Add = new ShowComponents;
$Add->Add();
?>
<form class="globalForms noPadding" action="" method="post">
<div class="textBoxInput">
<label class="keyWord boldText">Comment </label>
<div class="text"><!--cols="104"-->
<textarea name="comment" rows="14" style="width: 99%; resize: both !important;"><?php echo $executesql['comment']; ?></textarea>
</div>
</div>
<table class="globalTables leftAlign noHover" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="boldText">Name</td>
<td>
<input name="name" type="text" class="medium" value="<?php echo $executesql['name']; ?>" id="name" />
</td>
<td class="boldText">Category</td>
<td>
<select name="category">
<?php
$HeadCategoryNameQuery = 'SELECT * FROM category_head ORDER by name ASC';
$sql_exec_headcat = $db->query($HeadCategoryNameQuery);
while ($HeadCategory = $db->fetch_assoc($sql_exec_headcat)) {
echo '<option class="main_category" value="';
echo $HeadCategory['id'];
echo '" disabled>';
echo $HeadCategory['name'];
echo '</option>';
$subcatfrom = $HeadCategory['id'] * 100;
$subcatto = $subcatfrom + 99;
$SubCategoryNameQuery = 'SELECT * FROM category_sub WHERE id BETWEEN ' .$subcatfrom. ' AND ' .$subcatto. ' ORDER by name ASC';
$sql_exec_subcat = $db->query($SubCategoryNameQuery);
while ($SubCategory = $db->fetch_assoc($sql_exec_subcat)) {
echo '<option value="';
echo $SubCategory['id'];
echo '"';
if ($executesql_sub_catname['id'] == $SubCategory['id']) {
echo ' selected';
}
echo '>';
echo $SubCategory['name'];
echo '</option>';
}
}
?>
</select>
</td>
<td class="boldText">Quantity</td>
<td>
<input name="quantity" type="text" class="small" value="<?php echo $executesql['quantity']; ?>" id="quantity"/>
<button class="button white small" name="quantity_increase" type="submit"><span class="icon medium roundPlus"></span></button>
<button class="button white small" name="quantity_decrease" type="submit"><span class="icon medium roundMinus"></span></button>
</td>
</tr>
<tr>
<td class="boldText">Manufacturer</td>
<td>
<input name="manufacturer" type="text" class="medium" value="<?php echo $executesql['manufacturer']; ?>" />
</td>
<td class="boldText">Package</td>
<td>
<input name="package" type="text" class="medium" value="<?php echo $executesql['package']; ?>" />
</td>
<td class="boldText">Pins</td>
<td>
<input name="pins" type="text" class="small" value="<?php echo $executesql['pins']; ?>" />
</td>
</tr>
<tr>
<td class="boldText">Location</td>
<td>
<input name="location" type="text" class="medium" value="<?php echo $executesql['location']; ?>" id="location" />
</td>
<td class="boldText">Price</td>
<td>
<input name="price" type="text" class="small" value="<?php echo $executesql['price']; ?>" id="price" /> <?php echo $personal['currency']; ?>
</td>
<td class="boldText">To order</td>
<td>
<input name="orderquant" type="text" class="small" value="<?php echo $executesql['order_quantity']; ?>" id="orderquant"/>
<button class="button white small" name="orderquant_increase" type="submit"><span class="icon medium roundPlus"></span></button>
<button class="button white small" name="orderquant_decrease" type="submit"><span class="icon medium roundMinus"></span></button>
</td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td class="boldText">SMD</td>
<td>
<?php
if($executesql['smd'] == 'Yes'){
echo '<input type="radio" name="smd" value="Yes" checked="checked" /> Yes ';
echo '<input type="radio" name="smd" value="No" /> No';
}
else{
echo '<input type="radio" name="smd" value="Yes" /> Yes ';
echo '<input type="radio" name="smd" value="No" checked="checked" /> No';
}
?>
</td>
<td class="boldText">Scrap</td>
<td>
<?php
if($executesql['scrap'] == 'Yes'){
echo '<input type="radio" name="scrap" value="Yes" checked="checked" /> Yes ';
echo '<input type="radio" name="scrap" value="No" /> No';
}
else{
echo '<input type="radio" name="scrap" value="Yes" /> Yes ';
echo '<input type="radio" name="scrap" value="No" checked="checked" /> No';
}
?>
</td>
<td class="boldText">Public</td>
<td>
<?php
if($executesql['public'] == 'Yes'){
echo '<input type="radio" name="public" value="Yes" checked="checked" /> Yes ';
echo '<input type="radio" name="public" value="No" /> No';
}
else{
echo '<input type="radio" name="public" value="Yes" /> Yes ';
echo '<input type="radio" name="public" value="No" checked="checked" /> No';
}
?>
</td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td class="boldText">Weight</td>
<td>
<input name="weight" type="text" class="small" value="<?php echo $executesql['weight']; ?>" /> <?php if($personal['measurement'] == 1){echo 'g';} else {echo 'g'; } ?>
</td>
<td class="boldText">Width</td>
<td>
<input name="width" type="text" class="small" value="<?php echo $executesql['width']; ?>" /> <?php if($personal['measurement'] == 1){echo 'mm';} else {echo 'in'; } ?>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="boldText">Depth</td>
<td>
<input name="depth" type="text" class="small" value="<?php echo $executesql['depth']; ?>" /> <?php if($personal['measurement'] == 1){echo 'mm';} else {echo 'in'; } ?>
</td>
<td><img class="packageImage" border="0" src="img/boxSize.png"/></td>
<td></td>
</tr>
<tr>
<td class="boldText">Datasheet URL</td>
<td>
<input name="datasheet" type="text" class="medium" value="<?php echo $executesql['datasheet']; ?>" />
</td>
<td class="boldText">Height</td>
<td>
<input name="height" type="text" class="small" value="<?php echo $executesql['height']; ?>" /> <?php if($personal['measurement'] == 1){echo 'mm';} else {echo 'in'; } ?>
</td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td class="boldText">Image URL 1</td>
<td>
<input name="url1" type="text" class="medium" value="<?php echo $executesql['url1']; ?>" />
</td>
<td class="boldText">Image URL 2</td>
<td>
<input name="url2" type="text" class="medium" value="<?php echo $executesql['url2']; ?>" />
</td>
<td colspan="2"></td>
</tr>
<tr>
<td class="boldText">Image URL 3</td>
<td>
<input name="url3" type="text" class="medium" value="<?php echo $executesql['url3']; ?>" />
</td>
<td class="boldText">Image URL 4</td>
<td>
<input name="url4" type="text" class="medium" value="<?php echo $executesql['url4']; ?>" />
</td>
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td class="boldText">Add to project</td>
<td class="boldText">Quantity</td>
<?php
$sql = 'SELECT projects_data_component_id FROM projects_data WHERE projects_data_component_id = ' .(int)$_REQUEST['edit'];
$sql_echo = $db->query($sql);
if ($db->count($sql_echo) == 0) {
echo '<td colspan="3"></td>';
}
else {
echo '<td class="boldText">Project</td>';
echo '<td class="boldText">Quantity</td>';
echo '<td></td>';
}
?>
</tr>
<tr>
<td></td>
<td>
<select name="project">
<?php
include 'include/include_component_edit_project_add.php';
$MenuProj = new AddMenuProj;
$MenuProj->MenuProj();
?>
</select>
</td>
<td>
<input name="projquant" type="text" class="small" value="<?php if(isset($_POST['submit'])) { echo $_POST['projquant']; } ?>" />
</td>
<td>
<?php
include 'include/include_component_edit_project_edit.php';
$MenuProj = new EditProj;
$MenuProj->MenuProj();
?>
</tbody>
</table>
<div class="buttons">
<div class="input">
<button class="button green" name="update" type="submit"><span class="icon medium save"></span> Update</button>
<button class="button" name="based" type="submit"><span class="icon medium sqPlus"></span> New based on this</button>
<button class="button red" name="delete" type="submit"><span class="icon medium trash"></span> Delete</button>
</div>
</div>
</form>
</div>
<!-- END -->
<!-- Text outside the main content -->
<?php include 'include/footer.php'; ?>
<!-- END -->
</div>
</body>
</html>