Path : /home/vishqocm/pcib.in/admin/database/
File Upload :
Current File : /home/vishqocm/pcib.in/admin/database/admin_functions.php

<?php
/**
 * Admin Helper Functions
 * Common utility functions for the admin panel
 */

/**
 * Check if the current user has admin privileges
 * Returns true if the user is logged in and has admin or developer role
 * 
 * @return bool
 */
function has_admin_privileges() {
    if (!isset($_SESSION['user_id']) || 
        !isset($_SESSION['role']) || 
        ($_SESSION['role'] !== 'admin' && $_SESSION['role'] !== 'developer' && $_SESSION['role'] !== 'director')) {
        return false;
    }
    return true;
}

/**
 * Verify admin access and redirect if unauthorized
 * 
 * @param string $redirect_url URL to redirect to if unauthorized
 * @return void
 */
function require_admin_privileges($redirect_url = 'login.php') {
    if (!has_admin_privileges()) {
        header("Location: $redirect_url");
        exit;
    }
}

/**
 * Get a user-friendly display name for a role
 * 
 * @param string $role Role identifier
 * @return string User-friendly role name
 */
if (!function_exists('get_role_display_name')) {
    function get_role_display_name($role) {
        switch ($role) {
            case 'admin':
                return 'Administrator';
            case 'developer':
                return 'Developer';
            case 'director':
                return 'Director';
            case 'instructor':
                return 'Instructor';
            case 'student':
                return 'Student';
            default:
                return ucfirst($role);
        }
    }
}
?>