<?php
function get_logs($arrFilter=false){
	if(!empty($_REQUEST)){
		foreach($_REQUEST as $k=>$v)
			$arrFilter[$k] = $v;
	}
	
	//filtro id
	if($arrFilter['flt_userid'])
		$filter_where .= "logs.anagr_id = ".intval($arrFilter['flt_userid'])." AND ";
	
	if(!$arrFilter['no_limit']){
		$l = 50;
		$limit = "LIMIT ". (intval($_GET['p']) * $l) .",".$l;
	}
	
	if(!$arrFilter['showall']){
		$filter_where .= "users.user_grp = 'usr' AND ";
	}
	
		
	//query
	$result = $GLOBALS['mysqli']->query("
	SELECT SQL_CALC_FOUND_ROWS logs.*, DATE_FORMAT(log_dt,'%d/%m/%Y %H:%i') AS dt FROM logs
	LEFT JOIN users ON logs.user_id = users.user_id
	WHERE ".$filter_where." logs.ente_id = ".$_SESSION['user']['ente_id']." 
	ORDER BY log_dt DESC
	".$limit);

	if($result->num_rows > 0){

		if($l)
			$list['pagination'] = pagination($l);
		
		while($row=$result->fetch_assoc())
			$list['list'][] = $row;
		
		//se ho richiesto un'anagrafica rimando solo i dati, e' piu' comodo
		return $list;
	}
	
	return false;
}
?>