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

/*ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);*/

$abc = $_POST['json'];

$idata = json_decode($abc, true);

$session = $idata['session'];
$school_id = $idata['school_id'];
$notice_type = $idata['notice_type'];
$notice_detail = $idata['notice_detail'];
$Added_by = $idata['Added_by'];
$image_name = $idata['image_name'];
$base = $idata['image'];
$date = date("Y-m-d");

$student_list = json_encode($idata['student_list']);

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

header('Content-Type: bitmap; charset=utf-8');
$file_nm = '../../uploads/notice/' . $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);

$lastContentId = $db->getVal("SELECT content_id FROM student_notice ORDER BY id DESC LIMIT 1");
$lastContentId++;

$aryData = array(

    "school_id" => $school_id,
    "session" => $session,
    "date" => $date,
    "notice_type" => $notice_type,
    "upload_notice" => $image_name,
    "notice_detail" => $notice_detail,

    "student_id" => $student_list,

    "Added_by" => $Added_by,
    "status" => 1,
    "type" => 2,

    "content_id" => $lastContentId
);


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

if ($insert_complain > 0) {

    $msg = "Notice Added successfully.!";
}


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

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