<?php
include("../../includes/session.php");
include("../../includes/db.php");
include("../../includes/functions.php");
include("../../includes/liborders.inc.php");
session(1);

?>
<h2>Imprese</h2>
<div class="sub_menu">
<form action="" onsubmit="window.location='#imprese.php?q=' + $('#q').val(); return false;">
	<input class="text" name="q" id="q" type="text" size="40" maxlength="80" value="<?php echo $_REQUEST['q'];?>" />
    <button class="btn" type="submit">CERCA</button>
</form>
</div>
<?php
$q = addslashes(strip_tags(trim($_REQUEST['q'])));
//elenco imprese
$limit = 50;
$result = mysql_query("
SELECT SQL_CALC_FOUND_ROWS * FROM imprese WHERE
imp_anagrafica LIKE '%".$q."%' OR
imp_codfisc = '".$q."' OR
imp_piva = '".$q."'
ORDER BY imp_anagrafica LIMIT ".intval($_REQUEST['from']).",".$limit);

if(mysql_num_rows($result) > 0){
	
	$r2 = mysql_query("SELECT FOUND_ROWS() AS tot");
	$tot = mysql_result($r2,0,'tot');

	echo '
	<div class="tbl_row tbl_header">
		<div class="tbl_col" style="width:300px;">Anagrafica</div>
		<div class="tbl_col" style="width:160px;">Codice fiscale</div>
		<div class="tbl_col" style="width:110px;">Partita iva</div>
		<div class="tbl_col" style="width:180px;">Citt&agrave;</div>
		<div class="clear"><!-- --></div>
	</div>';
	
	while($row = mysql_fetch_array($result)){
		
		echo '
		<a href="javascript:void(0)" onclick="diag(event,800,\'impresa_show.php?cod='.$row['imp_cod'].'\',\''.addslashes($row['imp_anagrafica']).'\')" class="tbl_row">
			<div class="tbl_col" style="width:300px;">'.$row['imp_anagrafica'].'</div>
			<div class="tbl_col" style="width:160px;">'.$row['imp_codfisc'].'</div>
			<div class="tbl_col" style="width:110px;">'.$row['imp_piva'].'</div>
			<div class="tbl_col" style="width:180px;">'.$row['imp_citta'].'</div>
			<div class="clear"><!-- --></div>
		</a>
		';
	}
	
	echo naviga("#imprese.php",$tot,$limit);
}else{
	echo 'Nessuna impresa trovata';	
}
?>