+37
-16
@@ -15,7 +15,7 @@ require_once __DIR__ . '/../config/database.php';
|
||||
$db = getDbConnection();
|
||||
|
||||
// Ensure notes column exists
|
||||
try { $db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT '' AFTER group_name"); } catch (Exception $e) {}
|
||||
try { $db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT ''"); } catch (Exception $e) {}
|
||||
|
||||
// Auth check (except for session check)
|
||||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
@@ -370,20 +370,37 @@ function handleNodes($method, $id, $db) {
|
||||
break;
|
||||
case 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y, notes)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['label'],
|
||||
$data['ip_address'] ?? '',
|
||||
$data['node_type'] ?? 'host',
|
||||
$data['status'] ?? 'unknown',
|
||||
$data['group_name'] ?? 'default',
|
||||
$data['pos_x'] ?? 0,
|
||||
$data['pos_y'] ?? 0,
|
||||
$data['notes'] ?? ''
|
||||
]);
|
||||
try {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y, notes)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['label'],
|
||||
$data['ip_address'] ?? '',
|
||||
$data['node_type'] ?? 'host',
|
||||
$data['status'] ?? 'unknown',
|
||||
$data['group_name'] ?? 'default',
|
||||
$data['pos_x'] ?? 0,
|
||||
$data['pos_y'] ?? 0,
|
||||
$data['notes'] ?? ''
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
// Fallback without notes column
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['label'],
|
||||
$data['ip_address'] ?? '',
|
||||
$data['node_type'] ?? 'host',
|
||||
$data['status'] ?? 'unknown',
|
||||
$data['group_name'] ?? 'default',
|
||||
$data['pos_x'] ?? 0,
|
||||
$data['pos_y'] ?? 0
|
||||
]);
|
||||
}
|
||||
echo json_encode(['id' => $db->lastInsertId()]);
|
||||
break;
|
||||
case 'PUT':
|
||||
@@ -391,7 +408,7 @@ function handleNodes($method, $id, $db) {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$fields = [];
|
||||
$params = [];
|
||||
foreach (['label','ip_address','node_type','status','group_name','pos_x','pos_y','notes'] as $f) {
|
||||
foreach (['label','ip_address','node_type','status','group_name','pos_x','pos_y'] as $f) {
|
||||
if (isset($data[$f])) {
|
||||
$fields[] = "$f = ?";
|
||||
$params[] = $data[$f];
|
||||
@@ -402,6 +419,10 @@ function handleNodes($method, $id, $db) {
|
||||
$stmt = $db->prepare("UPDATE network_nodes SET " . implode(', ', $fields) . " WHERE id = ?");
|
||||
$stmt->execute($params);
|
||||
}
|
||||
// Update notes separately (column may not exist)
|
||||
if (isset($data['notes'])) {
|
||||
try { $db->prepare("UPDATE network_nodes SET notes = ? WHERE id = ?")->execute([$data['notes'], $id]); } catch (Exception $e) {}
|
||||
}
|
||||
echo json_encode(['updated' => true]);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -39,7 +39,7 @@ function migrate($db) {
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)");
|
||||
try {
|
||||
$db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT '' AFTER group_name");
|
||||
$db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT ''");
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user