ESH/save_hrp_key.php
2024-10-23 18:28:06 +05:30

87 lines
2.5 KiB
PHP

<?php
include('includes/config/config.php');
include('log_entry.php');
include ('includes/functions.php');
error_log ( "Start Printing Request Attributes" );
$requestStr="";
foreach ( $_REQUEST as $key => $value ) {
$requestStr.=$key . " : " . $value . "\n";
error_log ( $key . " : " . $value . "<br />\r\n" );
}
error_log ( "End Printing Request Attributes" );
save_log($requestStr,'hrp_key','SAVE','save_hrp_key.php');
$id = $_POST['key_param_id'];
$name = $_POST['key_param_name'];
$name=strtolower($name);
$max_id=$_POST['max_id'];
$dataid;
error_log('max-d'.$name);
if($id!=$max_id){
$query = "update key_health_reportable_parameter_master set key_param_name = '$name',key_param_id = '$id', modified_by = '".$_SESSION['user_id']."' where key_param_id = '".$id."'";
}
else if($id=$max_id){
$queid="select key_param_id from key_health_reportable_parameter_master where key_param_id='".$id."'";
if (!$resultid = @mysqli_query($conn,$queid)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($resultid) > 0) {
while ($rowid = @mysqli_fetch_assoc($resultid)) {
$dataid = $rowid['key_param_id'];
}
}
if (!empty($dataid))
$query = " update key_health_reportable_parameter_master set key_param_name = '$name',key_param_id = '$id', modified_by = '".$_SESSION['user_id']."' where key_param_id = '".$id."'";
else
$query = " insert into key_health_reportable_parameter_master (key_param_id,key_param_name, modified_by) values ('$id','$name','".$_SESSION['user_id']."' );";
error_log('test'.$query);
}
else {
$query = "insert into key_health_reportable_parameter_master (key_param_id,key_param_name, modified_by)
values ('$id','$name','".$_SESSION['user_id']."' ); ";
}
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
else{
$query = "select max(key_param_id) id from key_health_reportable_parameter_master ";
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_assoc($result)) {
$id_max = $row['id'];
}
}
$query = "select * from key_health_reportable_parameter_master where key_param_id='".$id_max."'";
//echo $query;
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_assoc($result)) {
$data=$row;
}
}
}
error_log('err0'.$query);
if($data==null)
{
$data['status'] = 200;
$data['message'] = "Data not found!";
}
echo json_encode($data);
?>