<?php

session_start();

require '../../config.php';
require '../admin_config.php';
require '../functions.php';

if (isset($_SESSION['user_email'])){

$connect = connect($database);
if(!$connect){
    header('Location: ./error.php');
}

$check_access = check_access($connect);

if ($check_access['user_role'] == 1 || $check_access['user_role'] == 2){
    
    $post_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
    
    if ($post_id > 0) {
        $connect->prepare("DELETE FROM blog_posts WHERE post_id = :id")->execute([':id' => $post_id]);
    }
    
    header('Location: ./blog.php?success=Post deleted successfully');
    exit;
	
}else{
	header('Location:'.SITE_URL);
}

}else{
	header('Location: ./login.php');	
}

?>
