<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Superadmin extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->load->model("mgeneral");
        $this->load->library("Funciones");
    }
    public function admindres(){
        $data=array(
            "dres"=>$this->mgeneral->get_dres(),
        );
        $this->funciones->crearInterface(array("superadmin/vadmindres"),array($data));
    }
    public function adminugels(){
        $vistas=array(
            "dialogs/vdialog_ugel",
            "dialogs/vdialog_admin_ugel",
            "superadmin/vadminugels",
        );
        $datas=array(
            array("dres"=>$this->mgeneral->get_dres()),
            array("dres"=>$this->mgeneral->get_dres()),
            array()
        );
        $this->funciones->crearInterface($vistas,$datas);
    }
    public function getugels(){
        $dre=$this->input->post("dre");
        echo "-->".$dre;
        $this->load->view("superadmin/vgetugels",array("ugels"=>$this->mgeneral->get_ugels($dre)));
    }
    public function nueva_ugel(){
        $_POST['ugel_esta_ide']=1;
        $_POST['ugel_sello']="sello_blanco.jpg";
        $_POST['ugel_logo']="sin_logo.jpg";
        $_POST['ugel_sellox']="150";
        $_POST['ugel_selloy']="145";
        $this->mgeneral->insertar("ugel",$_POST);
        $ide=$this->mgeneral->ultimo_id();
        $data=array(
            "form_ugel_ide"=>$ide,
            "form_esta_ide"=>1
        );
        $data["form_nombre"]="ACTIVOS";
        $this->mgeneral->insertar("formas",$data);
        $data["form_nombre"]="JUDICIALES ACTIVOS";
        $this->mgeneral->insertar("formas",$data);
        $data["form_nombre"]="PENSIONISTAS";
        $this->mgeneral->insertar("formas",$data);
        $data["form_nombre"]="JUDICIALES PENSIONISTAS";
        $this->mgeneral->insertar("formas",$data);
        $data["form_nombre"]="SOBREVIVIENTES";
        $this->mgeneral->insertar("formas",$data);
        $data["form_nombre"]="ADICIONAL 1";
        $this->mgeneral->insertar("formas",$data);
        $data["form_nombre"]="ADICIONAL 2";
        $this->mgeneral->insertar("formas",$data);

        /*for($anio=2004;$anio<=2030;$anio++){
            $this->mgeneral->tabla_data($anio,$ide);
        }*/
    }
    public function get_admin_ugel(){
        $data=array(
            "admins"=>$this->mgeneral->get_admins($this->input->post('ugel_ide')),
        );
        $this->load->view("superadmin/vget_admin_ugel",$data);
    }
    public function nuevo_admin_ugel(){
        $user=$this->input->post("usua_user");
        $result=$this->mgeneral->get_data("*","usuarios",array("usua_user = '$user'"));
        $nuevo=0;
        if(count($result)==0){
            $_POST["usua_esta_ide"]=1;
            $_POST["usua_pass"]=$this->input->post("usua_user");
            $_POST["usua_tipo_nombre"]="ADMIN";
            $nuevo=$this->mgeneral->insertar("usuarios",$_POST);
        }
        echo $nuevo;
    }
    public function get_usuario(){
        $user=$this->input->post("usua_user");
        $result=$this->mgeneral->get_data("*","usuarios",array("usua_user = '$user'"));
        if(count($result)==0){
            $data=array(
                "class"=>"text text-success",
                "result"=>"<span class='glyphicon glyphicon-ok'></span> <b>USUARIO DISPONIBLE</b>"
            );
        }
        else{
            $data=array(
                "class"=>"text text-danger",
                "result"=>"<span class='glyphicon glyphicon-remove'></span> <b>USUARIO NO DISPONIBLE</b>"
            );
        }
        echo json_encode($data);
    }
}