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

(-)a/C4/Creators/Batch.pm (-1 / +4 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-69 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'}, $number, $self->{'branch_code'}, $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 1822-1827 SET character_set_client = utf8; Link Here
1822
CREATE TABLE `creator_batches` (
1822
CREATE TABLE `creator_batches` (
1823
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1823
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1824
  `batch_id` int(10) NOT NULL DEFAULT '1',
1824
  `batch_id` int(10) NOT NULL DEFAULT '1',
1825
  `description` mediumtext DEFAULT NULL,
1825
  `item_number` int(11) DEFAULT NULL,
1826
  `item_number` int(11) DEFAULT NULL,
1826
  `borrower_number` int(11) DEFAULT NULL,
1827
  `borrower_number` int(11) DEFAULT NULL,
1827
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1828
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt (-2 / +32 lines)
Lines 125-131 Link Here
125
                return (-1);
125
                return (-1);
126
            };
126
            };
127
127
128
         $(document).ready(function() {
128
        $(document).ready(function() {
129
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
129
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
130
                "autoWidth": false,
130
                "autoWidth": false,
131
                "aoColumnDefs": [
131
                "aoColumnDefs": [
Lines 168-174 Link Here
168
                var batch_id = $(this).data("batch-id");
168
                var batch_id = $(this).data("batch-id");
169
                GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
169
                GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
170
            });
170
            });
171
         });
171
            $("#savedesc").click(function(event){
172
                event.preventDefault(); // prevent form submission
173
                var newdescription = $(this).siblings('input[name="description"]').val();
174
                var batch_id = $(this).data('batch_id');
175
                var ajaxData = {
176
                    'newdescription': newdescription,
177
                    'batch_id': batch_id,
178
                    'card_element': "batch",
179
                    'creator': "label",
180
                };
181
182
                $.ajax({
183
                    url: '/cgi-bin/koha/svc/creator_batches',
184
                    type: 'POST',
185
                    dataType: 'json',
186
                    data: ajaxData,
187
                })
188
189
                .done(function(data){
190
                    if (data.status == 'success') {
191
                        $("input[name='description']").text(data.newdesc);
192
                        $("#change-status").text(_("Saved"));
193
                    } else {
194
                        $("#change-status").text(_("Unable to save description"));
195
                    }
196
                });
197
            });
198
        });
172
    //]]>
199
    //]]>
173
    </script>
200
    </script>
174
</head>
201
</head>
Lines 225-230 Link Here
225
                                    <ol><li>
252
                                    <ol><li>
226
                                        <input type="hidden" name="op" value="add" />
253
                                        <input type="hidden" name="op" value="add" />
227
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
254
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
255
                                        <label for="description">Batch description: </label>
256
                                        <input type="text" name="description" value="[% description %]">
257
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id %]">Save description</a> <span id="change-status"></span>
228
                                    </li>
258
                                    </li>
229
                                    <li>
259
                                    <li>
230
                                        <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
260
                                        <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt (-6 / +192 lines)
Lines 4-9 Link Here
4
    <title>Koha &rsaquo; Tools &rsaquo; Patron card creator &rsaquo; Batches &rsaquo; [% IF batch_id %]Edit ([% batch_id %])[% ELSE %]New[% END %]</title>
4
    <title>Koha &rsaquo; Tools &rsaquo; Patron card creator &rsaquo; Batches &rsaquo; [% IF batch_id %]Edit ([% batch_id %])[% ELSE %]New[% END %]</title>
5
    [% INCLUDE 'doc-head-close.inc' %]
5
    [% INCLUDE 'doc-head-close.inc' %]
6
    [% Asset.css("css/datatables.css") %]
6
    [% Asset.css("css/datatables.css") %]
7
    [% INCLUDE 'greybox.inc' %]
8
    <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
9
    [% INCLUDE 'datatables.inc' %]
10
    <script type="text/javascript">
11
        //<![CDATA[
12
           function DeleteConfirm() {
13
                var msg = _("Are you sure you want to delete batch %s?").format("[% batch_id %]");
14
                var answer = confirm(msg);
15
                if (answer) {
16
                    window.location = "/cgi-bin/koha/patroncards/manage.pl?op=delete&amp;card_element=batch&amp;element_id=[% batch_id %]";
17
                }
18
                else {
19
                    return; // abort delete
20
                }
21
            };
22
            function Remove() {
23
                items = new Array;
24
25
                if(document.items.action.length > 0) {
26
                    for (var i=0; i < document.items.action.length; i++) {
27
                        if (document.items.action[i].checked) {
28
                            items.push("label_id=" +  document.items.action[i].value);
29
                        }
30
                    }
31
                    getstr = items.join("&");
32
                    var msg = _("Are you sure you want to remove the selected patron(s) from this batch?");
33
                } else if (document.items.action.checked) {
34
                    alert(_("Deletion of patron from a batch with only one patron will delete the batch.") + "\n\n" + _("If this is what you want, select the 'Delete batch' option from the toolbar"));
35
                    return; // no deletion for single item batch
36
                }
37
                else {
38
                    alert(_("Please select at least one patron to delete."));
39
                    return;     // no item selected
40
                }
41
                var answer = confirm(msg);
42
                if (answer) {
43
                    window.location = "/cgi-bin/koha/patroncards/edit-batch.pl?op=remove&amp;batch_id=[% batch_id %]&amp;" + getstr;
44
                }
45
                else {
46
                    return; // abort delete
47
                }
48
            };
49
            function Add() {
50
                var bor_nums = document.getElementById("bor_num_list");
51
                if (bor_nums.value == '') {
52
                    window.open("/cgi-bin/koha/patroncards/add_user_search.pl",
53
                   'PatronPopup',
54
                   'width=840,height=500,location=yes,toolbar=no,'
55
                   + 'scrollbars=yes,resize=yes');
56
                }
57
                else {
58
                    document.forms["add_by_bor_num"].submit();
59
                }
60
            };
61
62
            function add_user(borrowernumber) {
63
                $("#bor_num_list").val($("#bor_num_list").val()+borrowernumber+"\r\n");
64
            }
65
66
            function DeDuplicate() {
67
                window.location = "/cgi-bin/koha/patroncards/edit-batch.pl?op=de_duplicate&amp;batch_id=[% batch_id %]";
68
            };
69
            function Xport(mode) {
70
                if (mode == 'label') {
71
                    patroncards= new Array;
72
                    if(document.items.action.length > 0) {
73
                        for (var i=0; i < document.items.action.length; i++) {
74
                            if (document.items.action[i].checked) {
75
                                patroncards.push("label_id=" +  document.items.action[i].value);
76
                            }
77
                        }
78
                        if (patroncards.length < 1) {
79
                            alert(_("Please select at least one card to export."));
80
                            return;     // no batch selected
81
                        }
82
                        getstr = patroncards.join("&");
83
                    }
84
                    else if (document.items.action.checked) {
85
                        getstr = document.items.action.value;
86
                    }
87
                    else {
88
                        alert(_("Please select at least one card to export."));
89
                        return;     // no batch selected
90
                    }
91
                    return GB_showCenter(_("Export patron cards"), "/cgi-bin/koha/patroncards/print.pl?batch_id=[% batch_id %]&" + getstr, 400, 800);
92
                }
93
                else if (mode == 'batch') {
94
                    return GB_showCenter(_("Export patron cards"), "/cgi-bin/koha/patroncards/print.pl?batch_id=[% batch_id %]", 400, 800);
95
                }
96
                else {
97
                    // some pass-thru error trapping just in case...
98
                }
99
            };
100
            function selected_layout() {
101
                if (document.items.action.length) {
102
                for (i=0;i<document.items.action.length;i++){
103
                    if (document.items.action[i].checked==true){
104
                        return(document.items.action[i].value);
105
                    }
106
                };
107
                }
108
                else {
109
                    if (document.items.action.checked){
110
                        return(document.items.action.value);
111
                    }
112
                };
113
                alert(_("Please select at least one item."));
114
                return (-1);
115
            };
116
117
            $(document).ready(function() {
118
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
119
                "aoColumnDefs": [
120
                    { "aTargets": [ -2, -1 ], "bSortable": false, "bSearchable": false }
121
                ],
122
                "aaSorting": [[ 0, "asc" ]],
123
                "sPaginationType": "four_button",
124
                "autoWidth": false
125
            }));
126
            $("#additems").click(function(){
127
                Add();
128
                return false;
129
            });
130
            $("#removeitems").click(function(){
131
                Remove();
132
                return false;
133
            });
134
            $("#deletebatch").click(function(){
135
                DeleteConfirm();
136
                return false;
137
            });
138
            $("#deduplicate").click(function(){
139
                DeDuplicate();
140
                return false;
141
            });
142
            $("#exportitems").click(function(){
143
                Xport('label');
144
                return false;
145
            });
146
            $("#exportbatch").click(function(){
147
                Xport('batch');
148
                return false;
149
            });
150
            $(".delete").on("click", function(){
151
                return confirmDelete( _("Are you sure you want to delete this patron from the card batch?") );
152
            });
153
            $(".export").on("click", function(e){
154
                e.preventDefault();
155
                var label_id = $(this).data("label-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);
158
            });
159
            $("#savedesc").click(function(event){
160
                var newdescription = $(this).siblings('input[name="description"]').val();
161
                var batch_id = $(this).data('batch_id');
162
                var ajaxData = {
163
                    'newdescription': newdescription,
164
                    'batch_id': batch_id,
165
                    'card_element': "batch",
166
                    'creator': "patroncard",
167
                };
168
169
                $.ajax({
170
                    url: '/cgi-bin/koha/svc/creator_batches',
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
            });
185
            });
186
        //]]>
187
    </script>
188
>>>>>>> Bug 15766: Adding descriptions to patron card batches
7
</head>
189
</head>
8
190
9
<body id="pcard_edit-batch" class="tools pcard">
191
<body id="pcard_edit-batch" class="tools pcard">
Lines 44-55 Link Here
44
                                <div>
226
                                <div>
45
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
227
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
46
                                    <ol><li>
228
                                    <ol><li>
47
                                    <input type="hidden" name="op" value="add" />
229
                                        <input type="hidden" name="op" value="add" />
48
                                    <input type="hidden" name="batch_id" value="[% batch_id %]" />
230
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
49
                                    <label for="bor_num_list">Add by borrowernumber(s):
231
                                        <label for="description">Batch description: </label>
50
                                        <br /> <span class="hint">One borrowernumber per line.</span>
232
                                        <input type="text" name="description" value="[% description %]">
51
                                    </label>
233
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id %]">Save description</a> <span id="change-status"></span>
52
                                    <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
234
                                    </li><li>
235
                                        <label for="bor_num_list">Add by borrowernumber(s):
236
                                            <br /> <span class="hint">One borrowernumber per line.</span>
237
                                        </label>
238
                                        <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
53
                                    </li></ol>
239
                                    </li></ol>
54
                                    </fieldset>
240
                                    </fieldset>
55
                                </div>
241
                                </div>
(-)a/labels/label-edit-batch.pl (+3 lines)
Lines 61-66 my @item_numbers; Link Here
61
my $number_list;
61
my $number_list;
62
my $number_type = $cgi->param('number_type') || "barcode";
62
my $number_type = $cgi->param('number_type') || "barcode";
63
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
63
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
64
my $description = $cgi->param('description') || '';
64
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
65
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
65
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
66
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
66
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
67
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
Lines 98-103 elsif ($op eq 'add') { Link Here
98
    }
99
    }
99
    if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);}
100
    if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);}
100
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);}
101
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);}
102
    $template->param( description => $batch->{description} );
101
    if ($branch_code){
103
    if ($branch_code){
102
        foreach my $item_number (@item_numbers) {
104
        foreach my $item_number (@item_numbers) {
103
            $err = $batch->add_item($item_number);
105
            $err = $batch->add_item($item_number);
Lines 122-127 elsif ($op eq 'de_duplicate') { Link Here
122
}
124
}
123
else { # edit
125
else { # edit
124
    $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
126
    $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
127
    $template->param( description => $batch->{description} );
125
}
128
}
126
129
127
my $items = $batch->get_attr('items');
130
my $items = $batch->get_attr('items');
(-)a/labels/label-manage.pl (+1 lines)
Lines 66-71 my $display_columns = { layout => [ # db column => {col label Link Here
66
                                    ],
66
                                    ],
67
                        batch =>    [
67
                        batch =>    [
68
                                        {batch_id        => {label => 'Batch ID',       link_field      => 0}},
68
                                        {batch_id        => {label => 'Batch ID',       link_field      => 0}},
69
                                        {description     => {label => 'Description',    link_field      => 0}},
69
                                        {_item_count     => {label => 'Item Count',     link_field      => 0}},
70
                                        {_item_count     => {label => 'Item Count',     link_field      => 0}},
70
                                        {select          => {label => 'Actions',         value           => 'batch_id'}},
71
                                        {select          => {label => 'Actions',         value           => 'batch_id'}},
71
                                        {select1         => {label => ' ',           link_field       => 'batch_id'}},
72
                                        {select1         => {label => ' ',           link_field       => 'batch_id'}},
(-)a/patroncards/edit-batch.pl (+3 lines)
Lines 55-60 my $display_columns = [ {_summary => {label => 'Summary', link_field => 0} Link Here
55
                      ];
55
                      ];
56
my $op = $cgi->param('op') || 'new';
56
my $op = $cgi->param('op') || 'new';
57
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
57
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
58
my $description = $cgi->param('description') || '';
58
my ( @label_ids, @item_numbers, @borrower_numbers );
59
my ( @label_ids, @item_numbers, @borrower_numbers );
59
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
60
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
60
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
61
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
Lines 93-98 if ($bor_num_list) { Link Here
93
    }
94
    }
94
    if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
95
    if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
95
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
96
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
97
    $template->param( description => $batch->{'description'} );
96
    if ($branch_code){
98
    if ($branch_code){
97
        foreach my $borrower_number (@borrower_numbers) {
99
        foreach my $borrower_number (@borrower_numbers) {
98
            $err = $batch->add_item($borrower_number);
100
            $err = $batch->add_item($borrower_number);
Lines 119-124 elsif ($op eq 'de_duplicate') { Link Here
119
}
121
}
120
elsif ($op eq 'edit') {
122
elsif ($op eq 'edit') {
121
    $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
123
    $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
124
    $template->param( description => $batch->{'description'} );
122
}
125
}
123
elsif ($op eq 'new') {
126
elsif ($op eq 'new') {
124
    if ($branch_code eq '') {
127
    if ($branch_code eq '') {
(-)a/patroncards/manage.pl (+1 lines)
Lines 69-74 my $display_columns = { layout => [ # db column => {col label Link Here
69
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
69
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
70
                                    ],
70
                                    ],
71
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
71
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
72
                                        {description     => {label => 'Description',    link_field      => 0}},
72
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
73
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
73
                                        {_action         => {label => 'Actions',        link_field      => 0}},
74
                                        {_action         => {label => 'Actions',        link_field      => 0}},
74
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
75
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
(-)a/svc/creator_batches (-1 / +73 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( encode_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 C4::Labels::Batch;
30
31
=head1 NAME
32
33
svc/creator_batches - Web service for managing AJAX functionality for patroncards and label batches
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
47
if ($is_ajax) {
48
    my $batch_id = $cgi->param('batch_id');
49
    my $description = $cgi->param('newdescription');
50
    my $status = '';
51
    my $dbh = C4::Context->dbh;
52
    my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
53
    my $sth = $dbh->prepare($query);
54
    $sth->execute($description, $batch_id);
55
56
    # Check for success
57
    my $creator = $cgi->param('creator');
58
    if ( $creator eq 'patroncard' ) {
59
        my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
60
        if ( $batch->{description} eq $description ) {
61
            $status = 'success';
62
        }
63
    } elsif ( $creator eq 'label' ) {
64
        my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
65
        if ( $batch->{description} eq $description ) {
66
            $status = 'success';
67
        }
68
    }
69
70
    my $json = encode_json ( { status => $status, newdesc => $description } );
71
    output_with_http_headers $cgi, undef, $json, 'js';
72
    exit;
73
}

Return to bug 15766