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

    $jsondata = $_POST['json'];

    $status = 0;
    $msg = '';
    $array = array();

    $decode = json_decode($jsondata, true);

    $class              = $decode['class'];
    $parent_subject     = $decode['parent_subject'];
    $sub_subject        = $decode['sub_subject'];
    $chapter            = $decode['chapter'];
    $key_terms          = $decode['key_terms'];
    $mind_map           = $decode['mind_map'];
    $key_notes          = $decode['key_notes'];
    $practical_projects = $decode['practical_projects'];
    $session            = $decode['session'];

    $addedBy            = $decode['added_by'];

    $dataAry            = $decode['alldata'];

    $assignmentArray = array(
        "class"             => "$class",
        "parent_subject"    => "$parent_subject",
        "sub_subject"       => "$sub_subject",
        "chapter"           => "$chapter",
        "key_terms"         => "$key_terms",
        "mind_map"          => "$mind_map",
        "key_notes"         => "$key_notes",
        "practical_projects"=> "$practical_projects",
        "session"           => "$session",
        "added_by"          =>  $addedBy
        );

    $flgIn=$db->insertAry("assignment_new",$assignmentArray);

    if($flgIn > 0){
        foreach($dataAry as $data){

            $fileArray = array(
                        "assignment_id" => $flgIn,
                        "name"          => "$data[name]",
                        "description"   => "$data[description]",
                        "type"          => "$data[type]",
                        "session"       => "$session"
                    );

            $fileIn =$db->insertAry("assignment_files",$fileArray);

        }

        $status = 1;
        $msg = 'Assignment successfully saved.';
    }
    else {
        $msg = "something went wrong.";
    }

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

echo json_encode($array);

?>