<?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_VIEW")) {
    header("Location: ./app.php?msg=no_permission");
    die();
}

if (!empty($_GET["id"])) {
    $machineid = $_GET["id"];
} else if (!empty($_GET["arg"])) {
    $machineid = $_GET["arg"];
}
if (!Machine::exists($machineid)) {
    header("Location: ./app.php?msg=no_such_machine");
    exit();
}

$labeltype = "machineid";
if (!empty($VARS["labeltype"])) {
    switch ($VARS["labeltype"]) {
        case "doortag":
            $labeltype = "doortag";
            break;
        case "machineid":
        default:
            $labeltype = "machineid";
    }
}
$machine = new Machine($machineid);

$pdfurl = "./print/print.php?labeltype=$labeltype&id=$machineid";
?>

<div class="d-flex">
<ul class="nav nav-tabs">
    <li class="nav-item">
        <a class="nav-link<?php echo ($labeltype == "machineid" ? " active" : "") ?>" href="./app.php?page=printlabel&id=<?php echo $machine->getID(); ?>">Machine ID Label</a>
    </li>
    <li class="nav-item">
        <a class="nav-link<?php echo ($labeltype == "doortag" ? " active" : "") ?>" href="./app.php?page=printlabel&id=<?php echo $machine->getID(); ?>&labeltype=doortag">Door Tag</a>
    </li>
</ul>
    <div class="ml-auto">
        <a href="./app.php?page=viewmachine&id=<?php echo $machine->getID(); ?>" class="btn btn-info btn-sm"><i class="fas fa-eye"></i> <?php $Strings->get("Go to machine"); ?></a>
    </div>
</div>

<div>
    <iframe src="<?php echo $pdfurl; ?>" width="100%" height="500px"></iframe>
</div>