Dashboard Fach hinzufügen funktioniert in swe-b1-a-dev
This commit is contained in:
committed by
Matthias Grief
parent
a04936f59e
commit
77e91ae393
35
swe-b1-a-dev/webseite/dashboard/api/create-topic.php
Normal file
35
swe-b1-a-dev/webseite/dashboard/api/create-topic.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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]);
|
||||
Reference in New Issue
Block a user