/var/www/hkosl.com/innoutstorage2019/tc/rent_post.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
    
require_once('../webadmin/basic_info.php');

    
$message "";

    if (empty(
$_POST["billing-form-master-room-id"])) {
        
$message .= "請選擇單位尺碼。\\n\\n";
    }

    if (empty(
$_POST["billing-form-month"])) {
        
$message .= "請選擇租月期。\\n\\n";
    }

    if (empty(
$_POST["billing-form-title"])) {
        
$message .= "請選擇頭銜。\\n\\n";
    }

    if (empty(
$_POST["billing-form-firstname"])) {
        
$message .= "請輸入名字。\\n\\n";
    }

    if (empty(
$_POST["billing-form-lastname"])) {
        
$message .= "請輸入姓氏。\\n\\n";
    }

    if (empty(
$_POST["billing-form-phone"])) {
        
$message .= "請輸入聯絡電話。\\n\\n";
    }

    if (empty(
$_POST["billing-form-email"])) {
        
$message .= "請輸入電郵。\\n\\n";
    } else {
        if (!
filter_var($_POST["billing-form-email"], FILTER_VALIDATE_EMAIL)) {
            
$message .= "請輸入正確的電郵格式。";
        }
    }

    if (empty(
$_POST["billing-form-address"])) {
        
$message .= "請輸入帳單地址。\\n\\n";
    }



    if (isset(
$_POST["billing-form-transervice"])) {

        if(empty(
$_POST["billing-form-service-date"])){
            
$message .= "請選擇運輸日期。\\n\\n";
        }else{
            if(!
validateDate($_POST["billing-form-service-date"], $format 'Y-m-d')){
                
$message .= "請選擇正確的運輸日期。\\n\\n";
            }
        }

        if(empty(
$_POST["billing-form-delivery-to"])){
            
$message .= "請輸入運輸地址。\\n\\n";
        }

        if(empty(
$_POST["billing-form-delivery-from"])){
            
$message .= "請輸入運輸目的地。\\n\\n";
        }
    }

    if (empty(
$_POST["billing-form-agree"])) {
        
$message .= "請細閱及同意條款及細則。\\n\\n";
    }

    if (empty(
$_POST["g-recaptcha-response"])) {
        
$message .= "請進行驗證。\\n\\n";
    }else{
        
$url "https://www.google.com/recaptcha/api/siteverify";
        
$post_data = array("secret" => $google_recaptcha_secret_key"response" => $_POST["g-recaptcha-response"]);
        
$result call_curl($url$post_data1);
        
$result_array json_decode($resulttrue);
        if(!
$result_array["success"]){
            
$message .= "驗證無效。\\n\\n";
        }
    }
    if(empty(
$_SESSION["selected_room_size_info"])){
        
$message .= "這個單位尺碼的迷你倉已租滿。\\n\\n";
    }

    if (!empty(
$message)) {
        echo 
"<script>alert('" $message "'); history.back();</script>";
        exit;
    } else {
        
//order product
        
$_SESSION["warehousing_web"]["order_product"] = array();
        
//$_SESSION["warehousing_web"]["order_product_total"] = 0;
        
foreach($_POST["quantity"] as $key => $quantity){
            if(
$quantity 0){
                
$_SESSION["warehousing_web"]["order_product"][$key]["product_id"] = $_POST["product_id"][$key];
                
$_SESSION["warehousing_web"]["order_product"][$key]["qty"] = $_POST["quantity"][$key];
                
$product_info get_product((int)$key);
                
$_SESSION["warehousing_web"]["order_product"][$key]["price"] = $product_info["price"];
                
//$_SESSION["warehousing_web"]["order_product_total"] += $_POST["quantity"][$key]*$product_info["price"];
            
}
        }

        
$_SESSION["warehousing_web"]["master_room_id"] = $_POST["billing-form-master-room-id"];
        
$master_room_info get_master_room($_POST["billing-form-master-room-id"]);
        
$_SESSION["warehousing_web"]["location_id"] = $master_room_info["location_id"];
        
$_SESSION["warehousing_web"]["roughly_size"] = $master_room_info["length"]*$master_room_info["width"]*$master_room_info["height"];

        
$_SESSION["warehousing_web"]["rent_month"] = $_POST["billing-form-month"];
        
$_SESSION["warehousing_web"]["room_id"] =  $_SESSION["selected_room_size_info"]["room_id"];
        
$_SESSION["warehousing_web"]["total_amount"] = $_SESSION["selected_room_size_info"]["total_amount"];
        
$_SESSION["warehousing_web"]["deposit"] = $_SESSION["selected_room_size_info"]["deposit"];
        
$_SESSION["warehousing_web"]["discounted_price"] = $_SESSION["selected_room_size_info"]["discounted_price"];
        
$_SESSION["warehousing_web"]["retail_price"] = $_SESSION["selected_room_size_info"]["retail_price"];
        
$_SESSION["warehousing_web"]["first_month_half_price"] = $_SESSION["selected_room_size_info"]["first_month_half_price"];
        
$_SESSION["warehousing_web"]["order_discount"] = $_SESSION["selected_room_size_info"]["order_discount"];


        if(isset(
$_POST["billing-form-prepaid"])){
            
$_SESSION["warehousing_web"]["prepaid"] = 1;
            
$_SESSION["warehousing_web"]["prepaid_month"] = $_POST["billing-form-month"];
            
$_SESSION["warehousing_web"]["prepaid_amount"] = $_SESSION["selected_room_size_info"]["discounted_price"]*$_POST["billing-form-month"]+$_SESSION["selected_room_size_info"]["deposit"];
        }else{
            
$_SESSION["warehousing_web"]["prepaid"] = 0;
            
$_SESSION["warehousing_web"]["prepaid_month"] = 0;
            
$_SESSION["warehousing_web"]["prepaid_amount"] = 0;
        }

        
/*if(isset($_POST["billing-form-recurring-payment"])){
            $_SESSION["warehousing_web"]["auto_paid"] = true;
        }else{
            $_SESSION["warehousing_web"]["auto_paid"] = false;
        }*/

        //default use recurring payment
        
if($_SESSION["warehousing_web"]["rent_month"] > && $_SESSION["warehousing_web"]["prepaid"] == 0){
            
$_SESSION["warehousing_web"]["auto_paid"] = true;
            
$_SESSION["warehousing_web"]["recurring_payment"] = 1;
        }else{
            
$_SESSION["warehousing_web"]["auto_paid"] = false;
            
$_SESSION["warehousing_web"]["recurring_payment"] = 0;
        }

        
//billing info
        
$_SESSION["warehousing_web"]["title"] = $_POST["billing-form-title"];
        
$_SESSION["warehousing_web"]["firstname"] = $_POST["billing-form-firstname"];
        
$_SESSION["warehousing_web"]["lastname"] = $_POST["billing-form-lastname"];
        
$_SESSION["warehousing_web"]["customer_type"] = $_POST["billing-form-customer-type"];

        if(
$_POST["billing-form-customer-type"] == "BUSINESS"){
            
$_SESSION["warehousing_web"]["companyname"] = $_POST["billing-form-companyname"];
        }else{
            
$_SESSION["warehousing_web"]["companyname"] = "";
        }

        
$_SESSION["warehousing_web"]["tel"] = $_POST["billing-form-phone"];
        
$_SESSION["warehousing_web"]["email"] = $_POST["billing-form-email"];
        
$_SESSION["warehousing_web"]["address"] = $_POST["billing-form-address"];

        if(
$_SESSION["selected_room_size_info"]["first_month_half_price"] > 0){
            
$_SESSION["warehousing_web"]["warehousing_date"] = $_POST["billing-form-warehousing-date"];
        }else{
            
$_SESSION["warehousing_web"]["warehousing_date"] = date("Y-m-d");
        }

        
$_SESSION["warehousing_web"]["rent_from"] = $_SESSION["warehousing_web"]["warehousing_date"];

        
$rent_to = new DateTime($_SESSION["warehousing_web"]["warehousing_date"]);
        
$rent_to->modify("+".$_POST["billing-form-month"]." month -1 day");

        
$_SESSION["warehousing_web"]["rent_to"] = $rent_to->format("Y-m-d");

        if (isset(
$_POST["billing-form-transervice"])) {
            
$_SESSION["warehousing_web"]["transervice"] = 1;

            
$_SESSION["warehousing_web"]["service_date"] = $_POST["billing-form-service-date"];
            
$_SESSION["warehousing_web"]["delivery_from"] = $_POST["billing-form-delivery-from"];
            
$_SESSION["warehousing_web"]["delivery_to"] = $_POST["billing-form-delivery-to"];
        }else{
            
$_SESSION["warehousing_web"]["transervice"] = 0;

            
$_SESSION["warehousing_web"]["service_date"] = "";
            
$_SESSION["warehousing_web"]["delivery_from"] = "";
            
$_SESSION["warehousing_web"]["delivery_to"] = "";
        }


        
header("Location: confirm_rent.php");
    }