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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
|
<? include('_init.php'); include('JSON.php');
foreach ($_POST as $key => $value) { $_POST[$key] = _h($value); }
$data = $_POST;
if ($data['ajax'] == 'coupon') { $json = new Services_JSON();
$limit_type = $_POST['limit_type']; $coupon_code = strtoupper($_POST['coupon']); $fee = $_POST['fee'];
//hardcode for fixed price to $X if ((strtoupper($coupon_code) == "INKY20" || strtoupper($coupon_code) == "IMC$20") && $limit_type == "try") { //check if promotion code used $sql = "select count(*) as coupon_used_num from `order` where coupon_code = ? and deleted = ? and (status = ? or status = ?)"; $parameters = array($coupon_code, 0, "paid", "approved"); $result = bind_pdo($sql, $parameters, "selectone");
if ($result["coupon_used_num"] < 100) { $jsonReturnArr['status'] = true; $jsonReturnArr['total'] = 20; $jsonReturnArr['discount'] = $fee - $jsonReturnArr['total']; } else { $jsonReturnArr['status'] = false; }
echo $json->encode($jsonReturnArr); exit; }
$sql = "select id,discount_type,number,one_time from coupon where coupon_code = ? and status = ? and limit_type = ?"; $parameters = array($coupon_code, 1, $limit_type); $row_coupon = bind_pdo($sql, $parameters, "selectone");
if ($row_coupon['id']) { if ($row_coupon['one_time'] == 1) { //check if one time promotion code used $sql = "select id from `order` where coupon_code = ? and deleted = ? and (status = ? or status = ?)"; $parameters = array($coupon_code, 0, "paid", "approved"); $result = bind_pdo($sql, $parameters, "selectone");
if (!empty($result)) { $jsonReturnArr['status'] = false; } else { $jsonReturnArr['status'] = true; } } else { $jsonReturnArr['status'] = true; }
if ($jsonReturnArr['status']) { if ($row_coupon['discount_type'] == 'rate') { $jsonReturnArr['total'] = $fee * ($row_coupon['number'] / 100); } else if ($row_coupon['discount_type'] == 'cash') { $jsonReturnArr['total'] = $fee - $row_coupon['number']; }
$jsonReturnArr['discount'] = $fee - $jsonReturnArr['total'];
/* $tmp_order_data['coupon_fee'] = $jsonReturnArr['discount']; $tmp_order_data['coupon_code'] = $coupon_code; $sql = mysql_install($tmp_order_data, 'order', 'edit','id'); $tmp_order_data['id'] = $row['id']; $arraykey = array_keys($tmp_order_data); unset($parameters); for ($i = 0; $i < count($arraykey); $i++) { $parameters[$i] = $tmp_order_data[$arraykey[$i]]; } //$jsonReturnArr['sql'] = $sql; bind_pdo($sql, $parameters); */ }
} else { $jsonReturnArr['status'] = false; } echo $json->encode($jsonReturnArr); } else if ($data['ajax'] == 'checkTel') { //checkTel if ($data['type'] == 'tutor') { if ($data['id']) { $sql = "SELECT count(*) as count FROM tutor_main WHERE mobno=? AND isphoneverified = 1 AND id != ? AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1), $data['id']); } else { $sql = "SELECT count(*) as count FROM tutor_main WHERE mobno=? AND isphoneverified = 1 AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1)); } $record_mobno = bind_pdo($sql, $parameters, "selectone"); } else if ($data['type'] == 'student') { if ($data['id']) { $sql = "SELECT count(*) as count FROM student_main WHERE mobno=? AND isphoneverified = 1 AND id != ? AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1), $data['id']); } else { $sql = "SELECT count(*) as count FROM student_main WHERE mobno=? AND isphoneverified = 1 AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1)); } $record_mobno = bind_pdo($sql, $parameters, "selectone"); } // $json = new Services_JSON(); $jsonReturnArr['mobno_status'] = $record_mobno['count'] > 0 ? true : false; echo $json->encode($jsonReturnArr); exit(); } elseif ($data['ajax'] == 'checkEmail') { //checkTel if ($data['type'] == 'tutor') { if ($data['id']) { $sql = "SELECT count(*) as count FROM tutor_main WHERE mobno=? AND isphoneverified = 1 AND id != ? AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1), $data['id']); } else { $sql = "SELECT count(*) as count FROM tutor_main WHERE mobno=? AND isphoneverified = 1 AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1)); } $record_mobno = bind_pdo($sql, $parameters, "selectone"); } else if ($data['type'] == 'student') { if ($data['id']) { $sql = "SELECT count(*) as count FROM student_main WHERE mobno=? AND isphoneverified = 1 AND id != ? AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1), $data['id']); } else { $sql = "SELECT count(*) as count FROM student_main WHERE mobno=? AND isphoneverified = 1 AND deleted = 0"; $parameters = array(aes_crypt($data['mobno'], 1)); } $record_mobno = bind_pdo($sql, $parameters, "selectone"); } //checkUsername $sql = "SELECT count(*) as count FROM tutor_main WHERE email=? AND deleted = 0"; $parameters = array(aes_crypt($data['email'], 1)); $record_email = bind_pdo($sql, $parameters, "selectone"); $sql = "SELECT count(*) as count FROM student_main WHERE email=? AND deleted = 0"; $parameters = array(aes_crypt($data['email'], 1)); $record_email2 = bind_pdo($sql, $parameters, "selectone"); //checkUsername $sql = "SELECT count(*) as count FROM sys_cms_login WHERE cmsloginname=? AND deleted = 0"; $parameters = array($data['email']); $record_user = bind_pdo($sql, $parameters, "selectone"); // include('webadmin/function_auth.php'); $password = Password::strength($data['password']); // $json = new Services_JSON(); $jsonReturnArr['mobno_status'] = $record_mobno['count'] > 0 ? true : false; $jsonReturnArr['email_status'] = ($record_email['count'] + $record_email2['count']) > 0 ? true : false; $jsonReturnArr['user_status'] = $record_user['count'] > 0 ? true : false; $jsonReturnArr['password_status'] = $password; echo $json->encode($jsonReturnArr); exit(); } else if ($data['ajax'] == 'confirmSMSCode') { $json = new Services_JSON(); //skip for tel verify if(PRODUCTION==0){ $_SESSION["tel_verified"] = true; $jsonReturnArr['status'] = true; echo $json->encode($jsonReturnArr); exit(); }
//demo if ($_SESSION["sms_verification_code"] == $data['code']) { $jsonReturnArr['status'] = true; $sql = "update sms_log set verified = ? where session_id = ? and type = ? and tel = ?"; $parameters = array(1, session_id(), $data['type'], $data['tel']); bind_pdo($sql, $parameters);
$_SESSION["tel_verified"] = true; } else { $jsonReturnArr['status'] = false; $_SESSION["tel_verified"] = false; } echo $json->encode($jsonReturnArr); exit(); } else if ($data['ajax'] == 'sendSMS') { //skip for tel verify if(PRODUCTION==0){ $json = new Services_JSON(); $jsonReturnArr['sms_status'] = 'true'; echo $json->encode($jsonReturnArr); exit(); } //demo
$tel = (int)$data["tel"];
$sql = "SELECT lastupdate, verified FROM sms_log WHERE tel = ? AND type = ? order by lastupdate desc LIMIT 1"; $parameters = array($tel, $data['type']); $record_sms_log = bind_pdo($sql, $parameters, "selectone");
$json = new Services_JSON(); //$jsonReturnArr['time'] = time()-strtotime($record_sms_log['lastupdate']); if (time() - strtotime($record_sms_log['lastupdate']) > 60) { if ((empty($record_sms_log) || $record_sms_log["verified"] != 1) && !empty($tel)) { date_default_timezone_set('Asia/Hong_Kong'); ini_set("max_execution_time", "10"); $code = pass_gen(6, 'number'); $msg = urlencode("MusicCircle驗證碼:" . $code . "\n查詢: cs@musiccircle.hk \n" . date('Y-m-d H:i:s')); $phone = '852' . $tel; // 852 (dial code), 61231231(user phone number)
$accountno = "11029458"; $pwd = "31081158";
file_put_contents("/var/www/html/log/sendSMS.log", "start send SMS to phone: $phone\n");
$handle = fopen("http://api.accessyou.com/sms/sendsms-utf8.php?msg=$msg&phone=$phone&pwd=$pwd&accountno=$accountno", "r"); $contents = trim(fread($handle, 8192)); file_put_contents("/var/www/html/log/sendSMS.log", "send SMS to phone: $phone done\n"); if (!is_numeric($contents)) { $jsonReturnArr['sms_status'] = 'false'; } else { $jsonReturnArr['sms_status'] = 'true'; } $jsonReturnArr['tel'] = $tel;
/*$sql = "update " . $data['type'] . "_main set sms_code = ? where id = ?"; $parameters = array($code, $id); bind_pdo($sql, $parameters);*/ if ($jsonReturnArr['sms_status'] == "true") { $_SESSION["sms_verification_code"] = $code; }
// $sql = "INSERT into `sms_log` (type, tel, code, lastupdate, session_id) value (?,?,?,?,?)"; $parameters = array($data['type'], $jsonReturnArr['tel'], $code, date("Y-m-d H:i:s"), session_id()); bind_pdo($sql, $parameters); } else { $jsonReturnArr['sms_status'] = 'same'; } } else { $jsonReturnArr['sms_status'] = 'time'; } // echo $json->encode($jsonReturnArr); exit(); } else if ($data['ajax'] == 'checkverifyCode') { $json = new Services_JSON(); if ($data['type']) { if ($data['type'] == 'tutor') { $id = intval($_SESSION['member_login']); } else if ($data['type'] == 'student') { $id = intval($_SESSION['student_login']); } $sql = "select isphoneverified from " . $data['type'] . "_main where id = ? and deleted = ?"; $parameters = array($id, 0); $result = bind_pdo($sql, $parameters, "selectone");
if ($result['isphoneverified'] == 1) { $jsonReturnArr['smsstatus'] = true; } else { $jsonReturnArr['smsstatus'] = false; } } if ($_SESSION["verification__session"] == $data['verifyCode']) { $jsonReturnArr['status'] = true; } else { $jsonReturnArr['status'] = false; } echo $json->encode($jsonReturnArr); exit();
} else if ($data['ajax'] == 'filter_course') { /* var_dump($_POST); exit;*/ //filter tutor $inner_sql = ""; $where_clause = ""; $parameters = array(0, 1, 1);
$_SESSION["category_page"]["category_id"] = $_POST["category_id"]; $category_id = $_POST["category_id"]; if ($_POST["category_id"] != "ANY") { $exsql .= " and tb.mas_instrument = ?"; $parameters[] = $category_id; } else { $category_id = null; }
$_SESSION["category_page"]["level_of_grade"] = $_POST["level_of_grade"]; if (!empty($_POST["level_of_grade"])) { if ($_POST["level_of_grade"] != "ANY") { $exsql .= " and tb.level=?"; $parameters[] = $_POST["level_of_grade"]; } }
$location_array = json_decode(html_entity_decode($_POST["location"])); $_SESSION["category_page"]["location"] = $location_array;
if (is_array($location_array)) { $any_location = false; foreach ($location_array as $row) { if ($row == "ANY") { $any_location = true; } } if (!$any_location) { $location_sql = " and ("; foreach ($location_array as $row) { $location_sql .= "tb.classlocation = ? or "; $parameters[] = $row; } $location_sql = substr_replace($location_sql, "", -3) . ")"; $exsql .= $location_sql; } } /**/ $_SESSION["category_page"]["min_hourly_rate"] = $_POST["min_hourly_rate"]; $_SESSION["category_page"]["max_hourly_rate"] = $_POST["max_hourly_rate"];
if ($_POST["min_hourly_rate"] >= 0 && $_POST["max_hourly_rate"]) { $exsql .= " and (tb.fee >= ? and tb.fee <= ?)"; $parameters[] = $_POST["min_hourly_rate"]; $parameters[] = $_POST["max_hourly_rate"]; }
$week_array = json_decode(html_entity_decode($_POST["week"])); $_SESSION["category_page"]["week"] = $week_array;
if (count($week_array)) { $week_sql = " and ("; foreach ($week_array as $row) { $week_sql .= "tb.week like '%" . ($row) . "%' or "; } $week_sql = substr_replace($week_sql, "", -3) . ")"; $exsql .= $week_sql; }/**/
$time_array = json_decode(html_entity_decode($_POST["time"])); $_SESSION["category_page"]["time"] = $time_array; if (count($time_array)) { $time_sql .= " and ("; foreach ($time_array as $row) { if ($row == 1) { $time_sql .= "(tb.time_h >= 9 and tb.time_h <= 13) or "; } else if ($row == 2) { $time_sql .= "(tb.time_h >= 14 and tb.time_h <= 18) or "; } else if ($row == 3) { $time_sql .= "(tb.time_h >= 19 and tb.time_h <= 22) or "; } } $time_sql = substr_replace($time_sql, "", -3) . ")"; $exsql .= $time_sql; }
$_SESSION["category_page"]["sort_by"] = $_POST["sort_by"];
if (!empty($_POST["sort_by"])) { if ($_POST["sort_by"] == "LOW_HIGH") { $order_by = " order by tb.fee ASC"; } else if ($_POST["sort_by"] == "HIGH_LOW") { $order_by = " order by tb.fee DESC"; } }
$_SESSION["category_page"]["places"] = $_POST['places'];
if ($_POST['places'] == 1) { $exsql .= " and (people_count - (reserved_people_count + (select count(*) from `order` where order_type = 'course' and job_id = tb.id and (status = 'process' or status = 'paid') and deleted = 0))) > 0"; }
$limit = 10;
if ($_SESSION["is_student"] == 1) { $sql = "select profile_id,(select id from `student_main` where cmsloginid = tb.user_id LIMIT 1) as id from `profile_user` as tb where user_id = ? and deleted = ? LIMIT 1"; $parameters2 = array($_SESSION['cmsloginid'], 0); $row_profile = bind_pdo($sql, $parameters2, "selectone"); }
/*$sql = "select *, (select count(*) from `order` where job_id = tb.id and (status = 'process' or status = 'paid') and deleted = 0) as count, (select count(*) from `order` where job_id = tb.id and (status = 'process' or status = 'paid') and studentmain_id = '" . $row_profile['id'] . "' and deleted = 0) as studentcount from tutor_postjob as tb where deleted = ? and approved = ? and status = ? and (NOW() between start_date and end_date)" . $exsql . $order_by;*/ $sql = "select *, (select count(*) from `order` where order_type = 'course' and job_id = tb.id and (status = 'paid') and deleted = 0) as count, (select count(*) from `order` where order_type = 'course' and job_id = tb.id and (status = 'paid') and studentmain_id = '" . $row_profile['id'] . "' and deleted = 0) as studentcount from tutor_postjob as tb where deleted = ? and approved = ? and status = ? and (NOW() between start_date and end_date)" . $exsql . $order_by; $rows = bind_pdo($sql, $parameters, "selectall");
//debug_log(1, dump_sql($sql, $parameters));
if (empty($rows)) { echo " " . _lang("沒有適合的課堂"); } else { foreach ($rows as $key => $row) { if (!empty($row["id"])) {
$sql = "select nickname,tutor_no,id from tutor_main where id = ? and deleted = ? LIMIT 1"; $parameters = array($row["tutormain_id"], 0); $row_tutor = bind_pdo($sql, $parameters, "selectone");
$sql = "select name_cn as name from master_type_code where id = ? and typeid = ? and deleted = ? LIMIT 1"; $parameters = array($row["mas_instrument"], 'INSTRUMENT', 0); $row_instrument = bind_pdo($sql, $parameters, "selectone");
$sql = "select * from master_type_code where typeid = ? and id = ? and deleted = ?"; $parameters = array('RESIDENCE_POSITIONCODE', $row['classlocation'], 0); $row_position = bind_pdo($sql, $parameters, "selectone");
$sql = "SELECT date FROM tutor_postjob_date WHERE postjob_refid = ? order by date asc"; $parameters99 = array(intval($row['id'])); $row_postjob_mindate = bind_pdo($sql, $parameters99, "selectone");
$sql = "SELECT date FROM tutor_postjob_date WHERE postjob_refid = ? order by date desc"; $parameters99 = array(intval($row['id'])); $row_postjob_maxdate = bind_pdo($sql, $parameters99, "selectone");
$sql = "SELECT refid FROM tutor_postjob_date WHERE postjob_refid = ?"; $parameters99 = array(intval($row['id'])); $rows_postjob_date = bind_pdo($sql, $parameters99, "selectall");
$remain_num = $row["people_count"] - ($row["reserved_people_count"] + $row['count']);
if ($count_tutor >= $start && $count_tutor < ($start + $limit)) { $week_array = "";
$week_day = explode(',', $row['week']); if (!empty($week_day)) { foreach ($week_day as $week) {
} }
$week_list = array("en" => array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), "cn" => array("日", "一", "二", "三", "四", "五", "六"));
foreach ($week_list[$_SESSION["langcode"]] as $key2 => $row2) {
$color = "background-color: #ccc; color: #fff; border-right: 1px solid #fff;"; foreach ($week_day as $row3) { if ($row3 == $key2) { $color = "background-color: #CC1342; color: #fff; border-right: 1px solid #fff;"; break; } } $week_array .= "<div style='padding: 0px 6px;float:left;" . $color . "'>" . $row2 . "</div>"; }
$week_array .= "<div class='clearboth'></div>"; ?> <div class="col-lg-12 col-md-6"> <div class="Tutor">
<div class="col-lg-4"> <!-- check if full --> <?php $photo = ''; for ($i = 1; $i <= 6; $i++) { if (!$photo) { $photo = $row["upload_photo" . $i]; } }
if ($remain_num <= 0 || $row["is_full"] == 1) { echo '<div style="position: absolute; top:15px; left: 15px;"><img src="img/full.png" style="width: 50%;"/></div>'; //echo '<button class="ContactTutorBTN" type="button" style="cursor: default; background-color: #CC1342; width: 100%; margin-top: 10px;">已滿額</button>';
echo '<a href="course_detail.php?id=' . $row['id'] . '"><img src="file/teacherpostjob/' . $photo . '" style="width: 100%; padding: 15px 0;"/></a>'; } else { echo '<a href="course_detail.php?id=' . $row['id'] . '"><img src="file/teacherpostjob/' . $photo . '" style="width: 100%; padding: 15px 0;"/></a>'; } ?>
</div>
<div class="col-lg-4 course_info_right_height_ref"> <div style="margin-top:10px;"> <div> <div style=""> <a href="course_detail.php?id=<?= $row['id'] ?>" style="text-decoration: none;font-size:18px;font-weight: bold;color:#CC1342"> <?= $row_instrument["name"] . " " . $row["people_count"] . "人班 (" . count($rows_postjob_date) . "堂)" ?> </a> </div>
<div style="border-bottom: 1px solid #dddddd"> <span style=""> 導師 : <b><a href="profile.php?id=<?= $row_tutor["id"] ?>"><?= $row_tutor['nickname'] ?></a> </b> <br> <span style="padding-left: 39px;"> (導師編號 : <?= $row_tutor['tutor_no'] ?>)</span> </span><br> </div>
<div style="">級別 : <? if ($row['level'] == 1) { echo '初級'; } else if ($row['level'] == 3) { echo '中級'; } ?> </div> <div style="">學生年齡 : <? if ($row['student_age'] == 1) { echo '4 - 10歲'; } else if ($row['student_age'] == 2) { echo '11 - 18歲'; } else if ($row['student_age'] == 3) { echo '18歲或以上'; } ?> </div> <div style="border-bottom: 1px solid #dddddd">課堂人數 : <?= $row["people_count"] ?> 人
<?php if ($remain_num > 0 && $row["is_full"] != 1) { ?> (尚餘<span style="color:#F00;"> <?= ($remain_num) ?> 個</span>名額) <?php } ?>
</div>
<div style=""> <div style="float:left;"> <?= _lang("Teaching District") ?> : </div> <div style="float:left;"> <?= $row_position["name_cn"] ?> </div> <div style="clear:both;"></div> </div>
<div><?= _lang("上課日期") ?> : <?= date('Y年m月d日', strtotime($row_postjob_mindate["date"])) ?> 至 <br><?= date('Y年m月d日', strtotime($row_postjob_maxdate["date"])) ?> (共<?= count($rows_postjob_date) ?>堂) </div>
<div> <div style="float: left;"><?= _lang("逢星期") ?> : </div> <?= $week_array ?> <div style="clear:both;"></div>
</div>
<div> <?= _lang("上課時間") ?> : <?= date('H:i', strtotime('0000-00-00 ' . $row['time_h'] . ':' . $row['time_m'])) ?> 至 <?= date('H:i', strtotime('0000-00-00 ' . $row['time_h'] . ':' . $row['time_m']) + ($row['course_hours'] * 60)) ?> </div>
<div style="clear:both;"></div>
<div style="clear:both;"></div> </div>
</div> </div>
<div class="col-lg-4 course_info_right" style="position: relative;"> <div style="margin-top:10px;">
<div style="">課堂編號 : <?= $row["postjob_no"] ?></div>
<div style="margin-top:10px;">截止報名日期 : <?= date("Y-m-d", strtotime($row["end_date"])) ?></div>
<div class="course_category_price"> <div> <span style="font-size: 16px;">每人收費 : </span> <span style="font-size: 24px; margin-top:15px;color: #CC1342;"><?= " $" . (float)$row["fee"] ?></span> </div>
<? if (empty($row["is_full"])) { ?> <? if ($_SESSION["is_student"] == 1) { ?> <? if ($row['studentcount'] == 0 && (($row["reserved_people_count"] + $row['count']) < $row["people_count"])) { ?> <form action="webadmin/course_search_process.php" method="post"> <input type="hidden" name="id" value="<?= $row['id'] ?>"/> <input type="hidden" name="type" value="fontend"/> <!--<button class="ContactTutorBTN" type="submit" onclick="return confirm('你確認參加?');">--> <button class="ContactTutorBTN" type="submit"> 立即付款報名 </button> </form> <br> <? } else { ?> <button class="ContactTutorBTN" type="button" style="cursor: default;"> 你已報名參加 </button> <br> <? } ?> <? } else { if ($remain_num > 0) { ?> <button class="ContactTutorBTN" type="button" onclick="open_payment_tutor('<?= aes_crypt($row['id'], 1) ?>')"> 立即付款報名 </button> <br> <? } } } else { ?> <button class="ContactTutorBTN" type="button" style="background: grey; cursor: default;"> 已滿額 </button> <? } ?> </div>
<!--<button class="ContactTutorBTN" type="button" onclick="location.href='course_detail.php?id=<?/*= $row['id'] */ ?>'">課堂詳情</button>-->
</div> </div>
<div style="clear:both;"></div> </div> </div> <?php } $count_tutor++; } }
$_end = $start + $limit; if ($_end > $count_tutor) $_end = $count_tutor;
$_start = $start + 1;
if ($_end == 0) $_start = 0;
if ($_SESSION["langcode"] == "en") { echo '<div id="displaying_text_temp" style="display: none;">Displaying ' . ($_start) . ' - ' . ($_end) . ' of ' . $count_tutor . ' results</div>'; } else if ($_SESSION["langcode"] == "cn") { echo '<div id="displaying_text_temp" style="display: none;">顯示 ' . ($_start) . ' - ' . ($_end) . ' 共' . $count_tutor . '結果</div>'; }
$count = $count_tutor; $numpage = $count / $limit;
echo '<div class="col-lg-12">'; if ($numpage > 1) { pagenav(); } echo '</div>'; }
exit;
} else if ($data['ajax'] == 'filter_tutor') {
/*var_dump($_POST); exit;*/
//filter tutor $inner_sql = ""; $where_clause = ""; $parameters = array(0, "fee", 4, 0, 1);
$_SESSION["category_page"]["quick_search"] = $_POST["quick_search"]; if (!empty($_POST["quick_search"])) { $where_clause .= " and (tutor_main.nickname LIKE ? or tutor_main.tutor_no LIKE ?)"; $parameters[] = "%" . trim($_POST["quick_search"]) . "%"; $parameters[] = "%" . trim($_POST["quick_search"]) . "%"; }
$_SESSION["category_page"]["category_id"] = $_POST["category_id"]; $category_id = $_POST["category_id"]; if ($_POST["category_id"] != "ANY") { $where_clause .= " and tutor_charge.mas_instrument = ?"; $parameters[] = $category_id; } else { $category_id = null; }
$_SESSION["category_page"]["level_of_grade"] = $_POST["level_of_grade"]; if (!empty($_POST["level_of_grade"])) { if ($_POST["level_of_grade"] != "ANY") { $where_clause .= " and tutor_expectcharge.grade=?"; $parameters[] = $_POST["level_of_grade"]; } }
$location = json_decode(html_entity_decode($_POST["location"]));
if(!empty($location) && $location != "ANY"){ $inner_sql .= " INNER JOIN tutor_teachareacode ON tutor_teachareacode.tutormain_id = tutor_main.id"; $where_clause .= " and tutor_teachareacode.mas_teachareacode=?"; $parameters[] = $location; } /* $location_array = json_decode(html_entity_decode($_POST["location"])); $_SESSION["category_page"]["location"] = $location_array; if (is_array($location_array)) { $any_location = false; foreach ($location_array as $row) { if ($row == "ANY") { $any_location = true; } }
if (!$any_location) { $location_clause = " and ("; foreach ($location_array as $row) { $location_clause .= "tutor_teachareacode.mas_teachareacode=? or "; $parameters[] = $row; } $location_clause = substr_replace($location_clause, "", -3) . ")"; $where_clause .= $location_clause;
$inner_sql .= " INNER JOIN tutor_teachareacode ON tutor_teachareacode.tutormain_id = tutor_main.id"; } }*/
/*if (!empty($_POST["recommend"])) { $where_clause .= " and tutor_main.recommend = ?"; $parameters[] = 1; }*/
if (!isset($_POST["start"])) { $start = 0; $_SESSION["category_page"]["start"] = $start; } else { $start = (int)$_POST["start"]; }
$_SESSION["category_page"]["start"] = $_POST["start"];
$_SESSION["category_page"]["sort_by"] = $_POST["sort_by"];
$limit = 10;
$sql = "select tutor_main.nickname, tutor_main.tutor_no, tutor_main.recommend, tutor_main.profilephoto_path, tutor_main.self_describemyself, tutor_main.cmsloginid, tutor_charge.tutormain_id, tutor_expectcharge.grade, stars, tutorial_mins from tutor_main INNER JOIN tutor_charge ON tutor_main.id = tutor_charge.tutormain_id INNER JOIN tutor_expectcharge ON tutor_charge.id = tutor_expectcharge.charge_id {$inner_sql} where tutor_charge.deleted = ? and tutor_expectcharge.type = ? and tutor_main.status = ? and tutor_main.deleted = ? and tutor_main.approved = ? {$where_clause} group by tutor_main.id order by tutor_main.recommend DESC, tutor_main.tutorial_mins DESC, tutor_main.createdate ASC";
$all_tutors = bind_pdo($sql, $parameters, "selectall");
$grade_info = get_master_type_code("LEVEL_OF_GRADE");
$tutors = $all_tutors;
if (empty($tutors)) { echo " " . _lang("No tutors."); } else {
foreach ($tutors as $key => $tutor) { if (!empty($tutor["tutormain_id"])) { //$teaching_experience = get_master_type_code_by_id($tutor["mas_teachexp"]); $tutor_expectcharge = get_tutor_expectcharge($tutor["tutormain_id"], $category_id, "fee");
//$tutors[$key]["teaching_experience"] = $teaching_experience["name_" . $langcode]; $tutors[$key]["min_fee"] = $tutor_expectcharge[0]["min_fee"]; $tutors[$key]["min_minutes"] = $tutor_expectcharge[0]["min_minutes"]; $tutors[$key]["min_instrument_name"] = $tutor_expectcharge[0]["min_instrument_name"]; $tutors[$key]["min_instrument_grade"] = $tutor_expectcharge[0]["min_instrument_grade"]; $tutors[$key]["min_category_id"] = $tutor_expectcharge[0]["min_category_id"];
} }
if (!empty($_POST["sort_by"])) { if ($_POST["sort_by"] == "LOW_HIGH") { uasort($tutors, 'low2high'); } else if ($_POST["sort_by"] == "HIGH_LOW") { uasort($tutors, 'high2low'); } }
$count_tutor = 0; //start from 0 foreach ($tutors as $tutor) { if (!empty($tutor["tutormain_id"])) {
/*if ($tutor["min_fee"] < $_POST["min_hourly_rate"] || $tutor["min_fee"] > $_POST["max_hourly_rate"]) { continue; }*/
if ($count_tutor >= $start && $count_tutor < ($start + $limit)) {
$sql = "select DISTINCT(master_type_code.extra1) from tutor_teachareacode INNER JOIN master_type_code ON tutor_teachareacode.mas_teachareacode = master_type_code.id where tutor_teachareacode.tutormain_id =? and tutor_teachareacode.deleted = ?"; $parameters = array($tutor['tutormain_id'], 0); $rows = bind_pdo($sql, $parameters, "selectall");
$area_array = array(); foreach ($rows as $row) { $sql = "select name_en,name_cn from master_type_code where typeid = 'TEACH_AREACODE' and code = ? and deleted = ?"; $parameters = array($row['extra1'], 0); $row_teachareacode = bind_pdo($sql, $parameters, "selectone"); $area_array[] = $row_teachareacode['name_' . $langcode]; }
?> <div class="col-xs-6"> <div class="Tutor" <?= ($tutor["recommend"] == 1 ? "style='position:relative;'" : "") ?>> <a href="profile.php?id=<?= $tutor["tutormain_id"] ?>&category_id=<?= $tutor["min_category_id"] ?>&start=<?=$start?>"> <?php if ($tutor["recommend"] == 1) { echo "<div style='position:absolute; top:0; left: 0'><img src='img/recommend.png' style='width: 40%;'> </div>"; } ?> <?php if (!empty($tutor["profilephoto_path"])) { ?> <div class="tutor_img_container pointer" style="height: 120px;"> <div class="tutor_img" style="background: url(<?= $site_info["url"] ?>file/teacher/<?= $tutor["profilephoto_path"] ?>) center center no-repeat; background-size: cover; width: inherit; height: inherit"></div> </div> <?php } ?> </a> <div class="CategoryTutorName tc" style="white-space: nowrap; <?= ($tutor["recommend"] == 1 ? " background-color: #D70000; font-weight: bold;" : "") ?>"> <?= $tutor["nickname"] ?> </div> <div class="TutorInfo" style="padding: 0;"> <div class="fl" style="font-size: 14px; padding: 0 5px;"> <?= $tutor["min_instrument_name"] ?> </div>
<div class="fr" style="font-size: 14px; padding: 0 5px;"> $<?= $tutor["min_fee"] ?>起 </div>
<div class="clearboth"></div> </div> </div> </div> <?php } $count_tutor++; } }
$_end = $start + $limit; if ($_end > $count_tutor) $_end = $count_tutor;
$_start = $start + 1;
if ($_end == 0) $_start = 0;
if ($_SESSION["langcode"] == "en") { //echo '<div id="displaying_text_temp" style="display: none;">Displaying ' . ($_start) . ' - ' . ($_end) . ' of ' . $count_tutor . ' results</div>'; echo '<div id="displaying_text_temp" style="display: none;">'. $count_tutor . ' results</div>'; } else if ($_SESSION["langcode"] == "cn") { //echo '<div id="displaying_text_temp" style="display: none;">顯示 ' . ($_start) . ' - ' . ($_end) . ' 共' . $count_tutor . '結果</div>'; echo '<div id="displaying_text_temp" style="display: none;">' . $count_tutor . '個搜尋結果</div>'; }
$count = $count_tutor; $numpage = $count / $limit;
echo '<div class="col-lg-12">'; if ($numpage > 1) { pagenav(); } echo '</div>'; }
exit;
} else if ($data["ajax"] == "facebook_login_checking") { $sql = "select count(*) as count from student_main where facebook_id = ?;"; $parameters = array($_POST["userID"]); $record = bind_pdo($sql, $parameters, "selectone");
$sql = "select count(*) as count from tutor_main where facebook_id = ?;"; $parameters = array($_POST["userID"]); $record2 = bind_pdo($sql, $parameters, "selectone"); if (($record['count'] + $record2['count']) > 0) { echo 'false'; } else { if (intval($_SESSION['student_login'])) { $id = intval($_SESSION['student_login']); $data['type'] = 'student'; } else if (intval($_SESSION['member_login'])) { $id = intval($_SESSION['member_login']); $data['type'] = 'tutor'; } if ($data['type'] == 'student' || $data['type'] == 'tutor') { $sql = "update " . $data['type'] . "_main set facebook_id = ? where id = ?"; $parameters = array($_POST["userID"], $id); bind_pdo($sql, $parameters); } echo 'true'; } exit(); /* $json = new Services_JSON(); $url = "https://graph.facebook.com/me?fields=id,name&access_token=".$_POST["accessToken"]."&id=".$_POST["userID"];
$result = file_get_contents($url); $result = json_decode($result, true);
if(!empty($result["id"]) && !empty($result["name"])){ $_SESSION["user_facebook_id"] = $result["id"]; echo $result["id"]; echo 'a'; }else{ //echo "FAIL"; } */ } else if ($data["ajax"] == "subscribe_email") { global $dbh; //check email format $email = $_POST["email"]; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo _lang("Invalid email format."); } else { $sql = "select * from subscribe where email = ? and deleted = ?"; $parameters = array($email, 0); $result = bind_pdo($sql, $parameters, "selectone"); if (!empty($result)) { echo _lang("We have recorded your email. Thank you for subscription."); } else { $sql = "insert into subscribe (email, createdate, lastupdate) value (?, ?, ?)"; $parameters = array($_POST["email"], date("Y-m-d H:i:s"), date("Y-m-d H:i:s")); bind_pdo($sql, $parameters);
if ($dbh->lastInsertId() > 0) { echo _lang("We have recorded your email. Thank you for subscription."); } else { echo _lang("We cannot record your email. Please refresh page and try again."); } } } } else if ($data["ajax"] == "contact_student_submit") { global $dbh; if (empty($_POST["job_id"]) || (int)$_POST["job_id"] <= 0) { echo _lang("Cannot find job id."); } else { $studentpostjob_id = (int)$_POST["job_id"]; $_POST["content"] = hide_sensitive_word($_POST["content"]);
//checking if (isset($_SESSION["cmsloginid"]) && isset($_SESSION["is_tutor"]) && $_SESSION["is_tutor"] == 1) { //TODO:: check if any valid order between student and tutor, if valid, unlock pm, $sql = "select *,student_postjob.id as student_postjob_id from student_postjob INNER JOIN student_main ON student_main.id = student_postjob.studentmain_id where student_postjob.status = ? and student_postjob.deleted = ? and student_postjob.approved = ? and student_main.status = ? and student_main.deleted = ? and student_main.approved = ? and student_postjob.id = ? order by student_postjob.approved_date"; $parameters = array(1, 0, 1, 4, 0, 1, $studentpostjob_id); $job = bind_pdo($sql, $parameters, "selectone");
if (!empty($job)) { //check pm number and unlock or not if (!empty($job["tutormain_id"])) { //matched and unlock pm } else { //not matched, need to count times of pm $sql = "select count(*) as tutor2student_pm_count, chat_limit from chat where from_id = ? and from_role = ? and to_id = ? and to_role = ? and deleted = ? and studentpostjob_id = ?"; $parameters = array($_SESSION["member_login"], "TUTOR", $job["studentmain_id"], "STUDENT", 0, $studentpostjob_id); $result = bind_pdo($sql, $parameters, "selectone"); if ($result["tutor2student_pm_count"] >= $result["chat_limit"] && $result["tutor2student_pm_count"] > 0) { //not allow pm echo _lang("You have reached the personal message limit. You do not allow to send message. if you have any questions, you can contact us through whatsapp (94460817) or call 34604105 by phone."); } else { //allow pm //check if first chat $job_info = get_studentpostjob2($studentpostjob_id);
//$sql = "select count(*) as chat_count, chat_limit, max(id) as max_id, first_chat_id from chat where ( ((from_id = ? and from_role = ?) or (to_id = ? and to_role = ?)) and ((from_id = ? and from_role = ?) or (to_id = ? and to_role = ?)) ) and deleted = ? and studentpostjob_id = ?"; $sql = "select count(*) as chat_count, chat_limit, max(id) as max_id, first_chat_id from chat where ( ((from_id = ? and from_role = ?) and (to_id = ? and to_role = ?)) or ((from_id = ? and from_role = ?) and (to_id = ? and to_role = ?)) ) and deleted = ? and studentpostjob_id = ?"; $parameters = array($_SESSION["member_login"], "TUTOR", $job_info["studentmain_id"], "STUDENT", $job_info["studentmain_id"], "STUDENT", $_SESSION["member_login"], "TUTOR", 0, $studentpostjob_id); $result2 = bind_pdo($sql, $parameters, "selectone");
if ($result2["chat_count"] == 0) { $first_chat = 1; $chat_limit = $site_info["chat_limit"];
$sql = "select max(id) as max_id from chat"; $parameters = array(); $result3 = bind_pdo($sql, $parameters, "selectone"); $first_chat_id = $result3["max_id"] + 1; } else { $first_chat = 0; $chat_limit = $result2["chat_limit"]; $first_chat_id = $result2["first_chat_id"]; }
$sql = "insert into chat (studentpostjob_id, from_id, from_role, to_id, to_role, content, first_chat, sent_date, chat_limit, first_chat_id) values (?,?,?,?,?,?,?,?,?,?)"; $parameters = array($studentpostjob_id, $_SESSION["member_login"], "TUTOR", $job["studentmain_id"], "STUDENT", $_POST["content"], $first_chat, date("Y-m-d H:i:s"), $chat_limit, $first_chat_id); bind_pdo($sql, $parameters);
if ($dbh->lastInsertId() > 0) { insert_approval_list("CHAT", "chat", $dbh->lastInsertId());
/*$notification_title = "MusicCircle"; $notification_body = _lang("你有1個新留言,請回覆。"); $app_notification_id = create_app_notification($notification_title, $notification_body, "SENT", "chat"); $user = get_student($job["studentmain_id"]); send_app_notification($app_notification_id, $user["cmsloginid"], null, $notification_title, $notification_body);*/
echo _lang("Your message has sent."); } else { echo _lang("Your message cannot send. Please refresh page and try again."); } } } } else { echo _lang("Jobs or tutors are not valid."); } } else { echo _lang("Access Denied!"); } }
} else if ($data["ajax"] == "contact_tutor_submit") { global $dbh; if (empty($_POST["job_id"]) || (int)$_POST["job_id"] <= 0) { echo _lang("Cannot find job id."); } else if (empty($_POST["tutor_id"]) || (int)$_POST["tutor_id"] <= 0) { echo _lang("Cannot find tutor id."); } else { $studentpostjob_id = (int)$_POST["job_id"]; $tutor_id = (int)$_POST["tutor_id"];
$_POST["content"] = hide_sensitive_word($_POST["content"]);
//checking if (isset($_SESSION["cmsloginid"]) && isset($_SESSION["is_student"]) && $_SESSION["is_student"] == 1) { //TODO:: check if any valid order between student and tutor, if valid, unlock pm, $sql = "select *,student_postjob.id as student_postjob_id from student_postjob INNER JOIN student_main ON student_main.id = student_postjob.studentmain_id where student_postjob.status = ? and student_postjob.deleted = ? and student_postjob.approved = ? and student_main.status = ? and student_main.deleted = ? and student_main.approved = ? and student_postjob.id = ? order by student_postjob.approved_date"; $parameters = array(1, 0, 1, 4, 0, 1, $studentpostjob_id); //debug_log(123, dump_sql($sql, $parameters)); $job = bind_pdo($sql, $parameters, "selectone"); //debug_log(111, $job); //check tutor status $sql = "select * from tutor_main where id = ? and status = ? and deleted = ? and approved = ?"; $parameters = array($tutor_id, 4, 0, 1); $tutor_info = bind_pdo($sql, $parameters, "selectone"); //debug_log(222, $tutor_info); if (!empty($job) && !empty($tutor_info)) { //check pm number and unlock or not if (!empty($job["tutormain_id"])) { //matched and unlock pm } else { //not matched, need to count times of pm $sql = "select count(*) as student2tutor_pm_count, chat_limit from chat where from_id = ? and from_role = ? and to_id = ? and to_role = ? and deleted = ? and studentpostjob_id = ?"; $parameters = array($_SESSION["student_login"], "STUDENT", $tutor_id, "TUTOR", 0, $studentpostjob_id); $result = bind_pdo($sql, $parameters, "selectone"); if ($result["student2tutor_pm_count"] >= $result["chat_limit"] && $result["student2tutor_pm_count"] > 0) { //not allow pm echo _lang("You have reached the personal message limit. You do not allow to send message. if you have any questions, you can contact us through whatsapp (94460817) or call 34604105 by phone."); } else { //allow pm
//check if first chat //$sql = "select count(*) as chat_count, chat_limit, max(id) as max_id, first_chat_id from chat where ( (from_id = ? and from_role = ?) or (to_id = ? and to_role = ?) ) and deleted = ? and studentpostjob_id = ?"; $sql = "select count(*) as chat_count, chat_limit, max(id) as max_id, first_chat_id from chat where ( ((from_id = ? and from_role = ?) and (to_id = ? and to_role = ?)) or ((from_id = ? and from_role = ?) and (to_id = ? and to_role = ?)) ) and deleted = ? and studentpostjob_id = ?";
$parameters = array($_SESSION["student_login"], "STUDENT", $tutor_id, "TUTOR", $tutor_id, "TUTOR", $_SESSION["student_login"], "STUDENT", 0, $studentpostjob_id); $result2 = bind_pdo($sql, $parameters, "selectone"); if ($result2["chat_count"] == 0) { $first_chat = 1; $chat_limit = $site_info["chat_limit"];
$sql = "select max(id) as max_id from chat"; $parameters = array(); $result3 = bind_pdo($sql, $parameters, "selectone"); $first_chat_id = $result3["max_id"] + 1; } else { $first_chat = 0; $chat_limit = $result2["chat_limit"]; $first_chat_id = $result2["first_chat_id"]; }
$sql = "insert into chat (studentpostjob_id, from_id, from_role, to_id, to_role, content, first_chat, sent_date, chat_limit, first_chat_id) values (?,?,?,?,?,?,?,?,?,?)"; $parameters = array($studentpostjob_id, $_SESSION["student_login"], "STUDENT", $tutor_id, "TUTOR", $_POST["content"], $first_chat, date("Y-m-d H:i:s"), $chat_limit, $first_chat_id); bind_pdo($sql, $parameters);
if ($dbh->lastInsertId() > 0) { insert_approval_list("CHAT", "chat", $dbh->lastInsertId());
/*$notification_title = "MusicCircle"; $notification_body = _lang("你有1個新留言,請回覆。"); $app_notification_id = create_app_notification($notification_title, $notification_body, "SENT", "chat"); $user = get_tutor($tutor_id); send_app_notification($app_notification_id, $user["cmsloginid"], null, $notification_title, $notification_body);*/
echo _lang("Your message has sent."); } else { echo _lang("Your message cannot send. Please refresh page and try again."); } } } } else { echo _lang("Jobs or tutors are not valid."); } } else { echo _lang("Access Denied!"); } } } else if ($data["ajax"] == "check_contact") { if (empty($_POST["job_id"]) || empty($_POST["tutor_id"])) { //error $result = array("error" => 1); echo json_encode($result); } else { //check musical instrument $job_id = (int)$_POST["job_id"]; $tutor_id = (int)$_POST["tutor_id"]; $matched_musical_instrument = compare_job_and_tutor($job_id, $tutor_id);
$job_info = get_studentpostjob2($job_id); //$sql = "select count(*) as count_chat, first_chat_id from chat where studentpostjob_id = ? and ((from_id = ? and from_role = ?) or (to_id = ? and to_role = ?)) and deleted = ?"; $sql = "select count(*) as chat_count, chat_limit, max(id) as max_id, first_chat_id from chat where studentpostjob_id = ? and ( ((from_id = ? and from_role = ?) and (to_id = ? and to_role = ?)) or ((from_id = ? and from_role = ?) and (to_id = ? and to_role = ?)) ) and deleted = ? and approved = ?"; $parameters = array($job_id, $tutor_id, "TUTOR", $job_info["studentmain_id"], "STUDENT", $job_info["studentmain_id"], "STUDENT", $tutor_id, "TUTOR", 0, 1); $chat_info = bind_pdo($sql, $parameters, "selectone");
$result = array("error" => 0, "matched_musical_instrument" => $matched_musical_instrument, "count_chat" => $chat_info["count_chat"], "first_chat_id" => $chat_info["first_chat_id"]);
echo json_encode($result); }
} else if ($data["ajax"] == "check_student_contact_tutor") {
}else if ($data["ajax"] == "my_wish") { if(!empty($_POST["type"]) && !empty($_POST["id"]) && !empty($_SESSION["cmsloginid"])){
$sql = "select * from wish_list where type = ? and ref_id = ? and cmsloginid = ?"; $parameters = array($_POST["type"], $_POST["id"], $_SESSION["cmsloginid"]); $result = bind_pdo($sql, $parameters, "selectone");
if(empty($result)){ //insert $sql = "insert into wish_list (createdate, createby, lastupdate, lastupby, type, ref_id, cmsloginid) values (?,?,?,?,?,?,?)"; $parameters = array(date("Y-m-d H:i:s"), $_SESSION["cmsloginid"], date("Y-m-d H:i:s"), $_SESSION["cmsloginid"], _h($_POST["type"]), _h($_POST["id"]), $_SESSION["cmsloginid"]); bind_pdo($sql, $parameters);
echo "1"; }else{ $sql = "update wish_list set status=case when status = 1 then 0 else 1 end, lastupdate=?, lastupby=? where id=?"; $parameters = array(date("Y-m-d H:i:s"), $_SESSION['cmsloginid'], $result["id"]); bind_pdo($sql, $parameters);
if($result["status"] == 0){ echo "1"; }else{ echo "0"; } } } }else if ($data["ajax"] == "get_unread_num") { $unread_chat = 0; $unread_job_notification = 0; $unread_order = 0; if($_SESSION["cmsloginid"]){ //count chat unread num if ($_SESSION["is_student"] == 1) { $sql = "select count(*) as unread from chat where to_role = ? and to_id = ? and deleted = ? and approved = ? and read_date is null"; $parameters = array("STUDENT", $_SESSION["student_login"], 0, 1); } else if ($_SESSION["is_tutor"] == 1) { $sql = "select count(*) as unread from chat where to_role = ? and to_id = ? and deleted = ? and approved = ? and read_date is null"; $parameters = array("TUTOR", $_SESSION["member_login"], 0, 1); }
$result = bind_pdo($sql, $parameters, "selectone"); $unread_chat = $result["unread"];
if ($_SESSION["is_tutor"]) { //count app_notification type=job, read_date=null $sql = "select count(*) as unread from app_notification_user inner join app_notification on app_notification.id = app_notification_user.app_notification_id where app_notification_user.cmsloginid = ? and app_notification_user.success = ? and app_notification.type = ? and app_notification_user.read_date is null"; $parameters = array($_SESSION["cmsloginid"], 1, "job"); $result = bind_pdo($sql, $parameters, "selectone"); $unread_job_notification = $result["unread"]; }
//get unread order num $sql = "select count(*) as unread from notification n inner join `order` od on od.id = n.table_id where n.table_name = ? and n.cmsloginid = ? and n.deleted = ? and n.`read` = ? and n.read_date is null and od.deleted = ? and n.createdate > ?"; $parameters = array("order", $_SESSION["cmsloginid"], 0, 0, 0, "2017-09-01"); $result = bind_pdo($sql, $parameters, "selectone"); $unread_order = $result["unread"]; }
$json = new Services_JSON(); $jsonReturnArr = array("response" => "success", "unread_chat" => (int)$unread_chat, "unread_job_notification" => (int)$unread_job_notification, "unread_order" => (int)$unread_order);
echo $json->encode($jsonReturnArr); exit(); }
|