<?php
class HisMovSis{
	var  $tabla = '0';
	var  $modulo = '0';
	var  $tab_afe = '0';
	var  $reg_afe = '0';
	var  $tip_mov = '0';
	var  $obs_mov = '0';
	var  $fec_acc = '0';
	var  $hor_acc = '0';
	var  $usuario = '0';
	
	function HisMovSis($arrData){
		$this->tabla='dxhismovsis';
		$this->resetData($arrData);
		$this->modulo=$this->checkData($arrData['mod'],'NONE');
		$this->tab_afe=$this->checkData($arrData['tabAfe'],'NONE');
	}
	
	function resetData($arrData){
		$this->reg_afe=$this->checkData($arrData['regAfe'],'NONE');
		$this->tip_mov=$this->checkData($arrData['tipMov'],'C');
		$this->obs_mov=$this->checkData($arrData['obsMov'],'NONE');
		$this->tip_mov=$this->checkData($arrData['tipMov'],'C');
		$this->hor_acc=$this->checkData($arrData['horAcc'],date('H:i:s'));
		$this->fec_acc=$this->checkData($arrData['horAcc'],date('Y-m-d'));
		$this->usuario=$this->checkData($arrData['idUsu'],$_SESSION['num_usu']);	
	}
	
	function checkData($data,$default){
		if(isset($data)) 
			$auxData=$data;
		else 
			$auxData=$default;
		if(get_magic_quotes_gpc()) 
			$auxData = stripslashes($auxData);
		return mysqli_real_escape_string($con,$auxData);
	}
	
	function agregar(){
		$sq="INSERT INTO $this->tabla SET modulo='$this->modulo', tab_afe='$this->tab_afe', reg_afe='$this->reg_afe', tip_mov='$this->tip_mov', obs_mov='$this->obs_mov', usuario='$this->usuario', fec_acc='$this->fec_acc', hor_acc='$this->hor_acc'";
		$rs=mysqli_query($GLOBALS['con'] ,$sq);
		if($rs)	return 1;
		else return 0;
	}
	
	function modByUsu(){
		$sq="UPDATE $this->tabla SET modulo='$this->modulo', tab_afe='$this->tab_afe',  reg_afe='$this->reg_afe', tip_mov='$this->tip_mov', obs_mov='$this->obs_mov', usuario='$this->usuario', fec_acc='$this->fec_acc' WHERE usuario='$this->usuario'";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq);
		if($rs)	return 1;
		else return 0;
	}
	
	function getListByUsu(){
		$sq="SELECT * FROM $this->tabla WHERE usuario='$this->usuario' ORDER BY acc_fec, acc_hor, usuario";

		$rs=mysqli_query($GLOBALS['con'] ,$sq);
		if($rs) return $rs;
		else return -1;
	}
	
	function getMySQLError(){
		return 'Error N:' . mysqli_errno($GLOBALS['con']) . ": " . mysqli_error($GLOBALS['con']); 
	}
}	
?>
