/var/www/hkosl.com/innoutstorage2019/tc/reserve_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
<?php

    
require_once('../webadmin/basic_info.php');

    
$message "";

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

    if (empty(
$_POST["billing-form-name"])) {
        
$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-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(
$message)) {
        echo 
"<script>alert('" $message "'); history.back();</script>";
        exit;
    } else {

        
check_and_update_reserved_room();

        
$master_room_id = (int)$_POST["billing-form-title"];

        
$this_master_room_info get_master_room($master_room_id);

        
$available_master_master_room_info get_master_room_by_display_size($this_master_room_info["display_size"]);

        if (empty(
$available_master_master_room_info)) {
            
$available_master_master_room_id = array($master_room_id);
        } else {
            foreach (
$available_master_master_room_info as $available_master_room_info) {
                
$available_master_master_room_id[] = $available_master_room_info["id"];
            }
        }

        foreach (
$available_master_master_room_id as $this_master_room_id) {
            
//get room id
            
$sql        "select * from room where status = ? and deleted = ? and master_room_id = ?";
            
$parameters = array("OPEN"0$this_master_room_id);
            
$room_info  bind_pdo($sql$parameters"selectone");
            
$room_id    $room_info["id"];

            break;
        }

        if (empty(
$room_id) || $room_id <= 0) {
            echo 
"<script>alert('這個單位尺碼的迷你倉已租滿。'); history.back();</script>";
            exit;
        }

        
//update this room status to reserve, need to check how many room allow for online

        
$start_date = new DateTime();
        
$end_date = new DateTime();
        
$end_date->modify('+1 day');

        
$sql        "update room set status = ?, reserve_by_name = ?, reserve_by_tel = ?, reserve_by_email = ?, reservedate_from = ?, reservedate_to = ? where id = ? and status = ?";
        
$parameters = array("RESERVED"$_POST["billing-form-name"], $_POST["billing-form-phone"], $_POST["billing-form-email"], $start_date->format('Y-m-d H:i:s'), $end_date->format('Y-m-d H:i:s'), $room_id"OPEN");
        
$update_room_result     bind_pdo($sql$parameters);

        if (empty(
$update_room_result)) {
            echo 
"<script>alert('這個單位尺碼的迷你倉已租滿。'); history.back();</script>";
            exit;
        }else{

            
//reserve email

            
$email_subject "網上預訂迷你倉";

            
//email content to customer
            
ob_start();
            
?>
            <html>
            <head>
                <META name=GENERATOR content="MSHTML 8.00.6001.19394">
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

            </head>
            <body style="font-family:arial,helvetica,sans-serif!important;color:#000;background:#fff;">
            尊貴的客戶,<br><br>

            我們己收到你的預訂迷你倉要求,請在二十四小時內到我們的辦公室完成租倉程序。
            <br><br>
            <table>
                <tr>
                    <td valign="top">單位尺碼(長x闊x高):</td>
                    <td valign="top"><?= $this_master_room_info["display_size"?></td>
                </tr>

                <tr>
                    <td valign="top">姓名:</td>
                    <td valign="top"><?= ($_POST["billing-form-name"]); ?></td>
                </tr>

                <tr>
                    <td valign="top">聯絡電話:</td>
                    <td valign="top"><?= $_POST["billing-form-phone"?></td>
                </tr>

                <tr>
                    <td valign="top">電郵:</td>
                    <td valign="top"><?= $_POST["billing-form-email"?></td>
                </tr>

            </table>

            <br><br><br><br>

            <?= $site_info{"companyname_" $langcode?><br>
            <a href='<?= $site_info{"url"?>' target='_blank'><?= $site_info{"url"?></a>
            </body>
            </html>

            <?php
            $email_body 
ob_get_contents();

            
ob_end_clean();
            
$enquiryemail $site_info{"enquiryemail"};
            
$company_name $site_info{"companyname_" $langcode};

            
//for customer
            
$x_mail = new PHPMailer();
            
$x_mail->CharSet  "UTF-8";
            
$x_mail->Sender   $enquiryemail;
            
$x_mail->AddReplyTo($enquiryemail$company_name);
            
$x_mail->From     $enquiryemail;
            
$x_mail->FromName $company_name;

            
//send to user not send to client
            
if(PRODUCTION == 1){
                
$x_mail->AddAddress($_POST["billing-form-email"], $_POST["billing-form-name"]);
            }else{
                
$x_mail->AddAddress($enquiryemail$company_name);
                
$x_mail->AddBCC("skycheng@onesolution.com.hk"$company_name);
            }

            
$x_mail->WordWrap 50;
            
$x_mail->IsHTML(true);
            
$x_mail->Subject $email_subject;
            
$x_mail->Body    $email_body;

            if (
$x_mail->Send()) {

            } else {

            }

            
header("Location: thankyou_reserve.php");
            exit;
        }
    }