forked from siamon123/warehouse-inventory-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_product.php
147 lines (141 loc) · 6.07 KB
/
edit_product.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
<?php
$page_title = 'Edit product';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(2);
?>
<?php
$product = find_by_id('products',(int)$_GET['id']);
$all_categories = find_all('categories');
$all_photo = find_all('media');
if(!$product){
$session->msg("d","Missing product id.");
redirect('product.php');
}
?>
<?php
if(isset($_POST['product'])){
$req_fields = array('product-title','product-categorie','product-quantity','buying-price', 'saleing-price' );
validate_fields($req_fields);
if(empty($errors)){
$p_name = remove_junk($db->escape($_POST['product-title']));
$p_cat = (int)$_POST['product-categorie'];
$p_qty = remove_junk($db->escape($_POST['product-quantity']));
$p_buy = remove_junk($db->escape($_POST['buying-price']));
$p_sale = remove_junk($db->escape($_POST['saleing-price']));
if (is_null($_POST['product-photo']) || $_POST['product-photo'] === "") {
$media_id = '0';
} else {
$media_id = remove_junk($db->escape($_POST['product-photo']));
}
$query = "UPDATE products SET";
$query .=" name ='{$p_name}', quantity ='{$p_qty}',";
$query .=" buy_price ='{$p_buy}', sale_price ='{$p_sale}', categorie_id ='{$p_cat}',media_id='{$media_id}'";
$query .=" WHERE id ='{$product['id']}'";
$result = $db->query($query);
if($result && $db->affected_rows() === 1){
$session->msg('s',"Product updated ");
redirect('product.php', false);
} else {
$session->msg('d',' Sorry failed to updated!');
redirect('edit_product.php?id='.$product['id'], false);
}
} else{
$session->msg("d", $errors);
redirect('edit_product.php?id='.$product['id'], false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-12">
<?php echo display_msg($msg); ?>
</div>
</div>
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>Add New Product</span>
</strong>
</div>
<div class="panel-body">
<div class="col-md-7">
<form method="post" action="edit_product.php?id=<?php echo (int)$product['id'] ?>">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-th-large"></i>
</span>
<input type="text" class="form-control" name="product-title" value="<?php echo remove_junk($product['name']);?>">
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<select class="form-control" name="product-categorie">
<option value=""> Select a categorie</option>
<?php foreach ($all_categories as $cat): ?>
<option value="<?php echo (int)$cat['id']; ?>" <?php if($product['categorie_id'] === $cat['id']): echo "selected"; endif; ?> >
<?php echo remove_junk($cat['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<select class="form-control" name="product-photo">
<option value=""> No image</option>
<?php foreach ($all_photo as $photo): ?>
<option value="<?php echo (int)$photo['id'];?>" <?php if($product['media_id'] === $photo['id']): echo "selected"; endif; ?> >
<?php echo $photo['file_name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="qty">Quantity</label>
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-shopping-cart"></i>
</span>
<input type="number" class="form-control" name="product-quantity" value="<?php echo remove_junk($product['quantity']); ?>">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="qty">Buying price</label>
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-usd"></i>
</span>
<input type="number" class="form-control" name="buying-price" value="<?php echo remove_junk($product['buy_price']);?>">
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="qty">Selling price</label>
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-usd"></i>
</span>
<input type="number" class="form-control" name="saleing-price" value="<?php echo remove_junk($product['sale_price']);?>">
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
</div>
</div>
<button type="submit" name="product" class="btn btn-danger">Update</button>
</form>
</div>
</div>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>