/var/www/hkosl.com/innoutstorage/webadmin/bk20220830/customer_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
<?php
    
require_once('check_login.php');

    
$customer_info get_customer();

    
$message "";

    if (empty(
$_POST["customer_type"])) {
        
$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_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_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;
    }

    
$hkid        "";
    
$hkbr        "";
    
$companyname "";

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

    
$total_num_of_customer count($customer_info);
    
$new_code_id           $total_num_of_customer 1;
    
$password              random_string(15);
    
$encrypt_password      rsa_crypt($password1);

    
$customer_code "C" date("y") . str_pad($new_code_id4"0"STR_PAD_LEFT);

    
$data = array(
        
"code"        => $customer_code,
        
"typeid"      => $_POST["customer_type"],
        
"title"       => $_POST["title"],
        
"firstname"   => rsa_crypt($_POST["firstname"], 1),
        
"lastname"    => rsa_crypt($_POST["lastname"], 1),
        
"companyname" => $companyname,
        
"tel"         => rsa_crypt($_POST["tel"], 1),
        
"email"       => rsa_crypt($_POST["email"], 1),
        
"address"     => rsa_crypt($_POST["address"], 1),
        
"hkid"        => $hkid,
        
"hkbr"        => $hkbr,
        
"loginid"     => rsa_crypt($_POST["email"], 1),
        
"password"    => $encrypt_password,
        
"createby"    => $_SESSION['cmsloginid'],
        
"createdate"  => $nowdate,
        
"lastupby"    => $_SESSION['cmsloginid'],
        
"lastupdate"  => $nowdate
    
);

    
$result insert_record("customer"$data);

    
header("Location: customer_index.php?msg=新增成功");