<?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'];
$class = $idata['class'];
$section = $idata['section'];
$type = $idata['type'];
$max_mark = $idata['max_mark'];
$student_mark = $idata['student_mark'];  //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(
            "class" => $class,
            "idno" => $ids,
            "obtain" => $ab['obtain'],
            "subject" => $ab['subject'],

            //"total" => $max_mark,
            "total" => $ab['max_mark_sub'],

            "session" => $session,
            "school_id" => $school_id,
            "type" => $type,
            "status" => 1,
            "added_by" => 1,

        );

        $db->delete("exammarks", "where school_id='$school_id' and idno='$ids' and type='$type' and subject='" . $ab['subject'] . "' and session='$session'");

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

    }
}

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