tinyqc/v1/inc/entry_ajax.php

51 lines
1.4 KiB
PHP
Raw Normal View History

<?php
include '../config.php';
// Read POST data
$postData = json_decode(file_get_contents("php://input"));
$request = "";
if(isset($postData->request)){
$request = $postData->request;
}
// Get Test
if($request == 'getTest'){
$result = array();$data = array();
if(isset($postData->control)){
$control = $postData->control;
$sql = "select dt.id, dt.name from CONTROL_TEST ct left join DICT_TEST dt on dt.id=ct.testid where ct.controlid='$control'";
$stmt = sqlsrv_query( $conn1, $sql );
if( $stmt == false) { die( print_r( sqlsrv_errors(), true) ); }
while ( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC ) ) {
$id = $row[0];
$name = $row[1];
$data[] = array( "id" => $id, "name" => $name );
}
}
echo json_encode($data);
die;
}
// Get Control
elseif($request == 'getControl'){
$result = array();$data = array();
if(isset($postData->dates)){
$dates = $postData->dates;
$dept = $postData->dept;
$sql = "select id, name, lot from DICT_CONTROL where expdate > '$dates' and deptID='$dept'";
$stmt = sqlsrv_query( $conn1, $sql );
if( $stmt == false) { die( print_r( sqlsrv_errors(), true) ); }
while ( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC ) ) {
$id = $row[0];
$name = $row[1];
$lot = $row[2];
$data[] = array( "id" => $id, "name" => "$name - $lot" );
}
}
echo json_encode($data);
die;
}