From 135d8c9ef7fe197b0547629e38f9cc73de5dbc98 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 10 Jan 2015 20:19:08 +0100 Subject: Use system wide config file for label_id_prefix & label_name. --- mat | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mat b/mat index 16478fe..48e7efd 100755 --- a/mat +++ b/mat @@ -14,9 +14,6 @@ use Text::Iconv; tie my %Config, "Config::Simple", '/etc/mat.conf'; -use constant LABEL_NAME => $Config{'label_name'}; -use constant LABEL_ID_PREFIX => $Config{'label_id_prefix'}; - #use Data::Dumper; my $db = DBI->connect("dbi:SQLite:recipe.db", "", "", {RaiseError => 1, @@ -276,11 +273,11 @@ sub print_label { my $y_border = 40; my $iconv = Text::Iconv->new("UTF-8", "ISO8859-1"); - my $row0 = LABEL_NAME; + my $row0 = $Config{'label_name'}; my $row1 = $iconv->convert($dish_name); my $row2 = `date +%Y%m%d|tr -d '\n'`.' ('.$amount.'g)'; - my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", LABEL_ID_PREFIX, $id), { Version=>3 }); + my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", $Config{'label_id_prefix'}, $id), { Version=>3 }); my $idbarcode_image=$idbarcode->plot(); my $idtext = new GD::Image(500, $fontsize * 2); -- cgit v1.2.3 From 1c478c82986d8340814d5d17c4522704a489e529 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 10 Jan 2015 20:21:43 +0100 Subject: Add hackish support to print a logo on some labels. --- mat | 12 +++++++++++- sts | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mat b/mat index 48e7efd..45ce51d 100755 --- a/mat +++ b/mat @@ -280,6 +280,11 @@ sub print_label { my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", $Config{'label_id_prefix'}, $id), { Version=>3 }); my $idbarcode_image=$idbarcode->plot(); + my $logo; + if ($ENV{'PRINT_WITH_LOGO'}) { + $logo = GD::Image->newFromPng("layer1.png"); + } + my $idtext = new GD::Image(500, $fontsize * 2); my $white = $idtext->colorAllocate(255,255,255); my $black = $idtext->colorAllocate(0,0,0); @@ -333,10 +338,15 @@ sub print_label { $label->fill(0, 0, $white); $label->copyResized($idbarcode_image, $x_border, $y_border, 0, 0, $idbarcode_image->width() * 5, $idbarcode_image->height() * 5, $idbarcode_image->width(), $idbarcode_image->height()); - $label->copyResized($idtext, $x_border * 2, $y_border + $idbarcode_image->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height()); + $label->copyResized($idtext, $x_border * 3, $y_border + $idbarcode_image->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height()); $label->copyResized($text0_image, $label->width() - $x_border - 2 * $fontsize, $y_border, 0, 0, $bounds0[1] * 1, $bounds0[2], $bounds0[1], $bounds0[2]); $label->copyResized($text1_image, $label->width() - $x_border - 4 * $fontsize, $y_border, 0, 0, $bounds1[1] * 1, $bounds1[2], $bounds1[1], $bounds1[2]); $label->copyResized($text2_image, $label->width() - $x_border - 6 * $fontsize, $y_border, 0, 0, $bounds2[1] * 1, $bounds2[2], $bounds2[1], $bounds2[2]); + if ($ENV{'PRINT_WITH_LOGO'}) { + my ($logo_w, $logo_h ) = $logo->getBounds(); + my $vl = $logo->copyRotate90(); + $label->copy($vl, $x_border - 20, $label->height - $y_border + 20 - $logo_w, 0, 0, $logo_h, $logo_w); + } open(PNGFILE, ">label.png"); print PNGFILE $label->png; diff --git a/sts b/sts index 2f910f7..72771bd 100755 --- a/sts +++ b/sts @@ -2,5 +2,9 @@ # scale triggered store cd $HOME/mat/matplan/ -./mat storeportion `cat currently_cooking` "$1" hemfrys +if (grep -q v currently_cooking); then + PRINT_WITH_LOGO=y ./mat storeportion `cat currently_cooking|sed 's/v//'` "$1" hemfrys +else + ./mat storeportion `cat currently_cooking|sed 's/v//'` "$1" hemfrys +fi -- cgit v1.2.3 From f4ebbc7557f3d97ef5fd25c9a7052532e33a7470 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 10 Jan 2015 20:23:17 +0100 Subject: Order inventory by preparation date. --- mat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mat b/mat index 45ce51d..8e86cc2 100755 --- a/mat +++ b/mat @@ -185,7 +185,7 @@ sub cmd_inventory { my $sql = "SELECT recipe_id, count(recipe_id), storage FROM inventory"; $sql .= " WHERE storage='$storage'" if ( $storage ); - $sql .= " GROUP BY storage, recipe_id"; + $sql .= " GROUP BY storage, preparation_date, recipe_id"; my $all = $db->selectall_arrayref($sql); foreach my $row (@$all) { -- cgit v1.2.3 From 171cd3504615382db0783495b6abd18608627d50 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 7 Dec 2014 16:58:20 +0100 Subject: Implement relocate command. --- cgi-bin/mat.cgi | 73 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/cgi-bin/mat.cgi b/cgi-bin/mat.cgi index 7b31e87..4275478 100755 --- a/cgi-bin/mat.cgi +++ b/cgi-bin/mat.cgi @@ -5,6 +5,7 @@ use warnings; use Config::Simple; use CGI::Simple; +use CGI::Session; use DBI; tie my %Config, "Config::Simple", '/etc/mat.conf'; @@ -12,6 +13,9 @@ tie my %Config, "Config::Simple", '/etc/mat.conf'; my $q = new CGI::Simple; my $id = $q->param('id'); my $action = $q->param('action'); +my $storage = $q->param('storage'); +my $session = CGI::Session->new(undef, undef, {Directory => + $Config{'session_directory'}}); sub misconfigured { @@ -27,20 +31,67 @@ sub invalid_input() exit 1; } +sub unauthorized() +{ + print "Content-Type: text/plain; charset=utf-8\n\r\n\r"; + print "Not authorized!\n"; + exit 1; +} + +sub send_cookie() +{ + print $session->header(-type => 'text/plain', -charset => 'utf8'); +} + +sub cmd_view($) +{ + my ( $id ) = @_; + + my $db = DBI->connect($Config{'database'}, "", "", + {HandleError => \&misconfigured, AutoCommit => 1}); + + my $recipe_row = $db->selectrow_arrayref("SELECT name, storage, uri FROM ". + "recipes AS r JOIN inventory AS i ON i.recipe_id=r.id WHERE i.id=".$id. + ";"); + + print $id, "\n", $$recipe_row[0], "\n", $$recipe_row[1], "\n", + $$recipe_row[2], "\n"; +} + +sub cmd_relocate($$) +{ + my ( $id, $storage ) = @_; + + my $db = DBI->connect($Config{'database'}, "", "", + {HandleError => \&misconfigured, AutoCommit => 1}); + + $db->do('UPDATE inventory SET storage="'.$storage.'" WHERE id='.$id); + + cmd_view($id); +} + ### MAIN PROGRAM ############################################################## misconfigured unless ($Config{'database'}); +misconfigured unless $session; invalid_input unless ($id and $action); -invalid_input unless (($id =~ m/^[0-9]+$/) and ($action =~ m/^view$/)); - -my $db = DBI->connect($Config{'database'}, "", "", - {HandleError => \&misconfigured, AutoCommit => 1}); +invalid_input unless (($id =~ m/^[0-9]+$/) and ($action =~ m/^view|relocate$/) and + ($storage =~ /^[a-z0-9]*$/)); +send_cookie; -my $recipe_row = $db->selectrow_arrayref("SELECT name, storage, uri FROM ". - "recipes AS r JOIN inventory AS i ON i.recipe_id=r.id WHERE i.id=".$id. - ";"); - -print "Content-Type: text/plain; charset=utf-8\n\r\n\r"; -print $id, "\n", $$recipe_row[0], "\n", $$recipe_row[1], "\n", - $$recipe_row[2], "\n"; +for ($action) { + if (/^view$/) { + cmd_view($id); + } + elsif (/^relocate$/) { + if ($session->param('authenticated') eq "yes") { + cmd_relocate($id, $storage); + } else { + unauthorized(); + } + } + else { + invalid_input; + } +} -- cgit v1.2.3 From 8df944e4320ae7c8d63569ba11379a72afe338f7 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 10 Jan 2015 20:28:55 +0100 Subject: Default session expiration was a bit quick. --- cgi-bin/mat.cgi | 1 + 1 file changed, 1 insertion(+) diff --git a/cgi-bin/mat.cgi b/cgi-bin/mat.cgi index 4275478..d6e3d2d 100755 --- a/cgi-bin/mat.cgi +++ b/cgi-bin/mat.cgi @@ -86,6 +86,7 @@ for ($action) { } elsif (/^relocate$/) { if ($session->param('authenticated') eq "yes") { + $session->expire("5y"); cmd_relocate($id, $storage); } else { unauthorized(); -- cgit v1.2.3 From 31ee33ca4c14c03f5e1a2530735bda50d235de36 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 10 Jan 2015 21:40:16 +0100 Subject: Add storage links on relocate page. --- cgi-bin/mat.cgi | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cgi-bin/mat.cgi b/cgi-bin/mat.cgi index d6e3d2d..793671a 100755 --- a/cgi-bin/mat.cgi +++ b/cgi-bin/mat.cgi @@ -40,7 +40,7 @@ sub unauthorized() sub send_cookie() { - print $session->header(-type => 'text/plain', -charset => 'utf8'); + print $session->header(-type => 'text/html', -charset => 'utf8'); } sub cmd_view($) @@ -54,8 +54,20 @@ sub cmd_view($) "recipes AS r JOIN inventory AS i ON i.recipe_id=r.id WHERE i.id=".$id. ";"); - print $id, "\n", $$recipe_row[0], "\n", $$recipe_row[1], "\n", - $$recipe_row[2], "\n"; + print $id, "
", $$recipe_row[0], "
", $$recipe_row[1], "
"; + if(substr($$recipe_row[2], 0, 4) eq "http") { + print ''.$$recipe_row[2].'', "
"; + } else { + print $$recipe_row[2], "
"; + } + if ($session->param('authenticated') eq "yes") { + print "\n"; + for my $store ( split(" ", $Config{'relocate_stores'}) ) { + print " ". + "$store \n"; + } + print ""; + } } sub cmd_relocate($$) -- cgit v1.2.3 From 7ac05dbbea8543e4b1e1ac3f46779b7ad5191a81 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 10 Jan 2015 21:42:33 +0100 Subject: Initial commit of authenticate_session script. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index a759288..8acae4d 100644 --- a/Makefile +++ b/Makefile @@ -19,3 +19,5 @@ all: install: $(INSTALLDIRS) install -d $(DESTDIR)/usr/bin/ install mat $(DESTDIR)/usr/bin/ + install -d $(DESTDIR)/usr/lib/netizen-mat/ + install authenticate_session $(DESTDIR)/usr/lib/netizen-mat/ -- cgit v1.2.3