diff --git a/langs/en/actions.json b/langs/en/actions.json
index 0fb4def..5007c91 100644
--- a/langs/en/actions.json
+++ b/langs/en/actions.json
@@ -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"
}
diff --git a/langs/en/labels.json b/langs/en/labels.json
index c5c2448..04fb2c3 100644
--- a/langs/en/labels.json
+++ b/langs/en/labels.json
@@ -1,5 +1,6 @@
{
"Public Notes": "Public Notes",
"Private Notes": "Private Notes",
- "Machine ID": "Machine ID"
+ "Machine ID": "Machine ID",
+ "Back": "Back"
}
\ No newline at end of file
diff --git a/langs/en/messages.json b/langs/en/messages.json
index 58b866d..d34aeaf 100644
--- a/langs/en/messages.json
+++ b/langs/en/messages.json
@@ -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."
}
diff --git a/langs/messages.php b/langs/messages.php
index 888045a..0563225 100644
--- a/langs/messages.php
+++ b/langs/messages.php
@@ -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"
diff --git a/lib/Clients.lib.php b/lib/Clients.lib.php
index a1a673c..6ce99f5 100644
--- a/lib/Clients.lib.php
+++ b/lib/Clients.lib.php
@@ -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 {
diff --git a/pages.php b/pages.php
index 0632d94..a7c7280 100644
--- a/pages.php
+++ b/pages.php
@@ -56,4 +56,7 @@ define("PAGES", [
"editclient" => [
"title" => "Edit Client"
],
+ "printlabel" => [
+ "title" => "Print"
+ ],
]);
\ No newline at end of file
diff --git a/pages/machines.php b/pages/machines.php
index a0a9b29..d746bb3 100644
--- a/pages/machines.php
+++ b/pages/machines.php
@@ -61,7 +61,7 @@ $clients = Clients::getAll();
- get("View"); ?>
+ get("Print"); ?>
|
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";
+?>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/viewmachine.php b/pages/viewmachine.php
index 0265e57..5750a8c 100644
--- a/pages/viewmachine.php
+++ b/pages/viewmachine.php
@@ -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);
get("Edit"); ?>
get("Add Event"); ?>
get("Add Component"); ?>
+ get("Print Labels"); ?>
+ get("Back"); ?>
diff --git a/print/print.php b/print/print.php
new file mode 100644
index 0000000..78e318b
--- /dev/null
+++ b/print/print.php
@@ -0,0 +1,120 @@
+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);
\ No newline at end of file
diff --git a/print/templates/doortag.glabels b/print/templates/doortag.glabels
new file mode 100644
index 0000000..5762422
Binary files /dev/null and b/print/templates/doortag.glabels differ
diff --git a/print/templates/machineid.glabels b/print/templates/machineid.glabels
new file mode 100644
index 0000000..91e7b01
Binary files /dev/null and b/print/templates/machineid.glabels differ
diff --git a/required.php b/required.php
index b81e8b8..97cc2fc 100644
--- a/required.php
+++ b/required.php
@@ -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'; "
diff --git a/settings.template.php b/settings.template.php
index 5fa6ace..2480965 100644
--- a/settings.template.php
+++ b/settings.template.php
@@ -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" => [
|