<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
    exit("unauthorized");
}

include "../../php/ovh.php";
include "../../php/globals.php";
?>

<table id="cron_jobs_list_table" class="display" style="width: 100%;">
    <thead>
        <tr>
            <th>ID</th>
            <th>Comando</th>
            <th>Frequenza</th>
            <th>Stato</th>
            <th>Linguaggio</th>
            <th>Descrizione</th>
            <th>Email</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php
        $crons_list = $ovh->get("/hosting/web/mhhtmff.cluster029.hosting.ovh.net/cron");
        for ($i = 0; $i < count($crons_list); $i++) {
            $cron_details = $ovh->get("/hosting/web/mhhtmff.cluster029.hosting.ovh.net/cron/" . $crons_list[$i]);
            if (str_starts_with($cron_details["command"], $cron_command_prefix)) {
                echo "<tr>";
                echo "<td>" . $cron_details['id'] . "</td>";
                echo "<td>" . $cron_details['command'] . "</td>";
                echo "<td>" . $cron_details['frequency'] . "</td>";
                if ($cron_details['status'] == "enabled") {
                    echo "<td>Abilitato</td>";
                } else {
                    echo "<td>Disabilitato</td>";
                }
                echo "<td>" . $cron_details['language'] . "</td>";
                echo "<td>" . $cron_details['description'] . "</td>";
                echo "<td>" . $cron_details['email'] . "</td>";
                echo "<td>
                        <a onclick='editCronJob(" . $cron_details['id'] . ")' style='cursor: pointer; margin-right:10px'><i class='fa-solid fa-magnifying-glass'></i></a>
                        <a onclick='deleteCronJob(" . $cron_details['id'] . ")' style='cursor: pointer'><i class='fa-solid fa-trash'></i></a>
                    </td>";
                echo "</tr>";
            }
        }
        ?>
    </tbody>
</table>