JezK
Edit File: school_admin_access_anil.php
<?php include_once("Config.php"); class adminaccess { private $conn; function __construct() { require_once dirname(__FILE__) . '/DbConnect.php'; // opening db connection $db = new DbConn(); $this->conn = $db->connect(); } function school_attendance($class_id,$section_id,$school_id,$academic_id,$date) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $sql="select student_id,student_firstname,student_lastname,student_rollno from ced_t_students where school_id=".(int)$school_id." and academic_year_id=".(int)$academic_id." and class_id=".(int)$class_id." and section_id=".(int)$section_id; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { //$data['att_id']=$row['att_id']; $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['student_rollno']=$row['student_rollno']; $qry="select status,attendance_date from ced_t_attendance where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$academic_id." and attendance_date='".$today."'"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); $data['status']=$res['status']; $data['date']=$res['attendance_date']; } else { $data['status']='-'; $data['date']=$today; } //$data['month']=$row['month']; //$data['status']=$row[$colum]; $data2[]=$data; } } else { $sql="SELECT `student_id`,`student_firstname`,`student_lastname` FROM `ced_t_students` WHERE `class_id`='".$class_id."' and `section_id`='".$section_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { //$data['att_id']=$row['att_id']; $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; //$data['student_rollno']=$row['student_rollno']; $data['status']='Present'; //$data['date']=$row['attendance_date']; //$data['month']=$row['month']; //$data['status']=$row[$colum]; $data2[]=$data; } } } return $data2; } function absentdetails($id) { //$sql="select leave_id,leave_msg,no_of_days,leave_from,leave_to from tbl_leavedetails where student_id='".$id."' and applied_at='".$today."'"; //echo $sql; //$sql="SELECT * FROM `tbl_leavedetails` WHERE student_id='".$id."' and CURDATE() between `leave_from` and `leave_to`"; $sql="SELECT l.`absent_id`,l.`absent_reason`,l.`absent_from`,l.`absent_to`,l.`created_on`,s.`student_id`,s.`student_rollno`,s.`student_firstname`,s.`student_lastname`,s.`class_id`,s.`section_id` FROM ced_t_absentdetails l inner join ced_t_students s where l.student_id = s.student_id and s.student_id='".$id."' and CURDATE() between l.`absent_from` and l.`absent_to`"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { //$data['status']="1"; $row=mysqli_fetch_array($result); $data['absent_id']=$row['absent_id']; $data['absent_reason']=$row['absent_reason']; $data['absent_from']=$row['absent_from']; $data['absent_to']=$row['absent_to']; //$data['leave_to']=$row['leave_to']; $now=strtotime($row['absent_to']); $your_date = strtotime($row['absent_from']); $datediff = $now - $your_date; $days=floor($datediff/(60*60*24)); $data['no_of_days']=$days; $data['student_rollno']=$row['student_rollno']; $data['created_on']=$row['created_on']; $data['class_id']=$row['class_id']; $data['class_name']=$this->classname($row['class_id']); $data['section_id']=$row['section_id']; $data['section_name']=$this->sectionname($row['class_id'],$row['section_id']); //$data['section_id']=$row['section_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; } else { $data['status']="0"; } return $data; } function leavedetails($id,$date) { $sql="SELECT l.`leave_id`,l.`leave_message`,l.`leave_from`,l.`leave_to`,l.`leave_type`,l.`created_on`,s.`student_id`,s.`student_rollno`,s.`student_firstname`,s.`student_lastname`,s.`class_id`,s.`section_id` FROM ced_t_leavedetails l inner join ced_t_students s where l.student_id = s.student_id and s.student_id='".$id."' and '".$date."' between l.`leave_from` and l.`leave_to`"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); $data['leave_id']=$row['leave_id']; $data['leave_message']=$row['leave_message']; $data['leave_type']=$row['leave_type']; if($data['leave_type']==1) { $data['subject']="sick"; } else if($data['leave_type']==2) { $data['subject']="casual"; } else { $data['subject']="other"; } $data['leave_from']=$row['leave_from']; $data['leave_to']=$row['leave_to']; $now=strtotime($row['leave_to']); $your_date = strtotime($row['leave_from']); $datediff = $now - $your_date; $days=floor($datediff/(60*60*24)); $data['no_of_days']=$days; $data['student_rollno']=$row['student_rollno']; $data['created_on']=$row['created_on']; $data['class_id']=$row['class_id']; $data['class_name']=$this->classname($row['class_id']); $data['section_id']=$row['section_id']; $data['section_name']=$this->sectionname($row['class_id'],$row['section_id']); //$data['section_id']=$row['section_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; } else { $data['status']="0"; } return $data; } function student_name($id) { $sql="SELECT `student_firstname` , `student_rollno`,`student_lastname` FROM `ced_t_students` WHERE `student_id` = '".$id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); /*while($row=mysqli_fetch_array($result)) { $data[]=$row; }*/ $row=mysqli_fetch_array($result); $data=$row['student_firstname']." ".$row['student_lastname']; //$data=$row['student_rollno']; return $data; } function student_rollnumber($id) { $sql="SELECT `student_rollno` FROM `ced_t_students` WHERE `student_id` = '".$id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); /*while($row=mysqli_fetch_array($result)) { $data[]=$row; }*/ $row=mysqli_fetch_array($result); $data=$row['student_rollno']; return $data; } function classname($id) { $sql="SELECT `class_name` FROM `ced_t_class` WHERE `class_id` = '".$id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); $data=$row['class_name']; return $data; } function sectionname($class_id,$section_id) { $sql="SELECT `section_name` FROM `ced_t_sections` WHERE `section_id` = '".$section_id."' AND `class_id` = '".$class_id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); $data=$row['section_name']; return $data; } function get_subjectslists($class_id) { $sql="SELECT `subject_name` ,`subject_id` FROM `ced_t_subjects` s INNER JOIN `ced_t_class` c ON s.`class_category_id` = c.`class_category_id` WHERE s.`school_id` = c.`school_id` AND c.`class_id` ='".$class_id."'"; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['subject_name']=$row['subject_name']; $data2[]=$data; } return $data2; } function get_subjects_lists($class_id,$section_id,$exam_id,$student_id,$school_id,$academic_id) { //$sql="SELECT `subject_name` ,`subject_id` FROM `ced_t_subjects` s INNER JOIN `ced_t_class` c ON s.`class_category_id` = c.`class_category_id` WHERE s.`school_id` = c.`school_id` AND c.`class_id` ='".$class_id."'"; $sql="SELECT `subject_id`,`total_marks` FROM `ced_t_exam_timetable` WHERE `class_id`='".$class_id."' and `section_id`='".$section_id."' and `exam_id`='".$exam_id."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['subject_name']=$this->getsubject_name($row['subject_id'],$school_id,$academic_id); $data['total_marks']=$row['total_marks']; $data2[]=$data; } } return $data2; } function gettotal_marks($subject_id,$exam_id,$class_id,$section_id) { $sql="SELECT `total_marks` FROM `ced_t_exam_timetable` WHERE `subject_id`='".$subject_id."' and `exam_id`='".$exam_id."' and `class_id`='".$class_id."' and `section_id`='".$section_id."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); } return $row['total_marks']; } function get_classes($school_id,$academic_year_id) { $sql="SELECT `class_id` , `class_name` FROM `ced_t_class` where `school_id`='".$school_id."' and `academic_year_id`='".$academic_year_id."' order by class_order"; //echo $sql; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data[]=$row; } return $data; } function get_sections($class_id,$academic_id) { $sql="SELECT `section_id` , `section_name` FROM `ced_t_sections` WHERE `class_id` = '".$class_id."' and `academic_year_id`='".$academic_id."' order by section_id"; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data['section_id']=$row['section_id']; $data['section_name']=$row['section_name']; $data2[]=$data; } return $data2; } function addexamination_schedule($exam_id,$subject_id,$exam_date,$exam_time,$duration_time,$class_id,$section_id,$academic_id,$user_id,$total_marks) { $dateInput = explode('/',$exam_date); $date=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $sql12="SELECT * FROM `ced_t_exam_timetable` WHERE `exam_id`='".$exam_id."' and `class_id`='".$class_id."' and `section_id`='".$section_id."' and `subject_id`='".$subject_id."' "; $result12=mysqli_query($this->conn,$sql12); if(mysqli_num_rows($result12)>0) { $sql="UPDATE `ced_t_exam_timetable` SET `exam_date`='".$date."',`exam_time`='".$exam_time."',`exam_duration`='".$duration_time."', `updated_by`='".$user_id."',`updated_on`=CURDATE(), `total_marks`='".$total_marks."' WHERE `class_id`='".$class_id."' AND `section_id`='".$section_id."' AND `exam_id`='".$exam_id."' AND `subject_id`='".$subject_id."' AND `academic_year_id`='".$academic_id."'"; //$sql="UPDATE `ced_t_exam_timetable` SET `subject_id`='".$subject_id[$i]."', `exam_date`='".$date[$i]."',`exam_time`='".$exam_time[$i]."',`exam_duration`='".$duration_time[$i]."' WHERE `class_id`='".$class_id."' AND `section_id`='".$section_id."' AND `exam_id`='".$exam_id[$i]."' AND `academic_year_id`='".$academic_id."'"; } else { $sql="INSERT INTO `ced_t_exam_timetable`( `subject_id`, `exam_date`, `exam_time`, `exam_duration`, `class_id`, `section_id`, `exam_id`, `academic_year_id`,`total_marks`,`created_by`,`created_on`) VALUES ('".$subject_id."','".$date."','".$exam_time."','".$duration_time."','".$class_id."','".$section_id."','".$exam_id."','".$academic_id."','".$total_marks."','".$user_id."',CURDATE())"; } $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function get_homework($class_id,$section_id,$date,$subject) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $sql="select `School_diary_id`,`description` from `ced_t_school_diary` where class_id=".(int)$class_id." and section_id=".(int)$section_id." and subject_id=".(int)$subject." and diary_date='".$today."' and diary_type=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); $hw[]=$res['School_diary_id']; $hw[]=$res['description']; return $hw; } else return $hw[0]=0; } function adding_homework($class_id,$section_id,$date,$school_id,$academic_id) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $sql2="SELECT `subject_id`,`description`,`School_diary_id` FROM `ced_t_school_diary` WHERE `diary_date`='".$today."' and `school_id`='".$school_id."' and `academic_year_id`='".$academic_id."' and `class_id`='".$class_id."' and `section_id`='".$section_id."' " ; //echo $sql2; $result2=mysqli_query($this->conn,$sql2); while($row=mysqli_fetch_array($result2)) { $subjectids[]=$row['subject_id']; $subjectnames[]=$this->getsubject_name($row['subject_id'],$school_id,$academic_id); $description[]=$row['description']; $dairyid[]=$row['School_diary_id']; } $data['subject_id']=$subjectids; $data['subject_name']=$subjectnames; $data['description']=$description; $data['School_diary_id']=$dairyid; return $data; //print_r($data2); } function update_homework($diary_id,$description) { $description=mysqli_real_escape_string($description); $sql="UPDATE `ced_t_school_diary` SET `description`='".$description."' WHERE `School_diary_id`='".$diary_id."'"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function addhomework($class_id,$section_id,$subject_id,$date,$description,$user_id,$school_id,$academic_id) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $description=mysqli_real_escape_string($description); $sql="INSERT INTO `ced_t_school_diary`( `description`, `class_id`, `section_id`, `diary_date`, `subject_id`, `diary_type`, `assigned_by`, `school_id`, `created_on`, `created_by`, `academic_year_id`) VALUES ('".$description."','".$class_id."','".$section_id."','".$today."','".$subject_id."',1,2,'".$school_id."',CURDATE(),'".$user_id."','".$academic_id."')"; //echo $sql; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function addgrade_students($exam_id,$student_id,$grade,$academic_id,$user_id) { $sql="SELECT * FROM ` ced_t_student_grades` WHERE `exam_id`='".$exam_id."' AND `student_id`='".$student_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $sql="UPDATE ` ced_t_student_grades` SET `student_grade`='".$grade."',`updated_on`=CURDATE() ,`updated_by`='".$user_id."' WHERE `exam_id`='".$exam_id."' and `student_id`='".$student_id."' and `academic_year_id`='".$academic_id."'"; //echo $sql; } else { $sql="INSERT INTO ` ced_t_student_grades`( `exam_id`, `student_id`, `student_grade`, `academic_year_id`,`created_on`,`created_by`) VALUES ('".$exam_id."','".$student_id."','".$grade."','".$academic_id."',CURDATE(),'".$user_id."')"; //echo $sql; } $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function save_student_marks($exam_id,$student_id,$subject_id,$secured_marks,$exam_status,$grade,$academic_id,$total_secured_marks,$user_id) { $sql2="SELECT * FROM `ced_t_students_marks` WHERE `exam_id`='".$exam_id."' and `student_id`='".$student_id."' and `subject_id`='".$subject_id."' "; $result2=mysqli_query($this->conn,$sql2); if(mysqli_num_rows($result2)>0) { //$error=3; $sql="UPDATE `ced_t_students_marks` SET `marks_secured`='".$secured_marks."',`status`='".$exam_status."',`grade`='".$grade."' where `exam_id`='".$exam_id."' and `student_id`='".$student_id."' and `academic_year_id`='".$academic_id."' and `subject_id`='".$subject_id."'"; //echo $sql; } else { $sql="INSERT INTO `ced_t_students_marks`( `exam_id`, `student_id`, `marks_secured`, `subject_id`, `status`, `grade`, `created_by`,`created_on`, `academic_year_id`,`total_secured_marks`) VALUES ('".$exam_id."','".$student_id."','".$secured_marks."','".$subject_id."','".$exam_status."','".$grade."','".$user_id."',CURDATE(),'".$academic_id."','".$total_secured_marks."')"; //echo $sql; } $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function get_students($class_id,$section_id,$school_id,$academic_id,$exam_id,$subject_id) { $sql="SELECT s.`marks_secured`,s.`subject_id`,s.`student_id`,s.`exam_id`,s.`status`,m.`student_firstname`,m.`student_lastname` FROM `ced_t_students_marks`as s inner join `ced_t_students` as m WHERE m.`student_id`=s.`student_id` and m.`class_id`='".$class_id."' and m.`section_id`='".$section_id."' and s.`exam_id`='".$exam_id."' and s.`subject_id`='".$subject_id."' "; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['marks_secured']=$row['marks_secured']; $data['total_marks']=$this->gettotal_marks($subject_id,$exam_id,$class_id,$section_id); $data['status']=$row['status']; $data['exam_id']=$row['exam_id']; $data2[]=$data; } } else { $sql="SELECT `student_rollno` , `student_id`,`student_firstname` , `student_lastname` FROM `ced_t_students` WHERE `class_id` = '".$class_id."' AND `section_id` = '".$section_id."' AND `academic_year_id` = '".$academic_id."' AND `school_id` = '".$school_id."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['student_rollno']=$row['student_rollno']; $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['total_marks']=$this->gettotal_marks($subject_id,$exam_id,$class_id,$section_id); $data2[]=$data; } } else { $data2=""; } } return $data2; } function get_students2($class_id,$section_id,$school_id,$academic_id) { $sql=" SELECT `student_rollno` , `class_id`,`section_id` ,`student_id`,`student_firstname` , `student_lastname` FROM `ced_t_students` WHERE `class_id` = '".$class_id."' AND `section_id` = '".$section_id."' AND `academic_year_id` = '".$academic_id."' AND `school_id` = '".$school_id."' and status=1"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['student_rollno']=$row['student_rollno']; $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['class_name']=$this->classname($row['class_id']); $data['section_name']=$this->sectionname($row['class_id'],$row['section_id']); $data2[]=$data; } } else { $data2=""; } return $data2; } function get_studentsto_grade($class_id,$section_id,$exam_id,$school_id,$academic_id) { $sql=" SELECT g.`student_id`,g.`student_grade`,s.`student_rollno` ,s.`student_firstname`, s.`student_lastname` FROM ` ced_t_student_grades` as g inner join ced_t_students as s on s.`student_id` = g.`student_id` where s.`class_id` = '".$class_id."' and s.`section_id` = '".$section_id."' and s.`school_id` = '".$school_id."' and s.`academic_year_id` = '".$academic_id."' and g.`exam_id`='".$exam_id."' "; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['student_rollno']=$row['student_rollno']; $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['student_grade']=$row['student_grade']; $data2[]=$data; } } else { $sql=" SELECT `student_rollno` , `class_id`,`section_id` ,`student_id`,`student_firstname` , `student_lastname` FROM `ced_t_students` WHERE `class_id` = '".$class_id."' AND `section_id` = '".$section_id."' AND `academic_year_id` = '".$academic_id."' AND `school_id` = '".$school_id."' "; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['student_rollno']=$row['student_rollno']; $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['class_name']=$this->classname($row['class_id']); $data['section_name']=$this->sectionname($row['class_id'],$row['section_id']); $data2[]=$data; } } } return $data2; } function get_current_academicyear_id($chosen_academic_id,$school_id) { $sql="SELECT `academic_startdate`,`academic_enddate` FROM `ced_t_academicyear` WHERE `academic_id`='".$chosen_academic_id."' and `school_id`='".$school_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); $data['start_date']=$row['academic_startdate']; $data['end_date']=$row['academic_enddate']; } return $data; } function addstudents_route($student_id,$route_id,$stop_id,$academic_id) { for($i=0;$i<count($student_id);$i++) { $sql="SELECT * FROM `ced_t_students_routes` WHERE `student_id`='".$student_id[$i]."' and `route_id`='".$route_id."' "; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $sql="UPDATE `ced_t_students_routes` SET `route_stop_id`='".$stop_id."' WHERE `student_id`='".$student_id[$i]."' and `route_id`='".$route_id."' "; } else { $sql="INSERT INTO `ced_t_students_routes`( `student_id`, `academic_year_id`, `route_id`, `route_stop_id`, `created_on`) VALUES ('".$student_id[$i]."','".$academic_id."','".$route_id."','".$stop_id."',CURDATE())"; } $result=mysqli_query($this->conn,$sql); if($result) { $error=1; $success[]=$student_id[$i]; } else { $error=2; $fail[]=$student_id[$i]; } } if(count($fail)==0) { return "success"; } else { $failure = implode(",",$fail); $student_names=$this->student_names($failure); return $student_names; } } function staff_routes_info($route_id,$school_id,$academic_id) { $sql="SELECT `staff_name`,sf.`staff_id`,`staff_address`,`staff_mobile` FROM `ced_t_school_staff` sf inner join `ced_t_staff_routes` r on sf.`staff_id`=r.`staff_id` where r.`route_id`='".$route_id."' and sf.`academic_year_id`='".$academic_id."' and sf.`school_id`='".$school_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['staff_name']=$row['staff_name']; $data['staff_address']=$row['staff_address']; $data['staff_mobile']=$row['staff_mobile']; $data2[]=$data; } } else { $data2=""; } return $data2; } function student_names($student_ids) { $sql="SELECT `student_firstname` , `student_lastname` FROM `ced_t_students` WHERE `student_id` in ('".$student_ids."') "; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data[]=$row['student_firstname']." ".$row['student_lastname']; } $names = implode(",",$data); return $names; } function route_stops($route_id,$academic_id) { $sql="SELECT `route_stop_id`,`route_stop_name` FROM `ced_t_route_stops` WHERE `route_id`='".$route_id."' and `academic_year_id`='".$academic_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['route_stop_id']=$row['route_stop_id']; $data['route_stop_name']=$row['route_stop_name']; $data2[]=$data; } } return $data2; } function getroute_stops_lists($route_id,$academic_id) { $sql="SELECT `route_stop_id` ,`route_stop_name` FROM `ced_t_route_stops` WHERE `route_id`='".$route_id."' and `academic_year_id`='".$academic_id."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['route_stop_id']=$row['route_stop_id']; $data['route_stop_name']=$row['route_stop_name']; $data2[]=$data; } } //print_r($data2); return $data2; } function add_students_marks($class_id,$section_id,$school_id,$academic_id,$exam_name_id,$student_id) { $sql="SELECT t.`total_marks` , t.`class_id` , t.`section_id` , t.`pass_marks` , t.`exam_id` , m.`marks_secured` , m.`student_id` , m.`subject_id` FROM `ced_t_exam_timetable` t INNER JOIN `ced_t_students_marks` m WHERE t.`class_id` ='".$class_id."' AND t.`section_id` ='".$section_id."' AND t.`academic_year_id` ='".$academic_id."' AND m.`student_id` ='".$student_id."' AND m.`exam_id` ='".$exam_name_id."' AND m.`subject_id` = t.`subject_id` and t.`exam_id` = m.`exam_id`"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['marks_secured']=$row['marks_secured']; $data['pass_marks']=$row['pass_marks']; if($data['marks_secured']>$data['pass_marks']) { $data['status']="P"; } else { $data['status']="F"; } $data['student_id']=$row['student_id']; $data['exam_id']=$row['exam_id']; $data['student_rollno']=$this->student_rollnumber($row['student_id']); $data['subject_id']=$row['subject_id']; $data['student_name']=$this->student_name($data['student_id']); $data['subject_name']=$this->getsubject_name($row['subject_id'],$school_id,$academic_id); $data['total_marks']=$row['total_marks']; $grade=$this->getStudent_Grade($row['exam_id'],$row['student_id'],$academic_id); if($grade) { $data['grade']=$grade; } else { $data['grade']=""; } $data2[]=$data; } } return $data2; } function getStudent_Grade($exam_id,$student_id,$academic_id) { $sql="SELECT `student_grade` FROM ` ced_t_student_grades` WHERE `exam_id`='".$exam_id."' AND `academic_year_id`='".$academic_id."' AND `student_id`='".$student_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); } return $row['student_grade']; } function getsubjects($class_id,$school_id,$academic_id) { $sql="SELECT `subject_id` , `subject_name` FROM `ced_t_subjects` sub INNER JOIN `ced_t_class` cls ON sub.`class_category_id` = cls.`class_category_id` AND sub.`school_id` ='".$school_id."' AND sub.`academic_year_id` ='".$academic_id."' AND `class_id` ='".$class_id."'"; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['subject_name']=$row['subject_name']; $data2[]=$data; } return $data2; } function adding_student_marks($exam_id,$subject_id,$student_id,$secured_marks,$status,$academic_id,$user_id) { $sql2="SELECT * FROM `ced_t_students_marks` WHERE `exam_id`='".$exam_id."' and `student_id`='".$student_id."' and `academic_year_id`='".$academic_id."'"; $result2=mysqli_query($this->conn,$sql2); if(mysqli_num_rows($result2)>0) { $sql="UPDATE `ced_t_students_marks` SET `marks_secured`='".$secured_marks."',`status` ='".$status."' where `exam_id`='".$exam_id."' and `student_id`='".$student_id."' and `academic_year_id`='".$academic_id."' and `subject_id`='".$subject_id."' "; } else { $sql="INSERT INTO `ced_t_students_marks`( `exam_id`, `student_id`, `marks_secured`, `subject_id`, `status`, `grade`, `created_by`, `created_on` ,`academic_year_id`) VALUES ('".$exam_id."','".$student_id."','".$secured_marks."','".$subject_id."','".$status."',0,'".$user_id."',CURDATE(),'".$academic_id."')"; } //echo $sql; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function update_student_marks($exam_id,$subject_id,$student_id,$secured_marks,$status,$academic_id) { $sql="UPDATE `ced_t_students_marks` SET `marks_secured` ='".$secured_marks."' ,`status`='".$status."'WHERE `student_id` ='".$student_id."' AND `subject_id` ='".$subject_id."' AND `exam_id` ='".$exam_id."' AND `academic_year_id` ='".$academic_id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=0; } return $error; } function update_attendance($id,$status,$date,$academic_id) { $devid=$this->parentDeviceId($id); $sql2="select * from `ced_t_attendance` where student_id='".$id."' and attendance_date='".$date."' and `academic_year_id`='".$academic_id."' "; $result2=mysqli_query($this->conn,$sql2); if(mysqli_num_rows($result2)>0) $sql="update `ced_t_attendance` set `status`='".$status."' where attendance_date='".$date."' and student_id='".$id."' and `academic_year_id`='".$academic_id."' "; else $sql="INSERT INTO `ced_t_attendance`( `student_id`, `attendance_date` , `status`,`academic_year_id`) VALUES ('".$id."','".$date."','".$status."','".$academic_id."')"; $result=mysqli_query($this->conn,$sql); if($result) $error=1; else $error=2; if($status=='P') $message="Your child was Present"; else if($status=='A') $message="Your child was Absent"; else if($status=='L') $message="Your child is on Leave"; if($devid!='0') $notify=$this->send_notification($devid,$message,$id,'att_status'); return $error; } function send_notification($registation_ids,$message,$uid,$type) { $reg_ids=array($registation_ids); $msg['message']=$message; $msg['student_id']=$uid; $msg['type']=$type; $googleapi='AIzaSyDfQ9YXKCJEKgaush2VudGeZNCivxHBOh8'; $url = 'https://android.googleapis.com/gcm/send'; $fields = array('registration_ids' => $reg_ids,'data' => array("extra" =>$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 parentDeviceId($id) { $sql="select device_id from ced_t_students_parent where student_id=".(int)$id; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); return $res['device_id']; } else return '0'; } function load_school_homework($class_id,$sec_id,$school_id,$academic_id,$date) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $sql="SELECT `subject_id` , `description` , `School_diary_id`, `class_id` , `section_id` , `diary_date` FROM `ced_t_school_diary` WHERE `class_id` ='".$class_id."' AND `section_id` ='".$sec_id."' AND `school_id` ='".$school_id."' AND `academic_year_id` ='".$academic_id."' AND `diary_date` = '".$today."' and diary_type=1"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['School_diary_id']=$row['School_diary_id']; $data['subject_name']=$this->getsubject_name($row['subject_id'],$school_id,$academic_id); $data['description']=$row['description']; $data['class_id']=$row['class_id']; $data['section_id']=$row['section_id']; $data['diary_date']=$row['diary_date']; $data2[]=$data; } } else { $data2=0; } return $data2; } 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=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); return $row['subject_name']; } function update_student_onroute($student_id,$route_id,$route_stop_id,$school_id,$academic_id) { $sql="UPDATE `ced_t_students_routes` SET `route_id` = '".$route_id."',`route_stop_id` = '".$route_stop_id."' WHERE `student_id` = '".$student_id."' AND `academic_year_id` = '".$academic_id."'"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function delete_homework_details($homework_id) { $sql="DELETE FROM `ced_t_school_diary` WHERE `School_diary_id`='".$homework_id."'"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function exam_name_details($school_id,$academic_id) { $sql="SELECT `exam_name` , `exam_id` FROM `ced_t_exam_names` WHERE `school_id` ='".$school_id."' AND `academic_year_id` ='".$academic_id."'"; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data['exam_name']=$row['exam_name']; $data['exam_id']=$row['exam_id']; $data2[]=$data; } return $data2; } function exam_timetable($class_id,$section_id,$school_id,$academic_id,$exam_id) { $sql="SELECT `timetable_id` , `total_marks`, `class_id`,`section_id`,`subject_id` , `exam_date` , `exam_time` , `exam_duration` , `exam_id` FROM `ced_t_exam_timetable` WHERE `class_id` ='".$class_id."' AND `section_id` ='".$section_id."' AND `exam_id` ='".$exam_id."' AND `academic_year_id` ='".$academic_id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data['timetable_id']=$row['timetable_id']; $data['exam_date']=$row['exam_date']; $data['exam_id']=$row['exam_id']; $data['subject_id']=$row['subject_id']; $data['exam_time']=$row['exam_time']; $data['exam_duration']=$row['exam_duration']; $data['total_marks']=$row['total_marks']; $data['class_id']=$row['class_id']; $data['section_id']=$row['section_id']; $data['exam_subject']=$this->getsubject_name($row['subject_id'],$school_id,$academic_id); $data2[]=$data; } return $data2; } function loadexam_timetable($class_id,$section_id,$school_id,$academic_id,$exam_id) { $sql="SELECT `subject_name` ,`subject_id` FROM `ced_t_subjects` s INNER JOIN `ced_t_class` c ON s.`class_category_id` = c.`class_category_id` WHERE s.`school_id` = c.`school_id` AND c.`class_id` ='".$class_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['exam_subject']=$row['subject_name']; $data2[]=$data; } } return $data2; } function loadexam_timetable_subject($class_id,$section_id,$school_id,$academic_id,$exam_id,$subject_id) { $sql="SELECT `total_marks` ,`exam_date`,`exam_duration`,`exam_time`,`subject_id` FROM `ced_t_exam_timetable` WHERE `subject_id`='".$subject_id."' and `exam_id`='".$exam_id."' and `class_id`='".$class_id."' and `section_id`='".$section_id."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['total_marks']=$row['total_marks']; $data['exam_date']=$row['exam_date']; $data['exam_duration']=$row['exam_duration']; $data['exam_time']=$row['exam_time']; $data['exam_subject']=$this->getsubject_name($row['subject_id'],$school_id,$academic_id);; $data2[]=$data; } } return $data2; } function delete_exam_schedule($exam_timetable_id) { $sql="DELETE FROM `ced_t_exam_timetable` WHERE `timetable_id`='".$exam_timetable_id."' "; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function settigs_change_password($email,$current_password,$new_password,$school_id,$user_id) { $sql="SELECT * FROM `ced_t_authentication_details` WHERE `email`='".$email."' and `password`='".$current_password."' and `authenticate_id`='".$user_id."' and `school_admin_access`='1' and `school_id`='".$school_id."' "; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $sql2="UPDATE `ced_t_authentication_details` SET `password`='".$new_password."' where `email`='".$email."' "; $result2=mysqli_query($this->conn,$sql2); if($result2) { $error=1; } else { $error=2; } } return $error; } function school_students_routes($school_id,$academic_id) { $sql="SELECT `route_id`,`source_name`,`destination_name` FROM `ced_t_routes` WHERE `school_id`='".$school_id."' and `academic_year_id`='".$academic_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['route_id']=$row['route_id']; $data['route_name']=$row['source_name'].'_'.$row['destination_name']; $data2[]=$data; } } else { $data2=""; } return $data2; } function school_students_routes_info($route_id,$academic_id) { $sql="SELECT s.`student_id`,s.`student_firstname`,s.`student_lastname`,s.`class_id`,s.`section_id`,cr.`route_stop_name` FROM `ced_t_students` s inner join `ced_t_students_routes` sr on s.`student_id`=sr.`student_id` inner join `ced_t_route_stops` cr on sr.`route_stop_id`=cr.`route_stop_id` and sr.`route_id`='".$route_id."' and sr.`academic_year_id`='".$academic_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data['student_rollno']=$row['student_rollno']; $data['student_id']=$row['student_id']; $data['class_id']=$row['class_id']; $data['section_id']=$row['section_id']; $data['route_stop_name']=$row['route_stop_name']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['class_name']=$this->classname($row['class_id']); $data['section_name']=$this->sectionname($row['class_id'],$row['section_id']); $data2[]=$data; } } else { $data2=""; } return $data2; } function monthly_attendance($class_id,$section_id,$month_id) { $sql="SELECT `student_id` FROM `ced_t_students` WHERE `class_id`='".$class_id."' and `section_id`='".$section_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $student_iddata[]=$row['student_id']; } } $sql="SELECT `attendance_date` FROM `ced_t_attendance` WHERE month(`attendance_date`)='".$month_id."' and year(`attendance_date`)= year(CURDATE()) group by `attendance_date`"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $atten[]=$row['attendance_date']; } } $merge_data['studentids']=$student_iddata; $merge_data['dates']=$atten; for($i=0;$i<count($student_iddata);$i++) { for($j=0;$j<count($atten);$j++) { $sql = "SELECT day(`attendance_date`) as day, a.`status`,attendance_date FROM `ced_t_attendance` a inner join `ced_t_students` b on a.`student_id`=b.`student_id` WHERE month(`attendance_date`)='".$month_id."' and b.`class_id`='".$class_id."' and b.`section_id`='".$section_id."' and a.`student_id`='".$student_iddata[$i]."' and a.`attendance_date`='".$atten[$j]."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_array($result)) { $datas['student_id'] = $student_iddata[$i]; $datas['day'] = $row['attendance_date']; $datas['status'] = $row['status']; $datasd[] = $datas; } } } } $merge_data['att_status']=$datasd; //echo json_encode($merge_data); return $merge_data; } function student_attendance_status($studet_id,$date) { $sql="SELECT `status` FROM `ced_t_attendance` WHERE `student_id`='".$studet_id."' and `attendance_date`='".$date."'"; //echo $sql.'<br>'; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result) > 0) { $row=mysqli_fetch_array($result); return $row['status']; } else { return 'no'; } } function getstudent_ids($class_id,$section_id) { $sql="SELECT `student_id` FROM `ced_t_students` WHERE `class_id`='".$class_id."' and `section_id`='".$section_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data[]=$row['student_id']; } } return $data; } function attendance_dates($month,$class_id,$section_id,$school_id,$academic_id) { $sql="SELECT a.`attendance_date` FROM `ced_t_attendance` a inner join `ced_t_students` s on s.`student_id`=a.`student_id` and s.`class_id`='".$class_id."' and s.`academic_year_id`='".$academic_id."' and s.`school_id`='".$school_id."' and s.`section_id`='".$section_id."' and month(`attendance_date`)='".$month."' and year(`attendance_date`)= year(CURDATE()) group by `attendance_date`"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { while($row=mysqli_fetch_array($result)) { $data[]=$row['attendance_date']; } } return $data; } function view_examname($school_id,$academic_id) { $sql2="select * from ced_t_exam_names where school_id='".$school_id."' and academic_year_id='".$academic_id."' order by exam_id asc"; //echo $sql2; $result2=mysqli_query($this->conn,$sql2); while($row=mysqli_fetch_array($result2)) { $data[]=$row; } return $data; } function adding_exam_names($school_id,$academic_id,$exname,$admin_id) { $sql="SELECT * FROM `ced_t_exam_names` WHERE `exam_name`='".$exname."' and `academic_year_id`='".$academic_id."' and `school_id`='".$school_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $data=1; } else { $sql=" INSERT INTO `ced_t_exam_names`(`exam_name`, `school_id`, `academic_year_id`, `created_by`, `created_on`) VALUES ('".$exname."','".$school_id."','".$academic_id."','".$admin_id."',CURDATE())"; $result=mysqli_query($this->conn,$sql); if($result) { $data=2; } else { $data=3; } } return $data; } function edit_exam_names($edit_name,$admin_id,$exam_id) { $sql="UPDATE `ced_t_exam_names` SET `exam_name`='".$edit_name."',`updated_by`='".$admin_id."',`updated_on`=CURDATE() WHERE `exam_id`='".$exam_id."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=0; } return $error; } function delete_examname($id) { $sql="SELECT student_marks_id FROM `ced_t_students_marks` WHERE `exam_id`=".(int)$id; $result=mysqli_query($this->conn,$sql); $sql2="select timetable_id from ced_t_exam_timetable where exam_id=".(int)$id; $result1=mysqli_query($this->conn,$sql2); if(mysqli_num_rows($result)>0 ||mysqli_num_rows($result1)) { $error=2; } else { $sql="delete from ced_t_exam_names where exam_id='".$id."'"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=0; } } return $error; } function student_score_details($student_id,$class_id,$school_id,$academic_id) { $people=array(); $sql="SELECT s.`subject_id` ,s.`subject_name` FROM `ced_t_subjects` s inner join `ced_t_class` c on s.`class_category_id`=c.`class_category_id` and c.`class_id`='".$class_id."' and s.`school_id`=c.`school_id` and s.`school_id`='".$school_id."' "; $result=mysqli_query($this->conn,$sql); while($info=mysqli_fetch_array($result)) { $subjects[]=$info['subject_id']; $subjects2[]=$info['subject_name']; } $sql3="SELECT `exam_id` FROM `ced_t_exam_names` WHERE `school_id` ='".$school_id."' AND `academic_year_id` ='".$academic_id."'"; $result3=mysqli_query($this->conn,$sql3); while($row=mysqli_fetch_array($result3)) { //$data['exam_name']=$row['exam_name']; //$data['exam_id']=$row['exam_id']; $exams[]=$row['exam_id']; } $merge['subjects']=$subjects; $merge['subjects_list']=$subjects2; $merge['exames']=$exams; //echo count($exams); for($i=0;$i<count($subjects);$i++) { for($j=0;$j<count($exams);$j++) { //echo $j.'<br>'; $sql2="SELECT sub.`subject_id` , sub.`subject_name` , e.`exam_id` , m.`marks_secured` FROM `ced_t_subjects` sub INNER JOIN `ced_t_students_marks` m ON sub.`subject_id` = m.`subject_id` INNER JOIN `ced_t_exam_names` e ON m.`exam_id` = e.`exam_id` AND m.`student_id` ='".$student_id."' and m.`subject_id`= '".$subjects[$i]."' and m.`exam_id`='".$exams[$j]."' "; $result2=mysqli_query($this->conn,$sql2); if(mysqli_num_rows($result2) > 0) { $row=mysqli_fetch_array($result2); //$data['subject_name']=$row['subject_name']; $data['subject_id']=$subjects[$i]; $data['exam_id']=$exams[$j]; $exam_name=$this->get_exam_name($data['exam_id']); //echo $exam_name.'<br>'; if (in_array($exam_name, $people, true)) { //echo 'if : '.$exam_name.'<br>'; } else { //echo 'else : '.$exam_name.'<br>'; $people[]=$exam_name; } //$people[]=$exam_name; $data['marks_secured']=$row['marks_secured']; $data2[]=$data; } } } //echo json_encode($people); $merge['marks']=$data2; $merge['exam_names']=$people; $merge['total_marks']=$this->get_totalmarks($subjects,$exams,$student_id); return $merge; } function get_totalmarks($subjects,$exam_ids,$student_id) { $subj=implode(",",$subjects); for($i=0;$i<count($exam_ids);$i++) { $sql="SELECT sum(`marks_secured`) as sum FROM `ced_t_students_marks` WHERE `student_id` ='".$student_id."' and `subject_id` in(".$subj.") and `exam_id`='".$exam_ids[$i]."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); if($row['sum']>0) { $data[]= $row['sum']; } } } return $data; } function get_exam_name($exam_id) { $sql="SELECT `exam_name` FROM `ced_t_exam_names` WHERE `exam_id`='".$exam_id."'"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); } return $row['exam_name']; } function delete_student_route($student_id,$academic_id) { $sql="DELETE FROM `ced_t_students_routes` WHERE `student_route_id`=".(int)$student_id; $result=mysqli_query($this->conn,$sql); return 1; } function deletestaff_route($stf_id,$academic_id) { $sql="DELETE FROM `ced_t_staff_routes` WHERE `staff_route_id`='".$stf_id."'"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=2; } return $error; } function delete_marks_data($id) { $sql="delete from ced_t_exam_timetable where timetable_id='".$id."'"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; } else { $error=0; } return $error; } } ?>