001.
<?php
002.
session_start();
003.
include
(
"connect.php"
);
004.
include
(
"sidebar.php"
);
005.
mysql_query(
"SET NAMES UTF8"
);
006.
?>
007.
<!DOCTYPE html>
008.
<html lang=
"en"
>
009.
<head>
010.
<?php
011.
012.
013.
014.
015.
016.
017.
018.
019.
020.
021.
022.
023.
024.
025.
026.
027.
028.
?>
029.
030.
031.
<!-- <msdropdown> -->
032.
<link rel=
"stylesheet"
type=
"text/css"
href=
"css/msdropdown/dd.css"
/>
033.
<script src=
"js/msdropdown/jquery.dd.js"
></script>
034.
<script language=
"javascript"
>
035.
jQuery(document).ready(
function
(e) {
036.
try {
037.
jQuery(
"body select"
).msDropDown();
038.
} catch(e) {
039.
alert(e.message);
040.
}
041.
});
042.
</script>
043.
<!--
044.
<script language=
"JavaScript"
type=
"text/javascript"
>
045.
$(document).ready(
function
(){
046.
$(
"a.delete"
).click(
function
(e){
047.
if
(!confirm(
'คุณจะลบข้อมูลหรือไม่?'
)){
048.
e.preventDefault();
049.
return
false;
050.
}
051.
return
true;
052.
});
053.
});
054.
</script>
055.
056.
057.
058.
<script>
059.
function
goBack() {
060.
window.history.back();
061.
}
062.
</script>
063.
<!-- โชว์ตัวอย่างรูปที่เลือก -->
064.
<script language=
"JavaScript"
>
065.
function
showPreview(ele)
066.
{
067.
$(
'#imgAvatar'
).attr(
'src'
, ele.value);
068.
if
(ele.files && ele.files[0]) {
069.
070.
var
reader =
new
FileReader();
071.
072.
reader.onload =
function
(e) {
073.
$(
'#imgAvatar'
).attr(
'src'
, e.target.result);
074.
}
075.
076.
reader.readAsDataURL(ele.files[0]);
077.
}
078.
}
079.
</script>
080.
081.
<style type=
"text/css"
>
082.
#thumbnail img{width:120px;height:120px;margin:5px;}
083.
canvas{border:1px solid red;}
084.
</style>
085.
086.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
087.
<title>SC Sticker</title>
088.
</head>
089.
<body>
090.
091.
<?php
092.
093.
$test_id
=
"select MAX(SUBSTRING(mat_id,6)) as num from material "
;
094.
$tmp
= mysql_query(
$test_id
)
or
die
(mysql_error().
" Error Query ["
.
$test_id
.
"]"
);
095.
$rows
= mysql_fetch_array(
$tmp
);
096.
if
(
$rows
){
097.
$num
=
$rows
[
'num'
];
098.
if
(
$num
==Null){
099.
$num
= 0;
100.
}
101.
$test_id
=
$num
+1;
102.
if
(
$test_id
< 10){
103.
$mat_id
=
"MAT000"
.
$test_id
;
104.
}
105.
elseif
(
$test_id
< 100) {
106.
$mat_id
=
"MAT00"
.
$test_id
;
107.
}
108.
elseif
(
$test_id
< 1000) {
109.
$mat_id
=
"MAT0"
.
$test_id
;
110.
}
111.
}
112.
?>
113.
<?php
114.
if
(isset(
$_POST
[
'submit'
]))
115.
{
116.
$mat_id
= mysql_real_escape_string(htmlspecialchars(
$_POST
[
'mat_id'
]));
117.
$mat_name
= mysql_real_escape_string(htmlspecialchars(
$_POST
[
'mat_name'
]));
118.
$color_id
= mysql_real_escape_string(htmlspecialchars(
$_POST
[
'color_id'
]));
119.
$brand_id
=mysql_real_escape_string(htmlspecialchars(
$_POST
[
'brand_id'
]));
120.
121.
$typemat_id
=mysql_real_escape_string(htmlspecialchars(
$_POST
[
'typemat_id'
]));
122.
$mat_point_order
=mysql_real_escape_string(htmlspecialchars(
$_POST
[
'mat_point_order'
]));
123.
$mat_amount
=mysql_real_escape_string(htmlspecialchars(
$_POST
[
'mat_amount'
]));
124.
$unit_id
=mysql_real_escape_string(htmlspecialchars(
$_POST
[
'unit_id'
]));
125.
$costprice
=mysql_real_escape_string(htmlspecialchars(
$_POST
[
'costprice'
]));
126.
$mat_pic
=
$_FILES
[
'mat_pic'
][
'tmp_name'
];
127.
$mat_pic_name
=
$_FILES
[
'mat_pic'
][
'name'
];
128.
129.
mysql_query(
"SET character_set_results=utf8"
);
130.
mysql_query(
"SET character_set_client=utf8"
);
131.
mysql_query(
"SET character_set_connection=utf8"
);
132.
133.
134.
if
(
$mat_amount
<=0) {
135.
echo
"<script language=\"javascript\">"
;
136.
echo
"alert('กรุณากรอกจำนวนใหม่อีกครั้ง');"
;
137.
echo
"window.location='history.back()"
;
138.
echo
"</script>"
;
139.
exit
();
140.
}
141.
$sq
=
"SELECT mat_id FROM material ORDER BY mat_id "
;
142.
$result
= mysql_query(
$sq
)
143.
or
die
(mysql_error());
144.
145.
while
(
$row
= mysql_fetch_array(
$result
))
146.
{
147.
$sq2
=
$mat_id
;
148.
}
149.
150.
if
(
$mat_pic
){
151.
$arraypic
=
explode
(
"."
,
$mat_pic_name
);
152.
$filename
=
$sq2
;
153.
$filetype
=
$arraypic
[1];
154.
$filetyper
=
"jpg"
;
155.
156.
if
(
$filetype
==
"jpg"
||
$filetype
==
"jpeg"
||
$filetype
==
"png"
157.
||
$filetype
==
"gif"
){
158.
159.
$newimage
=
$filename
.
"."
.
$filetyper
;
160.
161.
$mat_path
=
'C:/xampp/htdocs/scsticker_test/img/mat_img/'
.
$newimage
;
162.
163.
copy
(
$mat_pic
,
"img/mat_img/"
.
$newimage
);
164.
}
else
{
165.
echo
"<h3>ERROR : ไม่สามารถ Upload รูปภาพ</h3>"
;
166.
}
167.
}
168.
$query
= mysql_query(
"SELECT COUNT(mat_name) FROM material WHERE mat_name = '"
.
$mat_name
.
"'"
);
169.
$row2
= mysql_fetch_array(
$query
);
170.
171.
if
(
$row2
[0] > 0) {
172.
$message
=
"ข้อมูลซ้ำซ้อน"
;
173.
echo
"<script type='text/javascript'>alert('$message');</script>"
;
174.
echo
'<script>location = "material.php"</script>'
;
175.
}
176.
else
if
(
$row2
[0]==0)
177.
{
178.
$message
=
"เพิ่มข้อมูลสำเร็จ"
;
179.
echo
"<script type='text/javascript'>alert('$message');</script>"
;
180.
$sql
= "INSERT INTO `scsticker`.`material` (`mat_id`, `mat_name`, `color_id`, `brand_id`, `mat_pic`, `typemat_id`, `mat_point_order`, `mat_amount`, `unit_id`, `costprice`)
181.
VALUES (
'".$mat_id."'
,
'".$mat_name."'
,
'".$color_id."'
,
'".$brand_id."'
,
'".$mat_path."'
,
'".$typemat_id."'
,
'".$mat_point_order."'
,
'".$mat_amount."'
,
'".$unit_id."'
,
'".$costprice."'
)";
182.
183.
mysql_query(
$sql
)
or
die
(mysql_error());
184.
echo
'<script>location = "material_show.php"</script>'
;
185.
}
186.
}
187.
188.
?>
189.
190.
<section id=
"main-content"
> <!-- อย่าลบเลย -->
191.
<section
class
=
"wrapper"
> <!-- อย่าลบเลย -->
192.
<!--overview start-->
193.
<div
class
=
"row"
>
194.
<div
class
=
"row"
>
195.
<!-- <div
class
=
"col-lg-12"
> -->
196.
197.
198.
199.
200.
201.
202.
<div
class
=
"panel panel-default"
>
203.
<div
class
=
"panel-body"
>
204.
<ol
class
=
"breadcrumb"
>
205.
<li><i
class
=
"fa fa-home"
></i><a href=
"index.html"
>หน้าเเรก</a></li>
206.
<li><i
class
=
"fa fa-laptop"
></i><a href=
"material_show.php"
>ข้อมูลวัสดุ</a></li>
207.
<li><i
class
=
"fa fa-laptop"
></i>เพิ่มข้อมูลวัสดุ</li>
208.
</ol>
209.
<h3
class
=
"page-header"
><i
class
=
"fa fa-laptop"
></i> เพิ่มข้อมูลวัสดุ</h3>
210.
211.
212.
213.
<div
class
=
"row"
>
214.
215.
216.
217.
<form action=
""
method=
"post"
id=
"form"
enctype=
"multipart/form-data"
>
218.
219.
<div
class
=
"col-sm-2"
></div>
220.
<div
class
=
"col-sm-2"
>รหัสวัสดุ</div>
221.
<div
class
=
"col-sm-8"
><input
class
=
"form-control"
style=
"width:300px;"
id=
"mat_id"
name=
"mat_id"
type=
"text"
readonly=
"readonly"
value=
"<?=$mat_id?>"
></div>
222.
223.
<div
class
=
"col-sm-2"
></div>
224.
<div
class
=
"col-sm-2"
>ชื่อวัสดุ<font color=
"red"
> *</font></div>
225.
<div
class
=
"col-sm-8"
><input
class
=
"form-control"
id=
"mat_name"
name=
"mat_name"
style=
"width:300px;"
></div>
226.
227.
<div
class
=
"col-sm-2"
></div>
228.
<div
class
=
"col-sm-2"
>สี<font color=
"red"
> *</font></div>
229.
<div
class
=
"col-sm-8"
><select name=
"color_id"
class
=
"form-control"
style=
"width:300px;"
>
230.
<?php
231.
$result1
= mysql_query(
"SELECT * FROM color ORDER BY color_name"
)
or
die
(mysql_error());
232.
while
(
$row1
= mysql_fetch_array(
$result1
))
233.
{
234.
?>
235.
<option value=
"<?php echo $row1["
color_id
"]?>"
data-image=
"img/color/<?=$row1['color_id']?>.jpg"
></option>
236.
<?php
237.
}
238.
?>
239.
</select>
240.
</div>
241.
242.
<div
class
=
"col-sm-2"
></div>
243.
<div
class
=
"col-sm-2"
>ยี่ห้อ<font color=
"red"
> *</font></div>
244.
<div
class
=
"col-sm-8"
><select name=
"brand_id"
class
=
"form-control"
style=
"width:300px;"
>
245.
<?php
246.
$result
= mysql_query(
"SELECT * FROM brand ORDER BY brand_name"
)
or
die
(mysql_error());
247.
while
(
$row
= mysql_fetch_array(
$result
))
248.
{
249.
?>
250.
<option value=
"<?php echo $row["
brand_id
"]?>"
><?php
echo
$row
[
"brand_name"
]?></option>
251.
<?php
252.
}
253.
?>
254.
</select>
255.
</div>
256.
257.
<div
class
=
"col-sm-2"
></div>
258.
<div
class
=
"col-sm-2"
>ประเภทวัสดุ<font color=
"red"
> *</font></div>
259.
<div
class
=
"col-sm-8"
><select name=
"typemat_id"
class
=
"form-control"
style=
"width:300px;"
>
260.
<?php
261.
$result
= mysql_query(
"SELECT * FROM type_material "
)
or
die
(mysql_error());
262.
while
(
$row
= mysql_fetch_array(
$result
))
263.
{
264.
?>
265.
<option value=
"<?php echo $row["
typemat_id
"]?>"
><?php
echo
$row
[
"typemat_name"
]?></option>
266.
<?php
267.
}
268.
?>
269.
</select>
270.
</div>
271.
272.
<div
class
=
"col-sm-2"
></div>
273.
<div
class
=
"col-sm-2"
>จุดสั่งซื้อ<font color=
"red"
> *</font></div>
274.
<div
class
=
"col-sm-8"
><input
class
=
"form-control"
id=
"mat_point_order"
name=
"mat_point_order"
style=
"width:300px;"
></div>
275.
276.
<div
class
=
"col-sm-2"
></div>
277.
<div
class
=
"col-sm-2"
>จำนวน<font color=
"red"
> *</font></div>
278.
<div
class
=
"col-sm-8"
><input
class
=
"form-control"
id=
"mat_amount"
name=
"mat_amount"
style=
"width:300px;"
></div>
279.
280.
<div
class
=
"col-sm-2"
></div>
281.
<div
class
=
"col-sm-2"
>หน่วยนับ<font color=
"red"
> *</font></div>
282.
<div
class
=
"col-sm-8"
><select name=
"unit_id"
class
=
"form-control"
style=
"width:300px;"
>
283.
<?php
284.
$result
= mysql_query(
"SELECT * FROM unit WHERE typeun_name = 'สินค้า'"
)
or
die
(mysql_error());
285.
while
(
$row
= mysql_fetch_array(
$result
))
286.
{
287.
?>
288.
<option value=
"<?php echo $row["
unit_id
"]?>"
><?php
echo
$row
[
"unit_name"
]?></option>
289.
<?php
290.
}
291.
?>
292.
</select>
293.
</div>
294.
295.
<div
class
=
"col-sm-2"
></div>
296.
<div
class
=
"col-sm-2"
>ราคาต้นทุน(บาท)<font color=
"red"
> *</font></div>
297.
<div
class
=
"col-sm-8"
><input
class
=
"form-control"
id=
"costprice"
name=
"costprice"
style=
"width:300px;"
></div>
298.
299.
<!-- <div
class
=
"col-sm-9"
> </div> <!-- <div id=
"thumbnail"
></div> -->
300.
<div
class
=
"col-sm-2"
></div>
301.
<div
class
=
"col-sm-2"
>รูปภาพ<font color=
"red"
> *</font></div>
302.
<div
class
=
"col-sm-8"
display:inline><input type=
"file"
name=
"mat_pic"
id=
"filUpload"
size=
"35"
OnChange=
"showPreview(this)"
></div>
303.
304.
305.
<div
class
=
"col-sm-2"
></div>
306.
<div
class
=
"col-sm-2"
></div><br>
307.
<div
class
=
"col-sm-8"
><img id=
"imgAvatar"
width=
"300px"
height=
"140px"
></div>
308.
309.
310.
<div
class
=
"col-sm-6"
><br><button type=
"submit"
class
=
"btn btn-success "
value=
"submit"
name=
"submit"
style=
"width: 120px; float: right;"
>เพิ่มข้อมูล</button></div>
311.
<div
class
=
"col-sm-6"
><br><button type=
"button"
class
=
"btn btn-danger "
style=
"width: 120px; float: left;"
value=
"Reload Page"
onClick=
"window.location.reload()"
>ล้างข้อมูล</button></div>
312.
313.
314.
</form>
315.
</div>
316.
<br>
317.
</div>
318.
</div>
319.
</div>
320.
</div>
321.
</div>
322.
323.
</div>
324.
325.
326.
<script language=
"javascript"
>
327.
$(document).ready(
function
() {
328.
$(
'#dataTables-example'
).DataTable({
329.
responsive: true,
330.
"bFilter"
: false
331.
});
332.
});
333.
334.
</script>
335.
<script>
336.
$(document).ready(
function
() {
337.
$(
"input#submit"
).click(
function
(){
338.
$.ajax({
339.
type:
"POST"
,
340.
url:
"process.php"
,
341.
data: $(
'form.contact'
).serialize(),
342.
success:
function
(msg){
343.
$(
"#thanks"
).html(msg)
344.
$(
"#form-content"
).modal(
'hide'
);
345.
346.
},
347.
error:
function
(){
348.
alert(
"failure"
);
349.
}
350.
});
351.
});
352.
});
353.
</script>
354.
<script>
355.
$(document).on(
"click"
,
".open-EditDialog"
,
function
() {
356.
var
id = $(this).data(
'id'
);
357.
var
name = $(this).data(
'name'
);
358.
$(
".modal-body #id"
).val( id );
359.
$(
".modal-body #name"
).val( name );
360.
});
361.
</script>
362.
</body>
363.
</html>