<?php
require_once('includes/functions.php');

$users = readJson('users');
$updated = 0;

foreach ($users as &$user) {
    if (!isset($user['cycle'])) {
        // Assign cycle based on ID for existing users
        $user['cycle'] = ($user['id'] % 2 == 0) ? 'Even' : 'Odd';
        $updated++;
    }
}

if ($updated > 0) {
    writeJson('users', $users);
    echo "✅ Added 'cycle' field to $updated users.<br>";
} else {
    echo "✅ All users already have a cycle field.<br>";
}
echo "<a href='admin/dashboard.php'>Go to Dashboard</a>";
?>