<?php
include("session.php");
include("../db.php");

switch($_GET['field']){
	case 'tipologiacod':
		$desc = 'Tipologia:';
		$campodesc = 'tipologia';
		$nextfield = 'lavorazionecod';
		break;
	case 'lavorazionecod':
		$desc = '2) Lavorazione:';
		$campodesc = 'lavorazione';
		$nextfield = 'attivitacod';
		break;
	case 'attivitacod':
		$desc = '3) Attivit&agrave;:';
		$campodesc = 'attivita';
		//$nextfield = 'attivitacod';
		break;
}
if($nextfield)
	$onChange = ' onChange="attspec(this,\''.$nextfield.'\')"';
	
$field = $_GET['field'];
$cod = $_REQUEST['cod'];
$source = $_REQUEST['source'];

$result = mysql_query("SELECT * FROM attivitaspec WHERE ".$source." = '".$cod."' AND ".$campodesc." <> '' GROUP BY ".$field);
//echo "SELECT * FROM attivitaspec WHERE ".$source." = '".$cod."' AND ".$campodesc." <> '' GROUP BY ".$field."<br>".$onChange;
if(mysql_num_rows($result) > 0){
	echo $desc.' <select name="'.$field.'"'.$onChange.'>';
	echo '<option></option>';
	while($row = mysql_fetch_array($result))
		echo '<option value="'.$row[$field].'">'.utf8_encode($row[$campodesc]).'</option>';
	echo '</select>';		
}
?>