<?php

session_start();

require '../../config.php';
require '../admin_config.php';
require '../functions.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){

// Get all campaigns with store info
$query = $connect->query("
    SELECT c.*, s.store_title 
    FROM campaigns c
    LEFT JOIN stores s ON c.campaign_store = s.store_id
    ORDER BY c.campaign_order ASC, c.campaign_id DESC
");
$campaigns = $query->fetchAll(PDO::FETCH_ASSOC);

require '../views/header.view.php';
require '../views/campaigns.view.php';
	
}else{
	header('Location:'.SITE_URL);
}

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

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

?>
