<?php
require_once __DIR__ . "/../auth/require-auth.php";
require_once __DIR__ . "/../services/db.php";

$data = json_decode(file_get_contents("php://input"), true);
$conn = db();

$ids = $data['section_ids'];
$projectId = $data['project_id'];

$position = 1;
foreach ($ids as $id) {
    sqlsrv_query($conn, "UPDATE sections SET position = ? WHERE id = ?", [$position, $id]);
    $position++;
}

echo json_encode(["success" => true]);
