Sindbad~EG File Manager
<?php
/**
* Global Configuration for COP News Portal
*/
// Start session if not already started
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Timezone
date_default_timezone_set('Africa/Accra');
// Application constants
define('APP_NAME', 'COP News Portal');
define('APP_VERSION', '1.0.0');
// Get the base URL dynamically
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$script_name = $_SERVER['SCRIPT_NAME'] ?? '';
$base_path = dirname(dirname($script_name));
if ($base_path === '/' || $base_path === '\\') {
$base_path = '';
}
define('BASE_URL', $protocol . $host . $base_path . '/');
define('UPLOAD_PATH', __DIR__ . '/../uploads/');
define('MAX_FILE_SIZE', 5242880); // 5MB
// Security constants
define('HASH_ALGO', PASSWORD_DEFAULT);
define('SESSION_LIFETIME', 3600); // 1 hour
// Database connection
require_once __DIR__ . '/database.php';
// Utility functions
function sanitize_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function redirect($url) {
// Simple redirect - let browser handle relative paths
header("Location: " . $url);
exit();
}
function is_logged_in() {
return isset($_SESSION['user_id']) && !empty($_SESSION['user_id']);
}
function require_login() {
if (!is_logged_in()) {
redirect('login.php');
}
}
function require_admin() {
require_login();
if ($_SESSION['account_type'] !== 'admin' && $_SESSION['account_type'] !== 'superuser') {
redirect('dashboard.php');
}
}
function require_superuser() {
require_login();
if ($_SESSION['account_type'] !== 'superuser') {
redirect('dashboard.php');
}
}
function get_user_id() {
return $_SESSION['user_id'] ?? null;
}
function get_user_type() {
return $_SESSION['account_type'] ?? null;
}
function flash_message($message, $type = 'info') {
$_SESSION['flash_message'] = $message;
$_SESSION['flash_type'] = $type;
}
function get_flash_message() {
if (isset($_SESSION['flash_message'])) {
$message = $_SESSION['flash_message'];
$type = $_SESSION['flash_type'] ?? 'info';
unset($_SESSION['flash_message'], $_SESSION['flash_type']);
return ['message' => $message, 'type' => $type];
}
return null;
}
function log_audit($action, $table_name, $record_id = null, $old_values = null, $new_values = null) {
try {
$database = new Database();
$conn = $database->getConnection();
$stmt = $conn->prepare("INSERT INTO audit_logs (user_id, action, table_name, record_id, old_values, new_values, ip_address, user_agent) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$user_id = get_user_id();
$ip_address = $_SERVER['REMOTE_ADDR'] ?? '';
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
$old_json = $old_values ? json_encode($old_values) : null;
$new_json = $new_values ? json_encode($new_values) : null;
$stmt->execute([$user_id, $action, $table_name, $record_id, $old_json, $new_json, $ip_address, $user_agent]);
} catch (Exception $e) {
error_log("Audit log error: " . $e->getMessage());
}
}
function get_setting($key, $default = null) {
try {
$database = new Database();
$conn = $database->getConnection();
$stmt = $conn->prepare("SELECT setting_value FROM settings WHERE setting_key = ?");
$stmt->execute([$key]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result ? $result['setting_value'] : $default;
} catch (Exception $e) {
error_log("Settings error: " . $e->getMessage());
return $default;
}
}
function get_site_title() {
return get_setting('site_title', 'COP News Portal');
}
function get_site_logo() {
return get_setting('site_logo', 'assets/images/logo.png');
}
// Auto-load classes
spl_autoload_register(function ($class_name) {
$class_file = __DIR__ . '/../classes/' . $class_name . '.php';
if (file_exists($class_file)) {
require_once $class_file;
}
});
?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists