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