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

$idSuratMasuk=$_GET['idSuratMasuk'];
$tarikh_resit=strtoupper($_POST['tarikh_resit']);
$perihal1=strtoupper($_POST['perihal1']);
$perihal2=strtoupper($_POST['perihal2']);
$lainlainhal=strtoupper($_POST['lainlainhal']);

$perihal1New = mysqli_real_escape_string($conn,$perihal1);
$perihal2New = mysqli_real_escape_string($conn,$perihal2);
$lainlainhalNew = mysqli_real_escape_string($conn,$lainlainhal);

$tarikhResitNew = date("Y-m-d", strtotime($tarikh_resit));

$ic=$_SESSION["kadPengenalan"];
date_default_timezone_set("Asia/Kuala_Lumpur");			
$date=date('Y-m-d');
$time=date('H:i:sa');
	
	
	if ($_POST['noCek7'] != "")
	{
		
		for($i=0;$i<=7;$i++)
		{
			$noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
			}
			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
	}
	else if ($_POST['noCek6'] != "")
	{
		
		for($i=0;$i<=6;$i++)
		{
			$noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
			}
			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
	}
	else if ($_POST['noCek5'] != "")
	{
		
		for($i=0;$i<=5;$i++)
		{
			$noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
			}
			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
	}
	else if ($_POST['noCek4'] != "")
	{
		
		for($i=0;$i<=4;$i++)
		{
			$noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
			}
			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
	}
	else if ($_POST['noCek3'] != "")
	{
		
		for($i=0;$i<=3;$i++)
		{
			$noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
			}
			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
	}
	else if ($_POST['noCek2'] != "")
	{
		
		for($i=0;$i<=2;$i++)
		{
			$noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
			{
				$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
			}
			else
			{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
			}
	}
	else if ($_POST['noCek1'] != "" )
	{
		for($i=0;$i<=1;$i++)
		{
			 $noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);
		}
		
		if($strQuery) 
		{
			$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
		}
		else
		{
			echo 'MySQL Error: ' . mysqli_error($conn);
			exit;
		}

	}
	else
	{
		for($i=0;$i<=0;$i++)
		{
			 $noCek = strtoupper($_POST['noCek'.$i]);
			$noCekNew = mysqli_real_escape_string($conn,$noCek);
						
			$noResit = strtoupper($_POST['noResit'.$i]);
			$noResitNew = mysqli_real_escape_string($conn,$noResit);
						
			$jumlah = strtoupper($_POST['jumlah'.$i]);
			$jumlahNew = mysqli_real_escape_string($conn,$jumlah);
			
		
			$query="INSERT INTO cek (no_cek,id_surat_masuk,no_resit, jumlah, tarikh_resit,perihal1,perihal2, lain_lain_hal)
			VALUES ('".$noCekNew."','".$idSuratMasuk."','".$noResitNew."','".$jumlahNew."','".$tarikhResitNew."','".$perihal1New."',
			'".$perihal2New."','".$lainlainhalNew."')";
			$strQuery = mysqli_query($conn,$query);

		}
		
		if($strQuery) 
		{
			$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
						VALUES ('$ic','$date','$time','Tambah','Tambah cek')";
				$strQuery1 = mysqli_query($conn,$q4);
				
				if($strQuery1)
				{
					echo "<script>alert('Maklumat cek berjaya disimpan.');";
					echo "window.location.href = '../DashboardAdmin.php';</script>";
					exit;
				}
				else{
					echo 'MySQL Error: ' . mysqli_error($conn);
					exit;
				} 
		}
		else
		{
			echo 'MySQL Error: ' . mysqli_error($conn);
			exit;
		}
	}

	
	?>

