/var/www/hkosl.com/innoutstorage/webadmin/master_room_modify.php


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
<?php
    
require_once('check_login.php');

    
//checking
    
$message "";

    if(!isset(
$_POST["is_onlinesales"])){
        
$message .= "請選擇可否在網上預訂此尺寸的倉。\\n\\n";
    }else{
        if(
$_POST["is_onlinesales"] == 1){
            if(!
is_numeric($_POST["remain_room"]) || $_POST["remain_room"] < 0){
                
$message .= "保留單位須為數字。\\n\\n";
            }else{
                if(
$_POST["remain_room"] > $_POST["total_room"]){
                    
$message .= "保留單位不能大於單位總數。\\n\\n";
                }else{
                    
$remain_room $_POST["remain_room"];
                }
            }
        }else{
            
$remain_room 0;
        }
    }


    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;
    }

    
$master_room_id = (int)$_POST["master_room_id"];
    
$discounted_price $_POST["discounted_price"];
    
$effectivedate_from $_POST["effectivedate_from"];
    
$effectivedate_to $_POST["effectivedate_to"];

    
$master_room_info get_master_room($master_room_id);

    
//update master_room
    /*$sql        = "update master_room set has_discounted_price=?, length=?, width=?, height=?, is_onlinesales=?, remain_room=?, lastupdate=?, lastupby=? where id = ?";
    $parameters = array($_POST["has_discounted_price"], $_POST["length"], $_POST["width"], $_POST["height"], $_POST["is_onlinesales"], $remain_room, $nowdate, $_SESSION['cmsloginid'], $master_room_id);*/

    
$sql        "update master_room set has_discounted_price=?, is_onlinesales=?, remain_room=?, lastupdate=?, lastupby=? where id = ?";
    
$parameters = array($_POST["has_discounted_price"], $_POST["is_onlinesales"], $remain_room$nowdate$_SESSION['cmsloginid'], $master_room_id);
    
bind_pdo($sql$parameters);

    
//new add for same display size
    
$sql        "update master_room set has_discounted_price=?, lastupdate=?, lastupby=? where length = ? and width = ? and height = ? and type = ?";
    
$parameters = array($_POST["has_discounted_price"], $nowdate$_SESSION['cmsloginid'], $master_room_info["length"], $master_room_info["width"], $master_room_info["height"], $master_room_info["type"]);
    
bind_pdo($sql$parameters);

    
//update and pricelist table

    /*$result = same_size_master_room($master_room_id);
    if(!empty($result)){
        foreach ($result as $row){*/
            //$master_room_id = $master_room_id;

            
if($_POST["has_discounted_price"] == 1){
                
$sql "update master_room_price set retail_price=?, discounted_price=?, effectivedate_from=?, effectivedate_to=?, lastupdate=?, lastupby=? where master_room_id = ?";
                
$parameters = array(round($_POST["retail_price"], 1), round($_POST["discounted_price"], 1), $_POST["effectivedate_from"], $_POST["effectivedate_to"], $nowdate$_SESSION['cmsloginid'], $master_room_id);
            }else{
                
$sql "update master_room_price set retail_price=?, discounted_price=?, effectivedate_from=?, effectivedate_to=?, lastupdate=?, lastupby=? where master_room_id = ?";
                
$parameters = array(round($_POST["retail_price"], 1), round($_POST["retail_price"]), NULLNULL$nowdate$_SESSION['cmsloginid'], $master_room_id);
            }

            
bind_pdo($sql$parameters);
        
/*}
    }*/

    
$dbh null;

    
header("Location: master_room_index.php?msg=修改成功&location_id=".(int)$_POST["location_id"]);