<?php 
session_start();
require 'funcs/conexion.php';
require 'funcs/funcs.php';
date_default_timezone_set('America/Mexico_City');
header("Content-Type: text/html;charset=utf-8");

$id_usuario = $_SESSION["id_usuario"];
$sql="SELECT * FROM usuarios WHERE id = '4'";
$result = $mysqli->query($sql); 
$row = $result->fetch_assoc();
$nombre=$row['nombre'];
$rol=$row['rol'];
//Minimo inventario
$sql="SELECT COUNT(*) as minimo FROM `productos` WHERE `pro_cantidad` <= `pro_minimo` and pro_activo = 1 and pro_tipo <> 'servicios'";
$result = $mysqli->query($sql); 
$row = $result->fetch_assoc();
$minimo=$row['minimo'];

if ($rol=='Admo')
 $imagen='admin-avatar.png';
else
 $imagen='doctor.png';

 ?>
<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8">
    <link rel="icon" type="image/png" href="favicon.png">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width initial-scale=1.0">
    <title>Sistema de Control Integral de Audiologica</title>
    <!-- GLOBAL MAINLY STYLES-->
    <link href="./assets/css/dataTables.bootstrap4.min.css" rel="stylesheet" crossorigin="anonymous" />
    <link href="./assets/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link href="./assets/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
    <link href="./assets/vendors/themify-icons/css/themify-icons.css" rel="stylesheet" />
    <!-- PLUGINS STYLES-->
    <link href="./assets/vendors/jvectormap/jquery-jvectormap-2.0.3.css" rel="stylesheet" />
    <!-- THEME STYLES-->
    <link href="assets/css/main.min.css" rel="stylesheet" />
    <!-- PAGE LEVEL STYLES-->
</head>

<body class="fixed-navbar">
    <div class="page-wrapper">
        <!-- START HEADER-->
        <header class="header">
            <div class="page-brand">
                <a class="link" href="inicio.php">
                    <span class="brand">Audio
                        <span class="brand-tip">lógica</span>
                        
                    </span>
                    <span class="brand-mini"><img src="img/logo.png" alt="Audiológica" width="50" height="30"></span>
                </a>
            </div>
            <div class="flexbox flex-1">
                <!-- START TOP-LEFT TOOLBAR-->
                <ul class="nav navbar-toolbar">
                    <li>
                        <a class="nav-link sidebar-toggler js-sidebar-toggler"><i class="ti-menu"></i></a>
                    </li>
                    <li>
                        <form class="navbar-search" action="javascript:;">
                            <div class="rel">
                                
                            </div>
                        </form>
                    </li>
                </ul>
                <!-- END TOP-LEFT TOOLBAR-->
                <!-- START TOP-RIGHT TOOLBAR-->
                <ul class="nav navbar-toolbar">
                    <li class="dropdown dropdown-inbox">
                        <a class="nav-link dropdown-toggle" data-toggle="dropdown"><i class="fa fa-envelope-o"></i>
                            <span class="badge badge-primary envelope-badge"><?php echo $minimo;?></span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-right dropdown-menu-media">
                            <li class="dropdown-menu-header">
                                <div>
                                    <span><strong><?php echo $minimo;?> Advertencias de </strong> Inventario</span>
                                    
                                </div>
                            </li>
                            <li class="list-group list-group-divider scroller" data-height="240px" data-color="#71808f">
                                <div>
                                 <?php
                                 $sql="SELECT * FROM `productos` WHERE `pro_cantidad` <= `pro_minimo` and pro_activo = 1 and pro_tipo <> 'servicios'";
                                 $resultado = mysqli_query($mysqli, $sql);
                                 while($row = mysqli_fetch_array($resultado)) {?>
                                    <a class="list-group-item">
                                        <div class="media">
                                            <div class="media-img">
                                                <img src="./assets/img/<?php if ($row['pro_tipo']=='equipo') echo 'equipo.png'; else echo 'insumo.png';?>" />
                                            </div>
                                            <div class="media-body">
                                                <div class="font-strong"> </div><?php echo $row['pro_nombre']; ?><small class="text-muted float-right"><?php echo 'Existencias '.$row['pro_cantidad']; ?></small>
                                                <div class="font-13"><?php echo $row['pro_descripcion']; ?></div>
                                            </div>
                                        </div>
                                    </a>
                                 <?php } ?>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown dropdown-user">
                        <a class="nav-link dropdown-toggle link" data-toggle="dropdown">
                            <img src="./assets/img/<?php echo $imagen;?>" />
                            <span></span>Usuario<i class="fa fa-angle-down m-l-5"></i></a>
                        <ul class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" href="configuracion.php?id=<?echo $id_usuario;?>"><i class="fa fa-cog"></i>Configuracion</a>
                            <li class="dropdown-divider"></li>
                            <a class="dropdown-item" href="logout.php"><i class="fa fa-power-off"></i>Salir</a>
                        </ul>
                    </li>
                </ul>
                <!-- END TOP-RIGHT TOOLBAR-->
            </div>
        </header>
        <!-- END HEADER-->
        <!-- START SIDEBAR-->
        <nav class="page-sidebar" id="sidebar">
            <div id="sidebar-collapse">
                <div class="admin-block d-flex">
                    <div>
                        <img src="./assets/img/<?php echo $imagen;?>" width="45px" />
                    </div>
                    <div class="admin-info">
                        <div class="font-strong"><?php echo $nombre; ?></div><small><?php echo $rol;?></small></div>
                </div>
                <ul class="side-menu metismenu">
                    <li>
                        <a class="active" href="inicio.php"><i class="sidebar-item-icon fa fa-th-large"></i>
                            <span class="nav-label">Dashboard</span>
                        </a>
                    </li>
                    <li class="heading">MENU</li>
                    <li>
                        <a href="javascript:;"><i class="sidebar-item-icon fa fa-bookmark"></i>
                            <span class="nav-label">Expediente Clinico</span><i class="fa fa-angle-left arrow"></i></a>
                        <ul class="nav-2-level collapse">
                            <li>
                                <a href="pacientes.php">Pacientes</a>
                            </li>
                            <li>
                                <a href="expediente.php">Expediente</a>
                            </li>
                            <li>
                                <a href="estudios.php">Estudios</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a href="javascript:;"><i class="sidebar-item-icon fa fa-edit"></i>
                            <span class="nav-label">Catalogos</span><i class="fa fa-angle-left arrow"></i></a>
                        <ul class="nav-2-level collapse">
                            <li>
                                <a href="insumos.php">Insumos</a>
                            </li>
                            <li>
                                <a href="equipo.php">Equipo</a>
                            </li>
                            <li>
                                <a href="servicios.php">Servicios</a>
                            </li>
                            <li>
                                <a href="referidos.php">Medicos Referidos</a>
                            </li>
                            <li>
                                <a href="contactarnos.php">Forma de contactarnos</a>
                            </li>

                        </ul>
                    </li>
                    
                    <li>
                        <a href="javascript:;"><i class="sidebar-item-icon fa fa-bullhorn"></i>
                            <span class="nav-label">Almacen</span><i class="fa fa-angle-left arrow"></i></a>
                        <ul class="nav-2-level collapse">
                            <li>
                                <a href="inventario.php">Inventario</a>
                            </li>
                            <li>
                                <a href="movimiento.php">Movimientos</a>
                            </li>
                        </ul>
                    </li>

                    <li>
                        <a href="agenda.php"><i class="sidebar-item-icon fa fa-calendar"></i>
                            <span class="nav-label">Agenda</span>
                        </a>
                    </li>
                    
                    <li>
                        <a href="javascript:;"><i class="sidebar-item-icon fa fa-shopping-cart"></i>
                            <span class="nav-label">Venta</span><i class="fa fa-angle-left arrow"></i></a>
                        <ul class="nav-2-level collapse">
                            <li>
                                <a href="ventas.php">Ventas</a>
                            </li>
                            <li>
                                <a href="vpacientes.php">Seleccionar Paciente</a>
                            </li>
                        </ul>
                    </li>
                    

                    <?if($rol=='Admo'){?>
                    <li>
                        <a href="usuarios.php"><i class="sidebar-item-icon fa fa-user-plus"></i>
                            <span class="nav-label">Usuarios</span>
                        </a>
                    </li>
                    <?}?>
 
 
                </ul>
            </div>
        </nav>
        <!-- END SIDEBAR-->