36 lines
873 B
PHP
36 lines
873 B
PHP
<?php
|
|
require_once("../../classes/TopicData.php");
|
|
require_once("../../classes/Config.php");
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
// Validate and sanitize input
|
|
$displayName = htmlspecialchars($_POST['displayName']);
|
|
$subjectId = $_POST['subjectId'];
|
|
$description = $_POST['description'];
|
|
$icon = $_POST['icon'];
|
|
$article = $_POST['article'];
|
|
|
|
// Generate ID from displayName
|
|
$id = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $displayName));
|
|
|
|
// Create topic
|
|
$topic = TopicData::createNew(
|
|
$id,
|
|
$subjectId,
|
|
$displayName,
|
|
$icon,
|
|
$description,
|
|
[], // empty related topics array
|
|
$article
|
|
);
|
|
|
|
if (!$topic || !$topic->save()) {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => false, 'message' => 'Failed to create topic']);
|
|
exit();
|
|
}
|
|
|
|
echo json_encode(['success' => true]);
|