JezK
Edit File: 2021-09-24student_access.php
<? session_start(); date_default_timezone_set("Asia/Calcutta"); include_once("connect.php"); include_once("error_codes.php"); class student_access { function get_classes_byschool_total($schoolid,$acadamic_id) { $sql="SELECT `class_id` , `class_name` , `junior_status`,`class_order` FROM `ced_t_class` where school_id = '".$schoolid."' and academic_year_id ='".$acadamic_id."' order by class_order asc"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data[]=$row; } return $data; } function get_sections_bystudent($classid) { $sql="SELECT `section_id` , `section_name` FROM `ced_t_sections` WHERE `class_id` = '".$classid."' order by section_id asc"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data2[$row['section_id']]=$row; } return $data2; } function check_license_count($schoolid) { $sql="SELECT license_count,school_license_id FROM `ced_t_school_licenses` WHERE school_id = '".$schoolid."' and license_status = '1' "; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data[$row['license_count']]=$row; } return $data; } function check_student_count($school_id) { $qry = "select count(student_id) as cnt from ced_t_students where school_id = '".$school_id."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function check_student($admission_number,$school_id,$ay) { $qry = "select student_id from ced_t_students where student_admission_number = '".$admission_number."' and school_id ='".$school_id."' and academic_year_id=".(int)$ay; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_student_roll($stu_rollnum,$classes,$sections,$school_id,$choosen_acc_id) { $qry = "select student_id from ced_t_students where student_rollno = '".$stu_rollnum."' and class_id=".(int)$classes." and section_id=".(int)$sections." and academic_year_id=".(int)$choosen_acc_id." and school_id ='".$school_id."' "; $result=mysql_query($qry); $row=mysql_num_rows($result); return $row; } function create_student($post,$im_url,$session) { //echo $im_url.'<br/>'; $created_date = date('Y-m-d'); $dateInput = explode('/',$post['stu_admissiondate']); $dateInput2 = explode('/',$post['stu_birthdate']); $admision_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $birth_date=$dateInput2[2].'-'.$dateInput2[1].'-'.$dateInput2[0]; $qry="INSERT INTO ced_t_students (student_rollno,class_id,section_id,student_firstname,student_lastname,student_admission_number,student_admission_date,student_address,student_blood_group, student_father_name,student_father_email,student_father_mobile,student_father_mobile2,student_mother_name,student_mother_email,student_mother_mobile,student_mother_mobile2,student_guardian_name, student_guardian_email,student_guardian_mobile,student_guardian_mobile2,academic_year_id,school_id,status,created_on,created_by,date_of_birth,profile_pic,hostler_status) VALUES ( '".trim($post['stu_rollnum'])."','".$post['classes']."','".$post['sections']."','".trim($post['stu_firstname'])."','".trim($post['stu_lastname'])."','".trim($post['stu_admissionnumber'])."','".$admision_date."', '".trim($post['stu_address'])."','".$post['stu_blodgroup']."','".trim($post['stu_fathername'])."','".$post['stu_fatheremail']."','".$post['stu_fathermobile']."','".$post['stu_fathermobile2']."', '".trim($post['stu_mothername'])."','".$post['stu_motheremail']."','".$post['stu_mothermobile']."','".$post['stu_mothermobile2']."','".trim($post['stu_gurdianname'])."','".$post['stu_gurdianemail']."', '".$post['stu_gurdianmobile']."','".$post['stu_gurdianmobile2']."','".$session['child']['choosen_academic_id']."','".$session['child']['log_school_id']."','1','".$created_date."','".$session['child']['auth_id']."','".$birth_date."','".$im_url."','".$post['hostel']."') "; //exit; $exe=mysql_query($qry); $student_id=mysql_insert_id(); $_SESSION['student_add']['stu_id'] = $student_id; $_SESSION['child']['section_id'] = $post['sections']; $_SESSION['child']['stu_class_id'] = $post['classes']; if($exe) $response=ERR203; else $response=ERR204; return $response; } function parentDeviceId($id) { $sql="select device_id from ced_t_students_parent where student_id=".(int)$id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); return $res['device_id']; } else return '0'; } function parentDeviceIds($id) { $sql="select device_id from ced_t_students_parent where student_id=".(int)$id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { while($res=mysql_fetch_array($exe)) $div[]=$res['device_id']; return $div; } else return '0'; } function student_data_byid($student_id) { $sql="SELECT * FROM `ced_t_students` WHERE student_id = '".$student_id."' "; $result=mysql_query($sql); $row=mysql_fetch_array($result); return $row; } function check_fathermail_edit($post,$schoolid) { $qry = "select student_id from ced_t_students where student_father_email = '".$post['stu_fatheremail']."' and class_id = '".$post['classes']."' and section_id ='".$post['sections']."' and school_id ='".$schoolid."' and student_id != '".$post['student_id']."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_mothermail_edit($post,$schoolid) { $qry = "select student_id from ced_t_students where student_mother_email = '".$post['stu_motheremail']."' and class_id = '".$post['classes']."' and section_id ='".$post['sections']."' and school_id ='".$schoolid."' and student_id != '".$post['student_id']."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_student_edit($admission_number,$student_id,$school_id,$ay) { $qry = "select student_id from ced_t_students where student_admission_number = '".$admission_number."' and school_id ='".$school_id."' and academic_year_id=".(int)$ay." and student_id !='".$student_id."'"; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function edit_check_student_roll($stdid,$stu_rollnum,$classes,$sections,$school_id,$choosen_acc_id) { $qry = "select student_id from ced_t_students where student_rollno = '".$stu_rollnum."' and class_id=".(int)$classes." and section_id=".(int)$sections." and academic_year_id=".(int)$choosen_acc_id." and school_id ='".$school_id."' and student_id<>".(int)$stdid; $result=mysql_query($qry); $row=mysql_num_rows($result); return $row; } function update_student($post,$session,$im_url) { $nstatus=0; $nstatus1=0; $msg=""; $prevs="select * from ced_t_students where student_id='".$post['student_id']."'"; $sql=mysql_query($prevs); $records=mysql_fetch_array($sql); /*if($records['student_father_mobile']!=$post['stu_fathermobile']) { $nstatus=1; $div="select a.authenticate_id,p.device_id from ced_t_authentication_details a inner join ced_t_students_parent p on a.authenticate_id=p.authenticate_id where p.student_id='".$post['student_id']."' and a.email='".$records['student_father_mobile']."' and parent_app_access=1 and a.school_id=".(int)$session['child']['log_school_id']; $getdiv=mysql_query($div); if(mysql_num_rows($getdiv)) { $divrec=mysql_fetch_array($getdiv); if($divrec['device_id']!='') $this->send_notice('logout',$divrec['device_id'],$msg); } $fauth="update ced_t_authentication_details set email='".$post['stu_fathermobile']."' where email='".$records['student_father_mobile']."' and parent_app_access=1 and school_id=".(int)$session['child']['log_school_id']; mysql_query($fauth); } if($records['student_mother_mobile']!=$post['stu_mothermobile']) { $nstatus1=1; $div="select a.authenticate_id,p.device_id from ced_t_authentication_details a inner join ced_t_students_parent p on a.authenticate_id=p.authenticate_id where p.student_id='".$post['student_id']."' and a.email='".$records['student_mother_mobile']."' and parent_app_access=1 and a.school_id=".(int)$session['child']['log_school_id']; $getdiv=mysql_query($div); if(mysql_num_rows($getdiv)) { $divrec=mysql_fetch_array($getdiv); if($divrec['device_id']!='') $this->send_notice('logout',$divrec['device_id']); } $fauth="update ced_t_authentication_details set email='".$post['stu_mothermobile']."' where email='".$records['student_mother_mobile']."' and parent_app_access=1 and school_id=".(int)$session['child']['log_school_id']; mysql_query($fauth); }*/ $update_date = date('Y-m-d'); $msg=''; $dateInput = explode('/',$post['stu_admissiondate']); $admision_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $dateInput2 = explode('/',$post['stu_birthdate']); $birth_date=$dateInput2[2].'-'.$dateInput2[1].'-'.$dateInput2[0]; $qry="update ced_t_students set student_rollno='".trim($post['stu_rollnum'])."',class_id='".$post['classes']."',section_id='".$post['sections']."',student_firstname='".trim($post['stu_firstname'])."',student_lastname='".trim($post['stu_lastname'])."', student_admission_number='".trim($post['stu_admissionnumber'])."',student_admission_date='".$admision_date."',student_address='".trim($post['stu_address'])."',student_blood_group='".$post['stu_blodgroup']."',student_father_name='".trim($post['stu_fathername'])."', student_father_email='".$post['stu_fatheremail']."',student_father_mobile='".$post['stu_fathermobile']."',student_father_mobile2='".$post['stu_fathermobile2']."',student_mother_name='".trim($post['stu_mothername'])."',student_mother_email='".$post['stu_motheremail']."', student_mother_mobile='".$post['stu_mothermobile']."',student_mother_mobile2='".$post['stu_mothermobile2']."',student_guardian_name='".trim($post['stu_gurdianname'])."',student_guardian_email='".$post['stu_gurdianemail']."',student_guardian_mobile='".$post['stu_gurdianmobile']."', student_guardian_mobile2='".$post['stu_gurdianmobile2']."',academic_year_id='".$session['child']['choosen_academic_id']."',updated_on='".date('Y-m-d')."',updated_by='".$session['child']['auth_id']."',date_of_birth='".$birth_date."',profile_pic='".$im_url."',hostler_status='".$post['hostel']."' where student_id = '".$post['student_id']."'"; $exe=mysql_query($qry); /*if(mysql_affected_rows()) { $divid=$this->parentDeviceIds($post['student_id']); if($divid!=0) { foreach($divid as $did) $this->send_notice('recall',$did,$msg); } }*/ if($exe) { $_SESSION['student_edit']['stu_id'] = $post['student_id']; $_SESSION['child']['section_id'] = $post['sections']; $_SESSION['child']['stu_class_id'] = $post['classes']; $response=ERR203; } else { $response=ERR205; } return $response; } function update_student_status($student_id,$status) { $update_date = date('Y-m-d'); $div="select device_id from ced_t_students_parent where student_id=".(int)$student_id; $getdiv=mysql_query($div); if(mysql_num_rows($getdiv)) { $divrec=mysql_fetch_array($getdiv); if($divrec['device_id']!='') { $getname="select student_firstname,student_lastname from ced_t_students where student_id=".(int)$student_id; $stdexe=mysql_query($getname); $name=mysql_fetch_array($stdexe); $msg['student_id']=$student_id; if($status==1) $msg['message']=$name['student_firstname']." ".$name['student_lastname']." has been deactivated. Please contact School Admin"; else $msg['message']=""; $this->send_notice('lic_status',$divrec['device_id'],$msg); } } if($status == '1') { $status = '0'; $sql="update ced_t_student_licenses set license_status='$status',school_license_id=0,updated_on='".$update_date."',updated_by='".$_SESSION['child']['auth_id']."' where student_id = ".(int)$student_id; $runit=mysql_query($sql); $qry="update ced_t_students set status ='".$status."',updated_on='".$update_date."',updated_by='".$_SESSION['child']['auth_id']."' where student_id = ".(int)$student_id; $exe=mysql_query($qry); } else { $status = '1'; $qry="update ced_t_students set status ='".$status."',updated_on='".$update_date."',updated_by='".$_SESSION['child']['auth_id']."' where student_id = ".(int)$student_id; $exe=mysql_query($qry); } if($exe) $response=ERR203; else $response=ERR205; return $response; } function delete_student($student_id) { $counter=0; $sql="select student_id from ced_t_student_licenses where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_attendance where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_leavedetails where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_noticeboard where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_school_diary where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_students_marks where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_students_routes where student_id=".(int)$student_id; $exe=mysql_query($sql); if( mysql_num_rows($exe)) $counter=1; $sql="select student_id from ced_t_student_fee where student_id=".(int)$student_id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) $counter=1; $sql="SELECT student_id FROM ` ced_t_student_grades` WHERE `student_id`=".(int)$student_id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) $counter=1; if($counter==0) { $qry = "delete from ced_t_students where student_id = '".$student_id."' "; $exe=mysql_query($qry); if($exe) { $qry_lic= "select * from ced_t_student_licenses where student_id = '".$student_id."' "; $result=mysql_query($qry_lic); if( mysql_num_rows($result) > 0) { $qry = "delete from ced_t_student_licenses where student_id = '".$student_id."' "; $exe=mysql_query($qry); } $response=ERR203; } } else { $response=ERR205; } return $response; } function students_data($class_id,$sec_id,$school_id,$academic_id) { $sql="SELECT `class_id`,`section_id`,`student_id`,`student_rollno`,`student_firstname`,`student_lastname`,`student_email_send_status`, `status` ,`student_father_name`, `student_mother_name`, `student_guardian_name` FROM `ced_t_students` WHERE `class_id` = '".$class_id."' and section_id ='".$sec_id."' and academic_year_id ='".$academic_id."' and school_id = '".$school_id."' "; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data[$row['student_id']]=$row; //$data2[]=$data; } return $data; } function get_classes_byschool($schoolid) { $sql="SELECT `class_id` , `class_name` FROM `ced_t_class` where school_id = '".$schoolid."' order by class_order asc"; //echo $sql; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data[$row['class_id']]=$row; //$data[]=$row; } return $data; } function get_school($school_id) { $sql="SELECT `school_id` , `school_name` FROM `ced_t_school` WHERE `school_id` = '".$school_id."'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); return $row; } function students_data_byid($student_id) { $qry = "select class_id,section_id from ced_t_students where student_id = '".$student_id."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function get_sections_data_byclass($class_id) { $sql="SELECT `section_id` , `section_name` FROM `ced_t_sections` WHERE `class_id` = '".$class_id."' order by section_id asc"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data[]=$row; } return $data; } function check_my_status($schoolid) { $sql="select school_status from ced_t_school where school_id=".(int)$schoolid; $exe=mysql_query($sql); $row=mysql_fetch_array($exe); $val=$row['school_status']; $qry="select email from ced_t_authentication_details where school_id=".(int)$schoolid." and school_su=1"; $res=mysql_query($qry); if(!mysql_num_rows($res) || $val=='0') return '0'; else return $val; } function check_student_count_add($school_id,$acadamic_id,$choosen_acc_id) { $qry = "select count(student_id) as cnt from ced_t_students where school_id = '".$school_id."' and academic_year_id = '".$acadamic_id."' or academic_year_id = '".$choosen_acc_id."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function check_student_count_add_data($school_id,$a_id) { $qry = "select count(student_id) as cnt from ced_t_students where school_id = '".$school_id."' and academic_year_id = '".$a_id."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function send_notice($type,$registatoin_ids,$msg) { $msg['type']=$type; $registatoin_ids=array($registatoin_ids); $googleapi='AIzaSyDZjnc0dm76JpZpk5mJSw_oOPgfoDSSbR0'; $url = 'https://android.googleapis.com/gcm/send'; $fields = array('registration_ids' => $registatoin_ids,'data' => $msg); $headers = array('Authorization: key='.$googleapi,'Content-Type: application/json'); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); return $result; } }