<?php
$filename = 'c_leitura.php';

if (!file_exists($filename)) {
  header("Location: error.php"); exit;   
}
error_reporting(0); 
include 'c_leitura.php';
require_once("db.php");

$idprod = addslashes($_GET['idprod']);
$dono = addslashes($_GET['dono']);
$exp =  addslashes($_GET['exp']);

$query = "SELECT status, validade,  DATEDIFF((DATE_ADD(expiracao,INTERVAL validade DAY)),SYSDATE()) dias FROM tablet WHERE idprod = '".$idprod."' AND cliente = '".$dono."'";
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result);

$status = $row['status'];
if ($row['dias'] > 0){
  $dias = $row['dias'];  
} else {
  $dias = 0;  
}


if($status == 0){
    echo "NA---splithere---";
} elseif ($status == 1 && $dias == 0) {
    echo "NA---splithere---"; 
    $query = "UPDATE tablet SET status='0' WHERE idprod='".$idprod."'";
    mysql_query($query) or die(mysql_error());
} else {
	echo $dias."---splithere---";
}
?>
