/var/www/hkosl.com/m.musiccircle/student_postjob_process.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
<?php
    
include('_init.php');

    if (
$_SESSION["is_student"] != 1) {
        
header("Location: index.php");
        exit;
    }

    if (
$_GET["action"]) {
        switch (
$_GET["action"]) {
            case 
"manage":
                
$message "";
                
//print_r($cms_user_info);

                
if ($_POST["id"]) {
                    
$row get_studentpostjob((int)$_POST["id"]);
                    
$id  $row['id'];
                }

                if (!
$_POST["studentmain_id"]) {
                    
$message .= _lang("Please Select Student.") . "\\n\\n";
                }

                
$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"
;
                
$parameters  = array($_SESSION['cmsloginid'], 0);
                
$row_profile bind_pdo($sql$parameters"selectone");

                
$sql           "select count(*) as count from student_postjob as tb where studentmain_id = ? and deleted = ? 
                           and (select count(*) from `order` where job_id = tb.id and deleted = 0 and `status` = 'paid') = 0"
;
                
$parameters    = array($row_profile['id'], 0);
                
$count_product bind_pdo($sql$parameters"selectone");
                if (!(
$count_product['count'] < 3)) {
                    echo 
"<script language='JavaScript'>alert('有效的已發貼子最多同時存在3個。'); history.back();</script>";
                    exit;
                }

                if (!empty(
$message)) {
                    echo 
"<script>alert('" $message "'); history.back();</script>";
                    exit;
                }
                
$nowdate date("Y-m-d H:i:s");
                if (!
$row['id']) {
                    
//
                    
$sql        "select max(id) as maxid from student_postjob ";
                    
$parameters = array();
                    
$row2       bind_pdo($sql$parameters"selectone");
                    
$id         $row2{"maxid"} + 1;

                    
$sql        "select count(*)+1 as maxcount from student_postjob where mas_instrument = ? ";
                    
$parameters = array($_POST['mas_instrument']);
                    
$row_order  bind_pdo($sql$parameters"selectone");

                    
$data['postjob_no'] = 'J' date('ymd') . sprintf("%03d"$_POST['mas_instrument']) . sprintf("%05d"$row_order['maxcount']);

                    
$data['id']            = $id;
                    
$data['createdate']    = $nowdate;
                    
$data['status']        = 1;
                    
$data['approved']      = 1;
                    
$data['approved_date'] = $nowdate;
                    
$data['approved_by']   = $_SESSION['cmsloginid'];
                }
                
$data['studentmain_id']      = $_POST['studentmain_id'];
                
$data['mas_instrument']      = $_POST['mas_instrument'];
                
$data['level']               = $_POST['level'];
                
$data['30mins_min_budget']   = $_POST['30mins_min_budget'];
                
$data['30mins_max_budget']   = $_POST['30mins_max_budget'];
                
$data['45mins_min_budget']   = $_POST['45mins_min_budget'];
                
$data['45mins_max_budget']   = $_POST['45mins_max_budget'];
                
$data['60mins_min_budget']   = $_POST['60mins_min_budget'];
                
$data['60mins_max_budget']   = $_POST['60mins_max_budget'];
                
$data['explessonpermonth']   = $_POST['explessonpermonth'];
                
$data['tutormain_id']        = $_POST['tutormain_id'];
                
$data['tutorreq_gender']     = $_POST['tutorreq_gender'];
                
$data['tutorreq_level']      = $_POST['tutorreq_level'];
                
$data['tutorreq_age']        = $_POST['tutorreq_age'];
                
$data['tutorreq_others']     = hide_sensitive_word($_POST['tutorreq_others']);
                
$data['completed_flag']      = (int)$_POST['completed_flag'];
                
$data['student_post_gender'] = $_POST['student_post_gender'];
                
$data['student_mas_contactstudentrel'] = $_POST['student_mas_contactstudentrel'];
                
$data['student_mas_yearrange'] = $_POST['student_mas_yearrange'];

                
/*$sql         = "select profile_id from `profile_user` as tb where user_id = ? and deleted = ? LIMIT 1";
                $parameters  = array($_SESSION['cmsloginid'], 0);
                $row_profile = bind_pdo($sql, $parameters, "selectone");
                if ($row_profile['profile_id'] == 4) {
                    $data['approved']      = 1;
                    $data['approved_date'] = $nowdate;
                    $data['approved_by']   = $_SESSION['cmsloginid'];
                    insert_approval_list('JOB', 'student_postjob', $id);
                }*/

                
$data['lastupby']   = $nowdate;
                
$data['lastupdate'] = $_SESSION['cmsloginid'];
                
$data['deleted']    = 0;
                if (
$row) {
                    
$sql        mysql_install($data'student_postjob''edit''id');
                    
$data['id'] = $id;
                } else {
                    
$sql mysql_install($data'student_postjob''add');
                }

                
$arraykey array_keys($data);
                unset(
$parameters);
                for (
$i 0$i count($arraykey); $i++) {
                    
$parameters[$i] = $data[$arraykey[$i]];
                }
                
bind_pdo($sql$parameters);

                if (empty(
$_POST["id"])) {
                    
//need to get musical instrument name and loop related tutor
                    
$sql            "select name_" get_langcode() . " as name from master_type_code where id = ? and typeid = ? and deleted = ? LIMIT 1";
                    
$parameters     = array($data["mas_instrument"], 'INSTRUMENT'0);
                    
$row_instrument bind_pdo($sql$parameters"selectone");

                    
$notification_title "MusicCircle";
                    
$notification_body _lang("有新的").$row_instrument["name"]._lang("帖子你可能會感興趣,請查看並給學生留言。");
                    
$app_notification_id create_app_notification($notification_title$notification_body"SENT""job");

                    
$sql "select * from tutor_charge
                inner join tutor_main on tutor_main.id = tutor_charge.tutormain_id
                inner join sys_cms_login on sys_cms_login.cmsloginid = tutor_main.cmsloginid
                where tutor_charge.mas_instrument = ? and tutor_charge.deleted = ? and tutor_main.status = ? and tutor_main.deleted = ? and tutor_main.approved = ? and sys_cms_login.cmsstatus = ? and sys_cms_login.deleted = ? and sys_cms_login.app_device_id is not null and sys_cms_login.app_notification_token is not null"
;
                    
$parameters = array($data["mas_instrument"], 040110);
                    
$result bind_pdo($sql$parameters"selectall");

                    global 
$site_info;
                    
$notification_url $site_info["app_url"]."job_detail.php?id=".$id;
                    if(!empty(
$result)){
                        foreach (
$result as $row01){
                            
send_app_notification($app_notification_id$row01["cmsloginid"], null$notification_title$notification_body$notification_url);
                        }
                    }
                }


                
// 希望學習地方
                
unset($tmpdata);
                
$sql        "DELETE FROM `student_postjoblearnvenus` WHERE studentpostjob_id=?;";
                
$parameters = array($id);
                
bind_pdo($sql$parameters);
                if (
is_array($_POST['teachvenus_id'])) {
                    foreach (
$_POST['teachvenus_id'] as $value) {
                        
$tmpdata['studentpostjob_id'] = $id;
                        
$tmpdata['mas_teachvenus']    = $value;
                        
$tmpdata['lastupby']          = $nowdate;
                        
$tmpdata['lastupdate']        = $_SESSION['cmsloginid'];
                        
$tmpdata['deleted']           = 0;
                        
$sql                          mysql_install($tmpdata'student_postjoblearnvenus''add');
                        
$arraykey                     array_keys($tmpdata);
                        unset(
$parameters);
                        for (
$i 0$i count($arraykey); $i++) {
                            
$parameters[$i] = $tmpdata[$arraykey[$i]];
                        }
                        
bind_pdo($sql$parameters);
                    }
                }
                
// 希望學習模式
                
unset($tmpdata);
                
$sql        "DELETE FROM `student_postjoblearnmode` WHERE studentpostjob_id=?;";
                
$parameters = array($id);
                
bind_pdo($sql$parameters);
                if (
is_array($_POST['teachmode_id'])) {
                    foreach (
$_POST['teachmode_id'] as $value) {
                        
$tmpdata['studentpostjob_id'] = $id;
                        
$tmpdata['mas_teachmode']     = $value;
                        
$tmpdata['lastupby']          = $nowdate;
                        
$tmpdata['lastupdate']        = $_SESSION['cmsloginid'];
                        
$tmpdata['deleted']           = 0;
                        
$sql                          mysql_install($tmpdata'student_postjoblearnmode''add');
                        
$arraykey                     array_keys($tmpdata);
                        unset(
$parameters);
                        for (
$i 0$i count($arraykey); $i++) {
                            
$parameters[$i] = $tmpdata[$arraykey[$i]];
                        }
                        
bind_pdo($sql$parameters);
                    }
                }
                
// 希望上課時間
                
unset($tmpdata);
                
$sql        "DELETE FROM `student_postjoblearntime` WHERE studentpostjob_id=?;";
                
$parameters = array($id);
                
bind_pdo($sql$parameters);
                if (
is_array($_POST['learntime'])) {
                    foreach (
$_POST['learntime'] as $value) {
                        
$tmpdata['studentpostjob_id'] = $id;
                        
$tmpdata['learntime']         = $value;
                        
$tmpdata['lastupby']          = $nowdate;
                        
$tmpdata['lastupdate']        = $_SESSION['cmsloginid'];
                        
$tmpdata['deleted']           = 0;
                        
$sql                          mysql_install($tmpdata'student_postjoblearntime''add');
                        
$arraykey                     array_keys($tmpdata);
                        unset(
$parameters);
                        for (
$i 0$i count($arraykey); $i++) {
                            
$parameters[$i] = $tmpdata[$arraykey[$i]];
                        }
                        
bind_pdo($sql$parameters);
                    }
                }
                
// 學習地區
                
$sql        "DELETE FROM `student_postjoblearndistrict` WHERE studentpostjob_id=?;";
                
$parameters = array($id);
                
bind_pdo($sql$parameters);
                
$sql        "select * from master_type_code where typeid = ? and deleted = ?";
                
$parameters = array('TEACH_AREACODE'0);
                
$rows_area  bind_pdo($sql$parameters"selectall");
                foreach (
$rows_area as $row_area) {
                    foreach (
$_POST['area' $row_area['id']] as $index => $value) {
                        unset(
$tmpdata);
                        
$tmpdata['studentpostjob_id'] = $id;
                        
$tmpdata['mas_teachareacode'] = $value;
                        
$tmpdata['lastupdate']        = $nowdate;
                        
$tmpdata['deleted']           = 0;
                        
$sql                          mysql_install($tmpdata'student_postjoblearndistrict''add');
                        
$arraykey                     array_keys($tmpdata);
                        unset(
$parameters);
                        for (
$i 0$i count($arraykey); $i++) {
                            
$parameters[$i] = $tmpdata[$arraykey[$i]];
                        }
                        
bind_pdo($sql$parameters);
                    }
                }

                
header("Location: student_postjob_index.php?update=1");
                break;

            case 
"status":
                
$nowdate date("Y-m-d H:i:s");
                
$id      = (int)$_GET["id"];

                
$sql        "update student_postjob set status=case when status = 1 then 0 else 1 end, lastupdate=?, lastupby=? where id = ?";
                
$parameters = array($nowdate$_SESSION['cmsloginid'], $id);

                
bind_pdo($sql$parameters);

                
header("Location: student_postjob_index.php?update=1");
                break;

            case 
"delete":
                
$id = (int)$_GET["id"];

                
$sql        "update student_postjob set deleted = 1 , lastupdate=?, lastupby=? where id = ?";
                
$parameters = array($nowdate$_SESSION['cmsloginid'], $id);
                
bind_pdo($sql$parameters);

                
header("Location: student_postjob_index.php?update=1");
                break;
        }
    }