<?php 
require_once 'connect.inc.php';



	function nnot(){
	$i = 0;
	global $con;
	$q = "select * from notice where 1";
	$r = mysqli_query($con,$q);
	while($q_r = mysqli_fetch_assoc($r)){
		$i++;
		$id = $q_r['id'];
		$msg = $q_r['msg'];
		$m = $q_r['m'];
		$email = $q_r['email'];
		
		$tr ='<tr> 
				<td>'.$i.'</td>
				<td>'.$email.'</td>
				<td>'.$msg.'</td>
				<td>'.$m.'</td>
				<td> <form action="" method="POST"> <input name="del" hidden value='.$id.'> <button type="submit" class="btn btn-u btn-danger"><i class="fa fa-bin"></i> Delete </button></form> </td></tr> 
					
					';
					echo $tr;
		
	}
	
}


		if(isset($_POST['del'])){
			$d =$_POST['del'];
			if(!empty($d)){
				$q = "delete from notice where id = '$d' ";
				if(mysqli_query($con,$q)){
				// 	echo '<script> alert("Message Deleted"); </script>';
						$_SESSION['success'] = "Notification Deleted";
						header('location:./');
						die();
				}
			}
		}

if(isset($_POST['act']) && isset($_POST['msg'])){
	
	$id = $_POST['act']; 
	$msg = mysqli_real_escape_string($con,$_POST['msg']); 
	if(!empty($id) && !empty($msg)){
		
			$q = "select email from info where id = '$id'";
			$r = mysqli_query($con,$q);
			$email = mysqli_R($r,0);
			$date=date("d M Y",time());
			
			
			$query = "insert into notice VALUES (NULL,'$msg','$email','$date','1')";
			
			if(mysqli_query($con,$query)){
				// echo '<script> alert("Message sent"); </script>';
					$_SESSION['success'] = "Notification Sent";
					header('location:./');
						die();
			}
			
	
	}
	
}








?>