<?php
include("../../db.php");
header("Access-Control-Allow-Origin: * ");
// mysql_set_charset('utf8');

$abc = $_POST['json'];

$idata = json_decode($abc, true);


$classname = $idata['classname'];
$section = $idata['section'];
$subjectname = $idata['subjectname'];
$detail = $idata['detail'];
$session = $idata['session'];
$school_id = $idata['school_id'];
$Added_by = $idata['Added_by'];
$image_name=$idata['image_name'];
// $base = $idata['image'];


/*
	    $session=$_REQUEST['session'];
	   $school_id=$_REQUEST['school_id'];
      
          $classname=$_REQUEST['classname'];
          $section=$_REQUEST['section'];
          $subjectname=$_REQUEST['subjectname'];
          $detail=$_REQUEST['detail'];
          $Added_by = $_REQUEST['Added_by'];
          
        */
/*
  $session=mysql_real_escape_string($session);
  $school_id=mysql_real_escape_string($school_id);
  // $assignment_type=mysql_real_escape_string($assignment_type);
  $classname=mysql_real_escape_string($classname);
  $section=mysql_real_escape_string($section);
  $subjectname=mysql_real_escape_string($subjectname);
  $detail=mysql_real_escape_string($detail);
  $Added_by =mysql_real_escape_string($Added_by);
  $subjectname=mysql_real_escape_string($subjectname);
  $detail=mysql_real_escape_string($detail);

 */
// upload file start


/*	 $target_dir = "../uploads/assignment/";
            $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
            
         $filename= basename($_FILES["fileToUpload"]["name"]);
  
            move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);		
			
*/


/*
$json = $_POST["usersJSON"];
$data = json_decode($json); 

$image_name=$data->image_name;
$base=$data->image;

*/





/*
if (!isset($myObj)) {
    $myObj = new stdClass();
}

// Decode Image
if ($base != null) {
    $binary = base64_decode($base);
} else {
    $binary = null;
}

header('Content-Type: bitmap; charset=utf-8');
$file_nm = '../../uploads/assignment/' . $image_name;


// Images will be saved under 'meeting_image' folder
$file = fopen($file_nm, 'wb');

// Create File
if ($binary != null) {
    $x = fwrite($file, $binary);
}
fclose($file);
*/




// upload file end
$date = date("Y-m-d");

$msg = "";

if (empty($lnewfile)) {
    $lnewfile = '';

}

if ($classname == "") {
    $msg = "Please enter  classname ";
} /*	elseif($section==""){
		
		$msg="Please enter  section ";
	 }
	 */

elseif ($subjectname == "") {

    $msg = "Please enter  subjectname";
} elseif ($detail == "") {

    $msg = "Please enter  detail";
} else {

    $aryData = array(

        "school_id" => $school_id,
        "session" => $session,
        "class" => $classname,
        "section" => $section,
        "upload_assignment" => $image_name,
        "subject" => $subjectname,
        "detail" => $detail,
        "Added_by" => $Added_by,
        "date" => $date,
        "status" => 1

    );

    //print_r($aryData);die;
    $insert_complain = $db->insertAry("assignment", $aryData);

    //print_r($insert_complain);die;
}

//echo $inser_complain; 

if ($insert_complain > 0) {
    $msg = "Homework Added successfully.!";


}


if ($msg != "") {
    echo json_encode(array('status' => 1, 'msg' => 'Done', "data" => $msg));

} else {
    echo json_encode(array('status' => 0, 'msg' => 'Homework not Added. Please try again later..!'));
}
