<?php
require_once "../../includes/db.php";
require_once "../../includes/functions.php";
require_once "../../includes/auth.php";
ensure_manager();

$data = json_decode(file_get_contents("php://input"), true);
$restaurant_id = $_SESSION['restaurant_id'];

$order = 1;
foreach($data as $branch_id){
    db()->prepare("UPDATE branches SET ordering=? WHERE id=? AND restaurant_id=?")
       ->execute([$order, $branch_id, $restaurant_id]);
    $order++;
}
echo "ok";
