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

?>
<h2>Lavoratori</h2>
<div class="sub_menu">
<form action="" onsubmit="window.location='#lavoratori.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 lavoratori.*,imprese.imp_anagrafica FROM lavoratori 
LEFT JOIN imprese ON lavoratori.imp_cod = imprese.imp_cod
WHERE
lav_anagrafica LIKE '%".$q."%' OR
lav_codfisc = '".$q."'
ORDER BY lav_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:290px;">Impresa</div>
		<div class="clear"><!-- --></div>
	</div>';
	
	while($row = mysql_fetch_array($result)){
		
		echo '
		<a href="javascript:void(0)" onclick="diag(event,700,\'lavoratore_show.php?cod='.$row['lav_cod'].'&noback\',\''.addslashes($row['lav_anagrafica']).'\')" class="tbl_row">
			<div class="tbl_col" style="width:300px;">'.$row['lav_anagrafica'].'</div>
			<div class="tbl_col" style="width:160px;">'.$row['lav_codfisc'].'</div>
			<div class="tbl_col" style="width:290px;">'.$row['imp_anagrafica'].'</div>
			<div class="clear"><!-- --></div>
		</a>
		';
	}
	
	echo naviga("#lavoratori.php",$tot,$limit);
}else{
	echo 'Nessun lavoratore trovato';
}
?>