Add label printing with gLabels integration

master
Skylar Ittner 4 years ago
parent 5bc4b63d8f
commit dbd797af99

@ -5,5 +5,8 @@
"View Machines": "View Machines",
"Add Event": "Add Event",
"Add Component": "Add Component",
"Add Client": "Add Client"
"Add Client": "Add Client",
"Print": "Print",
"Print Labels": "Print Labels",
"Go to machine": "Go to machine"
}

@ -1,5 +1,6 @@
{
"Public Notes": "Public Notes",
"Private Notes": "Private Notes",
"Machine ID": "Machine ID"
"Machine ID": "Machine ID",
"Back": "Back"
}

@ -3,5 +3,6 @@
"Component saved!": "Component saved!",
"Event logged!": "Event logged!",
"Client saved!": "Client saved!",
"Client must be edited in Invoice Ninja.": "Client must be edited in Invoice Ninja."
"Client must be edited in Invoice Ninja.": "Client must be edited in Invoice Ninja.",
"That ID does not exist in the system.": "That ID does not exist in the system."
}

@ -17,6 +17,10 @@ define("MESSAGES", [
"string" => "You don't have permission to do that.",
"type" => "danger"
],
"no_such_machine" => [
"string" => "That ID does not exist in the system.",
"type" => "danger"
],
"machine_saved" => [
"string" => "Machine saved!",
"type" => "success"

@ -42,7 +42,7 @@ if (!empty($SETTINGS["apis"]["invoiceninja"]["token"])) {
}
public static function getClient($id): Client {
return new Client($client->id, false);
return new Client($id, false);
}
public static function areLocal(): bool {

@ -56,4 +56,7 @@ define("PAGES", [
"editclient" => [
"title" => "Edit Client"
],
"printlabel" => [
"title" => "Print"
],
]);

@ -61,7 +61,7 @@ $clients = Clients::getAll();
<?php
}
?>
<a class="btn btn-info btn-sm" href="app.php?page=viewmachine&id=<?php echo $m['machineid']; ?>"><i class="fas fa-eye"></i> <?php $Strings->get("View"); ?></a>
<a class="btn btn-info btn-sm" href="app.php?page=printlabel&id=<?php echo $m['machineid']; ?>"><i class="fas fa-print"></i> <?php $Strings->get("Print"); ?></a>
</td>
<td><a href="./app.php?page=viewmachine&id=<?php echo $m['machineid']; ?>"><?php echo $m['machineid']; ?></a></td>
<td><?php

@ -0,0 +1,55 @@
<?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>

@ -19,7 +19,7 @@ if (!empty($_GET["id"])) {
$machineid = $_GET["arg"];
}
if (!Machine::exists($machineid)) {
header("Location: ./app.php?msg=invalid_parameters");
header("Location: ./app.php?msg=no_such_machine");
}
$machine = new Machine($machineid);
@ -34,6 +34,8 @@ $machine = new Machine($machineid);
<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>
<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>
<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>

@ -0,0 +1,120 @@
<?php
/*
* Copyright 2020 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/.
*/
require_once __DIR__ . "/../required.php";
redirectIfNotLoggedIn();
$user = new User($_SESSION['uid']);
if (!$user->hasPermission("MACHINEMANAGER_VIEW")) {
die("No permission.");
}
if (!empty($_GET["id"])) {
$machineid = $_GET["id"];
} else if (!empty($_GET["arg"])) {
$machineid = $_GET["arg"];
}
if (!Machine::exists($machineid)) {
exit("No such machine.");
}
$labeltype = "machineid";
switch ($VARS["labeltype"]) {
case "doortag":
$labeltype = "doortag";
break;
case "machineid":
default:
$labeltype = "machineid";
}
$machine = new Machine($machineid);
$mergedata = [
"id" => $machine->getID(),
"link" => str_replace("{{id}}", $machine->getID(), $SETTINGS["branding"]["trackinglink"]),
"price" => number_format($machine->getPrice(), 2),
"serial" => $machine->getSerial(),
"model" => $machine->getModel(),
"os" => $machine->getOS(),
"manufacturer" => $machine->getManufacturer(),
"publicnotes" => $machine->getPublicNotes(),
"privatenotes" => $machine->getPrivateNotes(),
"clientid" => "",
"clientname" => "",
"clientphone" => "",
"clientphoneformatted" => "",
"clientemail" => "",
"clientbillingaddress" => "",
"clientshippingaddress" => "",
"clientpublicnotes" => "",
"clientprivatenotes" => "",
];
/**
* https://stackoverflow.com/a/14167216
*/
function formatPhoneNumber($phoneNumber) {
$phoneNumber = preg_replace('/[^0-9]/', '', $phoneNumber);
if (strlen($phoneNumber) > 10) {
$countryCode = substr($phoneNumber, 0, strlen($phoneNumber) - 10);
$areaCode = substr($phoneNumber, -10, 3);
$nextThree = substr($phoneNumber, -7, 3);
$lastFour = substr($phoneNumber, -4, 4);
$phoneNumber = '+' . $countryCode . ' (' . $areaCode . ') ' . $nextThree . '-' . $lastFour;
} else if (strlen($phoneNumber) == 10) {
$areaCode = substr($phoneNumber, 0, 3);
$nextThree = substr($phoneNumber, 3, 3);
$lastFour = substr($phoneNumber, 6, 4);
$phoneNumber = '(' . $areaCode . ') ' . $nextThree . '-' . $lastFour;
} else if (strlen($phoneNumber) == 7) {
$nextThree = substr($phoneNumber, 0, 3);
$lastFour = substr($phoneNumber, 3, 4);
$phoneNumber = $nextThree . '-' . $lastFour;
}
return $phoneNumber;
}
if (!empty($machine->getClientID())) {
$client = Clients::getClient($machine->getClientID());
$mergedata["clientid"] = $client->getID();
$mergedata["clientname"] = $client->getName();
$mergedata["clientphone"] = $client->getPhone();
$mergedata["clientphoneformatted"] = formatPhoneNumber($client->getPhone());
$mergedata["clientemail"] = $client->getEmail();
$mergedata["clientbillingaddress"] = $client->getBillingAddress();
$mergedata["clientshippingaddress"] = $client->getMailingAddress();
$mergedata["clientpublicnotes"] = $client->getPublicNotes();
$mergedata["clientprivatenotes"] = $client->getPrivateNotes();
}
$csvfile = tempnam("/tmp", "MCHMGR_CSV");
$fp = fopen($csvfile, 'w');
fputcsv($fp, array_keys($mergedata));
fputcsv($fp, array_values($mergedata));
fclose($fp);
$pdffile = tempnam("/tmp", "MCHMGR_PDF");
shell_exec("glabels-3-batch --input=$csvfile --output=$pdffile " . __DIR__ . "/templates/$labeltype.glabels");
header('Content-type: application/pdf');
header("Content-Disposition: inline; filename=\"$labeltype (ID $mergedata[id])\"");
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo file_get_contents($pdffile);
unlink($csvfile);
unlink($pdffile);

Binary file not shown.

Binary file not shown.

@ -38,7 +38,7 @@ if (isset($_SESSION['mobile']) && $_SESSION['mobile'] === TRUE) {
. "object-src 'none'; "
. "img-src * data:; "
. "media-src 'self'; "
. "frame-src 'none'; "
. "frame-src 'self'; "
. "font-src 'self'; "
. "connect-src *; "
. "style-src 'self' 'unsafe-inline'; "
@ -49,7 +49,7 @@ if (isset($_SESSION['mobile']) && $_SESSION['mobile'] === TRUE) {
. "object-src 'none'; "
. "img-src * data:; "
. "media-src 'self'; "
. "frame-src 'none'; "
. "frame-src 'self'; "
. "font-src 'self'; "
. "connect-src *; "
. "style-src 'self' 'nonce-$SECURE_NONCE'; "

@ -39,7 +39,8 @@ $SETTINGS = [
"branding" => [
"machineidnumber" => "Netsyms machine ID number",
"shortmachineid" => "Machine ID Number",
"publictitle" => "Machine Lookup"
"publictitle" => "Machine Lookup",
"trackinglink" => "https://qr.ntsm.io/?t=mid&q={{id}}"
],
// Settings for connecting to the AccountHub server.
"accounthub" => [

Loading…
Cancel
Save