26 lines
657 B
PHP
26 lines
657 B
PHP
<?php
|
|
require 'db.php';
|
|
require 'auth.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
require_login();
|
|
$user_id = current_user_id();
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
if (!$data || !is_array($data)) {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid input']);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("UPDATE tasks SET task_order = ? WHERE id = ? AND user_id = ?");
|
|
|
|
foreach ($data as $item) {
|
|
$id = $item['id'] ?? null;
|
|
$order = $item['order'] ?? null;
|
|
if (!is_numeric($id) || !is_numeric($order)) continue;
|
|
$stmt->execute([(int)$order, (int)$id, $user_id]);
|
|
}
|
|
|
|
echo json_encode(['success' => true]);
|