diff --git a/admin/ajax_delete_image.php b/admin/ajax_delete_image.php new file mode 100644 index 0000000..25690ce --- /dev/null +++ b/admin/ajax_delete_image.php @@ -0,0 +1,37 @@ + false, 'error' => '无权限']); + exit; +} + +$input = json_decode(file_get_contents('php://input'), true); + +if ($input && isset($input['image_id'])) { + try { + // 先获取文件名以便删除物理文件 + $stmt = $pdo->prepare("SELECT filename FROM images WHERE id = ?"); + $stmt->execute([$input['image_id']]); + $image = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($image) { + // 删除数据库记录(会级联删除关联的标签) + $stmt = $pdo->prepare("DELETE FROM images WHERE id = ?"); + $stmt->execute([$input['image_id']]); + + // 删除物理文件 + $file_path = '../uploads/' . $image['filename']; + if (file_exists($file_path)) { + unlink($file_path); + } + } + + echo json_encode(['success' => true]); + } catch(PDOException $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } +} else { + echo json_encode(['success' => false, 'error' => '无效请求']); +} +?> \ No newline at end of file diff --git a/admin/ajax_delete_user.php b/admin/ajax_delete_user.php new file mode 100644 index 0000000..f2da9aa --- /dev/null +++ b/admin/ajax_delete_user.php @@ -0,0 +1,24 @@ + false, 'error' => '无权限']); + exit; +} + +$input = json_decode(file_get_contents('php://input'), true); + +if ($input && isset($input['user_id'])) { + try { + // 注意:这里会级联删除用户的所有图片 + $stmt = $pdo->prepare("DELETE FROM users WHERE id = ? AND username != 'admin'"); + $stmt->execute([$input['user_id']]); + + echo json_encode(['success' => true]); + } catch(PDOException $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } +} else { + echo json_encode(['success' => false, 'error' => '无效请求']); +} +?> \ No newline at end of file diff --git a/admin/ajax_toggle_image.php b/admin/ajax_toggle_image.php new file mode 100644 index 0000000..0d8509a --- /dev/null +++ b/admin/ajax_toggle_image.php @@ -0,0 +1,23 @@ + false, 'error' => '无权限']); + exit; +} + +$input = json_decode(file_get_contents('php://input'), true); + +if ($input && isset($input['image_id']) && isset($input['is_public'])) { + try { + $stmt = $pdo->prepare("UPDATE images SET is_public = ? WHERE id = ?"); + $stmt->execute([$input['is_public'], $input['image_id']]); + + echo json_encode(['success' => true]); + } catch(PDOException $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } +} else { + echo json_encode(['success' => false, 'error' => '无效请求']); +} +?> \ No newline at end of file diff --git a/admin/ajax_update_user.php b/admin/ajax_update_user.php new file mode 100644 index 0000000..29ea0bd --- /dev/null +++ b/admin/ajax_update_user.php @@ -0,0 +1,23 @@ + false, 'error' => '无权限']); + exit; +} + +$input = json_decode(file_get_contents('php://input'), true); + +if ($input && isset($input['user_id']) && isset($input['role'])) { + try { + $stmt = $pdo->prepare("UPDATE users SET role = ? WHERE id = ? AND username != 'admin'"); + $stmt->execute([$input['role'], $input['user_id']]); + + echo json_encode(['success' => true]); + } catch(PDOException $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } +} else { + echo json_encode(['success' => false, 'error' => '无效请求']); +} +?> \ No newline at end of file diff --git a/admin/feedbacks.php b/admin/feedbacks.php new file mode 100644 index 0000000..215445d --- /dev/null +++ b/admin/feedbacks.php @@ -0,0 +1,136 @@ +query(" + SELECT f.*, u.username + FROM feedbacks f + LEFT JOIN users u ON f.user_id = u.id + ORDER BY f.created_at DESC + LIMIT 50 + "); + $feedbacks = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch(PDOException $e) { + $feedbacks = []; +} +?> +
+

用户反馈

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID用户类型主题内容状态提交时间操作
+ + + + 匿名用户 + + + '错误报告', + 'feature' => '功能建议', + 'suggestion' => '改进建议', + 'other' => '其他' + ]; + echo $typeLabels[$feedback['type']] ?? $feedback['type']; + ?> + +
+ +
+
+ + +
+ + +
+
+
+
+ + \ No newline at end of file