4 [% PROCESS 'i18n.inc' %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>[% FILTER collapse %]
8 [% IF ( job_enqueued ) %]
9 [% t("Job enqueued") | html %] ›
11 [% IF ( import_batch_id ) %]
12 [% tx("Batch {batch_import_number}", { batch_import_number = import_batch_id }) | html %] ›
14 [% t("Manage staged MARC records") | html %] ›
15 [% t("Cataloging") | html %] ›
16 [% t("Koha") | html %]
18 [% INCLUDE 'doc-head-close.inc' %]
19 [% Asset.css("css/humanmsg.css") | $raw %]
21 span.change-status { font-style:italic; color:#666; display:none; }
22 ul.matches li { list-style-type:none; }
26 <body id="tools_manage-marc-import" class="tools">
27 [% WRAPPER 'header.inc' %]
28 [% INCLUDE 'cat-search.inc' %]
31 [% WRAPPER 'sub-header.inc' %]
32 [% WRAPPER breadcrumbs %]
33 [% WRAPPER breadcrumb_item %]
34 <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</a>
36 [% IF ( import_batch_id || job_enqueued ) %]
37 [% WRAPPER breadcrumb_item %]
38 <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a>
41 [% IF ( import_batch_id ) %]
42 [% WRAPPER breadcrumb_item bc_active= 1 %]
43 <span>Batch [% import_batch_id | html %]</span>
45 [% ELSIF ( job_enqueued ) %]
46 [% WRAPPER breadcrumb_item bc_active= 1 %]
47 [% t("Job enqueued") | html %]
50 [% WRAPPER breadcrumb_item bc_active= 1 %]
51 <span>Manage staged MARC records</span>
54 [% END #/ WRAPPER breadcrumbs %]
55 [% END #/ WRAPPER sub-header.inc %]
57 <div class="main container-fluid">
59 <div class="col-sm-10 col-sm-push-2">
61 <h1>Manage staged MARC records</h1>
62 [% IF ( import_batch_id ) %]
63 <h2>Batch [% import_batch_id | html %]</h2>
65 [% FOREACH message IN messages %]
66 [% IF message.type == 'success' %]
67 <div class="dialog message">
68 [% ELSIF message.type == 'warning' %]
69 <div class="dialog alert">
70 [% ELSIF message.type == 'error' %]
71 <div class="dialog alert" style="margin:auto;">
73 [% IF message.code == 'cannot_enqueue_job' %]
74 <span>Cannot enqueue this job.</span>
76 [% IF message.error %]
77 <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
83 <div class="dialog message">
84 <h1>The job has been enqueued!</h1>
85 <p>It will be processed as soon as possible.</p>
86 <p><a class="job_details" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]">View detail of the enqueued job</a>
89 [% ELSIF ( label_batch_msg ) %]
93 <div class="dialog message">
96 [% IF ( label_batch_msg == "error" ) %]
97 <span>Error attempting to create label batch. Please ask your system administrator to check the log for more details.</span>
99 <span>Label</span> <a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=edit&element_id=[% label_batch_msg | uri %]" >batch #[% label_batch_msg | html %]</a> created.
105 [% IF ( did_clean ) %]
106 <div class="dialog message">Cleaned import batch #[% import_batch_id | html %]</div>
109 [% IF ( did_delete ) %]
110 <div class="dialog message">Import batch deleted successfully</div>
113 [% UNLESS batch_list || batch_info || job_enqueued %]
114 <div class="dialog message">
115 <p>No records have been staged.</p>
116 <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
120 [% IF ( batch_info ) %]
121 [% IF ( can_commit ) %]
123 <input type="hidden" name="op" value="redo-matching" />
124 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
125 <input type="hidden" name="current_matcher_id" value="[% current_matcher_id | html %]" />
128 [% IF ( rematch_attempted ) %]
129 [% IF ( rematch_failed ) %]
130 <div class="dialog alert">Failed to apply different matching rule</div>
132 <div class="dialog message">Applied different matching rule. Number of records matched now
133 [% num_with_matches | html %]
138 [% IF ( changed_overlay_action ) %]
139 <div class="dialog message">Changed action if matching record found</div>
142 [% IF ( changed_nomatch_action ) %]
143 <div class="dialog message">Changed action if no match found</div>
146 [% IF ( changed_item_action ) %]
147 <div class="dialog message">Changed item processing option</div>
150 [% UNLESS job_enqueued %]
151 <fieldset class="rows" id="staged-record-matching-rules">
153 <li><span class="label">File name:</span> [% file_name | html %]</li>
154 <li><span class="label">Profile:</span> [% IF (profile) %][% profile | html %][% ELSE %](none)[% END %]</li>
155 <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments | html %][% ELSE %](none)[% END %]</li>
156 <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
157 <li><span class="label">Staged:</span> [% upload_timestamp | $KohaDates with_hours=1 %]</li>
158 <li><span class="label">Status:</span>
159 [% IF ( import_status == 'cleaned' ) %]
161 [% ELSIF ( import_status == 'imported' ) %]
162 <span>Imported</span>
163 [% ELSIF ( import_status == 'importing' ) %]
164 <span>Importing</span>
165 [% ELSIF ( import_status == 'reverted' ) %]
166 <span>Reverted</span>
167 [% ELSIF ( import_status == 'reverting' ) %]
168 <span>Reverting</span>
169 [% ELSIF ( import_status == 'staged' ) %]
172 [% import_status | html %]
177 <fieldset class="rows">
180 [% IF ( can_commit ) %]
181 <label for="new_matcher_id">Matching rule applied:</label>
182 <select name="new_matcher_id" id="new_matcher_id">
183 <option value="">Do not look for matching records</option>
184 [% FOREACH available_matcher IN available_matchers %]
185 [% IF ( available_matcher.selected ) %]
186 <option value="[% available_matcher.matcher_id | html %]" selected="selected">
187 [% available_matcher.code | html %] ([% available_matcher.description | html %])
190 <option value="[% available_matcher.matcher_id | html %]">
191 [% available_matcher.code | html %] ([% available_matcher.description | html %])
196 <span class="change-status">Changed. <a href="#" class="reset" id="reset_new_matcher_id">Reset</a></span>
198 <span class="label">Matching rule applied:</span>
199 [% IF ( current_matcher_id ) %]
200 [% current_matcher_code | html %] ([% current_matcher_description | html %])
202 <span>No matching rule in effect</span>
207 [% IF ( can_commit ) %]
208 <label for="overlay_action">Action if matching record found:</label>
209 [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>
211 <span class="label">Action if matching record found:</span>
212 [% IF ( overlay_action == 'replace' ) %]
213 <span>Replace existing record with incoming record</span>
214 [% ELSIF ( overlay_action == 'create_new' ) %]
215 <span>Add incoming record</span>
216 [% ELSIF ( overlay_action == 'ignore' ) %]
217 <span>Ignore incoming record (its items may still be processed)</span>
219 <span>[% overlay_action | html %]</span>
224 [% IF ( can_commit ) %]
225 <label for="nomatch_action">Action if no match found:</label>
226 [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>
228 <span class="label">Action if no match found:</span>
229 [% IF ( nomatch_action == 'create_new' ) %]
231 [% ELSIF ( nomatch_action == 'ignore' ) %]
232 Ignore incoming record (its items may still be processed)
234 [% nomatch_action | html %]
238 [% IF ( record_type == 'biblio' ) %]
240 [% IF ( can_commit ) %]
241 <label for="item_action">Item processing:</label>
242 [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>
244 <span class="label">Item processing:</span>
245 [% IF ( item_action == 'always_add' ) %]
246 <span>Always add items</span>
247 [% ELSIF ( item_action == 'add_only_for_matches' ) %]
248 <span>Add items only if matching bib was found</span>
249 [% ELSIF ( item_action == 'add_only_for_new' ) %]
250 <span>Add items only if no matching bib was found</span>
251 [% ELSIF ( item_action == 'ignore' ) %]
252 <span>Ignore items</span>
254 <span>[% item_action | html %]</span>
259 <input type ="hidden" name="item_action" value="ignore">
262 [% IF ( can_commit ) %]
263 <fieldset class="action"><input type="submit" class="btn btn-primary" value="Apply different matching rules" /></fieldset>
266 </fieldset> <!-- /#staged-record-matching-rules -->
269 [% IF ( can_commit ) %]
270 <form method="post" id="import_batch_form">
271 <input type="hidden" name="op" value="commit-batch" />
272 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
273 [% IF ( record_type != 'auth' ) %]
274 <fieldset class="rows">
277 <label for="frameworks">New record framework:</label>
278 <select name="framework" id="frameworks">
279 <option value="">Default</option>
280 [% FOREACH framework IN frameworks %]
281 <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
284 <div class="hint">New bibliographic records will use this framework</div>
287 <label for="overlay_framework">Replacement record framework:</label>
288 <select name="overlay_framework" id="overlay_frameworks">
289 <option value="_USE_ORIG_">Keep original framework</option>
290 <option value="">Default</option>
291 [% FOREACH framework IN frameworks %]
292 <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
295 <div class="hint">Replacement records will use this framework</div>
300 <fieldset class="action">
301 <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
303 </form> <!-- /#import_batch_form -->
304 [% END # /IF can_commit %]
305 [% IF ( can_revert ) %]
306 <form method="post" id="revert_batch_form">
307 <input type="hidden" name="op" value="revert-batch" />
308 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
309 <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" /></fieldset>
311 [% END # /IF can_revert %]
315 [% END # /IF batch_info %]
317 <br style="clear:both;" />
319 [% IF ( batch_list ) %]
321 [% PROCESS pagination %]
323 <div class="page-section">
324 <table class="dataTable">
340 [% FOREACH batch_lis IN batch_list %]
342 <td>[% batch_lis.import_batch_id | html %]</td>
343 <td><a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td>
344 <td>[% batch_lis.profile | html %]</td>
345 <td>[% batch_lis.comments | html %]</td>
346 <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
348 [% IF ( batch_lis.import_status == 'cleaned' ) %]
350 [% ELSIF ( batch_lis.import_status == 'imported' ) %]
351 <span>Imported</span>
352 [% ELSIF ( batch_lis.import_status == 'importing' ) %]
353 <span>Importing</span>
354 [% ELSIF ( batch_lis.import_status == 'reverted' ) %]
355 <span>Reverted</span>
356 [% ELSIF ( batch_lis.import_status == 'reverting' ) %]
357 <span>Reverting</span>
358 [% ELSIF ( batch_lis.import_status == 'staged' ) %]
361 <span>[% batch_lis.import_status | html %]</span>
364 <td>[% batch_lis.upload_timestamp | $KohaDates with_hours=1 %]</td>
365 <td>[% batch_lis.num_records | html %]</td>
366 <td>[% batch_lis.num_items | html %]
367 [% IF ( batch_lis.num_items && batch_lis.import_status == 'imported' ) %]
368 (<a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]&op=create_labels">Create label batch</a>)
372 [% IF ( batch_lis.can_clean ) %]
373 <form method="post" name="clean_batch_[% batch_lis.import_batch_id | html %]" id="clean_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_clean">
374 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
375 <input type="hidden" name="op" value="clean-batch" />
376 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-eraser"></i> Clean</button>
378 [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
379 <form method="post" action="/cgi-bin/koha/tools/manage-marc-import.pl" name="delete_batch_[% batch_lis.import_batch_id | html %]" id="delete_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_delete">
380 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
381 <input type="hidden" name="op" value="delete-batch" />
382 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-trash-can"></i> Delete</button>
387 [% END # /FOREACH batch_lis %]
390 </div> <!-- /.page-section -->
393 [% PROCESS pagination %]
395 [% END # /IF batch_lis %]
397 [% IF import_batch_id && !did_clean %]
398 <div class="page-section">
399 <table id="records-table">
406 <th>Match details</th>
407 <th><abbr title="Differences between the original bibliographic record and the imported">Diff</abbr></th>
414 <div id="marcPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
415 <div class="modal-dialog modal-wide">
416 <div class="modal-content">
417 <div class="modal-header">
418 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
419 <h3 id="marcPreviewLabel">MARC preview</h3>
421 <div class="modal-body">
422 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
424 <div class="modal-footer">
425 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
429 </div> <!-- /#marcPreview -->
430 [% END # /IF import_batch_id %]
433 </div> <!-- /.col-sm-10.col-sm-push-2 -->
434 <div class="col-sm-2 col-sm-pull-10">
436 [% INCLUDE 'cat-menu.inc' %]
438 </div> <!-- .col-sm-2.col-sm-pull-10 -->
439 </div> <!-- /.row -->
441 [% MACRO jsinclude BLOCK %]
442 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
443 [% INCLUDE 'datatables.inc' %]
445 $(document).ready(function() {
446 $("#staged-record-matching-rules select").change(function() {
447 var str = $(this).attr("id");
448 $("#reset_" + str).parent().show();
450 $("a.reset").click(function() {
451 var str = $(this).attr("id");
452 str = str.replace("reset_", "")
453 $("#" + str + " option[selected='selected']").attr("selected", "selected");
454 $(this).parent().hide();
457 [% IF import_batch_id %]
458 $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
463 "sAjaxSource": 'batch_records_ajax.pl',
464 "sPaginationType": "full_numbers",
465 "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
467 { "mDataProp": "import_record_id" },
468 { "mDataProp": "citation" },
469 { "mDataProp": "status" },
470 { "mDataProp": "overlay_status" },
471 { "mDataProp": null, "sDefaultContent": "" },
472 { "mDataProp": null, "sDefaultContent": "" },
473 { "mDataProp": "matched" }
475 "fnServerData": function(sSource, aoData, fnCallback) {
476 aoData.push({ "name": "import_batch_id", "value": [% import_batch_id | html %] });
483 'success': function(json) {
488 "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
489 [% IF(record_type == 'auth') %]
490 var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
492 var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
494 [% IF(record_type == 'auth') %]
495 var record_edit_url = "/cgi-bin/koha/authorities/authorities.pl?authid=";
497 var record_edit_url = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
500 var additional_details = "";
501 if( aData['author'] ){
502 additional_details += " " + aData['author'] + " ";
506 additional_details += " (" + aData['isbn'] + ") ";
510 additional_details += " (" + aData['issn'] + ") ";
513 $('td:eq(1)', nRow).html(
514 '<a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=' + aData['import_record_id'] + '&viewas=html" class="previewMARC">' + aData['citation'] + '</a> ' + additional_details
517 $('td:eq(2)', nRow).html(
518 aData['status'] == 'imported' ? _("Imported") :
519 aData['status'] == 'ignored' ? _("Ignored") :
520 aData['status'] == 'reverted' ? _("Reverted") :
521 aData['status'] == 'staged' ? _("Staged") :
522 aData['status'] == 'error' ? _("Error") :
526 $('td:eq(3)', nRow).html(
527 aData['overlay_status'] == 'no_match' ? _("No match") :
528 aData['overlay_status'] == 'match_applied' ? _("Match applied") :
529 aData['overlay_status'] == 'auto_match' ? _("Match found") :
530 aData['overlay_status']
533 if ( aData['matches'].length > 0 ) {
536 $('td:eq(4)', nRow).html('<ul class="matches"></ul>');
537 $('td:eq(5)', nRow).html('<ul class="matches"></ul>');
540 if( aData['status'] == "imported" || aData['status'] == "ignored" ){
541 disabled = ' disabled ';
543 aData['matches'].forEach(function(item,index){
544 if( item.chosen == 1 ){
545 checked = 'checked="checked"';
548 var match_option = "";
549 match_option = '<input type="radio" data-import_record_id="'+aData['import_record_id']+'" class="chosen" name="import_record_id_'+aData['import_record_id']+'_match" value="'+item.candidate_match_id+'" ' + checked + disabled + '> ';
551 var diff_url = '/cgi-bin/koha/tools/showdiffmarc.pl?batchid=%s&importid=%s&id=%s&type=%s';
552 var match_citation = '';
553 var matching_msg = '';
554 if ( item.record_type == 'auth' ){
555 matching_msg = _("Matches authority %s (score=%s):%s");
556 if( item.authorized_heading ){ match_citation += item.authorized_heading }
558 matching_msg = _("Matches bibliographic record %s (score=%s):%s");
559 if( item.title ){ match_citation += item.title + ' ' }
560 if( item.author ){ match_citation += item.author }
562 $('td:eq(4) ul', nRow).append('<li><label for="import_record_id_'+aData['import_record_id']+'_match_'+index+'">'+match_option+
563 matching_msg.format(item.candidate_match_id, item.score,
564 '<a target="_blank" href="' + record_details_url
565 + item.candidate_match_id + '">' + match_citation + '</a></label></li>')
567 $('td:eq(5) ul', nRow).append('<li><a href="'
568 + diff_url.format( [% import_batch_id | html %], aData['import_record_id'], item.candidate_match_id, item.record_type) + '">' + _("View") + '</a></li>');
571 if( !any_checked ){ checked = 'checked="checked"'; }
572 $('td:eq(4) ul', nRow).prepend('<li><label><input type="radio" data-import_record_id="'+aData['import_record_id']+'" class="chosen" name="import_record_id_'+aData['import_record_id']+'_match" value="none" ' + checked + disabled + ' > '+_("Ignore matches")+'</label></li>');
573 $('td:eq(5) ul', nRow).prepend('<li> </li>');
575 if (aData['diff_url']) {
576 $('td:eq(5)', nRow).html(
577 '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
580 if (aData['matched']) {
581 $('td:eq(6)', nRow).html(
582 '<a class="btn btn-default btn-xs" target="_blank" href="' + record_details_url
583 + aData['matched'] + '"><i class="fa-solid fa-eye"></i> ' + _("View") + '</a> '
584 [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
585 + '<a class="btn btn-default btn-xs" target="_blank" href="' + record_edit_url
586 + aData['matched'] + '"><i class="fa-solid fa-pencil" aria-hidden="true"></i> ' + _("Edit") + '</a>'
592 $("#revert_batch_form").on("submit", function() {
593 return confirm(_("Are you sure you want to undo the import of this batch into the catalog?"));
597 $("body").on("change", ".chosen", function(e) {
598 let apimethod = "DELETE";
600 if( $(this).val() != 'none' ){
602 apidata = JSON.stringify({ candidate_match_id: $(this).val() });
605 url: '/api/v1/import_batches/[% import_batch_id | html %]/records/'+$(this).data('import_record_id')+'/matches/chosen',
608 contentType: 'application/json'
609 }).fail(function(){ alert(_("Unable to update match choices")); return false; });
612 $("body").on("click", ".previewMARC", function(e) {
614 var ltitle = $(this).text();
615 var page = $(this).attr("href");
616 $("#marcPreviewLabel").text(ltitle);
617 $("#marcPreview .modal-body").load(page + " table");
618 $('#marcPreview').modal({ show: true });
620 $("#marcPreview").on("hidden.bs.modal", function() {
621 $("#marcPreviewLabel").html("");
622 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
624 $(".batch_form").on("submit", function() {
625 if ($(this).hasClass("batch_delete")) {
626 return confirm(_("Are you sure you want to permanently delete this batch?"));
628 return confirm(_("Clear all reservoir records staged in this batch? This cannot be undone."));
631 [% IF job_enqueued %]
633 function() { window.location.href=$('a.job_details').attr('href'); },
634 5000, // 5 secs to read
641 [% INCLUDE 'intranet-bottom.inc' %]
642 [% BLOCK pagination %]
644 <ul class="pagination">
645 [% FOREACH page IN pages %]
646 [% IF ( page.current_page && page.page_number > 1 ) %]
647 <li><a href="?offset=0" class="nav"><i class="fa fa-fw fa-angle-double-left"></i> First</a></li>
648 <li><a href="?offset=[% offset - results_per_page | uri %]"><i class="fa fa-fw fa-angle-left"></i> Previous</a></li>
651 [% FOREACH page IN pages %]
652 [% IF ( page.current_page ) %]
653 [% SET current_page = page.page_number %]
654 <li class="active"><span class="current">[% page.page_number | html %]</span></li>
656 <li><a class="nav" href="?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li>
659 [% IF ( current_page < pages.size() ) %]
661 <a href="?offset=[% offset + results_per_page | uri %]" class="nav">Next <i class="fa fa-fw fa-angle-right"></i></a>
664 <a href="?offset=[% ( results_per_page * ( pages.size - 1 ) ) | uri %]" class="nav">Last <i class="fa fa-fw fa-angle-double-right"></i></a>