<?php
session_start();
if ($first_name>=1){
echo "Prego effettuare il login <a href=\"/contenuti.php\"> Qui<br>
&copy;Bloghosteria.com<br>
</a>";
}
 elseif  ( empty( $first_name ) ) {
?> Prego effettuare il login <a href="/contenuti.php"> Qui<br>
&copy;Bloghosteria.com<br>
</a>
<?php
} elseif ($first_name==$_SESSION['first_name']) { 
include ("langselect.php");
include ("config.php");
 echo "Salve,
". $_SESSION['last_name'] ." <a href=logout.php> Logout</a>
<style type=\"text/css\">

a:link, a:visited {
	color: #009933; text-decoration: none;
	font-weight: bold;
}

a:hover {
	color: #ff6600;	text-decoration: none;
	font-weight: bold;
}
</style>
<p><a href=\"sample.php?last_name=$Ragione_Sociale\">$lang0004</a> |
<a href=\"clgestord.php?Ragione_Sociale=$Ragione_Sociale\">$lang0005</a> |
<a href=mailto:$emailwebm>$lang0006</a> |
<a href=\"gestpag.php?Ragione_Sociale=$Ragione_Sociale\">$lang0007</a></p>";
include ("config.php");
$npag = ("nd");
$inpgm = ("$lang0153");
mysql_connect("$hhost","$login","$pass") or die ("Problem connecting to DataBase");
$query = "SELECT * FROM sd_ordini WHERE Ragione_Sociale = '$Ragione_Sociale' and Tipo_Pagamento='$npag' ";
$result = mysql_db_query("$dbname", $query);
//Doc - added variable
$ordini_consolidated = "";
if ($result) {

	while ($r = mysql_fetch_array($result)) {
		$Ordini = $r["ID_Ordine"];
		$Protocollo = $r["Protocollo"];
		$Prezzo = $r["Prezzo"];
		$Iva = $r["Iva"];


		$Banca = ("PAYPAL");
		$tax = $tax + $Prezzo * $Iva / 100 * $Protocollo ;
		$Imponibile = $Imponibile + $Prezzo * $Protocollo ;
		$Total = $Imponibile + $tax ;
		//Doc
		$ordini_consolidated = $ordini_consolidated."--".$Ordini ;
	}

}

include ("numord.php");
mysql_connect("$hhost","$login","$pass") or die ("Problem connecting to DataBase");
$query = "SELECT * FROM pagam ";
$result = mysql_db_query("$dbname", $query);

// Doc
$sql = mysql_query("INSERT INTO pagam (Total, Ragione_Sociale, Banca, Ordini)
		VALUES('$Total', '$Ragione_Sociale', '$Banca', '$ordini_consolidated')") or die (mysql_error());



mysql_connect("$hhost","$login","$pass") or die ("Problem connecting to DataBase");
$query = "SELECT * FROM sd_ordini WHERE Ragione_Sociale = '$Ragione_Sociale' and Tipo_Pagamento='$npag' ";
$result = mysql_db_query("$dbname", $query);
if ($result) {


$query ="update sd_ordini set Tipo_Pagamento='$Tipo_Pagamento', Status='$inpgm'
where Ragione_Sociale='$Ragione_Sociale' and Tipo_Pagamento='$npag' ";
$result = mysql_db_query("$dbname", $query);

echo "$lang0134";



}else{
echo "<p>$lang0121</p>
<p>$emailwebm</p>";
}

} else {
echo "Prego effettuare il login <a href=\"contenuti.php\"> Qui<br>
&copy;Bloghosteria.com<br>
</a>";
}
?>
