JezK
Edit File: 2021-09-25school_admin_access_file.php
<?php date_default_timezone_set("Asia/Calcutta"); include_once("Config.php"); class adminaccess { private $conn; function __construct() { require_once dirname(__FILE__) . '/DbConnect.php'; // opening db connection $db = new DbConnect(); $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." and status=1"; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $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=mysql_query($qry); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); $data['status']=$res['status']; $data['date']=$res['attendance_date']; } else { $query="select leave_id from ced_t_leavedetails where student_id=".(int)$row['student_id']." and academic_year_id=".(int)$academic_id." and '".$today."' between leave_from and leave_to"; $execute=mysql_query($query); if(mysql_num_rows($execute)) { $data['status']='L'; $data['date']=$today; } else { $data['status']='-'; $data['date']=$today; } } $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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data['student_id']=$row['student_id']; $data['student_name']=$row['student_firstname']." ".$row['student_lastname']; $data['status']='Present'; $data2[]=$data; } } } 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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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]."'"; $result=mysql_query($sql); if(mysql_num_rows($result) > 0) { while($row = mysql_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; 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."'"; $result=mysql_query($sql); if(mysql_num_rows($result) > 0) { $row=mysql_fetch_array($result); return $row['status']; } else { return 'no'; } } 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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data[]=$row['attendance_date']; } } return $data; } function absentdetails($id,$rdate) { $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 '".$rdate."' between l.`absent_from` and l.`absent_to`"; //echo $sql; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { //$data['status']="1"; $row=mysql_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=$diff=round((abs(strtotime($data['absent_from'])-strtotime($data['absent_to']))+86400)/86400); if($row['absent_from']==$row['absent_to']) $data['no_of_days']=1; else $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=mysql_query($sql); if(mysql_num_rows($result)>0) { //$data['status']="1"; $row=mysql_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 if($data['leave_type']==0) { $data['subject']="Casual"; } $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=$diff=round((abs(strtotime($data['leave_from'])-strtotime($data['leave_to']))+86400)/86400); if($row['leave_from']==$row['leave_to']) $data['no_of_days']=1; else $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 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=mysql_query($sql2); while($row=mysql_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; } function update_homework($diary_id,$description,$class,$section,$subject,$date,$academic_id,$school_id,$user_id,$attachment_file) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $description=mysql_real_escape_string($description); if($today==date('Y-m-d')) { $dt="Today"; $bto=date('Y-m-d'); } else { $dt=$date; $bto=$today; } $sbjname=$this->getsubject_name($subject,$school_id,$academic_id); $sql="UPDATE `ced_t_school_diary` SET `description`='".$description."',`attachment`='".$attachment_file."',class_id='$class',section_id='$section',subject_id='$subject',diary_date='".$today."',updated_by='$user_id',updated_on='".date('Y-m-d')."' WHERE `School_diary_id`=".(int)$diary_id; $result=mysql_query($sql); if($result) { $error=1; $qry="select student_id,student_firstname,student_lastname from ced_t_students where class_id=".(int)$class." and section_id=".(int)$section." and 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)$academic_id." and license_status=1"; $exe2=mysql_query($qry2); if(mysql_num_rows($exe2)) { $devid=$this->parentDeviceId($row['student_id']); if(!empty($devid)) { $message=$row['student_firstname']." ".$row['student_lastname']." has been assigned Home Work for ".$sbjname." for ".$dt; $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",notify_type='homework',read_status=1,general_column1='".$bto."',created_on='".date('Y-m-d')."'"; mysql_query($noteins); $nstate=$this->getNotestate($devid['authenticate_id']); if($nstate=='1' && $devid['device_id']!='') $notify=$this->send_notification($devid['device_id'],$message,$row['student_id'],'homework',date('Y-m-d'),$today); } } } } } else { $error=1; } return $error; } function addhomework($class_id,$section_id,$subject_id,$date,$description,$user_id,$school_id,$academic_id,$attachment_file) { $dateInput = explode('/',$date); $today=$dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; if($today==date('Y-m-d')) { $dt="Today"; $bto=date('Y-m-d'); } else { $dt=$date; $bto=$today; } $description=mysql_real_escape_string($description); $sbjname=$this->getsubject_name($subject_id,$school_id,$academic_id); $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`,`attachment`) VALUES ('".$description."','".$class_id."','".$section_id."','".$today."','".$subject_id."',1,2,'".$school_id."',CURDATE(),'".$user_id."','".$academic_id."','".$attachment_file."')"; //echo $sql; $result=mysql_query($sql); if($result) { $error=1; $qry="select student_id,student_firstname,student_lastname from ced_t_students where class_id=".(int)$class_id." and section_id=".(int)$section_id; $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)$academic_id." and license_status=1"; $exe2=mysql_query($qry2); if(mysql_num_rows($exe2)) { $devid=$this->parentDeviceId($row['student_id']); if(!empty($devid)) { $message=$row['student_firstname']." ".$row['student_lastname']." has been assigned Home Work for ".$sbjname." for ".$dt; $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$row['student_id'].",notify_type='homework',read_status=1,general_column1='".$bto."',created_on='".date('Y-m-d')."'"; mysql_query($noteins); $nstate=$this->getNotestate($devid['authenticate_id']); if($nstate=='1' && $devid['device_id']!='') $notify=$this->send_notification($devid['device_id'],$message,$row['student_id'],'homework',date('Y-m-d'),$today); } } } } } 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=mysql_query($sql); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); $hw[]=$res['School_diary_id']; $hw[]=$res['description']; return $hw; } else return $hw[0]=0; } function delete_attachment($dairy_id) { $sql="select `attachment` from `ced_t_school_diary` where School_diary_id='".$dairy_id."'"; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); if($res['attachment']) { unlink('uploads/homework/'.$res['attachment']); } } $sql="UPDATE `ced_t_school_diary` SET `attachment`='' WHERE `School_diary_id`='".$dairy_id."'"; $result=mysql_query($sql); if($result) { $error=1; }else { $error=2; } return $error; } function delete_calevent($notification_id) { //$sql="UPDATE `ced_t_school_diary` SET `attachment`='' WHERE `School_diary_id`='".$dairy_id."'"; $sql="DELETE FROM `ced_t_noticeboard` WHERE `notification_id`='".$notification_id."'"; $result=mysql_query($sql); if($result) { $error=1; }else { $error=2; } return $error; } function getEventDates($date,$academic_yearid) { $eventdates=array(); $dtes=explode('-',$date); $sql_event="SELECT `created_on` FROM `ced_t_noticeboard` WHERE `notification_type`=6 and month(created_on)='".$dtes[1]."' and Year(`created_on`)='".$dtes[0]."' and `academicyear_id`='".$academic_yearid."'"; $res_event=mysql_query($sql_event); if(mysql_num_rows($res_event)>0) { while($row=mysql_fetch_array($res_event)) { $edates=explode(' ',$row['created_on']); $chngedte=explode('-',$edates[0]); $actual_date=$chngedte[1].'/'.$chngedte[2].'/'.$chngedte[0]; $eventdates[]=$actual_date; } } return $eventdates; } function getthisdiarydetails($hmid) { $sql="select * from ced_t_school_diary where School_diary_id=".(int)$hmid; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); return $res; } function student_name($id) { $sql="SELECT `student_firstname` , `student_rollno`,`student_lastname` FROM `ced_t_students` WHERE `student_id` = '".$id."' "; $result=mysql_query($sql); $row=mysql_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=mysql_query($sql); /*while($row=mysql_fetch_array($result)) { $data[]=$row; }*/ $row=mysql_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=mysql_query($sql); $row=mysql_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=mysql_query($sql); $row=mysql_fetch_array($result); $data=$row['section_name']; return $data; } function get_subjectslists($class_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."' and s.subject_status=1 and s.academic_year_id=".(int)$academic_id; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['subject_name']=$row['subject_name']; $data2[]=$data; } return $data2; } 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 asc"; //echo $sql; $result=mysql_query($sql); while($row=mysql_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 asc"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data['section_id']=$row['section_id']; $data['section_name']=$row['section_name']; $data2[]=$data; } return $data2; } 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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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."' "; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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_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=mysql_query($sql); if(mysql_num_rows($result)>0) { $row=mysql_fetch_array($result); $data['start_date']=$row['academic_startdate']; $data['end_date']=$row['academic_enddate']; } return $data; } function student_names($student_ids) { $sql="SELECT `student_firstname` , `student_lastname` FROM `ced_t_students` WHERE `student_id` in ('".$student_ids."') "; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data[]=$row['student_firstname']." ".$row['student_lastname']; } $names = implode(",",$data); return $names; } 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=mysql_query($sql); while($row=mysql_fetch_array($result)) { $data['subject_id']=$row['subject_id']; $data['subject_name']=$row['subject_name']; $data2[]=$data; } return $data2; } function update_attendance($id,$status,$date,$academic_id,$me) { /**************** Leave insertion by admin***************/ if($status=='L') { $query="select leave_id from ced_t_leavedetails where student_id=".(int)$id." and academic_year_id=".(int)$academic_id." and '".$date."' between leave_from and leave_to"; $execute=mysql_query($query); if(mysql_num_rows($execute)) { } else { $ins="insert into ced_t_leavedetails set leave_message='Marked by School',leave_from='".$date."',leave_to='".$date."',student_id=".(int)$id.",academic_year_id=".(int)$academic_id.",created_by='".$me."',created_on='".$date."'"; mysql_query($ins); } } if($status=='A') { $query="select absent_id from ced_t_absentdetails where student_id=".(int)$id." and academic_year_id=".(int)$academic_id." and '".$date."' between absent_from and absent_to"; $execute=mysql_query($query); if(mysql_num_rows($execute)) { } else { $ins="insert into ced_t_absentdetails set absent_reason='Marked by School',absent_from='".$date."',absent_to='".$date."',student_id=".(int)$id.",academic_year_id=".(int)$academic_id.",created_by='".$me."',created_on='".$date."'"; mysql_query($ins); } } ///////////////////////for notification $childname=$this->student_name($id); $devid=$this->parentDeviceId($id); if(date('Y-m-d')==$date) { $dt="Today"; $bto=date('Y-m-d'); } else { $dt='for '.date('d/m/Y',strtotime($date)); $bto=$date; } //////////////////////////////////end $sql2="select attendance_id from `ced_t_attendance` where student_id='".$id."' and attendance_date='".$date."' and `academic_year_id`='".$academic_id."' "; $result2=mysql_query($sql2); if(mysql_num_rows($result2)>0) { $rec=mysql_fetch_array($result2); $sql="update `ced_t_attendance` set `status`='".$status."',updated_by='$me' where attendance_id=".(int)$rec['attendance_id']; ////////////////// update or remove if leave exist with attendance status present or absent /* leave not touched for this version so commented $query="select leave_id,leave_from,leave_to from ced_t_leavedetails where student_id=".(int)$id." and academic_year_id=".(int)$academic_id." and '".$date."' between leave_from and leave_to"; $execute=mysql_query($query); if(mysql_num_rows($execute)) { $lev=mysql_fetch_array($execute); if($lev['leave_from']==$lev['leave_to'] && $lev['leave_from']==$date && $status!='L') { $updlev="delete from ced_t_leavedetails where leave_id=".(int)$lev['leave_id']; mysql_query($updlev); } else if($date > $lev['leave_from'] && $status!='L') { $updlev="update ced_t_leavedetails set leave_to='".$date."' where leave_id=".(int)$lev['leave_id']; mysql_query($updlev); } else if($lev['leave_from']==$date && $status!='L') { $updated=date('Y-m-d', strtotime('+1 day', strtotime($date))); if(date('l', strtotime($updated)) == 'Sunday') $updated=date('Y-m-d', strtotime('+2 day', strtotime($date))); if($updated <=$lev['leave_to']) $updlev="update ced_t_leavedetails set leave_from='".$updated."' where leave_id=".(int)$lev['leave_id']; else $updlev="delete from ced_t_leavedetails where leave_id=".(int)$lev['leave_id']; mysql_query($updlev); } }*/ } else { ////////////////// update or remove if leave exist with attendance status present or absent /*$query="select leave_id,leave_from,leave_to from ced_t_leavedetails where student_id=".(int)$id." and academic_year_id=".(int)$academic_id." and '".$date."' between leave_from and leave_to"; $execute=mysql_query($query); if(mysql_num_rows($execute)) { $lev=mysql_fetch_array($execute); if($lev['leave_from']==$lev['leave_to'] && $lev['leave_from']==$date && $status!='L') { $updlev="delete from ced_t_leavedetails where leave_id=".(int)$lev['leave_id']; mysql_query($updlev); } else if($date > $lev['leave_from'] && $status!='L') { $updlev="update ced_t_leavedetails set leave_to='".$date."' where leave_id=".(int)$lev['leave_id']; mysql_query($updlev); } else if($lev['leave_from']==$date && $status!='L') { $updated=date('Y-m-d', strtotime('+1 day', strtotime($date))); if(date('l', strtotime($updated)) == 'Sunday') $updated=date('Y-m-d', strtotime('+2 day', strtotime($date))); if($updated <=$lev['leave_to']) $updlev="update ced_t_leavedetails set leave_from='".$updated."'where leave_id=".(int)$lev['leave_id']; else $updlev="delete from ced_t_leavedetails where leave_id=".(int)$lev['leave_id']; mysql_query($updlev); } }*/ $sql="INSERT INTO `ced_t_attendance`( `student_id`, `attendance_date` , `status`,`academic_year_id`,`created_by`,`created_on`) VALUES ('".$id."','".$date."','".$status."','".$academic_id."','".$me."','".date('Y-m-d')."')"; } $result=mysql_query($sql); if($result) $error=1; else $error=2; if($status=='P') $message=$childname." has been marked Present ".$dt; else if($status=='A') $message=$childname." has been marked Absent ".$dt; else if($status=='L') $message=$childname." has been marked on Leave ".$dt; if(!empty($devid)) { $noteins="insert into ced_t_notifications set notify_name='".$message."',student_id=".(int)$id.",notify_type='att_status',read_status=1,general_column1='".$bto."',created_on='".date('Y-m-d')."'"; mysql_query($noteins); $nstate=$this->getNotestate($devid['authenticate_id']); if($nstate=='1' && $devid['device_id']!='') $notify=$this->send_notification($devid['device_id'],$message,$id,'att_status',date('Y-m-d'),$date); } return $error; } function parentDeviceId($id) { $rec=array(); $sql="SELECT sp.device_id,sp.authenticate_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." and account_status=1"; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); $rec['device_id']=$res['device_id']; $rec['authenticate_id']=$res['authenticate_id']; return $rec; } else return $rec; } function getNotestate($authenticate_id) { $sql="select notifications from ced_t_authentication_details where authenticate_id=".(int)$authenticate_id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); return $res['notifications']; } } 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`,`attachment` 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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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']; if($row['attachment']) { $data['attachment']=$row['attachment']; }else { $data['attachment']=""; } $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."'"; //echo $sql; $result=mysql_query($sql); $row=mysql_fetch_array($result); return $row['subject_name']; } function delete_homework_details($homework_id) { $sql="DELETE FROM `ced_t_school_diary` WHERE `School_diary_id`='".$homework_id."'"; $result=mysql_query($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=mysql_query($sql); if(mysql_num_rows($result)>0) { $sql2="UPDATE `ced_t_authentication_details` SET `password`='".$new_password."' where `email`='".$email."' "; $result2=mysql_query($sql2); if($result2) { $error=1; } else { $error=2; } } return $error; } 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 `academic_year_id`='".$academic_id."'"; $result=mysql_query($sql); if(mysql_num_rows($result)>0) $sql="UPDATE `ced_t_students_routes` SET `route_id`='".$route_id."',`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=mysql_query($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 s.`staff_name`,s.`staff_address`,s.`staff_mobile`,s.`staff_type`,sr.staff_route_id FROM `ced_t_school_staff` s inner join `ced_t_staff_routes` sr on s.`staff_id`=sr.`staff_id` where sr.`route_id`='".$route_id."' and sr.`academic_year_id`='".$academic_id."' and s.`school_id`='".$school_id."'"; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data['staff_route_id']=$row['staff_route_id']; $data['staff_name']=$row['staff_name']; switch($row['staff_type']) { case 1:$data['staff_type']='Teacher'; break; case 2:$data['staff_type']='Driver'; break; case 3:$data['staff_type']='Admin Staff'; break; case 4:$data['staff_type']='Maid'; break; case 5:$data['staff_type']='Others'; break; } $data['staff_address']=$row['staff_address']; $data['staff_mobile']=$row['staff_mobile']; $data2[]=$data; } } else { $data2=""; } return $data2; } 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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data['route_stop_id']=$row['route_stop_id']; $data['route_stop_name']=$row['route_stop_name']; $data2[]=$data; } } return $data2; } 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=mysql_query($sql); if($result) { $error=1; } else { $error=2; } return $error; } function school_students_routes($school_id,$academic_id) { $sql="SELECT `route_id`,`route_number`,`source_name`,`destination_name` FROM `ced_t_routes` WHERE `school_id`='".$school_id."' and `academic_year_id`='".$academic_id."'"; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data['route_id']=$row['route_id']; $data['route_name']=$row['route_number']." (".$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`,cr.`route_stop_id`,sr.student_route_id 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."' and s.status=1"; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data['student_route_id']=$row['student_route_id']; $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_id']=$row['route_stop_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 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=mysql_query($sql); if(mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { $data[]=$row['student_id']; } } return $data; } function delete_student_route($student_id,$academic_id) { $sql="DELETE FROM `ced_t_students_routes` WHERE `student_id`='".$student_id."' and `academic_year_id`='".$academic_id."'"; $result=mysql_query($sql); if($result) { $error=1; } else { $error=2; } return $error; } function check_my_status($schoolid) { $sql="select school_status from ced_t_school where school_id=".(int)$schoolid; $exe=mysql_query($sql); $row=mysql_fetch_array($exe); $val=$row['school_status']; $qry="select email from ced_t_authentication_details where school_id=".(int)$schoolid." and school_su=1"; $res=mysql_query($qry); if(!mysql_num_rows($res) || $val=='0') return '0'; else return $val; } //////////////////////////////////for monthly attendance get leave and absent info////////////////////////////////////////// function absentinfo($id) { $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 l.absent_id=".(int)$id; //echo $sql; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { //$data['status']="1"; $row=mysql_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 leaveinfo($id) { $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 l.leave_id=".(int)$id; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { //$data['status']="1"; $row=mysql_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 if($data['leave_type']==0) { $data['subject']="Casual"; } $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=$diff=round((abs(strtotime($data['leave_from'])-strtotime($data['leave_to']))+86400)/86400); if($row['leave_from']==$row['leave_to']) $data['no_of_days']=1; else $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 send_notification($registatoin_ids,$message,$uid,$type,$date,$today) { $msg['message']=$message; $msg['student_id']=$uid; $msg['type']=$type; $msg['date']=$date; $msg['apldate']=$today; $registatoin_ids=array($registatoin_ids); $googleapi='AIzaSyDZjnc0dm76JpZpk5mJSw_oOPgfoDSSbR0'; $url = 'https://android.googleapis.com/gcm/send'; $fields = array('registration_ids' => $registatoin_ids,'data' => $msg); $headers = array('Authorization: key='.$googleapi,'Content-Type: application/json'); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); return $result; } } ?>