<?php

include_once '../../model/conexion.php';

class ModelIndex {

    private $param = array();
    private $con;

    public function __construct() {
        $this->con = new Conexion();
    }

    public function gestionar($param) {
        $this->param = $param;
        switch ($this->param['param_opcion']) {
            case 'mostrarMenu':
                echo $this->mostrarMenu();
                break;
        }
    }

    private function mostrarMenu() {
        $this->con->cerrarAbrir();

        $sql = "call sp_mostrarMenu(";
        $sql .= "" . $_SESSION['usuario_id_cp'] . ", ";
        $sql .= "1,";
        $sql .= "1)";

        $menu = "";
        $datos = $this->con->consultaRetorno($sql);
        while ($filaGrupo = mysqli_fetch_row($datos)) {
            $menu .= '<li class="bold"><a class="collapsible-header waves-effect waves-cyan "><i class="material-icons dp48">' . $filaGrupo[2] . '</i><span class="menu-title" data-i18n="Invoice">' . $filaGrupo[1] . '</span></a>';
            $menu .= '<div class="collapsible-body">';
            $this->con->cerrarAbrir();
            $sql = "call sp_mostrarMenu(";
            $sql .= "" . $_SESSION['usuario_id_cp'] . ", ";
            $sql .= "" . $filaGrupo[0] . ",";
            $sql .= "2)";
            $datos2 = $this->con->consultaRetorno($sql);
            while ($filaTarea = mysqli_fetch_row($datos2)) {
                $menu .= '<ul class="collapsible collapsible-sub" data-collapsible="accordion">';
                $menu .= '<li><a id="tarea_' . $filaTarea[0] . '" onclick="cargarDivCuerpo(\'' . $filaTarea[2] . '\', \'' . $filaGrupo[1] . '\', \'' . $filaTarea[1] . '\',' . $filaTarea[0] . ')" style="cursor: pointer;"><i class="material-icons">radio_button_unchecked</i><span data-i18n="ChartJS">' . $filaTarea[1] . '</span></a>';
                $menu .= '</li>';
                $menu .= '</ul>';
            }
            $menu .= '</div>';
            $menu .= '</li>';
        }
        return $menu;
    }

}

?>