<?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'];
         $added_by= $idata['added_by'];
         $section=$idata['section'];
         $type= $idata['type'];
         $criteria= $idata['criteria'];
         $student_mark= $idata['student_grade'];  //json array parent
          
// 	 $session=mysql_real_escape_string($session);
// 	 $school_id=mysql_real_escape_string($school_id);
// 	 $added_by=mysql_real_escape_string($added_by);
	 //$class=mysql_real_escape_string($class);
// 	  $section=mysql_real_escape_string($section);
	   //$type=mysql_real_escape_string($type);
	 
	 foreach($student_mark as $x){
 
		 $ids=$x['id_no'];
		$sub_mark= $x['sub_mark'];
	
              foreach($sub_mark as $ab){
	
         $aryData=array(
		 "idno"=>$ids,
		 "grade"=>$ab['obtain'],
		 "subcriteria"=>$ab['subcriteria'],
		 "criteria"=>$criteria,
		 "session"=>$session,
		 "school_id"=>$school_id,
		 "term"=>$type,
		 "added_by"=>$added_by,
		
	 );	   
      $db->delete("examcriteriarecord","where school_id='$school_id' and idno='$ids' and term='$type' and criteria='$criteria'  and subcriteria='".$ab['subcriteria']."' and session='$session'");
      //echo $ss="examcriteriarecord","where school_id='$school_id' and idno='$ids' and term='$type' and subcriteria='".$ab['subcriteria']."' and session='$session'";

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

	 
	 }
	 
	if($insert_complain!="")
	{  
		echo json_encode(array('status' => 1, 'msg'=>'Grade Added Successfully'));
			
	}
	else
	{		
	 	echo json_encode(array('status' => 0, 'msg'=>'Grade Not Added Please Try Again..!'));
	}
	 
	 
	 
	 ?>