$success, 'message' => $message, 'data' => $data ]); exit; } function getCurrentUser() { session_start(); if (isset($_SESSION['user_id'])) { $db = getDB(); $stmt = $db->prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$_SESSION['user_id']]); return $stmt->fetch(); } return null; } function isAdmin() { $user = getCurrentUser(); return $user && $user['role'] === 'admin'; } function formatTime($seconds) { $minutes = floor($seconds / 60); $seconds = floor($seconds % 60); return sprintf("%d:%02d", $minutes, $seconds); } function getFileUrl($path) { if (empty($path)) return ''; if (filter_var($path, FILTER_VALIDATE_URL)) return $path; return getenv('APP_URL') . '/uploads/' . ltrim($path, '/'); } function generateSlug($string) { $string = strtolower($string); $string = preg_replace('/[^a-z0-9-]/', '-', $string); $string = preg_replace('/-+/', '-', $string); return trim($string, '-'); } ?>