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

60 lines
2.0 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
include('log_entry.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,'Communication List','SAVE','save_communication.php');
$noOfRows = $_POST['count_items'];
error_log("rows: " . $noOfRows);
begin();
$modified_by = $_SESSION['user_id'];
// $dis_agncy = $_POST['dis_agncy'];
//echo "hello".$noOfRows;
$sql_ifexists = " select * from communication_details where modified_by = '" . $modified_by . "' and date_format(comm_date,'%d-%m-%Y') ='" . ${"comm_date"} . "'";
//echo $sql_ifexists;
$result_ifexists = mysqli_query($conn,$sql_ifexists);
$exists = @mysqli_num_rows($result_ifexists);
error_log("existing rows:" . $exists);
if ($exists > 0) {
$del_qry = "delete from communication_details where modified_by = '" . $modified_by . "' and date_format(comm_date,'%d-%m-%Y') ='" . ${"comm_date"} . "'";
error_log("com del query".$del_qry);
mysqli_query($conn,$del_qry);
}
$communication_id = $_POST['communication_id'];
for ($i = 0; $i < $noOfRows; $i++) {
$communication_id_str = "communication_id" . $i;
$communication_id = $_REQUEST[$communication_id_str];
// echo $communication_id;
error_log("communication_id" . $communication_id);
//echo $procurement_refno;
$query_initial = "insert into ";
$endquery = "";
$query = $query_initial . " communication_details set communication_id ='" . ${"communication_id$i"} . "',shift_details_id = '" . ${"shift_details_id$i"} . "',details ='" . ${"details$i"} . "',remarks ='" . ${"remarks$i"} . "',comm_date = now() ,modified_by = '" . $_SESSION['user_id'] . "' " . $endquery;
error_log("save comm query:".$query);
if (!$result = @mysqli_query($conn,$query)) {
rollback();
exit(error_log(mysqli_error($conn)));
}
}
commit();