ppeasy/public/ajax.php

58 lines
2.5 KiB
PHP

<?php
include('include/headscript.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$requiredParams = [
'description_identificationparts', 'article_identificationparts',
'color_identificationparts',
'idtrfdetails', 'kindoftest', 'ididentificationparts'
];
foreach ($requiredParams as $param) {
if (! in_array($param, array_keys($_POST)) || empty($_POST[$param])) {
$response = json_encode([
'status' => 'failed',
'message' => "Mandatory field is missing !({$param})"
]);
header('Content-Type: application/json');
echo $response;
exit();
}
}
$UpdateQuery = new WA_MySQLi_Query($cmctrfdb);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "identificationparts";
$UpdateQuery->bindColumn("description_identificationparts", "s", "{$_POST['description_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("article_identificationparts", "s", "{$_POST['article_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("color_identificationparts", "s", "{$_POST['color_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("cmcreportnumber_identificationparts", "s", "{$_POST['cmcreportnumber_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("cmcreportdate_identificationparts", "s", "{$_POST['cmcreportdate_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("thirdlabreportnumber_identificationparts", "s", "{$_POST['thirdlabreportnumber_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("thirdlabreportdate_identificationparts", "s", "{$_POST['thirdlabreportdate_identificationparts']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("idtrfdetails", "i", "{$_POST['idtrfdetails']}", "WA_DEFAULT");
$UpdateQuery->bindColumn("kindoftest", "s", "{$_POST['kindoftest']}", "WA_DEFAULT");
$UpdateQuery->addFilter("ididentificationparts", "=", "i", "{$_POST['ididentificationparts']}");
try {
$UpdateQuery->execute();
$response = json_encode([
'status' => 'success'
]);
} catch (Exception $e) {
$response = json_encode([
'status' => 'failed',
'message' => $e->getMessage()
]);
}
} else {
$response = json_encode([
'status' => 'failed',
'message' => 'Method not allowed'
]);
}
header('Content-Type: application/json');
echo $response;