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

(-)a/C4/Biblio.pm (-6 / +22 lines)
Lines 3240-3245 sub _koha_delete_biblio_metadata { Link Here
3240
3240
3241
=head1 UNEXPORTED FUNCTIONS
3241
=head1 UNEXPORTED FUNCTIONS
3242
3242
3243
=head2 Update005Time
3244
3245
  &Update005Time( $record );
3246
3247
Updates the 005 timestamp of the given record to the current time.
3248
3249
=cut
3250
3251
sub UpdateMarcTimestamp {
3252
    my ( $record ) = @_;
3253
3254
    my $encoding = C4::Context->preference("marcflavour");
3255
3256
    if ( $encoding =~ /MARC21|UNIMARC/ ) {
3257
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3258
        # YY MM DD HH MM SS (update year and month)
3259
        my $f005 = $record->field('005');
3260
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) ) if $f005;
3261
    }
3262
}
3263
3243
=head2 ModBiblioMarc
3264
=head2 ModBiblioMarc
3244
3265
3245
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3266
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
Lines 3292-3303 sub ModBiblioMarc { Link Here
3292
    }
3313
    }
3293
3314
3294
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3315
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3295
    if($encoding =~ /MARC21|UNIMARC/) {
3316
    UpdateMarcTimestamp( $record );
3296
      my @a= (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3297
        # YY MM DD HH MM SS (update year and month)
3298
      my $f005= $record->field('005');
3299
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
3300
    }
3301
3317
3302
    my $metadata = {
3318
    my $metadata = {
3303
        biblionumber => $biblionumber,
3319
        biblionumber => $biblionumber,
(-)a/C4/ImportBatch.pm (-5 / +13 lines)
Lines 28-33 use C4::Charset; Link Here
28
use C4::AuthoritiesMarc;
28
use C4::AuthoritiesMarc;
29
use C4::MarcModificationTemplates;
29
use C4::MarcModificationTemplates;
30
use Koha::Items;
30
use Koha::Items;
31
use DateTime;
32
use DateTime::Format::Strptime;
31
use Koha::Plugins::Handler;
33
use Koha::Plugins::Handler;
32
use Koha::Logger;
34
use Koha::Logger;
33
35
Lines 1609-1618 sub _create_import_record { Link Here
1609
sub _update_import_record_marc {
1611
sub _update_import_record_marc {
1610
    my ($import_record_id, $marc_record, $marc_type) = @_;
1612
    my ($import_record_id, $marc_record, $marc_type) = @_;
1611
1613
1614
    my $upload_timestamp = _get_import_record_timestamp($marc_record);
1615
1612
    my $dbh = C4::Context->dbh;
1616
    my $dbh = C4::Context->dbh;
1613
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
1617
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?, upload_timestamp = ?
1614
                             WHERE  import_record_id = ?");
1618
                             WHERE  import_record_id = ?");
1615
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $import_record_id);
1619
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $upload_timestamp, $import_record_id);
1616
    $sth->finish();
1620
    $sth->finish();
1617
}
1621
}
1618
1622
Lines 1633-1644 sub _add_auth_fields { Link Here
1633
sub _add_biblio_fields {
1637
sub _add_biblio_fields {
1634
    my ($import_record_id, $marc_record) = @_;
1638
    my ($import_record_id, $marc_record) = @_;
1635
1639
1640
    my $controlnumber;
1641
    if ($marc_record->field('001')) {
1642
        $controlnumber = $marc_record->field('001')->data();
1643
    }
1636
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1644
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1637
    my $dbh = C4::Context->dbh;
1645
    my $dbh = C4::Context->dbh;
1638
    # FIXME no controlnumber, originalsource
1646
    # FIXME no originalsource
1639
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1647
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1640
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
1648
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn, control_number) VALUES (?, ?, ?, ?, ?, ?)");
1641
    $sth->execute($import_record_id, $title, $author, $isbn, $issn);
1649
    $sth->execute($import_record_id, $title, $author, $isbn, $issn, $controlnumber);
1642
    $sth->finish();
1650
    $sth->finish();
1643
                
1651
                
1644
}
1652
}
(-)a/cataloguing/editor.pl (-1 / +1 lines)
Lines 49-55 my $schema = Koha::Database->new->schema; Link Here
49
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
49
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
50
    {
50
    {
51
        batch_type => [ 'batch', 'webservice' ],
51
        batch_type => [ 'batch', 'webservice' ],
52
        import_status => 'staged',
52
        import_status => [ 'staged', 'staging' ],
53
    },
53
    },
54
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
54
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
55
) ];
55
) ];
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js (+52 lines)
Lines 130-135 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
130
            } );
130
            } );
131
        },
131
        },
132
132
133
        GetBatchRecord: function( batch_id, id, callback ) {
134
            $.get(
135
                '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id
136
            ).done( function( data ) {
137
                var record = new MARC.Record();
138
                record.loadMARCXML( data.record );
139
                callback(record);
140
            } ).fail( function( data ) {
141
                callback( { error: data } );
142
            } );
143
        },
144
145
        CreateBatch: function( batch_name, callback ) {
146
            $.ajax( {
147
                type: 'POST',
148
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/',
149
                data: { batch_name: batch_name },
150
            } ).done( function( data ) {
151
                callback( data );
152
            } ).fail( function( data ) {
153
                callback( { error: data } );
154
            } );
155
        },
156
157
        CreateBatchRecord: function( record, batch_id, callback, options ) {
158
            $.ajax( {
159
                type: 'POST',
160
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/',
161
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
162
            } ).done( function( data ) {
163
                callback( data );
164
            } ).fail( function( data ) {
165
                callback( { error: $.parseJSON( data.responseText ) || data.responseText } );
166
            } );
167
        },
168
169
        SaveBatchRecord: function( batch_id, id, record, callback, options ) {
170
            $.ajax( {
171
                type: 'POST',
172
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id,
173
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
174
            } ).done( function( data ) {
175
                callback( data );
176
            } ).fail( function( data ) {
177
                callback( { data: { error: data } } );
178
            } );
179
        },
180
181
        StartBatchExport: function( batch_id, options ) {
182
            window.open( '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '?download=1&' + $.param( options ) );
183
        },
184
133
        GetTagsBy: function( frameworkcode, field, value ) {
185
        GetTagsBy: function( frameworkcode, field, value ) {
134
            var result = {};
186
            var result = {};
135
187
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/preferences.js (+2 lines)
Lines 29-38 define( function() { Link Here
29
29
30
            Preferences.user = $.extend( {
30
            Preferences.user = $.extend( {
31
                // Preference defaults
31
                // Preference defaults
32
                enabledBatches: {},
32
                fieldWidgets: true,
33
                fieldWidgets: true,
33
                font: 'monospace',
34
                font: 'monospace',
34
                fontSize: '1em',
35
                fontSize: '1em',
35
                macros: {},
36
                macros: {},
37
                selected_save_targets: {},
36
                selected_search_targets: {},
38
                selected_search_targets: {},
37
            }, saved_prefs );
39
            }, saved_prefs );
38
        },
40
        },
(-)a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css (-1 / +43 lines)
Lines 59-64 body { Link Here
59
    font-size: 12px;
59
    font-size: 12px;
60
}
60
}
61
61
62
#save-targets input {
63
    display: inline-block;
64
    margin: 1px;
65
    vertical-align: middle;
66
}
67
68
#save-targets input:checked + label {
69
    color: #000;
70
}
71
72
#save-targets label {
73
    color: #666;
74
    display: inline-block;
75
    margin-left: 0.3em;
76
    padding: 0.3em 0;
77
    vertical-align: middle;
78
    width: 10em;
79
}
80
81
#save-targets li {
82
    overflow: hidden;
83
}
84
85
#shortcuts-container {
86
    font-size: 12px;
87
}
88
62
/*> MARC editor */
89
/*> MARC editor */
63
#editor .CodeMirror {
90
#editor .CodeMirror {
64
    line-height: 1.2;
91
    line-height: 1.2;
Lines 205-211 body { Link Here
205
232
206
/*> Search */
233
/*> Search */
207
234
208
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg {
235
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg .ui-modal {
236
    padding: 5px;
209
    width: 90%;
237
    width: 90%;
210
}
238
}
211
239
Lines 446-448 body { Link Here
446
.CodeMirror-gutter-wrapper {
474
.CodeMirror-gutter-wrapper {
447
    position: absolute;
475
    position: absolute;
448
}
476
}
477
478
/* >Batches */
479
#batches-list > li {
480
    border: 2px solid #F0F0F0;
481
    border-radius: 6px;
482
    display: block;
483
    line-height: 3em;
484
    font-size: 115%;
485
}
486
487
#batches-list > li input {
488
    display: inline-block;
489
    margin: 0 1em;
490
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-34 / +316 lines)
Lines 38-43 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
38
            recordtype: 'biblio',
38
            recordtype: 'biblio',
39
            checked: false,
39
            checked: false,
40
        },
40
        },
41
        [%- FOREACH batch = editable_batches -%]
42
            'batch:[% batch.import_batch_id %]': {
43
                name: _("Batch: ") + '[% batch.file_name %]',
44
                recordtype: 'biblio',
45
                checked: false,
46
            },
47
        [%- END -%]
41
        [%- FOREACH server = z3950_servers -%]
48
        [%- FOREACH server = z3950_servers -%]
42
            [% server.id | html %]: {
49
            [% server.id | html %]: {
43
                name: '[% server.servername | html %]',
50
                name: '[% server.servername | html %]',
Lines 63-70 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
63
70
64
    var state = {
71
    var state = {
65
        backend: '',
72
        backend: '',
66
        saveBackend: 'catalog',
73
        recordID: undefined,
67
        recordID: undefined
74
        saveTargets: {},
68
    };
75
    };
69
76
70
    var editor;
77
    var editor;
Lines 228-243 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
228
            },
235
            },
229
        },
236
        },
230
        'catalog': {
237
        'catalog': {
231
            titleForRecord: _("Editing catalog record #{ID}"),
238
            titleForRecord: _("Editing catalog record #%s"),
232
            links: [
239
            links: [
233
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber={ID}" },
240
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=%s" },
234
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber={ID}" },
241
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=%s" },
235
            ],
242
            ],
236
            saveLabel: _("Save to catalog"),
243
            saveLabel: _("New catalog record"),
244
            saveExistingLabel: _("Catalog record #%s"),
237
            get: function( id, callback ) {
245
            get: function( id, callback ) {
238
                if ( !id ) return false;
246
                if ( !id ) return false;
239
247
240
                KohaBackend.GetRecord( id, callback );
248
                KohaBackend.GetRecord( id, function( data ) {
249
                    if ( !data.error ) {
250
                        setSaveTargetChecked( 'catalog/', false );
251
                        addSaveTarget( {
252
                            label: backends.catalog.saveExistingLabel.format( id ),
253
                            id: 'catalog/' + id,
254
                            description: '',
255
                            checked: true
256
                        } );
257
                    }
258
259
                    callback(data);
260
                } );
241
            },
261
            },
242
            save: function( id, record, done ) {
262
            save: function( id, record, done ) {
243
                function finishCb( data ) {
263
                function finishCb( data ) {
Lines 252-258 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
252
            }
272
            }
253
        },
273
        },
254
        'iso2709': {
274
        'iso2709': {
255
            saveLabel: _("Save as ISO2709 (.mrc) file"),
275
            saveLabel: _("New ISO2709 (.mrc) file"),
256
            save: function( id, record, done ) {
276
            save: function( id, record, done ) {
257
                saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.mrc' );
277
                saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.mrc' );
258
278
Lines 260-266 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
260
            }
280
            }
261
        },
281
        },
262
        'marcxml': {
282
        'marcxml': {
263
            saveLabel: _("Save as MARCXML (.xml) file"),
283
            saveLabel: _("New MARCXML (.xml) file"),
264
            save: function( id, record, done ) {
284
            save: function( id, record, done ) {
265
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
285
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
266
286
Lines 282-287 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
282
        },
302
        },
283
    };
303
    };
284
304
305
    var editable_batches = {
306
        [%- FOREACH batch = editable_batches -%]
307
            [% batch.import_batch_id %]: {
308
                'name': '[% batch.file_name %]',
309
            },
310
        [%- END -%]
311
    };
312
313
    function addSaveTarget( target ) {
314
        state.saveTargets[target.id] = target;
315
        if (target.enabled == null) target.enabled = true;
316
317
        // Have to check that Preferences has been initialized
318
        var saved_value = Preferences.user && Preferences.user.selected_save_targets[target.id];
319
        if ( saved_value != null ) target.checked = saved_value;
320
321
        var target_list = $.map( state.saveTargets, function( target ) {
322
            return target;
323
        } );
324
325
        target_list.sort( function( a, b ) {
326
            return a.label.localeCompare(b.label);
327
        } );
328
329
        $('#save-targets ol').empty();
330
331
        $.each( target_list, function( i, target ) {
332
            var $new_target = $(
333
                '<li><input type="checkbox" class="save-toggle-target" data-target-id="' + target.id + '" id="save-target-' + i + '"' + ( target.checked ? ' checked="checked"' : '' ) + '> <label for="save-target-' + i + '">' + target.label + '</label></li>'
334
            );
335
336
            $new_target.find('input').change( function() {
337
                target.checked = this.checked;
338
            } );
339
340
            $('#save-targets ol').append($new_target);
341
342
            if (!target.enabled) $new_target.hide();
343
        } );
344
    }
345
346
    function setSaveTargetChecked( target_id, checked ) {
347
        if ( state.saveTargets[target_id] == null ) return;
348
349
        state.saveTargets[target_id].checked = checked;
350
        $( '#save-targets input[data-target-id="' + target_id + '"]' )[0].checked = checked;
351
    }
352
353
    function setSaveTargetEnabled( target_id, enabled ) {
354
        if ( !enabled ) {
355
            setSaveTargetChecked( target_id, false );
356
        }
357
358
        state.saveTargets[target_id].enabled = enabled;
359
        $( '#save-targets input[data-target-id="' + target_id + '"]' ).closest('li').toggle(enabled);
360
    }
361
285
    function setSource(parts) {
362
    function setSource(parts) {
286
        state.backend = parts[0];
363
        state.backend = parts[0];
287
        state.recordID = parts[1];
364
        state.recordID = parts[1];
Lines 292-304 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
292
369
293
        document.location.hash = '#' + parts[0] + '/' + parts[1];
370
        document.location.hash = '#' + parts[0] + '/' + parts[1];
294
371
295
        $('#title').text( backend.titleForRecord.replace( '{ID}', parts[1] ) );
372
        $('#title').text( backend.titleForRecord.format( parts[1] ) );
296
373
297
        $.each( backend.links || [], function( i, link ) {
374
        $.each( backend.links || [], function( i, link ) {
298
            $('#title').append(' <a target="_blank" href="' + link.href.replace( '{ID}', parts[1] ) + '">(' + link.title + ')</a>' );
375
            $('#title').append(' <a target="_blank" href="' + link.href.format( parts[1] ) + '">(' + link.title + ')</a>' );
299
        } );
376
        } );
300
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.replace( '{ID}', parts[1] ) );
377
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.format( parts[1] ) );
301
        $('#save-record span').text( backends[ state.saveBackend ].saveLabel );
302
    }
378
    }
303
379
304
    function saveRecord( recid, editor, callback ) {
380
    function saveRecord( recid, editor, callback ) {
Lines 334-339 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
334
410
335
            if (data.newId) {
411
            if (data.newId) {
336
                setSource(data.newId);
412
                setSource(data.newId);
413
414
                var backend = backends[ parts[0] ];
415
416
                setSaveTargetChecked( recid, false );
417
                addSaveTarget( {
418
                    label: backend.saveExistingLabel.format( data.newId[1] ),
419
                    id: data.newId.join('/'),
420
                    description: '',
421
                    checked: true
422
                } );
337
            } else {
423
            } else {
338
                setSource( [ state.backend, state.recordID ] );
424
                setSource( [ state.backend, state.recordID ] );
339
            }
425
            }
Lines 592-597 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
592
        var value = Preferences.user[pref];
678
        var value = Preferences.user[pref];
593
679
594
        switch (pref) {
680
        switch (pref) {
681
            case 'enabledBatches':
682
                $.each( editable_batches, function( batch_id, batch ) {
683
                    $( '#batches-list li[data-batch-id=' + batch_id + '] input' )[0].checked = Preferences.user.enabledBatches[batch_id];
684
                    setSaveTargetEnabled( 'batch:' + batch_id + '/', Preferences.user.enabledBatches[batch_id] || false );
685
                } );
595
            case 'fieldWidgets':
686
            case 'fieldWidgets':
596
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
687
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
597
                break;
688
                break;
Lines 613-618 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
613
                    if ( saved_val != null ) server.checked = saved_val;
704
                    if ( saved_val != null ) server.checked = saved_val;
614
                } );
705
                } );
615
                break;
706
                break;
707
            case 'selected_save_targets':
708
                $.each( state.saveTargets, function( target_id, target ) {
709
                    var saved_val = Preferences.user.selected_save_targets[target_id];
710
711
                    if ( saved_val != null ) setSaveTargetChecked( target_id, saved_val );
712
                } );
713
                break;
714
            case 'selected_search_targets':
715
                $.each( z3950Servers, function( server_id, server ) {
716
                    var saved_val = Preferences.user.selected_search_targets[server_id];
717
718
                    if ( saved_val != null ) server.checked = saved_val;
719
                } );
720
                break;
616
        }
721
        }
617
    }
722
    }
618
723
Lines 626-632 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
626
            } );
731
            } );
627
        }
732
        }
628
733
734
        function _addLiveHandler( sel, event, handler ) {
735
            $( document ).on( event, sel, function (e) {
736
                e.preventDefault();
737
                handler.call( this, e, Preferences.user[pref] );
738
                Preferences.Save( [% USER_INFO.borrowernumber %] );
739
                showPreference(pref);
740
            } );
741
        }
742
629
        switch (pref) {
743
        switch (pref) {
744
            case 'enabledBatches':
745
                _addLiveHandler( '#batches-list input', 'change', function() {
746
                    Preferences.user.enabledBatches[ $( this ).closest('li').data('batch-id') ] = this.checked;
747
                } );
748
                break;
630
            case 'fieldWidgets':
749
            case 'fieldWidgets':
631
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
750
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
632
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
751
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
Lines 642-647 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
642
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
761
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
643
                } );
762
                } );
644
                break;
763
                break;
764
            case 'selected_save_targets':
765
                $( document ).on( 'change', 'input.save-toggle-target', function() {
766
                    var target_id = $( this ).data('target-id');
767
                    Preferences.user.selected_save_targets[target_id] = this.checked;
768
                    Preferences.Save( [% USER_INFO.borrowernumber %] );
769
                } );
770
                break;
645
            case 'selected_search_targets':
771
            case 'selected_search_targets':
646
                $( document ).on( 'change', 'input.search-toggle-server', function() {
772
                $( document ).on( 'change', 'input.search-toggle-server', function() {
647
                    var server_id = $( this ).closest('li').data('server-id');
773
                    var server_id = $( this ).closest('li').data('server-id');
Lines 735-740 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
735
        showSavedMacros();
861
        showSavedMacros();
736
    }
862
    }
737
863
864
    function addImportBatch(batch) {
865
        var backend_id = 'batch:' + batch.batch_id;
866
        backends[backend_id] = {
867
            titleForRecord: _("Editing record from batch: ") + batch.name,
868
            saveLabel: _("Batch: ") + batch.name,
869
            saveExistingLabel: batch.name + ": #%s",
870
            get: function( id, callback ) {
871
                KohaBackend.GetBatchRecord( batch.batch_id, id, function( data ) {
872
                    if ( !data.error ) {
873
                        setSaveTargetChecked( backend_id + '/', false );
874
                        addSaveTarget( {
875
                            label: batch.name + ": #" + id,
876
                            id: backend_id + '/' + id,
877
                            description: '',
878
                            checked: true
879
                        } );
880
                    }
881
882
                    callback(data);
883
                } );
884
            },
885
            save: function( id, record, done, options ) {
886
                function finishCb( data ) {
887
                    done( {
888
                        error: data.message || data.error,
889
                        newRecord: data.updated_record,
890
                        newId: data.import_record_id && [ backend_id, data.import_record_id ]
891
                    } );
892
                }
893
894
                if ( id ) {
895
                    KohaBackend.SaveBatchRecord( batch.batch_id, id, record, finishCb, { allow_control_number_conflict: options.override_warnings } );
896
                } else {
897
                    KohaBackend.CreateBatchRecord( record, batch.batch_id, finishCb, { allow_control_number_conflict: options.override_warnings } );
898
                }
899
            },
900
        };
901
902
        // Build batch UI
903
        var $batch_entry = $( '<li data-batch-id="' + batch.batch_id + '"><input type="checkbox" />' + batch.name + '</li>' );
904
905
        var $batch_buttons = $('<span class="batch-buttons"></span>').appendTo($batch_entry);
906
        var $export_button = $( '<button>' + _("Export...") + '</button>' ).appendTo($batch_buttons).click( function() {
907
            $('#batches-list .batch-export').hide();
908
            $export_screen.show();
909
        } );
910
911
        var $export_screen = $(
912
            '<form class="batch-export form-horizontal" style="display: none">'
913
            + '<div class="control-group">'
914
            + '<label class="control-label">' + _("Control number range:") + '</label>'
915
            + '<div class="controls"><input class="batch-control-number-start" type="text"> - <input class="batch-control-number-end" type="text"></div>'
916
            + '</div>'
917
            + '<label class="control-label">' + _("Timestamp range (YYYYMMDD or YYYMMDDHHMMSS):") + '</label>'
918
            + '<div class="controls"><input class="batch-timestamp-start" type="text"> - <input class="batch-timestamp-end" type="text"></div>'
919
            + '</div>'
920
            + '<div class="control-group">'
921
            + '<div class="controls"><button class="batch-export-start">' + _("Start export") + '</div>'
922
            + '</form>'
923
        ).appendTo($batch_entry);
924
925
        $export_screen.find('.batch-export-start').click( function() {
926
            function getFormVal(name) {
927
                return $export_screen.find( '.batch-' + name ).val();
928
            }
929
930
            var options = {
931
                start_control_number: getFormVal('control-number-start'),
932
                end_control_number: getFormVal('control-number-end'),
933
                start_timestamp: getFormVal('timestamp-start'),
934
                end_timestamp: getFormVal('timestamp-end'),
935
            };
936
937
            KohaBackend.StartBatchExport( batch.batch_id, options );
938
        } );
939
940
        $('#batches-list').append( $batch_entry );
941
    }
942
738
    $(document).ready( function() {
943
    $(document).ready( function() {
739
        // Editor setup
944
        // Editor setup
740
        editor = new MARCEditor( {
945
        editor = new MARCEditor( {
Lines 784-789 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
784
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
989
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
785
                } );
990
                } );
786
            }, 100);
991
            }, 100);
992
787
        }
993
        }
788
994
789
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
995
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
Lines 824-832 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
824
        $.each( backends, function( id, backend ) {
1030
        $.each( backends, function( id, backend ) {
825
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
1031
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
826
        } );
1032
        } );
827
        saveableBackends.sort();
1033
828
        $.each( saveableBackends, function( undef, backend ) {
1034
        var batch_list = [];
829
            $( '#save-dropdown' ).append( '<li><a href="#" data-backend="' + backend[1] + '">' + backend[0] + '</a></li>' );
1035
1036
        $.each( editable_batches, function( batch_id, batch ) {
1037
            batch_list.push( $.extend( { batch_id: batch_id }, batch ) );
1038
        } );
1039
        batch_list.sort( function( a, b ) {
1040
            return a.name.localeCompare(b.name);
1041
        } );
1042
        $.each( batch_list, function() {
1043
            addImportBatch( this );
830
        } );
1044
        } );
831
1045
832
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
1046
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
Lines 841-855 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
841
1055
842
        // Click bindings
1056
        // Click bindings
843
        $( '#save-record, #save-dropdown a' ).click( function() {
1057
        $( '#save-record, #save-dropdown a' ).click( function() {
844
            $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner' ).siblings( 'span' ).text( _("Saving...") );
1058
            var enabledTargets = [];
1059
            var targetNames = [];
1060
            $.each( state.saveTargets, function() {
1061
                if ( this.checked ) {
1062
                    enabledTargets.push(this);
1063
                    targetNames.push(this.label);
1064
                }
1065
            } );
1066
            if ( enabledTargets.length == 0 ) {
1067
                humanMsg.displayAlert( _("Please select a save target"), { className: 'humanError' } );
1068
                return false;
1069
            }
1070
1071
            $( '#save-record' ).find('i').attr( 'class', 'icon-loading' ).siblings( 'span' ).text( _("Saving...") );
1072
1073
            var targets_left = enabledTargets.length;
1074
            var errors = false;
845
1075
846
            function finishCb(result) {
1076
            function finishCb(result) {
847
                if ( result.error == 'syntax' ) {
1077
                targets_left--;
848
                    humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
1078
                if ( result.error ) {
849
                } else if ( result.error == 'invalid' ) {
1079
                    if ( result.error == 'syntax' ) {
850
                    humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1080
                        humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
851
                } else if ( !result.error ) {
1081
                    } else if ( result.error == 'invalid' ) {
852
                    humanMsg.displayAlert( _("Record saved "), { className: 'humanSuccess' } );
1082
                        humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1083
                    } else if ( result.error.type == 'control_number_match' ) {
1084
                        humanMsg.displayAlert( _("Control number conflict, cannot save"), { className: 'humanError' } );
1085
                    } else {
1086
                        humanMsg.displayAlert( _("Unknown error, record not saved to one or more targets"), { className: 'humanError' } );
1087
                    }
1088
                    errors = true;
853
                }
1089
                }
854
1090
855
                $.each( result.errors || [], function( undef, error ) {
1091
                $.each( result.errors || [], function( undef, error ) {
Lines 885-904 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
885
                    }
1121
                    }
886
                } );
1122
                } );
887
1123
888
                $( '#save-record' ).find('i').attr( 'class', 'fa fa-hdd-o' );
889
1124
890
                if ( result.error ) {
1125
                if ( targets_left == 0 ) {
891
                    // Reset backend info
1126
                    if ( !errors ) {
892
                    setSource( [ state.backend, state.recordID ] );
1127
                        humanMsg.displayMsg( "<h3>" + _("Record saved to:</h3>") + "</h3>" + '<ul><li>' + targetNames.join('</li><li>') + '</li></ul>', { className: 'humanSuccess' } );
1128
                    }
1129
1130
                    $( '#save-record' ).find('i').attr( 'class', 'icon-hdd' ).end().find('span').text( _("Save") );
893
                }
1131
                }
894
            }
1132
            }
895
1133
896
            var backend = $( this ).data( 'backend' ) || ( state.saveBackend );
1134
            $.each( enabledTargets, function() {
897
            if ( state.backend == backend ) {
1135
                saveRecord( this.id, editor, finishCb, options );
898
                saveRecord( backend + '/' + state.recordID, editor, finishCb );
1136
            } );
899
            } else {
900
                saveRecord( backend + '/', editor, finishCb );
901
            }
902
1137
903
            return false;
1138
            return false;
904
        } );
1139
        } );
Lines 1039-1049 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1039
            }
1274
            }
1040
        } );
1275
        } );
1041
1276
1277
        $('#open-batches').click( function() {
1278
            $('#batches-ui').modal();
1279
1280
            return false;
1281
        } );
1282
1283
        $('#create-batch').click( function() {
1284
            var batch_name = prompt( _("Name of new import batch:") );
1285
            if (batch_name == null) return false;
1286
1287
            KohaBackend.CreateBatch( batch_name, function( data ) {
1288
                if ( data.error ) {
1289
                    humanMsg.displayAlert( _("Could not create import batch"), { className: 'humanError' } );
1290
                } else {
1291
                    humanMsg.displayAlert( _("Import batch created"), { className: 'humanSuccess' } );
1292
1293
                    addImportBatch( editable_batches[data.batch_id] = { batch_id: data.batch_id, name: batch_name } );
1294
1295
                    var backend_id = 'batch:' + data.batch_id;
1296
                    addSaveTarget( {
1297
                        label: backends[backend_id].saveLabel,
1298
                        id: backend_id + '/',
1299
                        description: '',
1300
                        enabled: false,
1301
                    } );
1302
                }
1303
            } );
1304
1305
            return false;
1306
        } );
1307
1308
        $('#manage-batches').click( function() {
1309
            window.open('/cgi-bin/koha/tools/manage-marc-import.pl');
1310
1311
            return false;
1312
        } );
1313
1042
        // Key bindings
1314
        // Key bindings
1043
        bindGlobalKeys();
1315
        bindGlobalKeys();
1044
1316
1045
        // Setup UI
1317
        // Setup UI
1046
        $("#advanced-search-ui, #search-results-ui, #macro-ui").each( function() {
1318
        $(".ui-modal").each( function() {
1047
            $(this).modal({ show: false });
1319
            $(this).modal({ show: false });
1048
        } );
1320
        } );
1049
1321
Lines 1093-1098 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1093
                { return undefined; }
1365
                { return undefined; }
1094
        };
1366
        };
1095
1367
1368
        $.each( backends, function( name ) {
1369
            if ( !this.save ) return; // Not a saving backend
1370
1371
            addSaveTarget( {
1372
                label: this.saveLabel,
1373
                id: name + '/',
1374
                description: '',
1375
            } );
1376
        } );
1377
1096
        // Start editor
1378
        // Start editor
1097
        Preferences.Load( [% logged_in_user.borrowernumber || 0 | html %] );
1379
        Preferences.Load( [% logged_in_user.borrowernumber || 0 | html %] );
1098
        displayPreferences(editor);
1380
        displayPreferences(editor);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt (-8 / +36 lines)
Lines 35-45 Link Here
35
    <div id="toolbar" class="btn-toolbar">
35
    <div id="toolbar" class="btn-toolbar">
36
        <button class="btn btn-default btn-sm" id="new-record" title="Open fresh record"><i class="fa fa-plus"></i> <span>New record</span></button>
36
        <button class="btn btn-default btn-sm" id="new-record" title="Open fresh record"><i class="fa fa-plus"></i> <span>New record</span></button>
37
        <div class="btn-group">
37
        <div class="btn-group">
38
            <button class="btn btn-default btn-sm" id="save-record" title="Save current record (Ctrl-S)"><i class="fa fa-hdd-o"></i> <span>Save</span></button>
38
            <button class="btn btn-default btn-sm" id="save-record" title="Save current record (Ctrl-S)"><i class="fa fa-save"></i> <span>Save </span></button>
39
            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
39
            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
40
            <span class="caret"></span>
40
            <ul id="save-dropdown" class="dropdown-menu">
41
            </button>
41
                <li><a id="save-with-override" href="#">Save overriding warnings</a></li>
42
            <ul class="dropdown-menu" id="save-dropdown">
43
            </ul>
42
            </ul>
44
        </div>
43
        </div>
45
        <button class="btn btn-default btn-sm" id="import-records" title="Import an ISO2709 or MARCXML record"><i class="fa fa-download"></i> <span>Import record...</span></button>
44
        <button class="btn btn-default btn-sm" id="import-records" title="Import an ISO2709 or MARCXML record"><i class="fa fa-download"></i> <span>Import record...</span></button>
Lines 49-54 Link Here
49
            <ul id="prefs-menu" class="dropdown-menu">
48
            <ul id="prefs-menu" class="dropdown-menu">
50
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
49
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
51
                <li><a id="set-field-widgets" href="#"></a></li>
50
                <li><a id="set-field-widgets" href="#"></a></li>
51
                <li><a id="open-batches" href="#">Import batches...</a></li>
52
                <li class="divider"></li>
52
                <li class="divider"></li>
53
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
53
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
54
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
54
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
Lines 95-106 Link Here
95
    </fieldset>
95
    </fieldset>
96
</form>
96
</form>
97
97
98
<h3>Save to:</h3>
99
<form id="save-targets">
100
    <fieldset class="brief">
101
    <ol></ol>
102
    </fieldset>
103
</form>
104
98
</div>
105
</div>
99
106
100
</div>
107
</div>
101
</div>
108
</div>
102
109
103
<div id="advanced-search-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
110
<div id="advanced-search-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
104
<div class="modal-dialog modal-lg">
111
<div class="modal-dialog modal-lg">
105
<div class="modal-content">
112
<div class="modal-content">
106
113
Lines 181-187 Link Here
181
</div>
188
</div>
182
</div>
189
</div>
183
190
184
<div id="search-results-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
191
<div id="search-results-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
185
<div class="modal-dialog modal-lg">
192
<div class="modal-dialog modal-lg">
186
<div class="modal-content">
193
<div class="modal-content">
187
194
Lines 228-234 Link Here
228
235
229
</div>
236
</div>
230
237
231
<div id="macro-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
238
<div id="macro-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
232
<div class="modal-dialog modal-lg">
239
<div class="modal-dialog modal-lg">
233
<div class="modal-content">
240
<div class="modal-content">
234
241
Lines 254-259 Link Here
254
</div>
261
</div>
255
</div>
262
</div>
256
263
264
<div id="batches-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="batches-title" aria-hidden="true">
265
266
<div class="modal-header">
267
    <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
268
    <h3 id="batches-title">Import batch settings</h3>
269
</div>
270
271
<div class="modal-body row-fluid">
272
    <div class="span9">
273
        <div id="toolbar" class="btn-toolbar">
274
            <button class="btn btn-small" type="submit" id="create-batch"><i class="icon-plus"></i> <span>Create new batch...</span></button>
275
            <button class="btn btn-small" type="submit" id="manage-batches"><i class="icon-list"></i> <span>Manage import batches...</span></button>
276
        </div>
277
        <ul id="batches-list"></ul>
278
    </div>
279
    <div class="span3">
280
    </div>
281
</div>
282
283
</div>
284
257
<div id="shortcuts-contents" style="display: none">
285
<div id="shortcuts-contents" style="display: none">
258
<table class="table table-condensed">
286
<table class="table table-condensed">
259
    <thead>
287
    <thead>
(-)a/svc/cataloguing/import_batches (-1 / +212 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
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.
19
20
use Modern::Perl;
21
22
use C4::Biblio qw();
23
use C4::Context;
24
use C4::ImportBatch qw( AddBiblioToBatch AddImportBatch GetImportRecordMarcXML ModBiblioInBatch );
25
use C4::Service;
26
use DateTime;
27
use DateTime::Format::Strptime;
28
use Encode qw( encode_utf8 );
29
use Koha::Database;
30
use MARC::Record;
31
32
our ( $query, $response ) = C4::Service->init( tools => 'manage_staged_marc' );
33
34
sub _parse_005_timestamp {
35
    my ( $timestamp, $default_to_end ) = @_;
36
37
    # YYYYMMDD
38
    if ( $timestamp =~ /^\d{8}$/ ) {
39
        my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d' );
40
        my $timestamp = $parser->parse_datetime($timestamp);
41
        if ( $timestamp && $default_to_end ) {
42
            $timestamp->set(
43
                hour => 23,
44
                minute => 59,
45
                second => 59
46
            );
47
        }
48
49
        return $timestamp;
50
    # YYYYMMDDHHMMSS
51
    } elsif ( $timestamp =~ /^\d{8}\d{6}$/ ) {
52
        my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d%H%M%S' );
53
        return $parser->parse_datetime($timestamp);
54
    }
55
}
56
57
sub download_batch {
58
    my ( $batch_id ) = @_;
59
60
    my $schema = Koha::Database->new()->schema();
61
62
    my %extra_conditions;
63
64
    my $start_control_number = $query->param( 'start_control_number' );
65
    my $end_control_number = $query->param( 'end_control_number' );
66
67
    if ( $start_control_number && $end_control_number ) {
68
        $extra_conditions{control_number} = { -between => [ $start_control_number, $end_control_number ] };
69
    }
70
71
    my $start_timestamp = $query->param( 'start_timestamp' );
72
    my $end_timestamp = $query->param( 'end_timestamp' );
73
74
    if ( $start_timestamp && $end_timestamp ) {
75
        my $start_timestamp = _parse_005_timestamp( $start_timestamp, 0 );
76
        my $end_timestamp = _parse_005_timestamp( $end_timestamp, 1 );
77
78
        my $dtf = $schema->storage->datetime_parser;
79
80
        $extra_conditions{'import_record.upload_timestamp'} = {
81
            -between => [
82
                $dtf->format_datetime($start_timestamp),
83
                $dtf->format_datetime($end_timestamp)
84
            ]
85
        };
86
    }
87
88
    my $records = $schema->resultset('ImportBiblio')->search(
89
        {
90
            'import_record.import_batch_id' => $batch_id,
91
            %extra_conditions
92
        },
93
        {
94
            join => 'import_record',
95
        }
96
    );
97
98
    my $mimetype = 'application/octet-stream';
99
    my $charset  = 'utf-8';
100
    my $filename = DateTime->now->strftime("batch-$batch_id-%Y-%m-%d-%H-%M-%S.mrc");
101
    my $content_length = $records->get_column( { length => 'import_record.marc' } )->sum || 0;
102
103
    print $query->header(
104
        -type => $mimetype,
105
        -charset => $charset,
106
        -attachment => $filename,
107
        -Content_length => $content_length
108
    );
109
110
    for my $marc ( $records->get_column( 'import_record.marc' )->all ) {
111
        print $marc;
112
    }
113
}
114
115
sub get_record {
116
    my ( $batch_id, $import_record_id ) = @_;
117
118
    my $marcxml = GetImportRecordMarcXML( $import_record_id );
119
120
    if ( !$marcxml ) {
121
        C4::Service->return_error( 'not_found' );
122
    }
123
124
    $response->param( record => $marcxml );
125
126
    C4::Service->return_success( $response );
127
}
128
129
sub _control_number_already_used {
130
    my ( $marc_record, $batch_id, $import_record_id ) = @_;
131
132
    return unless ( $marc_record->field('001') );
133
134
    my %extra_conditions;
135
136
    $extra_conditions{'import_record.import_record_id'} = { '!=', $import_record_id } if ( $import_record_id );
137
138
    my $control_number = $marc_record->field('001')->data;
139
140
    my $schema = Koha::Database->new()->schema();
141
    return $schema->resultset('ImportBiblio')->count(
142
        {
143
            control_number => $control_number,
144
            'import_record.import_batch_id' => $batch_id,
145
            %extra_conditions
146
        },
147
        {
148
            join => 'import_record',
149
        }
150
    );
151
}
152
153
sub create_record {
154
    my ( $batch_id ) = @_;
155
156
    my $marcflavour = C4::Context->preference('marcflavour') || 'marc21';
157
    my $marc_record = eval { MARC::Record::new_from_xml( $query->param('record'), "utf8", $marcflavour) };
158
    if ($@) {
159
        C4::Service->return_error( 'failed', $@ );
160
    }
161
162
    if ( !$query->param('allow_control_number_conflict') && _control_number_already_used( $marc_record, $batch_id ) ) {
163
        C4::Service->return_error( 'control_number_match', '' );
164
    }
165
166
    my $import_record_id = AddBiblioToBatch( $batch_id, 0, $marc_record, "utf8", int( rand(99999) ) );
167
    $response->param( import_record_id => $import_record_id );
168
169
    C4::Service->return_success( $response );
170
}
171
172
sub update_record {
173
    my ( $batch_id, $import_record_id ) = @_;
174
175
    my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
176
    my $marc_record = eval { MARC::Record::new_from_xml( $query->param('record'), "utf8", $marcflavour) };
177
    if ($@) {
178
        C4::Service->return_error( 'failed', $@ );
179
    }
180
181
    if ( !$query->param('allow_control_number_conflict') &&  _control_number_already_used( $marc_record, $batch_id, $import_record_id ) ) {
182
        C4::Service->return_error( 'control_number_match', '' );
183
    }
184
185
    C4::Biblio::UpdateMarcTimestamp( $marc_record );
186
    ModBiblioInBatch( $import_record_id, $marc_record );
187
188
    $response->param( updated_record => $marc_record->as_xml_record( C4::Context->preference('marcflavour') ) );
189
190
    C4::Service->return_success( $response );
191
}
192
193
sub create_batch {
194
    my ( $batch_name ) = C4::Service->require_params( 'batch_name' );
195
196
    my $batch_id = AddImportBatch({
197
        file_name => $batch_name,
198
        record_type => 'biblio'
199
    });
200
201
    $response->param( batch_id => $batch_id );
202
203
    C4::Service->return_success( $response );
204
}
205
206
C4::Service->dispatch(
207
    [ 'GET /(\d+)', [ 'download' ], \&download_batch ],
208
    [ 'GET /(\d+)/(\d+)', [], \&get_record ],
209
    [ 'POST /(\d+)/', [], \&create_record ],
210
    [ 'POST /(\d+)/(\d+)', [], \&update_record ],
211
    [ 'POST /', [], \&create_batch ],
212
);

Return to bug 18823