75 lines
3.0 KiB
PHP
75 lines
3.0 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
|
|
// Logging request parameters
|
|
$requestStr = "";
|
|
foreach ($_REQUEST as $key => $value) {
|
|
$requestStr .= $key . " : " . $value . "\n";
|
|
error_log($requestStr); // Log the entire request string at once
|
|
}
|
|
|
|
// Assuming session is started elsewhere
|
|
$modified_by = $_SESSION['user_id'];
|
|
$ohc_type_id = $_SESSION['current_ohcttype'];
|
|
|
|
// Extract POST data
|
|
$noOfRows = $_POST['count_items'];
|
|
$batch_name = mysqli_real_escape_string($conn, $_POST['batch_name']);
|
|
$count = mysqli_real_escape_string($conn, $_POST['count']);
|
|
|
|
if ($batch_name > 0) {
|
|
mysqli_begin_transaction($conn); // Start transaction
|
|
|
|
for ($i = 1; $i <= $count; $i++) {
|
|
$id = mysqli_real_escape_string($conn, $_POST["id$i"]);
|
|
$subject = mysqli_real_escape_string($conn, $_POST["subject$i"]);
|
|
$schedule_name = mysqli_real_escape_string($conn, $_POST["schedule_name$i"]);
|
|
$exam_type = mysqli_real_escape_string($conn, $_POST["exam_type$i"]); // Ensure you're getting the correct field
|
|
$exam_date = mysqli_real_escape_string($conn, $_POST["exam_date$i"]);
|
|
$max_mark = mysqli_real_escape_string($conn, $_POST["max_mark$i"]);
|
|
$passing_mark = mysqli_real_escape_string($conn, $_POST["passing_mark$i"]);
|
|
|
|
if ($id > 0) {
|
|
// Update query
|
|
$query = "UPDATE exam_schedule SET
|
|
exam_schedule_name = '$schedule_name',
|
|
batch_id = '$batch_name',
|
|
subject_id = '$subject',
|
|
exam_type = '$exam_type',
|
|
date_of_exam = '$exam_date',
|
|
max_marks = '$max_mark',
|
|
passing_marks = '$passing_mark',
|
|
modified_by = '$modified_by'
|
|
WHERE id = '$id'
|
|
AND ohc_type_id ='$ohc_type_id'";
|
|
|
|
if (!mysqli_query($conn, $query)) {
|
|
mysqli_rollback($conn); // Rollback if there's an error
|
|
echo json_encode(['error' => 'Update failed: ' . mysqli_error($conn)]);
|
|
exit;
|
|
}
|
|
} else {
|
|
// Insert query
|
|
$query = "INSERT INTO exam_schedule (exam_schedule_name, batch_id, subject_id, exam_type, date_of_exam, max_marks, passing_marks, modified_by, ohc_type_id)
|
|
VALUES ('$schedule_name', '$batch_name', '$subject', '$exam_type', '$exam_date', '$max_mark', '$passing_mark', '$modified_by', '$ohc_type_id')";
|
|
|
|
|
|
if (!mysqli_query($conn, $query)) {
|
|
mysqli_rollback($conn); // Rollback if there's an error
|
|
echo json_encode(['error' => 'Insert failed: ' . mysqli_error($conn)]);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
mysqli_commit($conn); // Commit transaction if all queries are successful
|
|
|
|
// Return data after successful insertion or update
|
|
$data = ['success' => true, 'message' => 'Records saved successfully'];
|
|
echo json_encode($data);
|
|
} else {
|
|
echo json_encode(['error' => 'Invalid batch name']);
|
|
}
|