<?php
session_start();
include 'myfunctions.php';

$tblName="";
$IDc=0;
   foreach($_POST as $key => $value):
		$frmValues[$key]=$value;
		if ($key=='tblName'){$tblName=$value;}
		if ($key=='IDc'){$IDc=$value;}
		if ($key=='PageName'){$PageName=$value;}
		if ($key=='IDcField'){$IDcField=$value;}
   endforeach;
 
 # =======================================
 #   Delete Files
 # ========================================
       $query="SELECT * FROM images WHERE image_group='notes' and image_group_id=".$IDc;	
	$num_rows=RecordsCount($conn,$query);
      $result=mysqli_query($conn, $query);
	  
	while ($rs = mysqli_fetch_array($result)) {
		unlink($rs['location']);
	}
 # =======================================
 #   Delete Records From Image and Notes     
 # ======================================== 
  $sql = "DELETE FROM images WHERE image_group='notes' and image_group_id=".$IDc;	
	if ($conn->query($sql) === TRUE) {
	   #  echo "Record deleted successfully";	
	} else {
	    # echo "Error deleting record: " . $conn->error;
	}	
	
  $sql = "DELETE FROM notes WHERE IDNote=".$IDc;	
	if ($conn->query($sql) === TRUE) { 
		#  echo "Record deleted successfully";	
	} else {
	    # echo "Error deleting record: " . $conn->error;
	}	 
	
setcookie($IDcField, '0' ); // +(10)=10 sec  : 86400 = 1 day
# Close connection
$conn->close();
echo '.'; 
?>
 
<script language="JavaScript" type="text/JavaScript">
 	  window.close();	  
	  window.opener.location.reload();
	//  window.history.go(-2);
	//  location.reload(); 
</script>
 
