3 # Bouzid Fergani, 2020 - inLibro
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use JSON qw( to_json );
23 use C4::Auth qw( check_cookie_auth );
24 use C4::Biblio qw( BiblioAutoLink TransformHtmlToMarc );
28 print $input->header('application/json');
30 # Check the user's permissions
31 my ( $auth_status, $auth_sessid ) =
32 C4::Auth::check_cookie_auth( $input->cookie('CGISESSID'), { editauthorities => 1, editcatalogue => 1 } );
33 if ( $auth_status ne "ok" ) {
34 print to_json( { status => 'UNAUTHORIZED' } );
38 # Link the biblio headings to authorities and return a json containing the status of all the links.
39 # Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
41 # tag = the tag number of the field
42 # authid = the value of the $9 subfield for this tag
43 # status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
47 my $record = TransformHtmlToMarc($input,1);
49 my ( $headings_changed, $results ) = BiblioAutoLink (
51 $input->param('frameworkcode'),
55 $json->{status} = 'OK';
56 $json->{links} = $results->{details} || '';