68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
require_once dirname(__DIR__) . '/db_conn.php';
|
|
|
|
if (session_status() !== PHP_SESSION_ACTIVE) {
|
|
session_start();
|
|
}
|
|
|
|
$memberId = (string)($_SESSION['member_id'] ?? $_SESSION['user_id'] ?? '');
|
|
$sysCompCode = (string)($_SESSION['sys_comp_code'] ?? $_SESSION['company'] ?? '');
|
|
|
|
if ($memberId === '') {
|
|
http_response_code(401);
|
|
echo json_encode(['success' => false, 'message' => 'not_logged_in'], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
$payload = [];
|
|
$rawBody = file_get_contents('php://input');
|
|
if (is_string($rawBody) && $rawBody !== '') {
|
|
$decoded = json_decode($rawBody, true);
|
|
if (is_array($decoded)) {
|
|
$payload = $decoded;
|
|
}
|
|
}
|
|
|
|
$contentId = trim((string)($payload['content_id'] ?? ''));
|
|
if ($contentId === '') {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => false, 'message' => 'content_id_required'], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db_conn();
|
|
|
|
if ($sysCompCode === '') {
|
|
$stmtUser = $pdo->prepare('SELECT sys_comp_code FROM edu_users WHERE member_id = ? ORDER BY sys_comp_code LIMIT 1');
|
|
$stmtUser->execute([$memberId]);
|
|
$sysCompCode = (string)($stmtUser->fetchColumn() ?: '');
|
|
}
|
|
|
|
$sql = 'UPDATE edu_learning_histories SET comment = NULL WHERE content_id = ? AND member_id = ?';
|
|
$params = [$contentId, $memberId];
|
|
|
|
if ($sysCompCode !== '') {
|
|
$sql .= ' AND sys_comp_code = ?';
|
|
$params[] = $sysCompCode;
|
|
}
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
|
|
if ($stmt->rowCount() < 1) {
|
|
echo json_encode(['success' => false, 'message' => '삭제할 소감이 없습니다.'], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode(['success' => true], JSON_UNESCAPED_UNICODE);
|
|
} catch (Throwable $e) {
|
|
error_log('[clear_comment] ' . $e->getMessage());
|
|
http_response_code(500);
|
|
echo json_encode(['success' => false, 'message' => 'server_error'], JSON_UNESCAPED_UNICODE);
|
|
}
|