JezK
Edit File: adm_operations.php
<?php date_default_timezone_set("Asia/Calcutta"); include_once("connect.php"); include_once("error_codes.php"); define('APP_LOGO_PATH','http://'.$_SERVER[HTTP_HOST].'/school/uploads/'); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\OAuth; use League\OAuth2\Client\Provider\Google; require '../composer_test/vendor/autoload.php'; class adm_operations { private $conn; function __construct() { require_once dirname(__FILE__) . '/connect.php'; // opening db connection $db = new DbConnect(); $this->conn = $db->connect(); } /*********************To Escape string quotes*********************/ function getpreventInjections($string) { $safe=mysqli_real_escape_string($this->conn,$string); return $safe; } /*********************ADMIN LOGIN AUTHENTICATION*******************/ function admin_login($user,$password) { //~ echo "coming"; //~ echo $password; $user=$this->getpreventInjections($user); $password=$this->getpreventInjections($password); //~ echo $password; $password1= $this->encrypt($password); //~ echo $password1; //~ exit; $qry="select a.*,s.school_name,s.school_status from ced_t_authentication_details a inner join ced_t_school s on a.school_id = s.school_id where email='".$user."' and password='".$password1."'"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); //~ print_r($res); $status=$res['school_status']; if($status == '0') { $response='closed'; } else if($res['school_admin_access']=='1') { $previlages="select privileges from ced_t_privileges where authentication_id=".(int)$res['authenticate_id']; $pexe=mysqli_query($this->conn,$previlages); $pres=mysqli_fetch_array($pexe); $response['me_id']=$res['authenticate_id']; $response['school_id']=$res['school_id']; $response['privileges']=$pres['privileges']; $response['school_name']=$res['school_name']; $status=$res['school_status']; $response['guest']='Admin'; $response['school_su']=1; $response['accesskey']=md5(uniqid(rand(), true)); //~ echo '<pre>'; //~ print_r($response); if($res['school_su']!='1') { $ayexist=$this->getcurrentacademicyear($res['school_id']); if($ayexist==ERR212) { return 'noay'; } else { $stf="select staff_name from ced_t_school_staff where auth_ref=".(int)$res['authenticate_id']; //~ echo $stf; $texe=mysqli_query($stf); if(mysqli_num_rows($texe)) { $tres=mysqli_fetch_array($texe); $response['guest']=$tres["staff_name"]; $response['school_su']=0; } } } else { return $response; } } else { $response='no_access'; } } else { $response=ERR202; } //~ echo $response; //~ exit; return $response; } function encrypt($string) { //~ echo 2432; $key='skoolonl!ne2o2!'; $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result.=$char; } return base64_encode($result); } function decrypt($string) { //~ echo 234; $key='skoolonl!ne2o2!'; $result=''; $string = base64_decode($string); for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)-ord($keychar)); $result.=$char; } return $result; } /*********************VERIFY THE USER WITH LICENSE KEY*******************/ function getlicenseverify($licensekey,$regon) { $licensekey=$this->getpreventInjections($licensekey); $sql="select school_id,school_name,school_email,school_license,school_phone,school_status from ced_t_school where school_license='".$licensekey."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { $emailcheck="select authenticate_id from ced_t_authentication_details where email='".$regon."' and school_su=1"; $exe1=mysqli_query($this->conn,$emailcheck); if(mysqli_num_rows($exe1)) { return 'exist'; } else { $rec=mysqli_fetch_array($exe); if($rec['school_phone']!=$regon) { $response="noentry"; return $response; } else { $response[0]=$rec['school_id']; $response[1]=$rec['school_name']; return $response; } } } else { $response="noentry"; return $response; } } /*********************GET SCHOOL DETAILS FOR SIGN UP *******************/ function regiterwithlicence($schoolid) { $check="select s.school_email,s.school_phone,c.contact_name,c.contact_number from ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$schoolid; $exe=mysqli_query($this->conn,$check); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); $record['school_email']=$res['school_email']; $record['school_phone']=$res['school_phone']; $record['contact_name']=$res['contact_name']; $record['contact_number']=$res['contact_number']; return $record; } else return ERR400; } function check_email_existance($email) { //$sql = 'SELECT `email` FROM `ced_t_authentication_details` WHERE `email` = "'.$email.'" and parent_app_access<>1'; $sql="select staff_id from ced_t_school_staff where staff_email='".$email."'"; $res = mysqli_query($this->conn,$sql); $cnt1 = mysqli_num_rows($res); $sql1="select school_email from ced_t_school where school_email='".$email."'"; $res1 = mysqli_query($this->conn,$sql1); $cnt2 = mysqli_num_rows($res1); if($cnt1==0 && $cnt2==1) return 0; else return 1; } function check_phone_exist($phone) { $qry="select school_id from ced_t_school where school_phone='".$phone."'"; $res=mysqli_query($this->conn,$qry); $cnt1=mysqli_num_rows($res); $qry1="select staff_id from ced_t_school_staff where staff_mobile='".$phone."'"; $res1=mysqli_query($this->conn,$qry1); $cnt2=mysqli_num_rows($res1); if($cnt1==1 && $cnt2==0) return 0; else return 1; } /*********************SCHOOL SIGN UP BY SCHOOL ADMIN******************/ function schoolSignUp($schid,$sch_email,$sch_password,$conpername,$contperson_phno,$phone) { $sch_password=$this->getpreventInjections($sch_password); $sch_password=$this->encrypt($sch_password); $conpername=$this->getpreventInjections($conpername); $contperson_phno=$this->getpreventInjections($contperson_phno); // update contact person info //$emailexist="select authenticate_id,email from ced_t_authentication_details where email='".$sch_email."'"; //$emltest=mysqli_query($emailexist); //$one=$this->check_email_existance($sch_email); $one=$this->check_phone_exist($phone); if(!$one) { // inserting authentication details into the table $update="update ced_t_school_contacts set contact_name='".$conpername."',contact_number='".$contperson_phno."' where school_id='".$schid."'"; $qexecute=mysqli_query($this->conn,$update); $authins="insert into ced_t_authentication_details set email='".$phone."',password='".$sch_password."',school_id='$schid',school_admin_access=1,teacher_app_access=1,created_on='".date('Y-m-d')."',created_by='0',status=1,school_su=1"; mysqli_query($this->conn,$authins); $authid=mysqli_insert_id($this->conn); $schoolactive="update ced_t_school set school_status=1, updated_by='$authid' where school_id=".(int)$schid; mysqli_query($this->conn,$schoolactive); return 'ok'; } else if($one) { return 'phone_exist'; } else { /*$row=mysqli_fetch_array($emltest); $updqry="update ced_t_authentication_details set password='".$sch_password."',school_admin_access=1,teacher_app_access=1,status=1 where authenticate_id='".$row[authenticate_id]."' and school_su=1"; mysqli_query($updqry); $schoolactive="update ced_t_school set school_status=1, updated_by='".$row[authenticate_id]."' where school_id=".(int)$schid; mysqli_query($schoolactive); return 'ok'; */ } } /*********************GET ACADEMIC DETAILS WITH ACADEMIC ID *******************/ function getAcadamicYearwithId($academic_id) { $qry="SELECT * FROM `ced_t_academicyear` WHERE academic_id=".(int)$academic_id; $exe=mysqli_query($this->conn,$qry); $res=mysqli_fetch_array($exe); $rec['academic_id']=$res['academic_id']; $rec['academic_name']=$res['academic_name']; $rec['academic_startdate']=str_replace('-','/',date('d-m-Y',strtotime($res['academic_startdate']))); $rec['academic_enddate']=str_replace('-','/',date('d-m-Y',strtotime($res['academic_enddate']))); return $rec; } /********************* ADD ACADEMIC YEAR *******************/ function addAcadamicYear($sch_id,$me,$date1,$date2) { $date1 = str_replace('/', '-', $date1); $date2 = str_replace('/', '-', $date2); $date1 = date('Y-m-d',strtotime($date1)); $date2 = date('Y-m-d',strtotime($date2)); $tdate=date('Y-m-d'); $inner1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and '".$date1."' between `academic_startdate` and `academic_enddate`"; //echo $inner1; $acd1=mysqli_query($this->conn,$inner1); $inner2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and '".$date2."' between `academic_startdate` and `academic_enddate`"; //echo $inner2; $acd2=mysqli_query($this->conn,$inner2); $outer1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and `academic_startdate` between '".$date1."' and '".$date2."'"; //echo $outer1; $pre1=mysqli_query($this->conn,$outer1); $outer2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and `academic_enddate` between '".$date1."' and '".$date2."'"; //echo $outer2; $pre2=mysqli_query($this->conn,$outer2); if(mysqli_num_rows($acd1) || mysqli_num_rows($acd2)) { return 'year1exist'; } else if(mysqli_num_rows($pre1) || mysqli_num_rows($pre2)) { return 'year2exist'; } else { if(strtotime($date1) >= strtotime($tdate) && strtotime($tdate) <= strtotime($date2)) $status=1; else $status=0; if(date('Y',strtotime($date1))==date('Y',strtotime($date2))) $acd_name=date('Y',strtotime($date1)); else $acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); //$acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); $sql="insert into ced_t_academicyear set academic_startdate='".$date1."',academic_enddate='".$date2."',school_id='".$sch_id."',academic_name='".$acd_name."',status='$status',created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $sql; //~ exit; $exe=mysqli_query($this->conn,$sql); print_r($exe); $thisid=mysqli_insert_id($this->conn); if($thisid) return $thisid; else return ERR210; } } /*********************UPDATE ACADEMIC DETAILS*******************/ function getEditAcadamicYear1($sch_id,$acd_id,$me,$date1,$date2) { $date1 = str_replace('/', '-', $date1); $date2 = str_replace('/', '-', $date2); $date1 = date('Y-m-d',strtotime($date1)); $date2 = date('Y-m-d',strtotime($date2)); $tdate=date('Y-m-d'); $inner1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date1."' between `academic_startdate` and `academic_enddate`"; $acd1=mysqli_query($this->conn,$inner1); $inner2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date2."' between `academic_startdate` and `academic_enddate`"; $acd2=mysqli_query($this->conn,$inner2); $outer1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_startdate` between '".$date1."' and '".$date2."'"; $pre1=mysqli_query($this->conn,$outer1); $outer2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_enddate` between '".$date1."' and '".$date2."'"; $pre2=mysqli_query($this->conn,$outer2); if(mysqli_num_rows($acd1) || mysqli_num_rows($acd2)) { return 'year1exist'; } else if(mysqli_num_rows($pre1) || mysqli_num_rows($pre2)) { return 'year2exist'; } else { if((strtotime($tdate) >= strtotime($date1)) && (strtotime($tdate) <= strtotime($date2))) $status=1; else $status=2; if(date('Y',strtotime($date1))==date('Y',strtotime($date2))) $acd_name=date('Y',strtotime($date1)); else $acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); $sql="update ced_t_academicyear set academic_startdate='".$date1."',academic_enddate='".$date2."',academic_name='".$acd_name."',updated_by='$me',status='$status' where academic_id='".$acd_id."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_affected_rows($this->conn)) return ERR211; else return ERR210; } } function getEditAcadamicYear($sch_id,$acd_id,$me,$date1,$date2) { $date1 = str_replace('/', '-', $date1); $date2 = str_replace('/', '-', $date2); $date1 = date('Y-m-d',strtotime($date1)); $date2 = date('Y-m-d',strtotime($date2)); $tdate = date('Y-m-d'); $timestamp = date('Y-m-d H:i:s'); $allowmodify=$this->getAcadamicYearwithId($acd_id); $pdate1=date('Y-m-d',strtotime(str_replace('/','-',$allowmodify['academic_startdate']))); $pdate2=date('Y-m-d',strtotime(str_replace('/','-',$allowmodify['academic_enddate']))); $res=$this->recordexistcheckforacademicyear($acd_id); $cur_acd=$this->getcurrentacademicyear($sch_id); if($cur_acd!=ERR212) { $academic_id=$cur_acd['academic_id']; $cur_academic_year=$this->getAcadamicYearwithId($academic_id); $cdate1=date('Y-m-d',strtotime(str_replace('/','-',$cur_academic_year['academic_startdate']))); $cdate2=date('Y-m-d',strtotime(str_replace('/','-',$cur_academic_year['academic_enddate']))); } else { $academic_id=0; $cdate1=date('Y-m-d'); $cdate2=date('Y-m-d'); } if((int)$acd_id==(int)$academic_id && $res=='cannot' && $pdate1!=$date1) // current AY Negative { return 'not2change'; } else if((int)$acd_id==(int)$academic_id && $res=='cannot' && $pdate1==$date1 && $date2>$tdate) // current AY change end date only { //return 'change_end_date'; $inner1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date1."' between `academic_startdate` and `academic_enddate`"; $acd1=mysqli_query($this->conn,$inner1); $inner2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date2."' between `academic_startdate` and `academic_enddate`"; $acd2=mysqli_query($this->conn,$inner2); $outer1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_startdate` between '".$date1."' and '".$date2."'"; $pre1=mysqli_query($this->conn,$outer1); $outer2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_enddate` between '".$date1."' and '".$date2."'"; $pre2=mysqli_query($this->conn,$outer2); if(mysqli_num_rows($acd1) || mysqli_num_rows($acd2)) { return 'year1exist'; } else if(mysqli_num_rows($pre1) || mysqli_num_rows($pre2)) { return 'year2exist'; } else { if((strtotime($tdate) >= strtotime($date1)) && (strtotime($tdate) <= strtotime($date2))) $status=1; else $status=2; if(date('Y',strtotime($date1))==date('Y',strtotime($date2))) $acd_name=date('Y',strtotime($date1)); else $acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); $sql="update ced_t_academicyear set academic_enddate='".$date2."',academic_name='".$acd_name."',updated_by='$me',updated_on='$timestamp',status='$status' where academic_id='".$acd_id."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_affected_rows($this->conn)) return ERR211; else return ERR210; } } else if((int)$acd_id!=(int)$academic_id && $res=='cannot' && $date2<=$cdate1) // Past AY Negative { return 'past_not_allow'; } else if((int)$acd_id!=(int)$academic_id && $res=='can' && $date2<=$cdate1) // Past AY Positive { //return 'past_allow'; $inner1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date1."' between `academic_startdate` and `academic_enddate`"; $acd1=mysqli_query($this->conn,$inner1); $inner2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date2."' between `academic_startdate` and `academic_enddate`"; $acd2=mysqli_query($this->conn,$inner2); $outer1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_startdate` between '".$date1."' and '".$date2."'"; $pre1=mysqli_query($this->conn,$outer1); $outer2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_enddate` between '".$date1."' and '".$date2."'"; $pre2=mysqli_query($this->conn,$outer2); if(mysqli_num_rows($acd1) || mysqli_num_rows($acd2)) { return 'year1exist'; } else if(mysqli_num_rows($pre1) || mysqli_num_rows($pre2)) { return 'year2exist'; } else { if((strtotime($tdate) >= strtotime($date1)) && (strtotime($tdate) <= strtotime($date2))) $status=1; else $status=2; if(date('Y',strtotime($date1))==date('Y',strtotime($date2))) $acd_name=date('Y',strtotime($date1)); else $acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); $sql="update ced_t_academicyear set academic_startdate='".$date1."',academic_enddate='".$date2."',academic_name='".$acd_name."',updated_by='$me',updated_on='$timestamp',status='$status' where academic_id='".$acd_id."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_affected_rows($this->conn)) return ERR211; else return ERR210; } } else if((int)$acd_id!=(int)$academic_id && $date1>$cdate2) // future allow { $inner1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date1."' between `academic_startdate` and `academic_enddate`"; $acd1=mysqli_query($this->conn,$inner1); $inner2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date2."' between `academic_startdate` and `academic_enddate`"; $acd2=mysqli_query($this->conn,$inner2); $outer1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_startdate` between '".$date1."' and '".$date2."'"; $pre1=mysqli_query($this->conn,$outer1); $outer2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_enddate` between '".$date1."' and '".$date2."'"; $pre2=mysqli_query($this->conn,$outer2); if(mysqli_num_rows($acd1) || mysqli_num_rows($acd2)) { return 'year1exist'; } else if(mysqli_num_rows($pre1) || mysqli_num_rows($pre2)) { return 'year2exist'; } else { if((strtotime($tdate) >= strtotime($date1)) && (strtotime($tdate) <= strtotime($date2))) $status=1; else $status=2; if(date('Y',strtotime($date1))==date('Y',strtotime($date2))) $acd_name=date('Y',strtotime($date1)); else $acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); $sql="update ced_t_academicyear set academic_startdate='".$date1."',academic_enddate='".$date2."',academic_name='".$acd_name."',updated_by='$me',updated_on='$timestamp',status='$status' where academic_id='".$acd_id."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_affected_rows($this->conn)) return ERR211; else return ERR210; } } else if((int)$acd_id!=(int)$academic_id && $res=='cannot' && $date2 >= $cdate1) // Past AY Negative { return 'past_not_allow'; } else if((int)$acd_id==(int)$academic_id && $res=='cannot' && $pdate1==$date1 && $date2<$tdate) { return 'end_not_allow'; } else { $inner1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date1."' between `academic_startdate` and `academic_enddate`"; $acd1=mysqli_query($this->conn,$inner1); $inner2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and '".$date2."' between `academic_startdate` and `academic_enddate`"; $acd2=mysqli_query($this->conn,$inner2); $outer1="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_startdate` between '".$date1."' and '".$date2."'"; $pre1=mysqli_query($this->conn,$outer1); $outer2="SELECT * FROM `ced_t_academicyear` WHERE school_id='$sch_id' and academic_id<>'$acd_id' and `academic_enddate` between '".$date1."' and '".$date2."'"; $pre2=mysqli_query($this->conn,$outer2); if(mysqli_num_rows($acd1) || mysqli_num_rows($acd2)) { return 'year1exist'; } else if(mysqli_num_rows($pre1) || mysqli_num_rows($pre2)) { return 'year2exist'; } else { if((strtotime($tdate) >= strtotime($date1)) && (strtotime($tdate) <= strtotime($date2))) $status=1; else $status=2; if(date('Y',strtotime($date1))==date('Y',strtotime($date2))) $acd_name=date('Y',strtotime($date1)); else $acd_name=date('Y',strtotime($date1)).'-'.date('y',strtotime($date2)); $sql="update ced_t_academicyear set academic_startdate='".$date1."',academic_enddate='".$date2."',academic_name='".$acd_name."',updated_by='$me',updated_on='$timestamp',status='$status' where academic_id='".$acd_id."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_affected_rows($this->conn)) return ERR211; else return ERR210; } } } /*********************GET CURRENT ACADEMIC DETAILS OF A SCHOOL WITH SCHOOL ID*******************/ function getcurrentacademicyear($sch_id) { $cur_date=date('Y-m-d'); $sql="select academic_id,academic_name from ced_t_academicyear where `academic_startdate`<='$cur_date' and `academic_enddate`>='$cur_date' and school_id=".(int)$sch_id; //~ echo $sql; $exeyear=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exeyear)) { $res=mysqli_fetch_array($exeyear); $rec['academic_id']=$res['academic_id']; $rec['academic_name']=$res['academic_name']; return $rec; } else return ERR212; } /*********************GET ACADEMIC DETAILS WITH ACADEMIC ID*******************/ function getacademicyearNameByacademicId($acdid) { $sql="select academic_id,academic_name from ced_t_academicyear where academic_id=".(int)$acdid; $exeyear=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exeyear)) { $res=mysqli_fetch_array($exeyear); $rec['academic_id']=$res['academic_id']; $rec['academic_name']=$res['academic_name']; return $rec; } else return ERR212; } function chosenislessthannow($acdid) { $sql="select academic_startdate,academic_enddate from ced_t_academicyear where academic_id=".(int)$acdid; $exe=mysqli_query($sql); $res=mysqli_fetch_array($this->conn,$exe); $d2=date('Y-m-d'); $d1=$res['academic_startdate']; if($d2>=$d1) return 'yes'; else return 'no'; } /*********************GET ALL ACADEMIC YEARS OF A SCHOOL*******************/ function getAllAcademicYearsofme($schoolid) { $qry="select * from ced_t_academicyear where school_id='".$schoolid."' order by academic_startdate"; //~ echo $qry; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_assoc($exe)) { $row[]=$res; } //print_r($row); return $row; } else return ERR213; } function recordexistcheckforacademicyear($academic_id) { $qry="select class_id from ced_t_class where academic_year_id=".(int)$academic_id; //~ echo $qry; $exe=mysqli_query($this->conn,$qry); $qry1="select subject_id from ced_t_subjects where academic_year_id=".(int)$academic_id; //~ echo $qry1; $exe1=mysqli_query($this->conn,$qry1); $qry2="select exam_id from ced_t_exam_names where academic_year_id=".(int)$academic_id; //~ echo $qry2; $exe2=mysqli_query($this->conn,$qry2); $qry3="select student_id from ced_t_students where academic_year_id=".(int)$academic_id; //~ echo $qry3; $exe3=mysqli_query($this->conn,$qry3); $qry4="select staff_id from ced_t_school_staff where academic_year_id=".(int)$academic_id; //~ echo $qry4; $exe4=mysqli_query($this->conn,$qry4); $qry5="select route_id from ced_t_routes where academic_year_id=".(int)$academic_id; //~ echo $qry5; $exe5=mysqli_query($this->conn,$qry5); if(mysqli_num_rows($exe) || mysqli_num_rows($exe1) || mysqli_num_rows($exe2) || mysqli_num_rows($exe3) || mysqli_num_rows($exe4)) return "cannot"; else return "can"; } /*********************DELETE ACADEMIC YEAR WITH ACADEMIC ID*******************/ function deleteacademicyear($academic_id) { $qry="select class_id from ced_t_class where academic_year_id=".(int)$academic_id; $exe=mysqli_query($this->conn,$qry); $qry1="select subject_id from ced_t_subjects where academic_year_id=".(int)$academic_id; $exe1=mysqli_query($this->conn,$qry1); $qry2="select exam_id from ced_t_exam_names where academic_year_id=".(int)$academic_id; $exe2=mysqli_query($this->conn,$qry2); $qry3="select student_id from ced_t_students where academic_year_id=".(int)$academic_id; $exe3=mysqli_query($this->conn,$qry3); $qry4="select staff_id from ced_t_school_staff where academic_year_id=".(int)$academic_id; $exe4=mysqli_query($this->conn,$qry4); $qry5="select student_fee_id from ced_t_student_fee where academic_year_id=".(int)$academic_id; $exe5=mysqli_query($this->conn,$qry5); $qry6="select route_id from ced_t_routes where academic_year_id=".(int)$academic_id; $exe6=mysqli_query($this->conn,$qry6); $qry7="select attendance_id from ced_t_attendance where academic_year_id=".(int)$academic_id; $exe7=mysqli_query($this->conn,$qry7); $qry8="select School_diary_id from ced_t_school_diary where academic_year_id=".(int)$academic_id; $exe8=mysqli_query($this->conn,$qry8); //$qry9="select route_id from ced_t_routes where academic_year_id=".(int)$academic_id; //$exe9=mysqli_query($qry9); if(mysqli_num_rows($exe) || mysqli_num_rows($exe1) || mysqli_num_rows($exe2) || mysqli_num_rows($exe3) || mysqli_num_rows($exe4) || mysqli_num_rows($exe5) || mysqli_num_rows($exe6) || mysqli_num_rows($exe7) || mysqli_num_rows($exe8)) return "cannot"; else { $delete="delete from ced_t_academicyear where academic_id=".(int)$academic_id; mysqli_query($this->conn,$delete); return "deleted"; } } /*********************GET ALL TEACHERS OF A SCHOOL WITH SCHOOL ID*******************/ function getallmyschoolteachers($schoolid,$acdid) { $qry="select staff_id,staff_name,staff_email,staff_mobile,status,auth_ref from ced_t_school_staff where academic_year_id='$acdid' and school_id=".(int)$schoolid." and staff_type=1 order by staff_id desc"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_assoc($exe)) $row[]=$res; return $row; } else return 'notfound'; } function getschooldetailsforteachermail($schoolid) { $qry="select school_name,school_email,school_phone from ced_t_school where school_id=".(int)$schoolid; $exe=mysqli_query($this->conn,$qry); $res=mysqli_fetch_array($exe); $row['school_name']=$res['school_name']; $row['school_email']=$res['school_email']; $row['school_phone']=$res['school_phone']; return $row; } /********************* ADD TEACHER TO A SCHOOL *******************/ function add_teacher_to_school($me,$sch_id,$tname,$tmobile,$temail,$taddress,$tdob,$acdid,$tapp) { $tname=$this->getpreventInjections($tname); $tmobile=$this->getpreventInjections($tmobile); $temail=$this->getpreventInjections($temail); $taddress=$this->getpreventInjections($taddress); $tdob=str_replace('/','-',$tdob); $tdob=date('Y-m-d',strtotime($tdob)); $refid=0; $logincheck="select school_id from ced_t_school where school_phone='".$tmobile."'"; $lexe=mysqli_query($this->conn,$logincheck); $check="select staff_id from ced_t_school_staff where staff_mobile='".$tmobile."'";//and academic_year_id='$acdid'"; $exe=mysqli_query($this->conn,$check); if(mysqli_num_rows($lexe) || mysqli_num_rows($exe)) //if(mysqli_num_rows($lexe)) { return 101; } else { if($tapp==1) { $mailsent=1; $pass=rand(100001,999999); $passe=$this->encrypt($pass); //$auth_ins="insert into ced_t_authentication_details set email='".$temail."',password='".$passe."',teacher_app_access='$tapp',school_id='$sch_id',status=1,created_by='$me',created_on='".date('Y-m-d')."'"; $auth_ins="insert into ced_t_authentication_details set email='".$tmobile."',password='".$passe."',teacher_app_access='$tapp',school_id='$sch_id',status=1,created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $auth_ins; mysqli_query($this->conn,$auth_ins); $refid=mysqli_insert_id($this->conn); } else $mailsent=0; $ins="insert into ced_t_school_staff set staff_name='".$tname."',staff_email='".$temail."',staff_mobile='".$tmobile."',staff_address='".$taddress."',date_of_birth='".$tdob."',created_on='".date('Y-m-d')."',created_by='$me',school_id='$sch_id',academic_year_id='$acdid',status='1',staff_type='1',auth_ref='$refid',mail_sent='$mailsent'"; //~ echo $ins; $qexe=mysqli_query($this->conn,$ins); $refid22=mysqli_insert_id($this->conn); if(mysqli_insert_id($this->conn)) { //~ echo 123; if($tapp==1) $this->sendteacherappaccessmail($tname,$sch_id,$temail,$pass,$tmobile); return $refid22; } else return 101; } } function uploadmypic($id,$file) { $qry="update ced_t_school_staff set staff_pic='".$file."' where staff_id=".(int)$id; mysqli_query($this->conn,$qry); } function sendteacherappaccessmail($tname,$schid,$temail,$pwd,$mobile) { $appdetails=$this->gettingAppDetails(); $detls=$this->getschooldetailsforteachermail($schid); $message='<p>Dear '.$tname.',</p> <p>Welcome!!<br> You have been successfully registered for '.$appdetails['app_name'].' mobile services provided by '.$detls[school_name].'. </p> <p>Your login credentials to access the '.$appdetails['app_name'].' Teacher App are as follows:<br> <b>Username:</b> '.$mobile.' <br> <b>Password: </b>'.$pwd.'</p> <p>If you have any questions related to your account / services, you can email us at '.$detls[school_email].' or call us on '.$detls[school_phone].'. For any technical assistance related to the mobile app, you can reach out to '.$appdetails['support_mail'].'.</p> <p>Thanking you for registering for the mobile services</p> <p> Best Regards,<br> '.$detls[school_name].'</p>'; $subject=$appdetails['app_name'] ." Teacher App Access for ".$detls[school_name]; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From: ".$appdetails['app_name']." <".$appdetails['sender_mail'].">"; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=$this->mail_send($temail,$subject,$message); $message_sms="Dear Teacher, Your login credentials to access the Skoolonline Teacher App are as follows: Username: ".$mobile.", Password: ".$pwd."; www.skoolonline.in"; //echo $link="http://180.149.242.74/unified.php?usr=dharani@krify.net&pwd=dksmr555&ph=".$mobile."&sndr=SKLONL&text=".urlencode($message_sms); //exit; $send_msg=file_get_contents("http://180.149.242.74/unified.php?usr=dharani@krify.net&pwd=dksmr555&ph=".$mobile."&sndr=SKLONL&text=".urlencode($message_sms)); } function send_driver_appaccessmail($tname,$schid,$temail,$pwd,$mobile) { $appdetails=$this->gettingAppDetails(); $detls=$this->getschooldetailsforteachermail($schid); $message='<p>Dear '.$tname.',</p> <p>Welcome!!<br> You have been successfully registered for '.$appdetails['app_name'].' mobile services provided by '.$detls[school_name].'. </p> <p>Your login credentials to access the '.$appdetails['app_name'].' Driver App are as follows:<br> <b>Username:</b> '.$mobile.' <br> <b>Password:</b> '.$pwd.'</p> <p>If you have any questions related to your account / services, you can email us at '.$detls[school_email].' or call us on '.$detls[school_phone].'. For any technical assistance related to the mobile app, you can reach out to '.$appdetails['support_mail'].'.</p> <p>Thanking you for registering for the mobile services</p> <p> Best Regards,<br> '.$detls[school_name].'</p>'; $subject= $appdetails['app_name']." Driver App Access for ".$detls[school_name]; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From: ".$appdetails['app_name']." <".$appdetails['sender_mail'].">"; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=$this->mail_send($temail,$subject,$message); $message_sms="Dear Staff, Your login credentials to access the Skoolonline Driver App are as follows: Username: ".$mobile.", Password: ".$pwd."; www.skoolonline.in"; $send_msg=file_get_contents("http://180.149.242.74/unified.php?usr=dharani@krify.net&pwd=dksmr555&ph=".$mobile."&sndr=SKLONL&text=".urlencode($message_sms)); } function send_admin_portal_access_mail($tname,$schid,$temail,$pwd,$privileges,$mobile) { $appdetails=$this->gettingAppDetails(); $detls=$this->getschooldetailsforteachermail($schid); $message='<p>Dear '.$tname.',</p> <p>Welcome!!<br> You have been successfully registered for '.$appdetails['app_name'].' School Admin Portal for '.$detls['school_name'].'. </p> <p>You can access the '.$appdetails['app_name'].' School Admin Portal by clicking <a href="'.ADMIN_PATH.'">here</a>. Your login credentials to access the '.$appdetails['app_name'].' School Admin Portal are as follows:<br> Username: '.$mobile.' <br> Password: '.$pwd.'</p> <p>You have been granted the following privileges under '.$appdetails['app_name'].' School Admin Portal:</p> <ul>'.$privileges.'</ul> <p>If you have any questions related to your account / services, you can email us at '.$detls[school_email].' or call us on '.$detls['school_phone'].'. For any technical assistance related to the web services, you can reach out to '.$appdetails['support_mail'].'.</p> <p>Thanking you</p> <p> Best Regards,<br> '.$detls['school_name'].'</p>'; $subject=$appdetails['app_name']." School Admin Portal Access for ".$detls['school_name']; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From: ".$appdetails['app_name']." <".$appdetails['sender_mail'].">"; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=$this->mail_send($temail,$subject,$message); } /*********************UPDATE TEACHER DETAILS*******************/ function edit_teacher_in_school($me,$sch_id,$teacherid,$tname,$tmobile,$temail,$taddress,$tdob,$tapp,$bfore,$acdid,$files) { $tname=$this->getpreventInjections($tname); $tmobile=$this->getpreventInjections($tmobile); $temail=$this->getpreventInjections($temail); $taddress=$this->getpreventInjections($taddress); $tdob=str_replace('/','-',$tdob); $tdob=date('Y-m-d',strtotime($tdob)); //$check="select staff_id,auth_ref,mail_sent from ced_t_school_staff where staff_email='".$temail."' and staff_id=".(int)$teacherid; $check="select staff_id,auth_ref,mail_sent from ced_t_school_staff where staff_id=".(int)$teacherid; $exe=mysqli_query($this->conn,$check); $aut=mysqli_fetch_array($exe); $stafcheck="select staff_id from ced_t_school_staff where staff_mobile='".$tmobile."' and staff_id<>".(int)$teacherid; //~ echo $stafcheck; //and academic_year_id='$acdid' $stexe=mysqli_query($this->conn,$stafcheck); //$logincheck="select email from ced_t_authentication_details where email='".$tmobile."' and authenticate_id<>".(int)$aut['auth_ref']; $logincheck="select school_phone from ced_t_school where school_phone='".$tmobile."'"; //school_id<>.(int)$sch_id //~ echo $logincheck; $lexe=mysqli_query($this->conn,$logincheck); if(mysqli_num_rows($lexe) || mysqli_num_rows($stexe)) { return '101'; } else { $pass=rand(100001,9999999); $passe=$this->encrypt($pass); if($aut['mail_sent']==0 && $tapp==1 && $aut['auth_ref']==0) { $updauth="insert into ced_t_authentication_details set email='".$tmobile."',password='".$passe."',teacher_app_access='$tapp',school_id='$sch_id',status=1,created_by='$me',created_on='".date('Y-m-d')."',notifications=1"; //~ echo $updauth; mysqli_query($this->conn,$updauth); $authref=mysqli_insert_id($this->conn); $upd="update ced_t_school_staff set staff_name='".$tname."',staff_email='".$temail."',staff_mobile='".$tmobile."',date_of_birth='".$tdob."',staff_address='".$taddress."',mail_sent=1,academic_year_id='$acdid',auth_ref='$authref',updated_by='$me' where staff_id='".$teacherid."'"; $qexe=mysqli_query($this->conn,$upd); $this->sendteacherappaccessmail($tname,$sch_id,$temail,$pass,$tmobile); } else if($tapp==0 || $tapp==1) { if($files!='') { $picupd="update ced_t_school_staff set staff_pic='".$files."' where staff_id=".(int)$teacherid; mysqli_query($this->conn,$picupd); } $upd="update ced_t_school_staff set staff_name='".$tname."',staff_email='".$temail."',staff_mobile='".$tmobile."',date_of_birth='".$tdob."',staff_address='".$taddress."',academic_year_id='$acdid',updated_by='$me' where staff_id='".$teacherid."'"; $qexe=mysqli_query($upd); $updauth="update ced_t_authentication_details set email='".$tmobile."',teacher_app_access='$tapp' where authenticate_id=".(int)$aut['auth_ref']; mysqli_query($this->conn,$updauth); } return '100'; } } /*********************ADMIN LOGIN AUTHENTICATION*******************/ function get_teacher_details($teacherid) { $qry="select staff_id,staff_name,staff_email,staff_mobile,staff_address,date_of_birth,auth_ref,staff_pic from ced_t_school_staff where staff_id=".(int)$teacherid; $exe=mysqli_query($this->conn,$qry); $row=mysqli_fetch_array($exe); $rec['staff_id']=$row['staff_id']; $rec['staff_name']=$row['staff_name']; $rec['staff_email']=$row['staff_email']; $rec['staff_mobile']=$row['staff_mobile']; $rec['staff_address']=$row['staff_address']; $rec['staff_pic']=$row['staff_pic']; $rec['date_of_birth']=date('d/m/Y',strtotime(str_replace('-','/',$row['date_of_birth']))); $rec['access_status']=$this->getthisuseraccessstatus($row['auth_ref']); return $rec; } function getthisuseraccessstatus($auth_ref) { $qry="select teacher_app_access from ced_t_authentication_details where authenticate_id=".(int)$auth_ref; $exe=mysqli_query($this->conn,$qry); $res=mysqli_fetch_array($exe); return $res['teacher_app_access']; } /*********************ACTIVE/DEACTIVE THE TEACHER *******************/ function deactivate_teacher_in_School($teachid,$status) { $sql="select auth_ref from ced_t_school_staff where staff_id=".(int)$teachid; $execute=mysqli_query($this->conn,$sql); $rec=mysqli_fetch_array($execute); $status=$this->getpreventInjections($status); if($status=='1') { $sts=2; $app=0; $query="update ced_t_authentication_details set school_admin_access='$app',teacher_app_access='$app' where authenticate_id=".(int)$rec['auth_ref']; mysqli_query($this->conn,$query); } if($status=='2') { $sts=1; } $qry="update ced_t_school_staff set status='$sts' where staff_id=".(int)$teachid; $exe=mysqli_query($this->conn,$qry); if(mysqli_affected_rows($this->conn)) return '100'; else return '101'; } /********************* GET ALL SECTION NAMES BY CLASS ID*******************/ function getallsectionbyclassID($class_id) { $query="select section_name from ced_t_sections where class_id=".(int)$class_id." order by section_id"; $exe=mysqli_query($this->conn,$query); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) $row[]=$res['section_name']; $sections=implode(',',$row); return $sections; } else { return '--'; } } /********************* GET ALL SECTIONS DETAILS BY CLASS ID*******************/ function getallsectionsdetailsbyclassId($class_id) { $query="select section_id,section_name from ced_t_sections where class_id=".(int)$class_id; $exe=mysqli_query($this->conn,$query); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_assoc($exe)) $row[]=$res; return $row; } else return '0'; } /*********************GET ALL CLASSES *******************/ function getallClassesforOrder($schoolid,$acdid) { $qry="select class_id,class_category_id,class_name,class_order,junior_status from ced_t_class where academic_year_id='$acdid' and school_id=".(int)$schoolid." order by class_order"; //~ echo $qry; //~ exit; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_assoc($exe)) $row[]=$res; //~ print_r($row); return $row; } else return '0'; } /*********************GET ALL PREVIOUS CLASSES IN ORDER*******************/ function getallpreviousClasses($schid,$acdid) { $qry="select cl.class_id,cl.class_name,c.class_category_name from ced_t_class cl inner join ced_t_class_categories c on cl.class_category_id=c.class_category_id where school_id='".$schid."' and academic_year_id='".$acdid."' order by cl.class_order asc"; //echo $qry; //~ exit; $exe=mysqli_query($this->conn,$qry); //~ echo mysqli_num_rows($exe); //~ exit; if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { $row['class_id']=$res['class_id']; $row['class_name']=$res['class_name']; $row['cat_name']=$res['class_category_name']; $row['sections']=$this->getallsectionbyclassID($res['class_id']); $records[]=$row; } return $records; } else { return '0'; } } /********************* ADD JUNIOR MOST CLASS OVER TIME*******************/ function addjuniorclassandsection($me,$schid,$category,$classname,$sections,$acdid) { $classname=$this->getpreventInjections($classname); $classname=ucwords($this->conn,$classname); $sql="select class_name from ced_t_class where class_name='".$classname."' and school_id='".$schid."' and academic_year_id=".(int)$acdid; $res=mysqli_query($sql); $num=mysqli_num_rows($res); if($num>0) { return '102'; //class name already exists } else { $clsins="insert into ced_t_class set class_name='".$classname."',class_category_id='".$category."',school_id='".$schid."',class_order='1',junior_status='1',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; $execute=mysqli_query($this->conn,$clsins); $clsid=mysqli_insert_id($this->conn); if(count($sections)>0) { foreach($sections as $secname) { $secins="insert into ced_t_sections set section_name='".ucwords($secname)."',class_id='".$clsid."',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; mysqli_query($secins); } } //foreach($sections) //$sql="select * from ced_t_class where school_id=".(int)$schid." and academic_year_id=".(int)$acdid; $sql="select * from ced_t_class where school_id=".(int)$schid; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { if($res['junior_status']=='1') { $count=1; $lowest=$res['class_id']; } } if($count=='1') { $sql1="select * from ced_t_class where school_id=".(int)$schid; //$sql1="select * from ced_t_class where school_id=".(int)$schid." and academic_year_id=".(int)$acdid; $exe1=mysqli_query($this->conn,$sql1); while($order=mysqli_fetch_array($exe1)) { if($order['class_id']!=$clsid) { $curorder=$order['class_order']+1; $reorder="update ced_t_class set class_order='".$curorder."',updated_by='$me',junior_status=0 where class_id='".$order['class_id']."'"; mysqli_query($reorder); } } } } return '100'; } } /********************* ADD NEW CLASS TO A SCHOOL WHICH SUPPORT JUNIOR MOST AS WELL FOR THE FIRST TIME*******************/ function addclassandsection($me,$schid,$category,$prevclass,$classname,$sections,$junior,$acdid) { $classname=$this->getpreventInjections($classname); $classname=ucwords(strtolower($classname)); if($junior == '1') { $sql="select class_name from ced_t_class where class_name='".$classname."' and school_id='".$schid."' and academic_year_id=".(int)$acdid; //~ echo $sql; //~ exit; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num > 0) { return '102'; //class name already exists } else { $clsins="insert into ced_t_class set class_name='".$classname."',class_category_id='".$category."',school_id='".$schid."',class_order='1',junior_status='1',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $clsins; //~ exit; $execute=mysqli_query($this->conn,$clsins); $clsid=mysqli_insert_id($this->conn); if(count($sections)>0) { foreach($sections as $secname) { $secins="insert into ced_t_sections set section_name='".ucwords(strtolower($secname))."',class_id='".$clsid."',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $secins; //~ exit; mysqli_query($this->conn,$secins); } } //foreach($sections) $sql="select * from ced_t_class where academic_year_id='$acdid' and school_id=".(int)$schid; //~ echo $sql; //~ exit; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { if($res['junior_status']=='1') { $count=1; $lowest=$res['class_id']; } } if($count=='1') { $sql1="select * from ced_t_class where academic_year_id='$acdid' and school_id=".(int)$schid; //~ echo $sql1; //~ exit; $exe1=mysqli_query($this->conn,$sql1); while($order=mysqli_fetch_array($exe1)) { echo $order['class_id']; //~ echo $clsid; //~ exit; if($order['class_id']!=$clsid) { $curorder=$order['class_order']+1; $reorder="update ced_t_class set class_order='".$curorder."',updated_by='$me',junior_status=0 where class_id='".$order['class_id']."'"; mysqli_query($this->conn,$reorder); } } } } return '100'; } } else { if($prevclass!=0) { $prevclass=$this->getclassorderid($prevclass); $prevclass=$prevclass + 1; //~ echo $prevclass; } else { $prevclass=1; } $sql="select class_name from ced_t_class where class_name='".$classname."' and school_id='".$schid."' and academic_year_id='$acdid'"; //~ echo $sql; //~ exit; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num>0) { return '102'; //class name already exists } else { $derive="select class_order from ced_t_class where school_id=".(int)$schid." and class_order='$prevclass' and academic_year_id='$acdid'"; //~ echo $derive;exit; $dexe=mysqli_query($this->conn,$derive); if(!mysqli_num_rows($dexe)) { $clsins="insert into ced_t_class set class_name='".$classname."',class_category_id='".$category."',school_id='".$schid."',class_order='".$prevclass."',junior_status='0',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $clsins; //~ exit; $execute=mysqli_query($this->conn,$clsins); $clsid=mysqli_insert_id($this->conn); if(count($sections) > 0) { foreach($sections as $secname) { $secins="insert into ced_t_sections set section_name='".ucwords(strtolower($secname))."',class_id='".$clsid."',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $secins; //~ exit; mysqli_query($this->conn,$secins); } } return '100'; // success } else return '103'; // If same class is parent to some other } } } /********************* GET THE CLASS POSITION (ORDER) IN THE CLASS LIST*******************/ function getclassorderid($prevclass) { $qry="select class_order from ced_t_class where class_id=".(int)$prevclass; //~ echo $qry; //~ exit; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); //~ print_r($res); //~ exit; } //~ print_r( $res['class_order']); //~ exit; return $res['class_order']; } /********************* GET CLASS DETAILS BY CLASS ID*******************/ function getClassDetailsByID($clsid) { $qry="select class_id,class_name,class_category_id,school_id,class_order,junior_status,academic_year_id from ced_t_class where class_id='".$clsid."'"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)); { $res=mysqli_fetch_array($exe); $rec['class_name']=$res['class_name']; $rec['class_id']=$res['class_id']; $rec['class_cat_id']=$res['class_category_id']; $rec['class_order']=$this->getprevClassId($res['school_id'],$res['class_order'],$res['academic_year_id']); $rec['junior_status']=$res['junior_status']; $rec['sch_id']=$res['school_id']; } $qry2="select section_id,section_name from ced_t_sections where class_id='".$clsid."' order by section_id"; $exe2=mysqli_query($this->conn,$qry2); while($result=mysqli_fetch_array($exe2)) { $r['sec_id']=$result['section_id']; $r['sec_name']=$result['section_name']; $re[]=$r; } $rec['sections']=$re; return $rec; } /********************* GET PREVIOUS CLASS ID WITH CURRENT CLASS ORDER ID*******************/ function getprevClassId($schid,$clsorder,$acdid) { if($clsorder==1) $clsorder=1; else $clsorder=$clsorder-1; $qry="select class_id,class_name from ced_t_class where school_id='".$schid."' and class_order='".$clsorder."' and academic_year_id='$acdid'"; $exe=mysqli_query($this->conn,$qry); $res=mysqli_fetch_array($exe); return $res['class_id']; } /********************* EDIT CLASS AND SECTIONS *******************/ function editclassandsection($me,$clsid,$schid,$category,$prevclass,$classname,$sections,$sectionids,$junior,$acdid,$removethem) { $classname=$this->getpreventInjections($classname); $classname=ucwords(strtolower($classname)); //$sections=$this->getpreventInjections($sections); if($junior=='1') // If this class is junior most other wise else condition { $sql="select class_name from ced_t_class where class_name='".$classname."' and school_id='".$schid."' and academic_year_id='$acdid' and class_id<>".(int)$clsid; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num>0) { return '102'; //class name already exists } else { $clsins="update ced_t_class set class_name='".$classname."',class_category_id='".$category."',school_id='".$schid."',updated_by='$me' where class_id='".$clsid."'"; $execute=mysqli_query($this->conn,$clsins); //$clsid=mysqli_insert_id(); if(count($sections)>0) { $i=0; foreach($sections as $secname) { $exist="select * from ced_t_sections where section_id='".$sectionids[$i]."' and academic_year_id='$acdid'"; $result_exist=mysqli_query($this->conn,$exist); if(mysqli_num_rows($result_exist)) { $secins="update ced_t_sections set section_name='".ucwords(strtolower($secname))."',class_id='".$clsid."' where section_id='".$sectionids[$i]."'"; mysqli_query($secins); } else { $secins="insert into ced_t_sections set section_name='".ucwords(strtolower($secname))."',class_id='".$clsid."',created_by='$me',academic_year_id='$acdid',created_on='".date('Y-m-d')."'"; mysqli_query($this->conn,$secins); } $i++; } $rmds=explode('_',trim($removethem,'_')); foreach($rmds as $subj) $x=$this->deletethisSection($subj); } } return '100';// success } else { if($prevclass!=0) { $prevclass=$this->getclassorderid($prevclass); $prevclass=$prevclass+1; } else $prevclass=1; $sql="select class_name from ced_t_class where class_name='".$classname."' and school_id='".$schid."' and academic_year_id='$acdid' and class_id<>".(int)$clsid; //~ echo $sql; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num>0) { return '102'; //class name already exists } else { $derive="select class_order from ced_t_class where school_id=".(int)$schid." and academic_year_id='$acdid' and class_order='$prevclass' and class_id<>".(int)$clsid; $dexe=mysqli_query($this->conn,$derive); if(!mysqli_num_rows($dexe)) { $clsins="update ced_t_class set class_name='".$classname."',class_category_id='".$category."',school_id='".$schid."',class_order='".$prevclass."',updated_by='$me',academic_year_id='$acdid' where class_id='".$clsid."'"; $execute=mysqli_query($this->conn,$clsins); if(count($sections)>0) { $i=0; foreach($sections as $secname) { $exist="select * from ced_t_sections where section_id='".$sectionids[$i]."'"; $result_exist=mysqli_query($this->conn,$exist); if(mysqli_num_rows($result_exist)) { $secins="update ced_t_sections set section_name='".ucwords(strtolower($secname))."',class_id='".$clsid."' where section_id='".$sectionids[$i]."'"; mysqli_query($secins); } else { $secins="insert into ced_t_sections set section_name='".ucwords(strtolower($secname))."',class_id='".$clsid."',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; mysqli_query($this->conn,$secins); } $i++; } $rmds=explode('_',trim($removethem,'_')); foreach($rmds as $subj) $this->deletethisSection($subj); } return '100'; //success } else return '103'; //same class is parent to other class } } } function candeletethisSection($sectionid) { $del=0; $qone="select timetable_id from ced_t_exam_timetable where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select School_diary_id from ced_t_school_diary where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select term_id from ced_t_feeterms where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select student_id from ced_t_students where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; if($del==0) { return 'ok'; } else return 'fail'; } function deletethisSection($sectionid) { $del=0; $qone="select timetable_id from ced_t_exam_timetable where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select School_diary_id from ced_t_school_diary where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select term_id from ced_t_feeterms where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select student_id from ced_t_students where section_id=".(int)$sectionid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; if($del==0) { $delcl="delete from ced_t_sections where section_id=".(int)$sectionid; $delexe=mysqli_query($this->conn,$delcl); return 'ok'; } else return 'fail'; } /********************* DELETE CLASS BY CLASS ID*******************/ function deletethisClass($schoolid,$classid,$acdid) { $del=0; // IF any records is associated with current class id then delete cant perform $qone="select staff_id from ced_t_school_staff where class_id=".(int)$classid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select student_id from ced_t_students where class_id=".(int)$classid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select School_diary_id from ced_t_school_diary where class_id=".(int)$classid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; $qone="select notification_id from ced_t_noticeboard where class_id=".(int)$classid; $one=mysqli_query($this->conn,$qone); if(mysqli_num_rows($one)) $del=1; //~ echo $del; //~ exit; if($del==0) { /*$delcl="select junior_status,class_order from ced_t_class where class_id=".(int)$classid; $delexe=mysqli_query($delcl); if(mysqli_num_rows($delexe)) { $res=mysqli_fetch_array($delexe); $row['junior_status']=$res['junior_status']; $row['class_order']=$res['class_order']; if($row['junior_status']=='1') return '101'; else { $allcls="select * from ced_t_class where school_id=".(int)$schoolid." and academic_year_id=".(int)$acdid; $allexe=mysqli_query($allcls); while($r=mysqli_fetch_array($allexe)) { if(($r['class_order']>$row['class_order']) && $r['class_id']!=$classid) { $ord=$r['class_order']; $ord--; $upd="update ced_t_class set class_order='$ord' where class_id=".(int)$r['class_id']; mysqli_query($upd); } } } }*/ $delcl="select junior_status,class_order from ced_t_class where class_id=".(int)$classid; //~ echo $delcl; //~ exit; $delexe=mysqli_query($this->conn,$delcl); if(mysqli_num_rows($delexe)) { $res=mysqli_fetch_array($delexe); $row['junior_status']=$res['junior_status']; $row['class_order']=$res['class_order']; if($row['junior_status']=='1' && $del==1) return '101'; else { $last="select class_id from ced_t_class where school_id=".(int)$schoolid." and academic_year_id=".(int)$acdid." order by class_order desc"; //~ echo $last; //~ exit; $lastexe=mysqli_query($this->conn,$last); $lastrec=mysqli_fetch_array($lastexe); //~ echo $lastrec['class_id']; //~ exit; if((int)$lastrec['class_id']==$classid) { $delete="delete from ced_t_class where class_id=".(int)$classid; mysqli_query($this->conn,$delete); $secdelete="delete from ced_t_sections where class_id=".(int)$classid; mysqli_query($this->conn,$secdelete); return 'success'; //deleted } else { return 'notlast'; } } } } else return 'fail';// if records exist } /********************* ADD NEW SUBJECT *******************/ function addnewsubjectToSchool($me,$schoolid,$catid,$sub_name,$acdid) { $sub_name=$this->getpreventInjections($sub_name); $sub_name=ucwords(strtolower($sub_name)); $subcheck="select subject_id from ced_t_subjects where school_id='$schoolid' and class_category_id='$catid' and subject_name='".$sub_name."' and academic_year_id='$acdid'"; $chkqry=mysqli_query($this->conn,$subcheck); if(!mysqli_num_rows($chkqry)) { $sql="insert into ced_t_subjects set subject_name='".$sub_name."',school_id='$schoolid',class_category_id='$catid',subject_status='1',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; $exe=mysqli_query($this->conn,$sql); if(mysqli_insert_id($this->conn)) return 'success'; else return 'failed'; } else return 'exist'; } /********************* UPDATE THE SUBJECT INFO *******************/ function updatesubjectToSchool($updid,$me,$schoolid,$catid,$sub_name,$acdid) { $sub_name=$this->getpreventInjections($sub_name); $sub_name=ucwords(strtolower($sub_name)); $subcheck="select subject_id from ced_t_subjects where school_id='$schoolid' and class_category_id='$catid' and subject_name='".$sub_name."' and subject_id<>'$updid' and academic_year_id=".(int)$acdid; $chkqry=mysqli_query($this->conn,$subcheck); if(!mysqli_num_rows($chkqry)) { $sql="update ced_t_subjects set subject_name='".$sub_name."',class_category_id='$catid',updated_by='$me' where subject_id=".(int)$updid; $exe=mysqli_query($this->conn,$sql); //if(mysqli_affected_rows()) return 'success'; } else return 'exist'; } /********************* GET ALL SUBJECTS TO VIEW BY CATEGORY ID*******************/ function getallsubjectsofclasscategory($schoolid,$catid,$acdid) { $sql="select s.subject_id,s.subject_name,s.subject_status,c.class_category_name from ced_t_subjects s inner join ced_t_class_categories c on s.class_category_id=c.class_category_id where s.class_category_id='$catid' and s.academic_year_id='$acdid' and s.school_id=".(int)$schoolid; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_assoc($exe)) { $row[]=$res; } return $row; } else return 'no subjects'; } /********************* GET SUBJECT DETAILS BY SUBJECT ID*******************/ function getthissubjectdetailsbyId($subid) { $qry="select s.subject_id,s.subject_name,s.class_category_id,c.class_category_name from ced_t_subjects s inner join ced_t_class_categories c on s.class_category_id=c.class_category_id where subject_id=".(int)$subid; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); $row['subject_id']=$res['subject_id']; $row['subject_name']=$res['subject_name']; $row['class_category_id']=$res['class_category_id']; $row['class_category_name']=$res['class_category_name']; return $row; } else return 'notfound'; } /********************* MAKE ACTIVE OR INACTIVE THE SUBJECT*******************/ function changesubjectstatus($subid,$state) { if($state=='1') $cstate=0; else $cstate=1; $qry="update ced_t_subjects set subject_status='$cstate' where subject_id=".(int)$subid; mysqli_query($this->conn,$qry); return 'ok'; } /********************* DELETE SUBJECT BY SUBJECT ID*******************/ function deletesubject($me,$schooid,$subjectid) { $sql1="select subject_id from ced_t_exam_timetable where subject_id=".(int)$subjectid; $sql2="select subject_id from ced_t_students_marks where subject_id=".(int)$subjectid; $sql3="select subject_id from ced_t_school_diary where subject_id=".(int)$subjectid; $exe1=mysqli_query($this->conn,$sql1); $exe2=mysqli_query($this->conn,$sql2); $exe3=mysqli_query($this->conn,$sql3); if(mysqli_num_rows($exe1) || mysqli_num_rows($exe2) || mysqli_num_rows($exe3)) { return 'cant delete'; // IF RECORD ASSOCIATIONS EXIST } else { $del="delete from ced_t_subjects where subject_id=".(int)$subjectid; mysqli_query($this->conn,$del); return 'ok'; // SUCCESS } } /********************* GET TEACHERS OF A SCHOOL BY SCHOOL ID*******************/ function getteacherappusers($schoolid,$acdid) { $qry="select s.staff_id,s.staff_name,s.staff_email,s.staff_mobile,s.status,auth_ref,a.teacher_app_access from ced_t_school_staff s left join ced_t_authentication_details a on s.auth_ref=a.authenticate_id where s.school_id='$schoolid' and s.academic_year_id='$acdid' and s.staff_type=1 and s.status=1"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($rec=mysqli_fetch_assoc($exe)) { $row[]=$rec; } return $row; } else return 'not'; } /********************* GET NON-TEACHING STAFF OF A SCHOOL BY SCHOOL ID*******************/ function getmyschoolnonteaching($schoolid,$acdid) { $qry="select s.staff_id,s.staff_name,s.staff_email,s.staff_mobile,s.status,s.auth_ref,a.driver_app_access from ced_t_school_staff s left join ced_t_authentication_details a on s.auth_ref=a.authenticate_id where s.school_id='$schoolid' and s.academic_year_id='$acdid' and s.staff_type=2 and s.status=1"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($rec=mysqli_fetch_assoc($exe)) { $row[]=$rec; } return $row; } else return 'not'; } /*********************GET SCHOOL STAFF BY SCHOOL ID AND STAFF TYPE*******************/ function getmyschoolstaff($schoolid,$acdid,$type) { $qry="select staff_id,staff_name,staff_email,staff_mobile,status,staff_type,auth_ref from ced_t_school_staff where school_id='$schoolid' and academic_year_id='$acdid' and staff_type='$type' and status=1"; //~ echo $qry; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($rec=mysqli_fetch_assoc($exe)) { $row[]=$rec; } return $row; } else return 'not'; } /********************* DELETE SCHOOL STAFF BY STAFF ID*******************/ function remove_teacher_from_School($stfid,$acdid,$ref) { $assoc=0; $qry1="select staff_route_id from ced_t_staff_routes where staff_id=".(int)$stfid; $exe1=mysqli_query($this->conn,$qry1); if($ref!=0) { $qry2="select School_diary_id from ced_t_school_diary where created_by=".(int)$ref." or updated_by=".(int)$ref; $exe2=mysqli_query($this->conn,$qry2); $qry3="select attendance_id from ced_t_attendance where created_by=".(int)$ref." or updated_by=".(int)$ref; $exe3=mysqli_query($this->conn,$qry3); if(mysqli_num_rows($exe2) || mysqli_num_rows($exe3)) { $assoc=1; } } if(mysqli_num_rows($exe1)) return 'cannot'; else if($assoc==1) return 'cannot'; else { $qry="select staff_id,auth_ref from ced_t_school_staff where staff_id=".(int)$stfid; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); $delete="delete from ced_t_authentication_details where authenticate_id=".(int)$res['auth_ref']; mysqli_query($this->conn,$delete); $delete1="delete from ced_t_school_staff where staff_id=".(int)$stfid; mysqli_query($this->conn,$delete1); $delpr="delete from ced_t_privileges where authentication_id=".(int)$ref; mysqli_query($this->conn,$delpr); return 'ok'; } } } /********************* GET SCHOOL STAFF BY SCHOOL ID*******************/ function getallmyschoolstaff($schoolid,$acdid) { //$qry="select s.staff_id,s.staff_name,s.staff_email,s.staff_mobile,s.status,s.auth_ref,a.school_admin_access from ced_t_school_staff s inner join ced_t_authentication_details a on s.auth_ref=a.authenticate_id where s.school_id=".(int)$schoolid." and s.academic_year_id='$acdid' and s.status=1 and a.school_admin_access=1"; $qry="select s.staff_id,s.staff_name,s.staff_email,s.staff_mobile,s.status,s.auth_ref,s.staff_type,p.privileges from ced_t_school_staff s inner join ced_t_privileges p on s.auth_ref=p.authentication_id where s.school_id=".(int)$schoolid." and s.academic_year_id='$acdid' and s.status=1"; //~ echo $qry; //~ exit; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($rec=mysqli_fetch_array($exe)) { $row['staff_id']=$rec['staff_id']; $row['staff_name']=$rec['staff_name']; $row['staff_email']=$rec['staff_email']; $row['staff_mobile']=$rec['staff_mobile']; $row['auth_ref']=$rec['auth_ref']; $row['privileges']=$rec['privileges']; $row['staff_type']=$rec['staff_type']; $sql="select school_admin_access from ced_t_authentication_details where authenticate_id=".(int)$rec['auth_ref']; $res=mysqli_query($this->conn,$sql); if(mysqli_num_rows($res)) { $record=mysqli_fetch_array($res); $row['school_admin_access']=$record['school_admin_access']; } $result[]=$row; } return $result; } else return 'not'; } /******************* Funciton for getting app details*************/ function gettingAppDetails() { $data=array(); $sql="SELECT `details_id`,`app_logo`,`app_name`,`sender_mail`,`support_mail`,`domain` FROM `ced_t_app_details` where `details_id`=1"; $result=mysqli_query($this->conn,$sql); if(mysqli_num_rows($result)>0) { $row=mysqli_fetch_array($result); $data['details_id']=$row['details_id']; $data['app_logo']=APP_LOGO_PATH.$row['app_logo']; $data['app_logo']="uploads/".$row['app_logo']; $data['app_name']=$row['app_name']; $data['sender_mail']=$row['sender_mail']; $data['support_mail']=$row['support_mail']; $data['domain']=$row['domain']; } return $data; } /******************* Funciton for updating app details*************/ function updatingAppDetails($sender_mail,$support_mail,$app_name,$im_url) { //$data=array(); $sql="UPDATE `ced_t_app_details` SET `app_logo`='".$im_url."',`app_name`='".$app_name."',`sender_mail`='".$sender_mail."',`support_mail`='".$support_mail."' WHERE `details_id`=1"; $result=mysqli_query($this->conn,$sql); if($result) { $error=1; }else { $error=2; } return $error; } /********************* GET ACCESS PRIVILEGES OF A PERSON*******************/ function getthisuserPrivileges($authid) { $qry="select privileges from ced_t_privileges where authentication_id=".(int)$authid; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); if($res['privileges']!='') return $res['privileges']; else return 0; } else return 0; } /********************* GET PRIVILEGES OF A PERSON FOR ACCESS CHECKING*******************/ function getthisuseraccessPrivileges($authid) { $response; $suqry="select school_su from ced_t_authentication_details where authenticate_id=".(int)$authid; $suexe=mysqli_query($this->conn,$suqry); if(mysqli_num_rows($suexe)) { $res1=mysqli_fetch_array($suexe); $response[0]=$res1['school_su']; } else $response[0]=0; $qry="select privileges from ced_t_privileges where authentication_id=".(int)$authid; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); $response[1]=$res['privileges']; } else $response[1]=0; return $response; } /********************* CHANGE STAFF STATUS OF A SCHOOL BY STAFF ID*******************/ function userstatuschange($staffid,$status,$type,$me) { if($type=='tch') { $sql="select staff_id,staff_name,staff_mobile,mail_sent,school_id,staff_email,auth_ref from ced_t_school_staff where staff_id=".(int)$staffid; $exe=mysqli_query($this->conn,$sql); $res=mysqli_fetch_array($exe); if($res['auth_ref']==0 && $status==1) { $autogenerate=rand(100001,999999); $passe=encrypt($autogenerate); $ins="insert into ced_t_authentication_details set email='".$res['staff_mobile']."',password='".$passe."',school_id='".$res['school_id']."',status=1,teacher_app_access=1,created_by='$me',created_on='".date('Y-m-d')."',notifications=1"; mysqli_query($this->conn,$ins); $authref=mysqli_insert_id(); $mailupdate="update ced_t_school_staff set mail_sent=1,auth_ref='$authref' where staff_id=".(int)$staffid; mysqli_query($this->conn,$mailupdate); $this->sendteacherappaccessmail($res['staff_name'],$res['school_id'],$res['staff_email'],$autogenerate,$res['staff_mobile']); } else if($res['auth_ref']!=0) { $pass="select password from ced_t_authentication_details where authenticate_id=".(int)$res['auth_ref']; $pres=mysqli_query($this->conn,$pass); $pexe=mysqli_fetch_array($pres); $autogenerate=$this->decryptIt($pexe['password']); $qry="update ced_t_authentication_details set teacher_app_access='$status' where authenticate_id=".(int)$res['auth_ref']; mysqli_query($this->conn,$qry); if($res['mail_sent']==0 && $status==1) { $this->sendteacherappaccessmail($res['staff_name'],$res['school_id'],$res['staff_email'],$autogenerate,$res['staff_mobile']); mysqli_query("update ced_t_school_staff set mail_sent=1 where staff_id=".(int)$res['staff_id']); } } } else if($type=='drv') { $sql="select staff_id,staff_name,mail_sent,school_id,staff_email,staff_mobile,auth_ref from ced_t_school_staff where staff_id=".(int)$staffid; $exe=mysqli_query($this->conn,$sql); $res=mysqli_fetch_array($exe); if($res['auth_ref']==0 && $status==1) { $autogenerate=rand(100001,999999); $passe=encrypt($autogenerate); $ins="insert into ced_t_authentication_details set email='".$res['staff_mobile']."',password='".$passe."',school_id='".$res['school_id']."',status=1,driver_app_access=1,created_by='$me',created_on='".date('Y-m-d')."',notifications=1"; mysqli_query($this->conn,$ins); $authref=mysqli_insert_id(); $mailupdate="update ced_t_school_staff set mail_sent=1,auth_ref='$authref' where staff_id=".(int)$res['staff_id']; mysqli_query($this->conn,$mailupdate); $this->send_driver_appaccessmail($res['staff_name'],$res['school_id'],$res['staff_email'],$autogenerate,$res['staff_mobile']); } else if($res['auth_ref']!=0) { $pass="select password from ced_t_authentication_details where authenticate_id=".(int)$res['auth_ref']; $pres=mysqli_query($this->conn,$pass); $pexe=mysqli_fetch_array($pres); $autogenerate=$this->decryptIt($pexe['password']); $qry="update ced_t_authentication_details set driver_app_access='$status' where authenticate_id=".(int)$res['auth_ref']; mysqli_query($this->conn,$qry); if($res['mail_sent']==0 && $status==1) { $this->sendteacherappaccessmail($res['staff_name'],$res['school_id'],$res['staff_email'],$autogenerate,$res['staff_mobile']); mysqli_query("update ced_t_school_staff set mail_sent=1 where staff_id=".(int)$res['staff_id']); } } } else if($type=='adm') { $sql="select staff_id,staff_name,mail_sent,school_id,staff_email,auth_ref from ced_t_school_staff where staff_id=".(int)$staffid; $exe=mysqli_query($this->conn,$sql); $res=mysqli_fetch_array($exe); $qry="update ced_t_authentication_details set school_admin_access='$status' where authenticate_id=".(int)$res['auth_ref']; mysqli_query($this->conn,$qry); } return 'ok'; } /********************* GET FEE TERMS OF A SCHOOL BY CLASS AND SECTION ID'S*******************/ function getfeetermsBySchool($schoolid,$classid,$secid,$acdid) { $qry="select term_id,term_name,term_amount,class_id,section_id,term_duedate from ced_t_feeterms where class_id='$classid' and section_id='$secid' and academic_year_id='$acdid' order by term_duedate"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_assoc($exe)) { $row[]=$res; } return $row; } else return '0'; } /********************* ADD FEE TERMS OF A SCHOOL*******************/ function addfeetermstoClass($me,$schoolid,$acdid,$class_id,$section_id,$termname,$amount,$duedate) { $i=0; foreach($termname as $term) { $term=$this->getpreventInjections($term); $amt=$this->getpreventInjections($amount[$i]); $duedt=$this->getpreventInjections($duedate[$i]); $duedt=date('Y-m-d',strtotime(str_replace('/','-',$duedt))); $qry="insert into ced_t_feeterms set term_name='".trim($term)."',term_amount='".trim($amt)."',term_duedate='".$duedt."',class_id='$class_id',section_id='$section_id',school_id='$schoolid',academic_year_id='$acdid',created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $qry; //~ exit; mysqli_query($this->conn,$qry); $effected=mysqli_insert_id($this->conn); $i++; } if($effected) { $sql = "select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$schoolid." and s.class_id=".(int)$class_id." and s.section_id=".(int)$section_id." and s.academic_year_id=".(int)$acdid." and s.status=1 and sp.account_status=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { $cklic=$this->check_lic_status($res['student_id']); if($res['device_id']!='' && $cklic) { $msg['type']="fee"; $msg['message']="Fee terms for ".$res['student_firstname']." ".$res['student_lastname']." has been updated"; $msg['student_id']=$res['student_id']; $nstate=$this->getNotestate($res['authenticate_id']); if($nstate=='1') $this->send_notice($res['device_id'],$msg); } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$msg['message']."',student_id=".(int)$res['student_id'].",notify_type='fee',read_status=1,created_on='".date('Y-m-d')."'"; mysqli_query($this->conn,$noteins); } } } } return 'ok'; } function getNotestate($authenticate_id) { $sql="select notifications from ced_t_authentication_details where authenticate_id=".(int)$authenticate_id; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); return $res['notifications']; } } /********************* GET FEE TERMS DETAILS FOR EDIT*******************/ function gettermforEdit($termid) { $qry="select term_id,term_name,term_amount,term_duedate,class_id,section_id from ced_t_feeterms where term_id=".(int)$termid; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { $rec=mysqli_fetch_array($exe); $row['term_id']=$rec['term_id']; $row['term_name']=$rec['term_name']; $row['term_amount']=$rec['term_amount']; $row['term_duedate']=$rec['term_duedate']; $row['class_id']=$rec['class_id']; $row['section_id']=$rec['section_id']; return $row; } else return 0; } /********************* UPDATE FEE TERMS *******************/ function updatefeeterm($termid,$me,$schoolid,$cls_id,$sec_id,$termname,$amount,$duedate,$prevamt,$acdid) { if($prevamt!=$amount) { $sql="select student_fee_id from ced_t_student_fee where term_id=".(int)$termid." and pay_status=1"; $res=mysqli_query($this->conn,$sql); if(mysqli_num_rows($res)) { return 'exist'; } else { $termname=$this->getpreventInjections($termname); $amount=$this->getpreventInjections($amount); $duedate=$this->getpreventInjections($duedate); $upd="update ced_t_feeterms set class_id='$cls_id',section_id='$sec_id',term_name='".$termname."',term_amount='".$amount."',term_duedate='".$duedate."',updated_by='$me' where term_id=".(int)$termid; $exe=mysqli_query($this->conn,$upd); if(mysqli_affected_rows($this->conn)) { $sql = "select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$schoolid." and s.class_id=".(int)$cls_id." and s.section_id=".(int)$sec_id." and s.academic_year_id=".(int)$acdid." and s.status=1 and sp.account_status=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { $cklic=$this->check_lic_status($res['student_id']); if($res['device_id']!='' && $cklic) { $msg['type']="fee"; $msg['message']="Fee terms for ".$res['student_firstname']." ".$res['student_lastname']." has been updated"; $msg['student_id']=$res['student_id']; $nstate=$this->getNotestate($res['authenticate_id']); if($nstate=='1') $this->send_notice($res['device_id'],$msg); } if($cklic!=0) { $noteins="insert into ced_t_notifications set notify_name='".$msg['message']."',student_id=".(int)$res['student_id'].",notify_type='fee',read_status=1,created_on='".date('Y-m-d')."'"; mysqli_query($noteins); } } } } } } else { $termname=$this->getpreventInjections($termname); $amount=$this->getpreventInjections($amount); $duedate=$this->getpreventInjections($duedate); $upd="update ced_t_feeterms set class_id='$cls_id',section_id='$sec_id',term_name='".$termname."',term_amount='".$amount."',term_duedate='".$duedate."',updated_by='$me' where term_id=".(int)$termid; $exe=mysqli_query($this->conn,$upd); if(mysqli_affected_rows($this->conn)) { $sql = "select sp.device_id,sp.student_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.school_id=".(int)$schoolid." and s.class_id=".(int)$cls_id." and s.section_id=".(int)$sec_id." and s.academic_year_id=".(int)$acdid." and s.status=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { $cklic=$this->check_lic_status($res['student_id']); if($res['device_id']!='' && $cklic) { $msg['type']="fee"; $msg['message']="Fee terms for ".$res['student_firstname']." ".$res['student_lastname']." has been updated"; $msg['student_id']=$res['student_id']; $this->send_notice($res['device_id'],$msg); } } } } return 'ok'; } } 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=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)>0) return 1; else return 0; } /********************* GET FEE TERMS OF A CLASS AND SECTION *******************/ function getalltermsbyclassnsection($classid,$sectionid,$acdid) { $sql="select term_id,term_name from ced_t_feeterms where class_id='$classid' and section_id='$sectionid' and academic_year_id=".(int)$acdid." order by term_duedate"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($row=mysqli_fetch_assoc($exe)) $rec[]=$row; return $rec; } else return '0'; } /********************* DELETE FEE TERMS BY TERM ID*******************/ function deleteFeeTermByid($termid) { $qry="select student_fee_id from ced_t_student_fee where term_id=".(int)$termid; $exe=mysqli_query($this->conn,$qry); if(!mysqli_num_rows($exe)) { $del="delete from ced_t_feeterms where term_id=".(int)$termid; mysqli_query($this->conn,$del); return 'ok'; // SUCCESS } else return 'not'; // RECORD ASSOCIATION EXIST } /********************* GET DATA FOR FEE ACCOUNTS *******************/ function getstudentfeeterms($school_id,$acdid,$class,$scn,$term) { $feedets=$this->gettermforEdit($term); $qry="select student_id,student_rollno,student_firstname,student_lastname from ced_t_students where school_id=".(int)$school_id." and class_id=".(int)$class." and section_id=".(int)$scn." and academic_year_id=".(int)$acdid." and status=1"; $qryexe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($qryexe)) { while($res=mysqli_fetch_array($qryexe)) { $row['student_id']=$res['student_id']; $row['student_rollno']=$res['student_rollno']; $row['student_firstname']=$res['student_firstname']; $row['student_lastname']=$res['student_lastname']; $row['term_name']=$feedets['term_name']; $row['term_amount']=$feedets['term_amount']; $row['due_date']=date('d/m/Y',strtotime($feedets['term_duedate'])); $sql="select student_fee_id,amount_paid,paid_on,pay_status from ced_t_student_fee where student_id=".(int)$res['student_id']." and term_id=".(int)$term." and academic_year_id=".(int)$acdid; $sqlexe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($sqlexe)) { $rec=mysqli_fetch_array($sqlexe); $row['student_fee_id']=$rec['student_fee_id']; $row['amount_paid']=$rec['amount_paid']; $row['paid_on']=date('d/m/Y',strtotime($rec['paid_on'])); if($rec['pay_status']=='1') { $row['pay_status']='Paid'; $row['paid_on']=date('d/m/Y',strtotime($rec['paid_on'])); } else { $row['pay_status']='Unpaid'; $row['paid_on']='N/A'; } } else { $row['student_fee_id']=0; $row['amount_paid']=$feedets['term_amount']; $row['paid_on']='N/A'; $row['pay_status']='Unpaid'; } $result[]=$row; } return $result; } else { return 'notfound'; } } function updatestudentFeeAccounts($acdid,$stdid,$feeid,$trmid,$clnid,$scnid,$paidsts,$feeamt,$session,$tname) { $i=0;$yy=0; foreach($stdid as $student) { if($paidsts[$student]!=$session[$student]) { $date=date('Y-m-d'); $pt=1; $yy=1; if($feeid[$i]=='0' && $paidsts[$student]=='1') { $ins="insert into ced_t_student_fee set student_id='".$stdid[$i]."',term_id='".$trmid."',amount_paid='".$feeamt."',paid_on='".$date."',pay_type='$pt',pay_status='".$paidsts[$student]."',academic_year_id='".$acdid."'"; mysqli_query($this->conn,$ins); $effect=mysqli_insert_id($this->conn); //$sql = "select sp.device_id,sp.student_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.student_id=".(int)$student." and sp.account_status=1"; $sql = "select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id inner join ced_t_student_licenses sl on sl.student_id=s.student_id where s.student_id=".(int)$student." and sp.account_status=1 and sl.license_status=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); if($res['device_id']!='') { $msg['type']="fee"; $msg['message']="School Fee for ".$res['student_firstname']." ".$res['student_lastname']." for ".$tname." has been updated"; $msg['student_id']=$res['student_id']; $nstate=$this->getNotestate($res['authenticate_id']); $noteins="insert into ced_t_notifications set notify_name='".$msg['message']."',student_id=".(int)$res['student_id'].",notify_type='fee',read_status=1,created_on='".date('Y-m-d')."'"; mysqli_query($this->conn,$noteins); if($nstate=='1') $this->send_notice($res['device_id'],$msg); } } } else { $upd="update ced_t_student_fee set paid_on='".$date."',pay_type='$pt',pay_status='".$paidsts[$student]."' where student_fee_id=".(int)$feeid[$i]; mysqli_query($this->conn,$upd); //$sql = "select sp.device_id,sp.student_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.student_id=".(int)$student." and sp.account_status=1"; $sql = "select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id inner join ced_t_student_licenses sl on sl.student_id=s.student_id where s.student_id=".(int)$student." and sp.account_status=1 and sl.license_status=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { $res=mysqli_fetch_array($exe); if($res['device_id']!='') { $msg['type']="fee"; if($paidsts[$student]=='1') $msg['message']="School Fee for ".$res['student_firstname']." ".$res['student_lastname']." for ".$tname." has been updated"; else $msg['message']="School Fee for ".$res['student_firstname']." ".$res['student_lastname']." for ".$tname." is due. Please make the payment"; $msg['student_id']=$res['student_id']; $noteins="insert into ced_t_notifications set notify_name='".$msg['message']."',student_id=".(int)$res['student_id'].",notify_type='fee',read_status=1,created_on='".date('Y-m-d')."'"; mysqli_query($this->conn,$noteins); $nstate=$this->getNotestate($res['authenticate_id']); if($nstate=='1') $this->send_notice($res['device_id'],$msg); } } } } $i++; } return $yy; } function send_fee_remainder($stdid,$tname) { $sql = "select sp.device_id,sp.student_id,sp.authenticate_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id inner join ced_t_student_licenses sl on sl.student_id=s.student_id where s.student_id=".(int)$stdid." and sp.account_status=1 and sl.license_status=1"; //~ echo $sql; //~ exit; //$sql = "select sp.device_id,sp.student_id,s.student_firstname,s.student_lastname from ced_t_students_parent sp inner join ced_t_students s on sp.student_id=s.student_id where s.student_id=".(int)$stdid." and sp.account_status=1"; $exe=mysqli_query($this->conn,$sql); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { if($res['device_id']!='') { $msg['type']="fee"; $msg['message']="School Fee for ".$res['student_firstname']." ".$res['student_lastname']." for ".$tname." is due. Please make the payment"; $msg['student_id']=$res['student_id']; $noteins="insert into ced_t_notifications set notify_name='".$msg['message']."',student_id=".(int)$res['student_id'].",notify_type='fee',read_status=1,created_on='".date('Y-m-d')."'"; mysqli_query($this->conn,$noteins); $nstate=$this->getNotestate($res['authenticate_id']); if($nstate=='1') $this->send_notice($res['device_id'],$msg); } } } } /********************* INSERT/UPDATE USER PRIVILEGES OF A SCHOOL *******************/ function saveuserprivileges($me,$user,$privileges) { if(empty($privileges)) $privileges=''; else { $privs=$privileges; $privileges=implode(',',$privileges); } $privileges=rtrim($privileges,','); if($privileges!='') { $sql1="select staff_name,mail_sent,school_id,staff_email,staff_mobile,auth_ref from ced_t_school_staff where staff_id=".(int)$user; //~ echo $sql1; $exe1=mysqli_query($this->conn,$sql1); $res=mysqli_fetch_array($exe1); if($res['auth_ref']==0) { $pass=rand(100001,999999); $passe=$this->encrypt($pass); $ins="insert into ced_t_authentication_details set email='".$res['staff_mobile']."',password='".$passe."',school_id='".$res['school_id']."',school_admin_access=1,status=1,notifications=1,created_by='$me',created_on='".date('Y-m-d')."'"; //~ echo $ins; //~ exit; mysqli_query($this->conn,$ins); $authref=mysqli_insert_id($this->conn); $stfupd="update ced_t_school_staff set auth_ref='$authref' where staff_id=".(int)$user; mysqli_query($this->conn,$stfupd); $qry="insert into ced_t_privileges set privileges='".$privileges."',authentication_id='$authref',created_by='$me',created_on='".date('Y-m-d')."',mail_sent=1"; //~ echo $qry; //~ exit; mysqli_query($this->conn,$qry); foreach($privs as $nameit) { if($nameit==1) $permit.='<li>Attendance</li>'; if($nameit==2) $permit.='<li>Diary</li>'; if($nameit==3) $permit.='<li>Notice Board</li>'; if($nameit==4) $permit.='<li>Examinations</li>'; if($nameit==5) $permit.='<li>Transport</li>'; if($nameit==6) $permit.='<li>Fee Payment</li>'; } $this->send_admin_portal_access_mail($res['staff_name'],$res['school_id'],$res['staff_email'],$pass,$permit,$res['staff_mobile']); } else { $upd="update ced_t_authentication_details set school_admin_access=1 where authenticate_id=".(int)$res['auth_ref']; mysqli_query($this->conn,$upd); $pwd="select password from ced_t_authentication_details where authenticate_id=".(int)$res['auth_ref']; $pwexe=mysqli_query($this->conn,$pwd); $mailpass=mysqli_fetch_array($pwexe); $pwd=$this->$this->decrypt($mailpass['password']); $chk="select user_id from ced_t_privileges where authentication_id=".(int)$res['auth_ref']; $exe=mysqli_query($this->conn,$chk); if(mysqli_num_rows($exe)>0) { $qry="update ced_t_privileges set privileges='".$privileges."',updated_by='$me' where authentication_id=".(int)$res['auth_ref']; mysqli_query($this->conn,$qry); } else { $qry="insert into ced_t_privileges set privileges='".$privileges."',authentication_id='".$res['auth_ref']."',created_by='$me',created_on='".date('Y-m-d')."',mail_sent=1"; mysqli_query($this->conn,$qry); foreach($privs as $nameit) { if($nameit==1) $permit.='<li>Attendance</li>'; if($nameit==2) $permit.='<li>Diary</li>'; if($nameit==3) $permit.='<li>Notice Board</li>'; if($nameit==4) $permit.='<li>Examinations</li>'; if($nameit==5) $permit.='<li>Transport</li>'; if($nameit==6) $permit.='<li>Fee Payment</li>'; } $this->send_admin_portal_access_mail($res['staff_name'],$res['school_id'],$res['staff_email'],$pwd,$permit,$res['staff_mobile']); } } } } /************FORGOT PASSWORD FOR SCHOOL ADMIN***********/ function forgotpwd_sendpasswordbyemail($email) { $qexist="SELECT p.authenticate_id,p.password,p.school_id,p.school_su,s.school_name,s.school_email from ced_t_authentication_details p inner join ced_t_school s on s.school_id=p.school_id where email='".$email."' and p.school_admin_access=1"; //$qexist="SELECT `password` FROM `ced_t_authentication_details` WHERE `email`='".$email."' and `status`=1"; $exe=mysqli_query($this->conn,$qexist); if(mysqli_num_rows($exe)>0) { $password=mysqli_fetch_array($exe); if($password['school_su']==1) { $sql="select contact_name from ced_t_school_contacts where school_id=".(int)$password['school_id']; $cont=mysqli_query($this->conn,$sql); $name=mysqli_fetch_array($cont); $contname=$name['contact_name']; $temail=$password['school_email']; } else { $sql="select staff_name,staff_email from ced_t_school_staff where auth_ref=".(int)$password['authenticate_id']." and school_id=".(int)$password['school_id']; $cont=mysqli_query($this->conn,$sql); $name=mysqli_fetch_array($cont); $contname=$name['staff_name']; $temail=$name['staff_email']; } $detls=$this->gettingAppDetails(); $pwd=$this->decrypt($password['password']); $to = $temail; $subject = "Forgot Password: ".$detls['app_name']; $message = ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-family:verdana,arial,san-sarif;"> <tr><td align="left" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td valign="top" align="center"> <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center"> <tr> <td colspan="2" style="padding:0px 10px" align="center" height="75" valign="middle" width="150"> <img src="'.$detls['app_logo'].'" alt="'.$detls['app_name'].'" align="center" > </td> </tr> </table> </td></tr> <tr><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top"><b>Dear '.$contname.', '.$password[school_name].' </b></td></tr> <tr><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top"> </td></tr> <tr> <td style="" align="left" valign="top"> <b>You have requested for your password using Forgot Password. Your password is '.$pwd.'. You may now login into '.$detls['app_name'].' School Admin Portal at <a href="'.ADMIN_PATH.'">'.$detls['domain'].'</a></b><br/> </td> </tr> <tr><td><br/><br/> Regards,<br/> '.$detls['app_name'].' Team<br/> </td></tr> </table> </td></tr> </table>'; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From: ".$detls['app_name']." <".$detls['sender_mail'].">"; $sent=mail($to,$subject,$message,$headers); //$mailer=$this->sendingemail($to,$subject,$message); if($sent) return 1; else return 2; } else { return 3; } } /***********GET SCHOOL ADMIN EMAIL***********/ function get_authentication_email($authid) { $sql="SELECT `email` FROM `ced_t_authentication_details` WHERE `authenticate_id`='".$authid."'"; //echo $sql; $result=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); return $row['email']; } function get_authentication_pass($authid) { $sql="SELECT `password` FROM `ced_t_authentication_details` WHERE `authenticate_id`='".$authid."'"; //~ echo $sql; $result=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); $pass = $row['password']; return $pass; } /******************************SCHOOL ADMIN CHANGE PASSWORD**************/ function schooladmin_settings_change_password($user_id,$current_password,$new_password,$school_id) { $current_password=$this->encrypt($current_password); $new_password=$this->encrypt($new_password); $sql="SELECT `authenticate_id`,`school_admin_access`,`school_su` FROM `ced_t_authentication_details` WHERE `authenticate_id`='".$user_id."' and `password`='".$current_password."' and `school_id`='".$school_id."'"; //~ echo $sql; $result=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); if(mysqli_num_rows($result)>0) { if($row[school_admin_access]!=0) { $sql2="UPDATE `ced_t_authentication_details` SET `password`='".$new_password."' where `authenticate_id`='".$user_id."'"; //~ echo $sql2; $result2=mysqli_query($this->conn,$sql2); if($result2) $error=1; else $error=2; } } else { $error=3; } echo $error; return $error; } /**********************function for getting routes regarding a school id*******************/ function getroutes2schid($schid,$acdid) { $sql="select route_number,source_name,destination_name,route_id from ced_t_routes where school_id=".(int)$schid." and academic_year_id=".(int)$acdid; $res=mysqli_query($this->conn,$sql); while($ro=mysqli_fetch_assoc($res)) { $data[]=$ro; } return $data; } /***************function for getting stops for the root**********/ function getstops2routeid($rid) { $sql="select route_stop_id,route_stop_name from ced_t_route_stops where route_id=".$rid.""; $res=mysqli_query($this->conn,$sql); while($ro=mysqli_fetch_assoc($res)) { $data[]=$ro; } return $data; } /*********function for add route and stop names to staff**********/ function addroute2staff($rtid,$staffid,$academic_id,$me,$type,$prvdvr) { if($type==2) { if($prvdvr!=0) { //$sql="select staff_id from ced_t_staff_routes where staff_id<>".$staffid." and academic_year_id=".(int)$academic_id." and route_id=".(int)$rtid; $sql="update ced_t_staff_routes set staff_id='$staffid',route_id='$rtid',updated_by='$me',academic_year_id='$academic_id' where staff_route_id=".(int)$prvdvr; $res=mysqli_query($this->conn,$sql); return 'single'; } else { $sql1="insert into ced_t_staff_routes(staff_id,route_id,academic_year_id,Created_by,created_on)values(".$staffid.",".$rtid.",".$academic_id.",".$me.",'".date('Y-m-d')."')"; $res=mysqli_query($this->conn,$sql1); return 'single'; } } else { $sql="select staff_route_id from ced_t_staff_routes where staff_id=".$staffid." and academic_year_id=".(int)$academic_id." and route_id=".(int)$rtid; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num>0) { return 'single'; } else { $sql1="insert into ced_t_staff_routes(staff_id,route_id,academic_year_id,Created_by,created_on)values(".$staffid.",".$rtid.",".$academic_id.",".$me.",'".date('Y-m-d')."')"; $res1=mysqli_query($this->conn,$sql1); return 'single'; } } } function edit_staffroute($recid,$rtid,$staffid,$acdid,$stftype) { if($stftype!=2) { $sql="select staff_id from ced_t_staff_routes where staff_id=".$staffid." and academic_year_id=".(int)$acdid." and route_id=".(int)$rtid." and staff_route_id<>".$recid; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num>0) { return 'same'; } else { $qry="update ced_t_staff_routes set route_id='$rtid' where staff_route_id=".(int)$recid; mysqli_query($this->conn,$qry); } } else { $sql="select staff_id from ced_t_staff_routes where staff_id<>".$staffid." and academic_year_id=".(int)$acdid." and route_id=".(int)$rtid." and staff_route_id<>".$recid; $res=mysqli_query($this->conn,$sql); $num=mysqli_num_rows($res); if($num>0) { return 'multiple'; } else { $qry="update ced_t_staff_routes set route_id='$rtid' where staff_route_id=".(int)$recid; mysqli_query($this->conn,$qry); } } } function removeRoutetostaff($staffid,$academic_id,$rtid) { $qry="delete from ced_t_staff_routes where staff_id=".$staffid." and academic_year_id=".(int)$academic_id." and route_id=".(int)$rtid; mysqli_query($this->conn,$qry); } /*********function for getting staff regrading that school id*********/ function getstaff2schid($schid) { $sql="select staff_id,staff_name,staff_address,staff_mobile from `ced_t_school_staff` where school_id=".$schid.""; $res=mysqli_query($this->conn,$sql); while($ro=mysqli_fetch_assoc($res)) { $data[]=$ro; } return $data; } function getstaff2schid1($schid,$acdid,$route_id,$type) { $sql="select staff_id,staff_name,staff_address,staff_mobile,staff_type from `ced_t_school_staff` where school_id=".$schid." and academic_year_id=".(int)$acdid." and status=1 and staff_type=".(int)$type; $res=mysqli_query($this->conn,$sql); while($ro=mysqli_fetch_array($res)) { $data['staff_id']=$ro['staff_id']; $data['staff_name']=$ro['staff_name']; $data['staff_address']=$ro['staff_address']; $data['staff_mobile']=$ro['staff_mobile']; $data['staff_type']=$ro['staff_type']; $sub_qry="select route_id,staff_route_id from ced_t_staff_routes where staff_id=".(int)$ro['staff_id']." and route_id=".(int)$route_id." and academic_year_id=".(int)$acdid; $sqexe=mysqli_query($this->conn,$sub_qry); if(mysqli_num_rows($sqexe)) { $rec=mysqli_fetch_array($sqexe); $data['route_id']=$rec['route_id']; $data['staff_route_id']=$rec['staff_route_id']; } else { $data['route_id']=''; $data['staff_route_id']=0; } $record[]=$data; } return $record; } ////////////////////////////////GET STAFF ROUTE BY ROUTE ID/////////////////////////////////////// function getstaffroutebystaffid($staffrouteid) { $sql="select s.staff_id,s.staff_name,s.staff_type,r.route_id from ced_t_school_staff s inner join ced_t_staff_routes r on s.staff_id=r.staff_id where staff_route_id=".(int)$staffrouteid; $exe=mysqli_query($this->conn,$sql); $res=mysqli_fetch_array($exe); $row['staff_id']=$res['staff_id']; $row['staff_name']=$res['staff_name']; $row['route_id']=$res['route_id']; $row['staff_type']=$res['staff_type']; return $row; } 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; } } return $data2; } //////////////////////////////////////DASHBOARD FUNCTION/////////////////////////////////////// function getschooltodayTotal($schoolid,$acdid) { $studentids=array(); $response=array(); $qry1="select staff_id from ced_t_school_staff where school_id=".(int)$schoolid." and academic_year_id=".(int)$acdid." and status=1 and staff_type=1"; $exe1=mysqli_query($this->conn,$qry1); if(mysqli_num_rows($exe1)) $response['teachers']=mysqli_num_rows($exe1); else $response['teachers']=0; $qry2="select staff_id from ced_t_school_staff where school_id=".(int)$schoolid." and academic_year_id=".(int)$acdid." and status=1 and staff_type<>1"; $exe2=mysqli_query($this->conn,$qry2); if(mysqli_num_rows($exe2)) $response['nonteachers']=mysqli_num_rows($exe2); else $response['nonteachers']=0; $qry3="select student_id from ced_t_students where school_id=".(int)$schoolid." and academic_year_id=".(int)$acdid." and status=1"; //~ echo $qry3; $exe3=mysqli_query($this->conn,$qry3); if(mysqli_num_rows($exe3)) $response['tstudents']=mysqli_num_rows($exe3); else $response['tstudents']=0; $qry4="select s.student_id from ced_t_students s inner join ced_t_attendance a on s.student_id=a.student_id where s.school_id=".(int)$schoolid." and s.academic_year_id=".(int)$acdid." and a.status='P' and a.attendance_date='".date('Y-m-d')."' and s.status=1"; $exe4=mysqli_query($this->conn,$qry4); if(mysqli_num_rows($exe4)) $response['presents']=mysqli_num_rows($exe4); else $response['presents']=0; $qry5="select s.student_id from ced_t_students s inner join ced_t_attendance a on s.student_id=a.student_id where s.school_id=".(int)$schoolid." and s.academic_year_id=".(int)$acdid." and a.status='A' and a.attendance_date='".date('Y-m-d')."' and s.status=1"; $exe5=mysqli_query($this->conn,$qry5); if(mysqli_num_rows($exe5)) $response['absents']=mysqli_num_rows($exe5); else $response['absents']=0; $qry_birthdays="select student_id,student_rollno,student_firstname,student_lastname,class_id,section_id from ced_t_students where school_id='".(int)$schoolid."' and academic_year_id='".(int)$acdid."' and status=1 and MONTH(date_of_birth)='".date('m')."' and DAY(date_of_birth)='".date('d')."'"; $exe3_birthdays=mysqli_query($this->conn,$qry_birthdays); if(mysqli_num_rows($exe3_birthdays)) { $response['tstudents_birthdays']=mysqli_num_rows($exe3_birthdays); while($rowbirth=mysqli_fetch_array($exe3_birthdays)) { $classname=$this->getClassDetailsByID($rowbirth['class_id']); $sectionname=$this->getSectionName($rowbirth['section_id']); $studentids['student_rollno']=$rowbirth['student_rollno']; $studentids['class_id']=$classname['class_name']; $studentids['section_id']=$sectionname; $studentids['student_name']=$rowbirth['student_firstname'].' '.$rowbirth['student_lastname']; //$studentids['student_lastname']=$rowbirth['student_lastname']; $data[]=$studentids; } //$ids=implode(",",$studentids); $response['tstudents_birthdays_studentids']=$data; } else $response['tstudents_birthdays']=0; return $response; } /******* no of parents using the app*********/ function check_license_sets_count($schoolid){ $today_date = date('Y-m-d'); $sql="SELECT school_license_id,license_count FROM `ced_t_school_licenses` WHERE school_id = '".$schoolid."' and license_valid_to > '".$today_date."' and license_status = 1 "; //echo $sql; $result=mysqli_query($this->conn,$sql); while($row=mysqli_fetch_array($result)) { $data[$row['school_license_id']]=$row; //$data2[]=$data; } return $data; } function getSectionName($sectionid) { $name=''; $qry2="select section_name from ced_t_sections where section_id='".$sectionid."' "; $exe2=mysqli_query($this->conn,$qry2); if(mysqli_num_rows($exe2)>0) { $row=mysqli_fetch_array($exe2); $name=$row['section_name']; } return $name; } function check_distributelicense_count_new($ids){ $sql= "SELECT count(*) as distributedcount FROM ced_t_student_licenses WHERE school_license_id IN (".$ids.") and license_status = 1 "; //echo $sql; $result=mysqli_query($this->conn,$sql); $row=mysqli_fetch_array($result); return $row; } function getvalidModuleaccess($schoolid) { $allmods=array(); $qry="select * from ced_t_school_licenses where school_id=".(int)$schoolid." and license_status=1"; $exe=mysqli_query($this->conn,$qry); if(mysqli_num_rows($exe)) { while($res=mysqli_fetch_array($exe)) { $modules=explode(',',$res['modules_included']); foreach($modules as $mod) { if(!in_array($mod,$allmods)) $allmods[]=$mod; } } return $allmods; } else return 0; } 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."' order by exam_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 check_my_status($schoolid) { $sql="select school_status from ced_t_school where school_id=".(int)$schoolid; $exe=mysqli_query($this->conn,$sql); $row=mysqli_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=mysqli_query($this->conn,$qry); if(!mysqli_num_rows($res) || $val=='0') return '0'; else return $val; } /* check and allow user to acces the portal*/ function check_my_access_status($login) { $qry="select email from ced_t_authentication_details where authenticate_id=".(int)$login." and school_su!=1 and school_admin_access=0"; $res=mysqli_query($this->conn,$qry); if(mysqli_num_rows($res)) return '0'; else return '1'; } function send_notice($registatoin_ids,$msg) { $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(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); return $result; } //smtp mail function mail_send($to,$sub,$mess) { $google_email = 'productsbu1@gmail.com'; $oauth2_clientId = '707771317205-m01emngdqfp8a7s5fn412pdl14d9s2ma.apps.googleusercontent.com'; $oauth2_clientSecret = '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'; $oauth2_refreshToken = '1//04mwEsI6-S-8WCgYIARAAGAQSNwF-L9IrMwoiBVMD5u7LcnOoAQgCGSR-FS3kp-kdyDV4g3kTCFUAzWtIIhH1yBZBm_Bl2wa4-ek'; $mail = new PHPMailer(TRUE); try { $mail->setFrom($google_email, 'Skoolonline'); $mail->addAddress($to); $mail->Subject = $sub; $mail->Body = $mess; $mail->isSMTP(); $mail->Port = 587; $mail->SMTPAuth = TRUE; $mail->SMTPSecure = 'tls'; $mail->IsHTML(true); /* Google's SMTP */ $mail->Host = 'smtp.gmail.com'; /* Set AuthType to XOAUTH2. */ $mail->AuthType = 'XOAUTH2'; /* Create a new OAuth2 provider instance. */ $provider = new Google( [ 'clientId' => $oauth2_clientId, 'clientSecret' => $oauth2_clientSecret, ] ); /* Pass the OAuth provider instance to PHPMailer. */ $mail->setOAuth( new OAuth( [ 'provider' => $provider, 'clientId' => $oauth2_clientId, 'clientSecret' => $oauth2_clientSecret, 'refreshToken' => $oauth2_refreshToken, 'userName' => $google_email, ] ) ); /* Finally send the mail. */ if ($mail->send()) { // echo "Mail sent successfully"; return 1; } else { echo "Mail not sent";exit; } } catch (Exception $e) { echo $e->errorMessage(); } catch (\Exception $e) { echo $e->getMessage(); } } } ?>