BUG 7143: Add Kyle Hall as the 42nd developer to history
[koha.git] / tools / quotes / quotes-upload_ajax.pl
blob08606e0eda945058c65173b875456bec8971c4c0
1 #!/usr/bin/perl
3 # Copyright 2012 Foundations Bible College Inc.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 use CGI qw ( -utf8 );
24 use JSON;
25 use autouse 'Data::Dumper' => qw(Dumper);
27 use C4::Auth;
28 use C4::Koha;
29 use C4::Context;
30 use C4::Output;
32 my $cgi = new CGI;
33 my $dbh = C4::Context->dbh;
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37 template_name => "",
38 query => $cgi,
39 type => "intranet",
40 authnotrequired => 0,
41 flagsrequired => { tools => 'edit_quotes' },
42 debug => 1,
46 my $success = 'true';
48 my $quotes = decode_json($cgi->param('quote'));
49 my $action = $cgi->param('action');
51 my $sth = $dbh->prepare('INSERT INTO quotes (source, text) VALUES (?, ?);');
53 my $insert_count = 0;
55 foreach my $quote (@$quotes) {
56 $insert_count++ if $sth->execute($quote->[1], $quote->[2]);
57 if ($sth->err) {
58 warn sprintf('Database returned the following error: %s', $sth->errstr);
59 $success = 'false';
63 print $cgi->header('application/json');
65 print to_json({
66 success => $success,
67 records => $insert_count,
68 });