68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
|
<?php
|
||
|
include_once 'db_connect.php';
|
||
|
include_once 'check_allowed_ip.php';
|
||
|
include 'options_helper.php';
|
||
|
|
||
|
$clientIP = $_SERVER['REMOTE_ADDR'];
|
||
|
|
||
|
if (!isAllowedIP($clientIP, $allowedSubnets)) {
|
||
|
http_response_code(403);
|
||
|
header('Content-Type: application/json');
|
||
|
echo json_encode([
|
||
|
'status' => 'error',
|
||
|
'message' => 'Access denied: Your IP is not authorized to modify records.'
|
||
|
]);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$id = $_POST['id'];
|
||
|
|
||
|
// Fetch the anime name and year for logging
|
||
|
$stmt = $conn->prepare("SELECT name, year FROM anime_list WHERE id = :id");
|
||
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||
|
$stmt->execute();
|
||
|
$record = $stmt->fetch(PDO::FETCH_ASSOC);
|
||
|
|
||
|
if (!$record) {
|
||
|
http_response_code(404);
|
||
|
echo json_encode([
|
||
|
'status' => 'error',
|
||
|
'message' => 'Record not found.'
|
||
|
]);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$anime_name = $record['name'];
|
||
|
$anime_year = $record['year'];
|
||
|
|
||
|
// Update the record to set is_completed to 1
|
||
|
|
||
|
$auto_add_complelete_date = getOptionValue($conn, 'auto_add_completed_date', '0');
|
||
|
if ($auto_add_complelete_date == 1) {
|
||
|
$current_date = date('Y-m-d');
|
||
|
$stmt = $conn->prepare("UPDATE anime_list SET is_completed = 1, date_completed = :current_date WHERE id = :id");
|
||
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||
|
$stmt->bindParam(':current_date', $current_date);
|
||
|
} else {
|
||
|
$stmt = $conn->prepare("UPDATE anime_list SET is_completed = 1 WHERE id = :id");
|
||
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||
|
}
|
||
|
$stmt->execute();
|
||
|
|
||
|
// Log the action
|
||
|
$action_time = new DateTime('now', new DateTimeZone('GMT+5'));
|
||
|
$action_time_formatted = $action_time->format('Y-m-d H:i:s');
|
||
|
$ip_address = $_SERVER['REMOTE_ADDR'];
|
||
|
$action_type = 'set_complete';
|
||
|
|
||
|
$log_stmt = $conn->prepare("INSERT INTO action_logs (action_time, ip_address, anime_name, action_type, year) VALUES (:action_time, :ip_address, :anime_name, :action_type, :anime_year)");
|
||
|
$log_stmt->bindParam(':action_time', $action_time_formatted);
|
||
|
$log_stmt->bindParam(':ip_address', $ip_address);
|
||
|
$log_stmt->bindParam(':anime_name', $anime_name);
|
||
|
$log_stmt->bindParam(':anime_year', $anime_year);
|
||
|
$log_stmt->bindParam(':action_type', $action_type);
|
||
|
$log_stmt->execute();
|
||
|
|
||
|
echo json_encode(['status' => 'success']);
|
||
|
?>
|