31 lines
948 B
PHP
31 lines
948 B
PHP
<?php
|
|
require 'db.php';
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
$type = $data['type'] ?? '';
|
|
$id = intval($data['id'] ?? 0);
|
|
|
|
if ($id <= 0 || ($type !== 'task' && $type !== 'subtask')) {
|
|
echo json_encode(['success' => false, 'error' => 'Invalid request']);
|
|
exit;
|
|
}
|
|
|
|
if ($type === 'task') {
|
|
$stmt = $pdo->prepare("UPDATE tasks SET highlighted = (highlighted + 1) % 3 WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
|
|
$stmt = $pdo->prepare("SELECT highlighted FROM tasks WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$newState = intval($stmt->fetchColumn());
|
|
} else {
|
|
$stmt = $pdo->prepare("UPDATE subtasks SET highlighted = (highlighted + 1) % 3 WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
|
|
$stmt = $pdo->prepare("SELECT highlighted FROM subtasks WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$newState = intval($stmt->fetchColumn());
|
|
}
|
|
|
|
echo json_encode(['success' => true, 'highlighted' => $newState]);
|