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
|
<?php require_once('check_login.php'); $discount_type = (int)$_POST["discount_type"]; $discount_id = (int)$_POST["discount_id"]; $master_room_id = (int)$_POST["master_room_id"];
if (!empty($_POST["effectivedate_from"]) && !empty($_POST["effectivedate_to"]) && !empty($_POST["master_room_id"]) && !empty($_POST["payment_term"])) {
//bug /*$result = same_size_master_room($master_room_id);
foreach ($result as $row) { //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 and id != ?"; $parameters = array($row["id"], $_POST["payment_term"], 0, $_POST["effectivedate_to"], $_POST["effectivedate_from"], $discount_id); $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; } }*/
//bug fix 20180823
$sql = "select * from master_room_discount where master_room_id = ? and payment_term = ? and deleted = ? and effectivedate_from <= ? and ? <= effectivedate_to and id != ?"; $parameters = array($master_room_id, $_POST["payment_term"], 0, $_POST["effectivedate_to"], $_POST["effectivedate_from"], $discount_id); $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; } }
$discount_type = $_POST["discount_type"]; $message = "";
if (empty($_POST["effectivedate_from"])) { $message .= "請輸入正確的開始日期。\\n\\n"; }
if (empty($_POST["effectivedate_to"])) { $message .= "請輸入正確的完結日期。\\n\\n"; }
if (!is_numeric($_POST["discount"]) || empty($_POST["discount"]) || $_POST["discount"] <= 0) { $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; }
if (isset($_POST["is_final_discount"])) { $is_final_discount = 1; } else { $is_final_discount = 0; }
$sql = "update master_room_discount set is_final_discount=?, discount=?, effectivedate_from=?, effectivedate_to=?, lastupdate=?, lastupby=?, show_frontend=? where id=?"; $parameters = array($is_final_discount, $_POST["discount"], $_POST["effectivedate_from"], $_POST["effectivedate_to"], $nowdate, $_SESSION['cmsloginid'], (int)$_POST["show_frontend"], $discount_id); bind_pdo($sql, $parameters);
$master_room_discount = get_master_room_discount($discount_id);
$result = same_size_master_room($master_room_id);
foreach ($result as $row) { $master_room_id = $row["id"]; $sql = "update master_room_discount set is_final_discount=?, discount=?, effectivedate_from=?, effectivedate_to=?, lastupdate=?, lastupby=?, show_frontend=? where payment_term=? and master_room_id=? and pair_key=?"; $parameters = array($is_final_discount, $_POST["discount"], $_POST["effectivedate_from"], $_POST["effectivedate_to"], $nowdate, $_SESSION['cmsloginid'], (int)$_POST["show_frontend"], $_POST["payment_term"], $master_room_id, $master_room_discount["pair_key"]);
bind_pdo($sql, $parameters); }
header("Location: discount_index.php?discount_type=$discount_type&msg=新增成功&location_id=" . (int)$_POST["location_id"]);
|