Add label printing with gLabels integration
parent
5bc4b63d8f
commit
dbd797af99
@ -1,5 +1,6 @@
|
||||
{
|
||||
"Public Notes": "Public Notes",
|
||||
"Private Notes": "Private Notes",
|
||||
"Machine ID": "Machine ID"
|
||||
"Machine ID": "Machine ID",
|
||||
"Back": "Back"
|
||||
}
|
@ -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>
|
@ -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.
Loading…
Reference in New Issue