94 lines
4.7 KiB
PHP
94 lines
4.7 KiB
PHP
|
<?php
|
||
|
include('includes/config/config.php');
|
||
|
include('includes/functions.php');
|
||
|
$response_array = array();
|
||
|
$response_mssages = "";
|
||
|
|
||
|
$usage_id = $_REQUEST['usage_id'];
|
||
|
for ($i = 0; $i < count($usage_id); $i++) {
|
||
|
if ($usage_id[$i] != null || $usage_id[$i] != '') {
|
||
|
$data_q = "SELECT * FROM temporary_csr_program WHERE temp_csr_id ='$usage_id[$i]'";
|
||
|
|
||
|
error_log('$data_q' . $data_q);
|
||
|
$result_data_q = mysqli_query($conn, $data_q);
|
||
|
while ($usage_fetch = mysqli_fetch_array($result_data_q)) {
|
||
|
|
||
|
$program_name = $usage_fetch['program_name'];
|
||
|
$program_details = $usage_fetch['program_details'];
|
||
|
$location = $usage_fetch['location'];
|
||
|
$start = $usage_fetch['start_date_time'];
|
||
|
$end = $usage_fetch['end_date_time'];
|
||
|
$start_date_time = date('Y-m-d H:i:s', strtotime("$start"));
|
||
|
error_log($start_date_time . " " . $start);
|
||
|
$end_date_time = date('Y-m-d H:i:s', strtotime("$end"));
|
||
|
error_log($end_date_time . " " . $end);
|
||
|
$coordinator_name = $usage_fetch['coordinator_name'];
|
||
|
$sub_coordinator_name = $usage_fetch['sub_coordinator_name'];
|
||
|
$total_participate = $usage_fetch['total_participate'];
|
||
|
$remarks = $usage_fetch['remarks'];
|
||
|
|
||
|
if (!empty($program_name) && !empty($program_details) && !empty($location) && !empty($start_date_time) && !empty($end_date_time)) {
|
||
|
error_log("IF");
|
||
|
|
||
|
$usage_id_sql = "SELECT csr_id FROM csr_program WHERE date(start_date_time)= 'DATE_FROMAT(" . $start_date_time . ",%Y-%m-%d)', date(end_date_time) = 'DATE_FORMAT(" . $end_date_time . ",%Y-%m-%d)' AND program_name = '" . $program_name . "' AND location = '" . $location . "'";
|
||
|
error_log("UPDATE OR NOT " . $usage_id_sql);
|
||
|
$result_id_sql = mysqli_query($conn, $usage_id_sql);
|
||
|
$row_id = mysqli_fetch_array($result_id_sql);
|
||
|
$csr_id = $row_id['csr_id'];
|
||
|
|
||
|
|
||
|
|
||
|
error_log("interm usage::" . $csr_id);
|
||
|
|
||
|
|
||
|
$initquery = "";
|
||
|
$endquery = "";
|
||
|
|
||
|
if ($csr_id != "" && $csr_id != null) {
|
||
|
$initquery = "update csr_program set ";
|
||
|
$endquery = " where csr_id = '" . $csr_id . "'";
|
||
|
$update_counter++;
|
||
|
} else {
|
||
|
$initquery = "INSERT INTO csr_program set ";
|
||
|
$endquery = "";
|
||
|
$insert_counter++;
|
||
|
}
|
||
|
$query_csr = $initquery . " start_date_time = '" . $start_date_time . "', end_date_time = '" . $end_date_time . "',total_participate = '$total_participate',program_name = '$program_name', program_details='$program_details', location='$location', coordinator_name='$coordinator_name', sub_coordinator_name='$sub_coordinator_name', remarks ='$remarks' $endquery ";
|
||
|
|
||
|
error_log("PERENT " . $query_csr);
|
||
|
|
||
|
|
||
|
error_log("PROCUREMENT QUERY::" . $query_csr);
|
||
|
$result1 = mysqli_query($conn, $query_csr);
|
||
|
|
||
|
if (!$csr_id) {
|
||
|
$csr_id = mysqli_insert_id($conn);
|
||
|
}
|
||
|
$participate_type = getFieldFromTable('participate_type', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$participate_name = getFieldFromTable('participate_name', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$address = getFieldFromTable('address', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$contact = getFieldFromTable('contact', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$vitals_checked = getFieldFromTable('vitals_check', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$item_id = getFieldFromTable('item_id', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$total_cost = getFieldFromTable('total_cost', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$remarks = getFieldFromTable('remarks', 'temporary_participate_csr_program', 'temp_csr_id', $usage_fetch['temp_csr_id']);
|
||
|
$initqueryp = "";
|
||
|
$endqueryp = "";
|
||
|
$query_csr = "";
|
||
|
$query_csr = "INSERT into participate_csr_program set participate_type = '$participate_type',csr_id=$csr_id,participate_name='$participate_name',`address`='$address',`contact`='" . $contact . "',vitals_check='" . $vitals_checked . "',item_id='" . $item_given . "',total_cost='" . $total_cost . "', remarks='" . $remarks . "'";
|
||
|
error_log("CHILD " . $query_csr);
|
||
|
$result1 = mysqli_query($conn, $query_csr);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$sql = "TRUNCATE TABLE temporary_csr_program";
|
||
|
error_log($sql . "delete");
|
||
|
$query = mysqli_query($conn, $sql);
|
||
|
$sql120 = "TRUNCATE TABLE temporary_participate_csr_program";
|
||
|
error_log($sql120 . "delete");
|
||
|
$query120 = mysqli_query($conn, $sql120);
|
||
|
commit();
|
||
|
|
||
|
echo json_encode($type);
|