<?php
include("../../db.php");
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: * ");




         $abc=$_POST['json'];
     
     
      $idata=json_decode($abc,true);
           $session= $idata['session'];
           $school_id= $idata['school_id'];
          $date= $idata['date'];
           $idno= $idata['idno'];
           $delete_entry= $idata['delete_entry'];
            $added_by= $idata['added_by'];
           
       //  $idno=mysql_real_escape_string($idno); 
// 	 $session=mysql_real_escape_string($session);
// 	 $school_id=mysql_real_escape_string($school_id);
// 	 $date=mysql_real_escape_string($date);
	 
// 	 $type=mysql_real_escape_string($type);
	
	$mnth=date("F");
	
	      

	
		
//$_POST["mobile"]='7827018991';

			
    
	foreach($idno as $x => $x_value){
 
	   $aryData=array(
	
		 "idno"=>$x_value,
		 "school_id"=>$school_id,
		 "session"=>$session,
		 "date" =>  $date,
		 "month"=>$mnth,
		 "status"=>0,
		 "added_by"=>$added_by,
		 "type"=>2
 
	 );	
//echo $x_value;



	$check_data= $db->getRows("select * from attandenc where idno='$x_value' and date='$date' and type='2' and status='0'");

	if(count($check_data)>0)
	
	{ 
	    
  
	    
	}    
else
{

	 $insert_complain=$db->insertAry("attandenc",$aryData); 	 

	
  
}
	
}

 	if($delete_entry=='0')
 	{
 	

}
else
{
    
 foreach($delete_entry as $p => $p_value){
 
	   $type=2;
    
  $arr=$db->delete("attandenc"," where idno='$p_value' and date='$date' and type='$type' and status='0'");
		
		if($arr>0){ $msg="Delete successfully.!";}  
 }   
    
}
  		
  		

//echo $inser_complain; 
  
  if($insert_complain>0){ 
  
  $msg="Attendance Added successfully.!";
  
  	  

  	  
  
  
  }
  
	
	if($msg!="")
	{  
		echo json_encode(array('status' => 1, 'msg'=>'Done', "data"=>$msg));    
			
	}
	else
	{		
	 	echo json_encode(array('status' => 0, 'msg'=>'Attendance not Added. Please try again later..!'));
	}
