You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
14 KiB
PHP

<?php
/*
* Copyright 2019 Netsyms Technologies.
* 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");
}
$machine = new Machine($machineid);
?>
<div class="card">
<h3 class="card-header d-flex">
<div>
<i class="<?php echo $machine->getIcon(); ?>"></i> <?php echo $machine->getTypeLabel(); ?> #<?php echo htmlspecialchars($machine->getID()); ?>
</div>
<?php if ($user->hasPermission("MACHINEMANAGER_EDIT")) { ?>
<div class="ml-auto">
<a href="./app.php?page=editmachine&arg=<?php echo htmlspecialchars($machine->getID()); ?>" class="btn btn-primary btn-sm"><i class="fas fa-edit"></i> <?php $Strings->get("Edit"); ?></a>
<a href="./app.php?page=addevent&id=<?php echo htmlspecialchars($machine->getID()); ?>" class="btn btn-success btn-sm"><i class="fas fa-history"></i> <?php $Strings->get("Add Event"); ?></a>
<div class="btn-group">
<a href="./app.php?page=editcomponent&machine=<?php echo htmlspecialchars($machine->getID()); ?>" class="btn btn-success btn-sm"><i class="fas fa-memory"></i> <?php $Strings->get("Add Component"); ?></a>
<button type="button" class="btn btn-success btn-sm dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="./app.php?page=components&attachto=<?php echo htmlspecialchars($machine->getID()); ?>"><?php $Strings->get("Attach Existing"); ?></a>
</div>
</div>
<a href="./app.php?page=printlabel&id=<?php echo htmlspecialchars($machine->getID()); ?>" class="btn btn-info btn-sm"><i class="fas fa-print"></i> <?php $Strings->get("Print Labels"); ?></a>
<a href="./app.php?page=machines" class="btn btn-danger btn-sm"><i class="fas fa-arrow-left"></i> <?php $Strings->get("Back"); ?></a>
</div>
<?php } ?>
</h3>
<div class="card-body">
<div class="row">
<div class="col-sm-6 mb-3">
<h6>Device Info:</h6>
<div class="list-group">
<?php
if (!empty($machine->getClientID())) {
$client = Clients::getClient($machine->getClientID());
?>
<div class="list-group-item">
<b><?php $Strings->get("Client"); ?></b>: <?php echo htmlspecialchars($client->getName()); ?>
<br />
<div class="ml-3">
<?php if (!empty($client->getPhone())) { ?>
<b>Phone:</b> <?php echo $client->getPhone(); ?>
<br />
<?php } ?>
<?php if (!empty($client->getBillingAddress())) { ?>
<b>Billing address:</b><br><?php echo str_replace("\n", "\n<br>", htmlspecialchars($client->getBillingAddress())); ?>
<br />
<?php } ?>
<?php if (!empty($client->getMailingAddress())) { ?>
<b>Mailing address:</b><br><?php echo str_replace("\n", "\n<br>", htmlspecialchars($client->getMailingAddress())); ?>
<?php } ?>
<br />
</div>
</div>
<?php
}
?>
<?php if (!empty($machine->getOS())) { ?>
<div class="list-group-item">
<b><?php $Strings->get("OS/Software"); ?></b>: <?php echo htmlspecialchars($machine->getOS()); ?>
</div>
<?php } ?>
<?php if (!empty($machine->getSerial())) { ?>
<div class="list-group-item">
<b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($machine->getSerial()); ?>
</div>
<?php } ?>
<?php if (!empty($machine->getManufacturer())) { ?>
<div class="list-group-item">
<b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($machine->getManufacturer()); ?>
</div>
<?php } ?>
<?php if (!empty($machine->getModel())) { ?>
<div class="list-group-item">
<b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($machine->getModel()); ?>
</div>
<?php } ?>
<?php if (!empty($machine->getCondition())) { ?>
<div class="list-group-item">
<b><?php $Strings->get("Condition"); ?></b>: <?php
$val = $machine->getCondition();
$filled = floor($val);
$empty = 10;
while ($filled > 0) {
$filled--;
$empty--;
echo "<i class=\"fas fa-star\"></i> ";
}
if ($val - floor($val) > 0.75) {
$empty--;
echo "<i class=\"fas fa-star\"></i> ";
} else if ($val - floor($val) > 0.25) {
$empty--;
echo "<i class=\"fas fa-star-half-alt\"></i> ";
}
while ($empty > 0) {
$empty--;
echo "<i class=\"far fa-star\"></i> ";
}
echo " ($val/10)";
?>
</div>
<?php } ?>
<?php if (!empty($machine->getPrice())) { ?>
<div class="list-group-item">
<b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($machine->getPrice(), 2); ?>
</div>
<?php } ?>
<?php
if (!empty($machine->getPrivateNotes())) {
?>
<div class="list-group-item">
<b><?php $Strings->get("Private Notes"); ?></b>:<br><div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($machine->getPrivateNotes())); ?></div>
</div>
<?php
}
if (!empty($machine->getPublicNotes())) {
?>
<div class="list-group-item">
<b><?php $Strings->get("Public Notes"); ?></b>:<br><div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($machine->getPublicNotes())); ?></div>
</div>
<?php
}
?>
</div>
<?php
$history = $machine->getEvents();
if (count($history) > 0) {
?>
<div class="mt-4">
<h6>Events:</h6>
<div class="list-group">
<?php
foreach ($history as $h) {
echo "<div class=\"list-group-item\">\n";
echo "<b>" . $h->getName() . "</b> on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "<br />\n";
if (!empty($h->getTechUID())) {
echo "<b>Technician:</b> " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "<br />\n";
}
if (!empty($h->getPublicNotes())) {
echo "<div><b>Public Notes:</b><br /><div class=\"ml-3\">" . str_replace("\n", "\n<br>", htmlspecialchars($h->getPublicNotes())) . "</div></div>";
}
if (!empty($h->getPrivateNotes())) {
echo "<div><b>Private Notes:</b><br /><div class=\"ml-3\">" . str_replace("\n", "\n<br>", htmlspecialchars($h->getPrivateNotes())) . "</div></div>";
}
echo "\n</div>\n";
}
?>
</div>
</div>
<?php
}
?>
</div>
<?php
$components = $machine->getComponents();
if (count($components) > 0) {
?>
<div class="col-sm-6 mb-3">
<h6>Components:</h6>
<div class="list-group">
<?php
foreach ($components as $c) {
?>
<div class="list-group-item">
<div class="float-right">
<a class="btn btn-danger btn-sm" href="./action.php?action=unlinkcomponent&source=viewmachine&id=<?php echo $c->getID(); ?>&machine=<?php echo $machine->getID(); ?>"><i class="fas fa-unlink"></i> <?php $Strings->get("Detach"); ?></a>
<a class="btn btn-primary btn-sm" href="./app.php?page=editcomponent&id=<?php echo $c->getID(); ?>"><i class="fas fa-edit"></i> <?php $Strings->get("Edit"); ?></a>
</div>
<b><?php echo $c->getTypeName(); ?></b><br />
<?php
if (!empty($c->getModel())) {
?>
<b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($c->getModel()); ?><br />
<?php
}
if (!empty($c->getCapacity())) {
?>
<b><?php $Strings->get("Capacity"); ?></b>: <?php echo htmlspecialchars($c->getCapacity()); ?><br />
<?php
}
if (!empty($c->getSerial())) {
?>
<b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($c->getSerial()); ?><br />
<?php
}
if (!empty($c->getManufacturer())) {
?>
<b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($c->getManufacturer()); ?><br />
<?php
}
if (!empty($c->getTestedDate())) {
?>
<b><?php $Strings->get("Tested On"); ?></b>: <?php echo date($SETTINGS["datetime_format"], strtotime($c->getTestedDate())); ?><br />
<?php
}
if (!empty($c->getPrice())) {
?>
<b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($c->getPrice(), 2); ?>
<?php
}
if (!empty($c->getPublicNotes())) {
?>
<div>
<b>Public Notes:</b><br />
<div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($c->getPublicNotes())); ?></div>
</div>
<?php
}
if (!empty($c->getPrivateNotes())) {
?>
<div>
<b>Private Notes:</b><br />
<div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($c->getPrivateNotes())); ?></div>
</div>
<?php } ?>
</div>
<?php
}
?>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>