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

(-)a/C4/Biblio.pm (-6 / +22 lines)
Lines 3080-3085 sub _koha_delete_biblio_metadata { Link Here
3080
3080
3081
=head1 UNEXPORTED FUNCTIONS
3081
=head1 UNEXPORTED FUNCTIONS
3082
3082
3083
=head2 Update005Time
3084
3085
  &Update005Time( $record );
3086
3087
Updates the 005 timestamp of the given record to the current time.
3088
3089
=cut
3090
3091
sub UpdateMarcTimestamp {
3092
    my ( $record ) = @_;
3093
3094
    my $encoding = C4::Context->preference("marcflavour");
3095
3096
    if ( $encoding =~ /MARC21|UNIMARC/ ) {
3097
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3098
        # YY MM DD HH MM SS (update year and month)
3099
        my $f005 = $record->field('005');
3100
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) ) if $f005;
3101
    }
3102
}
3103
3083
=head2 ModBiblioMarc
3104
=head2 ModBiblioMarc
3084
3105
3085
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3106
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
Lines 3132-3143 sub ModBiblioMarc { Link Here
3132
    }
3153
    }
3133
3154
3134
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3155
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3135
    if($encoding =~ /MARC21|UNIMARC/) {
3156
    UpdateMarcTimestamp( $record );
3136
      my @a= (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3137
        # YY MM DD HH MM SS (update year and month)
3138
      my $f005= $record->field('005');
3139
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
3140
    }
3141
3157
3142
    my $metadata = {
3158
    my $metadata = {
3143
        biblionumber => $biblionumber,
3159
        biblionumber => $biblionumber,
(-)a/C4/ImportBatch.pm (-6 / +14 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 1607-1616 sub _create_import_record { Link Here
1607
sub _update_import_record_marc {
1609
sub _update_import_record_marc {
1608
    my ($import_record_id, $marc_record, $marc_type) = @_;
1610
    my ($import_record_id, $marc_record, $marc_type) = @_;
1609
1611
1612
    my $upload_timestamp = _get_import_record_timestamp($marc_record);
1613
1610
    my $dbh = C4::Context->dbh;
1614
    my $dbh = C4::Context->dbh;
1611
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
1615
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?, upload_timestamp = ?
1612
                             WHERE  import_record_id = ?");
1616
                             WHERE  import_record_id = ?");
1613
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $import_record_id);
1617
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $upload_timestamp, $import_record_id);
1614
    $sth->finish();
1618
    $sth->finish();
1615
}
1619
}
1616
1620
Lines 1631-1644 sub _add_auth_fields { Link Here
1631
sub _add_biblio_fields {
1635
sub _add_biblio_fields {
1632
    my ($import_record_id, $marc_record) = @_;
1636
    my ($import_record_id, $marc_record) = @_;
1633
1637
1638
    my $controlnumber;
1639
    if ($marc_record->field('001')) {
1640
        $controlnumber = $marc_record->field('001')->data();
1641
    }
1634
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1642
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1635
    my $dbh = C4::Context->dbh;
1643
    my $dbh = C4::Context->dbh;
1636
    # FIXME no controlnumber, originalsource
1644
    # FIXME no originalsource
1637
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1645
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1638
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
1646
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn, control_number) VALUES (?, ?, ?, ?, ?, ?)");
1639
    $sth->execute($import_record_id, $title, $author, $isbn, $issn);
1647
    $sth->execute($import_record_id, $title, $author, $isbn, $issn, $controlnumber);
1640
    $sth->finish();
1648
    $sth->finish();
1641
                
1649
1642
}
1650
}
1643
1651
1644
sub _update_biblio_fields {
1652
sub _update_biblio_fields {
(-)a/cataloguing/editor.pl (-1 / +1 lines)
Lines 63-69 $template->param( Link Here
63
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
63
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
64
    {
64
    {
65
        batch_type => [ 'batch', 'webservice' ],
65
        batch_type => [ 'batch', 'webservice' ],
66
        import_status => 'staged',
66
        import_status => [ 'staged', 'staging' ],
67
    },
67
    },
68
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
68
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
69
) ];
69
) ];
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js (+52 lines)
Lines 168-173 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
168
            } );
168
            } );
169
        },
169
        },
170
170
171
        GetBatchRecord: function( batch_id, id, callback ) {
172
            $.get(
173
                '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id
174
            ).done( function( data ) {
175
                var record = new MARC.Record();
176
                record.loadMARCXML( data.record );
177
                callback(record);
178
            } ).fail( function( data ) {
179
                callback( { error: data } );
180
            } );
181
        },
182
183
        CreateBatch: function( batch_name, callback ) {
184
            $.ajax( {
185
                type: 'POST',
186
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/',
187
                data: { batch_name: batch_name },
188
            } ).done( function( data ) {
189
                callback( data );
190
            } ).fail( function( data ) {
191
                callback( { error: data } );
192
            } );
193
        },
194
195
        CreateBatchRecord: function( record, batch_id, callback, options ) {
196
            $.ajax( {
197
                type: 'POST',
198
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/',
199
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
200
            } ).done( function( data ) {
201
                callback( data );
202
            } ).fail( function( data ) {
203
                callback( { error: $.parseJSON( data.responseText ) || data.responseText } );
204
            } );
205
        },
206
207
        SaveBatchRecord: function( batch_id, id, record, callback, options ) {
208
            $.ajax( {
209
                type: 'POST',
210
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id,
211
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
212
            } ).done( function( data ) {
213
                callback( data );
214
            } ).fail( function( data ) {
215
                callback( { data: { error: data } } );
216
            } );
217
        },
218
219
        StartBatchExport: function( batch_id, options ) {
220
            window.open( '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '?download=1&' + $.param( options ) );
221
        },
222
171
        GetTagsBy: function( frameworkcode, field, value ) {
223
        GetTagsBy: function( frameworkcode, field, value ) {
172
            var result = {};
224
            var result = {};
173
225
(-)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 (-2 / +44 lines)
Lines 65-70 body { Link Here
65
    font-size: 12px;
65
    font-size: 12px;
66
}
66
}
67
67
68
#save-targets input {
69
    display: inline-block;
70
    margin: 1px;
71
    vertical-align: middle;
72
}
73
74
#save-targets input:checked + label {
75
    color: #000;
76
}
77
78
#save-targets label {
79
    color: #666;
80
    display: inline-block;
81
    margin-left: 0.3em;
82
    padding: 0.3em 0;
83
    vertical-align: middle;
84
    width: 10em;
85
}
86
87
#save-targets li {
88
    overflow: hidden;
89
}
90
91
#shortcuts-container {
92
    font-size: 12px;
93
}
94
68
/*> MARC editor */
95
/*> MARC editor */
69
#editor .CodeMirror {
96
#editor .CodeMirror {
70
    line-height: 1.2;
97
    line-height: 1.2;
Lines 220-226 body { Link Here
220
247
221
/*> Search */
248
/*> Search */
222
249
223
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg {
250
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg .ui-modal {
251
    padding: 5px;
224
    width: 90%;
252
    width: 90%;
225
}
253
}
226
254
Lines 454-459 body { Link Here
454
    position: absolute;
482
    position: absolute;
455
}
483
}
456
484
485
/* >Batches */
486
#batches-list > li {
487
    border: 2px solid #F0F0F0;
488
    border-radius: 6px;
489
    display: block;
490
    line-height: 3em;
491
    font-size: 115%;
492
}
493
494
#batches-list > li input {
495
    display: inline-block;
496
    margin: 0 1em;
497
}
498
457
/* Small devices (tablets, 768px and up) */
499
/* Small devices (tablets, 768px and up) */
458
@media (min-width: @screen-sm-min) {
500
@media (min-width: @screen-sm-min) {
459
    #statusbar {
501
    #statusbar {
Lines 473-476 body { Link Here
473
515
474
.ui-keyboard-accept {
516
.ui-keyboard-accept {
475
    display: none;
517
    display: none;
476
}
518
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-32 / +315 lines)
Lines 46-51 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
46
            recordtype: 'biblio',
46
            recordtype: 'biblio',
47
            checked: false,
47
            checked: false,
48
        },
48
        },
49
        [%- FOREACH batch = editable_batches -%]
50
            'batch:[% batch.import_batch_id %]': {
51
                name: _("Batch: ") + '[% batch.file_name %]',
52
                recordtype: 'biblio',
53
                checked: false,
54
            },
55
        [%- END -%]
49
        [%- FOREACH server = z3950_servers -%]
56
        [%- FOREACH server = z3950_servers -%]
50
            [% server.id | html %]: {
57
            [% server.id | html %]: {
51
                name: '[% server.servername | html %]',
58
                name: '[% server.servername | html %]',
Lines 71-78 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
71
78
72
    var state = {
79
    var state = {
73
        backend: '',
80
        backend: '',
74
        saveBackend: 'catalog',
81
        recordID: undefined,
75
        recordID: undefined
82
        saveTargets: {},
76
    };
83
    };
77
84
78
    var editor;
85
    var editor;
Lines 258-273 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
258
            }
265
            }
259
        },
266
        },
260
        'catalog': {
267
        'catalog': {
261
            titleForRecord: _("Editing catalog record #{ID}"),
268
            titleForRecord: _("Editing catalog record #%s"),
262
            links: [
269
            links: [
263
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber={ID}" },
270
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=%s" },
264
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber={ID}" },
271
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=%s" },
265
            ],
272
            ],
266
            saveLabel: _("Save to catalog"),
273
            saveLabel: _("New catalog record"),
274
            saveExistingLabel: _("Catalog record #%s"),
267
            get: function( id, callback ) {
275
            get: function( id, callback ) {
268
                if ( !id ) return false;
276
                if ( !id ) return false;
269
277
270
                KohaBackend.GetRecord( id, callback );
278
                KohaBackend.GetRecord( id, function( data ) {
279
                    if ( !data.error ) {
280
                        setSaveTargetChecked( 'catalog/', false );
281
                        addSaveTarget( {
282
                            label: backends.catalog.saveExistingLabel.format( id ),
283
                            id: 'catalog/' + id,
284
                            description: '',
285
                            checked: true
286
                        } );
287
                    }
288
289
                    callback(data);
290
                } );
271
            },
291
            },
272
            save: function( id, record, done ) {
292
            save: function( id, record, done ) {
273
                function finishCb( data ) {
293
                function finishCb( data ) {
Lines 290-296 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
290
            }
310
            }
291
        },
311
        },
292
        'marcxml': {
312
        'marcxml': {
293
            saveLabel: _("Save as MARCXML (.xml) file"),
313
            saveLabel: _("New MARCXML (.xml) file"),
294
            save: function( id, record, done ) {
314
            save: function( id, record, done ) {
295
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
315
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
296
316
Lines 312-317 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
312
        },
332
        },
313
    };
333
    };
314
334
335
    var editable_batches = {
336
        [%- FOREACH batch = editable_batches -%]
337
            [% batch.import_batch_id %]: {
338
                'name': '[% batch.file_name %]',
339
            },
340
        [%- END -%]
341
    };
342
343
    function addSaveTarget( target ) {
344
        state.saveTargets[target.id] = target;
345
        if (target.enabled == null) target.enabled = true;
346
347
        // Have to check that Preferences has been initialized
348
        var saved_value = Preferences.user && Preferences.user.selected_save_targets[target.id];
349
        if ( saved_value != null ) target.checked = saved_value;
350
351
        var target_list = $.map( state.saveTargets, function( target ) {
352
            return target;
353
        } );
354
355
        target_list.sort( function( a, b ) {
356
            return a.label.localeCompare(b.label);
357
        } );
358
359
        $('#save-targets ol').empty();
360
361
        $.each( target_list, function( i, target ) {
362
            var $new_target = $(
363
                '<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>'
364
            );
365
366
            $new_target.find('input').change( function() {
367
                target.checked = this.checked;
368
            } );
369
370
            $('#save-targets ol').append($new_target);
371
372
            if (!target.enabled) $new_target.hide();
373
        } );
374
    }
375
376
    function setSaveTargetChecked( target_id, checked ) {
377
        if ( state.saveTargets[target_id] == null ) return;
378
379
        state.saveTargets[target_id].checked = checked;
380
        $( '#save-targets input[data-target-id="' + target_id + '"]' )[0].checked = checked;
381
    }
382
383
    function setSaveTargetEnabled( target_id, enabled ) {
384
        if ( !enabled ) {
385
            setSaveTargetChecked( target_id, false );
386
        }
387
388
        state.saveTargets[target_id].enabled = enabled;
389
        $( '#save-targets input[data-target-id="' + target_id + '"]' ).closest('li').toggle(enabled);
390
    }
391
315
    function setSource(parts) {
392
    function setSource(parts) {
316
        state.backend = parts[0];
393
        state.backend = parts[0];
317
        state.recordID = parts[1];
394
        state.recordID = parts[1];
Lines 322-334 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
322
399
323
        document.location.hash = '#' + parts[0] + '/' + parts[1];
400
        document.location.hash = '#' + parts[0] + '/' + parts[1];
324
401
325
        $('#title').text( backend.titleForRecord.replace( '{ID}', parts[1] ) );
402
        $('#title').text( backend.titleForRecord.format( parts[1] ) );
326
403
327
        $.each( backend.links || [], function( i, link ) {
404
        $.each( backend.links || [], function( i, link ) {
328
            $('#title').append(' <a target="_blank" href="' + link.href.replace( '{ID}', parts[1] ) + '">(' + link.title + ')</a>' );
405
            $('#title').append(' <a target="_blank" href="' + link.href.format( parts[1] ) + '">(' + link.title + ')</a>' );
329
        } );
406
        } );
330
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.replace( '{ID}', parts[1] ) );
407
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.format( parts[1] ) );
331
        $('#save-record span').text( backends[ state.saveBackend ].saveLabel );
332
    }
408
    }
333
409
334
    function saveRecord( recid, editor, callback ) {
410
    function saveRecord( recid, editor, callback ) {
Lines 365-370 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
365
441
366
            if (data.newId) {
442
            if (data.newId) {
367
                setSource(data.newId);
443
                setSource(data.newId);
444
445
                var backend = backends[ parts[0] ];
446
447
                setSaveTargetChecked( recid, false );
448
                addSaveTarget( {
449
                    label: backend.saveExistingLabel.format( data.newId[1] ),
450
                    id: data.newId.join('/'),
451
                    description: '',
452
                    checked: true
453
                } );
368
            } else {
454
            } else {
369
                setSource( [ state.backend, state.recordID ] );
455
                setSource( [ state.backend, state.recordID ] );
370
            }
456
            }
Lines 623-628 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
623
        var value = Preferences.user[pref];
709
        var value = Preferences.user[pref];
624
710
625
        switch (pref) {
711
        switch (pref) {
712
            case 'enabledBatches':
713
                $.each( editable_batches, function( batch_id, batch ) {
714
                    $( '#batches-list li[data-batch-id=' + batch_id + '] input' )[0].checked = Preferences.user.enabledBatches[batch_id];
715
                    setSaveTargetEnabled( 'batch:' + batch_id + '/', Preferences.user.enabledBatches[batch_id] || false );
716
                } );
626
            case 'fieldWidgets':
717
            case 'fieldWidgets':
627
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
718
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
628
                break;
719
                break;
Lines 644-649 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
644
                    if ( saved_val != null ) server.checked = saved_val;
735
                    if ( saved_val != null ) server.checked = saved_val;
645
                } );
736
                } );
646
                break;
737
                break;
738
            case 'selected_save_targets':
739
                $.each( state.saveTargets, function( target_id, target ) {
740
                    var saved_val = Preferences.user.selected_save_targets[target_id];
741
742
                    if ( saved_val != null ) setSaveTargetChecked( target_id, saved_val );
743
                } );
744
                break;
745
            case 'selected_search_targets':
746
                $.each( z3950Servers, function( server_id, server ) {
747
                    var saved_val = Preferences.user.selected_search_targets[server_id];
748
749
                    if ( saved_val != null ) server.checked = saved_val;
750
                } );
751
                break;
647
        }
752
        }
648
    }
753
    }
649
754
Lines 657-663 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
657
            } );
762
            } );
658
        }
763
        }
659
764
765
        function _addLiveHandler( sel, event, handler ) {
766
            $( document ).on( event, sel, function (e) {
767
                e.preventDefault();
768
                handler.call( this, e, Preferences.user[pref] );
769
                Preferences.Save( [% USER_INFO.borrowernumber %] );
770
                showPreference(pref);
771
            } );
772
        }
773
660
        switch (pref) {
774
        switch (pref) {
775
            case 'enabledBatches':
776
                _addLiveHandler( '#batches-list input', 'change', function() {
777
                    Preferences.user.enabledBatches[ $( this ).closest('li').data('batch-id') ] = this.checked;
778
                } );
779
                break;
661
            case 'fieldWidgets':
780
            case 'fieldWidgets':
662
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
781
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
663
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
782
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
Lines 673-678 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
673
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
792
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
674
                } );
793
                } );
675
                break;
794
                break;
795
            case 'selected_save_targets':
796
                $( document ).on( 'change', 'input.save-toggle-target', function() {
797
                    var target_id = $( this ).data('target-id');
798
                    Preferences.user.selected_save_targets[target_id] = this.checked;
799
                    Preferences.Save( [% USER_INFO.borrowernumber %] );
800
                } );
801
                break;
676
            case 'selected_search_targets':
802
            case 'selected_search_targets':
677
                $( document ).on( 'change', 'input.search-toggle-server', function() {
803
                $( document ).on( 'change', 'input.search-toggle-server', function() {
678
                    var server_id = $( this ).closest('li').data('server-id');
804
                    var server_id = $( this ).closest('li').data('server-id');
Lines 766-771 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
766
        showSavedMacros();
892
        showSavedMacros();
767
    }
893
    }
768
894
895
    function addImportBatch(batch) {
896
        var backend_id = 'batch:' + batch.batch_id;
897
        backends[backend_id] = {
898
            titleForRecord: _("Editing record from batch: ") + batch.name,
899
            saveLabel: _("Batch: ") + batch.name,
900
            saveExistingLabel: batch.name + ": #%s",
901
            get: function( id, callback ) {
902
                KohaBackend.GetBatchRecord( batch.batch_id, id, function( data ) {
903
                    if ( !data.error ) {
904
                        setSaveTargetChecked( backend_id + '/', false );
905
                        addSaveTarget( {
906
                            label: batch.name + ": #" + id,
907
                            id: backend_id + '/' + id,
908
                            description: '',
909
                            checked: true
910
                        } );
911
                    }
912
913
                    callback(data);
914
                } );
915
            },
916
            save: function( id, record, done, options ) {
917
                function finishCb( data ) {
918
                    done( {
919
                        error: data.message || data.error,
920
                        newRecord: data.updated_record,
921
                        newId: data.import_record_id && [ backend_id, data.import_record_id ]
922
                    } );
923
                }
924
925
                if ( id ) {
926
                    KohaBackend.SaveBatchRecord( batch.batch_id, id, record, finishCb, { allow_control_number_conflict: options.override_warnings } );
927
                } else {
928
                    KohaBackend.CreateBatchRecord( record, batch.batch_id, finishCb, { allow_control_number_conflict: options.override_warnings } );
929
                }
930
            },
931
        };
932
933
        // Build batch UI
934
        var $batch_entry = $( '<li data-batch-id="' + batch.batch_id + '"><input type="checkbox" />' + batch.name + '</li>' );
935
936
        var $batch_buttons = $('<span class="batch-buttons"></span>').appendTo($batch_entry);
937
        var $export_button = $( '<button>' + _("Export...") + '</button>' ).appendTo($batch_buttons).click( function() {
938
            $('#batches-list .batch-export').hide();
939
            $export_screen.show();
940
        } );
941
942
        var $export_screen = $(
943
            '<form class="batch-export form-horizontal" style="display: none">'
944
            + '<div class="control-group">'
945
            + '<label class="control-label">' + _("Control number range:") + '</label>'
946
            + '<div class="controls"><input class="batch-control-number-start" type="text"> - <input class="batch-control-number-end" type="text"></div>'
947
            + '</div>'
948
            + '<label class="control-label">' + _("Timestamp range (YYYYMMDD or YYYMMDDHHMMSS):") + '</label>'
949
            + '<div class="controls"><input class="batch-timestamp-start" type="text"> - <input class="batch-timestamp-end" type="text"></div>'
950
            + '</div>'
951
            + '<div class="control-group">'
952
            + '<div class="controls"><button class="batch-export-start">' + _("Start export") + '</div>'
953
            + '</form>'
954
        ).appendTo($batch_entry);
955
956
        $export_screen.find('.batch-export-start').click( function() {
957
            function getFormVal(name) {
958
                return $export_screen.find( '.batch-' + name ).val();
959
            }
960
961
            var options = {
962
                start_control_number: getFormVal('control-number-start'),
963
                end_control_number: getFormVal('control-number-end'),
964
                start_timestamp: getFormVal('timestamp-start'),
965
                end_timestamp: getFormVal('timestamp-end'),
966
            };
967
968
            KohaBackend.StartBatchExport( batch.batch_id, options );
969
        } );
970
971
        $('#batches-list').append( $batch_entry );
972
    }
973
769
    $(document).ready( function() {
974
    $(document).ready( function() {
770
        // Editor setup
975
        // Editor setup
771
        editor = new MARCEditor( {
976
        editor = new MARCEditor( {
Lines 815-820 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
815
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
1020
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
816
                } );
1021
                } );
817
            }, 100);
1022
            }, 100);
1023
818
        }
1024
        }
819
1025
820
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
1026
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
Lines 855-863 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
855
        $.each( backends, function( id, backend ) {
1061
        $.each( backends, function( id, backend ) {
856
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
1062
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
857
        } );
1063
        } );
858
        saveableBackends.sort();
1064
859
        $.each( saveableBackends, function( undef, backend ) {
1065
        var batch_list = [];
860
            $( '#save-dropdown' ).append( '<li><a href="#" data-backend="' + backend[1] + '">' + backend[0] + '</a></li>' );
1066
1067
        $.each( editable_batches, function( batch_id, batch ) {
1068
            batch_list.push( $.extend( { batch_id: batch_id }, batch ) );
1069
        } );
1070
        batch_list.sort( function( a, b ) {
1071
            return a.name.localeCompare(b.name);
1072
        } );
1073
        $.each( batch_list, function() {
1074
            addImportBatch( this );
861
        } );
1075
        } );
862
1076
863
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
1077
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
Lines 873-886 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
873
        // Click bindings
1087
        // Click bindings
874
        $( '#save-record, #save-dropdown a' ).click( function() {
1088
        $( '#save-record, #save-dropdown a' ).click( function() {
875
             $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner fa-spin' ).siblings( 'span' ).text( _("Saving...") );
1089
             $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner fa-spin' ).siblings( 'span' ).text( _("Saving...") );
1090
            var enabledTargets = [];
1091
            var targetNames = [];
1092
            $.each( state.saveTargets, function() {
1093
                if ( this.checked ) {
1094
                    enabledTargets.push(this);
1095
                    targetNames.push(this.label);
1096
                }
1097
            } );
1098
            if ( enabledTargets.length == 0 ) {
1099
                humanMsg.displayAlert( _("Please select a save target"), { className: 'humanError' } );
1100
                return false;
1101
            }
1102
1103
            $( '#save-record' ).find('i').attr( 'class', 'icon-loading' ).siblings( 'span' ).text( _("Saving...") );
1104
1105
            var targets_left = enabledTargets.length;
1106
            var errors = false;
876
1107
877
            function finishCb(result) {
1108
            function finishCb(result) {
878
                if ( result.error == 'syntax' ) {
1109
                targets_left--;
879
                    humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
1110
                if ( result.error ) {
880
                } else if ( result.error == 'invalid' ) {
1111
                    if ( result.error == 'syntax' ) {
881
                    humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1112
                        humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
882
                } else if ( !result.error ) {
1113
                    } else if ( result.error == 'invalid' ) {
883
                    humanMsg.displayAlert( _("Record saved "), { className: 'humanSuccess' } );
1114
                        humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1115
                    } else if ( result.error.type == 'control_number_match' ) {
1116
                        humanMsg.displayAlert( _("Control number conflict, cannot save"), { className: 'humanError' } );
1117
                    } else {
1118
                        humanMsg.displayAlert( _("Unknown error, record not saved to one or more targets"), { className: 'humanError' } );
1119
                    }
1120
                    errors = true;
884
                }
1121
                }
885
1122
886
                $.each( result.errors || [], function( undef, error ) {
1123
                $.each( result.errors || [], function( undef, error ) {
Lines 916-935 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
916
                    }
1153
                    }
917
                } );
1154
                } );
918
1155
919
                $( '#save-record' ).find('i').attr( 'class', 'fa fa-hdd-o' );
920
1156
921
                if ( result.error ) {
1157
                if ( targets_left == 0 ) {
922
                    // Reset backend info
1158
                    if ( !errors ) {
923
                    setSource( [ state.backend, state.recordID ] );
1159
                        humanMsg.displayMsg( "<h3>" + _("Record saved to:</h3>") + "</h3>" + '<ul><li>' + targetNames.join('</li><li>') + '</li></ul>', { className: 'humanSuccess' } );
1160
                    }
1161
1162
                    $( '#save-record' ).find('i').attr( 'class', 'icon-hdd' ).end().find('span').text( _("Save") );
924
                }
1163
                }
925
            }
1164
            }
926
1165
927
            var backend = $( this ).data( 'backend' ) || ( state.saveBackend );
1166
            $.each( enabledTargets, function() {
928
            if ( state.backend == backend ) {
1167
                saveRecord( this.id, editor, finishCb, options );
929
                saveRecord( backend + '/' + state.recordID, editor, finishCb );
1168
            } );
930
            } else {
931
                saveRecord( backend + '/', editor, finishCb );
932
            }
933
1169
934
            return false;
1170
            return false;
935
        } );
1171
        } );
Lines 1070-1080 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1070
            }
1306
            }
1071
        } );
1307
        } );
1072
1308
1309
        $('#open-batches').click( function() {
1310
            $('#batches-ui').modal();
1311
1312
            return false;
1313
        } );
1314
1315
        $('#create-batch').click( function() {
1316
            var batch_name = prompt( _("Name of new import batch:") );
1317
            if (batch_name == null) return false;
1318
1319
            KohaBackend.CreateBatch( batch_name, function( data ) {
1320
                if ( data.error ) {
1321
                    humanMsg.displayAlert( _("Could not create import batch"), { className: 'humanError' } );
1322
                } else {
1323
                    humanMsg.displayAlert( _("Import batch created"), { className: 'humanSuccess' } );
1324
1325
                    addImportBatch( editable_batches[data.batch_id] = { batch_id: data.batch_id, name: batch_name } );
1326
1327
                    var backend_id = 'batch:' + data.batch_id;
1328
                    addSaveTarget( {
1329
                        label: backends[backend_id].saveLabel,
1330
                        id: backend_id + '/',
1331
                        description: '',
1332
                        enabled: false,
1333
                    } );
1334
                }
1335
            } );
1336
1337
            return false;
1338
        } );
1339
1340
        $('#manage-batches').click( function() {
1341
            window.open('/cgi-bin/koha/tools/manage-marc-import.pl');
1342
1343
            return false;
1344
        } );
1345
1073
        // Key bindings
1346
        // Key bindings
1074
        bindGlobalKeys();
1347
        bindGlobalKeys();
1075
1348
1076
        // Setup UI
1349
        // Setup UI
1077
        $("#advanced-search-ui, #search-results-ui, #macro-ui").each( function() {
1350
        $(".ui-modal").each( function() {
1078
            $(this).modal({ show: false });
1351
            $(this).modal({ show: false });
1079
        } );
1352
        } );
1080
1353
Lines 1136-1141 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1136
                    $('#loading').hide();
1409
                    $('#loading').hide();
1137
                }
1410
                }
1138
            );
1411
            );
1412
        }; );
1413
1414
        $.each( backends, function( name ) {
1415
            if ( !this.save ) return; // Not a saving backend
1416
1417
            addSaveTarget( {
1418
                label: this.saveLabel,
1419
                id: name + '/',
1420
                description: '',
1421
            } );
1139
        } );
1422
        } );
1140
1423
1141
        // Start editor
1424
        // Start editor
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt (-8 / +36 lines)
Lines 32-42 Link Here
32
    <div id="toolbar" class="btn-toolbar">
32
    <div id="toolbar" class="btn-toolbar">
33
        <button class="btn btn-default" id="new-record" title="Open fresh record"><i class="fa fa-plus"></i> <span>New record</span></button>
33
        <button class="btn btn-default" id="new-record" title="Open fresh record"><i class="fa fa-plus"></i> <span>New record</span></button>
34
        <div class="btn-group">
34
        <div class="btn-group">
35
            <button class="btn btn-default" id="save-record" title="Save current record (Ctrl-S)"><i class="fa fa-hdd-o"></i> <span>Save</span></button>
35
            <button class="btn btn-default" id="save-record" title="Save current record (Ctrl-S)"><i class="fa fa-save"></i> <span>Save</span></button>
36
            <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
36
            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
37
            <span class="caret"></span>
37
            <ul id="save-dropdown" class="dropdown-menu">
38
            </button>
38
                <li><a id="save-with-override" href="#">Save overriding warnings</a></li>
39
            <ul class="dropdown-menu" id="save-dropdown">
40
            </ul>
39
            </ul>
41
        </div>
40
        </div>
42
        <button class="btn btn-default" id="import-records" title="Import an MARC (ISO 2709) or MARCXML record"><i class="fa fa-download"></i> <span>Import record...</span></button>
41
        <button class="btn btn-default" id="import-records" title="Import an MARC (ISO 2709) or MARCXML record"><i class="fa fa-download"></i> <span>Import record...</span></button>
Lines 63-68 Link Here
63
                        </a>
62
                        </a>
64
                    </li>
63
                    </li>
65
                [% END %]
64
                [% END %]
65
                <li><a id="open-batches" href="#">Import batches...</a></li>
66
                <li class="divider"></li>
66
                <li class="divider"></li>
67
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
67
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
68
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
68
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
Lines 114-126 Link Here
114
                    <select id="clipboard" name="clipboard" size=10>
114
                    <select id="clipboard" name="clipboard" size=10>
115
                    </select>
115
                    </select>
116
                </fieldset>
116
                </fieldset>
117
118
                <h3>Save to:</h3>
119
                <form id="save-targets">
120
                    <fieldset class="brief">
121
                        <ol></ol>
122
                    </fieldset>
123
                </form>
117
            </aside>
124
            </aside>
118
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
125
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
119
     </div> <!-- /.row -->
126
     </div> <!-- /.row -->
120
127
121
</div>
128
</div>
122
129
123
<div id="advanced-search-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
130
<div id="advanced-search-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
124
<div class="modal-dialog modal-lg">
131
<div class="modal-dialog modal-lg">
125
<div class="modal-content">
132
<div class="modal-content">
126
133
Lines 201-207 Link Here
201
</div>
208
</div>
202
</div>
209
</div>
203
210
204
<div id="search-results-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
211
<div id="search-results-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
205
<div class="modal-dialog modal-lg">
212
<div class="modal-dialog modal-lg">
206
<div class="modal-content">
213
<div class="modal-content">
207
214
Lines 248-254 Link Here
248
255
249
</div>
256
</div>
250
257
251
<div id="macro-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
258
<div id="macro-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
252
<div class="modal-dialog modal-lg">
259
<div class="modal-dialog modal-lg">
253
<div class="modal-content">
260
<div class="modal-content">
254
261
Lines 293-298 Link Here
293
    </div>
300
    </div>
294
</div>
301
</div>
295
302
303
<div id="batches-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="batches-title" aria-hidden="true">
304
305
<div class="modal-header">
306
    <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
307
    <h3 id="batches-title">Import batch settings</h3>
308
</div>
309
310
<div class="modal-body row-fluid">
311
    <div class="span9">
312
        <div id="toolbar" class="btn-toolbar">
313
            <button class="btn btn-small" type="submit" id="create-batch"><i class="icon-plus"></i> <span>Create new batch...</span></button>
314
            <button class="btn btn-small" type="submit" id="manage-batches"><i class="icon-list"></i> <span>Manage import batches...</span></button>
315
        </div>
316
        <ul id="batches-list"></ul>
317
    </div>
318
    <div class="span3">
319
    </div>
320
</div>
321
322
</div>
323
296
<div id="shortcuts-contents" style="display: none">
324
<div id="shortcuts-contents" style="display: none">
297
[% IF ( CAN_user_parameters_manage_keyboard_shortcuts ) %]
325
[% IF ( CAN_user_parameters_manage_keyboard_shortcuts ) %]
298
    <a id="redefine_shortcuts" href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Redefine shortcuts</a>
326
    <a id="redefine_shortcuts" href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Redefine shortcuts</a>
(-)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