<?php session_start();
if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
    include ('../scripts/classes.php');
    //echo $your_email;
    if ($_SERVER['REQUEST_METHOD'] != 'POST') exit;
    
    foreach($_POST as $key => $value) $_POST[$key] = urldecode(trim($value));
    $barcode = mysqli_real_escape_string($mysqli, $_POST['barcode']);
    $errors = array();
    
    if ($barcode == '') {
      $errors[] = "Please enter barcode!";
    }
    
    	//Customer Match Query
    	$match = "SELECT barcode_id FROM cls_customers WHERE barcode_id='$barcode'";
    	$result = mysqli_query($mysqli, $match) or die("Query failed : " . mysqli_error($mysqli));
    	if (mysqli_num_rows($result) == 0){
    	$errors[]= "Δε βρέθηκε Πελάτης!";
    	$str = implode("\n", $errors);
    	die("Search error:\n\n" . $str);
    }
    if (sizeof($errors) > 0) {
      $str = implode("\n", $errors);
      die("Search error:\n\n" . $str);
    }
    mysqli_close($mysqli); 
    die('OK'); // send success indicator
} else {
    header('Location: login.php');
}
?>