<?php
include("../../db.php");
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: * ");

//require_once ("../unified_notification.php");

$abc = $_POST['json'];
$idata = json_decode($abc, true);

$id = $idata['teacher_id'];
$session = $idata['session'];
$subject = $idata['subject'];
$details = $idata['details'];
$date = date("Y-m-d");
$image_name = $idata['image_name'];

// $base = $idata['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); 

*/

$date_array = $idata['date_list'];

$conId = $db->getVal("SELECT content_id FROM teacher_leave ORDER BY id DESC LIMIT 1");
if ($conId == '' || $conId == null){
    $conId = 0;
}
$conId += 1;

$aryData = array(
    "teacher_id" => $id,
    "subject" => $subject,
    "details" => $details,
    "image" => $image_name,
    "session" => $session,
  //  "date" => $date,
    "leave_status" => 0,

    "content_id" => $conId
);

foreach ($date_array as $item) {

    $aryData['date'] = $item['leave_date'];
    $aryData['is_half_day'] = $item['is_half_day'];

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

}

if ($insert_complain > 0) {

    $msg = "leave Added successfully.!";

}

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

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