<?php
function get_personale($user_id=false){
	
	//filtro id
	if($user_id !== false){
		$user_id = intval($user_id);
		$filter_where .= "users.user_id = ".$user_id." AND ";
	}
	
	$servizi_ente = get_ente_servizi();

	//query
	$limit = 50;
	$result = $GLOBALS['mysqli']->query("
	SELECT SQL_CALC_FOUND_ROWS *, users.user_id AS user_id FROM users 
	WHERE ".$filter_where." users.ente_id = ".$_SESSION['user']['ente_id']." AND user_grp = 'per'
	ORDER BY users.user_cognome, users.user_nome 
	LIMIT ". (intval($_GET['p']) * $limit) .",".$limit);
	if($result->num_rows > 0){

		$list['pagination'] = pagination($limit);
		while($row=$result->fetch_assoc()){
			
			$list['list'][$row['user_id']] = $row;
			
			//servizi
			$arr_servizi = array();
			$serv = $row['user_services'];
			if($serv <> NULL){
				$servizi = explode(",",$serv);
				foreach($servizi as $v){
					foreach($servizi_ente as $s)
						if($v == $s['serv_cod'])
							$arr_servizi[$s['serv_cod']] = $s['serv_name'];
				}
				
			}
			$list['list'][$row['user_id']]['servizi'] = $arr_servizi;
		}
		
		//se ho richiesto un'anagrafica rimando solo i dati, e' piu' comodo
		return $user_id ? $list['list'][$user_id] : $list;
	}
	
	return false;
}

function del_personale($user_id){
	
	$result = $GLOBALS['mysqli']->query("DELETE FROM users WHERE user_id = ".$user_id." AND ente_id = ".$_SESSION['user']['ente_id']);
	
}

?>