Added support for creating labels for print using QR codes.

Also fixed a bug when adding a product without tags
and a minor usability fix on the checkout page
This commit is contained in:
Erik Thuning 2019-06-11 14:59:49 +02:00
parent 56c634cf18
commit 4acd884261
3 changed files with 121 additions and 13 deletions

@ -139,7 +139,8 @@
¤¤ product_details ¤¤
<h2>Artikeldata</h2>
<form id="productdata"
onSubmit="JavaScript:saveProduct(event)">
onSubmit="JavaScript:saveProduct(event)"
class="left">
<input type="hidden"
name="id"
value="¤id¤" />
@ -235,6 +236,34 @@
</tbody>
</table>
</form>
¤label¤
<div class="clear"></div>
¤¤ product_label ¤¤
<div class="qr left">
<a href="./?page=print&id=¤id¤"
title="Skriv ut">
<span>¤name¤</span>
<img src="./?page=qr&id=¤id¤">
<span>¤serial¤</span>
</a>
</div>
¤¤ label_page ¤¤
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="./template.css" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<title>¤title¤</title>
</head>
<body>
¤label¤
</body>
</html>
¤¤ discard_button ¤¤
<form>
@ -455,7 +484,8 @@
<input type="text"
name="product"
placeholder="Serienummer"
required />
required
¤disabled¤ />
<button>
Låna ut
</button>
@ -465,7 +495,8 @@
id="end"
onClick="JavaScript:calendar(event)"
name="end"
value="¤end¤" />
value="¤end¤"
¤disabled¤ />
</form>
¤subtitle¤
¤loan_table¤

@ -3,6 +3,7 @@
require_once('./include/db.php');
require_once('./include/ldap.php');
require_once('./include/functions.php');
include_once('./phpqrcode/qrlib.php');
function make_page($page) {
switch($page) {
@ -23,6 +24,10 @@ function make_page($page) {
return new HistoryPage();
case 'ajax':
return new Ajax();
case 'qr':
return new QR();
case 'print':
return new Printer();
}
}
@ -585,13 +590,18 @@ class ProductPage extends Page {
$tags .= replace(array('tag' => ucfirst($tag)),
$this->fragments['tag']);
}
$out = replace(array('id' => $this->product->get_id(),
'name' => $this->product->get_name(),
'serial' => $this->product->get_serial(),
'invoice' => $this->product->get_invoice(),
'tags' => $tags,
'info' => $info),
$this->fragments['product_details']);
$fields = array('id' => $this->product->get_id(),
'name' => $this->product->get_name(),
'serial' => $this->product->get_serial(),
'invoice' => $this->product->get_invoice(),
'tags' => $tags,
'info' => $info);
$label = '';
if(class_exists('QRcode', false)) {
$label = replace($fields, $this->fragments['product_label']);
}
$fields['label'] = $label;
$out = replace($fields, $this->fragments['product_details']);
if(!$this->product->get_discardtime()) {
$out .= replace(array('id' => $this->product->get_id()),
$this->fragments['discard_button']);
@ -631,7 +641,8 @@ class ProductPage extends Page {
'serial' => '',
'invoice' => '',
'tags' => $tags,
'info' => $fields),
'info' => $fields,
'label' => ''),
$this->fragments['product_details']);
return $out;
}
@ -731,11 +742,14 @@ class CheckoutPage extends Page {
$notes = '';
$loan_table = '';
$subhead = '';
$enddate = gmdate('Y-m-d', time() + 604800); # 1 week from now
$enddate = '';
$disabled = 'disabled';
if($this->user !== null) {
$username = $this->user->get_name();
$displayname = $this->user->get_displayname();
$notes = $this->user->get_notes();
$enddate = gmdate('Y-m-d', time() + 604800); # 1 week from now
$disabled = '';
$loans = $this->user->get_loans('active');
$loan_table = 'Inga pågående lån.';
if($loans) {
@ -749,6 +763,7 @@ class CheckoutPage extends Page {
'notes' => $notes,
'end' => $enddate,
'subtitle' => $subhead,
'disabled' => $disabled,
'loan_table' => $loan_table),
$this->fragments['checkout_page']));
}
@ -1021,7 +1036,10 @@ class Ajax extends Responder {
$name = $info['name'];
$serial = $info['serial'];
$invoice = $info['invoice'];
$tags = $this->unescape_tags($info['tag']);
$tags = array();
if(isset($info['tag'])) {
$tags = $this->unescape_tags($info['tag']);
}
foreach(array('id', 'name', 'serial', 'invoice', 'tag') as $key) {
unset($info[$key]);
}
@ -1198,6 +1216,40 @@ class Ajax extends Responder {
}
}
class QR extends Responder {
protected $product = '';
public function __construct() {
parent::__construct();
if(isset($_GET['id'])) {
$this->product = new Product($_GET['id']);
}
}
public function render() {
if(class_exists('QRcode', false)) {
QRcode::svg((string)$this->product->get_serial());
}
}
}
class Printer extends QR {
public function __construct() {
parent::__construct();
}
public function render() {
$label = replace(array('id' => $this->product->get_id(),
'name' => $this->product->get_name(),
'serial' => $this->product->get_serial()),
$this->fragments['product_label']);
$title = 'Etikett för artikel '.$this->product->get_serial();
print(replace(array('title' => $title,
'label' => $label),
$this->fragments['label_page']));
}
}
class Result {
private $type = '';
private $message = '';

@ -135,3 +135,28 @@ input[type="text"].newtemplate {
margin: 5px;
padding-left: 2px;
}
.qr {
margin: 0 10px;
padding: 5px;
border: 1px solid black;
font-weight: bold;
text-align: center;
font-size: 120%;
}
@media print {
.qr {
border: none;
}
}
.qr > a:link, .qr > a:visited {
color: black;
text-decoration: none;
}
.qr > a > * {
display: block;
margin: 0 auto;
}