<?php
function current_user(){global $pdo; if(empty($_SESSION['uid'])) return null;
    static $u=null; if($u) return $u;
    $s=$pdo->prepare("SELECT * FROM users WHERE id=?"); $s->execute([$_SESSION['uid']]);
    return $u=$s->fetch();
}
function require_login(){if(!current_user()) redirect(BASE_URL.'/public/login.php');}
function require_admin(){$u=current_user(); if(!$u || $u['role']!=='admin') redirect(BASE_URL.'/public/login.php');}
function require_user(){$u=current_user(); if(!$u) redirect(BASE_URL.'/public/login.php');
    if($u['status']==='banned'){session_destroy(); die('আপনার একাউন্ট বন্ধ করা হয়েছে।');}}
