Dashboard Fach hinzufügen funktioniert in swe-b1-a-dev
This commit is contained in:
committed by
Matthias Grief
parent
a04936f59e
commit
77e91ae393
42
swe-b1-a-dev/webseite/dashboard/api/create-subject.php
Normal file
42
swe-b1-a-dev/webseite/dashboard/api/create-subject.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
require_once("../../classes/SubjectData.php");
|
||||
require_once("../../classes/Config.php");
|
||||
|
||||
// Debug logging
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Log all POST data
|
||||
error_log("POST data: " . print_r($_POST, true));
|
||||
|
||||
// Validate and sanitize input
|
||||
$displayName = htmlspecialchars($_POST['displayName']);
|
||||
$description = $_POST['description'];
|
||||
$color = preg_replace('/[^#A-Fa-f0-9]/', '', $_POST['color']);
|
||||
$icon = $_POST['icon']; // Get raw icon value
|
||||
|
||||
// Log processed values
|
||||
error_log("Processing subject creation:");
|
||||
error_log("Display Name: " . $displayName);
|
||||
error_log("Color: " . $color);
|
||||
// error_log("Icon: " . $icon);
|
||||
|
||||
// Generate ID from displayName
|
||||
$id = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $displayName));
|
||||
|
||||
// Set default icon if none is provided
|
||||
if (empty($icon)) {
|
||||
$icon = 'fa-book';
|
||||
}
|
||||
|
||||
// Create and save subject
|
||||
$subject = SubjectData::createNew($id, $displayName, $description, $color, $icon, []);
|
||||
|
||||
if (!$subject || !$subject->save()) {
|
||||
error_log("Failed to create/save subject");
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to create or save subject']);
|
||||
exit();
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
Reference in New Issue
Block a user