<?php 

require_once "conexion.php";

class ModeloVehiculo {

    static public function MdlMostrarVehiculo($tabla, $item, $valor){

        if($item != null){

            $stmt = Conexion:: conectar()->prepare("SELECT * FROM $tabla WHERE $item = :$item");

            $stmt -> bindParam(":".$item, $valor, PDO::PARAM_STR);
            
            $stmt -> execute();

            return $stmt -> fetch();

        }else {

            $stmt = Conexion:: conectar()->prepare("SELECT * FROM $tabla");
            
            $stmt -> execute();

            return $stmt -> fetchAll();
        }

        $stmt -> close();

        $stmt = null;
    }

    static public function MdlMostrarZonas($tabla, $item, $valor){

        if($item != null){

            $stmt = Conexion:: conectar()->prepare("SELECT * FROM $tabla WHERE $item = :$item ORDER BY id ASC");

            $stmt -> bindParam(":".$item, $valor, PDO::PARAM_STR);
            
            $stmt -> execute();

            return $stmt -> fetch();

        }else {

            $stmt = Conexion:: conectar()->prepare("SELECT * FROM $tabla ORDER BY id ASC");
            
            $stmt -> execute();

            return $stmt -> fetchAll();
        }

        $stmt -> close();

        $stmt = null;
    }


    /** Registro de vehiculo*/

    static public function mdlIngresarVehiculo($tabla, $datos){

        $stmt = Conexion:: conectar()->prepare("INSERT INTO $tabla(marca, placa, estado) VALUES (:marca, :placa, :estado)");
        
        $stmt -> bindParam(":marca", $datos["marca"], PDO::PARAM_STR);
        $stmt -> bindParam(":placa", $datos["placa"], PDO::PARAM_STR);
        $stmt -> bindParam(":estado", $datos["estado"], PDO::PARAM_INT);

        if($stmt -> execute()){
            return "ok";
        }else{
            return "error";
        }
        
        $stmt -> close();

        $stmt = null;

        
    }

    
    static public function mdlIngresarZona($tabla, $datos){

        $stmt = Conexion:: conectar()->prepare("INSERT INTO $tabla(codigo, descripcion) VALUES (:codigo, :descripcion)");
        
        $stmt -> bindParam(":codigo", $datos["codigo"], PDO::PARAM_STR);
        $stmt -> bindParam(":descripcion", $datos["descripcion"], PDO::PARAM_STR);

        if($stmt -> execute()){
            return "ok";
        }else{
            return "error";
        }
        
        $stmt -> close();

        $stmt = null;

        
    }

    static public function mdlEditarVehiculo($tabla, $datos){

        $stmt = Conexion::conectar()->prepare("UPDATE $tabla SET marca = :marca, placa= :placa WHERE id_vehiculo = :id_vehiculo");

        $stmt -> bindParam(":id_vehiculo", $datos["id_vehiculo"], PDO::PARAM_STR);
		$stmt -> bindParam(":marca", $datos["marca"], PDO::PARAM_STR);
        $stmt -> bindParam(":placa", $datos["placa"], PDO::PARAM_STR);
       
		if($stmt -> execute()){

			return "ok";
            
		
		}else{

			return "error";	

		}

		$stmt -> close();

		$stmt = null;

    }

     /*=============================================
	BORRAR VEHICULO
	=============================================*/

	static public function mdlBorrarVehiculo($tabla, $datos){

		$stmt = Conexion::conectar()->prepare("DELETE FROM $tabla WHERE id_vehiculo = :id_vehiculo");

		$stmt -> bindParam(":id_vehiculo", $datos, PDO::PARAM_INT);

		if($stmt -> execute()){

			return "ok";
		
		}else{

			return "error";	

		}

		$stmt -> close();

		$stmt = null;


	}

    static public function mdlEditarZona($tabla, $datos){

        $stmt = Conexion::conectar()->prepare("UPDATE $tabla SET codigo = :codigo, descripcion= :descripcion WHERE id = :id");

        $stmt -> bindParam(":id", $datos["id"], PDO::PARAM_STR);
		$stmt -> bindParam(":codigo", $datos["codigo"], PDO::PARAM_STR);
        $stmt -> bindParam(":descripcion", $datos["descripcion"], PDO::PARAM_STR);
       
		if($stmt -> execute()){

			return "ok";
            
		
		}else{

			return "error";	

		}

		$stmt -> close();

		$stmt = null;

    }

    static public function mdlBorrarZona($tabla, $datos){

		$stmt = Conexion::conectar()->prepare("DELETE FROM $tabla WHERE id = :id");

		$stmt -> bindParam(":id", $datos, PDO::PARAM_INT);

		if($stmt -> execute()){

			return "ok";
		
		}else{

			return "error";	

		}

		$stmt -> close();

		$stmt = null;


	}

  

}