<?php
function get_sms($sms_id=false){

	if($sms_id !== false)
		$filter_where .= "sms.sms_id = ".intval($sms_id)." AND ";

	
	if(!$arrFilter['no_limit']){
		$l = 50;
		$limit = "LIMIT ". (intval($_GET['p']) * $l) .",".$l;
	}
	
		
	//query
	$result = $GLOBALS['mysqli']->query("
	SELECT SQL_CALC_FOUND_ROWS *, DATE_FORMAT(sms_dt,'%d/%m/%Y %H:%i') AS sms_date
	FROM sms_archive
	WHERE ".$filter_where." sms_archive.ente_id = ".$_SESSION['user']['ente_id']." 
	ORDER BY sms_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 record specifico, rimando solo i dati, e' piu' comodo
		return $sms_id ? $list['list'][0] : $list;
	}
	
	return false;
}
?>