/var/www/hkosl.com/innoutstorage/webadmin/customer_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
104
105
106
107
108
109
110
111
<?php
    
require_once('check_login.php');

    
$customer_info get_customer();

    
$message "";

    if (empty(
$_POST["customer_id"]) || empty($_POST["customer_type"]) || (int)$_POST["customer_id"] <= 0) {
        
$message .= "找不到相關客戶。\\n\\n";
    }

    if (empty(
$_POST["identity_id"])) {
        
$message .= "請輸入證明文件號碼。\\n\\n";
    }

    if (
$_POST["customer_type"] == "BUSINESS") {
        if (empty(
$_POST["companyname"])) {
            
$message .= "請輸入公司名稱。\\n\\n";
        }
    }

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

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

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

    if (empty(
$_POST["tel"])) {
        
$message .= "請輸入電話號碼。\\n\\n";
    } else {
        if (!
is_numeric($_POST["tel"])) {
            
$message .= "請輸入正確的電話號碼。\\n\\n";
        } else {
            foreach (
$customer_info as $customer) {
                if (
$customer["deleted"] == 1)
                    continue;

                
$decrypt_tel rsa_crypt($customer["tel"], 2);

                if ((!empty(
$decrypt_tel) && $decrypt_tel == $_POST["tel"] && $_POST["customer_id"] != $customer["id"] && $_POST["customer_type"] == $customer["typeid"])) {
                    
$message .= "此電話已登記,請使用另一個電話。\\n\\n";
                    break;
                }
            }
        }
    }

    if (empty(
$_POST["email"])) {
        
//$message .= "請輸入電郵地址。\\n\\n";
    
} else {
        if (!
filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
            
$message .= "請輸入正確的電郵。\\n\\n";
        } else {
            foreach (
$customer_info as $customer) {
                if (
$customer["deleted"] == 1)
                    continue;

                
$decrypt_email rsa_crypt($customer["email"], 2);

                if ((!empty(
$decrypt_email) && $decrypt_email == $_POST["email"] && $_POST["customer_id"] != $customer["id"] && $_POST["customer_type"] == $customer["typeid"])) {
                    
$message .= "此電郵已登記,請使用另一個電郵。\\n\\n";
                    break;
                }
            }
        }
    }

    if (empty(
$_POST["address"])) {
        
$message .= "請輸入聯絡地址。\\n\\n";
    }

    if (!empty(
$message)) {
        echo 
"<script>alert('" $message "'); history.back(); </script>";
        exit;
    }

    
$customer_info get_customer($_POST["customer_id"]);

    if (
$_POST["customer_type"] == "BUSINESS") {
        
$hkbr rsa_crypt($_POST["identity_id"], 1);

        
$sql        "update customer set typeid = ?, hkbr = ?, companyname = ?, lastupby = ?, lastupdate = ? where id=?";
        
$parameters = array($_POST["customer_type"], $hkbr$_POST["companyname"], $_SESSION["cmsloginid"], $nowdate, (int)$_POST["customer_id"]);
        
bind_pdo($sql$parameters);

        
$sql        "update `order` set customer_hkbr = ?, customer_companyname = ? where customer_code = ? and customer_hkbr IS NULL and status = ?";
        
$parameters = array($hkbr$customer_info["code"], $_POST["companyname"], "NEW");
        
bind_pdo($sql$parameters);
    } else {
        
$hkid       rsa_crypt($_POST["identity_id"], 1);
        
$sql        "update customer set typeid = ?, hkid = ?, companyname = ?, lastupby = ?, lastupdate = ?  where id=?";
        
$parameters = array($_POST["customer_type"], $hkid""$_SESSION["cmsloginid"], $nowdate, (int)$_POST["customer_id"]);
        
bind_pdo($sql$parameters);

        
$sql        "update `order` set customer_hkid = ?, customer_companyname = ?  where customer_code = ? and customer_hkid IS NULL and status = ?";
        
$parameters = array($hkid""$customer_info["code"], "NEW");
        
bind_pdo($sql$parameters);
    }

    
$sql        "update customer set title = ?, lastname = ?, firstname = ?, tel = ?, email = ?, address = ? where id=?";
    
$parameters = array($_POST["title"], rsa_crypt($_POST["lastname"], 1), rsa_crypt($_POST["firstname"], 1), rsa_crypt($_POST["tel"], 1), rsa_crypt($_POST["email"], 1), rsa_crypt($_POST["address"], 1), (int)$_POST["customer_id"]);
    
bind_pdo($sql$parameters);

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