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

(-)a/C4/Biblio.pm (-18 / +23 lines)
Lines 320-326 sub ModBiblio { Link Here
320
    SetUTF8Flag($record);
320
    SetUTF8Flag($record);
321
    my $dbh = C4::Context->dbh;
321
    my $dbh = C4::Context->dbh;
322
322
323
    $frameworkcode = "" unless $frameworkcode;
323
    $frameworkcode = "" if !$frameworkcode || $frameworkcode eq "Default"; # XXX
324
324
325
    _strip_item_fields($record, $frameworkcode);
325
    _strip_item_fields($record, $frameworkcode);
326
326
Lines 1043-1051 for the given frameworkcode Link Here
1043
1043
1044
sub GetMarcFromKohaField {
1044
sub GetMarcFromKohaField {
1045
    my ( $kohafield, $frameworkcode ) = @_;
1045
    my ( $kohafield, $frameworkcode ) = @_;
1046
    return 0, 0 unless $kohafield and defined $frameworkcode;
1046
    return (0, undef) unless $kohafield and defined $frameworkcode;
1047
    my $relations = C4::Context->marcfromkohafield;
1047
    my $relations = C4::Context->marcfromkohafield;
1048
    return ( $relations->{$frameworkcode}->{$kohafield}->[0], $relations->{$frameworkcode}->{$kohafield}->[1] );
1048
    if ( my $mf = $relations->{$frameworkcode}->{$kohafield} ) {
1049
        return @$mf;
1050
    }
1051
    warn qq{No marc tags for framework "$frameworkcode" field $kohafield};
1052
    return (0, undef);
1049
}
1053
}
1050
1054
1051
=head2 GetMarcBiblio
1055
=head2 GetMarcBiblio
Lines 3179-3187 sub _koha_marc_update_bib_ids { Link Here
3179
    # we drop the original field
3183
    # we drop the original field
3180
    # we add the new builded field.
3184
    # we add the new builded field.
3181
    my ( $biblio_tag,     $biblio_subfield )     = GetMarcFromKohaField( "biblio.biblionumber",          $frameworkcode );
3185
    my ( $biblio_tag,     $biblio_subfield )     = GetMarcFromKohaField( "biblio.biblionumber",          $frameworkcode );
3186
    die qq{No biblionumber tag for framework "$frameworkcode"} unless $biblio_tag;
3182
    my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
3187
    my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
3188
    die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblio_tag;
3183
3189
3184
    if ( $biblio_tag != $biblioitem_tag ) {
3190
    if ( $biblio_tag == $biblioitem_tag ) {
3191
3192
        # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
3193
        my $new_field = MARC::Field->new(
3194
            $biblio_tag, '', '',
3195
            "$biblio_subfield"     => $biblionumber,
3196
            "$biblioitem_subfield" => $biblioitemnumber
3197
        );
3198
3199
        # drop old field and create new one...
3200
        my $old_field = $record->field($biblio_tag);
3201
        $record->delete_field($old_field) if $old_field;
3202
        $record->insert_fields_ordered($new_field);
3203
    } else {
3185
3204
3186
        # biblionumber & biblioitemnumber are in different fields
3205
        # biblionumber & biblioitemnumber are in different fields
3187
3206
Lines 3209-3228 sub _koha_marc_update_bib_ids { Link Here
3209
        $old_field = $record->field($biblioitem_tag);
3228
        $old_field = $record->field($biblioitem_tag);
3210
        $record->delete_field($old_field) if $old_field;
3229
        $record->delete_field($old_field) if $old_field;
3211
        $record->insert_fields_ordered($new_field);
3230
        $record->insert_fields_ordered($new_field);
3212
3213
    } else {
3214
3215
        # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
3216
        my $new_field = MARC::Field->new(
3217
            $biblio_tag, '', '',
3218
            "$biblio_subfield"     => $biblionumber,
3219
            "$biblioitem_subfield" => $biblioitemnumber
3220
        );
3221
3222
        # drop old field and create new one...
3223
        my $old_field = $record->field($biblio_tag);
3224
        $record->delete_field($old_field) if $old_field;
3225
        $record->insert_fields_ordered($new_field);
3226
    }
3231
    }
3227
}
3232
}
3228
3233
(-)a/cataloguing/merge.pl (-57 / +79 lines)
Lines 27-32 use C4::Auth; Link Here
27
use C4::Items;
27
use C4::Items;
28
use C4::Biblio;
28
use C4::Biblio;
29
use C4::Serials;
29
use C4::Serials;
30
use C4::Koha;
30
use C4::Reserves qw/MergeHolds/;
31
use C4::Reserves qw/MergeHolds/;
31
32
32
my $input = new CGI;
33
my $input = new CGI;
Lines 61-67 if ($merge) { Link Here
61
    # Rewriting the leader
62
    # Rewriting the leader
62
    $record->leader(GetMarcBiblio($tobiblio)->leader());
63
    $record->leader(GetMarcBiblio($tobiblio)->leader());
63
64
64
    my $frameworkcode = &GetFrameworkCode($tobiblio);
65
    my $frameworkcode = $input->param('frameworkcode');
65
    my @notmoveditems;
66
    my @notmoveditems;
66
67
67
    # Modifying the reference record
68
    # Modifying the reference record
Lines 108-184 if ($merge) { Link Here
108
	push @errors, $error if ($error); 
109
	push @errors, $error if ($error); 
109
    }
110
    }
110
111
111
    # Errors
112
    my @errors_loop  = map{{error => $_}}@errors;
113
114
    # Parameters
112
    # Parameters
115
    $template->param(
113
    $template->param(
116
	errors  => \@errors_loop,
117
	result => 1,
114
	result => 1,
118
	biblio1 => $input->param('biblio1')
115
	biblio1 => $input->param('biblio1')
119
    );
116
    );
120
117
121
122
#-------------------------
118
#-------------------------
123
# Show records to merge
119
# Show records to merge
124
#-------------------------
120
#-------------------------
125
} else {
121
} else {
126
127
    my $mergereference = $input->param('mergereference');
122
    my $mergereference = $input->param('mergereference');
128
    my $biblionumber = $input->param('biblionumber');
123
    my $biblionumber = $input->param('biblionumber');
129
124
130
    my $data1 = GetBiblioData($biblionumber[0]);
125
    if (scalar(@biblionumber) != 2) {
131
    my $data2 = GetBiblioData($biblionumber[1]);
126
        push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged.";
132
127
    }
133
    # Ask the user to choose which record will be the kept
128
    else {
134
    if (not $mergereference) {
129
        my $data1 = GetBiblioData($biblionumber[0]);
135
	$template->param(
130
        my $data2 = GetBiblioData($biblionumber[1]);
136
	    choosereference => 1,	
131
137
	    biblio1 => $biblionumber[0],
132
        # Checks if both records use the same framework
138
	    biblio2 => $biblionumber[1],
133
        my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]);
139
	    title1 => $data1->{'title'},
134
        my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]);
140
	    title2 => $data2->{'title'}
135
141
	    );
136
        if ($mergereference) {
142
    } else {
137
143
138
            my $framework;
144
	if (scalar(@biblionumber) != 2) {
139
            if ($frameworkcode1 ne $frameworkcode2) {
145
	    push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged.";
140
                $framework = $input->param('frameworkcode')
146
	}
141
                  or push @errors, "Famework not selected.";
147
142
            } else {
148
	# Checks if both records use the same framework
143
                $framework = $frameworkcode1;	
149
	my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]);
144
            }
150
	my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]);
145
151
	my $framework;
146
            # Getting MARC Structure
152
	if ($frameworkcode1 ne $frameworkcode2) {
147
            my $tagslib = GetMarcStructure(1, $framework);
153
	    push @errors, "The records selected for merging are using different frameworks. Currently merging is only available for records using the same framework.";
148
154
	} else {
149
            my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0];
155
	    $framework = $frameworkcode1;	
150
156
	}
151
            # Creating a loop for display
157
152
            my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib);
158
	# Getting MARC Structure
153
            my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib);
159
	my $tagslib = GetMarcStructure(1, $framework);
154
160
155
            # Parameters
161
	my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0];
156
            $template->param(
162
157
                biblio1 => $mergereference,
163
	# Creating a loop for display
158
                biblio2 => $notreference,
164
	my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib);
159
                mergereference => $mergereference,
165
	my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib);
160
                record1 => @record1,
166
161
                record2 => @record2,
167
	# Errors
162
                framework => $framework,
168
	my @errors_loop  = map{{error => $_}}@errors;
163
            );
169
164
        }
170
	# Parameters
165
        else {
171
	$template->param(
166
172
	    errors  => \@errors_loop,
167
        # Ask the user to choose which record will be the kept
173
	    biblio1 => $mergereference,
168
            $template->param(
174
	    biblio2 => $notreference,
169
                choosereference => 1,	
175
	    mergereference => $mergereference,
170
                biblio1 => $biblionumber[0],
176
	    record1 => @record1,
171
                biblio2 => $biblionumber[1],
177
	    record2 => @record2,
172
                title1 => $data1->{'title'},
178
	    framework => $framework
173
                title2 => $data2->{'title'}
179
	    );
174
            );
175
            if ($frameworkcode1 ne $frameworkcode2) {
176
                my $frameworks = getframeworks;
177
                my @frameworkselect;
178
                foreach my $thisframeworkcode ( keys %$frameworks ) {
179
                    my %row = (
180
                        value         => $thisframeworkcode,
181
                        frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
182
                    );
183
                    if ($frameworkcode1 eq $thisframeworkcode){
184
                        $row{'selected'} = 1;
185
                        }
186
                    push @frameworkselect, \%row;
187
                }
188
                $template->param(
189
                    frameworkselect => \@frameworkselect,
190
                    frameworkcode1 => $frameworkcode1,
191
                    frameworkcode2 => $frameworkcode2,
192
                );
193
            }
194
        }
180
    }
195
    }
181
}
196
}
197
198
if (@errors) {
199
    # Errors
200
    my @errors_loop  = map{{error => $_}}@errors;
201
    $template->param( errors  => \@errors_loop );
202
}
203
182
output_html_with_http_headers $input, $cookie, $template->output;
204
output_html_with_http_headers $input, $cookie, $template->output;
183
exit;
205
exit;
184
206
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-6 / +34 lines)
Lines 161-166 $(document).ready(function(){ Link Here
161
161
162
});
162
});
163
163
164
function changeFramework(fw) {
165
    $("#Frameworks").val(fw);
166
}
167
164
//]]>
168
//]]>
165
</script>
169
</script>
166
</head>
170
</head>
Lines 194-203 $(document).ready(function(){ Link Here
194
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
198
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
195
    <fieldset class="rows">
199
    <fieldset class="rows">
196
	<legend>Merge reference</legend>
200
	<legend>Merge reference</legend>
201
    <table>
202
      <tr>
203
        <td style="border-width: 0px; text-align: left">
197
	<ol>
204
	<ol>
198
	<li class="radio"><input type="radio" value="[% biblio1 %]" checked="checked" id="mergereference1" name="mergereference" /><label style="float:none" for="mergereference1">[% title1 %] ([% biblio1 %])</label></li>
205
	<li class="radio"><input type="radio" value="[% biblio1 %]" checked="checked" id="mergereference1" name="mergereference" onclick="changeFramework('[% frameworkcode1 %]')" /><label style="float:none" for="mergereference1">[% title1 %] ([% biblio1 %])</label></li>
199
	<li class="radio"><input type="radio" value="[% biblio2 %]" id="mergereference2" name="mergereference" /><label style="float:none" for="mergereference2">[% title2 %] ([% biblio2 %])</label></li>
206
	<li class="radio"><input type="radio" value="[% biblio2 %]" id="mergereference2" name="mergereference" onclick="changeFramework('[% frameworkcode2 %]')" /><label style="float:none" for="mergereference2">[% title2 %] ([% biblio2 %])</label></li>
200
</ol>
207
</ol>
208
        </td>
209
        <td style="border-width: 0px">
210
    [% IF frameworkselect %]
211
          <label style="float:none" for="frameworkcode">Framework:</label><br>
212
            <select name="frameworkcode" id="Frameworks">
213
                            <option value="Default">Default</option>
214
                            [% FOREACH frameworkcodeloo IN frameworkselect %]
215
                                [% IF ( frameworkcodeloo.selected ) %]
216
                                    <option value="[% frameworkcodeloo.value %]" selected="selected">
217
                                [% ELSE %]
218
                                    <option value="[% frameworkcodeloo.value %]">
219
                                [% END %]
220
                                 [% frameworkcodeloo.frameworktext %]                              
221
                                 </option>
222
                            [% END %]
223
            </select>
224
    [% END %]
225
        </td>
226
      </tr>
227
    </table>
228
201
	<input type="hidden" name="biblionumber" value="[% biblio1 %]" />
229
	<input type="hidden" name="biblionumber" value="[% biblio1 %]" />
202
	<input type="hidden" name="biblionumber" value="[% biblio2 %]" />
230
	<input type="hidden" name="biblionumber" value="[% biblio2 %]" />
203
	<fieldset class="action"><input type="submit" value="Next" /></fieldset>
231
	<fieldset class="action"><input type="submit" value="Next" /></fieldset>
Lines 332-345 $(document).ready(function(){ Link Here
332
		[% END %]
360
		[% END %]
333
361
334
	    </ul>
362
	    </ul>
363
</div>
364
</div> <!-- // #result -->
365
</div> <!-- .yui-u -->
335
366
336
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
367
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
337
<input type="hidden" name="biblio2" value="[% biblio2 %]" />
368
<input type="hidden" name="biblio2" value="[% biblio2 %]" />
338
<input type="hidden" name="mergereference" value="[% mergereference %]" />
369
<input type="hidden" name="mergereference" value="[% mergereference %]" />
370
<input type="hidden" name="frameworkcode" value="[% framework %]" />
339
371
340
</div>
341
</div> <!-- // #result -->
342
</div> <!-- .yui-u -->
343
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
372
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
344
</div>
373
</div>
345
</form>
374
</form>
346
- 

Return to bug 6210