<?php
require_once("ConexionMod.php");
require_once("CargoMod.php");
class AreaEnt extends CargoEnt{
	private $idarea,$nomarea;
	public function setIdarea($val){$this->idarea=$val;} public function getIdarea(){return $this->idarea;}
	public function setNomarea($val){$this->nomarea=$val;} public function getNomarea(){return $this->nomarea;}
}
class AreaMod extends CargoMod{
	public function registrarArea($val){
		$sql="insert into area(nomarea) values('".$val->getNomarea()."');";
		$query=mysqli_query(ConexionMod::Conectar(),$sql) or die("Error de registro");
		if($query){
			$obj=new AreaMod();
			$val=$obj->obtenerUltimoId();
			echo $val->getIdarea();
		}
		mysqli_close(ConexionMod::Conectar());
	}
	
	public function obtenerUltimoId(){
		$sql = "SELECT idarea FROM area ORDER BY idarea DESC LIMIT 1;";
		$que = mysqli_query(ConexionMod::Conectar(),$sql);
		$res = mysqli_fetch_row($que);
		$obj = new AreaEnt();
		$obj->setIdarea($res[0]);
		return $obj;
		mysqli_close(ConexionMod::Conectar());
	}
	
	public function autoCompleArea($val){
		$nor=$val->getNomarea();	
		$sql="SELECT * FROM area WHERE nomarea like '%".$nor."%' ORDER BY idarea ASC LIMIT 0,15;";
		$query=mysqli_query(ConexionMod::Conectar(),$sql);
		$i=0;
		if(mysqli_num_rows($query)!=0){
			while($rs=mysqli_fetch_row($query)){
				$arreglo[$i]=new AreaEnt();
				$arreglo[$i]->setIdarea($rs[0]);
				$arreglo[$i]->setNomarea($rs[1]);
				$i++;
			}
			return $arreglo;
		}else{
			return 0;
		}
		mysqli_close(ConexionMod::Conectar());
	}
}
?>