<?php

session_start();

require '../../config.php';
require '../admin_config.php';
require '../functions.php';
require '../views/header.view.php';

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

$connect = connect($database);

$check_access = check_access($connect);

if ($check_access['user_role'] == 1 || $check_access['user_role'] == 2){

$siteSettings = getSettings($connect);

// Get all contact messages
$query = "SELECT * FROM contact_messages ORDER BY contact_date DESC";
$result = $connect->query($query);
$messages = [];

if ($result) {
    $messages = $result->fetchAll(PDO::FETCH_ASSOC);
}

// Get statistics
$stats = [
    'total' => count($messages),
    'new' => 0,
    'read' => 0,
    'replied' => 0
];

foreach ($messages as $msg) {
    $stats[$msg['contact_status']]++;
}

require '../views/contact-messages.view.php';

}else{
	
	header('Location:'.SITE_URL);
}

require '../views/footer.view.php';

}else{
	
	header('Location:'.SITE_URL);
}

?>
