-
Notifications
You must be signed in to change notification settings - Fork 0
/
product-form.php
254 lines (211 loc) · 9.08 KB
/
product-form.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
<?php include("inc_connect.php");?>
<?php if($_SESSION["LOGIN_OK"]!=true || $_SESSION["LOGIN_LEVEL"]<=0) { header("location: logout.php"); } ?>
<?php
if($_POST["code"]!="" && $_POST["name"]!="" ) {
$SQL = "select * from tb_product where code='".$_POST["code"]."' and pro_id<>'".$_POST["pro_id"]."'";
$result = mysqli_query($mysqli, $SQL) or die(mysqli_error($mysqli).$SQL);
if(mysqli_num_rows($result)>0) {
alert("รหัสสินค้าซ้ำ โปรดลองใหม่อีกครั้ง","");
}
if($_FILES["file"]["tmp_name"]!="") {
@unlink("images-upload/".$_POST["picture"]);
$filename = $_FILES["file"]["name"];
$arr = explode(".",$filename);
$picture = date("YmdHis").".".end($arr);
move_uploaded_file($_FILES["file"]["tmp_name"], "images-upload/".$picture);
} else {
$picture = $_POST["picture"];
}
if($_POST["pro_id"]==0) {
$SQL = "insert into tb_product (
code,
name,
detail,
picture,
qty,
cost,
price,
confirm,
lastupdate
) values (
'".$_POST["code"]."',
'".$_POST["name"]."',
'".$_POST["detail"]."',
'".$picture."',
'".$_POST["qty"]."',
'".$_POST["cost"]."',
'".$_POST["price"]."',
1,
'".date("Y-m-d H:i:s")."'
)";
} else {
$SQL = "update tb_product set
code='".$_POST["code"]."',
name='".$_POST["name"]."',
detail='".$_POST["detail"]."',
picture='".$picture."',
qty='".$_POST["qty"]."',
cost='".$_POST["cost"]."',
price='".$_POST["price"]."'
where pro_id='".$_POST["pro_id"]."'";
}
mysqli_query($mysqli, $SQL) or die(mysqli_error($mysqli).$SQL);
header("location:product.php");
// alert("บันทึกข้อมูลเสร็จเรียบร้อยแล้ว","product.php");
} elseif($_GET["del"]!="" && $_GET["pro_id"]!="" && $_GET["picture"]!="") {
$SQL = "update tb_product set picture='' where pro_id='".$_GET["pro_id"]."' ";
mysqli_query($mysqli, $SQL) or die(mysqli_error($mysqli).$SQL);
@unlink("images-upload/".$_GET["picture"]);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="ระบบซื้อขายสินค้า">
<meta name="author" content="zues.com">
<meta name="keywords" content="ระบบซื้อขายสินค้า ">
<title>ระบบซื้อขายสินค้า</title>
<link rel="shortcut icon" href="images/zues.jpg">
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="dist/css/offcanvas.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include("inc_menu.php"); ?>
<div class="container">
<?php include("inc_user.php"); ?>
<div class="col-xs-12" style="background-color: #ffffff">
<h4><span class="label label-primary"><i class="glyphicon glyphicon-barcode"></i> ข้อมูลสินค้า</span></h4>
<hr>
<form class="form-horizontal" name="l" id="l" action="?" method="post" enctype="multipart/form-data" onsubmit="return validate();">
<?php
$SQL = "select * from tb_product where pro_id='".$_GET["pro_id"]."'";
$result = mysqli_query($mysqli, $SQL) or die(mysqli_error($mysqli).$SQL);
$tmp = mysqli_fetch_array($result);
?>
<div class="form-group">
<label class="col-sm-2 control-label">รหัสสินค้า</label>
<div class="col-sm-4 col-lg-3">
<input type="text" class="form-control" id="code" name="code" placeholder="ต้องป้อน" maxlength="20" value="<?php print $tmp["code"]?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">ชื่อสินค้า</label>
<div class="col-sm-4 col-lg-3">
<input type="text" class="form-control" id="name" name="name" placeholder="ต้องป้อน" maxlength="150" value="<?php print $tmp["name"]?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">รายละเอียดสินค้า</label>
<div class="col-sm-4 col-lg-3">
<textarea class="form-control" id="detail" name="detail" placeholder="" rows="5"><?php print $tmp["detail"]?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">รูปภาพ</label>
<div class="col-sm-4 col-lg-3">
<input type="file" class="form-control" id="file" name="file">
<?php if($tmp["picture"]!="") { ?>
<br/>
<a href="images-upload/<?php print $tmp["picture"]?>" target="_blink" class="thumbnail"><img src="images-upload/<?php print $tmp["picture"]?>"></a> <a href="?pro_id=<?php print $tmp["pro_id"]?>&del=true&picture=<?php print $tmp["picture"]?>" onclick="return del();"><i class="glyphicon glyphicon-trash"></i> ลบ</a>
<input type="hidden" name="picture" value="<?php print $tmp["picture"]?>">
<?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">ราคาต้นทุน</label>
<div class="col-sm-4 col-lg-3">
<input type="number" class="form-control" id="cost" name="cost" placeholder="ต้องป้อน" maxlength="50" value="<?php print $tmp["cost"]?>" min="0" max="100000000">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">ราคาขาย</label>
<div class="col-sm-4 col-lg-3">
<input type="number" class="form-control" id="price" name="price" placeholder="ต้องป้อน" maxlength="50" value="<?php print $tmp["price"]?>" min="0" max="100000000">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">จำนวนคงเหลือ</label>
<div class="col-sm-4 col-lg-3">
<input type="number" class="form-control" id="qty" name="qty" placeholder="" maxlength="50" value="<?php print $tmp["qty"]?>" min="0" max="100000000" step="1">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-4 col-lg-3">
<button type="submit" class="btn btn-primary">บันทึก</button>
<button type="reset" class="btn btn-default">ยกเลิก</button>
<button type="button" class="btn btn-default" onclick="location.href='product.php';">ย้อนกลับ</button>
<input type="hidden" name="pro_id" value="<?php print $_GET["pro_id"]?>">
</div>
</div>
</form>
</div>
<?php include("inc_footer.php"); ?>
</div><!--/.container-->
<?php include("inc_footerpage.php"); ?>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
<script>
function validate() {
if($('#code').val()=="") {
alert("โปรดป้อนรหัสสินค้า");
$('#code').focus();
return false;
}
if($('#name').val()=="") {
alert("โปรดป้อนชื่อสินค้า");
$('#name').focus();
return false;
}
if($('#cost').val()=="") {
alert("โปรดป้อนราคาต้นทุน");
$('#cost').focus();
return false;
}
if($('#price').val()=="") {
alert("โปรดป้อนราคาขาย");
$('#price').focus();
return false;
}
if($('#qty').val()=="") {
alert("โปรดป้อนจำนวนคงเหลือ");
$('#qty').focus();
return false;
}
if(confirm("คุณต้องการบันทึกข้อมูลหรือไม่?")) {
return true;
} else {
return false;
}
}
function del() {
if(confirm("คุณต้องการลบรูปภาพนี้หรือไม่?")) {
return true;
} else {
return false;
}
}
</script>
</body>
</html>