<?php

/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

redirectIfNotLoggedIn();
$user = new User($_SESSION['uid']);
if (!$user->hasPermission("MACHINEMANAGER_EDIT")) {
    header("Location: ./app.php?msg=no_permission");
    die();
}

$editing = false;

if (empty($_GET['id']) || !Machine::exists($_GET['id'])) {
    header("Location: ./app.php?msg=invalid_parameters");
}
$machine = new Machine($_GET['id']);

$form = new FormBuilder("Add Event", "fas fa-history", "action.php", "POST");

$form->setID("editmachine");

$form->addHiddenInput("action", "addevent");
$form->addHiddenInput("source", "viewmachine");
$form->addHiddenInput("machine", htmlspecialchars($_GET['id']));

$eventselect = ["" => ""] + Event::getTypesFormattedForForm();

$form->addInput("event", "", "select", true, null, $eventselect, "Event", "fas fa-list");
$form->addInput("date", date("Y-m-d"), "date", true, null, null, "Date", "fas fa-calendar");
$form->addInput("time", date("H:i"), "time", true, null, null, "Time", "fas fa-clock");
$form->addInput("privatenotes", "", "textarea", false, null, null, "Private Notes", "fas fa-comment-dots", 6, 0, 10000);
$form->addInput("publicnotes", "", "textarea", false, null, null, "Public Notes", "far fa-comment-dots", 6, 0, 10000);

$form->addButton("Save", "fas fa-save", null, "submit", "savebtn");

$form->generate();
