<?php
require_once('encrypt.php');
require_once('definition.php');

class routehelper 
{   
    private $db;
    public function __construct(){
        $this->db=Conectar::conexion();
    }
    public function validacion ($token_user,$token,$user){
        $consulta=$this->db->query("SELECT 1 FROM users as u WHERE u.token_user='$token_user' AND u.token='$token' AND u.id_user='$user' AND u.id_status='1' ");
        $consulta2=$consulta->num_rows;
        if ($consulta2 == 0) {
            return false;
        }
        return true;
    }
    public function validacion_agencia ($token_user,$token,$user){
        $consulta=$this->db->query("SELECT 1 FROM agencies as u WHERE u.token_agency='$token_user' AND u.token='$token' AND u.id_agency='$user' AND u.id_status='1' ");
        $consulta2=$consulta->num_rows;
        if ($consulta2 == 0) {
            return false;
        }
        return true;
    }
    public function validacion_adviser ($token_user,$token,$user){
        $consulta=$this->db->query("SELECT 1 FROM advisers as u WHERE u.token_adviser='$token_user' AND u.token='$token' AND u.id_adviser='$user' AND u.id_status='1' ");
        $consulta2=$consulta->num_rows;
        if ($consulta2 == 0) {
            return false;
        }
        return true;
    }
    public function validacion_module ($perfil_usuario,$page_v){
        /*if ($page_v !== "home" && !empty($page_v)) {
            if ($perfil_usuario == "2" || $perfil_usuario == "1") {
                return true;
            }
            $consulta=$this->db->query("SELECT 1 FROM users_permits WHERE name_module='$page_v' AND id_profile='$perfil_usuario'");
            $consulta2=$consulta->num_rows;
            if ($consulta2 == 0) {
                return false;
            }
        }*/
        return true;

    }
    public function validacion_action ($user,$opcion){

        /*if ($user == "2" || $user == "1") {
            return true;
        }else{
            $consulta=$this->db->query("SELECT 1 FROM users_permits as u WHERE u.id_profile='$user' AND u.name_module='$opcion'");
            $consulta2=$consulta->num_rows;
            if ($consulta2 == 0) {
                return false;
            }
            return true;

        }*/

        return true;
    }
    public static function encryptroute($route)
    {
        $per=new encrypthelper();
        $route = $_SESSION['bn_token_global'].'/'.$route ;
        return $per->encode($route);
    }

    public static function encryptroute_agencie($route)
    {
        $per=new encrypthelper();
        $route = $_SESSION['bn_token_global_agencias'].'/'.$route ;
        return $per->encode($route);
    }

    public static function encryptroute_adviser($route)
    {
        $per=new encrypthelper();
        $route = $_SESSION['bn_token_global_advisers'].'/'.$route ;
        return $per->encode($route);
    }

    public static function decryptroute($payload)
    {
        $per=new encrypthelper();
        return $per->decode($payload);
    }

}