<?php

    if (session_status() === PHP_SESSION_NONE) {
        session_start();
    }

    // session_start();
    //flash message helper
    function flash($name = '', $message = '', $class = 'alert alert-success'){
        if(!empty($name)){
            if(!empty($message) && empty($_SESSION[$name])){
                if(!empty($_SESSION[$name])){
                    unset($_SESSION[$name]);
                }

                if(!empty($_SESSION[$name . '_class'])){
                    unset($_SESSION[$name]);
                }

                $_SESSION[$name] = $message;
                $_SESSION[$name . '_class'] = $class;
            }elseif(empty($message) && !empty($_SESSION[$name])){
                $class = !empty($_SESSION[$name . '_class']) ? $_SESSION[$name . '_class'] : ''; 
                echo '<div class="'. $class .'" id="msg-flash">'. $_SESSION[$name]. '</div>';
                unset($_SESSION[$name]);
                unset($_SESSION[$name . '_class']);
            }
        }
    }

    function isLoggedIn(){
        $file  = file_exists('../app/config/install.php');
        if(isset($_SESSION['user_id']) && isset($_SESSION['name']) && $file === true){
            return true;
        }else{
            return false;
        }
    }