considera che prima c'è tutta la parte sulle sessioni del carrello; questa che segue è la parte della stampata del carrello e degli step successivi
Codice PHP:
$db = mysql_connect($host, $user, $password);
mysql_select_db($dbname, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.php");
foreach ($_SESSION['jnb_quantity'] as $prod=>$qta)
{
$query= "SELECT * FROM libri where id = '$prod'";
$rs = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($rs);
$titolo2 = str_replace("
"," ", $row['titolo']);
$costo = sprintf("%01.2f",$row['prezzo']*$qta);
$tot+=sprintf("%01.2f",$costo);
$globale = sprintf("%01.2f",$tot);
echo "<tr><td class='col'>";
if ($row['tipo'] == 'l') {
$_SESSION['spese1'] = 'y';
echo"";
}
else {
echo"PDF - ";
$_SESSION['spese2'] = 'n';
}
echo"$titolo2</td>
<td class='col' style='text-align: right;'>$row[prezzo]</td>
<td class='col' style='text-align: center;'>$qta</td>
<td class='col' style='text-align: right;'>$costo</td>
<td class='col' style='width: 10px;'>[url='viewp.php?where=carrello&action=subtract&product=$row[id]&quantidade=1&step=1'][img]del.gif[/img][/url]</td>
</tr>";
}
echo "
<tr><td colspan='4' style='text-align: right; padding: 5px;'>Totale [b]€ $globale[/b]</td></tr>
";
$db = mysql_connect($host, $user, $password);
mysql_select_db($dbname, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.php");
if (isset($_POST['spedizione'])) {
$_SESSION['spedizione'] = $_POST["spedizione"];
$spedizione = $_SESSION['spedizione'];
} if (isset($_SESSION['spedizione'])) {
$spedizione = $_SESSION['spedizione']; }
$query_sped= "SELECT * FROM metodi_spedizione where id_metodi_spedizione='$spedizione'";
$rs_sped = mysql_query($query_sped) or die(mysql_error());
$row_sped=mysql_fetch_array($rs_sped);
$descrizione_sped = $row_sped["descrizione_metodi_spedizione"];
$prezzo_sped = $row_sped["prezzo_metodi_spedizione"];
if (isset($spedizione)) {
echo "
<tr><td colspan='4' style='text-align: right; padding: 5px;'>$descrizione_sped [b]€ $prezzo_sped[/b]</td></tr>
";
}
if (isset($_POST['pagamento'])){
$_SESSION['pagamento'] = $_POST["pagamento"];
$pagamento = $_SESSION['pagamento'];
} if (isset($_SESSION['pagamento'])) {
$pagamento = $_SESSION['pagamento']; }
$query= "SELECT * FROM metodi_pagamento where id_metodi_pagamento='$pagamento'";
$rs = mysql_query($query) or die(mysql_error());
$row=mysql_fetch_array($rs);
$descrizione_pag = $row["descrizione_metodi_pagamento"];
$prezzo_pag = $row["prezzo_metodi_pagamento"];
if (isset($pagamento)) {
echo "
<tr><td colspan='4' style='text-align: right; padding: 5px;'>$descrizione_pag [b]€ $prezzo_pag[/b]</td></tr>
";
}
$completo = $prezzo_sped+$prezzo_pag+$globale;
$completo_format = sprintf("%01.2f",$completo);
echo"
<tr><td colspan='4' style='text-align: right; padding: 5px;'>Importo dovuto [b]€ $completo_format[/b]</td></tr>
</table>
";
// inizio 0
$step = $_GET["step"];
if (($step == '0') || ($step == '')) {
echo"
[url='index.php'][img]../images/continua.gif[/img][/url][url='viewp.php?where=carrello&step=1'][img]../images/procedi.gif[/img][/url]
";
}
// inizio 1
if ($step == '1') {
echo"<form name='modulo' action='viewp.php?where=carrello&step=2' method='POST'>";
if ($_SESSION['spese1'] == 'y') {
echo"
<fieldset>
<legend>[b]Seleziona un metodo di spedizione[/b]</legend>
";
$db=mysql_connect($host,$user,$password) or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
$sql="SELECT * FROM metodi_spedizione ORDER BY predefinito DESC";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($result)) {
$id_metodi_spedizione = $row["id_metodi_spedizione"];
$descrizione_metodi_spedizione = $row["descrizione_metodi_spedizione"];
$prezzo_metodi_spedizione = $row["prezzo_metodi_spedizione"];
$predefinito = $row["predefinito"];
echo"
<input type='radio' name='spedizione' value='$id_metodi_spedizione'"; if ($predefinito == '1') { echo"checked='checked'"; } echo"/> $descrizione_metodi_spedizione - $prezzo_metodi_spedizione €
";
}
} else { $_SESSION['spedizione'] = '1'; }
echo"</fieldset>
";
echo"<fieldset><legend>[b]Seleziona un metodo di pagamento[/b]</legend>
";
$db=mysql_connect($host,$user,$password)
or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
$sql_pag="SELECT * FROM metodi_pagamento ORDER BY predefinito DESC";
$result_pag=mysql_query($sql_pag) or die(mysql_error());
while ($row_pag=mysql_fetch_array($result_pag)) {
$id_metodi_pagamento = $row_pag["id_metodi_pagamento"];
$descrizione_metodi_pagamento = $row_pag["descrizione_metodi_pagamento"];
$prezzo_metodi_pagamento = $row_pag["prezzo_metodi_pagamento"];
$predefinito_pag = $row_pag["predefinito"];
echo"
<input type='radio' name='pagamento' value='$id_metodi_pagamento'"; if ($predefinito_pag == '1') { echo"checked='checked'"; } echo"/> $descrizione_metodi_pagamento - $prezzo_metodi_pagamento €
";
}
echo"</fieldset>";
echo"
[url='viewp.php?where=carrello&step=0'][img]../images/continua.gif[/img][/url]<INPUT type='SUBMIT' value=' ' style='background-image:url('../images/procedi.gif'); repeat: no; width: 59px; height: 25px; vertical-align: bottom; border: 0px;'></form>";
}
// inizio 2 LOGIN O REGISTRAZIONE
if ($step == '2') {
if (isset($_SESSION['pagamento']) && isset($_SESSION['spedizione']))
{
if (!isset($_SESSION['riconosciuto'])){
echo"
<form name='login' action='viewp.php?action=contr' method='post'>
<fieldset>
<legend>[b]Fai il login[/b]</legend>
Email <input name='email' type='text' value='' size='25' />
Password <input name='pass' type='password' size='15' />
Non sei registrato? [url='viewp.php?action=newus']Registrati ora[/url]
Hai dimenticaticato la password? [url='viewp.php?action=resetus']Clicca qui[/url]
</fieldset>
<INPUT type='SUBMIT' value='Entra'>
</form>
";
}
else
{
$riconosciuto = $_SESSION['riconosciuto'];
$db = mysql_connect($host, $user, $password);
mysql_select_db($dbname, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.php");
$rif_pagamento = $_SESSION['pagamento'];
$query= "SELECT * FROM metodi_pagamento where id_metodi_pagamento='$rif_pagamento'";
$rs = mysql_query($query) or die(mysql_error());
$row=mysql_fetch_array($rs);
$gate = $row["gate"];
$db = mysql_connect($host, $user, $password);
mysql_select_db($dbname, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.php");
$query_utente= "SELECT * FROM utenti where email_utenti='$riconosciuto'";
$rs_utente = mysql_query($query_utente) or die(mysql_error());
$row_utente=mysql_fetch_array($rs_utente);
$id_utente = $row_utente["id_utenti"];
$nome = $row_utente["nome_utenti"];
$cognome = $row_utente["cognome_utenti"];
$emaildb = $row_utente["email_utenti"];
$password = md5($row_utente["password_utenti"]);
$indirizzo = $row_utente["indirizzo_utenti"];
$citta = $row_utente["citta_utenti"];
$cap = $row_utente["cap_utenti"];
$stato = $row_utente["stato_utenti"];
$tel = $row_utente["tel_utenti"];
echo"
<form action='viewp.php?action=compra' method='post' name='frmPaypal'>
<fieldset><legend>[b]Riepilogo dati utente[/b]</legend>
<table width='100%' border='0' cellspacing='0' cellpadding='5'>
<input type='hidden' name='cmd' value='_ext-enter'>
<input type='hidden' name='redirect_cmd' value='_xclick'>
<input type='hidden' name='business' value='xxxx'>
<input type='hidden' name='id_utente' value='$id_utente'>
<input type='hidden' name='gate' value='$gate'>
<input type='hidden' name='amount' value='$completo_format'>
<input type='hidden' name='currency_code' value='EUR'>
<input type='hidden' name='notify_url' value='http://www.progedit.com/prove/ipn.php'>
<input type='hidden' name='return' value='http://www.tuosito.it/rientro.php'>
<input type='hidden' name='cancel_return' value='http://www.tuosito.it/rientro.php'>
<tr>
<td style='text-align: right; width: 80px;'>Nome</td>
<td style='width: 20px;'></td>
<td>
<input type='text' name='first_name' value='$nome'></td>
</tr>
<tr>
<td style='text-align: right;'>Cognome</td>
<td></td>
<td><input type='text' name='last_name' value='$cognome'></td>
</tr>
<tr>
<td style='text-align: right;'>Email</td>
<td></td>
<td><input type='text' name='email' value='$emaildb' readonly='readonly'></td>
</tr>
<tr>
<td style='text-align: right;'>Password</td>
<td></td>
<td><input type='password' name='pass' value='$password'></td>
</tr>
<tr>
<td style='text-align: right;'>Indirizzo</td>
<td></td>
<td>
<input type='hidden' name='address_override' value='1'>
<input type='text' name='address1' value='$indirizzo'></td>
</tr>
<tr>
<td style='text-align: right;'>Città</td>
<td></td>
<td><input type='text' name='city' value='$citta'></td>
</tr>
<tr>
<td style='text-align: right;'>CAP</td>
<td></td>
<td><input type='text' name='zip' value='$cap'></td>
</tr>
<tr>
<td style='text-align: right;'>Stato</td>
<td></td>
<td><input type='text' name='state' value='$stato'></td>
</tr>
<tr>
<td style='text-align: right;'>Telefono</td>
<td></td>
<td><input type='text' name='night_phone_a' value='$tel'></td>
</tr>
</table>
</fieldset>
<INPUT type='SUBMIT' value='Invia ordine'>
<INPUT type='SUBMIT' value='Aggiorna i dati anagrafici' onclick=\"this.form.action='viewp.php?do=updus'\">
</form>
";
}
}
else {
echo"<div align='left' style='color: red; font-weight: bold;'>Attenzione: non hai selezionato il metodo di pagamento o di spedizione.
[url='viewp.php?where=carrello&step=1']Torna indietro[/url]</div>";
}
}
}
else
{
echo"Il carrello è vuoto";
}
}