<?php
include('dbconnection.php');
session_start();
$query = 'SELECT `order`.* FROM `order` WHERE (`order`.`stato`= 0 and `order`.`punto_vendita`='.$_SESSION['id_pv'].')';
$run_query = mysqli_query($connection, $query);
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
setInterval(newNoti, 3000);
function newNoti(){
var ultimo = $('table tr:last td:first').text();
//var ultimo = $(".table tr").last().attr("punto_vendita");
alert(ultimo)
$.ajax({
type: "post",
url: "file2.php",
data:{'last_id':ultimo},
success:function(resp){
if(resp != ""){
document.querySelector('audio').play();
$(".table").append(resp);
}
},
error:function(){
alert('Some problem occured, please try again.');
}
})
}
});
</script>
</head>
<body>
<audio src="icq_sound_mp3.mp3" id="audio"></audio>
<div id="visualizzaTabella">
<div class="container">
<div class="top_header">
<h2>
ORDINI IN ARRIVO
<?php
if ($result=mysqli_query($connection,$query))
{
$rowcount=mysqli_num_rows($result);
printf("( %d )\n",$rowcount);
mysqli_free_result($result);
}
?>
</h2>
</div>
<br>
<div id="links">
<table class="table table-bordered table table-hover">
<thead>
<tr>
<th style="display:none;">Id</th>
<th>Id</th>
<th>Parthner</th>
<th>Dettaglio Ordine</th>
<th>Stato</th>
</tr>
</thead>
<tbody>
<?php
while( $result = mysqli_fetch_assoc($run_query) )
{
if($result) {
?>
<tr id="<?php echo $result['id_order']; ?>">
<tr>
<td style="display:none;"><?php echo $result['id']; ?></td>
<td><?php echo $result['id_order']; ?></td>
<td><img align="middle" src="<?php echo $result['parthner']?>" width="50%" ></td>
<td><?php echo $result['json_ordine'] ?></td>
<td>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input value="<?php echo $result['stato'] ?>" type="submit" name="">
</form>
</td>
</tr> <?php } } ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$id = ($_POST["id"]);
$url = "####".$id;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
"Authorization: bWVtZW50byBhdWRlcmUgc2VtcGVy",
"Azione: 1")
);
//So that curl_exec returns the contents of the cURL; rather than echoing it
//curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$response = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response == 200) {
echo '<script type="text/javascript">';
echo 'alert("COMUNICAZIONE ESEGUITA CORRETTAMENTE")';
echo '</script>';
exit;}
else{
echo '<script type="text/javascript">';
echo 'alert("ERRORE DI COMUNICAZIONE, RIPROVA")';
echo '</script>';
exit;
}
}
mysqli_close($connection);
?>