insert ignore into ffzg_inventura
[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 my $sth_inventura = $dbh->prepare(qq{
28 insert ignore into ffzg_inventura (date_scanned,barcode,source_id) values (date(now()), ?, 'abc')
29 });
30 get '/' => sub {
31         my $c = shift;
32
33         my $barcode = $c->param('barcode');
34         warn "# $barcode";
35         $sth->execute( $barcode );
36         while ( my $row = $sth->fetchrow_hashref ) {
37                 warn "# row ",dump($row);
38                 $c->stash( $_ => $row->{$_} ) foreach keys %$row;
39         }
40         $sth_update->execute( $barcode );
41         $sth_inventura->execute( $barcode );
42         $c->render(template => 'index');
43 };
44
45 app->start;
46 __DATA__
47
48 @@ index.html.ep
49 % layout 'default';
50
51 %= form_for '/' => begin
52         %#= text_field 'barcode'
53         <input name=barcode size=10 autofocus>
54         %= submit_button 'Scan'
55 % end
56
57 <%= stash('author') %>
58 <b><%= stash('title') %></b>
59
60 @@ layouts/default.html.ep
61 <!DOCTYPE html>
62 <html>
63   <head>
64   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
65   <style>
66         body {
67                 font-size: 800%;
68         }
69   </style>
70   <title>Inventura</title>
71 </head>
72   <body><%= content %></body>
73 </html>