<?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'];
    $student_data = $idata['student_data'];
    
    $status=0;

    foreach($student_data as $student){

         $attendanceData=array(
    		 "idno"=>$student['stu_id'],
    		 "session"=>"$session",
    		 "school_id"=>$school_id,
    		 "added_by"=>$added_by,
    	 );

    	 if($student[term1_att] != ""){
    	     $attendanceData['term1_att'] = $student[term1_att];
    	 }

    	 if($student[term2_att] != ""){
    	     $attendanceData['term2_att'] = $student[term2_att];
    	 }

    	 if($student[teacher_rem_term1] != ""){
    	     $attendanceData['teacher_remarks_term1'] = $student[teacher_rem_term1];
    	 }

    	 if($student[teacher_rem_term2] != ""){
    	     $attendanceData['teacher_remarks_term2'] = $student[teacher_rem_term2];
    	 }

    	 if($student[spec_part_term1] != ""){
    	     $attendanceData['specific_participation_term1'] = $student[spec_part_term1];
    	 }

    	 if($student[spec_part_term2] != ""){
    	     $attendanceData['specific_participation_term2'] = $student[spec_part_term2];
    	 }

    	$any=$db->getRow("Select * from allattandence where idno='".$student['stu_id']."' and session='".$session."'");

    	if(count($any) > 1){
    		$attendance = $db->updateAry("allattandence", $attendanceData,"where idno='".$student['stu_id']."' and school_id='".$school_id."' and session='".$session."'");	
    	    $status = 1;
    	}
		else {
		    $attendance1 = $db->insertAry("allattandence", $attendanceData);
		    $status = 1;
	    }

    }

    echo json_encode(array('status' => $status )); 

?>