<?php
header('Content-Type: application/json');
include('../class/include.php');
if (!Account::isAuthentified() || !CSRF::isAjaxRequest())
{
    die("Bad request");
}



$all_payload_predata = Payload::GetAllOwnedPayload();
$list = [];

foreach ($all_payload_predata as $data)
{

    $button_delete = '<button style="padding: 0; border: none; background: none; color: gray;" onclick="deletePayload('.$data['id'].')" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg></button>';

    $button_view = '<button style="padding: 0; border: none; background: none; color: gray;" onclick="viewPayload('.$data['id'].')"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file-text"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg></button>';

    array_push($list, ["DT_RowId" => "payload-".$data['id'], $data['payload_name'], $button_delete."&nbsp;".$button_view]);
}

echo json_encode(['data' => $list]);
?>
