/var/www/hkosl.com/imusiccircle/webadmin/student_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
<?php
    $page_settings 
= array(
        
'formid'     => 'student'// for permission
        
'section'    => 'Master'// parent/page title
        
'subsection' => 'Student'// page title
        
'domain'     => 'student'// table/model name
        
'access'     => 'GNr'// for permission
    
);

    require_once 
"check_login.php";
    
$nowdate date("Y-m-d H:i:s");
    
$message "";

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

    if (!
$row['id']) {
        if (!
$_POST["email"]) {
            
$message .= _lang("請輸入你的電郵") . "\\n\\n";
        } else {
            
//checkEmail
            
$sql          "SELECT count(*) as count FROM student_main WHERE email=? AND deleted = 0";
            
$parameters   = array($_POST['email']);
            
$record_email bind_pdo($sql$parameters"selectone");

            if (
$record_email['count'] > 0) {
                
$message .= _lang("你的電郵已有人使用") . "\\n\\n";
            }
        }
        if (!
$_POST["password"]) {
            
$message .= _lang("請輸入你的密碼") . "\\n\\n";
        } else {
            if (
strlen($_POST["password"]) < 8) {
                
$message .= _lang("必須輸入最少8位字元的密碼") . "\\n\\n";
            } elseif (
$_POST["password"] != $_POST["repassword"]) {
                
$message .= _lang("你輸入的密碼不一致") . "\\n\\n";
            }
        }
    }

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


    if (
$row) {
        
$id intval($_POST['id']);
        if (
$_POST["password"]) {
            
$data['cmsloginpw'] = Password::hash($_POST['password']);
            
$sql                mysql_install($data'sys_cms_login''edit''cmsloginid');
            
$data['cmsloginid'] = $row{'cmsloginid'};
            
$arraykey           array_keys($data);
            unset(
$parameters);
            for (
$i 0$i count($arraykey); $i++) {
                
$parameters[$i] = $data[$arraykey[$i]];
            }
            
bind_pdo($sql$parameters);
        }
    } else {
        
//CMS Login
        
$sql                         "select max(cmsloginid) as maxid from sys_cms_login ";
        
$parameters                  = array();
        
$row2                        bind_pdo($sql$parameters"selectone");
        
$cmsloginid                  $row2{"maxid"} + 1;
        
$data['cmsloginid']          = $cmsloginid;
        
$data['cmsusername']         = aes_crypt($_POST['email'], 1);
        
$data['cmsloginname']        = aes_crypt($_POST['email'], 1);
        
$data['cmsloginpw']          = Password::hash($_POST['password']);
        
$data['cmsrole']             = 'user';
        
$data['cmsstatus']           = '1';
        
$data['createdate']          = $nowdate;
        
$data['createby']            = '';
        
$data['lastupdate']          = $nowdate;
        
$data['lastupby']            = '';
        
$data['password_expirydate'] = '2047-07-01';
        
$data['deleted']             = 0;
        
$data['is_tutor']            = 0;
        
$data['is_student']          = 1;
        
$sql                         mysql_install($data'sys_cms_login''add');
        
$arraykey                    array_keys($data);
        unset(
$parameters);
        for (
$i 0$i count($arraykey); $i++) {
            
$parameters[$i] = $data[$arraykey[$i]];
        }
        
bind_pdo($sql$parameters);
        
//
        
unset($data);
        
$data['deleted']    = 0;
        
$data['profile_id'] = 4;
        
$data['user_id']    = $cmsloginid;
        
$sql                mysql_install($data'profile_user''add');
        
$arraykey           array_keys($data);
        unset(
$parameters);
        for (
$i 0$i count($arraykey); $i++) {
            
$parameters[$i] = $data[$arraykey[$i]];
        }
        
bind_pdo($sql$parameters);
        unset(
$data);
        
//
        
$sql        "select max(id) as maxid from student_main ";
        
$parameters = array();
        
$row2       bind_pdo($sql$parameters"selectone");

        
$id                      $row2{"maxid"} + 1;
        
$data['student_no']      = getstudentNo($id);
        
$data['status']          = 4;
        
$data['approved']        = 1;
        
$data['approved_date']   = $nowdate;
        
$data['approved_by']     = $_SESSION['cmsloginid'];
        
$data['createdate']      = $nowdate;
        
$data['lastupdate']      = $nowdate;
        
$data['id']              = $id;
        
$data['cmsloginid']      = $cmsloginid;
        
$data['email']           = aes_crypt($_POST['email'], 1);
        
$data['mobno']           = aes_crypt($_POST['mobno'], 1);
        
$data['isemailverified'] = 1;
        
$data['isphoneverified'] = 1;
    }
    
$data['contactname']           = $_POST['contactname'];
    
$data['restelno']              = aes_crypt($_POST['hometelno'], 1);
    
$data['gender']                = $_POST['gender'];
    
$data['mas_yearrange']         = $_POST['mas_yearrange'];
    
$data['mas_contactstudentrel'] = $_POST['mas_contactstudentrel'];
    
$data['mas_residencecode']     = $_POST['mas_residencecode'];
    
$data['address']               = $_POST['address'];
    
$data['mas_contacttimerange']  = $_POST['mas_contacttimerange'];
    
$data['lastupby']              = $nowdate;
    
$data['lastupdate']            = $_SESSION['cmsloginid'];
    
$data['deleted']               = 0;

    
//student profile pic
    
for($i=1;$i<=1;$i++){
        if(!
$_POST["profile_pic".$i."_on"]){
            
$data['profile_pic'.$i] = '';
        }

        if(!empty(
$_POST["base64_profile_pic".$i])){
            
$base64_string $_POST["base64_profile_pic".$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) . "_student_profile_pic_"$id $file_ext// default length 8

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

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

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

                
$data['profile_pic'.$i] = $newfilename;
            }
        }
    }

    if (
$row) {
        
$sql        mysql_install($data'student_main''edit''id'$id);
        
$data['id'] = $id;
    } else {
        
$sql mysql_install($data'student_main''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);
    
$sql        "instrumentquali";
    
$sql        "DELETE FROM `student_instrumentquali` WHERE studentmain_id=?;";
    
$post       formatPostData($_POST['instrumentquali']);
    
$parameters = array($id);
    
bind_pdo($sql$parameters);

    if (
is_array($post)) {
        foreach (
$post as $value) {
            
$tmpdata['studentmain_id'] = $id;
            
$tmpdata['mas_instrument'] = $value['mas_instrument'];
            
$tmpdata['grade']          = $value['grade'];
            
$tmpdata['year']           = $value['year'];
            
$tmpdata['lastupby']       = $nowdate;
            
$tmpdata['lastupdate']     = $_SESSION['cmsloginid'];
            
$tmpdata['deleted']        = 0;
            
$sql                       mysql_install($tmpdata'student_instrumentquali''add');
            
$arraykey                  array_keys($tmpdata);
            unset(
$parameters);
            for (
$i 0$i count($arraykey); $i++) {
                
$parameters[$i] = $tmpdata[$arraykey[$i]];
            }
            
bind_pdo($sql$parameters);
        }
    }
    
$status 2;
    
header("Location: student_index.php?msg=1&status=" $status);
?>