<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];

if (isset($_REQUEST['barcode'])) {
    $barcode = $_REQUEST['barcode'];
    $code = $_REQUEST['code'];

    $getm = mysqli_query($conn, "SELECT * FROM `item` WHERE `barcode`='$barcode' and code != '$code'")or die(mysqli_error($conn));
    $m = mysqli_num_rows($getm);

    if($m > 0){
        $data = '1';
    }else{
        $data = '0';
    }
    
    $rows = array();
    $rows = array('dataflg' => $data
    );
    header("Content-type: application\json");
    echo json_encode($rows);
    
}


if (isset($_REQUEST['name'])) {
    $name = $_REQUEST['name'];
    $code = $_REQUEST['code'];

    $getm = mysqli_query($conn, "SELECT * FROM `item` WHERE `name`='$name' and code != '$code'")or die(mysqli_error($conn));
    $m = mysqli_num_rows($getm);

    if($m > 0){
        $data = '1';
    }else{
        $data = '0';
    }
    
    $rows = array();
    $rows = array('dataflg2' => $data
    );
    header("Content-type: application\json");
    echo json_encode($rows);
}