<?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['hsncode'])) {
    $hsncode = $_REQUEST['hsncode'];
    $ms = $_REQUEST["ms"];

    if ($ms == "M"){
        $gethsn = mysqli_query($conn, "SELECT `descrip1`,`descrip2` FROM `matsup` WHERE `hsncode`='$hsncode' ")or die(mysqli_error($conn));
        $fethsn = mysqli_fetch_array($gethsn);
        $descrip1 = $fethsn['descrip1'];
        $descrip2 = $fethsn['descrip2'];
    }else{
        $gethsn = mysqli_query($conn, "SELECT `descrip1`,`descrip2` FROM `manservice` WHERE `hsncode`='$hsncode' ")or die(mysqli_error($conn));
        $fethsn = mysqli_fetch_array($gethsn);
        $descrip1 = $fethsn['descrip1'];
        $descrip2 = $fethsn['descrip2'];
    }

    $data = array( 'descrip1' => "$descrip1", 'descrip2' => "$descrip2",);
    header('Content-Type: application/json');
    echo json_encode($data);
}

// if (isset($_REQUEST['descrip1']) || $_REQUEST['descrip2']) {

//     $descrip1 = $_REQUEST['descrip1'];
//     $descrip2 = $_REQUEST['descrip2'];
//     $ms = $_REQUEST["ms"];

//     if ($ms == "M"){
//        $gethsn = mysqli_query($conn, "SELECT hsncode,`descrip1`,`descrip2` FROM `matsup` WHERE `descrip1`='$descrip1' OR `descrip2`='$descrip2' ")or die(mysqli_error($conn));
//        $fethsn = mysqli_fetch_array($gethsn);
//        $hsncode = $fethsn['hsncode'];
//        $descrip1 = $fethsn['descrip1'];
//        $descrip2 = $fethsn['descrip2'];
//     }else{
//        $gethsn = mysqli_query($conn, "SELECT hsncode,`descrip1`,`descrip2` FROM `manservice` WHERE `descrip1`='$descrip1' OR `descrip2`='$descrip2' ")or die(mysqli_error($conn));
//        $fethsn = mysqli_fetch_array($gethsn);
//        $hsncode = $fethsn['hsncode'];
//        $descrip1 = $fethsn['descrip1'];
//        $descrip2 = $fethsn['descrip2'];
//     }


//     $data = array( 'hsncode' => "$hsncode",'descrip1' => "$descrip1", 'descrip2' => "$descrip2",);
//     header('Content-Type: application/json');
//     echo json_encode($data);
// }
?>