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

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

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

                
if(!empty($_POST)){
                    if(
$_POST["id"]){
                        
$row get_teacherpostjob((int)$_POST["id"]);
                        
$id $row['id'];
                    }

                    if (!
$_POST["tutormain_id"]) {
                        
$message .= "請選擇導師。" "\\n\\n";
                    }
                }else{
                    
//post data too large
                    
$message .= "你所上傳的圖片檔案過大,請選擇像素較低的圖片或分開上傳。";
                }

                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 tutor_postjob";
                    
$parameters = array();
                    
$row2       bind_pdo($sql$parameters"selectone");
                    
$id $row2{"maxid"} + 1;

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

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

                    
$data['id'] = $id;
                    
$data['createdate'] = $nowdate;
                    
$data['status'] = 0;
                    
/*
                    $data['approved'] = 1;
                    $data['approved_date'] = $nowdate;
                    $data['approved_by'] = $_SESSION['cmsloginid'];
                    */
                
}
                
$data['start_date'] = $_POST['start_date'];
                
$data['end_date'] = $_POST['end_date'];
                
$data['tutormain_id'] = $_POST['tutormain_id'];
                
$data['mas_instrument'] = $_POST['mas_instrument'];
                
$data['level'] = $_POST['level'];
                
$data['student_age'] = $_POST['student_age'];
                
$data['detail_cn'] = $_POST['detail_cn'];
                
$data['reserved_people_count'] = $_POST['reserved_people_count'];
                
$data['people_count'] = $_POST['people_count'];
                
$data['course_count'] = $_POST['course_count'];
                
$data['course_hours'] = $_POST['course_hours'];
                
$data['address_cn'] = $_POST['address_cn'];
                if(
$_POST['address_admin_cn']){
                    
$data['address_admin_cn'] = $_POST['address_admin_cn'];
                }
                
$data['fee'] = $_POST['fee'];

                
//樂器安排
                /*$data['instrument_arrangement'] = $_POST["instrument_arrangement"];
                if ($_POST["instrument_arrangement"] == "1") {
                    $data['instrument_deposit']            = $_POST["instrument_deposit"];
                    $data['instrument_arrangement_remark'] = $_POST["instrument_arrangement_remark"];
                } else if ($_POST["instrument_arrangement"] == "2") {
                    $data['instrument_deposit']            = $_POST["instrument_deposit"];
                    $data['instrument_rent_fee']           = $_POST["instrument_rent_fee"];
                    $data['instrument_arrangement_remark'] = $_POST["instrument_arrangement_remark"];
                } else if ($_POST["instrument_arrangement"] == "3") {

                }*/

                
$data['instrument_arrangement_1'] = (int)$_POST['instrument_arrangement_1'];
                
$data['instrument_arrangement_2'] = (int)$_POST['instrument_arrangement_2'];
                
$data['instrument_arrangement_3'] = (int)$_POST['instrument_arrangement_3'];

                if((int)
$_POST['instrument_arrangement_1']==1){
                    
$data['instrument_deposit_1'] = $_POST['instrument_deposit_1'];
                }else{
                    
$data['instrument_deposit_1'] = "";
                }

                if((int)
$_POST['instrument_arrangement_2']==1){
                    
$data['instrument_deposit_2'] = $_POST['instrument_deposit_2'];
                    
$data['instrument_rent_fee_2'] = $_POST['instrument_rent_fee_2'];
                }else{
                    
$data['instrument_deposit_2'] = "";
                    
$data['instrument_rent_fee_2'] = "";
                }

                if(isset(
$_POST['is_full']) && $_POST['is_full']==1){
                    
$data['is_full'] = 1;
                }else{
                    
$data['is_full'] = 0;
                }

                
$data['instrument_arrangement_remark'] = $_POST['instrument_arrangement_remark'];

                for(
$i=1;$i<=6;$i++){
                    if(!
$_POST["upload_photo".$i."_on"]){
                        
$data['upload_photo'.$i] = '';
                    }

                    if(!empty(
$_POST["base64_upload_photo".$i])){
                        
$base64_string $_POST["base64_upload_photo".$i];
                        
$file_data explode(','$base64_string);

                        if(
strpos($file_data[0], "image/jpeg") !== false || strpos($file_data[0], "image/png") !== false){
                            if(
strpos($file_data[0], "image/jpeg") !== false){
                                
$file_ext ".jpg";
                            }else if(
strpos($file_data[0], "image/png") !== false){
                                
$file_ext ".png";
                            }

                            
$newfilename random_string(10) . "_teacherpostjob_"$id $file_ext// default length 8

                            
$output_file "file/teacherpostjob/".$newfilename;
                            
$ifp fopen($output_file"wb");

                            
fwrite($ifpbase64_decode($file_data[1]));
                            
fclose($ifp);

                            
//image_fix_orientation("file/teacherpostjob/" . $newfilename);

                            
$data['upload_photo'.$i] = $newfilename;

                        }
                    }

                    
/*if ($_FILES["upload_photo".$i]['name'] <> '') {
                        //check if image type is valid or not


                        //check if image type is valid or not
                        $filename = $_FILES["upload_photo".$i]['name'];
                        preg_match("/\.([^\.]+)$/", $filename, $file_ext);
                        $newfilename = random_string(10) . "_teacherpostjob_" . $id . "." . $file_ext[1]; // default length 8
                        move_uploaded_file($_FILES["upload_photo".$i]['tmp_name'], "../file/teacherpostjob/" . $newfilename) or die ("Could not copy the file");
                        image_fix_orientation("../file/teacherpostjob/" . $newfilename);
                        $photo = $newfilename;
                        $data['upload_photo'.$i] = $photo;
                    }*/
                
}
                
$data['time_h'] = $_POST['time_h'];
                
$data['time_m'] = $_POST['time_m'];
                
$data['week'] = implode(',',$_POST['week']);
                
$data['classlocation'] = $_POST['classlocation'];
                
/*
                $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'] == 3){
                    $data['approved'] = 0;
                    $data['approved_date'] = $nowdate;
                    $data['approved_by'] = $_SESSION['cmsloginid'];
                    insert_approval_list('JOB', 'teacher_postjob', $id);
                }
                */

                
$data['lastupby'] = $nowdate;
                
$data['lastupdate'] = $_SESSION['cmsloginid'];
                
$data['deleted'] = 0;
                if(
$row){
                    if(
$row_profile['profile_id']==4){
                        
$data['approved'] = 0;
                    }else{
                        
$data['approved'] = 1;
                    }
                    
$sql mysql_install($data,'tutor_postjob','edit','id',$id,1);
                    
$data['id'] = $id;
                }else{
                    
$sql mysql_install($data,'tutor_postjob','add');
                }
                
$arraykey=array_keys($data);
                unset(
$parameters);
                for(
$i=0;$i<count($arraykey);$i++){
                    
$parameters[$i]=$data[$arraykey[$i]];
                }

                
bind_pdo($sql$parameters);
                
// 上課日子及時間
                
unset($tmpdata);
                if(
$id){
                    
$sql "DELETE FROM `tutor_postjob_date` WHERE postjob_refid = ?;";
                    
$parameters = array($id);
                    
bind_pdo($sql$parameters);
                }
                if(
is_array($_POST['date'])){
                    foreach(
$_POST['date'] as $value){
                        
$tmpdata['postjob_refid'] = $id;
                        
$tmpdata['date'] = $value.' '.$_POST['time_h'].':'.$_POST['time_m'];
                        
$tmpdata['deleted'] = 0;
                        
$sql mysql_install($tmpdata,'tutor_postjob_date','add');
                        
//echo $sql;
                        
$arraykey=array_keys($tmpdata);
                        unset(
$parameters);
                        for(
$i=0;$i<count($arraykey);$i++){
                            
$parameters[$i]=$tmpdata[$arraykey[$i]];
                        }
                        
bind_pdo($sql$parameters);
                    }
                }

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

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

                
$sql        "update tutor_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: tutor_postjob_index.php?update=1");
                break;

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

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

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