<?php

class TipNiv{
	var  $tabla = '0';
	var  $id_tipniv = '0';
	var  $num_niv = '0';
	var  $id_tipcli = '0';
	var  $por_com = '0';
	var  $cta_con = '0';
	var  $acc_fec = '0';
	var  $acc_hor = '0';
	var  $usuario = '0';
	var  $lastInsId = '0';

	function TipNiv($data){
		$this->tabla='dgtipniv';
		$this->resetData($data);
	}

	function resetData($data){
		$this->id_tipniv=$this->checkData($data['idTipNiv'],'');
		$this->num_niv=$this->checkData($data['numNiv'],'');
		$this->id_tipcli=$this->checkData($data['idTipCli'],'');
		$this->por_com=$this->checkData($data['porCom'],'');
		$this->cta_con=$this->checkData($data['ctaCon'],'');
		$this->acc_fec=$this->checkData($data['accFec'],date('Y-m-d'));
		$this->acc_hor=$this->checkData($data['accHor'],date('H:i:s'));
		$this->usuario=$this->checkData($data['usuario'],$_SESSION['num_usu']);
	}

	function agregar(){
		$sq_create="INSERT INTO $this->tabla SET num_niv='$this->num_niv', id_tipcli='$this->id_tipcli', por_com='$this->por_com', cta_con='$this->cta_con', acc_fec='$this->acc_fec', acc_hor='$this->acc_hor', usuario='$this->usuario'";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_create);
		if($rs){
			$this->lastInsId=mysqli_insert_id();
			return 1;
		}
		else
			return -1;
	}

	function modificar(){
		$sq_update="UPDATE $this->tabla SET num_niv='$this->num_niv', id_tipcli='$this->id_tipcli', por_com='$this->por_com', cta_con='$this->cta_con', acc_fec='$this->acc_fec', acc_hor='$this->acc_hor', usuario='$this->usuario' WHERE id_tipniv='$this->id_tipniv'";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_update);
		if($rs)
			return 1;
		else
			return 0;
	}

	function busReg(){
		$sq_retrieve="SELECT * FROM $this->tabla WHERE id_tipniv='$this->id_tipniv'";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_retrieve);
		if($rs)
			return $rs;
		else
			return 0;
	}

	function eliminar(){
		$sq_delete="DELETE FROM $this->tabla WHERE id_tipniv='$this->id_tipniv'";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_delete);
		if($rs)
			return 1;
		else
			return 0;
	}

	
	function checkData($data,$default){
		if(isset($data)) 
			$auxData=$data;
		else 
			$auxData=$default;
		if(get_magic_quotes_gpc()) 
			$auxData = stripslashes($auxData);
		$auxData=htmlentities($auxData);
		return mysqli_real_escape_string($con,$auxData);
	}

	function getLastInsId(){
		return $this->lastInsId;
	}

	function getMySQLError(){
		return 'Error N:' . mysqli_errno($GLOBALS['con']) . ": " . mysqli_error($GLOBALS['con']); 
	}

}?>