/var/www/hkosl.com/innoutstorage2019/en/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 .= "Please select a unit size.\\n\\n";
    }

    if (empty(
$_POST["billing-form-name"])) {
        
$message .= "Please enter your name.\\n\\n";
    }

    if (empty(
$_POST["billing-form-phone"])) {
        
$message .= "Please enter your phone.\\n\\n";
    }

    if (empty(
$_POST["billing-form-email"])) {
        
$message .= "Please enter your email.\\n\\n";
    } else {
        if (!
filter_var($_POST["billing-form-email"], FILTER_VALIDATE_EMAIL)) {
            
$message "Invalid email format";
        }
    }

    if (empty(
$_POST["billing-form-agree"])) {
        
$message .= "Please read the terms and conditions and tick it if you agree it.\\n\\n";
    }

    if (empty(
$_POST["g-recaptcha-response"])) {
        
$message .= "Please click the verification box.\\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 .= "Cannot pass form checking.\\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('Not available to reserve this kind of size.'); 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('Not available to reserve this kind of size.'); history.back();</script>";
            exit;
        }else{

            
//reserve email

            
$email_subject "Online Reserve Storage";

            
//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;">
            Dear customer,<br><br>

            We have received your reserve storage request. Please visit our office and complete the rental process.
            <br><br>
            <table>
                <tr>
                    <td valign="top">Unit Size(LxWxH):</td>
                    <td valign="top"><?= $this_master_room_info["display_size"?></td>
                </tr>

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

                <tr>
                    <td valign="top">Phone:</td>
                    <td valign="top"><?= $_POST["billing-form-phone"?></td>
                </tr>

                <tr>
                    <td valign="top">Email:</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;

            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()) {
                
/*echo "<script>alert('Your online reserve storage  has sent. We will reply you as soon as possible.'); window.location.href='contactus.php';</script>";
                exit;*/
            
} else {
                
/*echo "<script>alert('Your online enquiry cannot send. Please try again.'); history.back();</script>";
                exit;*/
            
}

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