| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- include_once "../../include/DB.php";
- $AssetID="";
- if (isset($_POST["AssetID"]) && !empty($_POST["AssetID"])) {
- $AssetID=$_POST["AssetID"];
- }
- $ServiceCheckSQL = "SELECT * FROM servicehistory servicehistory WHERE servicehistory.AssetID='$AssetID' AND servicehistory.isServiced='0'";
- $ServiceCheckResult = $conn->query($ServiceCheckSQL);
- if ($ServiceCheckResult!== false && $ServiceCheckResult->num_rows > 0) {
- while($ServiceCheckRow = $ServiceCheckResult->fetch_assoc()) {
- $ServiceHistoryID = $ServiceCheckRow["ServiceHistoryID"];
- $ServiceUpdateSQL = "UPDATE servicehistory servicehistory SET servicehistory.InWard='$currentDateTime',isServiced='1' WHERE servicehistory.ServiceHistoryID='$ServiceHistoryID'";
- $ServiceUpdateResult = $conn->query($ServiceUpdateSQL);
- if ($ServiceUpdateResult === TRUE) {
- $value = array(
- "Message"=>"Service updated successfully",
- );
- // Use json_encode() function
- $json = json_encode($value);
- }else {
- http_response_code(404);
- $errorMesage= $conn->error;
- // Declare an array with error message
- $value = array(
- "Message"=>"Something went wrong",
- "Error"=>$errorMesage
- );
- // Use json_encode() function
- $json = json_encode($value);
- }
- }
-
- }else {
- $ServiceInsertSQL = "INSERT INTO servicehistory(AssetID) VALUES ('$AssetID')";
- $ServiceInsertResult = $conn->query($ServiceInsertSQL);
- if ($ServiceInsertResult === TRUE) {
- $value = array(
- "Message"=>"Service insert successfully",
- );
- // Use json_encode() function
- $json = json_encode($value);
- }else {
- http_response_code(404);
- $errorMesage= $conn->error;
- // Declare an array with error message
- $value = array(
- "Message"=>"Something went wrong",
- "Error"=>$errorMesage
- );
- // Use json_encode() function
- $json = json_encode($value);
- }
- }
- // Display the output
- echo ($json);
- $conn->close();
|