3 # Copyright 2013 C & P Bibliography Services
5 # This file is part of Koha.
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 2 of the License, or (at your option) any later
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.
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.
25 use C4::AuthoritiesMarc;
31 my @authid = $input->param('authid');
32 my $merge = $input->param('merge');
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "authorities/merge.tt",
42 flagsrequired => { editauthorities => 1 },
46 #------------------------
48 #------------------------
51 # Creating a new record from the html code
52 my $record = TransformHtmlToMarc($input);
53 my $recordid1 = $input->param('recordid1');
54 my $recordid2 = $input->param('recordid2');
55 my $typecode = $input->param('frameworkcode');
57 # Rewriting the leader
58 $record->leader( GetAuthority($recordid1)->leader() );
60 # Modifying the reference record
61 ModAuthority( $recordid1, $record, $typecode );
63 # Deleting the other record
64 if ( scalar(@errors) == 0 ) {
67 if ($input->param('mergereference') eq 'breeding') {
68 require C4::ImportBatch;
69 C4::ImportBatch::SetImportRecordStatus( $recordid2, 'imported' );
71 $error = (DelAuthority($recordid2) == 0);
73 push @errors, $error if ($error);
79 recordid1 => $recordid1
82 #-------------------------
83 # Show records to merge
84 #-------------------------
87 my $mergereference = $input->param('mergereference');
88 $template->{'VARS'}->{'mergereference'} = $mergereference;
90 if ( scalar(@authid) != 2 ) {
91 push @errors, { code => "WRONG_COUNT", value => scalar(@authid) };
94 my $recordObj1 = Koha::Authority->get_from_authid($authid[0]) || Koha::Authority->new();
97 if ($mergereference eq 'breeding') {
98 $recordObj2 = Koha::Authority->get_from_breeding($authid[1]) || Koha::Authority->new();
99 $mergereference = $authid[0];
101 $recordObj2 = Koha::Authority->get_from_authid($authid[1]) || Koha::Authority->new();
104 if ($mergereference) {
107 if ( $recordObj1->authtype ne $recordObj2->authtype && $mergereference ne 'breeding' ) {
108 $framework = $input->param('frameworkcode')
109 or push @errors, "Framework not selected.";
112 $framework = $recordObj1->authtype;
115 # Getting MARC Structure
116 my $tagslib = GetTagsLabels( 1, $framework );
117 foreach my $field ( keys %$tagslib ) {
118 if ( defined $tagslib->{$field}->{'tab'} && $tagslib->{$field}->{'tab'} eq ' ' ) {
119 $tagslib->{$field}->{'tab'} = 0;
124 ( $authid[0] == $mergereference )
128 # Creating a loop for display
130 my @record1 = $recordObj1->createMergeHash($tagslib);
131 my @record2 = $recordObj2->createMergeHash($tagslib);
135 recordid1 => $mergereference,
136 recordid2 => $notreference,
139 framework => $framework,
144 # Ask the user to choose which record will be the kept
146 choosereference => 1,
147 recordid1 => $authid[0],
148 recordid2 => $authid[1],
149 title1 => $recordObj1->authorized_heading,
150 title2 => $recordObj2->authorized_heading,
152 if ( $recordObj1->authtype ne $recordObj2->authtype ) {
153 my $frameworks = getauthtypes;
155 foreach my $thisframeworkcode ( keys %$frameworks ) {
157 value => $thisframeworkcode,
159 $frameworks->{$thisframeworkcode}->{'authtypetext'},
161 if ( $recordObj1->authtype eq $thisframeworkcode ) {
162 $row{'selected'} = 1;
164 push @frameworkselect, \%row;
167 frameworkselect => \@frameworkselect,
168 frameworkcode1 => $recordObj1->authtype,
169 frameworkcode2 => $recordObj2->authtype,
179 $template->param( errors => \@errors );
182 output_html_with_http_headers $input, $cookie, $template->output;
189 # ------------------------
191 # ------------------------