Note

Contenuto del File

## Conversione a PHP 8.3 e utilizzo di PDO

```php
<?php

in
La prima linea della tua risposta deve essere il titolo, rispondi in italiano
converti tutto a php 8.3 e usa pdo invece che mysql
<?php

include("../../firewall.php");

//$_GET   = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);$_POST  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
/* I prefer not to use $_REQUEST...but for those who do: */
//$_REQUEST = (array)$_POST + (array)$_GET + (array)$_REQUEST;

# 
# gestione templates
# 
#if ($eregi != "on") {
//if (eregi("^(.*)(bla\.inc2\.php)(.*)$", $_SERVER['REQUEST_URI'])) {
#	die ("bye.");
#}

  include_once('../adminna/mysql2i.class.php');

$myFile = "templateemailpaypalnotify.htm";
$fh = fopen($myFile, 'r');
$templateemailpaypalnotify = fread($fh, filesize($myFile));
fclose($fh);

$myFile = "condizionilegali.htm";
$fh = fopen($myFile, 'r');
$sellertos = creapagina(fread($fh, filesize($myFile)));
fclose($fh);

$myFile = "templatemandafattura.htm";
$fh = fopen($myFile, 'r');
$emailbasemandafattura = fread($fh, filesize($myFile));
fclose($fh);




#
# comuni
# 

$mip = $_SERVER['REMOTE_ADDR'];
$oggi = date ("Y-m-d H:m:s");
$oggi2 = date ("d-m-Y");
$siteurl="https://www.fatturami.it/iusondemand.com/";

#
# gestione seller
# 

$sellerid = 1;
$annoinizio=date("Y")-3;



include ("account.inc.php");


# 
# accesso database
#  

$db_host = "127.0.0.1";
$db_user = "84-fatturatti";
$db_password = "Gua2BiThr9Y5RqX6";
$db_name = "84-fattur";




#
# gestione errori
#

$errorname="";
$erroraddress="";
$errorcity="";
$errorzip="";
$errorcf="";
$errorpiva="";
$errortos="";
$erroremail="";
$errorcountry="";
$errorprovincia="";


#
# customizzazioni redirect paypal
#

$grazieurl		= strip_tags(stripslashes($_REQUEST["grazieurl"]));
$annullaurl		= strip_tags(stripslashes($_REQUEST["annullaurl"]));
$page_style		= strip_tags(stripslashes($_REQUEST["page_style"]));
$abbmode		= strip_tags(stripslashes($_REQUEST["abbmode"]));
$backup			= strip_tags(stripslashes($_REQUEST["backup"]));


#
# gestione payer buyer
#

$titolo      	  	  = str_replace('"',"'",trim(stripslashes(strip_tags($_REQUEST["titolo"]))));
$causalenonimponibile = str_replace('"',"'",trim(stripslashes(strip_tags($_REQUEST["causalenonimponibile"]))));
$prezzo      	  	  = str_replace(",",".",trim(stripslashes(strip_tags($_REQUEST["prezzo"]))));
if ($causalenonimponibile == "") {$causalenonimponibile = "Non imponibile";}

#paypal supporta solo il punto, non la virgola
$customid      	  = trim(stripslashes(strip_tags($_REQUEST["custom"])));
$salva      	  = trim(stripslashes(strip_tags($_REQUEST["salva"])));
$eu      	 	  = trim(stripslashes(strip_tags($_REQUEST["eu"])));
$ra      		  = trim(stripslashes(strip_tags($_REQUEST["ra"])));
if ($ra !="") {$ra="on";}
$scorp      	  = trim(stripslashes(strip_tags($_REQUEST["scorp"])));

$js      	  = trim(stripslashes(strip_tags($_REQUEST["js"])));
if ($js !="") {$js="on";}

$submit      	  = trim(stripslashes(strip_tags($_REQUEST["submit"])));
$buyername   	  = trim(stripslashes(strip_tags($_REQUEST["buyername"])));
$buyeraddress	  = trim(stripslashes(strip_tags($_REQUEST["buyeraddress"])));
$buyercodicedestinatario	  = trim(stripslashes(strip_tags($_REQUEST["buyercodicedestinatario"])));
$buyerzip    	  = trim(stripslashes(strip_tags($_REQUEST["buyerzip"])));
$buyercity   	  = trim(stripslashes(strip_tags($_REQUEST["buyercity"])));
$email            = trim(stripslashes(strip_tags($_REQUEST["email"])));
$ccemail  	  	  = trim(stripslashes(strip_tags($_REQUEST["ccemail"])));
$buyeremail  	  = trim(stripslashes(strip_tags($_REQUEST["buyeremail"])));
$buyercf     	  = strtoupper(trim(stripslashes(strip_tags($_REQUEST["buyercf"]))));

$_REQUEST["buyerpiva"] = str_ireplace("IT","",$_REQUEST["buyerpiva"]);

$buyerpiva   	  = trim(stripslashes(strip_tags($_REQUEST["buyerpiva"])));
$buyerpay   	  = trim(stripslashes(strip_tags($_REQUEST["buyerpay"])));
$buyertos    	  = trim(stripslashes(strip_tags($_REQUEST["buyertos"])));
$buyertel    	  = trim(stripslashes(strip_tags($_REQUEST["buyertel"])));
$buyercountry  	  = pulisci(substr(strtoupper(trim(stripslashes(strip_tags($_REQUEST["buyercountry"])))),0,3));






if ($buyercountry =="") {$buyercountry     = "IT";}
if (is_numeric($buyershop) != true) {$buyershop=0;}

$fatturadata    	= trim(stripslashes(strip_tags($_REQUEST["fatturadata"])));
$fatturanum			= trim(stripslashes(strip_tags($_REQUEST["fatturanum"])));
$fatturaimponibile	= trim(stripslashes(strip_tags($_REQUEST["fatturaimponibile"])));
$fatturanonimponibile = str_replace(",",".",trim(stripslashes(strip_tags($_REQUEST["fatturanonimponibile"]))));

$fatturaiva			= trim(stripslashes(strip_tags($_REQUEST["fatturaiva"])));
$fatturara			= trim(stripslashes(strip_tags($_REQUEST["fatturara"])));
$fatturainps		= trim(stripslashes(strip_tags($_REQUEST["fatturainps"])));
$fatturatot			= trim(stripslashes(strip_tags($_REQUEST["fatturatot"])));
$fatturaprezzo		= trim(stripslashes(strip_tags($_REQUEST["fatturaprezzo"])));
$fatturalegal		= trim(stripslashes(strip_tags($_REQUEST["fatturalegal"])));

if (strpos($ccemail,";")!== false) {$ccemail="";}
if (strpos($ccemail,",")!== false) {$ccemail="";}
if (strpos($ccemail,"|")!== false) {$ccemail="";}
if (strpos($ccemail,"'")!== false) {$ccemail="";}
if (strpos($ccemail,"&lt;")!== false) {$ccemail="";}
if (strpos($ccemail,"&gt;")!== false) {$ccemail="";}
if (strpos($ccemail,"\"")!== false) {$ccemail="";}
if (strpos($ccemail,"@")=== false) {$ccemail="";}

$da	=	intval(strip_tags(trim(stripslashes($_REQUEST['da'] ))));
$data	=	strip_tags(trim(stripslashes($_REQUEST['data'] )));
$num 	=  	strip_tags(trim(stripslashes($_REQUEST['num'] )));

if (is_numeric($sellerid) != true) {$sellerid=0;}
if (is_numeric($num) != true) {$num=0;}
if (is_numeric($fatturaanno) != true) {$fatturaanno=0;}
if (is_numeric($da)  != true) {$da=0;}
if (is_numeric($data)  != true) {$data=0;}
if (is_numeric($fatturanonimponibile)  != true) {$fatturanonimponibile=0;}

$search		= str_replace("\"","",strip_tags(trim(stripslashes($_REQUEST['search'] ))));
$asearch	= addcslashes($search,"%_;=?'\\");
$name		= trim(stripslashes(strip_tags($_REQUEST["name"])));
$pwd		= trim(stripslashes(strip_tags($_REQUEST["pwd"])));
$qpwd		= "Pertinio.33";
#$sellerloginid 	= $_SESSION['sellerloginid'];

if ($email !="") {$buyeremail=$email;}



######################################################################
# gli ordini verranno inviati via email a $selleremail o $bueyermail
######################################################################

$ordersnotifyemail=$selleremail;

######################################################################


$tmp=strpos($buyername," ");
if ($tmp>0) {
  $buyerfirst=ucfirst(substr($buyername,0,$tmp));
  $buyerlast=ucfirst(substr($buyername,$tmp+1));
} else {
  $buyerfirst=$buyername;
  $buyerlast=$buyername;
}

if (strlen($buyeraddress)>100 ) {
  $buyeraddress2=substr($buyeraddress,100);
  $buyeraddress1=substr($buyeraddress,0,100);
} else {
  $buyeraddress1=$buyeraddress;
  $buyeraddress2="";
};




 
#queste cambiate da efatt.inc.php

$tabella	= "orders";
$campi	= "`id` , `data` , `name` , `address` , `country` , `zip` , `city` , `email` , `cf` , `piva` , `provincia` , `prezzo` , `titolo` , `currency` , `secid`, `sellerid`, `ccemail`, `pay`, `evaso`, `fatturato`, `tel`, `shop`, `abboid`, `note`, `formatotrasmissione`, `codicedestinatario`, `pec`, `context`, `nome`, `cognome`, `denominazione`";
$howmanyfields	= 29;


$tabellapreventivi	= "preventivi";
$campipreventivi	= "`id` , `data` , `name` , `address` , `country` , `zip` , `city` , `email` , `cf` , `piva` , `provincia` , `prezzo` , `titolo` , `currency` , `secid`, `sellerid`, `ccemail`, `pay`, `evaso`, `fatturato`, `tel`, `shop`, `abboid`, `note`, `spese`, `referente`, `num`, `quantita`";
$howmanyfieldspreventivi	= 27; 

$tabellapayment	= "payment";
$campipayment	= "`id` , `data` , `email` , `prezzo` , `titolo` , `secid` , `name` , `txn_id` , `status` , `currency`, `subscr_date`, `recurring_payment_id`, `product_name`,`next_payment_date`,`amount_per_cycle`,`time_created`,`txn_type`,`payer_id`,`initial_payment_txn_id`,`sellerid`";
$howmanyfieldspayment = 19;

$tabellainvoice	= "invoice";
$campiinvoice	= "`id` , `num`, `data` , `name` , `address` , `zip` , `city` , `provincia`, `country` , `piva` , `cf`, `causale`, `prezzo`, `imponibile`, `nonimponibile`, `iva`, `currency`, `sellerid` , `email` , `pay`, `legali`, `ra`, `previdenza`, `fatturanetto`, `causalenonimponibile` ";
$howmanyfieldsinvoice = 24;

$tabellalistino	= "listino";
$campilistino	= "`id` , `sellerid`,`titolo`,`prezzo`,`descrizione`,`destemail`,`url`,`finoal`,`emailattach`,`uniqueid`,`tempurlmaxcounter`,`tempurlmaxdays`,`realurl`,`ipnurl`,`currency`,`page_style`,`annullaurl`,`senderemail`,`sendername`, `abbofreq`, `abbounit` ";
$howmanyfieldslistino = 20;

$tabellaevasi	= "evasi";
$campievasi	= "`id` , `listinoid`,`secid`,`data`,`ip`,`uniqueid`,`paymentid`,brevernd ";
$howmanyfieldsevasi = 7;

$tabellaeventi = "listino";
$campieventi ="`id` , `titolo`,prezzo, `url`,`max`,`email`, `finoal`,`visible`,sellerid, `dove`,`quando`,`contatti`,`cosa`, `destinatari`, `avvisominimo`, autoconferma,dal,tag,`descrizione`,`ripensamento` ";
$howmanyfieldseventi = 19;
$filtrasqleventi = " eventiid = 1 ";

$tabellacheckin	= "checkin";
$campicheckin	= "`id` , `ordersid`, `data`, `userid`, `listinoid` ";
$howmanyfieldscheckin = 4;

$tabellaabbonamenti	= "orders";
$campiabbonamenti	= "`id` , `data` , `name` , `address` , `country` , `zip` , `city` , `email` , `cf` , `piva` , `provincia` , `prezzo` , `titolo` , `currency` , `secid`, `sellerid`, `ccemail`, `pay`, `evaso`, `fatturato`, `tel`, `shop`, `abboid`";
$howmanyfieldsabbonamenti	= 20;

$tabellaabbonati="abbonati";
$campiabbonati="id,last_name,first_name,item_name,custom,subscr_id,subscr_date,payer_email,payer_id,action";
$howmanyfieldsabbonati=9;

$tabellaautori="user";
$campiautori="id,name,email,pwd,query,compensi,paypal,iban,cf,piva,sede,idseller,verified";
$howmanyfieldsautori=12;


$tabellastat="stat";
$campistat="id,datetime,device,type,cnt";
$howmanyfieldsstat=3;

$tabellareferer="statreferer";
$campireferer="id,date,referer,type,cnt";
$howmanyfieldsreferer=4;


$tabellascadenze="scadenze";
$campiscadenze="id,data,gg,mm,aa,causale,prezzo,destemail,nome,preavviso1,preavviso2,preavviso3,testomail,next,finoal,sellerid,note,status";
$howmanyfieldsscadenze=17;

$tabellascadenzelog		="scadenzelog";
$campiscadenzelog		="id,data,idscadenze,testo,note,prezzo,uuid,causale,sellerid";  
$howmanyfieldsscadenzelog=8;


include ("../efatt.inc.php");


#$basesql ="SELECT $campi FROM $tabella WHERE multiblog = '".$sitetitle."' and mdata <='".date("Y-m-d")."' and verified not like '-' and  ";
#$insertsql="INSERT $campi INTO $tabella ";
#$finesql=" multiblog = '".$sitetitle."' and verified not like '-' and mdata <='".date("Y-m-d")."' ORDER BY mdata desc,ID DESC";


#
# funzioni
#


function creapagina($tmp){
global $main,$titolo,$prezzo,$brevernd,$causalenonimponibile;
global $buyername,$buyeraddress,$buyercity,$buyerzip,$buyercf,$buyerpiva,$buyeremail,$buyertel,$buyerpay;
global $buyertos,$buyercountry,$buyerprovincia,$buyerfirst,$buyerlast,$buyeraddress1,$buyeraddress2,$buyershop;
global $sellername,$sellernome,$sellercognome,$sellerpiva,$sellertel,$sellerfax,$selleremail,$sellercurrency,$selleraddress,$sellercity;
global $errorname,$erroraddress,$errorcity,$errorzip,$errorcf,$errorpiva,$errortos,$erroremail,$errorcountry,$errorprovincia, $errorpec;
global $mip,$oggi,$oggi2,$siteurl,$customid,$paystatus,$ccemail,$num,$eu,$ra,$scorp,$desc;
global $fatturadata,$fatturanum,$fatturaimponibile,$fatturasubimponibile,$fatturanonimponibile,$fatturaprezzo,$fatturaiva,$fatturalegal,$fatturatot,$fatturara,$fatturainps,$fatturanetto;
global $lastfattnum,$lastfattemail,$lastfattdata,$lastfattname,$helpemail;
global $sellerivadesc,$selleriva,$sellerannulla,$sellergrazie,$sellerurl,$sellertos,$sellertosurl,$sellerlegal,$sellercap,$sellerrea,$sellercf;
global $sellerra,$sellerradesc,$sellerinps,$sellerinpsdesc,$sellerlogo,$sellerimg,$selleriban,$sellerbank,$mainpaypalemail,$fatturamiurl,$abboprice,$abbounit,$abbofreq;
global $buyerziptype,$buyernametype, $buyeremailtype, $buyeraddresstype, $buyercitytype, $buyercftype, $buyerpivatype, $buyercountrytype;
global $totale,$tempiva,$buyercontext,$context, $buyerpec,$buyercodicedestinatario,$countryselector;


######################
global $errorcountry,$errorprovincia, $errorpec , $sellercap, $sellerrea,$sellercf;
global $sellerra,$sellerradesc,$sellerinps,$sellerinpsdesc, $buyerziptype,$buyernametype, $buyeremailtype, $buyeraddresstype, $buyercitytype, $buyercftype, $buyerpivatype, $buyercountrytype;
global $totale,$tempiva,$buyercontext,$context, $buyerpec,$buyercodicedestinatario,$countryselector;
global $sellerREAUfficio, $sellerNumeroREA, $sellerCapitaleSociale, $sellerSocioUnico,$sellerRegimeFiscale,$sellerStatoLiquidazione,$esellername,$esellernome,$esellercognome;
global $TipoDocumento, $Divisa, $Art73, $eselleriva,$eNatura, $EsigibilitaIVA, $RiferimentoNormativo, $CondizioniPagamento,$ModalitaPagamento,$pagamentiselector,$formatotrasmissione;

global $buyernome, $buyercognome, $buyerdenominazione , $buyerformatotrasmissione , $buyercodicedestinatario, $buyerpec,$PECDestinatario;
 
global $Trasmittentecountry ,$TrasmittenteIdCodice, $ProgressivoInvio ,$formatotrasmissione,$ebuyeriva,$sellerzip,$sellerprovincia,$sellercountry,$ebuyerpivaextraeu,$sellerpuroiban,$sellerbanca;
 
##### Provincia

$listprov["AQ"] = "Aquila";
$listprov["CH"] = "Chieti";
$listprov["PE"] = "Pescara";
$listprov["TE"] = "Teramo";
$listprov["MT"] = "Matera";
$listprov["PZ"] = "Potenza";
$listprov["CZ"] = "Catanzaro";
$listprov["CS"] = "Cosenza";
$listprov["KR"] = "Crotone";
$listprov["RC"] = "Reggio Calabria";
$listprov["VV"] = "Vibo Valentia";
$listprov["AV"] = "Avellino";
$listprov["BN"] = "Benevento";
$listprov["CE"] = "Caserta";
$listprov["NA"] = "Napoli";
$listprov["SA"] = "Salerno";
$listprov["BO"] = "Bologna";
$listprov["FE"] = "Ferrara";
$listprov["FC"] = "Forlì-Cesena";
$listprov["MO"] = "Modena";
$listprov["PR"] = "Parma";
$listprov["PC"] = "Piacenza";
$listprov["RA"] = "Ravenna";
$listprov["RE"] = "Reggio Emilia";
$listprov["RN"] = "Rimini";
$listprov["GO"] = "Gorizia";
$listprov["PN"] = "Pordenone";
$listprov["TS"] = "Trieste";
$listprov["UD"] = "Udine";
$listprov["FR"] = "Frosinone";
$listprov["LT"] = "Latina";
$listprov["RI"] = "Rieti";
$listprov["RM"] = "Roma";
$listprov["VT"] = "Viterbo";
$listprov["GE"] = "Genova";
$listprov["IM"] = "Imperia";
$listprov["SP"] = "la Spezia";
$listprov["SV"] = "Savona";
$listprov["BG"] = "Bergamo";
$listprov["BS"] = "Brescia";
$listprov["CO"] = "Como";
$listprov["CR"] = "Cremona";
$listprov["LC"] = "Lecco";
$listprov["LO"] = "Lodi";
$listprov["MN"] = "Mantova";
$listprov["MI"] = "Milano";
$listprov["MB"] = "Monza e Brianza";
$listprov["PV"] = "Pavia";
$listprov["SO"] = "Sondrio";
$listprov["VA"] = "Varese";
$listprov["AN"] = "Ancona";
$listprov["AP"] = "Ascoli Piceno";
$listprov["FM"] = "Fermo";
$listprov["MC"] = "Macerata";
$listprov["PU"] = "Pesaro e Urbino";
$listprov["CB"] = "Campobasso";
$listprov["IS"] = "Isernia";
$listprov["AL"] = "Alessandria";
$listprov["AT"] = "Asti";
$listprov["BI"] = "Biella";
$listprov["CN"] = "Cuneo";
$listprov["NO"] = "Novara";
$listprov["TO"] = "Torino";
$listprov["VB"] = "Verbano Cusio Ossola";
$listprov["VC"] = "Vercelli";
$listprov["BA"] = "Bari";
$listprov["BT"] = "Barletta-Andria-Trani";
$listprov["BR"] = "Brindisi";
$listprov["FG"] = "Foggia";
$listprov["LE"] = "Lecce";
$listprov["TA"] = "Taranto";
$listprov["CA"] = "Cagliari";
$listprov["CI"] = "Carbonia-Iglesias";
$listprov["VS"] = "Medio Campidano";
$listprov["NU"] = "Nuoro";
$listprov["OG"] = "Ogliastra";
$listprov["OT"] = "Olbia-Tempio";
$listprov["OR"] = "Oristano";
$listprov["SS"] = "Sassari";
$listprov["SU"] = "Sud Sardegna";
$listprov["AG"] = "Agrigento";
$listprov["CL"] = "Caltanissetta";
$listprov["CT"] = "Catania";
$listprov["EN"] = "Enna";
$listprov["ME"] = "Messina";
$listprov["PA"] = "Palermo";
$listprov["RG"] = "Ragusa";
$listprov["SR"] = "Siracusa";
$listprov["TP"] = "Trapani";
$listprov["AR"] = "Arezzo";
$listprov["FI"] = "Firenze";
$listprov["GR"] = "Grosseto";
$listprov["LI"] = "Livorno";
$listprov["LU"] = "Lucca";
$listprov["MS"] = "Massa-Carrara";
$listprov["PI"] = "Pisa";
$listprov["PT"] = "Pistoia";
$listprov["PO"] = "Prato";
$listprov["SI"] = "Siena";
$listprov["BZ"] = "Bolzano";
$listprov["TN"] = "Trento";
$listprov["PG"] = "Perugia";
$listprov["TR"] = "Terni";
$listprov["AO"] = "Val_d'Aosta";
$listprov["BL"] = "Belluno";
$listprov["PD"] = "Padova";
$listprov["RO"] = "Rovigo";
$listprov["TV"] = "Treviso";
$listprov["VE"] = "Venezia";
$listprov["VR"] = "Verona";
$listprov["VI"] = "Vicenza";

asort($listprov);

$selectprovincia = '<select name=buyerprovincia id="iodbuyerprovincia" class="iodinputempty" style="width:300px;"> onClick="controllaordine()" onchange="controllaordine()"  oninput="controllaordine()>';
$selectprovincia .= "\r\n<option value='' $tmps>scegli</option>";
foreach ($listprov as $key => $value) { 
	$tmps="";
	if ($buyerprovincia == $key) {$tmps = " selected";}
	$selectprovincia .= "\r\n<option value='$key' $tmps>$value</option>";
}
$selectprovincia .= "\r\n</select>";



$modpagamento[""] = "nulla";
$modpagamento["MP08"] = "carta di pagamento";
$modpagamento["MP01"] = "contanti";
$modpagamento["MP02"] = "assegno";
$modpagamento["MP03"] = "assegno circolare";
$modpagamento["MP04"] = "contanti presso Tesoreria";
$modpagamento["MP05"] = "bonifico";
$modpagamento["MP06"] = "vaglia cambiario";
$modpagamento["MP07"] = "bollettino bancario";
$modpagamento["MP09"] = "RID";
$modpagamento["MP10"] = "RID utenze";
$modpagamento["MP11"] = "RID veloce";
$modpagamento["MP12"] = "RIBA";
$modpagamento["MP13"] = "MAV";
$modpagamento["MP14"] = "quietanza erario";
$modpagamento["MP15"] = "giroconto su conti di contabilità speciale";
$modpagamento["MP16"] = "domiciliazione bancaria";
$modpagamento["MP17"] = "domiciliazione postale";
$modpagamento["MP18"] = "bollettino di c/c postale";
$modpagamento["MP19"] = "SEPA Direct Debit";
$modpagamento["MP20"] = "SEPA Direct Debit CORE";
$modpagamento["MP21"] = "SEPA Direct Debit B2B";
$modpagamento["MP22"] = "Trattenuta su somme già riscosse";

//echo "<li>$buyerpay";

$selectmodalitapagamento = '<select name=ModalitaPagamento id="iodbuyermodalitapagamento" class="iodinputempty" >';
foreach ($modpagamento as $key => $value) { 
	$tmps="";
	if ($ModalitaPagamento == $key or strtolower($buyerpay) == strtolower($value) ) {$tmps = " selected";}
	$selectmodalitapagamento .= "\r\n<option value='$key' $tmps>$value</option>";
}
if ($buyerpay == "") {$buyerpay = "paypal";}
if ($buyerpay == "-") {$buyerpay = "paypal";}
if (strtolower($buyerpay) == "paypal" ) {$key="MP08"; $value="PayPal"; $tmps = " selected";}
$selectmodalitapagamento .= "\r\n<option value='$key' $tmps>$value</option>";
$selectmodalitapagamento .= "\r\n</select>";


$tmp=str_replace("--selectprovincia--"			,$selectprovincia,$tmp);
$tmp=str_replace("--selectmodalitapagamento--"	,$selectmodalitapagamento,$tmp);
$tmp=str_replace("--etitolo--"					,$titolo,$tmp);

$tmp=str_replace("--TipoDocumento--"			,$TipoDocumento,$tmp);
$tmp=str_replace("--Divisa--"					,$Divisa,$tmp);
$tmp=str_replace("--Art73--"					,$Art73,$tmp);
$tmp=str_replace("--eNatura--"					,$eNatura,$tmp);
$tmp=str_replace("--eselleriva--"				,$eselleriva,$tmp);
$tmp=str_replace("--ebuyeriva--"				,$ebuyeriva,$tmp);

$tmp=str_replace("--Trasmittentecountry--"		,$Trasmittentecountry,$tmp);
$tmp=str_replace("--TrasmittenteIdCodice--"		,$TrasmittenteIdCodice,$tmp);
$tmp=str_replace("--ProgressivoInvio--"			,$ProgressivoInvio,$tmp);
$tmp=str_replace("--FormatoTrasmissione--"		,$formatotrasmissione,$tmp);

$tmp=str_replace("--EsigibilitaIVA--"			,$EsigibilitaIVA,$tmp);
$tmp=str_replace("--CondizioniPagamento--"		,$CondizioniPagamento,$tmp);
$tmp=str_replace("--ModalitaPagamento--"		,$ModalitaPagamento,$tmp);

$codtipodocument["TD01"]= "Fattura";
$codtipodocument["TD02"]= "Acconto/anticipo su fattura";
$codtipodocument["TD03"]= "Acconto/anticipo su parcella";
$codtipodocument["TD04"]= "Nota di credito";
$codtipodocument["TD05"]= "Nota di debito";
$codtipodocument["TD06"]= "Parcella";
$codtipodocument["TD20"]= "Autofattura";
$codtipodocument["TD07"]= "Fattura semplificata";
$codtipodocument["TD08"]= "Nota di Credito semplificata";
$codtipodocument["TD10"]= "Fattura per acquisto intracomunitario beni";
$codtipodocument["TD11"]= "Fattura per acquisto intracomunitario servizi";
$codtipodocument["TD12"]= "Documento riepilogativo (art.6, DPR 695/1996)";

$tipodocumentotxt = "";
foreach ($codtipodocument as $key => $value) {
	if ($key == $TipoDocumento) {
		$tipodocumentotxt = $value;
	}
}
$tmp=str_replace("--tipodocumentotxt--"		,$tipodocumentotxt,$tmp);


$tmp=str_replace("--pagamentiselector--"		,$pagamentiselector,$tmp);
$tmp=str_replace("--formatotrasmissione--"		,$formatotrasmissione,$tmp);
$tmp=str_replace("--buyernome--"				,$buyernome,$tmp);
$tmp=str_replace("--buyercognome--"				,$buyercognome,$tmp);
$tmp=str_replace("--buyerdenominazione--"		,$buyerdenominazione,$tmp);
$tmp=str_replace("--buyerformatotrasmissione--"	,$buyerformatotrasmissione,$tmp);
$tmp=str_replace("--buyercodicedestinatario--"	,$buyercodicedestinatario,$tmp);
$tmp=str_replace("--CodiceDestinatario--"		,$buyercodicedestinatario,$tmp);
$tmp=str_replace("--PECDestinatario--"			,$PECDestinatario,$tmp);
$tmp=str_replace("--buyerpec--"					,$buyerpec,$tmp);
$tmp=str_replace("--buyercontext--"				,$buyercontext,$tmp);
$tmp=str_replace("--buyercodicedestinatario--"	,$buyercodicedestinatario,$tmp);

$tmp=str_replace("--sellerra--"					,$sellerra,$tmp);
$tmp=str_replace("--sellerradesc--"				,$sellerradesc,$tmp);
$tmp=str_replace("--sellerinps--"				,$sellerinps,$tmp);
$tmp=str_replace("--sellerinpsdesc--"			,$sellerinpsdesc,$tmp);


$tmp=str_replace("--sellerprovincia--"			,$sellerprovincia,$tmp);
$tmp=str_replace("--sellercountry--"			,$sellercountry,$tmp);
$tmp=str_replace("--sellerSocioUnico--"			,$sellerSocioUnico,$tmp);
$tmp=str_replace("--sellerCapitaleSociale--"	,$sellerCapitaleSociale,$tmp);
$tmp=str_replace("--sellerREAUfficio--"			,$sellerREAUfficio,$tmp);
$tmp=str_replace("--sellerNumeroREA--"			,$sellerNumeroREA,$tmp);
$tmp=str_replace("--sellerRegimeFiscale--"		,$sellerRegimeFiscale,$tmp);
$tmp=str_replace("--sellerStatoLiquidazione--"	,$sellerStatoLiquidazione,$tmp);
$tmp=str_replace("--sellercap--"				,$sellercap		,$tmp);
$tmp=str_replace("--sellerzip--"				,$sellerzip		,$tmp);
$tmp=str_replace("--sellercf--"					,$sellercf		,$tmp);
$tmp=str_replace("--sellerrea--"				,$sellerrea		,$tmp);
$tmp=str_replace("--sellerpuroiban--"			,$sellerpuroiban		,$tmp);
$tmp=str_replace("--sellerbanca--"				,$sellerbanca		,$tmp);


$tmp=str_replace("--speseesenti--"		,"
     <DettaglioLinee>
        <NumeroLinea>2</NumeroLinea>
        <Descrizione>--causalenonimponibile--</Descrizione>
        <Quantita>1.00</Quantita>
        <PrezzoUnitario>--efatturanonimponibile--</PrezzoUnitario>
        <PrezzoTotale>--efatturanonimponibile--</PrezzoTotale>
        <AliquotaIVA>0.00</AliquotaIVA>
        <Natura>N1</Natura>
      </DettaglioLinee>",$tmp); 


$tmp=str_replace("--riepilogoesenti--"		,"
      <DatiRiepilogo>
        <AliquotaIVA>0.00</AliquotaIVA>
        <Natura>N1</Natura>
        <ImponibileImporto>--efatturanonimponibile--</ImponibileImporto>
        <Imposta>0.00</Imposta>
        <RiferimentoNormativo>Escluso Art. 15 DPR 633/72</RiferimentoNormativo>
      </DatiRiepilogo>",$tmp); 



	
$tmp=str_replace("--efatturadata--"		,substr($fatturadata,-4,4)."-".substr($fatturadata,3,2)."-".substr($fatturadata,0,2),$tmp);
$tmp=str_replace("--efatturaanno--"				,substr($fatturadata,-4,4)	,$tmp);
$tmp=str_replace("--efattura2anno--"			,substr($fatturadata,-2,2)	,$tmp);

$tmp=str_replace("--efatturaprezzo--"			,str_replace("," , "." , $fatturaprezzo),$tmp);
$tmp=str_replace("--efatturasubimponibile--"	,str_replace("," , "." , $fatturasubimponibile),$tmp);
$tmp=str_replace("--efatturaimponibile--"		,str_replace("," , "." , $fatturaimponibile),$tmp);
$tmp=str_replace("--efatturanonimponibile--"	,str_replace("," , "." , $fatturanonimponibile),$tmp);
$tmp=str_replace("--efatturaiva--"				,str_replace("," , "." , $fatturaiva),$tmp);
$tmp=str_replace("--efatturatot--"				,str_replace("," , "." , $fatturatot),$tmp);
$tmp=str_replace("--efatturara--"				,str_replace("," , "." , $fatturara),$tmp);
$tmp=str_replace("--efatturainps--"				,str_replace("," , "." , $fatturainps),$tmp);
$tmp=str_replace("--efatturanetto--"			,str_replace("," , "." , $fatturanetto),$tmp);


$tmp=str_replace("--esellername--"		,iconv("UTF-8", "UTF-8//IGNORE", $esellername) ,$tmp);
$tmp=str_replace("--esellernome--"		,iconv("UTF-8", "UTF-8//IGNORE", $esellernome) ,$tmp);
$tmp=str_replace("--esellercognome--"	,iconv("UTF-8", "UTF-8//IGNORE", $esellercognome) ,$tmp);
$tmp=str_replace("--eselleriva--"		,iconv("UTF-8", "UTF-8//IGNORE", $eselleriva) ,$tmp);
$tmp=str_replace("--ebuyerpivaextraeu--"		,iconv("UTF-8", "UTF-8//IGNORE", $ebuyerpivaextraeu) ,$tmp);




#########################


$fatturaanno=substr($fatturadata,6,4);



$tmp=str_replace("--main--",$main,$tmp);
$tmp=str_replace("--causalenonimponibile--",$causalenonimponibile,$tmp);
$tmp=str_replace("--titolo--",$titolo,$tmp);
$tmp=str_replace("--prezzo--",$prezzo,$tmp);
$tmp=str_replace("--tempiva--",$tempiva,$tmp);
$tmp=str_replace("--totale--",$totale,$tmp);
$tmp=str_replace("--title--",$titolo,$tmp);
$tmp=str_replace("--price--",$prezzo,$tmp);
$tmp=str_replace("--context--",$context,$tmp);
$tmp=str_replace("--ip--",$mip,$tmp);
$tmp=str_replace("--num--",$num,$tmp);
$tmp=str_replace("--ra--",$ra,$tmp);
$tmp=str_replace("--scorp--",$scorp,$tmp);
$tmp=str_replace("--countryselector--",$countryselector,$tmp);
$tmp=str_replace("--eu--",$eu,$tmp);
if ($eu!="") {
	$tmp=str_replace("--eucheck--"," checked",$tmp);
} else {
	$tmp=str_replace("--eucheck--"," ",$tmp);
}
$tmp=str_replace("--desc--"		,$desc,$tmp);
$tmp=str_replace("--date--"		,$oggi,$tmp);
$tmp=str_replace("--oggi--"		,$oggi2,$tmp);
$tmp=str_replace("--siteurl--"	,$siteurl,$tmp);
$tmp=str_replace("--paystatus--",$paystatus,$tmp);
$tmp=str_replace("--ccemail--"	,$ccemail,$tmp);
$tmp=str_replace("--brevernd--"	,$brevernd,$tmp);
$tmp=str_replace("--downloadid--",$brevernd,$tmp);
$tmp=str_replace("--secid--"	,$customid,$tmp);
$tmp=str_replace("--customid--"	,$customid,$tmp);
$tmp=str_replace("--email--"	,$buyeremail,$tmp);
$tmp=str_replace("--shop--"		,$buyershop,$tmp);


 
$tmp=str_replace("--buyername--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyername	),$tmp);
$tmp=str_replace("--buyerfirst--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyerfirst	),$tmp);
$tmp=str_replace("--buyerlast--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyerlast	),$tmp);
$tmp=str_replace("--buyeraddress--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyeraddress	),$tmp);
$tmp=str_replace("--buyeraddress1--" ,iconv("UTF-8", "UTF-8//IGNORE", $buyeraddress1),$tmp);
$tmp=str_replace("--buyeraddress2--" ,iconv("UTF-8", "UTF-8//IGNORE", $buyeraddress2),$tmp);
$tmp=str_replace("--buyercity--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyercity	),$tmp);
$tmp=str_replace("--buyerzip--"		 ,iconv("UTF-8", "UTF-8//IGNORE", $buyerzip		),$tmp);
$tmp=str_replace("--buyercf--"		 ,iconv("UTF-8", "UTF-8//IGNORE", $buyercf		),$tmp);
$tmp=str_replace("--buyeriva--"		 ,iconv("UTF-8", "UTF-8//IGNORE", $buyerpiva	),$tmp);
$tmp=str_replace("--buyerpiva--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyerpiva	),$tmp);
$tmp=str_replace("--buyeremail--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyeremail	),$tmp);
$tmp=str_replace("--buyertel--"		 ,iconv("UTF-8", "UTF-8//IGNORE", $buyertel		),$tmp);
$tmp=str_replace("--buyerpay--"		 ,iconv("UTF-8", "UTF-8//IGNORE", $buyerpay		),$tmp);
$tmp=str_replace("--buyertos--"		 ,iconv("UTF-8", "UTF-8//IGNORE", $buyertos		),$tmp);
$tmp=str_replace("--buyercountry--"	 ,iconv("UTF-8", "UTF-8//IGNORE", $buyercountry	),$tmp);
$tmp=str_replace("--buyerprovincia--",iconv("UTF-8", "UTF-8//IGNORE", $buyerprovincia),$tmp);


$tmp=str_replace("--buyernametype--"	 ,iconv("UTF-8", "UTF-8//IGNORE",$buyernametype		),$tmp);
$tmp=str_replace("--buyeraddresstype--"	 ,iconv("UTF-8", "UTF-8//IGNORE",$buyeraddresstype	),$tmp);
$tmp=str_replace("--buyercitytype--"	 ,iconv("UTF-8", "UTF-8//IGNORE",$buyercitytype		),$tmp);
$tmp=str_replace("--buyerziptype--"		 ,iconv("UTF-8", "UTF-8//IGNORE",$buyerziptype		),$tmp);
$tmp=str_replace("--buyercftype--"		 ,iconv("UTF-8", "UTF-8//IGNORE",$buyercftype		),$tmp);
$tmp=str_replace("--buyerpivatype--"	 ,iconv("UTF-8", "UTF-8//IGNORE",$buyerpivatype		),$tmp);
$tmp=str_replace("--buyeremailtype--"	 ,iconv("UTF-8", "UTF-8//IGNORE",$buyeremailtype	),$tmp);
$tmp=str_replace("--buyercountrytype--"	 ,iconv("UTF-8", "UTF-8//IGNORE",$buyercountrytype	),$tmp);
$tmp=str_replace("--buyerprovinciatype--",iconv("UTF-8", "UTF-8//IGNORE",$buyerprovinciatype),$tmp);
$tmp=str_replace("--buyerpectype--"		 ,iconv("UTF-8", "UTF-8//IGNORE",$buyerpectype		),$tmp);


$tmp=str_replace("--sellername--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellername		),$tmp);
$tmp=str_replace("--sellernome--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellernome		),$tmp);
$tmp=str_replace("--sellercognome--"	,iconv("UTF-8", "UTF-8//IGNORE",$sellercognome	),$tmp);
$tmp=str_replace("--sellerpiva--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellerpiva		),$tmp);
$tmp=str_replace("--selleriva--"		,iconv("UTF-8", "UTF-8//IGNORE",$selleriva		),$tmp);
$tmp=str_replace("--sellerivadesc--"	,iconv("UTF-8", "UTF-8//IGNORE",$sellerivadesc	),$tmp);
$tmp=str_replace("--sellertel--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellertel		),$tmp);
$tmp=str_replace("--sellerfax--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellerfax		),$tmp);
$tmp=str_replace("--selleraddress--"	,iconv("UTF-8", "UTF-8//IGNORE",$selleraddress	),$tmp);
$tmp=str_replace("--sellercity--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellercity		),$tmp);
$tmp=str_replace("--sellercurrency--"	,iconv("UTF-8", "UTF-8//IGNORE",$sellercurrency	),$tmp);
$tmp=str_replace("--selleremail--"		,iconv("UTF-8", "UTF-8//IGNORE",$selleremail	),$tmp);
$tmp=str_replace("--sellerlogo--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellerlogo		),$tmp);
$tmp=str_replace("--sellerimg--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellerimg		),$tmp);
$tmp=str_replace("--selleriban--"		,iconv("UTF-8", "UTF-8//IGNORE",$selleriban		),$tmp);
$tmp=str_replace("--sellerbank--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellerbank		),$tmp);
$tmp=str_replace("--sellerbanca--"		,iconv("UTF-8", "UTF-8//IGNORE",$sellerbanca		),$tmp);





$tmp=str_replace("--sellerlegal--"		,$sellerlegal,$tmp);

$tmp=str_replace("--sellertos--"		,$sellertos,$tmp);
$tmp=str_replace("--sellertosurl--"		,$sellertosurl,$tmp);
$tmp=str_replace("--sellerurl--"		,$sellerurl,$tmp);
$tmp=str_replace("--sellerpaypalgrazie--",$sellerpaypalgrazie,$tmp);
$tmp=str_replace("--sellerpaypalannulla--",$sellerpaypalannulla,$tmp);


$tmp=str_replace("--errorname--",$errorname,$tmp);
$tmp=str_replace("--erroraddress--",$erroraddress,$tmp);
$tmp=str_replace("--errorcity--",$errorcity,$tmp);
$tmp=str_replace("--errorzip--",$errorzip,$tmp);
$tmp=str_replace("--errorcf--",$errorcf,$tmp);
$tmp=str_replace("--errorpiva--",$errorpiva,$tmp);
$tmp=str_replace("--errortos--",$errortos,$tmp);
$tmp=str_replace("--erroremail--",$erroremail,$tmp);
$tmp=str_replace("--errorcountry--",$errorcountry,$tmp);
$tmp=str_replace("--errorprovincia--",$errorprovincia,$tmp);
$tmp=str_replace("--errorpec--",$errorpec,$tmp);
$tmp=str_replace("--errortitolo--","",$tmp);
$tmp=str_replace("--errorprice--","",$tmp);

$tmp=str_replace("--fatturaprezzo--",$fatturaprezzo,$tmp);
$tmp=str_replace("--fatturasubimponibile--",$fatturasubimponibile,$tmp);
$tmp=str_replace("--fatturaimponibile--",$fatturaimponibile,$tmp);
$tmp=str_replace("--fatturanonimponibile--",$fatturanonimponibile,$tmp);
$tmp=str_replace("--fatturaiva--",$fatturaiva,$tmp);
$tmp=str_replace("--fatturadata--",$fatturadata,$tmp);
$tmp=str_replace("--fatturaanno--",$fatturaanno,$tmp);
$tmp=str_replace("--fatturanum--",$fatturanum,$tmp);
$tmp=str_replace("--fatturalegal--",$fatturalegal,$tmp);
$tmp=str_replace("--fatturatot--",$fatturatot,$tmp);
$tmp=str_replace("--fatturara--",$fatturara,$tmp);
$tmp=str_replace("--fatturainps--",$fatturainps,$tmp);
$tmp=str_replace("--fatturanetto--",$fatturanetto,$tmp);


$tmp=str_replace("--helpemail--",$helpemail,$tmp);
$tmp=str_replace("--mainpaypalemail--",$mainpaypalemail,$tmp);
$tmp=str_replace("--fatturamiurl--",$fatturamiurl,$tmp);
$tmp=str_replace("--lastfattnum--",$lastfattnum,$tmp);

$tmp1=$lastfattnum+1;
if ( substr($lastfattdata,-4,4) != date("Y") ) {$tmp1=1;}
$tmp=str_replace("--newfattnum--",$tmp1,$tmp);

$tmp=str_replace("--lastfattdata--",$lastfattdata,$tmp);
$tmp=str_replace("--lastfattemail--",$lastfattemail,$tmp);
$tmp=str_replace("--lastfattname--",$lastfattname,$tmp);

$tmp=str_replace("--abboprice--",$abboprice,$tmp);
$tmp=str_replace("--abbounit--",$abbounit,$tmp);
$tmp=str_replace("--abbofreq--",$abbofreq,$tmp);

return $tmp;
}


function creapaginaOLD($tmp){
global $main,$titolo,$prezzo,$brevernd,$causalenonimponibile;
global $buyername,$buyeraddress,$buyercity,$buyerzip,$buyercf,$buyerpiva,$buyeremail,$buyertel,$buyerpay;
global $buyertos,$buyercountry,$buyerprovincia,$buyerfirst,$buyerlast,$buyeraddress1,$buyeraddress2,$buyershop;
global $sellername,$sellerpiva,$sellertel,$sellerfax,$selleremail,$sellercurrency,$selleraddress,$sellercity;
global $errorname,$erroraddress,$errorcity,$errorzip,$errorcf,$errorpiva,$errortos,$erroremail,$errorcountry,$errorprovincia;
global $mip,$oggi,$oggi2,$siteurl,$customid,$paystatus,$ccemail,$num,$eu,$ra,$scorp,$desc;
global $fatturadata,$fatturanum,$fatturaimponibile,$fatturasubimponibile,$fatturanonimponibile,$fatturaprezzo,$fatturaiva,$fatturalegal,$fatturatot,$fatturara,$fatturainps,$fatturanetto;
global $lastfattnum,$lastfattemail,$lastfattdata,$lastfattname,$helpemail;
global $sellerivadesc,$selleriva,$sellerannulla,$sellergrazie,$sellerurl,$sellertos,$sellertosurl,$sellerlegal,$sellercap,$sellerrea,$sellercf;
global $sellerra,$sellerradesc,$sellerinps,$sellerinpsdesc,$sellerlogo,$selleriban,$sellerbank,$mainpaypalemail,$fatturamiurl,$abboprice,$abbounit,$abbofreq,$sellerzip;

$fatturaanno=substr($fatturadata,6,4);

$tmp=str_replace("--main--",$main,$tmp);
$tmp=str_replace("--titolo--",$titolo,$tmp);
$tmp=str_replace("--causalenonimponibile--",$causalenonimponibile,$tmp);
$tmp=str_replace("--prezzo--",$prezzo,$tmp);
$tmp=str_replace("--title--",$titolo,$tmp);
$tmp=str_replace("--price--",$prezzo,$tmp);
$tmp=str_replace("--ip--",$mip,$tmp);
$tmp=str_replace("--num--",$num,$tmp);
$tmp=str_replace("--ra--",$ra,$tmp);
$tmp=str_replace("--scorp--",$scorp,$tmp);
$tmp=str_replace("--eu--",$eu,$tmp);
if ($eu!="") {$tmp=str_replace("--eucheck--"," checked",$tmp);} else {$tmp=str_replace("--eucheck--"," ",$tmp);}
$tmp=str_replace("--desc--",$desc,$tmp);
$tmp=str_replace("--date--",$oggi,$tmp);
$tmp=str_replace("--oggi--",$oggi2,$tmp);
$tmp=str_replace("--siteurl--",$siteurl,$tmp);
$tmp=str_replace("--paystatus--",$paystatus,$tmp);
$tmp=str_replace("--ccemail--",$ccemail,$tmp);
$tmp=str_replace("--brevernd--",$brevernd,$tmp);
$tmp=str_replace("--downloadid--",$brevernd,$tmp);
$tmp=str_replace("--secid--",$customid,$tmp);
$tmp=str_replace("--customid--",$customid,$tmp);
$tmp=str_replace("--email--",$buyeremail,$tmp);
$tmp=str_replace("--shop--",$buyershop,$tmp);

$tmp=str_replace("--buyername--",$buyername,$tmp);
$tmp=str_replace("--buyerfirst--",$buyerfirst,$tmp);
$tmp=str_replace("--buyerlast--",$buyerlast,$tmp);
$tmp=str_replace("--buyeraddress--",$buyeraddress,$tmp);
$tmp=str_replace("--buyeraddress1--",$buyeraddress1,$tmp);
$tmp=str_replace("--buyeraddress2--",$buyeraddress2,$tmp);
$tmp=str_replace("--buyercity--",$buyercity,$tmp);
$tmp=str_replace("--buyerzip--",$buyerzip,$tmp);
$tmp=str_replace("--buyercf--",$buyercf,$tmp);
$tmp=str_replace("--buyerpiva--",$buyerpiva,$tmp);
$tmp=str_replace("--buyeremail--",$buyeremail,$tmp);
$tmp=str_replace("--buyertel--",$buyertel,$tmp);
$tmp=str_replace("--buyerpay--",$buyerpay,$tmp);
$tmp=str_replace("--buyertos--",$buyertos,$tmp);
$tmp=str_replace("--buyercountry--",$buyercountry,$tmp);
$tmp=str_replace("--buyerprovincia--",$buyerprovincia,$tmp);

$tmp=str_replace("--sellername--",$sellername,$tmp);
$tmp=str_replace("--sellerpiva--",$sellerpiva,$tmp);
$tmp=str_replace("--selleriva--",$selleriva,$tmp);
$tmp=str_replace("--sellerivadesc--",$sellerivadesc,$tmp);
$tmp=str_replace("--sellertel--",$sellertel,$tmp);
$tmp=str_replace("--sellerfax--",$sellerfax,$tmp);
$tmp=str_replace("--selleraddress--",$selleraddress,$tmp);
$tmp=str_replace("--sellercity--",$sellercity,$tmp);
$tmp=str_replace("--sellercurrency--",$sellercurrency,$tmp);
$tmp=str_replace("--selleremail--",$selleremail,$tmp);
$tmp=str_replace("--sellerlogo--",$sellerlogo,$tmp);
$tmp=str_replace("--selleriban--",$selleriban,$tmp);
$tmp=str_replace("--sellerbank--",$sellerbank,$tmp);


$tmp=str_replace("--sellerra--",$sellerra,$tmp);
$tmp=str_replace("--sellerradesc--",$sellerradesc,$tmp);
$tmp=str_replace("--sellerinps--",$sellerinps,$tmp);
$tmp=str_replace("--sellerinpsdesc--",$sellerinpsdesc,$tmp);

$tmp=str_replace("--sellerlegal--",$sellerlegal,$tmp);
$tmp=str_replace("--sellercap--",$sellercap,$tmp);
$tmp=str_replace("--sellerzip--",$sellerzip,$tmp);
$tmp=str_replace("--sellercf--",$sellercf,$tmp);
$tmp=str_replace("--sellerrea--",$sellerrea,$tmp);
$tmp=str_replace("--sellertos--",$sellertos,$tmp);
$tmp=str_replace("--sellertosurl--",$sellertosurl,$tmp);
$tmp=str_replace("--sellerurl--",$sellerurl,$tmp);
$tmp=str_replace("--sellerpaypalgrazie--",$sellerpaypalgrazie,$tmp);
$tmp=str_replace("--sellerpaypalannulla--",$sellerpaypalannulla,$tmp);


$tmp=str_replace("--errorname--",$errorname,$tmp);
$tmp=str_replace("--erroraddress--",$erroraddress,$tmp);
$tmp=str_replace("--errorcity--",$errorcity,$tmp);
$tmp=str_replace("--errorzip--",$errorzip,$tmp);
$tmp=str_replace("--errorcf--",$errorcf,$tmp);
$tmp=str_replace("--errorpiva--",$errorpiva,$tmp);
$tmp=str_replace("--errortos--",$errortos,$tmp);
$tmp=str_replace("--erroremail--",$erroremail,$tmp);
$tmp=str_replace("--errorcountry--",$errorcountry,$tmp);
$tmp=str_replace("--errorprovincia--",$errorprovincia,$tmp);

$tmp=str_replace("--fatturaprezzo--",$fatturaprezzo,$tmp);
$tmp=str_replace("--fatturasubimponibile--",$fatturasubimponibile,$tmp);
$tmp=str_replace("--fatturaimponibile--",$fatturaimponibile,$tmp);
$tmp=str_replace("--fatturanonimponibile--",$fatturanonimponibile,$tmp);
$tmp=str_replace("--fatturaiva--",$fatturaiva,$tmp);
$tmp=str_replace("--fatturadata--",$fatturadata,$tmp);
$tmp=str_replace("--fatturaanno--",$fatturaanno,$tmp);
$tmp=str_replace("--fatturanum--",$fatturanum,$tmp);
$tmp=str_replace("--fatturalegal--",$fatturalegal,$tmp);
$tmp=str_replace("--fatturatot--",$fatturatot,$tmp);
$tmp=str_replace("--fatturara--",$fatturara,$tmp);
$tmp=str_replace("--fatturainps--",$fatturainps,$tmp);
$tmp=str_replace("--fatturanetto--",$fatturanetto,$tmp);

$tmp=str_replace("--helpemail--",$helpemail,$tmp);
$tmp=str_replace("--mainpaypalemail--",$mainpaypalemail,$tmp);
$tmp=str_replace("--fatturamiurl--",$fatturamiurl,$tmp);

$tmp=str_replace("--lastfattnum--",$lastfattnum,$tmp);

$tmp1=$lastfattnum+1;
if ( substr($lastfattdata,-4,4) != date("Y") ) {$tmp1=1;}
$tmp=str_replace("--newfattnum--",$tmp1,$tmp);

$tmp=str_replace("--lastfattdata--",$lastfattdata,$tmp);
$tmp=str_replace("--lastfattemail--",$lastfattemail,$tmp);
$tmp=str_replace("--lastfattname--",$lastfattname,$tmp);

$tmp=str_replace("--abboprice--",$abboprice,$tmp);
$tmp=str_replace("--abbounit--",$abbounit,$tmp);
$tmp=str_replace("--abbofreq--",$abbofreq,$tmp);

return $tmp;
}

function ControlloPIVA($pi){
	    if( $pi == '' )  return false;
	    if( strlen($pi) != 11 )
		return false;
	    if( ! preg_match ("/^[0-9]+$/", $pi) )
		return false;
	    $s = 0;
	    for( $i = 0; $i <= 9; $i += 2 )
		$s += ord($pi[$i]) - ord('0');
	    for( $i = 1; $i <= 9; $i += 2 ){
		$c = 2*( ord($pi[$i]) - ord('0') );
		if( $c > 9 )  $c = $c - 9;
		$s += $c;
	    }
	    if( ( 10 - $s%10 )%10 != ord($pi[10]) - ord('0') )
		return false;
	    return true;
}

function ControlloCodiceFiscale($cf){
    if( $cf == '' )  return false;
    if( strlen($cf) != 16 )
	return false;
    $cf = strtoupper($cf);
    if( ! preg_match ("/^[A-Z0-9]+$/", $cf) ){
	return false;
    }
    $s = 0;
    for( $i = 1; $i <= 13; $i += 2 ){
	$c = $cf[$i];
	if( '0' <= $c && $c <= '9' )
	    $s += ord($c) - ord('0');
	else
	    $s += ord($c) - ord('A');
    }
    for( $i = 0; $i <= 14; $i += 2 ){
	$c = $cf[$i];
	switch( $c ){
	case '0':  $s += 1;  break;
	case '1':  $s += 0;  break;
	case '2':  $s += 5;  break;
	case '3':  $s += 7;  break;
	case '4':  $s += 9;  break;
	case '5':  $s += 13;  break;
	case '6':  $s += 15;  break;
	case '7':  $s += 17;  break;
	case '8':  $s += 19;  break;
	case '9':  $s += 21;  break;
	case 'A':  $s += 1;  break;
	case 'B':  $s += 0;  break;
	case 'C':  $s += 5;  break;
	case 'D':  $s += 7;  break;
	case 'E':  $s += 9;  break;
	case 'F':  $s += 13;  break;
	case 'G':  $s += 15;  break;
	case 'H':  $s += 17;  break;
	case 'I':  $s += 19;  break;
	case 'J':  $s += 21;  break;
	case 'K':  $s += 2;  break;
	case 'L':  $s += 4;  break;
	case 'M':  $s += 18;  break;
	case 'N':  $s += 20;  break;
	case 'O':  $s += 11;  break;
	case 'P':  $s += 3;  break;
	case 'Q':  $s += 6;  break;
	case 'R':  $s += 8;  break;
	case 'S':  $s += 12;  break;
	case 'T':  $s += 14;  break;
	case 'U':  $s += 16;  break;
	case 'V':  $s += 10;  break;
	case 'W':  $s += 22;  break;
	case 'X':  $s += 25;  break;
	case 'Y':  $s += 24;  break;
	case 'Z':  $s += 23;  break;
	}
    }
    if( chr($s%26 + ord('A')) != $cf[15] )
	return false;
    return true;
}


#
#invio email di notifica a compratore e in copia al venditore;
#
function sendemail($to,$subject,$message) {
global $sellername,$selleremail;

$random_hash = md5(date('r', time())); 

$headers  = "MIME-Version: 1.0\r\n".
	    "From: ".$sellername." <".$selleremail.">\r\n".
	    "Reply-To: ".$selleremail."\r\n";
$headers .= "Bcc: ".$selleremail."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary = phpalt-$random_hash\r\n\r\n";
 
$bdy = "--phpalt-$random_hash\r\n".
            "Content-Type: text/plain; charset=ISO-8859-1\r\n\r\n".
            strip_tags($message)."\r\n\r\n";

$bdy .= "--phpalt-$random_hash\r\n".
            "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n".
            $message."\r\n\r\n";
 
$bdy ." --phpalt-$random_hash--\r\n";

$mail_sent = @mail( $to, $subject, $bdy, $headers );
$mail_sent ? $tmp="Mail sent" : $tmp="Mail failed";
return $tmp;
}


function mandafattura($toemail,$fromemail,$pdf,$testo,$contentpdf) {

#
# ATTENZIONE $CONTENTPDF NON FUNZIONA TROVARE TEMP FILE NAME UNIQUE
#


	$fileatt 	= $pdf; 	// Path to the file
	$fileatt_type 	= "application/pdf"; // File Type
	$fileatt_name 	= $pdf; 	// Filename that will be used for the file as the attachment
	
	$email_from 	= $fromemail; 	// Who the email is from
	$email_subject 	= "Invio fattura"; // The Subject of the email
	$email_txt 	= $testo; 	// Message that the email has in it
	$email_to 	= $toemail;	// Who the email is too


$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

#$data=$contentpdf;

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\r\nMIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\r\n\r\n" .
"--{$mime_boundary}\r\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
$email_txt . "\r\n\r\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\r\n" .
"Content-Type: {$fileatt_type};\r\n" .
" name=\"{$fileatt_name}\"\r\n" .
//"Content-Disposition: attachment;\r\n" .
//" filename=\"{$fileatt_name}\"\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n" .
$data . "\r\n\r\n" .
"--{$mime_boundary}--\r\n";


$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
	$tmp= "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
	$tmp= "Sorry but the email could not be sent. Please go back and try again!";
} 


return $tmp;
}

function pulisci ($tmp) {
	$tmp=strtr($tmp,"'%;:\"\\","       ");
	return $tmp;
}

function random_string($len = 12)
{					
	$pool = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
	$str = '';
	for ($i=0; $i < $len; $i++)
	{
		$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
	}
	return $str;
}


###############################################################################
# make csv
###############################################################################

#$elenco="ordini";
#$sugg="#1 This is a test string\r\n added as testfilephp.txt.\n";

function makecsv($elenco,$csvsugg) {

	$path	= "../../zip/";
	$dt	= date("Y m d His");
	$dt2	= date("Ymd");
	$filename = $elenco." ".$dt2.".zip";

	$tmpname=tempnam($path,"zip");

	$zip = new ZipArchive();

	if ($zip->open($tmpname, ZIPARCHIVE::CREATE)!==TRUE) {
	    exit("cannot open <$tmpname>\n");
	}

	$info="Csv output of ".$elenco." produced on the filter you asked today, ".$dt;
	
	$zip->addFromString("info.txt" , $info);
	$zip->addFromString("elenco".$elenco." ".$dt2.".csv" , $csvsugg);

#	echo "numfiles: " . $zip->numFiles . "\n";
#	echo "status:" . $zip->status . "\n";
	$zip->close();

	header("Cache-Control: public");
	header("Content-Description: File Transfer");
	header("Content-Disposition: attachment; filename=" . $filename);
	header("Content-Transfer-Encoding: binary");
	// Leggo il contenuto del file
	readfile($tmpname);

	unlink($tmpname);
}


Function cdt($tmp) {
 return substr($tmp,8,2).".".substr($tmp,5,2).".".substr($tmp,0,4);
}
Function rdt($tmp) {
 return substr($tmp,-2,2).".".substr($tmp,-4,2).".".substr($tmp,0,4);
}

function leggifile ($nomefile) {
	$nomefile=str_replace(".template",".htm",$nomefile);
	$myFile = "./template".$nomefile;
	$fh = fopen($myFile, 'r');
	$tmp = fread($fh, filesize($myFile));
	fclose($fh);
	return $tmp;
}


function apredb($db_host, $db_user, $db_password, $db_name) {
	global $dbg;
	
	$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
	$mysqli->set_charset("utf8mb4");
	
	if ($mysqli->connect_errno) {
		if ($dbg==1) { 
			die ("mysqli err: " . $mysqli->connect_errno . " " . $mysqli->connect_error . "n");
		}
		if (!$mysqli->set_charset("utf8mb4")) { 
			echo "Error loading character set utf8: ". $mysqli->error; exit; 
		}
	}
	return $mysqli;
}

?>

devstral-small-2505 0.9  
Array
(
    [id] => c9a911532c4f48f8b2b4622338d0165e
    [created] => 1753892563
    [model] => devstral-small-2505
    [usage] => Array
        (
            [prompt_tokens] => 18673
            [total_tokens] => 35114
            [completion_tokens] => 16441
        )

    [object] => chat.completion
    [choices] => Array
        (
            [0] => Array
                (
                    [index] => 0
                    [finish_reason] => stop
                    [message] => Array
                        (
                            [role] => assistant
                            [tool_calls] => 
                            [content] => ## Conversione a PHP 8.3 e utilizzo di PDO

```php
<?php

include("../../firewall.php");

include_once('../adminna/mysql2i.class.php');

$myFile = "templateemailpaypalnotify.htm";
$fh = fopen($myFile, 'r');
$templateemailpaypalnotify = fread($fh, filesize($myFile));
fclose($fh);

$myFile = "condizionilegali.htm";
$fh = fopen($myFile, 'r');
$sellertos = creapagina(fread($fh, filesize($myFile)));
fclose($fh);

$myFile = "templatemandafattura.htm";
$fh = fopen($myFile, 'r');
$emailbasemandafattura = fread($fh, filesize($myFile));
fclose($fh);

$mip = $_SERVER['REMOTE_ADDR'];
$oggi = date("Y-m-d H:m:s");
$oggi2 = date("d-m-Y");
$siteurl = "https://www.fatturami.it/iusondemand.com/";

$sellerid = 1;
$annoinizio = date("Y") - 3;

include("account.inc.php");

$db_host = "127.0.0.1";
$db_user = "84-fatturatti";
$db_password = "Gua2BiThr9Y5RqX6";
$db_name = "84-fattur";

$errorname = "";
$erroraddress = "";
$errorcity = "";
$errorzip = "";
$errorcf = "";
$errorpiva = "";
$errortos = "";
$erroremail = "";
$errorcountry = "";
$errorprovincia = "";

$grazieurl = strip_tags(stripslashes($_REQUEST["grazieurl"]));
$annullaurl = strip_tags(stripslashes($_REQUEST["annullaurl"]));
$page_style = strip_tags(stripslashes($_REQUEST["page_style"]));
$abbmode = strip_tags(stripslashes($_REQUEST["abbmode"]));
$backup = strip_tags(stripslashes($_REQUEST["backup"]));

$titolo = str_replace('"', "'", trim(stripslashes(strip_tags($_REQUEST["titolo"]))));
$causalenonimponibile = str_replace('"', "'", trim(stripslashes(strip_tags($_REQUEST["causalenonimponibile"]))));
$prezzo = str_replace(",", ".", trim(stripslashes(strip_tags($_REQUEST["prezzo"]))));
if ($causalenonimponibile == "") {
    $causalenonimponibile = "Non imponibile";
}

$customid = trim(stripslashes(strip_tags($_REQUEST["custom"])));
$salva = trim(stripslashes(strip_tags($_REQUEST["salva"])));
$eu = trim(stripslashes(strip_tags($_REQUEST["eu"])));
$ra = trim(stripslashes(strip_tags($_REQUEST["ra"])));
if ($ra != "") {
    $ra = "on";
}
$scorp = trim(stripslashes(strip_tags($_REQUEST["scorp"])));

$js = trim(stripslashes(strip_tags($_REQUEST["js"])));
if ($js != "") {
    $js = "on";
}

$submit = trim(stripslashes(strip_tags($_REQUEST["submit"])));
$buyername = trim(stripslashes(strip_tags($_REQUEST["buyername"])));
$buyeraddress = trim(stripslashes(strip_tags($_REQUEST["buyeraddress"])));
$buyercodicedestinatario = trim(stripslashes(strip_tags($_REQUEST["buyercodicedestinatario"])));
$buyerzip = trim(stripslashes(strip_tags($_REQUEST["buyerzip"])));
$buyercity = trim(stripslashes(strip_tags($_REQUEST["buyercity"])));
$email = trim(stripslashes(strip_tags($_REQUEST["email"])));
$ccemail = trim(stripslashes(strip_tags($_REQUEST["ccemail"])));
$buyeremail = trim(stripslashes(strip_tags($_REQUEST["buyeremail"])));
$buyercf = strtoupper(trim(stripslashes(strip_tags($_REQUEST["buyercf"]))));

$_REQUEST["buyerpiva"] = str_ireplace("IT", "", $_REQUEST["buyerpiva"]);

$buyerpiva = trim(stripslashes(strip_tags($_REQUEST["buyerpiva"])));
$buyerpay = trim(stripslashes(strip_tags($_REQUEST["buyerpay"])));
$buyertos = trim(stripslashes(strip_tags($_REQUEST["buyertos"])));
$buyertel = trim(stripslashes(strip_tags($_REQUEST["buyertel"])));
$buyercountry = pulisci(substr(strtoupper(trim(stripslashes(strip_tags($_REQUEST["buyercountry"])))), 0, 3));

if ($buyercountry == "") {
    $buyercountry = "IT";
}
if (is_numeric($buyershop) != true) {
    $buyershop = 0;
}

$fatturadata = trim(stripslashes(strip_tags($_REQUEST["fatturadata"])));
$fatturanum = trim(stripslashes(strip_tags($_REQUEST["fatturanum"])));
$fatturaimponibile = trim(stripslashes(strip_tags($_REQUEST["fatturaimponibile"])));
$fatturanonimponibile = str_replace(",", ".", trim(stripslashes(strip_tags($_REQUEST["fatturanonimponibile"]))));

$fatturaiva = trim(stripslashes(strip_tags($_REQUEST["fatturaiva"])));
$fatturara = trim(stripslashes(strip_tags($_REQUEST["fatturara"])));
$fatturainps = trim(stripslashes(strip_tags($_REQUEST["fatturainps"])));
$fatturatot = trim(stripslashes(strip_tags($_REQUEST["fatturatot"])));
$fatturaprezzo = trim(stripslashes(strip_tags($_REQUEST["fatturaprezzo"])));
$fatturalegal = trim(stripslashes(strip_tags($_REQUEST["fatturalegal"])));

if (strpos($ccemail, ";") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, ",") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, "|") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, "'") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, "&lt;") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, "&gt;") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, "\"") !== false) {
    $ccemail = "";
}
if (strpos($ccemail, "@") === false) {
    $ccemail = "";
}

$da = intval(strip_tags(trim(stripslashes($_REQUEST['da']))));
$data = strip_tags(trim(stripslashes($_REQUEST['data'])));
$num = strip_tags(trim(stripslashes($_REQUEST['num'])));

if (is_numeric($sellerid) != true) {
    $sellerid = 0;
}
if (is_numeric($num) != true) {
    $num = 0;
}
if (is_numeric($fatturaanno) != true) {
    $fatturaanno = 0;
}
if (is_numeric($da) != true) {
    $da = 0;
}
if (is_numeric($data) != true) {
    $data = 0;
}
if (is_numeric($fatturanonimponibile) != true) {
    $fatturanonimponibile = 0;
}

$search = str_replace("\"", "", strip_tags(trim(stripslashes($_REQUEST['search']))));
$asearch = addcslashes($search, "%_;=?'\\");
$name = trim(stripslashes(strip_tags($_REQUEST["name"])));
$pwd = trim(stripslashes(strip_tags($_REQUEST["pwd"])));
$qpwd = "Pertinio.33";

if ($email != "") {
    $buyeremail = $email;
}

$ordersnotifyemail = $selleremail;

$tmp = strpos($buyername, " ");
if ($tmp > 0) {
    $buyerfirst = ucfirst(substr($buyername, 0, $tmp));
    $buyerlast = ucfirst(substr($buyername, $tmp + 1));
} else {
    $buyerfirst = $buyername;
    $buyerlast = $buyername;
}

if (strlen($buyeraddress) > 100) {
    $buyeraddress2 = substr($buyeraddress, 100);
    $buyeraddress1 = substr($buyeraddress, 0, 100);
} else {
    $buyeraddress1 = $buyeraddress;
    $buyeraddress2 = "";
}

$tabella = "orders";
$campi = "`id` , `data` , `name` , `address` , `country` , `zip` , `city` , `email` , `cf` , `piva` , `provincia` , `prezzo` , `titolo` , `currency` , `secid`, `sellerid`, `ccemail`, `pay`, `evaso`, `fatturato`, `tel`, `shop`, `abboid`, `note`, `formatotrasmissione`, `codicedestinatario`, `pec`, `context`, `nome`, `cognome`, `denominazione`";
$howmanyfields = 29;

$tabellapreventivi = "preventivi";
$campipreventivi = "`id` , `data` , `name` , `address` , `country` , `zip` , `city` , `email` , `cf` , `piva` , `provincia` , `prezzo` , `titolo` , `currency` , `secid`, `sellerid`, `ccemail`, `pay`, `evaso`, `fatturato`, `tel`, `shop`, `abboid`, `note`, `spese`, `referente`, `num`, `quantita`";
$howmanyfieldspreventivi = 27;

$tabellapayment = "payment";
$campipayment = "`id` , `data` , `email` , `prezzo` , `titolo` , `secid` , `name` , `txn_id` , `status` , `currency`, `subscr_date`, `recurring_payment_id`, `product_name`,`next_payment_date`,`amount_per_cycle`,`time_created`,`txn_type`,`payer_id`,`initial_payment_txn_id`,`sellerid`";
$howmanyfieldspayment = 19;

$tabellainvoice = "invoice";
$campiinvoice = "`id` , `num`, `data` , `name` , `address` , `zip` , `city` , `provincia`, `country` , `piva` , `cf`, `causale`, `prezzo`, `imponibile`, `nonimponibile`, `iva`, `currency`, `sellerid` , `email` , `pay`, `legali`, `ra`, `previdenza`, `fatturanetto`, `causalenonimponibile` ";
$howmanyfieldsinvoice = 24;

$tabellalistino = "listino";
$campilistino = "`id` , `sellerid`,`titolo`,`prezzo`,`descrizione`,`destemail`,`url`,`finoal`,`emailattach`,`uniqueid`,`tempurlmaxcounter`,`tempurlmaxdays`,`realurl`,`ipnurl`,`currency`,`page_style`,`annullaurl`,`senderemail`,`sendername`, `abbofreq`, `abbounit` ";
$howmanyfieldslistino = 20;

$tabellaevasi = "evasi";
$campievasi = "`id` , `listinoid`,`secid`,`data`,`ip`,`uniqueid`,`paymentid`,brevernd ";
$howmanyfieldsevasi = 7;

$tabellaeventi = "listino";
$campieventi = "`id` , `titolo`,prezzo, `url`,`max`,`email`, `finoal`,`visible`,sellerid, `dove`,`quando`,`contatti`,`cosa`, `destinatari`, `avvisominimo`, autoconferma,dal,tag,`descrizione`,`ripensamento` ";
$howmanyfieldseventi = 19;
$filtrasqleventi = " eventiid = 1 ";

$tabellacheckin = "checkin";
$campicheckin = "`id` , `ordersid`, `data`, `userid`, `listinoid` ";
$howmanyfieldscheckin = 4;

$tabellaabbonamenti = "orders";
$campiabbonamenti = "`id` , `data` , `name` , `address` , `country` , `zip` , `city` , `email` , `cf` , `piva` , `provincia` , `prezzo` , `titolo` , `currency` , `secid`, `sellerid`, `ccemail`, `pay`, `evaso`, `fatturato`, `tel`, `shop`, `abboid`";
$howmanyfieldsabbonamenti = 20;

$tabellaabbonati = "abbonati";
$campiabbonati = "id,last_name,first_name,item_name,custom,subscr_id,subscr_date,payer_email,payer_id,action";
$howmanyfieldsabbonati = 9;

$tabellaautori = "user";
$campiautori = "id,name,email,pwd,query,compensi,paypal,iban,cf,piva,sede,idseller,verified";
$howmanyfieldsautori = 12;

$tabellastat = "stat";
$campistat = "id,datetime,device,type,cnt";
$howmanyfieldsstat = 3;

$tabellareferer = "statreferer";
$campireferer = "id,date,referer,type,cnt";
$howmanyfieldsreferer = 4;

$tabellascadenze = "scadenze";
$campiscadenze = "id,data,gg,mm,aa,causale,prezzo,destemail,nome,preavviso1,preavviso2,preavviso3,testomail,next,finoal,sellerid,note,status";
$howmanyfieldsscadenze = 17;

$tabellascadenzelog = "scadenzelog";
$campiscadenzelog = "id,data,idscadenze,testo,note,prezzo,uuid,causale,sellerid";
$howmanyfieldsscadenzelog = 8;

include("../efatt.inc.php");

function creapagina($tmp)
{
    global $main, $titolo, $prezzo, $brevernd, $causalenonimponibile;
    global $buyername, $buyeraddress, $buyercity, $buyerzip, $buyercf, $buyerpiva, $buyeremail, $buyertel, $buyerpay;
    global $buyertos, $buyercountry, $buyerprovincia, $buyerfirst, $buyerlast, $buyeraddress1, $buyeraddress2, $buyershop;
    global $sellername, $sellernome, $sellercognome, $sellerpiva, $sellertel, $sellerfax, $selleremail, $sellercurrency, $selleraddress, $sellercity;
    global $errorname, $erroraddress, $errorcity, $errorzip, $errorcf, $errorpiva, $errortos, $erroremail, $errorcountry, $errorprovincia, $errorpec;
    global $mip, $oggi, $oggi2, $siteurl, $customid, $paystatus, $ccemail, $num, $eu, $ra, $scorp, $desc;
    global $fatturadata, $fatturanum, $fatturaimponibile, $fatturasubimponibile, $fatturanonimponibile, $fatturaprezzo, $fatturaiva, $fatturalegal, $fatturatot, $fatturara, $fatturainps, $fatturanetto;
    global $lastfattnum, $lastfattemail, $lastfattdata, $lastfattname, $helpemail;
    global $sellerivadesc, $selleriva, $sellerannulla, $sellergrazie, $sellerurl, $sellertos, $sellertosurl, $sellerlegal, $sellercap, $sellerrea, $sellercf;
    global $sellerra, $sellerradesc, $sellerinps, $sellerinpsdesc, $sellerlogo, $sellerimg, $selleriban, $sellerbank, $mainpaypalemail, $fatturamiurl, $abboprice, $abbounit, $abbofreq;
    global $buyerziptype, $buyernametype, $buyeremailtype, $buyeraddresstype, $buyercitytype, $buyercftype, $buyerpivatype, $buyercountrytype;
    global $totale, $tempiva, $buyercontext, $context, $buyerpec, $buyercodicedestinatario, $countryselector;
    global $errorcountry, $errorprovincia, $errorpec, $sellercap, $sellerrea, $sellercf;
    global $sellerra, $sellerradesc, $sellerinps, $sellerinpsdesc, $buyerziptype, $buyernametype, $buyeremailtype, $buyeraddresstype, $buyercitytype, $buyercftype, $buyerpivatype, $buyercountrytype;
    global $totale, $tempiva, $buyercontext, $context, $buyerpec, $buyercodicedestinatario, $countryselector;
    global $sellerREAUfficio, $sellerNumeroREA, $sellerCapitaleSociale, $sellerSocioUnico, $sellerRegimeFiscale, $sellerStatoLiquidazione, $esellername, $esellernome, $esellercognome;
    global $TipoDocumento, $Divisa, $Art73, $eselleriva, $eNatura, $EsigibilitaIVA, $RiferimentoNormativo, $CondizioniPagamento, $ModalitaPagamento, $pagamentiselector, $formatotrasmissione;
    global $buyernome, $buyercognome, $buyerdenominazione, $buyerformatotrasmissione, $buyercodicedestinatario, $buyerpec, $PECDestinatario;
    global $Trasmittentecountry, $TrasmittenteIdCodice, $ProgressivoInvio, $formatotrasmissione, $ebuyeriva, $sellerzip, $sellerprovincia, $sellercountry, $ebuyerpivaextraeu, $sellerpuroiban, $sellerbanca;

    $listprov = [
        "AQ" => "Aquila", "CH" => "Chieti", "PE" => "Pescara", "TE" => "Teramo", "MT" => "Matera", "PZ" => "Potenza",
        "CZ" => "Catanzaro", "CS" => "Cosenza", "KR" => "Crotone", "RC" => "Reggio Calabria", "VV" => "Vibo Valentia",
        "AV" => "Avellino", "BN" => "Benevento", "CE" => "Caserta", "NA" => "Napoli", "SA" => "Salerno", "BO" => "Bologna",
        "FE" => "Ferrara", "FC" => "Forlì-Cesena", "MO" => "Modena", "PR" => "Parma", "PC" => "Piacenza", "RA" => "Ravenna",
        "RE" => "Reggio Emilia", "RN" => "Rimini", "GO" => "Gorizia", "PN" => "Pordenone", "TS" => "Trieste", "UD" => "Udine",
        "FR" => "Frosinone", "LT" => "Latina", "RI" => "Rieti", "RM" => "Roma", "VT" => "Viterbo", "GE" => "Genova",
        "IM" => "Imperia", "SP" => "la Spezia", "SV" => "Savona", "BG" => "Bergamo", "BS" => "Brescia", "CO" => "Como",
        "CR" => "Cremona", "LC" => "Lecco", "LO" => "Lodi", "MN" => "Mantova", "MI" => "Milano", "MB" => "Monza e Brianza",
        "PV" => "Pavia", "SO" => "Sondrio", "VA" => "Varese", "AN" => "Ancona", "AP" => "Ascoli Piceno", "FM" => "Fermo",
        "MC" => "Macerata", "PU" => "Pesaro e Urbino", "CB" => "Campobasso", "IS" => "Isernia", "AL" => "Alessandria",
        "AT" => "Asti", "BI" => "Biella", "CN" => "Cuneo", "NO" => "Novara", "TO" => "Torino", "VB" => "Verbano Cusio Ossola",
        "VC" => "Vercelli", "BA" => "Bari", "BT" => "Barletta-Andria-Trani", "BR" => "Brindisi", "FG" => "Foggia",
        "LE" => "Lecce", "TA" => "Taranto", "CA" => "Cagliari", "CI" => "Carbonia-Iglesias", "VS" => "Medio Campidano",
        "NU" => "Nuoro", "OG" => "Ogliastra", "OT" => "Olbia-Tempio", "OR" => "Oristano", "SS" => "Sassari",
        "SU" => "Sud Sardegna", "AG" => "Agrigento", "CL" => "Caltanissetta", "CT" => "Catania", "EN" => "Enna",
        "ME" => "Messina", "PA" => "Palermo", "RG" => "Ragusa", "SR" => "Siracusa", "TP" => "Trapani", "AR" => "Arezzo",
        "FI" => "Firenze", "GR" => "Grosseto", "LI" => "Livorno", "LU" => "Lucca", "MS" => "Massa-Carrara", "PI" => "Pisa",
        "PT" => "Pistoia", "PO" => "Prato", "SI" => "Siena", "BZ" => "Bolzano", "TN" => "Trento", "PG" => "Perugia",
        "TR" => "Terni", "AO" => "Val_d'Aosta", "BL" => "Belluno", "PD" => "Padova", "RO" => "Rovigo", "TV" => "Treviso",
        "VE" => "Venezia", "VR" => "Verona", "VI" => "Vicenza"
    ];

    asort($listprov);

    $selectprovincia = '<select name=buyerprovincia id="iodbuyerprovincia" class="iodinputempty" style="width:300px;"> onClick="controllaordine()" onchange="controllaordine()"  oninput="controllaordine()">';
    $selectprovincia .= "\r\n<option value='' $tmps>scegli</option>";
    foreach ($listprov as $key => $value) {
        $tmps = "";
        if ($buyerprovincia == $key) {
            $tmps = " selected";
        }
        $selectprovincia .= "\r\n<option value='$key' $tmps>$value</option>";
    }
    $selectprovincia .= "\r\n</select>";

    $modpagamento = [
        "" => "nulla", "MP08" => "carta di pagamento", "MP01" => "contanti", "MP02" => "assegno",
        "MP03" => "assegno circolare", "MP04" => "contanti presso Tesoreria", "MP05" => "bonifico",
        "MP06" => "vaglia cambiario", "MP07" => "bollettino bancario", "MP09" => "RID",
        "MP10" => "RID utenze", "MP11" => "RID veloce", "MP12" => "RIBA", "MP13" => "MAV",
        "MP14" => "quietanza erario", "MP15" => "giroconto su conti di contabilità speciale",
        "MP16" => "domiciliazione bancaria", "MP17" => "domiciliazione postale", "MP18" => "bollettino di c/c postale",
        "MP19" => "SEPA Direct Debit", "MP20" => "SEPA Direct Debit CORE", "MP21" => "SEPA Direct Debit B2B",
        "MP22" => "Trattenuta su somme già riscosse"
    ];

    $selectmodalitapagamento = '<select name=ModalitaPagamento id="iodbuyermodalitapagamento" class="iodinputempty" >';
    foreach ($modpagamento as $key => $value) {
        $tmps = "";
        if ($ModalitaPagamento == $key or strtolower($buyerpay) == strtolower($value)) {
            $tmps = " selected";
        }
        $selectmodalitapagamento .= "\r\n<option value='$key' $tmps>$value</option>";
    }
    if ($buyerpay == "") {
        $buyerpay = "paypal";
    }
    if ($buyerpay == "-") {
        $buyerpay = "paypal";
    }
    if (strtolower($buyerpay) == "paypal") {
        $key = "MP08";
        $value = "PayPal";
        $tmps = " selected";
    }
    $selectmodalitapagamento .= "\r\n<option value='$key' $tmps>$value</option>";
    $selectmodalitapagamento .= "\r\n</select>";

    $tmp = str_replace("--selectprovincia--", $selectprovincia, $tmp);
    $tmp = str_replace("--selectmodalitapagamento--", $selectmodalitapagamento, $tmp);
    $tmp = str_replace("--etitolo--", $titolo, $tmp);
    $tmp = str_replace("--TipoDocumento--", $TipoDocumento, $tmp);
    $tmp = str_replace("--Divisa--", $Divisa, $tmp);
    $tmp = str_replace("--Art73--", $Art73, $tmp);
    $tmp = str_replace("--eNatura--", $eNatura, $tmp);
    $tmp = str_replace("--eselleriva--", $eselleriva, $tmp);
    $tmp = str_replace("--ebuyeriva--", $ebuyeriva, $tmp);
    $tmp = str_replace("--Trasmittentecountry--", $Trasmittentecountry, $tmp);
    $tmp = str_replace("--TrasmittenteIdCodice--", $TrasmittenteIdCodice, $tmp);
    $tmp = str_replace("--ProgressivoInvio--", $ProgressivoInvio, $tmp);
    $tmp = str_replace("--FormatoTrasmissione--", $formatotrasmissione, $tmp);
    $tmp = str_replace("--EsigibilitaIVA--", $EsigibilitaIVA, $tmp);
    $tmp = str_replace("--CondizioniPagamento--", $CondizioniPagamento, $tmp);
    $tmp = str_replace("--ModalitaPagamento--", $ModalitaPagamento, $tmp);

    $codtipodocument = [
        "TD01" => "Fattura", "TD02" => "Acconto/anticipo su fattura", "TD03" => "Acconto/anticipo su parcella",
        "TD04" => "Nota di credito", "TD05" => "Nota di debito", "TD06" => "Parcella", "TD20" => "Autofattura",
        "TD07" => "Fattura semplificata", "TD08" => "Nota di Credito semplificata", "TD10" => "Fattura per acquisto intracomunitario beni",
        "TD11" => "Fattura per acquisto intracomunitario servizi", "TD12" => "Documento riepilogativo (art.6, DPR 695/1996)"
    ];

    $tipodocumentotxt = "";
    foreach ($codtipodocument as $key => $value) {
        if ($key == $TipoDocumento) {
            $tipodocumentotxt = $value;
        }
    }
    $tmp = str_replace("--tipodocumentotxt--", $tipodocumentotxt, $tmp);

    $tmp = str_replace("--pagamentiselector--", $pagamentiselector, $tmp);
    $tmp = str_replace("--formatotrasmissione--", $formatotrasmissione, $tmp);
    $tmp = str_replace("--buyernome--", $buyernome, $tmp);
    $tmp = str_replace("--buyercognome--", $buyercognome, $tmp);
    $tmp = str_replace("--buyerdenominazione--", $buyerdenominazione, $tmp);
    $tmp = str_replace("--buyerformatotrasmissione--", $buyerformatotrasmissione, $tmp);
    $tmp = str_replace("--buyercodicedestinatario--", $buyercodicedestinatario, $tmp);
    $tmp = str_replace("--CodiceDestinatario--", $buyercodicedestinatario, $tmp);
    $tmp = str_replace("--PECDestinatario--", $PECDestinatario, $tmp);
    $tmp = str_replace("--buyerpec--", $buyerpec, $tmp);
    $tmp = str_replace("--buyercontext--", $buyercontext, $tmp);
    $tmp = str_replace("--buyercodicedestinatario--", $buyercodicedestinatario, $tmp);
    $tmp = str_replace("--sellerra--", $sellerra, $tmp);
    $tmp = str_replace("--sellerradesc--", $sellerradesc, $tmp);
    $tmp = str_replace("--sellerinps--", $sellerinps, $tmp);
    $tmp = str_replace("--sellerinpsdesc--", $sellerinpsdesc, $tmp);
    $tmp = str_replace("--sellerprovincia--", $sellerprovincia, $tmp);
    $tmp = str_replace("--sellercountry--", $sellercountry, $tmp);
    $tmp = str_replace("--sellerSocioUnico--", $sellerSocioUnico, $tmp);
    $tmp = str_replace("--sellerCapitaleSociale--", $sellerCapitaleSociale, $tmp);
    $tmp = str_replace("--sellerREAUfficio--", $sellerREAUfficio, $tmp);
    $tmp = str_replace("--sellerNumeroREA--", $sellerNumeroREA, $tmp);
    $tmp = str_replace("--sellerRegimeFiscale--", $sellerRegimeFiscale, $tmp);
    $tmp = str_replace("--sellerStatoLiquidazione--", $sellerStatoLiquidazione, $tmp);
    $tmp = str_replace("--sellercap--", $sellercap, $tmp);
    $tmp = str_replace("--sellerzip--", $sellerzip, $tmp);
    $tmp = str_replace("--sellercf--", $sellercf, $tmp);
    $tmp = str_replace("--sellerrea--", $sellerrea, $tmp);
    $tmp = str_replace("--sellerpuroiban--", $sellerpuroiban, $tmp);
    $tmp = str_replace("--sellerbanca--", $sellerbanca, $tmp);

    $tmp = str_replace("--speseesenti--", "
     <DettaglioLinee>
        <NumeroLinea>2</NumeroLinea>
        <Descrizione>--causalenonimponibile--</Descrizione>
        <Quantita>1.00</Quantita>
        <PrezzoUnitario>--efatturanonimponibile--</PrezzoUnitario>
        <PrezzoTotale>--efatturanonimponibile--</PrezzoTotale>
        <AliquotaIVA>0.00</AliquotaIVA>
        <Natura>N1</Natura>
      </DettaglioLinee>", $tmp);

    $tmp = str_replace("--riepilogoesenti--", "
      <DatiRiepilogo>
        <AliquotaIVA>0.00</AliquotaIVA>
        <Natura>N1</Natura>
        <ImponibileImporto>--efatturanonimponibile--</ImponibileImporto>
        <Imposta>0.00</Imposta>
        <RiferimentoNormativo>Escluso Art. 15 DPR 633/72</RiferimentoNormativo>
      </DatiRiepilogo>", $tmp);

    $tmp = str_replace("--efatturadata--", substr($fatturadata, -4, 4) . "-" . substr($fatturadata, 3, 2) . "-" . substr($fatturadata, 0, 2), $tmp);
    $tmp = str_replace("--efatturaanno--", substr($fatturadata, -4, 4), $tmp);
    $tmp = str_replace("--efattura2anno--", substr($fatturadata, -2, 2), $tmp);
    $tmp = str_replace("--efatturaprezzo--", str_replace(",", ".", $fatturaprezzo), $tmp);
    $tmp = str_replace("--efatturasubimponibile--", str_replace(",", ".", $fatturasubimponibile), $tmp);
    $tmp = str_replace("--efatturaimponibile--", str_replace(",", ".", $fatturaimponibile), $tmp);
    $tmp = str_replace("--efatturanonimponibile--", str_replace(",", ".", $fatturanonimponibile), $tmp);
    $tmp = str_replace("--efatturaiva--", str_replace(",", ".", $fatturaiva), $tmp);
    $tmp = str_replace("--efatturatot--", str_replace(",", ".", $fatturatot), $tmp);
    $tmp = str_replace("--efatturara--", str_replace(",", ".", $fatturara), $tmp);
    $tmp = str_replace("--efatturainps--", str_replace(",", ".", $fatturainps), $tmp);
    $tmp = str_replace("--efatturanetto--", str_replace(",", ".", $fatturanetto), $tmp);
    $tmp = str_replace("--esellername--", iconv("UTF-8", "UTF-8//IGNORE", $esellername), $tmp);
    $tmp = str_replace("--esellernome--", iconv("UTF-8", "UTF-8//IGNORE", $esellernome), $tmp);
    $tmp = str_replace("--esellercognome--", iconv("UTF-8", "UTF-8//IGNORE", $esellercognome), $tmp);
    $tmp = str_replace("--eselleriva--", iconv("UTF-8", "UTF-8//IGNORE", $eselleriva), $tmp);
    $tmp = str_replace("--ebuyerpivaextraeu--", iconv("UTF-8", "UTF-8//IGNORE", $ebuyerpivaextraeu), $tmp);

    $fatturaanno = substr($fatturadata, 6, 4);

    $tmp = str_replace("--main--", $main, $tmp);
    $tmp = str_replace("--causalenonimponibile--", $causalenonimponibile, $tmp);
    $tmp = str_replace("--titolo--", $titolo, $tmp);
    $tmp = str_replace("--prezzo--", $prezzo, $tmp);
    $tmp = str_replace("--tempiva--", $tempiva, $tmp);
    $tmp = str_replace("--totale--", $totale, $tmp);
    $tmp = str_replace("--title--", $titolo, $tmp);
    $tmp = str_replace("--price--", $prezzo, $tmp);
    $tmp = str_replace("--context--", $context, $tmp);
    $tmp = str_replace("--ip--", $mip, $tmp);
    $tmp = str_replace("--num--", $num, $tmp);
    $tmp = str_replace("--ra--", $ra, $tmp);
    $tmp = str_replace("--scorp--", $scorp, $tmp);
    $tmp = str_replace("--countryselector--", $countryselector, $tmp);
    $tmp = str_replace("--eu--", $eu, $tmp);
    if ($eu != "") {
        $tmp = str_replace("--eucheck--", " checked", $tmp);
    } else {
        $tmp = str_replace("--eucheck--", " ", $tmp);
    }
    $tmp = str_replace("--desc--", $desc, $tmp);
    $tmp = str_replace("--date--", $oggi, $tmp);
    $tmp = str_replace("--oggi--", $oggi2, $tmp);
    $tmp = str_replace("--siteurl--", $siteurl, $tmp);
    $tmp = str_replace("--paystatus--", $paystatus, $tmp);
    $tmp = str_replace("--ccemail--", $ccemail, $tmp);
    $tmp = str_replace("--brevernd--", $brevernd, $tmp);
    $tmp = str_replace("--downloadid--", $brevernd, $tmp);
    $tmp = str_replace("--secid--", $customid, $tmp);
    $tmp = str_replace("--customid--", $customid, $tmp);
    $tmp = str_replace("--email--", $buyeremail, $tmp);
    $tmp = str_replace("--shop--", $buyershop, $tmp);
    $tmp = str_replace("--buyername--", iconv("UTF-8", "UTF-8//IGNORE", $buyername), $tmp);
    $tmp = str_replace("--buyerfirst--", iconv("UTF-8", "UTF-8//IGNORE", $buyerfirst), $tmp);
    $tmp = str_replace("--buyerlast--", iconv("UTF-8", "UTF-8//IGNORE", $buyerlast), $tmp);
    $tmp = str_replace("--buyeraddress--", iconv("UTF-8", "UTF-8//IGNORE", $buyeraddress), $tmp);
    $tmp = str_replace("--buyeraddress1--", iconv("UTF-8", "UTF-8//IGNORE", $buyeraddress1), $tmp);
    $tmp = str_replace("--buyeraddress2--", iconv("UTF-8", "UTF-8//IGNORE", $buyeraddress2), $tmp);
    $tmp = str_replace("--buyercity--", iconv("UTF-8", "UTF-8//IGNORE", $buyercity), $tmp);
    $tmp = str_replace("--buyerzip--", iconv("UTF-8", "UTF-8//IGNORE", $buyerzip), $tmp);
    $tmp = str_replace("--buyercf--", iconv("UTF-8", "UTF-8//IGNORE", $buyercf), $tmp);
    $tmp = str_replace("--buyeriva--", iconv("UTF-8", "UTF-8//IGNORE", $buyerpiva), $tmp);
    $tmp = str_replace("--buyerpiva--", iconv("UTF-8", "UTF-8//IGNORE", $buyerpiva), $tmp);
    $tmp = str_replace("--buyeremail--", iconv("UTF-8", "UTF-8//IGNORE", $buyeremail), $tmp);
    $tmp = str_replace("--buyertel--", iconv("UTF-8", "UTF-8//IGNORE", $buyertel), $tmp);
    $tmp = str_replace("--buyerpay--", iconv("UTF-8", "UTF-8//IGNORE", $buyerpay), $tmp);
    $tmp = str_replace("--buyertos--", iconv("UTF-8", "UTF-8//IGNORE", $buyertos), $tmp);
    $tmp = str_replace("--buyercountry--", iconv("UTF-8", "UTF-8//IGNORE", $buyercountry), $tmp);
    $tmp = str_replace("--buyerprovincia--", iconv("UTF-8", "UTF-8//IGNORE", $buyerprovincia), $tmp);
    $tmp = str_replace("--buyernametype--", iconv("UTF-8", "UTF-8//IGNORE", $buyernametype), $tmp);
    $tmp = str_replace("--buyeraddresstype--", iconv("UTF-8", "UTF-8//IGNORE", $buyeraddresstype), $tmp);
    $tmp = str_replace("--buyercitytype--", iconv("UTF-8", "UTF-8//IGNORE", $buyercitytype), $tmp);
    $tmp = str_replace("--buyerziptype--", iconv("UTF-8", "UTF-8//IGNORE", $buyerziptype), $tmp);
    $tmp = str_replace("--buyercftype--", iconv("UTF-8", "UTF-8//IGNORE", $buyercftype), $tmp);
    $tmp = str_replace("--buyerpivatype--", iconv("UTF-8", "UTF-8//IGNORE", $buyerpivatype), $tmp);
    $tmp = str_replace("--buyeremailtype--", iconv("UTF-8", "UTF-8//IGNORE", $buyeremailtype), $tmp);
    $tmp = str_replace("--buyercountrytype--", iconv("UTF-8", "UTF-8//IGNORE", $buyercountrytype), $tmp);
    $tmp = str_replace("--buyerprovinciatype--", iconv("UTF-8", "UTF-8//IGNORE", $buyerprovinciatype), $tmp);
    $tmp = str_replace("--buyerpectype--", iconv("UTF-8", "UTF-8//IGNORE", $buyerpectype), $tmp);
    $tmp = str_replace("--sellername--", iconv("UTF-8", "UTF-8//IGNORE", $sellername), $tmp);
    $tmp = str_replace("--sellernome--", iconv("UTF-8", "UTF-8//IGNORE", $sellernome), $tmp);
    $tmp = str_replace("--sellercognome--", iconv("UTF-8", "UTF-8//IGNORE", $sellercognome), $tmp);
    $tmp = str_replace("--sellerpiva--", iconv("UTF-8", "UTF-8//IGNORE", $sellerpiva), $tmp);
    $tmp = str_replace("--selleriva--", iconv("UTF-8", "UTF-8//IGNORE", $selleriva), $tmp);
    $tmp = str_replace("--sellerivadesc--", iconv("UTF-8", "UTF-8//IGNORE", $sellerivadesc), $tmp);
    $tmp = str_replace("--sellertel--", iconv("UTF-8", "UTF-8//IGNORE", $sellertel), $tmp);
    $tmp = str_replace("--sellerfax--", iconv("UTF-8", "UTF-8//IGNORE", $sellerfax), $tmp);
    $tmp = str_replace("--selleraddress--", iconv("UTF-8", "UTF-8//IGNORE", $selleraddress), $tmp);
    $tmp = str_replace("--sellercity--", iconv("UTF-8", "UTF-8//IGNORE", $sellercity), $tmp);
    $tmp = str_replace("--sellercurrency--", iconv("UTF-8", "UTF-8//IGNORE", $sellercurrency), $tmp);
    $tmp = str_replace("--selleremail--", iconv("UTF-8", "UTF-8//IGNORE", $selleremail), $tmp);
    $tmp = str_replace("--sellerlogo--", iconv("UTF-8", "UTF-8//IGNORE", $sellerlogo), $tmp);
    $tmp = str_replace("--sellerimg--", iconv("UTF-8", "UTF-8//IGNORE", $sellerimg), $tmp);
    $tmp = str_replace("--selleriban--", iconv("UTF-8", "UTF-8//IGNORE", $selleriban), $tmp);
    $tmp = str_replace("--sellerbank--", iconv("UTF-8", "UTF-8//IGNORE", $sellerbank), $tmp);
    $tmp = str_replace("--sellerbanca--", iconv("UTF-8", "UTF-8//IGNORE", $sellerbanca), $tmp);
    $tmp = str_replace("--sellerlegal--", $sellerlegal, $tmp);
    $tmp = str_replace("--sellertos--", $sellertos, $tmp);
    $tmp = str_replace("--sellertosurl--", $sellertosurl, $tmp);
    $tmp = str_replace("--sellerurl--", $sellerurl, $tmp);
    $tmp = str_replace("--sellerpaypalgrazie--", $sellerpaypalgrazie, $tmp);
    $tmp = str_replace("--sellerpaypalannulla--", $sellerpaypalannulla, $tmp);
    $tmp = str_replace("--errorname--", $errorname, $tmp);
    $tmp = str_replace("--erroraddress--", $erroraddress, $tmp);
    $tmp = str_replace("--errorcity--", $errorcity, $tmp);
    $tmp = str_replace("--errorzip--", $errorzip, $tmp);
    $tmp = str_replace("--errorcf--", $errorcf, $tmp);
    $tmp = str_replace("--errorpiva--", $errorpiva, $tmp);
    $tmp = str_replace("--errortos--", $errortos, $tmp);
    $tmp = str_replace("--erroremail--", $erroremail, $tmp);
    $tmp = str_replace("--errorcountry--", $errorcountry, $tmp);
    $tmp = str_replace("--errorprovincia--", $errorprovincia, $tmp);
    $tmp = str_replace("--errorpec--", $errorpec, $tmp);
    $tmp = str_replace("--errortitolo--", "", $tmp);
    $tmp = str_replace("--errorprice--", "", $tmp);
    $tmp = str_replace("--fatturaprezzo--", $fatturaprezzo, $tmp);
    $tmp = str_replace("--fatturasubimponibile--", $fatturasubimponibile, $tmp);
    $tmp = str_replace("--fatturaimponibile--", $fatturaimponibile, $tmp);
    $tmp = str_replace("--fatturanonimponibile--", $fatturanonimponibile, $tmp);
    $tmp = str_replace("--fatturaiva--", $fatturaiva, $tmp);
    $tmp = str_replace("--fatturadata--", $fatturadata, $tmp);
    $tmp = str_replace("--fatturaanno--", $fatturaanno, $tmp);
    $tmp = str_replace("--fatturanum--", $fatturanum, $tmp);
    $tmp = str_replace("--fatturalegal--", $fatturalegal, $tmp);
    $tmp = str_replace("--fatturatot--", $fatturatot, $tmp);
    $tmp = str_replace("--fatturara--", $fatturara, $tmp);
    $tmp = str_replace("--fatturainps--", $fatturainps, $tmp);
    $tmp = str_replace("--fatturanetto--", $fatturanetto, $tmp);
    $tmp = str_replace("--helpemail--", $helpemail, $tmp);
    $tmp = str_replace("--mainpaypalemail--", $mainpaypalemail, $tmp);
    $tmp = str_replace("--fatturamiurl--", $fatturamiurl, $tmp);
    $tmp = str_replace("--lastfattnum--", $lastfattnum, $tmp);
    $tmp1 = $lastfattnum + 1;
    if (substr($lastfattdata, -4, 4) != date("Y")) {
        $tmp1 = 1;
    }
    $tmp = str_replace("--newfattnum--", $tmp1, $tmp);
    $tmp = str_replace("--lastfattdata--", $lastfattdata, $tmp);
    $tmp = str_replace("--lastfattemail--", $lastfattemail, $tmp);
    $tmp = str_replace("--lastfattname--", $lastfattname, $tmp);
    $tmp = str_replace("--abboprice--", $abboprice, $tmp);
    $tmp = str_replace("--abbounit--", $abbounit, $tmp);
    $tmp = str_replace("--abbofreq--", $abbofreq, $tmp);

    return $tmp;
}

function creapaginaOLD($tmp)
{
    global $main, $titolo, $prezzo, $brevernd, $causalenonimponibile;
    global $buyername, $buyeraddress, $buyercity, $buyerzip, $buyercf, $buyerpiva, $buyeremail, $buyertel, $buyerpay;
    global $buyertos, $buyercountry, $buyerprovincia, $buyerfirst, $buyerlast, $buyeraddress1, $buyeraddress2, $buyershop;
    global $sellername, $sellerpiva, $sellertel, $sellerfax, $selleremail, $sellercurrency, $selleraddress, $sellercity;
    global $errorname, $erroraddress, $errorcity, $errorzip, $errorcf, $errorpiva, $errortos, $erroremail, $errorcountry, $errorprovincia;
    global $mip, $oggi, $oggi2, $siteurl, $customid, $paystatus, $ccemail, $num, $eu, $ra, $scorp, $desc;
    global $fatturadata, $fatturanum, $fatturaimponibile, $fatturasubimponibile, $fatturanonimponibile, $fatturaprezzo, $fatturaiva, $fatturalegal, $fatturatot, $fatturara, $fatturainps, $fatturanetto;
    global $lastfattnum, $lastfattemail, $lastfattdata, $lastfattname, $helpemail;
    global $sellerivadesc, $selleriva, $sellerannulla, $sellergrazie, $sellerurl, $sellertos, $sellertosurl, $sellerlegal, $sellercap, $sellerrea, $sellercf;
    global $sellerra, $sellerradesc, $sellerinps, $sellerinpsdesc, $sellerlogo, $selleriban, $sellerbank, $mainpaypalemail, $fatturamiurl, $abboprice, $abbounit, $abbofreq, $sellerzip;

    $fatturaanno = substr($fatturadata, 6, 4);

    $tmp = str_replace("--main--", $main, $tmp);
    $tmp = str_replace("--titolo--", $titolo, $tmp);
    $tmp = str_replace("--causalenonimponibile--", $causalenonimponibile, $tmp);
    $tmp = str_replace("--prezzo--", $prezzo, $tmp);
    $tmp = str_replace("--title--", $titolo, $tmp);
    $tmp = str_replace("--price--", $prezzo, $tmp);
    $tmp = str_replace("--ip--", $mip, $tmp);
    $tmp = str_replace("--num--", $num, $tmp);
    $tmp = str_replace("--ra--", $ra, $tmp);
    $tmp = str_replace("--scorp--", $scorp, $tmp);
    $tmp = str_replace("--eu--", $eu, $tmp);
    if ($eu != "") {
        $tmp = str_replace("--eucheck--", " checked", $tmp);
    } else {
        $tmp = str_replace("--eucheck--", " ", $tmp);
    }
    $tmp = str_replace("--desc--", $desc, $tmp);
    $tmp = str_replace("--date--", $oggi, $tmp);
    $tmp = str_replace("--oggi--", $oggi2, $tmp);
    $tmp = str_replace("--siteurl--", $siteurl, $tmp);
    $tmp = str_replace("--paystatus--", $paystatus, $tmp);
    $tmp = str_replace("--ccemail--", $ccemail, $tmp);
    $tmp = str_replace("--brevernd--", $brevernd, $tmp);
    $tmp = str_replace("--downloadid--", $brevernd, $tmp);
    $tmp = str_replace("--secid--", $customid, $tmp);
    $tmp = str_replace("--customid--", $customid, $tmp);
    $tmp = str_replace("--email--", $buyeremail, $tmp);
    $tmp = str_replace("--shop--", $buyershop, $tmp);
    $tmp = str_replace("--buyername--", $buyername, $tmp);
    $tmp = str_replace("--buyerfirst--", $buyerfirst, $tmp);
    $tmp = str_replace("--buyerlast--", $buyerlast, $tmp);
    $tmp = str_replace("--buyeraddress--", $buyeraddress, $tmp);
    $tmp = str_replace("--buyeraddress1--", $buyeraddress1, $tmp);
    $tmp = str_replace("--buyeraddress2--", $buyeraddress2, $tmp);
    $tmp = str_replace("--buyercity--", $buyercity, $tmp);
    $tmp = str_replace("--buyerzip--", $buyerzip, $tmp);
    $tmp = str_replace("--buyercf--", $buyercf, $tmp);
    $tmp = str_replace("--buyerpiva--", $buyerpiva, $tmp);
    $tmp = str_replace("--buyeremail--", $buyeremail, $tmp);
    $tmp = str_replace("--buyertel--", $buyertel, $tmp);
    $tmp = str_replace("--buyerpay--", $buyerpay, $tmp);
    $tmp = str_replace("--buyertos--", $buyertos, $tmp);
    $tmp = str_replace("--buyercountry--", $buyercountry, $tmp);
    $tmp = str_replace("--buyerprovincia--", $buyerprovincia, $tmp);
    $tmp = str_replace("--sellername--", $sellername, $tmp);
    $tmp = str_replace("--sellerpiva--", $sellerpiva, $tmp);
    $tmp = str_replace("--selleriva--", $selleriva, $tmp);
    $tmp = str_replace("--sellerivadesc--", $sellerivadesc, $tmp);
    $tmp = str_replace("--sellertel--", $sellertel, $tmp);
    $tmp = str_replace("--sellerfax--", $sellerfax, $tmp);
    $tmp = str_replace("--selleraddress--", $selleraddress, $tmp);
    $tmp = str_replace("--sellercity--", $sellercity, $tmp);
    $tmp = str_replace("--sellercurrency--", $sellercurrency, $tmp);
    $tmp = str_replace("--selleremail--", $selleremail, $tmp);
    $tmp = str_replace("--sellerlogo--", $sellerlogo, $tmp);
    $tmp = str_replace("--selleriban--", $selleriban, $tmp);
    $tmp = str_replace("--sellerbank--", $sellerbank, $tmp);
    $tmp = str_replace("--sellerra--", $sellerra, $tmp);
    $tmp = str_replace("--sellerradesc--", $sellerradesc, $tmp);
    $tmp = str_replace("--sellerinps--", $sellerinps, $tmp);
    $tmp = str_replace("--sellerinpsdesc--", $sellerinpsdesc, $tmp);
    $tmp = str_replace("--sellerlegal--", $sellerlegal, $tmp);
    $tmp = str_replace("--sellercap--", $sellercap, $tmp);
    $tmp = str_replace("--sellerzip--", $sellerzip, $tmp);
    $tmp = str_replace("--sellercf--", $sellercf, $tmp);
    $tmp = str_replace("--sellerrea--", $sellerrea, $tmp);
    $tmp = str_replace("--sellertos--", $sellertos, $tmp);
    $tmp = str_replace("--sellertosurl--", $sellertosurl, $tmp);
    $tmp = str_replace("--sellerurl--", $sellerurl, $tmp);
    $tmp = str_replace("--sellerpaypalgrazie--", $sellerpaypalgrazie, $tmp);
    $tmp = str_replace("--sellerpaypalannulla--", $sellerpaypalannulla, $tmp);
    $tmp = str_replace("--errorname--", $errorname, $tmp);
    $tmp = str_replace("--erroraddress--", $erroraddress, $tmp);
    $tmp = str_replace("--errorcity--", $errorcity, $tmp);
    $tmp = str_replace("--errorzip--", $errorzip, $tmp);
    $tmp = str_replace("--errorcf--", $errorcf, $tmp);
    $tmp = str_replace("--errorpiva--", $errorpiva, $tmp);
    $tmp = str_replace("--errortos--", $errortos, $tmp);
    $tmp = str_replace("--erroremail--", $erroremail, $tmp);
    $tmp = str_replace("--errorcountry--", $errorcountry, $tmp);
    $tmp = str_replace("--errorprovincia--", $errorprovincia, $tmp);
    $tmp = str_replace("--fatturaprezzo--", $fatturaprezzo, $tmp);
    $tmp = str_replace("--fatturasubimponibile--", $fatturasubimponibile, $tmp);
    $tmp = str_replace("--fatturaimponibile--", $fatturaimponibile, $tmp);
    $tmp = str_replace("--fatturanonimponibile--", $fatturanonimponibile, $tmp);
    $tmp = str_replace("--fatturaiva--", $fatturaiva, $tmp);
    $tmp = str_replace("--fatturadata--", $fatturadata, $tmp);
    $tmp = str_replace("--fatturaanno--", $fatturaanno, $tmp);
    $tmp = str_replace("--fatturanum--", $fatturanum, $tmp);
    $tmp = str_replace("--fatturalegal--", $fatturalegal, $tmp);
    $tmp = str_replace("--fatturatot--", $fatturatot, $tmp);
    $tmp = str_replace("--fatturara--", $fatturara, $tmp);
    $tmp = str_replace("--fatturainps--", $fatturainps, $tmp);
    $tmp = str_replace("--fatturanetto--", $fatturanetto, $tmp);
    $tmp = str_replace("--helpemail--", $helpemail, $tmp);
    $tmp = str_replace("--mainpaypalemail--", $mainpaypalemail, $tmp);
    $tmp = str_replace("--fatturamiurl--", $fatturamiurl, $tmp);
    $tmp = str_replace("--lastfattnum--", $lastfattnum, $tmp);
    $tmp1 = $lastfattnum + 1;
    if (substr($lastfattdata, -4, 4) != date("Y")) {
        $tmp1 = 1;
    }
    $tmp = str_replace("--newfattnum--", $tmp1, $tmp);
    $tmp = str_replace("--lastfattdata--", $lastfattdata, $tmp);
    $tmp = str_replace("--lastfattemail--", $lastfattemail, $tmp);
    $tmp = str_replace("--lastfattname--", $lastfattname, $tmp);
    $tmp = str_replace("--abboprice--", $abboprice, $tmp);
    $tmp = str_replace("--abbounit--", $abbounit, $tmp);
    $tmp = str_replace("--abbofreq--", $abbofreq, $tmp);

    return $tmp;
}

function ControlloPIVA($pi)
{
    if ($pi == '') {
        return false;
    }
    if (strlen($pi) != 11) {
        return false;
    }
    if (!preg_match("/^[0-9]+$/", $pi)) {
        return false;
    }
    $s = 0;
    for ($i = 0; $i <= 9; $i += 2) {
        $s += ord($pi[$i]) - ord('0');
    }
    for ($i = 1; $i <= 9; $i += 2) {
        $c = 2 * (ord($pi[$i]) - ord('0'));
        if ($c > 9) {
            $c = $c - 9;
        }
        $s += $c;
    }
    if ((10 - $s % 10) % 10 != ord($pi[10]) - ord('0')) {
        return false;
    }
    return true;
}

function ControlloCodiceFiscale($cf)
{
    if ($cf == '') {
        return false;
    }
    if (strlen($cf) != 16) {
        return false;
    }
    $cf = strtoupper($cf);
    if (!preg_match("/^[A-Z0-9]+$/", $cf)) {
        return false;
    }
    $s = 0;
    for ($i = 1; $i <= 13; $i += 2) {
        $c = $cf[$i];
        if ('0' <= $c && $c <= '9') {
            $s += ord($c) - ord('0');
        } else {
            $s += ord($c) - ord('A');
        }
    }
    for ($i = 0; $i <= 14; $i += 2) {
        $c = $cf[$i];
        switch ($c) {
            case '0':
                $s += 1;
                break;
            case '1':
                $s += 0;
                break;
            case '2':
                $s += 5;
                break;
            case '3':
                $s += 7;
                break;
            case '4':
                $s += 9;
                break;
            case '5':
                $s += 13;
                break;
            case '6':
                $s += 15;
                break;
            case '7':
                $s += 17;
                break;
            case '8':
                $s += 19;
                break;
            case '9':
                $s += 21;
                break;
            case 'A':
                $s += 1;
                break;
            case 'B':
                $s += 0;
                break;
            case 'C':
                $s += 5;
                break;
            case 'D':
                $s += 7;
                break;
            case 'E':
                $s += 9;
                break;
            case 'F':
                $s += 13;
                break;
            case 'G':
                $s += 15;
                break;
            case 'H':
                $s += 17;
                break;
            case 'I':
                $s += 19;
                break;
            case 'J':
                $s += 21;
                break;
            case 'K':
                $s += 2;
                break;
            case 'L':
                $s += 4;
                break;
            case 'M':
                $s += 18;
                break;
            case 'N':
                $s += 20;
                break;
            case 'O':
                $s += 11;
                break;
            case 'P':
                $s += 3;
                break;
            case 'Q':
                $s += 6;
                break;
            case 'R':
                $s += 8;
                break;
            case 'S':
                $s += 12;
                break;
            case 'T':
                $s += 14;
                break;
            case 'U':
                $s += 16;
                break;
            case 'V':
                $s += 10;
                break;
            case 'W':
                $s += 22;
                break;
            case 'X':
                $s += 25;
                break;
            case 'Y':
                $s += 24;
                break;
            case 'Z':
                $s += 23;
                break;
        }
    }
    if (chr($s % 26 + ord('A')) != $cf[15]) {
        return false;
    }
    return true;
}

function sendemail($to, $subject, $message)
{
    global $sellername, $selleremail;

    $random_hash = md5(date('r', time()));

    $headers = "MIME-Version: 1.0\r\n" .
        "From: " . $sellername . " <" . $selleremail . ">\r\n" .
        "Reply-To: " . $selleremail . "\r\n";
    $headers .= "Bcc: " . $selleremail . "\r\n";
    $headers .= "Content-Type: multipart/alternative;boundary = phpalt-$random_hash\r\n\r\n";

    $bdy = "--phpalt-$random_hash\r\n" .
        "Content-Type: text/plain; charset=ISO-8859-1\r\n\r\n" .
        strip_tags($message) . "\r\n\r\n";

    $bdy .= "--phpalt-$random_hash\r\n" .
        "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n" .
        $message . "\r\n\r\n";

    $bdy .= "--phpalt-$random_hash--\r\n";

    $mail_sent = @mail($to, $subject, $bdy, $headers);
    $tmp = $mail_sent ? "Mail sent" : "Mail failed";
    return $tmp;
}

function mandafattura($toemail, $fromemail, $pdf, $testo, $contentpdf)
{
    $fileatt = $pdf; // Path to the file
    $fileatt_type = "application/pdf"; // File Type
    $fileatt_name = $pdf; // Filename that will be used for the file as the attachment

    $email_from = $fromemail; // Who the email is from
    $email_subject = "Invio fattura"; // The Subject of the email
    $email_txt = $testo; // Message that the email has in it
    $email_to = $toemail; // Who the email is too

    $headers = "From: " . $email_from;

    $file = fopen($fileatt, 'rb');
    $data = fread($file, filesize($fileatt));
    fclose($file);

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    $headers .= "\r\nMIME-Version: 1.0\r\n" .
        "Content-Type: multipart/mixed;\r\n" .
        " boundary=\"{$mime_boundary}\"";

    $email_message .= "This is a multi-part message in MIME format.\r\n\r\n" .
        "--{$mime_boundary}\r\n" .
        "Content-Type:text/html; charset=\"iso-8859-1\"\r\n" .
        "Content-Transfer-Encoding: 7bit\r\n\r\n" .
        $email_txt . "\r\n\r\n";

    $data = chunk_split(base64_encode($data));

    $email_message .= "--{$mime_boundary}\r\n" .
        "Content-Type: {$fileatt_type};\r\n" .
        " name=\"{$fileatt_name}\"\r\n" .
        "Content-Transfer-Encoding: base64\r\n\r\n" .
        $data . "\r\n\r\n" .
        "--{$mime_boundary}--\r\n";

    $ok = @mail($email_to, $email_subject, $email_message, $headers);
    if ($ok) {
        $tmp = "<font face=verdana size=2>The file was successfully sent!</font>";
    } else {
        $tmp = "Sorry but the email could not be sent. Please go back and try again!";
    }

    return $tmp;
}

function pulisci($tmp)
{
    $tmp = strtr($tmp, "'%;:\"\\", "       ");
    return $tmp;
}

function random_string($len = 12)
{
    $pool = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
    $str = '';
    for ($i = 0; $i < $len; $i++) {
        $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
    }
    return $str;
}

function makecsv($elenco, $csvsugg)
{
    $path = "../../zip/";
    $dt = date("Y m d His");
    $dt2 = date("Ymd");
    $filename = $elenco . " " . $dt2 . ".zip";

    $tmpname = tempnam($path, "zip");

    $zip = new ZipArchive();

    if ($zip->open($tmpname, ZIPARCHIVE::CREATE) !== TRUE) {
        exit("cannot open <$tmpname>\n");
    }

    $info = "Csv output of " . $elenco . " produced on the filter you asked today, " . $dt;

    $zip->addFromString("info.txt", $info);
    $zip->addFromString("elenco" . $elenco . " " . $dt2 . ".csv", $csvsugg);

    $zip->close();

    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=" . $filename);
    header("Content-Transfer-Encoding: binary");
    readfile($tmpname);

    unlink($tmpname);
}

function cdt($tmp)
{
    return substr($tmp, 8, 2) . "." . substr($tmp, 5, 2) . "." . substr($tmp, 0, 4);
}

function rdt($tmp)
{
    return substr($tmp, -2, 2) . "." . substr($tmp, -4, 2) . "." . substr($tmp, 0, 4);
}

function leggifile($nomefile)
{
    $nomefile = str_replace(".template", ".htm", $nomefile);
    $myFile = "./template" . $nomefile;
    $fh = fopen($myFile, 'r');
    $tmp = fread($fh, filesize($myFile));
    fclose($fh);
    return $tmp;
}

function apredb($db_host, $db_user, $db_password, $db_name)
{
    global $dbg;

    $mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
    $mysqli->set_charset("utf8mb4");

    if ($mysqli->connect_errno) {
        if ($dbg == 1) {
            die("mysqli err: " . $mysqli->connect_errno . " " . $mysqli->connect_error . "n");
        }
        if (!$mysqli->set_charset("utf8mb4")) {
            echo "Error loading character set utf8: " . $mysqli->error;
            exit;
        }
    }
    return $mysqli;
}

?>
                        )

                )

        )

)