/var/www/hkosl.com/alliancealliance/enrollment_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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<?php
    
require_once('webadmin/basic_info.php');
    require_once(
'inc/class.phpmailer.php');

    
$ara explode("|"$_SESSION['vCode']);
    
$verification $_POST['verification'];
    if (
$ara[0] == $verification) {

        
$_SESSION['vCode'] = "";
        
$message "";

        if (empty(
$_POST["course_category_id"]) || (int)($_POST["course_category_id"]) < 0) {
            
$message .= "Please select a course name.\\n\\n";
        }

        if (empty(
$_POST["course_id"]) || (int)($_POST["course_id"]) < 0) {
            
$message .= "Please select a course code.\\n\\n";
        }else{
            
$course get_course((int)$_POST["course_id"]);

            if (
$course["valid_apply"] == 1) {
                if(!
check_course_valid_apply((int)$_POST["course_id"])){
                    echo 
"<script>alert('This course is closed.'); location.href='index.php';</script>";
                    exit;
                }
            } else {
                echo 
"<script>alert('This course is ".$course["stop_applying_text_".$langcode].".'); location.href='index.php';</script>";
                exit;
            }
        }

        if (empty(
$_POST["title"])) {
            
$message .= "Please select your title.\\n\\n";
        }

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

        if (empty(
$_POST["identity_id"])) {
            
$message .= "Please enter your HKID/Passport No.\\n\\n";
        }

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

        if (empty(
$_POST["company_address"])) {
            
$message .= "Please enter your company address.\\n\\n";
        }

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

        if (empty(
$_POST["tel"])) {
            
$message .= "Please enter your telephone.\\n\\n";
        } else {
            if (!
is_numeric($_POST["tel"])) {
                
$message .= "Invalid telephone format\\n\\n";
            }
        }

        if (empty(
$_POST["mobile"])) {
            
$message .= "Please enter your mobile number.\\n\\n";
        } else {
            if (!
is_numeric($_POST["mobile"])) {
                
$message .= "Invalid mobile number format\\n\\n";
            }
        }

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

        if (!empty(
$_POST["cc_email"]) && !filter_var($_POST["cc_email"], FILTER_VALIDATE_EMAIL)) {
            
$message .= "Invalid cc email format\\n\\n";
        }

        if (!empty(
$_POST["fax"]) && !is_numeric($_POST["fax"])) {
            
$message .= "Invalid fax number format\\n\\n";
        }

        if (empty(
$_POST["exp_air_cargo"])) {
            
$message .= "Please select your experience in air cargo industry.\\n\\n";
        }

        if (empty(
$_POST["education_level"])) {
            
$message .= "Please select your education level.\\n\\n";
        }

        if (!empty(
$_POST["date_obtain_pre_cert"]) && !validateDate($_POST["date_obtain_pre_cert"], "Y-m-d")) {
            
$message .= "Please enter correct date of obtain previous certificate.\\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_data, 1);
            $result_array = json_decode($result, true);
            if (!$result_array["success"]) {
                $message .= "Cannot pass form checking.\\n\\n";
            }
        }*/

        
$sql         "select * from course where id = ?";
        
$parameters  = array((int)$_POST["course_id"]);
        
$course_info bind_pdo($sql$parameters"selectone");

        if (
$course_info["valid_apply"] != 1) {
            
$message .= "This course does not allow to apply. Please ask our staff for further details\\n\\n";
        }

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

        
$ref_code get_ref_code();

        
//insert record into enrollment
        
if (isset($_POST["ra_code"])) {
            
$sql          "select * from ra_code where deleted = ? and code = ?";
            
$parameters   = array(0$_POST["ra_code"]);
            
$ra_code_info bind_pdo($sql$parameters"selectone");

            if (
$ra_code_info["company_name_" $langcode] != $_POST["company_name"]) {
                
$company_name_diff 1;
            } else {
                
$company_name_diff 0;
            }

            
$company_address_diff 0;

            
/*if ($ra_code_info["company_address_" . $langcode] != $_POST["company_address"]) {
                $company_address_diff = 1;
            } else {
                $company_address_diff = 0;
            }*/
        
}


        
//get course category name and course name
        
$sql                  "select * from course_category where id = ?";
        
$parameters           = array((int)$_POST["course_category_id"]);
        
$course_category_info bind_pdo($sql$parameters"selectone");


        
//send email
        
$email_subject "Online Course Enrollment";
        
$email_body    '<html>
                        <head>
                                    <META name=GENERATOR content="MSHTML 8.00.6001.19394">
                                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                                    <style>
                                        table td{
                                            padding: 5px;
                                        }
                                    </style>
                                </head>
                                <body style="font-family:arial,helvetica,sans-serif !important;color:#000;background:#fff; width: 800px;">
                                Dear Customer,<br><br>

                                The following information is your enrollment record.<br><br>


                                <table style="width: 100%; border-collapse: collapse;">
                                <tr>
                                <td colspan="3">
                                    <b>Enrollment Date: ' 
date("Y-m-d") . '</b>
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                    <b>Reference Code: ' 
$ref_code '</b>
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                <br>
                                    <b>INFORMATION OF COURSE</b>
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                    Course Name:<br>
                                    ' 
$course_category_info["name_" $langcode] . '
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                    Course Code:<br>
                                    ' 
$course_info["code"] . '
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                <br>
                                    <b>INFORMATION OF PARTICIPANT</b>
                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Title:<br>
                                    ' 
$_POST["title"] . '
                                </td>
                                <td>
                                    Name of Participant:<br>
                                    ' 
$_POST["participant_name"] . '
                                </td>
                                <td>
                                    HKID/Passport No.:<br>
                                    ' 
$_POST["identity_id"] . '
                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Company RA Code (if any):<br>
                                    ' 
$_POST["ra_code"] . '
                                </td>
                                <td>
                                    Name of Company:<br>
                                    ' 
$_POST["company_name"] . '
                                </td>
                                <td>

                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                    Company Address:<br>
                                    ' 
$_POST["company_address"] . '
                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Position:<br>
                                    ' 
$_POST["position"] . '
                                </td>
                                <td>
                                    IATA Code (if any):<br>
                                    ' 
$_POST["iata_code"] . '
                                </td>
                                <td>

                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Tel.:<br>
                                    ' 
$_POST["tel"] . '
                                </td>
                                <td>
                                    Mobile:<br>
                                    ' 
$_POST["mobile"] . '
                                </td>
                                <td>

                                </td>
                                </tr>

                                <tr>
                                <td>
                                    E-mail:<br>
                                    ' 
$_POST["email"] . '
                                </td>
                                <td>
                                    CC E-mail:<br>
                                    ' 
$_POST["cc_email"] . '
                                </td>
                                <td>
                                    Fax:<br>
                                    ' 
$_POST["fax"] . '
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                    Experience in air cargo industry:<br>
                                    ' 
$_POST["exp_air_cargo"] . '
                                </td>
                                </tr>

                                <tr>
                                <td colspan="3">
                                <br>
                                    <b>OTHERS INFORMATION</b>
                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Education Level:<br>
                                    ' 
$_POST["education_level"] . '
                                </td>
                                <td>
                                    Existing airfreight compliance client od Alliance:<br>
                                    ' 
$_POST["existing_airfreight"] . '
                                </td>
                                <td>

                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Are you renewing the certificate?:<br>
                                    ' 
$_POST["renew_cert"] . '
                                </td>
                                <td>
                                    Date of obtain previous certificate:<br>
                                    ' 
$_POST["date_obtain_pre_cert"] . '
                                </td>
                                <td>

                                </td>
                                </tr>

                                <tr>
                                <td>
                                    Institution of issuing:<br>
                                    ' 
$_POST["institution_issuing"] . '
                                </td>
                                <td>
                                    Have you ever enroll the DG Training?<br>
                                    ' 
$_POST["have_enroll_dg_training"] . '
                                </td>
                                <td>

                                </td>
                                </tr>

                                </table>'
;

        
$email_body .= '<br><br><br>' $site_info{"companyname_en"} . '<br> <a href="' $site_info{"url"} . '" target="_blank">' $site_info{"url"} . '</a></body></html>';


        
/*var_dump($email_body);

        exit;*/

        
$sender_email $site_info["enquiryemail"];
        
$company_name $site_info["companyname_" $langcode];

        
//for customer
        
$x_mail = new PHPMailer();
        
$x_mail->IsSMTP();
        
$x_mail->Host       'smtp.mandrillapp.com';                 // Specify main and backup server
        
$x_mail->Port       587;                                    // Set the SMTP port
        
$x_mail->SMTPAuth   true;                               // Enable SMTP authentication
        
$x_mail->Username   'garricklam@onesolution.com.hk';                // SMTP username
        
$x_mail->Password   'lYtE-w6jVOD4vZQrurvraQ';                  // SMTP password
        
$x_mail->SMTPSecure 'tls';

        
$x_mail->CharSet "UTF-8";
        
$x_mail->Sender  $sender_email;
        
$x_mail->AddReplyTo($sender_email$company_name);
        
$x_mail->From     $sender_email;
        
$x_mail->FromName $company_name;

        
//send to user not send to client
        
$x_mail->AddAddress($_POST["email"], $_POST["participant_name"]);
        
$x_mail->AddBCC($site_info["enquiryemail"], $site_info["companyname_" $langcode]);

        
$x_mail->WordWrap 50;
        
$x_mail->IsHTML(true);
        
$x_mail->Subject $email_subject;
        
$x_mail->Body    $email_body;
        if (
$x_mail->Send()) {
            
$sent_email 1;
            
//echo "<script>alert('電郵已成功送出。'); history.back();</script>";
        
} else {
            
$sent_email 0;
            
//echo "<script>alert('電郵未能成功送出。'); history.back();</script>";
        
}

        
$sql        "insert into enrollment set course_fee = ?,ref_code = ?, enrollment_date=?, sent_email=?, company_name_diff=?, company_address_diff=?, createdate=?, createby=?, lastupdate=?, lastupby=?, ";
        
$parameters = array($course_info["fee"], $ref_codedate("Y-m-d"), $sent_email$company_name_diff$company_address_diff$nowdate0$nowdate0);

        foreach (
$_POST as $key => $value) {
            if (
$key == "verification") {
                continue;
            }

            
$sql .= $key "=?, ";

            if (
$key == "participant_name" || $key == "identity_id" || $key == "tel" || $key == "mobile" || $key == "email" || $key == "cc_email") {
                
$parameters[] = rsa_crypt($value1);
            } else {
                
$parameters[] = $value;
            }
        }

        
$sql substr_replace($sql"", -2);
        
bind_pdo($sql$parameters);

        
$lastInsertId $dbh->lastInsertId();

        if (
$lastInsertId) {
            
$_SESSION["enrollment_success"] = 1;
            
$_SESSION["ref_code"] = $ref_code;
            echo 
"<script>alert('We have record your course enrollment. You will receive an email with your enrollment information soon.'); location.href='enrollment_success.php';</script>";
        } else {
            echo 
"<script>alert('We cannot record your course enrollment. Please try again.'); history.back();</script>";
        }
    }else{
        echo 
"<script type='text/javascript'>
            alert('Please enter correct verification code.');
            history.back();
        </script>"
;
        exit;
    }