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
|
<?php require_once('check_login.php');
//checking $message = "";
if(!isset($_POST["is_onlinesales"])){ $message .= "請選擇可否在網上預訂此尺寸的倉。\\n\\n"; }
if(empty($_POST["length"])){ $message .= "請輸入長度。\\n\\n"; }else{ if(!is_numeric($_POST["length"]) || $_POST["length"] <= 0){ $message .= "長度須為正數數字。\\n\\n"; } }
if(empty($_POST["width"])){ $message .= "請輸入闊度。\\n\\n"; }else{ if(!is_numeric($_POST["width"]) || $_POST["width"] <= 0){ $message .= "闊度須為正數數字。\\n\\n"; } }
if(empty($_POST["height"])){ $message .= "請輸入高。\\n\\n"; }else{ if(!is_numeric($_POST["height"]) || $_POST["height"] <= 0){ $message .= "高須為正數數字。\\n\\n"; } }
if(!empty($_POST["length"]) && !empty($_POST["width"]) && !empty($_POST["height"]) ){ $sql = "select * from master_room where length = ? and width = ? and height = ? and deleted = ?"; $parameters = array($_POST["length"], $_POST["width"], $_POST["height"], 0); $result = bind_pdo($sql, $parameters, "selectall");
if(!empty($result)){ $message .= "這個尺寸的單位已經存在。\\n\\n"; } }
if(empty($_POST["retail_price"])){ $message .= "請輸入原價。\\n\\n"; }else{ if(!empty($_POST["retail_price"]) && !is_numeric($_POST["retail_price"])){ $message .= "原價必須為正數數字。\\n\\n"; } }
if($_POST["has_discounted_price"] == 1){ if(!empty($_POST["discounted_price"]) && !is_numeric($_POST["discounted_price"])){ $message .= "優惠價必須為正數數字。\\n\\n"; }
if(!empty($_POST["retail_price"]) && !empty($_POST["discounted_price"]) && $_POST["discounted_price"] > $_POST["retail_price"]){ $message .= "優惠價不能大於原價。\\n\\n"; }
if(!empty($_POST["effectivedate_from"]) && !validateDate($_POST["effectivedate_from"], "Y-m-d")){ $message .= "請輸入正確的開始日期。\\n\\n"; }
if(!empty($_POST["effectivedate_to"]) && !validateDate($_POST["effectivedate_to"], "Y-m-d")){ $message .= "請輸入正確的完結日期。\\n\\n"; }
if(!empty($_POST["effectivedate_from"]) && !empty($_POST["effectivedate_to"]) && $_POST["effectivedate_from"] > $_POST["effectivedate_to"]){ $message .= "開始日期不能大於完結日期。\\n\\n"; } }
if(!empty($message)){ echo "<script>alert('".$message."'); history.back();</script>"; exit; }
$discounted_price = $_POST["discounted_price"]; $effectivedate_from = $_POST["effectivedate_from"]; $effectivedate_to = $_POST["effectivedate_to"];
$sql = "insert into master_room set is_onlinesales=?, remain_room=?, length=?, width=?, height=?, createdate=?, createby=?, lastupdate=?, lastupby=?"; $parameters = array($_POST["is_onlinesales"], $_POST["remain_room"], $_POST["length"], $_POST["width"], $_POST["height"], $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid']);
bind_pdo($sql, $parameters);
$master_room_id = $dbh->lastInsertId();
if($_POST["has_discounted_price"] == 1){ //insert into pricelist table $sql = "insert into master_room_price set master_room_id = ?, retail_price=?, discounted_price=?, effectivedate_from=?, effectivedate_to=?, createdate=?, createby=?, lastupdate=?, lastupby=?"; $parameters = array($master_room_id, round($_POST["retail_price"], 1), round($_POST["discounted_price"], 1), $_POST["effectivedate_from"], $_POST["effectivedate_to"], $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid']); }else{ //insert into pricelist table $sql = "insert into master_room_price set master_room_id = ?, retail_price=?, discounted_price=?, effectivedate_from=?, effectivedate_to=?, createdate=?, createby=?, lastupdate=?, lastupby=?"; $parameters = array($master_room_id, round($_POST["retail_price"], 1), round($_POST["retail_price"], 1), NULL, NULL,$nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid']); }
bind_pdo($sql, $parameters);
$dbh = null;
header("Location: master_room_index.php?msg=新增成功");
|