<?php
$input_nome = $_POST['nome'] ;
if ( strlen( $_POST['nome'] ) != 0 )
{
      $input_nome = $_POST['nome'] ;
      $input_cognome = $_POST['cognome'] ;
      $input_giorno = $_POST['giorno'] ;
      $input_mese = $_POST['mese'] ;
      $input_anno = $_POST['anno'] ;
      $input_sesso = $_POST['sesso'] ;
      $input_luogo = $_POST['luogo'] ;
}
else if ( strlen( $_GET['nome'] ) != 0 )
{
      $input_nome = $_GET['nome'] ;
      $input_cognome = $_GET['cognome'] ;
      $input_giorno = $_GET['giorno'] ;
      $input_mese = $_GET['mese'] ;
      $input_anno = $_GET['anno'] ;
      $input_sesso = $_GET['sesso'] ;
      $input_luogo = $_GET['luogo'] ;
}
else
{
      $input_nome = "" ;
      $input_cognome = "" ;
      $input_giorno = "" ;
      $input_mese = 1 ;
      $input_anno = "" ;
      $input_sesso = 0 ;
      $input_luogo = "" ;
}
?>
<script language="Javascript1.2" style="text/css">
function fill_form()
{
<?php
    echo "\tdocument.codfisform.nome.value = \"$input_nome\" ;\n" ;
    echo "\tdocument.codfisform.cognome.value = \"$input_cognome\" ;\n" ;
    echo "\tdocument.codfisform.giorno.value = \"$input_giorno\" ;\n" ;
    echo "\tdocument.codfisform.mese.selectedIndex = ".($input_mese-1)." ;\n" ;
    echo "\tdocument.codfisform.anno.value = \"$input_anno\" ;\n" ;
    echo "\tdocument.codfisform.luogo.value = \"$input_luogo\" ;\n" ;
    echo "\tdocument.codfisform.sesso.selectedIndex = $input_sesso ;\n" ;
?>
}
function cerca_luogo()
{
    var luogo = document.codfisform.luogo.value ;
    if ( luogo.length == 0 )
    {
        alert( 'Impossibile effettuare la ricerca.\n\nIl campo luogo é vuoto !' );
        return ;
    }
    var PHPcmd = "luogo.php?luogo="+luogo ;
    window.open( PHPcmd, 'NewWnd', 'width=200, scrollbars=yes, menubar=no, status=no, location=no' );
}
function checkreset()
{
  var r=confirm("Sei sicuro di voler cancellare i dati ?");
  if (r)
  {
      document.codfisform.nome.value = "";
      document.codfisform.cognome.value = "";
      document.codfisform.giorno.value = "";
      document.codfisform.mese.selectedIndex = 0;
      document.codfisform.anno.value = "";
      document.codfisform.luogo.value = "";
      document.codfisform.sesso.selectedIndex = 0;
  }
}
</script>
<body onLoad="javascript:fill_form();">
<form name="codfisform" method="get" action="index.php" >
<table style="border: solid 1px black;">
<tr><td>NOME : </td><td><input name="nome" type="textbox" size="17" /></td></tr>
<tr><td>COGNOME : </td><td><input name="cognome" type="textbox" size="17" /></td></tr>
<tr><td>DATA DI NASCITA : </td>
    <td>
    <input name="giorno" type="textbox" size="2" />-
    <select name="mese">
        <option value="1">Gennaio
        <option value="2">Febbraio
        <option value="3">Marzo
        <option value="4">Aprile
        <option value="5">Maggio
        <option value="6">Giugno
        <option value="7">Luglio
        <option value="8">Agosto
        <option value="9">Settembre
        <option value="10">Ottobre
        <option value="11">Novembre
        <option value="12">Dicembre
    </select>-
    <input name="anno" type="textbox" size="2" />
    </td>
</tr>
<tr><td>LUOGO DI NASCITA : </td>
    <td>
    <input name="luogo" type="textbox" size="17" />
     
    <input onClick="javascript:cerca_luogo();" name="luogoBtn" type="button" value="?" />
    </td>
</tr>
<tr><td>SESSO : </td>
    <td>
    <select name="sesso">
        <option value="0">M
        <option value="1">F
    </select>
    </td>
</tr>
<tr>
    <td colspan=2 align=center><input type="submit" value="Calcola il Codice Fiscale" /></td>
    <td><input onClick="javascript:checkreset();" type="button" value="reset" /></td>
</tr>
</table>
</form>
<?php
$input_nome = $_POST['nome'] ;
if ( strlen( $input_nome ) == 0 )
{
      $input_nome = $_GET['nome'] ;
      $input_cognome = $_GET['cognome'] ;
      $input_giorno = $_GET['giorno'] ;
      $input_mese = $_GET['mese'] ;
      $input_anno = $_GET['anno'] ;
      $input_sesso = $_GET['sesso'] ;
      $input_luogo = $_GET['luogo'] ;
}
else
{
      $input_cognome = $_POST['cognome'] ;
      $input_giorno = $_POST['giorno'] ;
      $input_mese = $_POST['mese'] ;
      $input_anno = $_POST['anno'] ;
      $input_sesso = $_POST['sesso'] ;
      $input_luogo = $_POST['luogo'] ;
}
require_once(dirname(__FILE__)."/cod_fis.php");
$codfis = new cf();
$codicefiscale = $codfis->estrai_CF( $input_nome, $input_cognome, $input_giorno, $input_mese, $input_anno, $input_sesso, $input_luogo ) ;
if ( strlen( $_POST['nome'] ) != 0 )
{
      echo "NOME : <b>$input_nome</b>      " ;
      echo "COGNOME : <b>$input_cognome</b><br/>" ;
      echo "GIORNO : <b>$input_giorno</b>     " ;
      echo "MESE : <b>".ottieni_mese($input_mese)."</b>     " ;
      echo "ANNO : <b>$input_anno</b><br/>" ;
      echo "SESSO : <b>".( ( $input_sesso == 0 ) ? "Maschile" : "Femminile" )."</b>     " ;
      echo "LUOGO DI NASCITA : <b>$input_luogo</b><br/>" ;
}
if ( $GLOBALS['error_code'] == 0 )
    echo "<br/>CODICE FISCALE : <b>$codicefiscale</b>";
else
{
    echo "<br/>CODICE FISCALE : <font color=red><b>".$GLOBALS['error_str']."</b></font>";
}
?>
</body>