Swal.fire("错误", "无效的App ID", "error").then(() => { window.location.href = "index.php"; });'; exit; } $appId = $_GET['id']; // 获取App信息 $app = null; $getAppSql = "SELECT * FROM apps WHERE id = ?"; $stmt = $conn->prepare($getAppSql); $stmt->bind_param("i", $appId); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { echo ''; exit; } $app = $result->fetch_assoc(); $platforms = json_decode($app['platforms'], true); $success = ''; $error = ''; // 处理编辑App请求 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_app'])) { $name = $_POST['name']; $description = $_POST['description']; $ageRating = $_POST['age_rating']; $newPlatforms = json_encode($_POST['platforms'] ?? []); // 处理表单提交 if ($_SERVER['REQUEST_METHOD'] === 'POST') { // 验证必填字段 $required = ['name', 'description', 'age_rating', 'platforms']; $errors = []; foreach ($required as $field) { if (empty($_POST[$field])) { $errors[] = ucfirst($field) . ' 不能为空'; } } // 年龄分级验证 if (($_POST['age_rating'] === '12+' || $_POST['age_rating'] === '17+') && empty($_POST['age_rating_description'])) { $errors[] = '年龄分级为12+或以上时,年龄分级说明不能为空'; } // 处理应用图标上传(如果有新上传) if (!empty($_FILES['images']['name'][0])) { $uploadDir = '../images/'; foreach ($_FILES['images']['tmp_name'] as $key => $tmpName) { $fileName = basename($_FILES['images']['name'][$key]); $targetPath = $uploadDir . $fileName; if (move_uploaded_file($tmpName, $targetPath)) { $insertImageSql = "INSERT INTO app_images (app_id, image_path) VALUES (?, ?)"; $imgStmt = $conn->prepare($insertImageSql); $imgStmt->bind_param("is", $appId, $targetPath); $imgStmt->execute(); } } } // 处理新上传的App文件 if (!empty($_FILES['app_file']['name'])) { $uploadDir = '../files/'; $fileName = basename($_FILES['app_file']['name']); $targetPath = $uploadDir . $fileName; if (move_uploaded_file($_FILES['app_file']['tmp_name'], $targetPath)) { $version = $_POST['version']; $changelog = $_POST['changelog']; $insertVersionSql = "INSERT INTO app_versions (app_id, version, changelog, file_path) VALUES (?, ?, ?, ?)"; $verStmt = $conn->prepare($insertVersionSql); $verStmt->bind_param("isss", $appId, $version, $changelog, $targetPath); $verStmt->execute(); } } // 更新标签关联 $stmt = $conn->prepare("DELETE FROM app_tags WHERE app_id = ?"); $stmt->bind_param("i", $appId); $stmt->execute(); $stmt->close(); if (!empty($_POST['tags'])) { $stmt = $conn->prepare("INSERT INTO app_tags (app_id, tag_id) VALUES (?, ?)"); foreach ($_POST['tags'] as $tagId) { $stmt->bind_param("ii", $appId, $tagId); $stmt->execute(); } $stmt->close(); } $updateAppSql = "UPDATE apps SET name = ?, description = ?, age_rating = ?, platforms = ? WHERE id = ?"; $updateStmt = $conn->prepare($updateAppSql); $updateStmt->bind_param("ssssi", $name, $description, $ageRating, $newPlatforms, $appId); if ($updateStmt->execute() === TRUE) { echo ''; exit; } else { echo ''; } $updateStmt->close(); } } ?>