<?php
$defaultFolder = '../uploads/';
if (!file_exists($defaultFolder))
    mkdir($defaultFolder, 0777);
include('./dao/auto_load.php');
if (!isset($_SESSION['id_usuario'])) {
    \Dao\Funcoes::redireciona('login.php');
    return;
}
$conecta = new \Conn\MySqlConnect();
$logedUser = new \Dao\Usuarios();
$logedUser->getUsuarioPorId($conecta, $_SESSION['id_usuario']);
if ($logedUser->tipo == 'U') {
    $perm = explode(';', $logedUser->permissoes);
    if ($pagina != 'meus-dados' && $pagina != 'home' && !in_array($pagina, $perm))
        echo '<script type="text/javascript">alert("Você não tem permissão para acessar esta página!");location.replace("./");</script>';
}
?>
<!DOCTYPE html>
<html lang="pt-Br">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>.:: Painel Visual Prime --</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="all,follow">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700">
        <link rel="stylesheet" href="assets/css/custom.min.css">
        <link rel="shortcut icon" href="../img/logo-vp.png" type="image/png">
        <link rel="apple-touch-icon" href="../img/logo-vp.png" type="image/png" sizes="1270x861">
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
            <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
        <!-- jQuery -->
        <script src="assets/js/jquery-3.2.1.min.js"></script>
    </head>
    <body>
        <nav class="side-navbar">
            <div class="side-navbar-wrapper">
                <div class="sidenav-header d-flex align-items-center justify-content-center">
                    <div class="sidenav-header-inner text-center">
                        <?php
                        if ($logedUser->image != '' && file_exists('../uploads/usuarios/' . $logedUser->image))
                            echo '<img src="../uploads/usuarios/' . $logedUser->image . '" alt="person" class="img-fluid rounded-circle">';
                        else
                            echo '<img src="assets/images/pngwing.com.png" alt="person" class="img-fluid rounded-circle">';
                        ?>
                        <h2 class="h5 text-uppercase"><?php echo $logedUser->nome; ?></h2>
                        <span class="text-uppercase"><?php echo ($logedUser->tipo == 'A' ? 'Administrador' : 'Usuário'); ?></span>
                    </div><!--/.sidenav-header-inner -->
                    <div class="sidenav-header-logo">
                        <a href="./" class="brand-small text-center"> <strong>B</strong><strong class="text-primary">D</strong></a>
                    </div><!--/.sidenav-header-logo -->
                </div><!--/.sidenav-header -->
                <div class="main-menu">
                    <ul id="side-main-menu" class="side-menu list-unstyled">                  
                        <li class="<?php echo ($pagina == 'home' ? 'active' : ''); ?>">
                            <a href="./" title="Página Inicial">
                                <i class="fa fa-home"></i>
                                <span>Home</span>
                            </a>
                        </li>
                        <?php
                        foreach ($lst_paginas as $key => $page) {
                            $active = ($pagina == $key) ? 'active' : '';
                            if ($logedUser->tipo == 'U') {
                                $perm = explode(';', $logedUser->permissoes);
                                if (in_array($key, $perm)) {
                                    $active = ($pagina == $key) ? 'active' : '';
                                    echo '<li class="' . $active . '"><a href="' . $key . '.php"><i class="' . $page['icon'] . '"></i><span>' . $page['title'] . '</span></a></li>';
                                }
                            } else {
                                echo '<li class="' . $active . '"><a href="' . $key . '.php"><i class="' . $page['icon'] . '"></i><span>' . $page['title'] . '</span></a></li>';
                            }
                        }
                        ?>
                       <li class="<?php echo ($pagina == 'meus-dados' ? 'active' : ''); ?>">

                            <a href="meus-dados.php" title="Editar Meus Dados">
                                <i class="fa fa-user"></i>
                                <span>Meus Dados</span>
                            </a>
                        </li>
                    </ul><!--/.side-menu -->
                </div><!--/.main-menu -->
            </div><!--/.side-navbar-wrappe -->
        </nav><!--/.side-navbar -->
        <div class="page home-page">
            <header class="header">
                <nav class="navbar">
                    <div class="container-fluid">
                        <div class="navbar-holder d-flex align-items-center justify-content-between">
                            <div class="navbar-header">
                                <a id="toggle-btn" href="#" class="menu-btn"><i class="icon-bars"> </i></a>
                                <a href="./" class="navbar-brand">
                                    <div class="brand-text d-none d-md-inline-block">
                                        <span>PAINEL</span><strong class="text-primary"> ADMINISTRATIVO</strong>
                                    </div><!--/.brand-text -->
                                </a><!--/.navbar-brand -->
                            </div><!--/.navbar-header -->
                            <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                                <li id="notifications" role="presentation" class="nav-item dropdown open">
                                    <a href="javascript:;" class="dropdown-toggle info-number" id="navbar_dropdown" data-toggle="dropdown" aria-expanded="true">
                                        <i class="fa fa-envelope-o"></i>
                                        <span class="badge bg-green">0</span>
                                    </a>
                                    <ul class="dropdown-menu list-unstyled msg_list" role="menu" aria-labelledby="navbar_dropdown" x-placement="bottom-start"></ul>
                                </li>
                                <li class="nav-item"><a href="php/logout.php" class="nav-link logout">Logout<i class="fa fa-sign-out"></i></a></li>
                            </ul>
                        </div>
                    </div>
                </nav>
            </header>