Codice PHP:
//mappa per gli omocodici
$omomap=array("L","M","N","P","Q","R","S","T","U","V");
switch ($datodaestrarre):
case ("data"):
//leggo cifre anno
$yearstr=_substr($codicefiscale,6,1);
$yearstr2=_substr($codicefiscale,7,1);
//correggo eventuale omocodia
$yearstr=(array_search($yearstr,$omomap)!==false?trim(array_search($yearstr,$omomap)):$yearstr);
$yearstr2=(array_search($yearstr2,$omomap)!==false?trim(array_search($yearstr2,$omomap)):$yearstr2);
//ricavo l'anno
$year=1900+intval($yearstr.$yearstr2);
//ricavo il mese
$monthmap=array("a","b","c","d","e","h","l","m","p","r","s","t");
$month=array_search(_strtolower(_substr($codicefiscale,8,1)),$monthmap)+1;
//leggo cifre giorno
$daystr=_substr($codicefiscale,9,1);
$daystr2=_substr($codicefiscale,10,1);
//correggo eventuale omocodia
$daystr=(array_search($daystr,$omomap)!==false?trim(array_search($daystr,$omomap)):$daystr);
$daystr2=(array_search($daystr2,$omomap)!==false?trim(array_search($daystr2,$omomap)):$daystr2);
//ricavo il giorno
$day=intval($daystr.$daystr2);
if ($day>40):
$day=$day-40;
endif;
//$objDebug->Messages="Autofilled value: ".date($widget->MascheraIO,mktime(0,0,0,$month,$day,$year));
$valoretrovato=date($widget->MascheraIO,mktime(0,0,0,$month,$day,$year));
break;
case ("maschio"):
//leggo cifre giorno
$daystr=_substr($codicefiscale,9,1);
$daystr2==_substr($codicefiscale,10,1);
//correggo eventuale omocodia
$daystr=(array_search($daystr,$omomap)!==false?trim(array_search($daystr,$omomap)):$daystr);
$daystr2=(array_search($daystr2,$omomap)!==false?trim(array_search($daystr2,$omomap)):$daystr2);
//ricavo il giorno
$day=intval($daystr.$daystr2);
//è maschi se day < 40
$valoretrovato=(($day>40)?"0":"1");
break;
case ("comune"):
$daticomune=_substr($codicefiscale,11,4);
if (_substr($daticomune,0,1)=="Z"):
//è uno stato estero il comune non lo so
$valoretrovato="";
else:
$valoretrovato=$daticomune;
endif;
//qui devo convertire al l'id del comune se sto riempiendo un campo extid, al nome altrimenti
if ($valoretrovato!=""):
if ($widget->TipoValore=="extid"):
$sSQL="SELECT id FROM comuni WHERE codfisc=\"".$valoretrovato."\"";
else:
$sSQL="SELECT nome FROM comuni WHERE codfisc=\"".$valoretrovato."\"";
endif;
$objConn=ConnessioneHL::Init();
$record=$objConn->OttieniRecord($sSQL);
if (is_array($record)):
if ($widget->TipoValore=="extid"):
$valoretrovato=$record["id"];
else:
$valoretrovato=$record["nome"];
endif;
endif;
endif;
break;
case ("provincia"):
$daticomune=_substr($codicefiscale,11,4);
if (_substr($daticomune,0,1)=="Z"):
//è uno stato estero la provincia non la so
$valoretrovato="";
else:
$valoretrovato=$daticomune;
endif;
//qui devo convertire al l'id della prov se sto riempiendo un campo extid, al nome della prov altrimenti
if ($valoretrovato!=""):
if ($widget->TipoValore=="extid"):
$sSQL="SELECT idprovincia FROM comuni WHERE codfisc=\"".$valoretrovato."\"";
else:
$sSQL="SELECT province.nome as nomeprovincia FROM comuni LEFT JOIN province ON comuni.idprovincia=province.id WHERE codfisc=\"".$valoretrovato."\"";
endif;
$objConn=ConnessioneHL::Init();
$record=$objConn->OttieniRecord($sSQL);
if (is_array($record)):
if ($widget->TipoValore=="extid"):
$valoretrovato=$record["idprovincia"];
else:
$valoretrovato=$record["nomeprovincia"];
endif;
endif;
endif;
break;
case ("stato"):
case ("nazione"):
$valoretrovato="it";
$datistato=_substr($codicefiscale,11,4);
//$objDebug->Messages="Dati stato: ".$datistato;
if (_substr($datistato,0,1)=="Z"):
//è uno stato estero devo guardare nella codifica degli stati esteri
$valoretrovato="ee";
$sSQL="SELECT iso2 FROM nazcodfisc WHERE cod=\"".$datistato."\"";
$objConn=ConnessioneHL::Init();
$record=$objConn->OttieniRecord($sSQL);
if (is_array($record)):
$valoretrovato=$record["iso2"];
endif;
endif;
//qui dovrei convertire all'id numerico della nazione se è un campo extid quello in cui inserisco il valore
if ($widget->TipoValore=="extid"):
$sSQL="SELECT id FROM nazioni WHERE iso2=\"".$valoretrovato."\"";
$objConn=ConnessioneHL::Init();
$record=$objConn->OttieniRecord($sSQL);
if (is_array($record)):
$valoretrovato=$record["id"];
endif;
endif;
break;
case ("check"):
$valoretrovato=_substr($codicefiscale,15,1);
break;