simplest possible mojo web scan barcode app
[koha-dla] / barcode-seen.pl
1 #!/usr/bin/env perl
2 use Mojolicious::Lite;
3
4 use lib '/srv/koha_ffzg';
5 BEGIN {
6         $ENV{KOHA_CONF} = '/etc/koha/sites/ffzg/koha-conf.xml';
7 }
8 use C4::Context;
9
10 use Data::Dump qw(dump);
11
12 my $sql = qq{
13 select
14         title,
15         author
16 from items
17 join biblio on biblio.biblionumber = items.biblionumber where barcode = ?
18 };
19
20 my $dbh = C4::Context->dbh;
21 my $sth = $dbh->prepare($sql);
22
23 my $sth_update = $dbh->prepare(qq{
24 update items set datelastseen = now() where barcode = ?
25 });
26
27 get '/' => sub {
28         my $c = shift;
29
30         my $barcode = $c->param('barcode');
31         warn "# $barcode";
32         $sth->execute( $barcode );
33         while ( my $row = $sth->fetchrow_hashref ) {
34                 warn "# row ",dump($row);
35                 $c->stash( $_ => $row->{$_} ) foreach keys %$row;
36         }
37         $sth_update->execute( $barcode );
38         $c->render(template => 'index');
39 };
40
41 app->start;
42 __DATA__
43
44 @@ index.html.ep
45 % layout 'default';
46
47 %= form_for '/' => begin
48         %#= text_field 'barcode'
49         <input name=barcode size=10 autofocus>
50         %= submit_button 'Scan'
51 % end
52
53 <%= stash('author') %>
54 <b><%= stash('title') %></b>
55
56 @@ layouts/default.html.ep
57 <!DOCTYPE html>
58 <html>
59   <head>
60   <style>
61         body {
62                 font-size: 800%;
63         }
64   </style>
65   <title>Inventura</title>
66 </head>
67   <body><%= content %></body>
68 </html>