<?php

class TipCli{
	var  $tabla = '0';
	var  $id_tipcli = '0';
	var  $des_tipcli = '0';
	var  $num_pun = '0';
	var  $num_pun_per = '0';	
	var  $cta_con = '0';
	var  $min_per = '0';
	var  $es_rec = '0';
	var  $acc_fec = '0';
	var  $acc_hor = '0';
	var  $usuario = '0';
	var  $lastInsId = '0';

	function TipCli($data){
		$this->tabla='dgtipcli';
		$this->resetData($data);
	}

	function resetData($data){
		$this->id_tipcli=$this->checkData($data['idTipCli'],'');
		$this->des_tipcli=$this->checkData($data['desTipCli'],'');
		$this->num_pun=$this->checkData($data['numPun'],'');
		$this->num_pun_per=$this->checkData($data['numPunPer'],'');		
		$this->cta_con=$this->checkData($data['ctaCon'],'');
		$this->min_per=$this->checkData($data['minPer'],'');
		$this->es_rec=$this->checkData($data['esRec'],'');				
		$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 des_tipcli='$this->des_tipcli', num_pun='$this->num_pun', num_pun_per='$this->num_pun_per', cta_con='$this->cta_con',min_per='$this->min_per',es_rec='$this->es_rec', 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 des_tipcli='$this->des_tipcli', num_pun='$this->num_pun', num_pun_per='$this->num_pun_per', cta_con='$this->cta_con',min_per='$this->min_per',es_rec='$this->es_rec', acc_fec='$this->acc_fec', acc_hor='$this->acc_hor', usuario='$this->usuario' WHERE id_tipcli='$this->id_tipcli'";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_update);
		if($rs)
			return 1;
		else
			return 0;
	}

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

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


	function eliminar(){
		$sq_delete="DELETE FROM $this->tabla WHERE id_tipcli='$this->id_tipcli'";
		
		$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']); 
	}

}
?>