JezK
Edit File: school_admin_student13.php
<?php session_start(); include_once("Config.php"); class studentacess { private $conn; function __construct() { require_once dirname(__FILE__) . '/DbConnect.php'; // opening db connection $db = new DbConnect(); $this->conn = $db->connect(); } function create_student($post,$session){ $created_date = date('Y-m-d'); $dateInput = explode('/',$post['stu_admissiondate']); $admision_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[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 ) VALUES ( '".$post['stu_rollnum']."', '".$post['classes']."', '".$post['sections']."', '".$post['stu_firstname']."', '".$post['stu_lastname']."', '".$post['stu_admissionnumber']."', '".$admision_date."', '".$post['stu_address']."', '".$post['stu_blodgroup']."', '".$post['stu_fathername']."', '".$post['stu_fatheremail']."', '".$post['stu_fathermobile']."', '".$post['stu_fathermobile2']."', '".$post['stu_mothername']."', '".$post['stu_motheremail']."', '".$post['stu_mothermobile']."', '".$post['stu_mothermobile2']."', '".$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']."') "; $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']; // exit; /* if($student_id){ $mails = explode(",",$post['student_mails']); foreach($mails as $k=>$val){ $qry="INSERT INTO ced_t_students_parent ( student_id,parent_email,school_id,created_by,created_on) VALUES ('".$student_id."','".$val."','1','admin_user','".$created_date."') "; $exe=mysql_query($qry); } $response=ERR203; }else{ $response=ERR204; }*/ if($exe) { $response=ERR203; }else{ $response=ERR204; } return $response; } function check_student($admission_number,$school_id ){ $qry = "select student_id from ced_t_students where student_admission_number = '".$admission_number."' and school_id ='".$school_id."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_student_edit($admission_number,$student_id,$school_id ){ $qry = "select student_id from ced_t_students where student_admission_number = '".$admission_number."' and school_id ='".$school_id."' and student_id !='".$student_id."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function update_student($post,$session){ $update_date = date('Y-m-d'); //$admision_date = date_format($post['stu_admissiondate'],"Y/m/d"); $dateInput = explode('/',$post['stu_admissiondate']); $admision_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $qry="update ced_t_students set student_rollno='".$post['stu_rollnum']."', class_id='".$post['classes']."', section_id='".$post['sections']."', student_firstname='".$post['stu_firstname']."', student_lastname='".$post['stu_lastname']."', student_admission_number='".$post['stu_admissionnumber']."', student_admission_date='".$admision_date."', student_address='".$post['stu_address']."', student_blood_group='".$post['stu_blodgroup']."', student_father_name='".$post['stu_fathername']."', student_father_email='".$post['stu_fatheremail']."', student_father_mobile='".$post['stu_fathermobile']."', student_father_mobile2='".$post['stu_fathermobile2']."', student_mother_name='".$post['stu_mothername']."', student_mother_email='".$post['stu_motheremail']."', student_mother_mobile='".$post['stu_mothermobile']."', student_mother_mobile2='".$post['stu_mothermobile2']."', student_guardian_name='".$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='".$update_date."', updated_by='".$session['child']['auth_id']."' where student_id = '".$post['student_id']."' "; $exe=mysql_query($qry); 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 delete_student($student_id){ $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 update_student_status($student_id,$status){ $update_date = date('Y-m-d'); if($status == '1'){ $status = '0'; }else { $status = '1'; } $qry="update ced_t_students set status = '".$status."' ,updated_on='".$update_date."', updated_by='admin_user' where student_id = '".$student_id."' "; //echo $qry; //exit; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function insert_student_licences($stuid,$license,$user_id,$licence_id,$acadamic_id){ $created_date = date('Y-m-d'); $qry="INSERT INTO ced_t_student_licenses ( student_id,license_key,license_status,school_license_id,academic_year_id,created_on,created_by) VALUES ('".$stuid."','".$license."','1','".$licence_id."','".$acadamic_id."','".$created_date."','".$user_id."')"; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function students_license_data($schoolid){ $qry = "SELECT st.student_id as stuid,stl.student_id as stulid ,stl.license_key,stl.license_status ,stl.student_license_id FROM `ced_t_students` as st INNER JOIN `ced_t_student_licenses` as stl ON st.student_id = stl.student_id"; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data[$row['stulid']]=$row; //$data2[]=$data; } return $data; } function update_student_licensestatus($ids){ $str= ltrim ($ids, ','); $str= rtrim ($ids, ','); $qry = "update ced_t_student_licenses set license_status='0' where student_id in(".$str.")"; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function check_student_licensestatus($ids){ $str= ltrim ($ids, ','); $str= rtrim ($ids, ','); $qry = "select license_status,student_id from ced_t_student_licenses where student_id in(".$str.") and student_id != 0 "; //echo $qry; $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { $data2[$row['license_status']]=$row; //$data2[$row['license_status']][]=$row; } return $data2; }else { return '0'; } } function update_license_status($post){ $qry = "update ced_t_student_licenses set license_status='".$post['status']."' where student_id ='".$post['stuid']."' "; //echo $qry; //exit; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function send_licences_mail($studid){ $qry = "select student_firstname,student_lastname,student_id,student_father_name,student_mother_name,student_guardian_name,student_father_email,student_mother_email,student_guardian_email from ced_t_students where student_id in(".$studid.")"; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data[$row['student_id']]=$row; //$data2[]=$data; } return $data; } function get_licences_key($studid){ $qry = "Select student_id,license_key,license_status from ced_t_student_licenses where license_status = '1' and student_id in(".$studid.")"; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data[$row['student_id']]=$row; //$data2[]=$data; } return $data; } function send_LicenceKey_student($result_data,$license_data,$session){ $qry_school="select school_name,school_email,school_phone from ced_t_school where school_id=".(int)$session['child']['log_school_id']; $exe_school=mysql_query($qry_school); $res_school=mysql_fetch_array($exe_school); foreach($result_data as $key=>$val){ if($license_data[$key]['license_key']){ //$subject = "Student License Key"; $subject = "skoolonline Parent App Access for ".$session['child']['school_name']; if($val['student_father_email']){ $to_father = $val['student_father_email']; /* if($to_father != ''){ $mails[] = $to_father; } if($to_mother != ''){ $mails[] = $to_mother; } if($to_gaurdiun != ''){ $mails[] = $to_gaurdiun; } print_r($mails); exit;*/ $content_father = "<body> <p>Dear ".$val['student_father_name'].",<br><br> <p>Welcome!!</p> <p> You have been successfully registered for skoolonline mobile services provided by ".$session['child']['school_name']." for your Child ".$val['student_firstname']." ".$val['student_lastname'].". </p> <p>You can download the skoolonline Parent App on your mobile phone from the Google App Store by simply searching for 'skoolonline'. Your one time license key for accessing the skoolonline Parent App is as follows: </p> <p>License Key: <b style='font-family: myfont;'>".$license_data[$key]['license_key']."</b></p> <p>After entering the license key in the mobile app, you would be asked to create a Username and Password.</p> <p>Please DO NOT share your username and password with any other person to ensure complete security of data related to your child.</p> <p>If you have any questions related to your account / services, you can email us at ".$res_school['school_email']." or call us on ".$res_school['school_phone'].".</p> <p> In case of any technical help related to the mobile app, you can reach out to help@skoolonline.in.</p> <p>Thank You,</p> <p>Regards,</p> <p>".$session['child']['school_name']."</p> </body>"; $message_father = " <html> <head> <title>skoolonline</title> </head> ".$content_father." </html>"; //echo $message_father; $mail_send = $this->mail_send($to_father,$subject,$message_father); if($mail_send == '1'){ $qry = "update ced_t_students set student_email_send_status='1' where student_id ='".$key."' "; $exe=mysql_query($qry); } } if($val['student_mother_email'] && $val['student_father_email'] != $val['student_mother_email'] ){ $to_mother = $val['student_mother_email']; $content_mother = "<body> <p>Dear ".$val['student_mother_name'].",</p><br> <p>Welcome!!</p> <p> You have been successfully registered for skoolonline mobile services provided by ".$session['child']['school_name']." for your Child ".$val['student_firstname']." ".$val['student_lastname'].". </p> <p>You can download the skoolonline Parent App on your mobile phone from the Google App Store by simply searching for 'skoolonline'. Your one time license key for accessing the skoolonline Parent App is as follows: </p> <p>License Key: <b style='font-family: myfont;'>".$license_data[$key]['license_key']."</b></p> <p>After entering the license key in the mobile app, you would be asked to create a Username and Password.</p> <p>Please DO NOT share your username and password with any other person to ensure complete security of data related to your child.</p> <p>If you have any questions related to your account / services, you can email us at ".$res_school['school_email']." or call us on ".$res_school['school_phone'].".</p> <p> In case of any technical help related to the mobile app, you can reach out to help@skoolonline.in.</p> <p>Thank You,</p> <p>Regards,</p> <p>".$session['child']['school_name']."</p> </body>"; $message_mother = " <html> <head> <title>skoolonline</title> </head> ".$content_mother." </html>"; $mail_send = $this->mail_send($to_mother,$subject,$message_mother); if($mail_send == '1'){ $qry = "update ced_t_students set student_email_send_status='1' where student_id ='".$key."' "; $exe=mysql_query($qry); } } } } return $mail_send; } function mail_send($to,$sub,$mess){ $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers //$headers .= 'From: <prasanthi@krify.net>' . "\r\n"; $headers .= 'From:skoolonline<dontreply@skoolonline.in>' . "\r\n"; $sent=mail($to,$sub,$mess,$headers); if($sent) return '1'; else return '0'; } function dairy_data($class_id,$section_id,$dairy_date,$school_id,$dairy_type,$academic_id,$studentids){ /*echo $studentids; exit; $studentids =ltrim($studentids,','); $studentids =rtrim($studentids,','); $studentids_data = explode(',',$studentids); $studencon = ''; $i=1; $str =''; $string = '';*/ if($studentids == "all"){ $str_new = "all"; $status = "all"; }else{ $str = str_replace("all","",$studentids); $str= ltrim ($studentids, ','); $str =rtrim($studentids,','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); $status = "singles"; } /* if($studentids != ''){ foreach($studentids_data as $key=>$val){ if($i == count($studentids_data)){ $str = " OR student_id = 'all' "; }else { $str = " OR "; } if($val != '' ){ $studencon .= "student_id like '%".$val."%' ".$str; } $i++; } }else{ $studencon .= "student_id = '' "; } $string = "and (".$studencon.")";*/ $dateInput = explode('/',$dairy_date); $dairy_newdate=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $qry = "select sd.*,ss.subject_name from ced_t_school_diary as sd INNER JOIN ced_t_subjects as ss ON sd.subject_id=ss.subject_id and sd.class_id = '".$class_id."' and sd.section_id='".$section_id."' and sd.school_id='".$school_id."' and sd.diary_date='".$dairy_newdate."' and sd.academic_year_id='".$academic_id."' and sd.diary_type ='".$dairy_type."' and student_id = '".$str_new."' and student_id != '' order by sd.School_diary_id desc"; //echo $qry; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data[$row['School_diary_id']]=$row; //$data2[]=$data; } return $data; } function get_subjects_dairy($class_id,$school_id,$academic_id){ $qry = "select ss.subject_name,ss.subject_id from ced_t_subjects as ss INNER JOIN ced_t_class as cc ON cc.class_category_id = ss.class_category_id and cc.class_id='".$class_id."' and cc.school_id='".$school_id."' and ss.academic_year_id = '".$academic_id."' "; //echo $qry; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data2[]=$row; } return $data2; } function get_students_data($class_id,$school_id,$section_id){ $qry = "select student_id,class_id,section_id,student_firstname,student_lastname from ced_t_students where class_id='".$class_id."' and school_id='".$school_id."' and section_id='".$section_id."' "; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data2[]=$row; } return $data2; } function get_students_data_dairy($class_id,$school_id,$section_id,$acadamicid){ $qry = "select student_id,class_id,section_id,student_firstname,student_lastname from ced_t_students where class_id='".$class_id."' and school_id='".$school_id."' and section_id='".$section_id."' and academic_year_id = '".$acadamicid."' and status = '1' "; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data2[]=$row; } return $data2; } function check_generalcomment($post){ $dateInput = explode('/',$post['dairy_date']); $dairy_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $category = '2'; $qry = "select count(School_diary_id) as cnt,description,class_id,section_id,subject_id,school_id,academic_year_id from ced_t_school_diary where class_id='".$post['classes']."' and section_id='".$post['sections']."' and subject_id='".$post['subjects']."' and diary_date='".$dairy_date."' and diary_type='".$category."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function update_generalcomment($data,$post){ $update_date = date('Y-m-d'); $qry = "update ced_t_school_diary set description ='".$post['dairy_desription']."' where class_id = '".$data['class_id']."' and section_id ='".$data['section_id']."' and subject_id = '".$data['subject_id']."' and school_id = '".$data['school_id']."' and academic_year_id = '".$data['academic_year_id'] ."' and diary_type = 2"; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function update_generalcomment_edit_dump($data){ print_r($data); exit; $str= ltrim ($data['student_ids_all'], ','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); $update_date = date('Y-m-d'); $qry = "update ced_t_school_diary set description ='".$data['dairy_desription']."', student_id ='".$str_new."' where School_diary_id = '".$data['sudent_dairy_id']."' "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function update_generalcomment_edit($data,$session){ $dateInput = explode('/',$data['dairy_date']); $dairy_newdate=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; if($data['student_ids_data'] == "all"){ $str_new = "all"; $status = "all"; }else{ $str= ltrim ($data['student_ids_data'], ','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); $status = "singles"; } $today_date =date('d/m/Y'); if($today_date == $data['dairy_date']){ $date_msg = "Today"; }else { $date_msg = $data['dairy_date']; } $update_date = date('Y-m-d'); $qry = "update ced_t_school_diary set description ='".mysql_escape_string($data['dairy_desription'])."', updated_by='".$session['child']['auth_id']."', updated_on='".$update_date."' where School_diary_id = '".$data['sudent_dairy_id']."' "; $exe=mysql_query($qry); if($exe) { $_SESSION['child']['dairy_section_id'] = $data['sections']; $_SESSION['child']['dairy_class_id'] = $data['classes']; $_SESSION['child']['dairy_date'] = $data['dairy_date']; $_SESSION['child']['studentids'] = $str_new; $_SESSION['child']['dairy_type_general'] = $status; $_SESSION['child']['general_names'] = $data['student_allnamesedit_data']; $response=ERR203; if($data['student_ids_data'] == "all"){ // $qry="select student_id,student_firstname,student_lastname from ced_t_students where school_id=".(int)$data['school_id']." and academic_year_id=".(int)$data['acadamic_id']." and section_id=".(int)$data['sections']." and class_id=".(int)$data['classes']; $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$data['school_id']." and s.academic_year_id=".(int)$data['acadamic_id']." and s.section_id=".(int)$data['sections']." and s.class_id=".(int)$data['classes']; }else{ //$qry="select student_id,student_firstname,student_lastname from ced_t_students where school_id=".(int)$data['school_id']." and academic_year_id=".(int)$data['acadamic_id']." and section_id=".(int)$data['sections']." and class_id=".(int)$data['classes']." and student_id in(".$str.")" ; $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$data['school_id']." and s.academic_year_id=".(int)$data['acadamic_id']." and s.section_id=".(int)$data['sections']." and s.class_id=".(int)$data['classes']." and s.student_id in(".$str.")" ; } $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { //$qry2="select student_id from ced_t_student_licenses where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$data['acadamic_id']." and license_status=1"; //$exe2=mysql_query($qry2); $cklic=$this->check_lic_status($row['student_id']); $notification_status=$this->check_notification_status($row['authenticate_id']); $subject_name = $this->getsubject_name($data['subjects'],$data['school_id'],$data['acadamic_id']); $student_name = $this->student_name($row['student_id']); //if($devid!='0') //{ $message = $student_name." has been assigned Individual Work for ".$subject_name." for ".$date_msg; if($row['device_id'] !='' && $cklic && $notification_status == 1) { //$devid=$this->parentDeviceId($row['student_id']); $notify=$this->send_notification($row['device_id'],$message,$row['student_id'],'gencmnt',date('Y-m-d'),$dairy_newdate,''); //} } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",class_id=".(int)$row['class_id'].",section_id=".(int)$row['section_id'].",school_id=".(int)$row['school_id'].",notify_type='gencmnt',general_column1=".$dairy_newdate.",read_status=1,created_on='".date('Y-m-d')."'"; mysql_query($noteins); } } } } else { $response=ERR205; } return $response; } function update_generalcomment_new($data,$id){ $dateInput = explode('/',$data['dairy_date']); $dairy_newdate=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; if($data['student_ids'] == "all" ){ $str_new = "all"; $status = "all"; }else{ $str= ltrim ($data['student_ids_data'], ','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); $status = $data['student_status']; } if($post['student_ids_data'] == "all"){ $str = $data['student_ids_all']; }else{ $str = $data['student_ids_data']; } $str =ltrim($str,','); $str =rtrim($str,','); $today_date =date('d/m/Y'); if($today_date == $data['dairy_date']){ $date_msg = "Today"; }else { $date_msg = $data['dairy_date']; } $update_date = date('Y-m-d'); $qry = "update ced_t_school_diary set description ='".mysql_escape_string($data['dairy_desription'])."', student_id ='".$str_new."' where School_diary_id = '".$id."' "; $exe=mysql_query($qry); if($exe) { $_SESSION['child']['dairy_section_id'] = $data['sections']; $_SESSION['child']['dairy_class_id'] = $data['classes']; $_SESSION['child']['dairy_date'] = $data['dairy_date']; $_SESSION['child']['studentids'] = $str_new; $_SESSION['child']['dairy_type_general'] = $status; $_SESSION['child']['general_names'] = $data['student_allnames_data']; $response=ERR203; // $qry="select student_id,student_firstname,student_lastname from ced_t_students where school_id=".(int)$data['school_id']." and academic_year_id=".(int)$data['acadamic_id']." and section_id=".(int)$data['sections']." and class_id=".(int)$data['classes']." and student_id in(".$str.")" ; $qry = "select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$data['school_id']." and s.class_id=".(int)$data['classes']." and s.section_id=".(int)$data['sections']." and s.academic_year_id=".(int)$data['acadamic_id']." and s.student_id in(".$str.") and s.status=1 and sp.account_status=1"; $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { //$qry2="select student_id from ced_t_student_licenses where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$data['acadamic_id']." and license_status=1"; //$exe2=mysql_query($qry2); $cklic=$this->check_lic_status($row['student_id']); $notification_status=$this->check_notification_status($row['authenticate_id']); $subject_name = $this->getsubject_name($data['subjects'],$data['school_id'],$data['acadamic_id']); $student_name = $this->student_name($row['student_id']); $message = $student_name." has been assigned Individual Work for ".$subject_name." for ".$date_msg; if($row['device_id'] !='' && $cklic && $notification_status == 1) { //$devid=$this->parentDeviceId($row['student_id']); $notify=$this->send_notification($row['device_id'],$message,$row['student_id'],'gencmnt',date('Y-m-d'),$dairy_newdate,''); } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",class_id=".(int)$row['class_id'].",section_id=".(int)$row['section_id'].",school_id=".(int)$row['school_id'].",notify_type='gencmnt',general_column1=".$dairy_newdate.",read_status=1,created_on='".date('Y-m-d')."'"; mysql_query($noteins); } } } } else { $response=ERR205; } return $response; } function check_parent_data($post){ if($post['student_ids_data'] == "all"){ $str = $post['student_ids_all']; }else{ $str = $post['student_ids_data']; } $str =ltrim($str,','); $str =rtrim($str,','); $select_parent_qry = "select * from ced_t_students_parent where student_id in (".$str.") "; //echo $select_parent_qry; $exe_parent=mysql_query($select_parent_qry); while($row_parent =mysql_fetch_array($exe_parent)) { $data2[]=$row_parent; } return $data2; } function check_parent_data_licence($ids){ $ids =ltrim($ids,','); $ids =rtrim($ids,','); $select_parent_qry = "select * from ced_t_students_parent where student_id in (".$ids.") "; // echo $select_parent_qry; // echo "<br>"; $exe_parent=mysql_query($select_parent_qry); while($row_parent =mysql_fetch_array($exe_parent)) { $data2[]=$row_parent; } return $data2; } function insert_generalcomment($post){ $dateInput = explode('/',$post['dairy_date']); $dairy_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; if( $post['student_ids'] == "all" ){ $str_new = "all"; $status = "all"; }else{ $str=''; $str = $post['student_ids_data']; /*if($post['students_ids']){ foreach($post['students_ids'] as $key=>$val){ $str .= ",".$val; } $str =ltrim($str,','); $str =rtrim($str,','); }*/ $str =ltrim($str,','); $str =rtrim($str,','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); $status = $post['student_status']; } if($post['student_ids_data'] == "all"){ $str_students = $post['student_ids_all']; }else{ $str_students = $post['student_ids_data']; } $str_students = ltrim($str_students,','); $str_students = rtrim($str_students,','); $today_date = date('d/m/Y'); if($today_date == $post['dairy_date']){ $date_msg = "Today"; } else { $date_msg = $post['dairy_date']; } $category = '2'; $created_date = date('Y-m-d'); /*$select_qry = "select student_id from ced_t_students where class_id='".$post['classes']."' and section_id='".$post['sections']."' and school_id='".$post['school_id']."' ".$con ; //$select_qry = "select student_id from ced_t_students where class_id='1' and section_id='1' and school_id='1' "; $exe=mysql_query($select_qry); while($row=mysql_fetch_array($exe)) { $data2[$row['student_id']]=$row; }*/ $values= ''; //foreach($data2 as $k=>$val){ $values= "('".$post['classes']."','".$post['sections']."','".$str_new."','".$dairy_date."','".$post['subjects']."','".$category."','".$post['auth_id']."','".$post['school_id']."','".mysql_escape_string($post['dairy_desription'])."','".$created_date."','admin_user','".$post['acadamic_id']."')"; //} $str= ltrim ($str, ','); $qry = "insert into ced_t_school_diary (class_id,section_id,student_id,diary_date,subject_id,diary_type,assigned_by,school_id,description,created_on,created_by,academic_year_id) values ".$values." "; $exe=mysql_query($qry); $lastid = mysql_insert_id(); if($exe) { $_SESSION['child']['dairy_section_id'] = $post['sections']; $_SESSION['child']['dairy_class_id'] = $post['classes']; $_SESSION['child']['dairy_date'] = $post['dairy_date']; $_SESSION['child']['studentids'] = $str_new; $_SESSION['child']['dairy_type_general'] = $status; $_SESSION['child']['general_names'] = $post['student_allnames_data']; $response = $lastid; // $qry="select student_id,student_firstname,student_lastname from ced_t_students where school_id=".(int)$post['school_id']." and academic_year_id=".(int)$post['acadamic_id']." and section_id=".(int)$post['sections']." and class_id=".(int)$post['classes']." and student_id in(".$str_students.")" ; if($str_new == "all"){ $qry = "select sp.device_id,sp.authenticate_id,sp.student_id,s.school_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$post['school_id']." and s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']." and s.academic_year_id=".(int)$post['acadamic_id']." and s.status=1 and sp.account_status=1"; }else{ $qry = "select sp.device_id,sp.authenticate_id,sp.student_id,s.school_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$post['school_id']." and s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']." and s.academic_year_id=".(int)$post['acadamic_id']." and s.student_id in(".$str.") and s.status=1 and sp.account_status=1"; } $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { // $qry2="select student_id from ced_t_student_licenses where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$post['acadamic_id']." and license_status=1"; // $exe2=mysql_query($qry2); $cklic=$this->check_lic_status($row['student_id']); $notification_status=$this->check_notification_status($row['authenticate_id']); $subject_name = $this->getsubject_name($post['subjects'],$post['school_id'],$post['acadamic_id']); $student_name = $this->student_name($row['student_id']); $message = $student_name." has been assigned Individual Work for ".$subject_name." for ".$date_msg; if($row['device_id']!='' && $cklic && $notification_status == 1) { //$devid=$this->parentDeviceId($row['student_id']); $notify=$this->send_notification($row['device_id'],$message,$row['student_id'],'gencmnt',date('Y-m-d'),$dairy_date,''); } if($cklic !=0) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",class_id=".(int)$row['class_id'].",section_id=".(int)$row['section_id'].",school_id=".(int)$row['school_id'].",notify_type='gencmnt',general_column1=".$dairy_date.",read_status=1,created_on='".date('Y-m-d')."'"; //echo $noteins; mysql_query($noteins); } } } } else { $response=ERR205; } return $response; //exit; //$qry = "insert into ced_t_school_diary (class_id,section_id) values () "; } function details_nonteach_staff($schoolid,$acadamicid) { $select_qry = "select staff_name,staff_id,staff_type,staff_driving_license,staff_mobile from ced_t_school_staff where school_id='".$schoolid."' and academic_year_id='".$acadamicid."' and staff_type <>1 "; $exe=mysql_query($select_qry); while($row=mysql_fetch_array($exe)) { $data2[$row['staff_id']]=$row; } return $data2; } function create_nonteach_staff($post,$session,$file) { $created_date = date('Y-m-d'); $qry="INSERT INTO ced_t_school_staff ( staff_name, staff_otherperson, staff_mobile, staff_address, staff_pic, status, school_id, staff_driving_license, staff_experience, staff_type, academic_year_id, created_by, created_on) VALUES ('".$post['staff_name']."', '".$post['staff_person']."', '".$post['staff_number']."', '".$post['staff_address']."', '".$file['nonteach_pic']['name']."', '1', '".$session['child']['log_school_id']."', '".$post['staff_licence']."', '".$post['staff_exp']."', '".$post['staff_type']."', '".$session['child']['choosen_academic_id']."', '".$session['child']['auth_id']."', '".$created_date."' ) "; $result=mysql_query($qry); if($result){ $response=ERR203; }else{ $response=ERR204; } return $response; } function staff_data_byid($staff_id){ $qry = "select * from ced_t_school_staff where staff_id = '".$staff_id."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function staff_data_update($post,$session) { $update_date = date('Y-m-d'); $qry = "update ced_t_school_staff set staff_name='".$post['staff_name']."', staff_otherperson='".$post['staff_person']."', staff_mobile='".$post['staff_number']."', staff_address='".$post['staff_address']."', staff_driving_license='".$post['staff_licence']."', staff_experience='".$post['staff_exp']."', staff_type='".$post['staff_type']."', updated_by='".$session['child']['auth_id']."', updated_on='".$update_date."' where staff_id ='".$post['staff_id']."' "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function delete_staff($staff_id){ $qry = "delete from ced_t_school_staff where staff_id = '".$staff_id."' "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function route_data($scool_id,$acadamic_id){ $select_qry = "select * from ced_t_routes where school_id='".$scool_id."' and academic_year_id ='".$acadamic_id."' "; //echo $select_qry; $exe=mysql_query($select_qry); while($row=mysql_fetch_array($exe)) { $data2[$row['route_id']]=$row; } return $data2; } function stop_count($route_id){ $qry = "select count(*) as cnt,route_id from ced_t_route_stops where route_id = '".$route_id."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function insert_route_data($post,$session){ foreach($post['stopname'] as $k=>$val){ $stopnames['names'][] = $val; } foreach($post['soursedate'] as $sk=>$sval){ $stopnames['times'][] = $sval; } $create_date = date('Y-m-d'); $stops = explode(",",$post['stop_no']); $qry="INSERT INTO ced_t_routes ( source_name, route_number, source_time, destination_name, destination_time, vehicle_type, vehicle_number, school_id, created_by, created_on, academic_year_id) VALUES ('".$post['source_name']."', '".$post['route_number']."', '".$post['source_time']."', '".$post['destination_name']."', '".$post['destination_time']."', '".$post['route_vehical_type']."', '".$post['route_vehical_no']."', '".$session['child']['log_school_id']."', '".$session['child']['auth_id']."', '".$create_date."', '".$session['child']['choosen_academic_id']."' ) "; $exe=mysql_query($qry); $route_id=mysql_insert_id(); if($route_id){ $str = ''; $str .= ",('".$post['source_name']."','".$post['source_time']."','".$route_id."','".$create_date."','".$post['acadamic_id']."')"; $str .= ",('".$post['destination_name']."','".$post['destination_time']."','".$route_id."','".$create_date."','".$post['acadamic_id']."')"; for($k=0; $k < count($stopnames['names']); $k++){ $str .= ",('".$stopnames['names'][$k]."','".$stopnames['times'][$k]."','".$route_id."','".$create_date."','".$post['acadamic_id']."')"; } $str= ltrim ($str, ','); $qry = "insert into ced_t_route_stops (route_stop_name,route_stop_time,route_id,Created_on,academic_year_id) values ".$str." "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR204; } return $response; } } function route_data_byid($routeid){ $qry = "select * from ced_t_routes where route_id = '".$routeid."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row; } function stop_data_byrouteid($route_id){ /*$qry = "select count(route_id) as count from ced_t_route_stops where route_id = '".$route_id."' "; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); return $row;*/ $qry = "select * from ced_t_route_stops where route_id = '".$route_id."' order by route_stop_id asc"; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data2[$row['route_stop_id']]=$row; } return $data2; } 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 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_fathermail($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."'"; $result=mysql_query($qry); if(mysql_num_rows($result)) { $row=mysql_fetch_array($result); return $row; } else return 0; } function check_mothermail($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."'"; $result=mysql_query($qry); if(mysql_num_rows($result)) { $row=mysql_fetch_array($result); return $row; } else return 0; } 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 data_comment($commentid){ $qry = "select * from ced_t_school_diary where School_diary_id = '".$commentid."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function delete_comment($id){ $qry = "delete from ced_t_school_diary where School_diary_id = '".$id."' "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR205; } return $response; } function get_description_dairy($data){ $dateInput = explode('/',$data['dairy_date']); $dairy_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $str= ltrim ($data['studentids'], ','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); //$str= rtrim ($data['studentids'], ','); $qry = "select School_diary_id,description from ced_t_school_diary where class_id = '".$data['class_id']."' and section_id = '".$data['sec_id']."' and diary_date ='".$dairy_date."' and subject_id ='".$data['subject']."' and student_id ='".$str_new."' and diary_type = 2"; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_generalcomment_edit($data){ if($data['student_ids'] == "all"){ $str_new = "all"; }else{ $str= ltrim ($data['student_ids_data'], ','); $str= rtrim ($data['student_ids_data'], ','); $str_data = explode(',',$str); arsort($str_data); $str_new = implode(",",$str_data); } $dateInput = explode('/',$data['dairy_date']); $dairy_date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $qry = "select count(School_diary_id) as cnt , School_diary_id,description from ced_t_school_diary where class_id = '".$data['classes']."' and section_id = '".$data['sections']."' and diary_date ='".$dairy_date."' and subject_id ='".$data['subjects']."' and student_id ='".$str_new."' and diary_type = 2 " ; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_licencekey($key){ $qry = "select student_id from ced_t_student_licenses where license_key = '".$key."' "; $result=mysql_query($qry); if(mysql_num_rows($result)) { $row=mysql_fetch_array($result); return $row; } else return 0; } function student_details_completedata($clas,$sect,$school_id,$acadamic_id){ $qry = "select student_id from ced_t_students where class_id = '".$clas."' and section_id ='".$sect."' and school_id ='".$school_id."' and academic_year_id = '".$acadamic_id."' "; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['student_id']]=$row; } return $data2; } function update_routestop_data($post,$editids,$session){ if($post['delete_route_ids'] != ''){ $stopidsids =ltrim($post['delete_route_ids'],','); $delete=$this->delete_stops($stopidsids); } $update_date = date('Y-m-d'); $stops = explode(",",$editids); $stops_sdids = explode(",",$post['stopids']); foreach($post['stopname'] as $k=>$val){ $stopnames['names'][] = $val; } foreach($post['soursedate'] as $sk=>$sval){ $stopnames['times'][] = $sval; } $i=1; $qry_route = "update `ced_t_routes` set route_number='".$post['route_number']."', source_name='".$post['source_name']."', source_time='".$post['source_time']."', destination_name='".$post['destination_name']."', destination_time='".$post['destination_time']."', vehicle_type='".$post['route_vehical_type']."', vehicle_number='".$post['route_vehical_no']."', updated_by='".$session['child']['auth_id']."', updated_on='".$update_date."' where route_id ='".$post['route_id']."' "; $exe_route=mysql_query($qry_route); $sqry = "update ced_t_route_stops set route_stop_name='".$post['source_name']."', route_stop_time='".$post['source_time']."', route_id='".$post['route_id']."', updated_by='".$session['child']['auth_id']."', updated_on='".$update_date."' where route_stop_id ='".$stops_sdids[0]."' "; $exe=mysql_query($sqry); $dqry = "update ced_t_route_stops set route_stop_name='".$post['destination_name']."', route_stop_time='".$post['destination_time']."', route_id='".$post['route_id']."', updated_by='".$session['child']['auth_id']."', updated_on='".$update_date."' where route_stop_id ='".$stops_sdids[1]."' "; $exe=mysql_query($dqry); for($i=0; $i <= count($stops); $i++){ if($stops[$i]){ $qry = "update ced_t_route_stops set route_stop_name='".$stopnames['names'][$i]."', route_stop_time='".$stopnames['times'][$i]."', route_id='".$post['route_id']."', updated_by='".$session['child']['auth_id']."', updated_on='".$update_date."' where route_stop_id ='".$stops[$i]."' "; // echo $qry; // echo "<br>"; } $exe=mysql_query($qry); } // exit; if($exe_route) { $response=ERR203; } else { $response=ERR204; } return $response; } function insert_routestop_data($post,$ids,$session){ $create_date = date('Y-m-d'); $ids =ltrim($post['stop_no'],','); $ids =rtrim($post['stop_no'],','); $stops = explode(",",$ids); foreach($post['stopname'] as $k=>$val){ $stopnames['names'][] = $val; } foreach($post['soursedate'] as $sk=>$sval){ $stopnames['times'][] = $sval; } if($post['delete_route_ids'] != ''){ $stopidsids =ltrim($post['delete_route_ids'],','); $delete=$this->delete_stops($stopidsids); }else { unset($stops[0]); } $str =''; if(count($stops) == 1 || count($stops) == 0 ){ $str = "('".$stopnames['names'][$stops[0]]."','".$stopnames['times'][$stops[0]]."','".$post['route_id']."','".$create_date."','".$post['acadamic_id']."')"; }else { for($i=0; $i <= count($stops); $i++){ if($stops[$i] && $stopnames['names'][$stops[$i]] != ''){ $str .= ",('".$stopnames['names'][$stops[$i]]."','".$stopnames['times'][$stops[$i]]."','".$post['route_id']."','".$create_date."','".$post['acadamic_id']."')"; } } $str= ltrim ($str, ','); } $qry = "insert into ced_t_route_stops (route_stop_name,route_stop_time,route_id,Created_on,academic_year_id) values ".$str." "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR204; } return $response; } function route_data_staff($route_id,$acadamic_id){ $qry = "select * from ced_t_staff_routes where route_id = '".$route_id."' and academic_year_id = '".$acadamic_id."' "; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['staff_route_id']]=$row; } return $data2; } function route_data_student($route_id,$acadamic_id){ $qry = "select * from ced_t_students_routes where route_id = '".$route_id."' and academic_year_id = '".$acadamic_id."' "; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['staff_route_id']]=$row; } return $data2; } function route_data_staff_edit($route_id,$acadamic_id){ $qry = "select * from ced_t_staff_routes where route_id = '".$route_id."' and academic_year_id = '".$acadamic_id."' "; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['staff_route_id']]=$row; } return $data2; } function route_data_student_edit($route_id,$acadamic_id){ $qry = "select * from ced_t_students_routes where route_stop_id = '".$route_id."' and academic_year_id = '".$acadamic_id."' "; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['staff_route_id']]=$row; } return $data2; } function check_route_data($post,$session){ $qry = "select * from ced_t_routes where route_number = '".$post['route_number']."' and academic_year_id = '".$session['child']['choosen_academic_id']."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function check_route_data_edit($post,$session){ $qry = "select * from ced_t_routes where route_number = '".$post['route_number']."' and academic_year_id = '".$session['child']['choosen_academic_id']."' and route_id != '".$post['route_id']."' "; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function delete_route($routeid){ $qry = "delete from ced_t_route_stops where route_id = '".$routeid."' "; $exe=mysql_query($qry); if($exe) { $qry = "delete from ced_t_routes where route_id = '".$routeid."' "; $exe=mysql_query($qry); $response=ERR203; } else { $response=ERR204; } return $response; } function delete_route_stop($routeid){ $qry = "delete from ced_t_route_stops where route_stop_id = '".$routeid."' "; $exe=mysql_query($qry); if($exe) { $response=ERR203; } else { $response=ERR204; } return $response; } function check_generalnotice_data($post){ $qry = "select * from `ced_t_noticeboard` where class_id = '".$post['classes']."' and section_id ='".$post['sections']."' and notification_type ='".$post['category']."' and academicyear_id = '".$post['academic_id']."' and school_id = '".$post['school_id']."' "; //echo $qry; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function insert_generalnotice($post,$session,$file){ $target_dir = "uploads/noticeboard/"; $au_type =''; if($post['classes'] == "all" && $post['sections'] == "all"){ $au_type = "1"; }else if($post['classes'] != "all" && $post['sections'] == "all"){ $au_type = "2"; }else if($post['classes'] != "all" && $post['sections'] != "all"){ $au_type = "3"; } if($post['category'] == "1"){ $category = "General"; }else if($post['category'] == "2"){ $category = "Vacation"; }else if($post['category'] == "3"){ $category = "Activities"; }else if($post['category'] == "4"){ $category = "PTM"; } $created_date = date('Y-m-d H:i:s'); $qry="INSERT INTO ced_t_noticeboard ( class_id, section_id, academicyear_id, notification_type, school_id, created_by, created_on, notification_description, audience_type) VALUES ('".$post['classes']."', '".$post['sections']."', '".$session['child']['choosen_academic_id']."', '".$post['category']."', '".$session['child']['log_school_id']."', '".$session['child']['auth_id']."', '".$created_date."', '".mysql_escape_string($post['notice_description'])."', '".$au_type."' ) "; $result=mysql_query($qry); $ntc=mysql_insert_id(); $i=0; if($ntc){ foreach($file['photos']['name'] as $img) { $target_file = $target_dir .date('his'). basename($img); if (move_uploaded_file($file["photos"]["tmp_name"][$i], $target_file)) { ; $savef=basename($target_file); $sql="insert into ced_t_noticeboard_images set notice_id='$ntc',image='".$savef."'"; mysql_query($sql); } $i++; } $response=ERR203; $_SESSION['child']['notice_cate_id'] = $post['category']; $error=1; if($post['classes'] == "all" && $post['sections'] == "all"){ $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']; }else if($post['classes'] == "all" && $post['sections'] != "all"){ $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']." and s.section_id=".(int)$post['sections'] ; }else if($post['classes'] != "all" && $post['sections'] == "all"){ $qry="select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']." and s.class_id=".(int)$post['classes'] ; }else { $qry="select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']; } $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { //$qry2="select student_id from ced_t_student_licenses where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$session['child']['choosen_academic_id']." and license_status=1"; $cklic=$this->check_lic_status($row['student_id']); $notification_status=$this->check_notification_status($row['authenticate_id']); $message="Notice Board updated for ".$row['student_firstname']." ".$row['student_lastname']." for ".$category." messages"; // $exe2=mysql_query($qry2); //$devid=$this->parentDeviceId($row['student_id']); if($row['device_id']!='' && $cklic && $notification_status == 1) { //echo $devid; //echo "<br>"; $notify=$this->send_notification($row['device_id'],$message,$row['student_id'],'notbrd',date('Y-m-d'),$created_date,$post['category']); //print_r($notify); } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",class_id=".(int)$row['class_id'].",section_id=".(int)$row['section_id'].",school_id=".(int)$row['school_id'].",notify_type='notbrd',general_column1='".$created_date."',general_column2=".$post['category'].",read_status=1,created_on='".date('Y-m-d')."'"; mysql_query($noteins); } } } }else{ $response=ERR204; } return $response; } function generalnotice_data($sessions,$type){ $qry = "select * from ced_t_noticeboard where school_id = '".$sessions['child']['log_school_id']."' and academicyear_id = '".$sessions['child']['choosen_academic_id']."' and notification_type = '".$type."' order by notification_id desc"; //echo $qry; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['notification_id']]=$row; } return $data2; } function generalnotice_images_data($id){ $qry = "select * from `ced_t_noticeboard_images` where notice_id = '".$id."' order by noticeboard_img_id asc"; //echo $qry; $result=mysql_query($qry); while($row=mysql_fetch_array($result)) { $data2[$row['noticeboard_img_id']]=$row; } return $data2; } function notice_data_byid($id){ $qry = "select * from `ced_t_noticeboard` where notification_id = '".$id."' "; //echo $qry; $result=mysql_query($qry); $row=mysql_fetch_array($result); return $row; } function update_generalnotice($post,$session,$file){ $imageids =ltrim($post['edit_image_ids'],','); $target_dir = "uploads/noticeboard/"; $created_date = date('Y-m-d H:i:s'); if($post['category'] == "1"){ $category = "General"; }else if($post['category'] == "2"){ $category = "Vacation"; }else if($post['category'] == "3"){ $category = "Activities"; }else if($post['category'] == "4"){ $category = "PTM"; }else if($post['category'] == "5"){ $category = "For You"; } $qry="update ced_t_noticeboard set updated_by='".$session['child']['auth_id']."',notification_description='".mysql_escape_string($post['notice_description'])."' where notification_id = '".mysql_escape_string($post['notice_id'])."' "; $exe=mysql_query($qry); $i=0; if($exe) { if($post['edit_image_ids'] != ''){ $delete=$this->deletethisimage($imageids); } foreach($file['photos']['name'] as $img) { $target_file = $target_dir .date('his'). basename($img); if (move_uploaded_file($file["photos"]["tmp_name"][$i], $target_file)) { $savef=basename($target_file); $sql="insert into ced_t_noticeboard_images set notice_id='".$post['notice_id']."',image='".$savef."'"; mysql_query($sql); } $i++; } $response=ERR203; $_SESSION['child']['notice_cate_id'] = $post['category']; $error=1; if($post['classes'] == "all" && $post['sections'] == "all"){ $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']; }else if($post['classes'] == "all" && $post['sections'] != "all"){ $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']." and s.section_id=".(int)$post['sections'] ; }else if($post['classes'] != "all" && $post['sections'] == "all"){ $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']." and s.class_id=".(int)$post['classes'] ; }else if($post['student'] == '' || $post['student'] == 'all'){ $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']; }else { $qry="select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']." and s.student_id in(".$post['student'].") "; } $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { //$qry2="select student_id from ced_t_student_licenses where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$session['child']['choosen_academic_id']." and license_status=1"; //$exe2=mysql_query($qry2); $cklic=$this->check_lic_status($row['student_id']); $notification_status=$this->check_notification_status($row['authenticate_id']); $message="Notice Board updated for ".$row['student_firstname']." ".$row['student_lastname']." for ".$category." messages"; if($row['device_id'] !='' && $cklic && $notification_status == 1) { //$devid=$this->parentDeviceId($row['student_id']); //if($devid!='0') //{ $notify=$this->send_notification($row['device_id'],$message,$row['student_id'],'notbrd',date('Y-m-d'),$created_date,$post['category']); //} } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",class_id=".(int)$row['class_id'].",section_id=".(int)$row['section_id'].",school_id=".(int)$row['school_id'].",notify_type='notbrd',general_column1='".$created_date."',general_column2='".$post['category']."',read_status=1,created_on='".date('Y-m-d')."'"; mysql_query($noteins); } } } } else { $response=ERR205; } return $response; } function delete_notice($notice_id){ $qry = "delete from ced_t_noticeboard where notification_id = '".$notice_id."' "; $exe=mysql_query($qry); if($exe) { $qry = "delete from ced_t_noticeboard_images where noticeboard_img_id = '".$notice_id."' "; $exe=mysql_query($qry); $response=ERR203; } else { $response=ERR204; } return $response; } function parentDeviceId($id) { $sql="SELECT sp.device_id FROM `ced_t_students_parent` sp inner join `ced_t_student_licenses` sl on sp.student_id=sl.student_id WHERE sp.student_id='$id' and sp.account_status=1 and sl.license_status=1"; //$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 send_notification($registatoin_ids,$message,$uid,$type,$date,$today,$category) { $msg['message']=$message; $msg['student_id']=$uid; $msg['type']=$type; $msg['date']=$date; $msg['apldate']=$today; $msg['category']=$category; $registatoin_ids=array($registatoin_ids); $googleapi='AIzaSyDfQ9YXKCJEKgaush2VudGeZNCivxHBOh8'; $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; } function insert_generalnotice_foryou($post,$session,$file){ $target_dir = "uploads/noticeboard/"; $au_type ='4'; $category = "For You"; $str = ''; $created_date = date('Y-m-d H:i:s'); if($post['status'] == "all"){ $studentids = "all"; }else { foreach($post['student'] as $k=>$val){ $str .= ",".$val; } $str =ltrim($str,','); $studentids = $str; } $qry="INSERT INTO ced_t_noticeboard ( class_id, section_id, academicyear_id, notification_type, student_id, school_id, created_by, created_on, notification_description, audience_type) VALUES ('".$post['classes']."', '".$post['sections']."', '".$session['child']['choosen_academic_id']."', '".$post['category']."', '".$studentids."', '".$session['child']['log_school_id']."', '".$session['child']['auth_id']."', '".$created_date."', '".mysql_escape_string($post['notice_description'])."', '".$au_type."' ) "; $result=mysql_query($qry); $ntc=mysql_insert_id(); $i=0; if($ntc){ foreach($file['photos']['name'] as $img) { $target_file = $target_dir .date('his'). basename($img); if (move_uploaded_file($file["photos"]["tmp_name"][$i], $target_file)) { $savef=basename($target_file); $sql="insert into ced_t_noticeboard_images set notice_id='$ntc',image='".$savef."'"; mysql_query($sql); } $i++; } $response=ERR203; if($post['status'] == "all"){ //$qry="select student_id,student_firstname,student_lastname from ced_t_students where school_id=".(int)$session['child']['log_school_id']." and academic_year_id=".(int)$session['child']['choosen_academic_id']." and section_id=".(int)$post['sections']." and class_id=".(int)$post['classes']; $qry = "select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']." and s.status=1 and sp.account_status=1"; }else { //$qry = "select student_id,class_id,section_id,student_firstname,student_lastname from ced_t_students where class_id='".(int)$post['classes']."' and school_id='".(int)$session['child']['log_school_id']."' and academic_year_id=".(int)$session['child']['choosen_academic_id']." and section_id='".(int)$post['sections']."' and student_id in(".$studentids.") "; $qry = "select sp.device_id,sp.authenticate_id,sp.student_id,s.student_firstname,s.student_lastname,s.section_id,s.class_id,s.school_id from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$session['child']['log_school_id']." and s.class_id=".(int)$post['classes']." and s.section_id=".(int)$post['sections']." and s.academic_year_id=".(int)$session['child']['choosen_academic_id']." and s.student_id in(".$studentids.") and s.status=1 and sp.account_status=1"; } $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($row=mysql_fetch_array($exe)) { //$qry2="select student_id from ced_t_student_licenses where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$session['child']['choosen_academic_id']." and license_status=1"; //$exe2=mysql_query($qry2); // if(mysql_num_rows($exe2)) //{ $cklic=$this->check_lic_status($row['student_id']); $notification_status=$this->check_notification_status($row['authenticate_id']); $message="Notice Board updated for ".$row['student_firstname']." ".$row['student_lastname']." for ".$category." messages"; //$devid=$this->parentDeviceId($row['student_id']); if($row['device_id']!='' && $cklic && $notification_status == 1 ) { $notify=$this->send_notification($row['device_id'],$message,$row['student_id'],'notbrd',date('Y-m-d'),$created_date,$post['category']); } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",class_id=".(int)$row['class_id'].",section_id=".(int)$row['section_id'].",school_id=".(int)$row['school_id'].",notify_type='notbrd',general_column1='".$created_date."',general_column2='".$post['category']."',read_status=1,created_on='".date('Y-m-d')."'"; mysql_query($noteins); } // } } } }else{ $response=ERR204; } return $response; } function get_students_data_notice($class_id,$section_id,$school_id){ $qry = "select student_id,class_id,section_id,student_firstname,student_lastname from ced_t_students where class_id='".$class_id."' and school_id='".$school_id."' and section_id='".$section_id."' "; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data2[$row['student_id']]=$row; } return $data2; } function get_students_data_notice_byids($class_id,$section_id,$studentids,$school_id){ $qry = "select student_id,class_id,section_id,student_firstname,student_lastname from ced_t_students where class_id='".$class_id."' and school_id='".$school_id."' and section_id='".$section_id."' and student_id in(".$studentids.") "; //echo $qry; $exe=mysql_query($qry); while($row=mysql_fetch_array($exe)) { $data2[$row['student_id']]=$row; } return $data2; } function notice_data_images($notice_id) { $sql="select * from ced_t_noticeboard_images where notice_id=".(int)$notice_id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { while($row=mysql_fetch_assoc($exe)) { $rec[]=$row; } return $rec; } else { return 0; } } function deletethisimage($imgids) { $sql="delete from ced_t_noticeboard_images where noticeboard_img_id in (".$imgids.")"; mysql_query($sql); return 'deleted'; } function getsubject_name($subject_id,$school_id,$academic_id) { $sql="SELECT `subject_name` FROM `ced_t_subjects` WHERE `subject_id` ='".$subject_id."' and `school_id`='".$school_id."' and `academic_year_id`='".$academic_id."'"; //echo $sql; $result=mysql_query($sql); $row=mysql_fetch_array($result); return $row['subject_name']; } function student_name($id) { $sql="SELECT `student_firstname` , `student_rollno`,`student_lastname` FROM `ced_t_students` WHERE `student_id` = '".$id."' "; //echo $sql; $result=mysql_query($sql); /*while($row=mysql_fetch_array($result)) { $data[]=$row; }*/ $row=mysql_fetch_array($result); $data=$row['student_firstname']." ".$row['student_lastname']; //$data=$row['student_rollno']; return $data; } function delete_stops($stopids) { $sql="delete from ced_t_route_stops where route_stop_id in (".$stopids.")"; mysql_query($sql); return 'deleted'; } function check_password($pass,$uid){ $sql="SELECT `password` FROM `ced_t_authentication_details` WHERE `authenticate_id` = '".$uid."' "; $result=mysql_query($sql); $row=mysql_fetch_array($result); $pwd=$this->decryptIt($row['password']); return $pwd; } /*********************Decrypt the password*********************/ function decryptIt($q) { $cryptKey = 'qJB0rGtIn5UB1xG03efyCp'; $qDecoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0"); return( $qDecoded ); } /*********************Encrypt the password*********************/ function encryptIt($q) { $cryptKey = 'qJB0rGtIn5UB1xG03efyCp'; $qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) ); return( $qEncoded ); } function check_lic_status($student_id) { $sql="select license_status from ced_t_student_licenses where student_id=".(int)$student_id." and license_status=1"; $exe=mysql_query($sql); if(mysql_num_rows($exe)>0) return 1; else return 0; } function check_notification_status($notification_id){ $sql="select notifications from ced_t_authentication_details where authenticate_id=".(int)$notification_id." and notifications=1"; $exe=mysql_query($sql); if(mysql_num_rows($exe)>0) return 1; else return 0; } } ?>