<?php
//creo la sessione
//in TUTTE le pagine in cui uso le sessioni
session_start();
if(!isset($_SESSION['user']) || !isset($_SESSION['pwd'])){//verifichi che esistano entrambe
//non esistono
//var_dump($_SESSION);
header("location:login.php");
exit();
}
if(!isset($_SESSION['barcode'])){
} else {
//unset($_SESSION['barcode']);
if(basename($_SERVER['HTTP_REFERER']) != 'puntifidelity.php'){
//non provengo da login.php
unset($_SESSION['barcode']);
//var_dump($_SESSION);
} else {
}
}
//session_destroy($_SESSION['barcode']);
//session_write_close();
include('connect.php');
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<title>Creazione DdT</title>
<style type="text/css">
* { font-family:Arial; }
h2 { padding:0 0 5px 5px; }
h2 a { color: #224f99; }
a { color:#999; text-decoration: none; }
a:hover { color:#802727; }
p { padding:0 0 5px 0; }
input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; }
</style>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
var ajax = new sack();
var currentClientID=false;
function getClientData()
{
var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
if(clientId.length==4 && clientId!=currentClientID){
currentClientID = clientId
ajax.requestFile = 'getClient.php?getClientId='+clientId; // Specifying which file to get
ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}
}
function showClientData()
{
var formObj = document.forms['clientForm'];
eval(ajax.response);
}
function initFormEvents()
{
document.getElementById('clientID').onblur = getClientData;
document.getElementById('clientID').focus();
}
window.onload = initFormEvents;
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
$("#aggiungi").click(function() {
elem = $(".campo").first().clone();
elem.css("display", "block");
elem.appendTo("#campi");
});
$("#campi").on("click", ".remove", function() {
$(this).parent().remove();
});
$("#aggiungi").click();
});
</script>
<style type="text/css">
body { background-image: url(sfondo.jpg);
background-repeat: repeat-x;
font: Eras Medium ITC;
}
</style>
<style type="text/css">
#main {
width:820px;
height:600px;
position:absolute;
top:352px;
left:523px;
margin:-150px 0 0 -336px;
}
</style>
</head>
<body bgcolor="#f7b76b">
<p align="center">
<img src="images/logo.png" >
<form action="read_ddt.php" method="post" name="read">
<div id="main">
Operatore: <font color="#FF0000"><?php echo $_SESSION[user]; ?></font><br>
Data: <?php echo (date("d/m/Y"));?><br>
Ora: <?php echo (date("H:i"));?><br>
Barcode card:<font color="#FF0000"><?php echo $_SESSION[barcode]; ?></font><br><br>
<input type="button" onClick="window.open('puntifidelity.htm', 'Cerca card', 'width=690, height=700, resizable, status, scrollbars=1, location');"
value="Cerca card">
<p align="left"><a href="#" id="aggiungi">Aggiungi riga</a></p>
<div id="campi">
<p>
<div class="campo" style="display: none;">
<input type="text" placeholder="Barcode" name="campo[]" id="barcode">
<input type="text" placeholder="Codice" name="codice[]" id="clientID">
<input type="text" placeholder="Descrizione" name="descrizione[]" id="descrizione">
<input type="text" placeholder="Quantità" name="quantita[]" id="quantita">
<br><a href="#" class="remove">Rimuovi riga</a></br>
</p>
</div>
</div>
<p>
<?php
if(!isset($_SESSION['barcode'])){
echo '<b><font color="black"> Saldo Punti : </font></b> 0 <br>';
echo '<br>';
} else {
$query=mysql_query("SELECT * FROM fidelitypoint WHERE barcode='$_SESSION[barcode]' ");
//verifico che esista una una card con tale barcode
$esiste=mysql_num_rows($query);
//se $esiste == 0 non cè
if($esiste > 0){//esiste
//estraggo usn e pass
$rows=mysql_fetch_array($query);
}
$querypunti=mysql_query("Select sum(punti) from fidelitypoint where barcode='$_SESSION[barcode]'");
$row=mysql_fetch_array($querypunti);
echo'<b><font color="black"> Saldo Punti : </font></b><font color="red">' . $row[0] . '</font>';
echo '<br>';
echo '<br>';
}
?>
<input name="read" type="submit" id="read" value="Inserisci">
</p>
</div>
</form>
</p>
</body>
</html>