/var/www/(Del)eizo.hkosl.com/global/webadmin/customer_warranty_add.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
    
include 'config.php';

    
// Check if the user is logged in

    
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) {
        
header("Location: login.php");
        exit;
    }

    
$nowdate date("Y-m-d H:i:s");

    
//must

    
$customer_name       $_POST["customer_name"];
    
$customer_name_email $_POST["customer_name"];
    
$email               $_POST["email"];
    
$customer_email      $_POST["email"];
    
$contact_number      $_POST["contact_number"];
    
//$address             = $_POST["address1"] . " " . $_POST["address2"];
    
$address             $_POST["address1"];

    
$gender $_POST["gender"];
    
$region         $_POST["region"];
    if(
$region == "CN"){
        
$check_region "CN";
    }else{
        
$check_region "HK";
    }


    
$series           $_POST["series"];
    
$model            $_POST["model"];
    
$serial_number       $_POST["serial_number"];
    
$date_of_purchase $_POST["date_of_purchase"];
    
$merchant_name    $_POST["merchant_name"];

    
//optional
    
$age_group       $_POST["age_group"];
    
$education_level $_POST["education_level"];
    
$occupation      $_POST["occupation"];
    
$monthly_income  $_POST["monthly_income"];
    
$receive_promotes  $_POST["receive_promotes"];

    
//checking required field
    
if (empty($customer_name) || empty($gender) || empty($email) || empty($contact_number) || empty($address) || empty($region) || empty($series) || empty($model) || empty($serial_number) || empty($date_of_purchase) || empty($merchant_name)) {
        echo 
"<script type='text/javascript'>
            alert('必填的資料有漏空,請填寫所有必填項目!');
            history.back();
            
        </script>"
;
        exit;
    }
    
//checking email format
    
if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
        echo 
"<script type='text/javascript'>
            alert('電子信箱格式出錯,請重新輸入!');
            history.back();
            
        </script>"
;
        exit;
    }

    
//checking the contact_number
    
if (!is_numeric($contact_number)) {
        echo 
"<script type='text/javascript'>
            alert('聯絡電話應是數字,請重新輸入!');
            history.back();
            
        </script>"
;
        exit;
    }


    
//data encryption
    //include_once('../phpseclib0.3.6/Crypt/RSA.php');
    
set_include_path(get_include_path() . PATH_SEPARATOR 'phpseclib0.3.6');

    include(
'Crypt/RSA.php');

    
$rsa = new Crypt_RSA();

    
$public_key "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDH0i//hwmPSCUNAS9UiD3wSH43 NxwRKwGtHQKGarANuYNacSXb+rS2N0WKihz+aSkevePj5GZPtu21Fpx0Tt541DBl UrYL0vPK4S6QUX8I5vsOQ/XuIyh9NKcD2fbmf/1QrC+q7pv6xa6ctaV8u1RPGI7C AIPtMCrh9Pbg+EFo0wIDAQAB";

    
$rsa->loadKey($public_key); // public key

    //$ciphertext = base64_encode($rsa->encrypt($plaintext));

    
$customer_name  base64_encode($rsa->encrypt($_POST["customer_name"]));
    
$email          base64_encode($rsa->encrypt($_POST["email"]));
    
$contact_number base64_encode($rsa->encrypt($_POST["contact_number"]));
    
$address        base64_encode($rsa->encrypt($_POST["address1"] . " " $_POST["address2"]));

    
//checking the model code and the serial number
    
$sql "select * from serial_number sn, model model, series series where sn.series_code = series.series_code and sn.model_code = model.model_code and sn.series_code = ? and sn.model_code = ? and sn.serial_number = ? and sn.deleted = ? and sn.region = ? and model.region = ? and series.region = ? group by sn.serial_number_id ";
    if (!(
$sth $dbh->prepare($sql))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    if (!
$sth->execute(array($series$model$serial_number"0"$check_region,$check_region,$check_region))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    
//$row = $sth->fetch(PDO::FETCH_ASSOC);

    
if($region == "CN"){
        
$sql3 "select * from customer_warranty where serial_number = ? and deleted = ? and region = ?)";
        if (!(
$sth3 $dbh->prepare($sql3))) {
            throw new 
Exception('[' $sth3->errorCode() . ']: ' print_r($sth3->errorInfo()));
        }

        if (!
$sth3->execute(array($serial_number"0""CN"))) {
            throw new 
Exception('[' $sth3->errorCode() . ']: ' print_r($sth3->errorInfo()));
        }
    }else{
        
$sql3 "select * from customer_warranty where serial_number = ? and deleted = ? and (region = ? or region = ?)";
        if (!(
$sth3 $dbh->prepare($sql3))) {
            throw new 
Exception('[' $sth3->errorCode() . ']: ' print_r($sth3->errorInfo()));
        }

        if (!
$sth3->execute(array($serial_number"0""HK""MO"))) {
            throw new 
Exception('[' $sth3->errorCode() . ']: ' print_r($sth3->errorInfo()));
        }
    }


    if(
$sth3->rowCount() > 0){
        echo 
"<script type='text/javascript'>
            alert('你所輸入的產品序號已被使用!');
            history.back();

        </script>"
;
        exit;
    }

    if (
$sth->rowCount() > && $sth3->rowCount() <= 0) { //it is a valid of that product
        
$row $sth->fetch(PDO::FETCH_ASSOC);

        
$datetime1 = new DateTime($date_of_purchase);
        
$datetime2 = new DateTime($nowdate);

        
$difference $datetime1->diff($datetime2);

        
/*echo 'Difference: '.$difference->y.' years, '
            .$difference->m.' months, '
            .$difference->d.' days';

        var_dump($row);*/
        
if ($row{"free_mix_color"} == && ($difference->>= 30 || $difference->>= 1)) {
            
$free_mix_color 1;

        } else {
            
$free_mix_color 0;
        }

        if (
$difference->>= 30 || $difference->>= 1) {
            
$extend_warranty_year $row{"extend_warranty_year"};

        } else {
            
$extend_warranty_year 0;

        }

        if(
$extend_warranty_year 0){
            
$warranty_detail_sc $row{"warranty_detail_extend_sc"};
            
$warranty_detail_tc $row{"warranty_detail_extend_tc"};
            
$warranty_detail_en $row{"warranty_detail_extend_en"};
        }else{
            
$warranty_detail_sc $row{"warranty_detail_sc"};
            
$warranty_detail_tc $row{"warranty_detail_tc"};
            
$warranty_detail_en $row{"warranty_detail_en"};
        }

        
//record data in database
        
$sql2 "insert into customer_warranty (customer_name, gender, email, contact_number, address, region, age_group, education_level, occupation, monthly_income, merchant_name, date_of_purchase, series_code, model_code, serial_number, free_mix_color,fixed_warranty_year, extend_warranty_year, warranty_detail_sc, warranty_detail_tc, warranty_detail_en, createby, createdate, lastupby, lastupdate,receive_promotes) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        if (!(
$sth2 $dbh->prepare($sql2))) {
            throw new 
Exception('[' $sth2->errorCode() . ']: ' print_r($sth2->errorInfo()));
        }

        
$parameters2 = array($customer_name$gender$email$contact_number$address$region$age_group$education_level$occupation$monthly_income$merchant_name$date_of_purchase$series$model$serial_number$free_mix_color$row{"fixed_warranty_year"}, $extend_warranty_year$warranty_detail_sc$warranty_detail_tc$warranty_detail_en$_SESSION['cmsloginid'], $nowdate$_SESSION['cmsloginid'], $nowdate$receive_promotes);


        if (!
$sth2->execute($parameters2)) {
            throw new 
Exception('[' $sth2->errorCode() . ']: ' print_r($sth2->errorInfo()));
        }else{
            
header("Location: customer_warranty_index.php?msg=Add Successful");
        }
    } else {

            echo 
"<script type='text/javascript'>
            alert('您所輸入的產品序號與產品不相符,請重新輸入!');
            history.back();
            
        </script>"
;
            exit;


    }

?>