View | Details | Raw Unified | Return to bug 15766
Collapse All | Expand All

(-)a/C4/Creators/Batch.pm (-2 / +5 lines)
Lines 15-20 sub _check_params { Link Here
15
    my @valid_template_params = (
15
    my @valid_template_params = (
16
        'label_id',
16
        'label_id',
17
        'batch_id',
17
        'batch_id',
18
        'description',
18
        'item_number',
19
        'item_number',
19
        'card_number',
20
        'card_number',
20
        'branch_code',
21
        'branch_code',
Lines 43-48 sub new { Link Here
43
    my $type = ref($invocant) || $invocant;
44
    my $type = ref($invocant) || $invocant;
44
    my $self = {
45
    my $self = {
45
        batch_id        => 0,
46
        batch_id        => 0,
47
        description     => '',
46
        items           => [],
48
        items           => [],
47
        branch_code     => 'NB',
49
        branch_code     => 'NB',
48
        batch_stat      => 0,   # False if any data has changed and the db has not been updated
50
        batch_stat      => 0,   # False if any data has changed and the db has not been updated
Lines 63-72 sub add_item { Link Here
63
        my $batch_id = $sth->fetchrow_array;
65
        my $batch_id = $sth->fetchrow_array;
64
        $self->{'batch_id'}= ++$batch_id;
66
        $self->{'batch_id'}= ++$batch_id;
65
    }
67
    }
66
    my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);";
68
    my $query = "INSERT INTO creator_batches (batch_id, description, $number_type, branch_code, creator) VALUES (?,?,?,?,?);";
67
    my $sth = C4::Context->dbh->prepare($query);
69
    my $sth = C4::Context->dbh->prepare($query);
68
#    $sth->{'TraceLevel'} = 3;
70
#    $sth->{'TraceLevel'} = 3;
69
    $sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1);
71
    $sth->execute($self->{'batch_id'}, $self->{'description'}, $number, $self->{'branch_code'}, $1);
70
    if ($sth->err) {
72
    if ($sth->err) {
71
       warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr);
73
       warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr);
72
        return -1;
74
        return -1;
Lines 149-154 sub retrieve { Link Here
149
    while (my $record = $sth->fetchrow_hashref) {
151
    while (my $record = $sth->fetchrow_hashref) {
150
        $self->{'branch_code'} = $record->{'branch_code'};
152
        $self->{'branch_code'} = $record->{'branch_code'};
151
        $self->{'creator'} = $record->{'creator'};
153
        $self->{'creator'} = $record->{'creator'};
154
        $self->{'description'} = $record->{'description'};
152
        push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
155
        push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
153
        $record_flag = 1;       # true if one or more rows were retrieved
156
        $record_flag = 1;       # true if one or more rows were retrieved
154
    }
157
    }
(-)a/C4/Creators/Lib.pm (-1 / +1 lines)
Lines 279-285 NOTE: Do not pass in the keyword 'WHERE.' Link Here
279
sub get_batch_summary {
279
sub get_batch_summary {
280
    my ( $params ) = @_;
280
    my ( $params ) = @_;
281
    my @batches = ();
281
    my @batches = ();
282
    $params->{fields} = ['batch_id', 'count(batch_id) as _item_count'];
282
    $params->{fields} = ['batch_id', 'description', 'count(batch_id) as _item_count'];
283
    my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
283
    my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
284
    $query .= " GROUP BY batch_id";
284
    $query .= " GROUP BY batch_id";
285
    my $sth = C4::Context->dbh->prepare($query);
285
    my $sth = C4::Context->dbh->prepare($query);
(-)a/installer/data/mysql/atomicupdate/bug_15766_-_add_description_column_to_batches.perl (+9 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    unless( column_exists( 'creator_batches', 'description' ) ) {
4
        $dbh->do(q|ALTER TABLE creator_batches ADD description mediumtext default NULL AFTER batch_id|);
5
    }
6
7
    SetVersion( $DBversion );
8
    print "Upgrade to $DBversion done (Bug 15766: Add column creator_batches.description)\n";
9
}
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1813-1818 SET character_set_client = utf8; Link Here
1813
CREATE TABLE `creator_batches` (
1813
CREATE TABLE `creator_batches` (
1814
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1814
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1815
  `batch_id` int(10) NOT NULL DEFAULT '1',
1815
  `batch_id` int(10) NOT NULL DEFAULT '1',
1816
  `description` mediumtext DEFAULT NULL,
1816
  `item_number` int(11) DEFAULT NULL,
1817
  `item_number` int(11) DEFAULT NULL,
1817
  `borrower_number` int(11) DEFAULT NULL,
1818
  `borrower_number` int(11) DEFAULT NULL,
1818
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1819
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt (-6 / +36 lines)
Lines 156-161 Link Here
156
                var batch_id = $(this).data("batch-id");
156
                var batch_id = $(this).data("batch-id");
157
                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
157
                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
158
            });
158
            });
159
            $("#savedesc").click(function(event){
160
                event.preventDefault(); // prevent form submission
161
                var newdescription = $(this).siblings('input[name="description"]').val();
162
                var batch_id = $(this).data('batch_id');
163
                var ajaxData = {
164
                    'newdescription': newdescription,
165
                    'batch_id': batch_id,
166
                    'card_element': "batch",
167
                };
168
169
                $.ajax({
170
                    url: '/cgi-bin/koha/svc/patroncards',
171
                    type: 'POST',
172
                    dataType: 'json',
173
                    data: ajaxData,
174
                })
175
176
                .done(function(data){
177
                    if (data.status == 'success') {
178
                        $("input[name='description']").text(data.newdesc);
179
                        $("#change-status").text(_("Saved"));
180
                    } else {
181
                        $("#change-status").text(_("Unable to save description"));
182
                    }
183
                });
184
            });
159
         });
185
         });
160
        //]]>
186
        //]]>
161
    </script>
187
    </script>
Lines 198-209 Link Here
198
                                <div>
224
                                <div>
199
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
225
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
200
                                    <ol><li>
226
                                    <ol><li>
201
                                    <input type="hidden" name="op" value="add" />
227
                                        <input type="hidden" name="op" value="add" />
202
                                    <input type="hidden" name="batch_id" value="[% batch_id %]" />
228
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
203
                                    <label for="bor_num_list">Add by borrowernumber(s):
229
                                        <label for="description">Batch description: </label>
204
                                        <br /> <span class="hint">One borrowernumber per line.</span>
230
                                        <input type="text" name="description" value="[% description %]">
205
                                    </label>
231
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id %]">Save description</a> <span id="change-status"></span>
206
                                    <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
232
                                    </li><li>
233
                                        <label for="bor_num_list">Add by borrowernumber(s):
234
                                            <br /> <span class="hint">One borrowernumber per line.</span>
235
                                        </label>
236
                                        <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
207
                                    </li></ol>
237
                                    </li></ol>
208
                                    </fieldset>
238
                                    </fieldset>
209
                                </div>
239
                                </div>
(-)a/patroncards/edit-batch.pl (+3 lines)
Lines 54-59 my $display_columns = [ {_summary => {label => 'Summary', link_field => 0} Link Here
54
                      ];
54
                      ];
55
my $op = $cgi->param('op') || 'new';
55
my $op = $cgi->param('op') || 'new';
56
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
56
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
57
my $description = $cgi->param('description') || '';
57
my ( @label_ids, @item_numbers, @borrower_numbers );
58
my ( @label_ids, @item_numbers, @borrower_numbers );
58
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
59
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
59
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
60
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
Lines 92-97 if ($bor_num_list) { Link Here
92
    }
93
    }
93
    if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
94
    if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
94
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
95
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
96
    $template->param( description => $batch->{'description'} );
95
    if ($branch_code){
97
    if ($branch_code){
96
        foreach my $borrower_number (@borrower_numbers) {
98
        foreach my $borrower_number (@borrower_numbers) {
97
            $err = $batch->add_item($borrower_number);
99
            $err = $batch->add_item($borrower_number);
Lines 118-123 elsif ($op eq 'de_duplicate') { Link Here
118
}
120
}
119
elsif ($op eq 'edit') {
121
elsif ($op eq 'edit') {
120
    $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
122
    $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
123
    $template->param( description => $batch->{'description'} );
121
}
124
}
122
elsif ($op eq 'new') {
125
elsif ($op eq 'new') {
123
    if ($branch_code eq '') {
126
    if ($branch_code eq '') {
(-)a/patroncards/manage.pl (+1 lines)
Lines 70-75 my $display_columns = { layout => [ # db column => {col label Link Here
70
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
70
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
71
                                    ],
71
                                    ],
72
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
72
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
73
                                        {description     => {label => 'Description',    link_field      => 0}},
73
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
74
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
74
                                        {_action         => {label => 'Actions',        link_field      => 0}},
75
                                        {_action         => {label => 'Actions',        link_field      => 0}},
75
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
76
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
(-)a/svc/patroncards (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz>
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use JSON qw( to_json );
23
use CGI;
24
use C4::Service;
25
use C4::Context;
26
use C4::Auth qw /check_cookie_auth/;
27
use C4::Output qw(:DEFAULT :ajax);
28
use C4::Patroncards::Batch;
29
use Data::Dumper;
30
31
=head1 NAME
32
33
svc/patroncards - Web service for managing AJAX functionality for patroncards
34
35
=head1 DESCRIPTION
36
37
=cut
38
39
# AJAX requests
40
my $is_ajax = is_ajax();
41
my $cgi = new CGI;
42
my ( $auth_status, $sessionID ) = check_cookie_auth( $cgi->cookie('CGISESSID'), { catalogue => 1 } );
43
if ( $auth_status ne "ok" ) {
44
    exit 0;
45
}
46
if ($is_ajax) {
47
    my $card_element = $cgi->param('card_element');
48
    if ( $card_element eq 'batch' ) {
49
        my $batch_id = $cgi->param('batch_id');
50
        my $description = $cgi->param('newdescription');
51
        my $status = '';
52
        my $dbh = C4::Context->dbh;
53
        my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
54
        my $sth = $dbh->prepare($query);
55
        $sth->execute($description, $batch_id);
56
57
        # Check for success
58
        my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
59
        if ( $batch->{description} eq $description ) {
60
            $status = 'success';
61
        }
62
63
        my $json = to_json ( { status => $status, newdesc => $description } );
64
        output_with_http_headers $cgi, undef, $json, 'js';
65
        exit;
66
    }
67
}

Return to bug 15766