<?php
include '../connect.php';
session_start();

$idSuratMasuk=$_GET['idSuratMasuk'];
$iduser=$_GET['iduser'];
$staff=strtoupper($_POST['staff']);
$tarikhEdaran=strtoupper($_POST['tarikhEdaran']);
$catatan=strtoupper($_POST['catatan']);
	
$tarikhNew = date("Y-m-d", strtotime($tarikhEdaran));
$ic=$_SESSION["kadPengenalan"];
date_default_timezone_set("Asia/Kuala_Lumpur");			
$date=date('Y-m-d');
$time=date('H:i:sa');

$staffNew = mysqli_real_escape_string($conn,$staff);
$catatanNew = mysqli_real_escape_string($conn,$catatan);

	if($staffNew =="" || $tarikhNew =="")
	{
		mysqli_commit($conn);
		echo "<script>alert('Sila lengkapkan maklumat penting. ');";
		echo "window.location.href = '../ubahsuaiEdaranUser.php?idSuratMasuk=$idSuratMasuk'";
		echo "</script>";
		exit;
		
	}
	else
	{
		$query="INSERT INTO edaran_surat (id_surat_masuk,edaran_kepada,tarikh_edaran, catatan_edaran, id_user)
		VALUES ('".$idSuratMasuk."','".$staffNew."','".$tarikhNew."','".$catatanNew."','".$iduser."')";
		$strQuery = mysqli_query($conn,$query);
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Ubahsuai','Ubahsuai edaran')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>";
					echo "window.location.href = '../ubahsuaiEdaranUser.php?idSuratMasuk=$idSuratMasuk'";
					echo "</script>";
					exit;
				}
				else
				{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				}
			}

			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
			
			
	}


?>

