<?php

//require_once("class.conectar.php");

//class Jefaturas extends Conectar
class Jefatura
{

	private $l_jef=array();
	private $b_jef=array();
	private $b_jefid=array();
	private $b_ujef=array();


		public function listar_jefatura($con)
	{
		$sql="select j_id as id, j_abrev as abrev, j_desc as nom from tb_jefatura";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->l_jef[]=$reg;
		}
			return $this->l_jef;
	}

//buscar_jefatura
		public function buscar_jefatura($con,$nom)
	{
		$sql="select j_id as id, j_abrev as abrev, j_desc as nom
		from tb_jefatura where j_desc='$nom'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->b_jef[]=$reg;
		}
			return $this->b_jef;
	}

	public function buscar_jefaturaxidj($con,$idj)
	{

		$sql="select j_id as id, j_abrev as abrev, j_desc as nom
		from tb_jefatura where j_id='$idj'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->b_jefid[]=$reg;
		}
			return $this->b_jefid;
	}

	public function buscar_ultimoidj($con)
	{

		$sql="select j_id as id, j_abrev as abrev, j_desc as nom
		from tb_jefatura order by j_id desc limit 1";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->b_ujef[]=$reg;
		}
			return $this->b_ujef;
	}

	public function registrar_jefatura($con,$idj,$nom,$abrev)
	{
		$sql ="insert into tb_jefatura value('$idj',upper('$abrev'),upper('$nom'))";
		echo $sql;
		$res=mysqli_query($con, $sql);
	}


	public function modificar_jefatura($con,$idj,$nom,$abrev)
	{
		$sql ="update tb_jefatura set j_desc= '$nom', j_abrev = '$abrev'
		where j_id='$idj'";
		$res=mysqli_query($con, $sql);
	}


	public function eliminar_jefatura($con,$idj)
	{
		$sql="delete from tb_jefatura where j_id='$idj'";
		$res=mysqli_query($con, $sql);
	}

}
?>
