| 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
 | <?phprequire_once('check_login.php');
 
 $discount_type = (int)$_POST["discount_type"];
 $master_room_info = get_master_room();
 $message = "";
 
 if (!is_numeric($_POST["discount"]) || empty($_POST["discount"]) || $_POST["discount"] <= 0) {
 $message .= "優惠折扣必須輸入正數數字。\\n\\n";
 }
 
 if (empty($_POST["effectivedate_from"])) {
 $message .= "請輸入正確的開始日期。\\n\\n";
 }
 
 if (empty($_POST["effectivedate_to"])) {
 $message .= "請輸入正確的完結日期。\\n\\n";
 }
 
 if ($_POST["effectivedate_from"] > $_POST["effectivedate_to"]) {
 $message .= "開始日期不能大於完結日期。\\n\\n";
 }
 
 if (!empty($_POST["effectivedate_from"]) && !empty($_POST["effectivedate_to"]) && !empty($_POST["master_room_id"]) && !empty($_POST["payment_term"])) {
 /*if($_POST["master_room_id"] == "ALL"){
 foreach($master_room_info as $master_room){
 //need to check if this kind of prepaid discount exist or not
 $sql = "select * from master_room_discount where master_room_id = ? and payment_term = ? and deleted = ? and effectivedate_from <= ? and ? <= effectivedate_to";
 $parameters = array($master_room["id"], $_POST["payment_term"], 0, $_POST["effectivedate_to"], $_POST["effectivedate_from"]);
 $master_room_discount_info = bind_pdo($sql, $parameters, "selectone");
 if(!empty($master_room_discount_info)) {
 $message = $master_room["length"]." X ".$master_room["width"]." X ".$master_room["height"]." 相關的優惠設定已存在。優惠設定取消。";
 
 echo "<script>alert('".$message."'); window.location.href='discount_modifyform.php?id=".$master_room_discount_info["id"]."&discount_type=".$_POST["discount_type"]."'; </script>";
 exit;
 }
 }
 
 }else{*/
 foreach ($_POST["master_room_ids"] as $master_room_id) {
 //bug
 /*$result = same_size_master_room($master_room_id);
 
 foreach ($result as $row){
 $master_room_id = $row["id"];
 
 //need to check if this kind of prepaid discount exist or not
 $sql = "select * from master_room_discount where master_room_id = ? and payment_term = ? and deleted = ? and effectivedate_from <= ? and ? <= effectivedate_to";
 $parameters = array($master_room_id, $_POST["payment_term"], 0, $_POST["effectivedate_to"], $_POST["effectivedate_from"]);
 $master_room_discount_info = bind_pdo($sql, $parameters, "selectone");
 if(!empty($master_room_discount_info)) {
 $message = "相關的優惠設定已存在。優惠設定取消。";
 
 echo "<script>alert('".$message."'); window.location.href='discount_modifyform.php?id=".$master_room_discount_info["id"]."&discount_type=".$_POST["discount_type"]."'; </script>";
 exit;
 }
 }*/
 $sql = "select * from master_room_discount where master_room_id = ? and payment_term = ? and deleted = ? and effectivedate_from <= ? and ? <= effectivedate_to";
 $parameters = array($master_room_id, $_POST["payment_term"], 0, $_POST["effectivedate_to"], $_POST["effectivedate_from"]);
 $master_room_discount_info = bind_pdo($sql, $parameters, "selectone");
 if (!empty($master_room_discount_info)) {
 $message = "相關的優惠設定已存在。優惠設定取消。";
 
 echo "<script>alert('" . $message . "'); window.location.href='discount_modifyform.php?id=" . $master_room_discount_info["id"] . "&discount_type=" . $_POST["discount_type"] . "'; </script>";
 exit;
 }
 
 }
 
 //}
 
 }
 
 if (!empty($message)) {
 echo "<script>alert('" . $message . "'); history.back(); </script>";
 exit;
 }
 
 if (isset($_POST["is_final_discount"])) {
 $is_final_discount = 1;
 } else {
 $is_final_discount = 0;
 }
 
 $pair_key = random_string(32);
 $location_id = (int)$_POST["location_id"]; //f12/14
 foreach ($_POST["master_room_ids"] as $master_room_id) {
 $result = same_size_master_room($master_room_id);
 foreach ($result as $row) {
 $master_room_id = $row["id"];
 $sql = "insert into master_room_discount set is_final_discount=?, master_room_id=?, payment_term=?, discount_type=?, discount=?, effectivedate_from=?, effectivedate_to=?, status=?, createdate=?, createby=?, lastupdate=?, lastupby=?, location_id=?, show_frontend=?, pair_key=?";
 $parameters = array($is_final_discount, $master_room_id, $_POST["payment_term"], "%", $_POST["discount"], $_POST["effectivedate_from"], $_POST["effectivedate_to"], "1", $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid'], $location_id, (int)$_POST["show_frontend"], $pair_key);
 bind_pdo($sql, $parameters);
 }
 }
 
 
 /*if($_POST["master_room_ids"] == "ALL"){
 foreach($master_room_info as $master_room){
 $sql        = "insert into master_room_discount set is_final_discount=?, master_room_id=?, payment_term=?, discount_type=?, discount=?, effectivedate_from=?, effectivedate_to=?, status=?, createdate=?, createby=?, lastupdate=?, lastupby=?, location_id=?, show_frontend=?";
 $parameters = array($is_final_discount, $master_room["id"], $_POST["payment_term"], "%", $_POST["discount"], $_POST["effectivedate_from"], $_POST["effectivedate_to"], "1", $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid'], $location_id, (int)$_POST["show_frontend"]);
 bind_pdo($sql, $parameters);
 }
 }else{
 $sql        = "insert into master_room_discount set is_final_discount=?, master_room_id=?, payment_term=?, discount_type=?, discount=?, effectivedate_from=?, effectivedate_to=?, status=?, createdate=?, createby=?, lastupdate=?, lastupby=?, location_id=?, show_frontend=?";
 $parameters = array($is_final_discount, $_POST["master_room_id"], $_POST["payment_term"], "%", $_POST["discount"], $_POST["effectivedate_from"], $_POST["effectivedate_to"], "1", $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid'], $location_id, (int)$_POST["show_frontend"]);
 bind_pdo($sql, $parameters);
 }*/
 
 $dbh = null;
 
 header("Location: discount_index.php?discount_type=$discount_type&msg=新增成功&location_id=" . (int)$_POST["location_id"]);
 
 
 |