<?php
include("../../db.php");
header('Content-Type: application/json');

$jsondata = $_POST['json'];

$status = 0;
$msg = 'Unable to save data...! Please try again later';
$array = array();

$decode = json_decode($jsondata, true);

$class = $decode['class'];
$subject_id = $decode['subject_id'];
$session = $decode['session'];
$teacher_id = $decode['teacher_id'];
$data = $decode['data'];

$delete = $decode['remove'];

foreach ($data as $chapter_id){

    $tempArray = array("class" => $class, "subject_id" => $subject_id, "chapter_id" => $chapter_id, "teacher_id" => $teacher_id, "session" => $session);

    $db->insertAry("syllabus_covered", $tempArray);

}

foreach ($delete as $item) {
    $db->delete("syllabus_covered","where chapter_id='".$item."'");
}

$status = 1;
$msg = 'Data successfully submitted.';

$array['status'] = $status;
$array['msg'] = $msg;

echo json_encode($array);
