001.
<?php
002.
003.
session_start();
004.
005.
if
(!
$_SESSION
[
'userid'
]){
006.
header(
"Location: index.php"
);
007.
008.
}
else
{
009.
010.
$con
= mysqli_connect(
"localhost"
,
"root"
,
""
,
"databaseanysupply"
)
or
die
(
"Error: "
. mysqli_error(
$con
));
011.
mysqli_query(
$con
,
"SET NAMES 'utf8' "
);
012.
error_reporting
(
error_reporting
() & ~E_NOTICE );
013.
date_default_timezone_set(
'Asia/Bangkok'
);
014.
?>
015.
016.
<!DOCTYPE html>
017.
<html lang=
"en"
dir=
"ltr"
>
018.
<head>
019.
<meta charset=
"UTF-8"
>
020.
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
021.
<meta http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
022.
<link rel=
"stylesheet"
href=
"styleAdminMain.css"
>
027.
029.
030.
<title>Site Page</title>
031.
</head>
032.
<body>
033.
<?php
034.
$sql_provinces
=
"SELECT * FROM provinces"
;
035.
$query
= mysqli_query(
$con
,
$sql_provinces
);
036.
?>
037.
038.
<!-- Popper JS -->
040.
041.
<!-- Latest compiled JavaScript -->
043.
045.
047.
048.
049.
050.
<script type=
"text/javascript"
>
051.
$(document).ready(
function
(){
052.
053.
showAllUsers();
054.
055.
function
showAllUsers(){
056.
$.ajax({
057.
url:
"actionsite.php"
,
058.
type:
"POST"
,
059.
data: {action:
"view"
},
060.
success:
function
(response){
061.
062.
$(
"#showUser"
).html(response);
063.
$(
"table"
).DataTable({
064.
order: [0,
'desc'
]
065.
});
066.
}
067.
});
068.
}
069.
070.
071.
072.
$(
"#insert"
).click(
function
(e){
073.
if
($(
"#form-data"
)[0].checkValidity()){
074.
e.preventDefault();
075.
$.ajax({
076.
url:
"actionsite.php"
,
077.
type:
"POST"
,
078.
data: $(
"#form-data"
).serialize()+
"&action=insert"
,
079.
success:
function
(response){
080.
Swal.fire({
081.
title:
'Add Successfully!'
,
082.
icon:
'success'
083.
})
084.
$(
"#addModal"
).modal(
'hide'
);
085.
$(
"#form-data"
)[0].reset();
086.
showAllUsers();
087.
}
088.
});
089.
}
090.
});
091.
092.
$(
"body"
).on(
"click"
,
".editBtn"
,
function
(e){
093.
e.preventDefault();
094.
edit_id = $(this).attr(
'id'
);
095.
$.ajax({
096.
url:
"actionsite.php"
,
097.
type:
"POST"
,
098.
data: {edit_id:edit_id},
099.
success:
function
(response){
100.
datasite = JSON.parse(response);
101.
$(
"#Siteid"
).val(datasite.Siteid);
102.
$(
"#sname"
).val(datasite.Sitename);
103.
$(
"#slocation"
).val(datasite.Sitelocation);
104.
}
105.
});
106.
});
107.
108.
109.
110.
$(
"#update"
).click(
function
(e){
111.
if
($(
"#edit-form-data"
)[0].checkValidity()){
112.
e.preventDefault();
113.
$.ajax({
114.
url:
"actionsite.php"
,
115.
type:
"POST"
,
116.
data: $(
"#edit-form-data"
).serialize()+
"&action=update"
,
117.
success:
function
(response){
118.
Swal.fire({
119.
title:
'Update Successfully!'
,
120.
icon:
'success'
121.
})
122.
$(
"#editModal"
).modal(
'hide'
);
123.
$(
"#edit-form-data"
)[0].reset();
124.
showAllUsers();
125.
}
126.
});
127.
}
128.
});
129.
130.
131.
$(
"body"
).on(
"click"
,
".delBtn"
,
function
(e){
132.
e.preventDefault();
133.
var
tr = $(this).closest(
'tr'
);
134.
del_id = $(this).attr(
'id'
);
135.
Swal.fire({
136.
title:
'Are you sure?'
,
137.
text:
"You won't be able to revert this!"
,
138.
icon:
'warning'
,
139.
showCancelButton: true,
140.
confirmButtonColor:
'#3085d6'
,
141.
cancelButtonColor:
'#d33'
,
142.
confirmButtonText:
'Yes, delete it!'
143.
}).then((result) => {
144.
if
(result.value) {
145.
$.ajax({
146.
url:
"actionsite.php"
,
147.
type:
"POST"
,
148.
data:{del_id: del_id},
149.
success:
function
(response){
150.
tr.css(
'background-color'
,
'#ff6666'
);
151.
Swal.fire(
152.
'Deleted!'
,
153.
'Deleted Successfully'
,
154.
'success'
155.
)
156.
showAllUsers();
157.
}
158.
});
159.
}
160.
});
161.
});
162.
163.
164.
$(
"body"
).on(
"click"
,
".infoBtn"
,
function
(e){
165.
e.preventDefault();
166.
info_id = $(this).attr(
'id'
);
167.
$.ajax({
168.
url:
"actionsite.php"
,
169.
type:
"POST"
,
170.
data:{info_id:info_id},
171.
success:
function
(response){
172.
173.
datasite = JSON.parse(response);
174.
Swal.fire({
175.
title:
'<strong>Site Info: ID('
+datasite.Siteid+
')</strong>'
,
176.
icon:
'info'
,
177.
html:
'<b>ชื่อสถานที่ :</b>'
+datasite.Sitename+
'<br><b>ที่อยู่สถานที่ :</b>'
+datasite.Sitelocation,
178.
showCancelButton: true,
179.
})
180.
}
181.
});
182.
});
183.
});
184.
185.
</script>
186.
187.
188.
<div
class
=
"wrapper"
>
189.
190.
<div
class
=
"header"
>
191.
<div
class
=
"header-menu"
>
192.
<div
class
=
"sidebar-btn"
>
193.
<i
class
=
"fas fa-bars"
></i>
194.
</div>
195.
<div
class
=
"title"
>Any <span>Supply</span></div>
196.
<ul>
197.
<li><a href=
"userprofile_page.php"
><i
class
=
"fas fa-user"
></i></a></li>
198.
<li><a href=
"logout.php"
><i
class
=
"fas fa-power-off"
></i></a></li>
199.
</ul>
200.
</div>
201.
</div>
202.
203.
204.
<div
class
=
"sidebar"
>
205.
<div
class
=
"sidebar-menu"
>
206.
<center
class
=
"profile"
>
207.
<img src=
"img/userpiclogo.jpg"
class
=
"profile_image"
alt=
""
>
208.
<p><?php
echo
$_SESSION
[
'user'
].
" "
.
$_SESSION
[
'lastname'
]; ?></p>
209.
</center>
210.
211.
<li
class
=
"item"
id=
"member"
>
212.
<a href=
"#member"
class
=
"menu-btn"
>
213.
<i
class
=
"fas fa-user-circle"
></i><span>Member<i
class
=
"fas fa-chevron-down drop-down"
>
214.
</i></span>
215.
</a>
216.
<div
class
=
"sub-menu"
>
217.
<a href=
"registermember.php"
><i
class
=
"fas fa-folder-plus"
></i><span>ผูัใช้งาน</span></a>
218.
<a href=
"site.php"
><i
class
=
"fas fa-folder-plus"
></i><span>Site</span></a>
219.
</div>
220.
</li>
221.
222.
<li
class
=
"item"
>
223.
<a href=
"location.php"
class
=
"menu-btn"
>
224.
<i
class
=
"fa fa-map-marker"
></i><span>FixMap</span>
225.
</a>
226.
</li>
227.
228.
<li
class
=
"item"
id=
"messages"
>
229.
<a href=
"#messages"
class
=
"menu-btn"
>
230.
<i
class
=
"fas fa-comment-alt"
></i><span>Inquire<i
class
=
"fas fa-chevron-down drop-down"
>
231.
</i></span>
232.
</a>
233.
<div
class
=
"sub-menu"
>
234.
<a href=
"JobOrder_Admin.php"
><i
class
=
"fas fa-folder-plus"
></i><span>JobOrder</span></a>
235.
<a href=
"#"
><i
class
=
"fas fa-folder-plus"
></i><span>JobOrderIS</span></a>
236.
<a href=
"#"
><i
class
=
"fas fa-folder-plus"
></i><span>JobOrderPM</span></a>
237.
</div>
238.
</li>
239.
240.
<li
class
=
"item"
id=
"master"
>
241.
<a href=
"#master"
class
=
"menu-btn"
>
242.
<i
class
=
"fas fa-database"
></i><span>Master Data<i
class
=
"fas fa-chevron-down drop-down"
>
243.
</i></span>
244.
</a>
245.
<div
class
=
"sub-menu"
>
246.
<a href=
"#"
><i
class
=
"fas fa-globe-asia"
></i><span>Sites</span></a>
247.
<a href=
"#"
><i
class
=
"fab fa-product-hunt"
></i><span>Product Site</span></a>
248.
<a href=
"#"
><i
class
=
"fas fa-user-secret"
></i><span>Customer</span></a>
249.
<a href=
"#"
><i
class
=
"far fa-address-book"
></i><span>Contracts</span></a>
250.
<a href=
"#"
><i
class
=
"fas fa-file-signature"
></i><span>ตรวจสอบสัญญาบริการ</span></a>
251.
</div>
252.
</li>
253.
254.
</div>
255.
</div>
256.
257.
<div
class
=
"main-container"
>
258.
<div
class
=
"tableJobOrder"
>
259.
<div
class
=
"row"
>
260.
<div
class
=
"col-lg-12"
>
261.
<h4
class
=
"text-center text-danger font-weight-normal my-3"
>Site</h4>
262.
</div>
263.
</div>
264.
265.
<div
class
=
"row"
>
266.
<div
class
=
"col-lg-6"
>
267.
<h4
class
=
"mt-2 text-primary"
>All Site in database!</h4>
268.
</div>
269.
<div
class
=
"col-lg-6"
>
270.
<button type=
"button"
class
=
"btn btn-primary m-1 float-right"
data-toggle=
"modal"
data-target=
"#addModal"
><i
class
=
"fas fa-map-marker fa-lg"
> </i>Add Site</button>
271.
272.
<a href=
"actionsite.php?export=excel"
class
=
"btn btn-success m-1 float-right"
><i
class
=
"fas fa-table fa-lg"
></i> Export to Excel</a>
273.
274.
</div>
275.
</div>
276.
<hr
class
=
"my-1"
>
277.
<div
class
=
"row"
>
278.
<div
class
=
"col-lg-12"
>
279.
<div
class
=
"table-responsive"
id=
"showUser"
>
280.
<h3
class
=
"text-center text-success"
style=
"margin-top:150"
>Loading...</h3>
281.
</div>
282.
</div>
283.
</div>
284.
</div>
285.
286.
<!-- Add New -->
287.
<div
class
=
"modal fade"
id=
"addModal"
>
288.
<div
class
=
"modal-dialog modal-dialog-centered"
>
289.
<div
class
=
"modal-content"
>
290.
291.
<!-- Modal Header -->
292.
<div
class
=
"modal-header"
>
293.
<h4
class
=
"modal-title"
>SiteJob</h4>
294.
<button type=
"button"
class
=
"close"
data-dismiss=
"modal"
>×</button>
295.
</div>
296.
297.
<!-- Modal body -->
298.
<div
class
=
"modal-body px-4"
>
299.
<form action=
""
method=
"post"
id=
"form-data"
>
300.
<div
class
=
"form-group"
>
301.
<input type=
"text"
name=
"sname"
class
=
"form-control"
placeholder=
"Site Name"
require
>
302.
</div>
303.
<div
class
=
"form-group"
>
304.
<input type=
"text"
name=
"slocation"
class
=
"form-control"
placeholder=
"Site Location"
require
>
305.
</div>
306.
307.
<div
class
=
"form-group"
>
308.
<label
for
=
"sel1"
>จังหวัด:</label>
309.
<select
class
=
"form-control"
name=
"provinces"
id=
"provinces"
>
310.
<option value=
""
selected disabled>-กรุณาเลือกจังหวัด-</option>
311.
<?php
foreach
(
$query
as
$value
) { ?>
312.
<option value=
"<?=$value['id']?>"
><?=
$value
[
'name_th'
]?></option>
313.
<?php } ?>
314.
</select>
315.
<br>
316.
<label
for
=
"sel1"
>อำเภอ:</label>
317.
<select
class
=
"form-control"
name=
"amphures"
id=
"amphures"
>
318.
</select>
319.
<br>
320.
321.
<label
for
=
"sel1"
>ตำบล:</label>
322.
<select
class
=
"form-control"
name=
"districts"
id=
"districts"
>
323.
</select>
324.
<br>
325.
326.
<label
for
=
"sel1"
>รหัสไปรษณีย์:</label>
327.
<input type=
"text"
name=
"zip_code"
id=
"zip_code"
class
=
"form-control"
>
328.
<br>
329.
</div>
330.
331.
<div
class
=
"form-group"
>
332.
<input type=
"submit"
name=
"insert"
id=
"insert"
value=
"เพิ่ม"
class
=
"btn btn-success btn-block"
>
333.
</div>
334.
</form>
335.
</div>
336.
</div>
337.
</div>
338.
</div>
339.
340.
<!-- Edit New -->
341.
<div
class
=
"modal fade"
id=
"editModal"
>
342.
<div
class
=
"modal-dialog modal-dialog-centered"
>
343.
<div
class
=
"modal-content"
>
344.
345.
<!-- Modal Header -->
346.
<div
class
=
"modal-header"
>
347.
<h4
class
=
"modal-title"
>Edit SiteJob</h4>
348.
<button type=
"button"
class
=
"close"
data-dismiss=
"modal"
>×</button>
349.
</div>
350.
351.
<!-- Modal body -->
352.
<div
class
=
"modal-body px-4"
>
353.
<form action=
""
method=
"post"
id=
"edit-form-data"
>
354.
<input type=
"hidden"
name=
"Siteid"
id=
"Siteid"
>
355.
<div
class
=
"form-group"
>
356.
<input type=
"text"
name=
"sname"
class
=
"form-control"
id=
"sname"
require
>
357.
</div>
358.
<div
class
=
"form-group"
>
359.
<input type=
"text"
name=
"slocation"
class
=
"form-control"
id=
"slocation"
require
>
360.
</div>
361.
<div
class
=
"form-group"
>
362.
<input type=
"submit"
name=
"update"
id=
"update"
value=
"UPDATE"
class
=
"btn btn-primary btn-block"
>
363.
</div>
364.
</form>
365.
</div>
366.
</div>
367.
</div>
368.
</div>
369.
</div>
370.
</div>
371.
</div>
372.
373.
374.
</body>
375.
</html>
376.
<?php
include
(
'script.php'
);?>
377.
<?php } ?>