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

(-)a/cataloguing/additem.pl (-201 / +234 lines)
Lines 26-32 use CGI qw ( -utf8 ); Link Here
26
use C4::Auth qw( get_template_and_user haspermission );
26
use C4::Auth qw( get_template_and_user haspermission );
27
use C4::Barcodes::ValueBuilder;
27
use C4::Barcodes::ValueBuilder;
28
use C4::Barcodes;
28
use C4::Barcodes;
29
use C4::Biblio qw( GetFrameworkCode GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal ModBiblio );
29
use C4::Biblio      qw( GetFrameworkCode GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal ModBiblio );
30
use C4::Circulation qw( barcodedecode LostItem );
30
use C4::Circulation qw( barcodedecode LostItem );
31
use C4::Context;
31
use C4::Context;
32
use C4::Members;
32
use C4::Members;
Lines 43-55 use Koha::SearchEngine::Indexer; Link Here
43
use Koha::UI::Form::Builder::Item;
43
use Koha::UI::Form::Builder::Item;
44
use Koha::Result::Boolean;
44
use Koha::Result::Boolean;
45
45
46
use Encode qw( encode_utf8 );
46
use Encode          qw( encode_utf8 );
47
use List::MoreUtils qw( any uniq );
47
use List::MoreUtils qw( any uniq );
48
use List::Util qw( first min );
48
use List::Util      qw( first min );
49
use MARC::File::XML;
49
use MARC::File::XML;
50
use MIME::Base64 qw( decode_base64url encode_base64url );
50
use MIME::Base64 qw( decode_base64url encode_base64url );
51
use Storable qw( freeze thaw );
51
use Storable     qw( freeze thaw );
52
use URI::Escape qw( uri_escape_utf8 );
52
use URI::Escape  qw( uri_escape_utf8 );
53
53
54
our $dbh = C4::Context->dbh;
54
our $dbh = C4::Context->dbh;
55
55
Lines 62-76 sub add_item_to_item_group { Link Here
62
    if ( $item_group eq 'create' ) {
62
    if ( $item_group eq 'create' ) {
63
        my $item_group = Koha::Biblio::ItemGroup->new(
63
        my $item_group = Koha::Biblio::ItemGroup->new(
64
            {
64
            {
65
                biblio_id   => $biblionumber,
65
                biblio_id     => $biblionumber,
66
                description => $item_group_description,
66
                description   => $item_group_description,
67
                display_order => $display_order,
67
                display_order => $display_order,
68
            }
68
            }
69
        )->store();
69
        )->store();
70
70
71
        $item_group_id = $item_group->id;
71
        $item_group_id = $item_group->id;
72
    }
72
    } else {
73
    else {
74
        $item_group_id = $item_group;
73
        $item_group_id = $item_group;
75
    }
74
    }
76
75
Lines 83-89 sub add_item_to_item_group { Link Here
83
}
82
}
84
83
85
sub get_item_from_template {
84
sub get_item_from_template {
86
    my ( $template_id ) = @_;
85
    my ($template_id) = @_;
87
86
88
    my $template = Koha::Item::Templates->find($template_id);
87
    my $template = Koha::Item::Templates->find($template_id);
89
88
Lines 91-97 sub get_item_from_template { Link Here
91
}
90
}
92
91
93
sub get_item_from_cookie {
92
sub get_item_from_cookie {
94
    my ( $input ) = @_;
93
    my ($input) = @_;
95
94
96
    my $item_from_cookie;
95
    my $item_from_cookie;
97
    my $lastitemcookie = $input->cookie('LastCreatedItem');
96
    my $lastitemcookie = $input->cookie('LastCreatedItem');
Lines 104-134 sub get_item_from_cookie { Link Here
104
        };
103
        };
105
        if ($@) {
104
        if ($@) {
106
            $lastitemcookie ||= 'undef';
105
            $lastitemcookie ||= 'undef';
107
            warn "Storable::thaw failed to thaw LastCreatedItem-cookie. Cookie value '".encode_base64url($lastitemcookie)."'. Caught error follows: '$@'";
106
            warn "Storable::thaw failed to thaw LastCreatedItem-cookie. Cookie value '"
107
                . encode_base64url($lastitemcookie)
108
                . "'. Caught error follows: '$@'";
108
        }
109
        }
109
    }
110
    }
110
    return $item_from_cookie;
111
    return $item_from_cookie;
111
}
112
}
112
113
113
my $input        = CGI->new;
114
my $input = CGI->new;
114
115
115
my $biblionumber;
116
my $biblionumber;
116
my $itemnumber;
117
my $itemnumber;
117
if( $input->param('itemnumber') && !$input->param('biblionumber') ){
118
if ( $input->param('itemnumber') && !$input->param('biblionumber') ) {
118
    $itemnumber = $input->param('itemnumber');
119
    $itemnumber = $input->param('itemnumber');
119
    my $item = Koha::Items->find( $itemnumber );
120
    my $item = Koha::Items->find($itemnumber);
120
    $biblionumber = $item->biblionumber;
121
    $biblionumber = $item->biblionumber;
121
} else {
122
} else {
122
    $biblionumber = $input->param('biblionumber');
123
    $biblionumber = $input->param('biblionumber');
123
    $itemnumber = $input->param('itemnumber');
124
    $itemnumber   = $input->param('itemnumber');
124
}
125
}
125
126
126
my $biblio = Koha::Biblios->find($biblionumber);
127
my $biblio = Koha::Biblios->find($biblionumber);
127
128
128
my $op           = $input->param('op') || q{};
129
my $op             = $input->param('op') || q{};
129
my $hostitemnumber = $input->param('hostitemnumber');
130
my $hostitemnumber = $input->param('hostitemnumber');
130
my $marcflavour  = C4::Context->preference("marcflavour");
131
my $marcflavour    = C4::Context->preference("marcflavour");
131
my $searchid     = $input->param('searchid');
132
my $searchid       = $input->param('searchid');
133
132
# fast cataloguing datas
134
# fast cataloguing datas
133
my $fa_circborrowernumber  = $input->param('circborrowernumber');
135
my $fa_circborrowernumber  = $input->param('circborrowernumber');
134
my $fa_barcode             = $input->param('barcode');
136
my $fa_barcode             = $input->param('barcode');
Lines 143-162 our $frameworkcode = &GetFrameworkCode($biblionumber); Link Here
143
145
144
# Defining which userflag is needing according to the framework currently used
146
# Defining which userflag is needing according to the framework currently used
145
my $userflags;
147
my $userflags;
146
if (defined $input->param('frameworkcode')) {
148
if ( defined $input->param('frameworkcode') ) {
147
    $userflags = ($input->param('frameworkcode') eq 'FA') ? "fast_cataloging" : "edit_items";
149
    $userflags = ( $input->param('frameworkcode') eq 'FA' ) ? "fast_cataloging" : "edit_items";
148
}
150
}
149
151
150
if (not defined $userflags) {
152
if ( not defined $userflags ) {
151
    $userflags = ($frameworkcode eq 'FA') ? "fast_cataloging" : "edit_items";
153
    $userflags = ( $frameworkcode eq 'FA' ) ? "fast_cataloging" : "edit_items";
152
}
154
}
153
155
154
my ($template, $loggedinuser, $cookie)
156
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
155
    = get_template_and_user({template_name => "cataloguing/additem.tt",
157
    {
156
                 query => $input,
158
        template_name => "cataloguing/additem.tt",
157
                 type => "intranet",
159
        query         => $input,
158
                 flagsrequired => {editcatalogue => $userflags},
160
        type          => "intranet",
159
                 });
161
        flagsrequired => { editcatalogue => $userflags },
162
    }
163
);
160
164
161
if ( $op eq 'edititem' || $op eq 'dupeitem' ) {
165
if ( $op eq 'edititem' || $op eq 'dupeitem' ) {
162
    my $item = Koha::Items->find($itemnumber);
166
    my $item = Koha::Items->find($itemnumber);
Lines 167-212 if ( $op eq 'edititem' || $op eq 'dupeitem' ) { Link Here
167
}
171
}
168
172
169
# Does the user have a restricted item editing permission?
173
# Does the user have a restricted item editing permission?
170
my $patron = Koha::Patrons->find( $loggedinuser );
174
my $patron = Koha::Patrons->find($loggedinuser);
171
175
172
my $item = $itemnumber ? Koha::Items->find( $itemnumber ) : undef;
176
my $item = $itemnumber ? Koha::Items->find($itemnumber) : undef;
173
if ( $item && !$patron->can_edit_items_from( $item->homebranch ) ) {
177
if ( $item && !$patron->can_edit_items_from( $item->homebranch ) ) {
174
    print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber");
178
    print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber");
175
    exit;
179
    exit;
176
}
180
}
177
181
178
my $uid = $patron->userid;
182
my $uid               = $patron->userid;
179
my $restrictededition = $uid ? haspermission($uid,  {'editcatalogue' => 'edit_items_restricted'}) : undef;
183
my $restrictededition = $uid ? haspermission( $uid, { 'editcatalogue' => 'edit_items_restricted' } ) : undef;
184
180
# In case user is a superlibrarian, editing is not restricted
185
# In case user is a superlibrarian, editing is not restricted
181
$restrictededition = 0 if ($restrictededition != 0 &&  C4::Context->IsSuperLibrarian());
186
$restrictededition = 0 if ( $restrictededition != 0 && C4::Context->IsSuperLibrarian() );
187
182
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted
188
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted
183
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'}));
189
$restrictededition = 0
190
    if ( $restrictededition != 0
191
    && $frameworkcode eq 'FA'
192
    && haspermission( $uid, { 'editcatalogue' => 'fast_cataloging' } ) );
184
193
185
our $tagslib = &GetMarcStructure(1,$frameworkcode);
194
our $tagslib = &GetMarcStructure( 1, $frameworkcode );
186
my $record = $biblio->metadata->record;
195
my $record = $biblio->metadata->record;
187
196
188
output_and_exit_if_error( $input, $cookie, $template,
197
output_and_exit_if_error(
189
    { module => 'cataloguing', record => $record } );
198
    $input, $cookie, $template,
199
    { module => 'cataloguing', record => $record }
200
);
190
201
191
my $current_item;
202
my $current_item;
192
my $nextop="cud-additem";
203
my $nextop = "cud-additem";
193
my @errors; # store errors found while checking data BEFORE saving item.
204
my @errors;    # store errors found while checking data BEFORE saving item.
194
205
195
# Getting last created item cookie
206
# Getting last created item cookie
196
my $prefillitem = C4::Context->preference('PrefillItem');
207
my $prefillitem = C4::Context->preference('PrefillItem');
197
208
198
my $load_template_submit = $input->param('load_template_submit');
209
my $load_template_submit   = $input->param('load_template_submit');
199
my $delete_template_submit = $input->param('delete_template_submit');
210
my $delete_template_submit = $input->param('delete_template_submit');
200
my $unload_template_submit = $input->param('unload_template_submit');
211
my $unload_template_submit = $input->param('unload_template_submit');
201
my $use_template_for_session = $input->param('use_template_for_session') || $input->cookie('ItemEditorSessionTemplateId');
212
my $use_template_for_session =
213
    $input->param('use_template_for_session') || $input->cookie('ItemEditorSessionTemplateId');
202
my $template_id = $input->param('template_id') || $input->cookie('ItemEditorSessionTemplateId');
214
my $template_id = $input->param('template_id') || $input->cookie('ItemEditorSessionTemplateId');
203
if ( $delete_template_submit ) {
215
if ($delete_template_submit) {
204
    my $t = Koha::Item::Templates->find($template_id);
216
    my $t = Koha::Item::Templates->find($template_id);
205
    $t->delete if $t && ( $t->patron_id eq $loggedinuser || haspermission( $uid, { 'editcatalogue' => 'manage_item_editor_templates' } ) );
217
    $t->delete
206
    $template_id = undef;
218
        if $t
219
        && ( $t->patron_id eq $loggedinuser
220
        || haspermission( $uid, { 'editcatalogue' => 'manage_item_editor_templates' } ) );
221
    $template_id              = undef;
207
    $use_template_for_session = undef;
222
    $use_template_for_session = undef;
208
}
223
}
209
if ($load_template_submit || $unload_template_submit) {
224
if ( $load_template_submit || $unload_template_submit ) {
210
    $op = q{} if $template_id;
225
    $op = q{} if $template_id;
211
226
212
    $template_id = undef if !$input->param('template_id');
227
    $template_id = undef if !$input->param('template_id');
Lines 228-291 if ($load_template_submit || $unload_template_submit) { Link Here
228
    $cookie = [ $cookie, $template_cookie ];
243
    $cookie = [ $cookie, $template_cookie ];
229
}
244
}
230
$template->param(
245
$template->param(
231
    template_id    => $template_id,
246
    template_id              => $template_id,
232
    item_templates => Koha::Item::Templates->get_available($loggedinuser),
247
    item_templates           => Koha::Item::Templates->get_available($loggedinuser),
233
    use_template_for_session => $use_template_for_session,
248
    use_template_for_session => $use_template_for_session,
234
);
249
);
235
250
236
#-------------------------------------------------------------------------------
251
#-------------------------------------------------------------------------------
237
if ($op eq "cud-additem") {
252
if ( $op eq "cud-additem" ) {
238
253
239
    my $add_submit                 = $input->param('add_submit');
254
    my $add_submit                 = $input->param('add_submit');
240
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
255
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
241
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
256
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
242
    my $save_as_template_submit    = $input->param('save_as_template_submit');
257
    my $save_as_template_submit    = $input->param('save_as_template_submit');
243
    my $number_of_copies           = min( scalar $input->param('number_of_copies') || 0, 1000 ); # TODO refine hardcoded maximum?
258
    my $number_of_copies = min( scalar $input->param('number_of_copies') || 0, 1000 );  # TODO refine hardcoded maximum?
244
259
245
    my @columns = Koha::Items->columns;
260
    my @columns = Koha::Items->columns;
246
    my $item = Koha::Item->new;
261
    my $item    = Koha::Item->new;
247
    $item->biblionumber($biblio->biblionumber);
262
    $item->biblionumber( $biblio->biblionumber );
248
    for my $c ( @columns ) {
263
    for my $c (@columns) {
249
        if ( $c eq 'more_subfields_xml' ) {
264
        if ( $c eq 'more_subfields_xml' ) {
250
            my @more_subfields_xml = $input->multi_param("items.more_subfields_xml");
265
            my @more_subfields_xml = $input->multi_param("items.more_subfields_xml");
251
            my @unlinked_item_subfields;
266
            my @unlinked_item_subfields;
252
            for my $subfield ( @more_subfields_xml ) {
267
            for my $subfield (@more_subfields_xml) {
253
                my $v = $input->param('items.more_subfields_xml_' . $subfield);
268
                my $v = $input->param( 'items.more_subfields_xml_' . $subfield );
254
                push @unlinked_item_subfields, $subfield, $v;
269
                push @unlinked_item_subfields, $subfield, $v;
255
            }
270
            }
256
            if ( @unlinked_item_subfields ) {
271
            if (@unlinked_item_subfields) {
257
                my $marc = MARC::Record->new();
272
                my $marc = MARC::Record->new();
273
258
                # use of tag 999 is arbitrary, and doesn't need to match the item tag
274
                # use of tag 999 is arbitrary, and doesn't need to match the item tag
259
                # used in the framework
275
                # used in the framework
260
                $marc->append_fields(MARC::Field->new('999', ' ', ' ', @unlinked_item_subfields));
276
                $marc->append_fields( MARC::Field->new( '999', ' ', ' ', @unlinked_item_subfields ) );
261
                $marc->encoding("UTF-8");
277
                $marc->encoding("UTF-8");
262
                $item->more_subfields_xml($marc->as_xml("USMARC"));
278
                $item->more_subfields_xml( $marc->as_xml("USMARC") );
263
                next;
279
                next;
264
            }
280
            }
265
            $item->more_subfields_xml(undef);
281
            $item->more_subfields_xml(undef);
266
        } else {
282
        } else {
267
            next if $c eq 'itemnumber';
283
            next if $c eq 'itemnumber';
268
            my @v = grep { $_ ne "" }
284
            my @v = grep { $_ ne "" } uniq $input->multi_param( "items." . $c );
269
                uniq $input->multi_param( "items." . $c );
270
285
271
            next unless @v;
286
            next unless @v;
272
287
273
            if ( $c eq 'permanent_location' ) { # See 27837
288
            if ( $c eq 'permanent_location' ) {    # See 27837
274
                $item->make_column_dirty('permanent_location');
289
                $item->make_column_dirty('permanent_location');
275
            }
290
            }
276
291
277
            $item->$c(join ' | ', @v);
292
            $item->$c( join ' | ', @v );
278
        }
293
        }
279
    }
294
    }
280
295
281
    # if autoBarcode is set to 'incremental', calculate barcode...
296
    # if autoBarcode is set to 'incremental', calculate barcode...
282
    my $submitted_barcode = $item->barcode;
297
    my $submitted_barcode = $item->barcode;
283
    if ( ! defined $item->barcode && C4::Context->preference('autoBarcode') eq 'incremental' ) {
298
    if ( !defined $item->barcode && C4::Context->preference('autoBarcode') eq 'incremental' ) {
284
        my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
299
        my ($barcode) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
285
        $item->barcode($barcode);
300
        $item->barcode($barcode);
286
    }
301
    }
287
302
288
    $item->barcode(barcodedecode($item->barcode));
303
    $item->barcode( barcodedecode( $item->barcode ) );
289
304
290
    if ($save_as_template_submit) {
305
    if ($save_as_template_submit) {
291
        my $template_name       = $input->param('template_name');
306
        my $template_name       = $input->param('template_name');
Lines 293-315 if ($op eq "cud-additem") { Link Here
293
        my $replace_template_id = $input->param('replace_template_id');
308
        my $replace_template_id = $input->param('replace_template_id');
294
309
295
        my $contents = $item->unblessed;
310
        my $contents = $item->unblessed;
296
        $contents->{barcode} = $submitted_barcode; # Don't save the autobarcode in the template
311
        $contents->{barcode} = $submitted_barcode;    # Don't save the autobarcode in the template
297
312
298
        if ($replace_template_id) {
313
        if ($replace_template_id) {
299
            my $template = Koha::Item::Templates->find($replace_template_id);
314
            my $template = Koha::Item::Templates->find($replace_template_id);
300
            $template->update(
315
            $template->update(
301
                {
316
                {
302
                    id             => $replace_template_id,
317
                    id        => $replace_template_id,
303
                    is_shared      => $template_is_shared ? 1 : 0,
318
                    is_shared => $template_is_shared ? 1 : 0,
304
                    contents       => $contents,
319
                    contents  => $contents,
305
                }
320
                }
306
            ) if $template && (
321
                )
307
                $template->patron_id eq $loggedinuser
322
                if $template
308
                ||
323
                && ( $template->patron_id eq $loggedinuser
309
                haspermission( $uid, { 'editcatalogue' => 'manage_item_editor_templates' } )
324
                || haspermission( $uid, { 'editcatalogue' => 'manage_item_editor_templates' } ) );
310
            );
325
        } else {
311
        }
312
        else {
313
            my $template = Koha::Item::Template->new(
326
            my $template = Koha::Item::Template->new(
314
                {
327
                {
315
                    name      => $template_name,
328
                    name      => $template_name,
Lines 320-327 if ($op eq "cud-additem") { Link Here
320
            )->store();
333
            )->store();
321
        }
334
        }
322
    }
335
    }
336
323
    # If we have to add or add & duplicate, we add the item
337
    # If we have to add or add & duplicate, we add the item
324
    elsif ( $add_submit || $add_duplicate_submit || $prefillitem) {
338
    elsif ( $add_submit || $add_duplicate_submit || $prefillitem ) {
325
339
326
        # check for item barcode # being unique
340
        # check for item barcode # being unique
327
        if ( defined $item->barcode
341
        if ( defined $item->barcode
Lines 330-340 if ($op eq "cud-additem") { Link Here
330
            # if barcode exists, don't create, but report The problem.
344
            # if barcode exists, don't create, but report The problem.
331
            push @errors, "barcode_not_unique";
345
            push @errors, "barcode_not_unique";
332
346
333
            $current_item = $item->unblessed; # Restore edit form for the same item
347
            $current_item = $item->unblessed;    # Restore edit form for the same item
334
        }
348
        }
335
        unless ( @errors ) {
349
        unless (@errors) {
336
            $item->store->discard_changes;
350
            $item->store->discard_changes;
337
            add_item_to_item_group( $item->biblionumber, $item->itemnumber, $item_group, $item_group_description, $display_order );
351
            add_item_to_item_group(
352
                $item->biblionumber, $item->itemnumber, $item_group, $item_group_description,
353
                $display_order
354
            );
338
355
339
            # This is a bit tricky : if there is a cookie for the last created item and
356
            # This is a bit tricky : if there is a cookie for the last created item and
340
            # we just added an item, the cookie value is not correct yet (it will be updated
357
            # we just added an item, the cookie value is not correct yet (it will be updated
Lines 343-355 if ($op eq "cud-additem") { Link Here
343
            # correct values.
360
            # correct values.
344
361
345
            # Pushing the last created item cookie back
362
            # Pushing the last created item cookie back
346
            if ( $prefillitem ) {
363
            if ($prefillitem) {
347
                my $last_created_item_cookie = $input->cookie(
364
                my $last_created_item_cookie = $input->cookie(
348
                    -name => 'LastCreatedItem',
365
                    -name => 'LastCreatedItem',
366
349
                    # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
367
                    # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
350
                    -value   => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ),
368
                    -value    => encode_base64url( freeze( { %{ $item->unblessed }, itemnumber => undef } ) ),
351
                    -HttpOnly => 1,
369
                    -HttpOnly => 1,
352
                    -expires => '',
370
                    -expires  => '',
353
                    -sameSite => 'Lax'
371
                    -sameSite => 'Lax'
354
                );
372
                );
355
373
Lines 362-378 if ($op eq "cud-additem") { Link Here
362
    }
380
    }
363
381
364
    # If we have to add & duplicate
382
    # If we have to add & duplicate
365
    if ($prefillitem || $add_duplicate_submit) {
383
    if ( $prefillitem || $add_duplicate_submit ) {
366
384
367
        $current_item = $item->unblessed;
385
        $current_item = $item->unblessed;
368
386
369
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
387
        if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
370
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
388
            my ($barcode) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
371
            $current_item->{barcode} = $barcode;
389
            $current_item->{barcode} = $barcode;
372
        }
390
        } else {
373
        else {
391
374
            # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
392
            # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
375
            $current_item->{barcode} = undef; # FIXME or delete?
393
            $current_item->{barcode} = undef;    # FIXME or delete?
376
        }
394
        }
377
395
378
        # Don't use the "prefill" feature if we want to generate the form with all the info from this item
396
        # Don't use the "prefill" feature if we want to generate the form with all the info from this item
Lines 396-403 if ($op eq "cud-additem") { Link Here
396
414
397
            push @errors, "no_next_barcode";
415
            push @errors, "no_next_barcode";
398
416
399
        }
417
        } else {
400
        else {
418
401
            # We add each item
419
            # We add each item
402
420
403
            # For the first iteration
421
            # For the first iteration
Lines 409-423 if ($op eq "cud-additem") { Link Here
409
                # If there is a barcode
427
                # If there is a barcode
410
                if ($barcodevalue) {
428
                if ($barcodevalue) {
411
429
412
# Getting a new barcode (if it is not the first iteration or the barcode we tried already exists)
430
                    # Getting a new barcode (if it is not the first iteration or the barcode we tried already exists)
413
                    $barcodevalue = $barcodeobj->next_value($oldbarcode)
431
                    $barcodevalue = $barcodeobj->next_value($oldbarcode)
414
                      if ( $i > 0 || $exist_itemnumber );
432
                        if ( $i > 0 || $exist_itemnumber );
415
433
416
                    # Putting it into the record
434
                    # Putting it into the record
417
                    if ($barcodevalue) {
435
                    if ($barcodevalue) {
418
                        if ( C4::Context->preference("autoBarcode") eq
436
                        if ( C4::Context->preference("autoBarcode") eq 'hbyymmincr' && $i > 0 )
419
                            'hbyymmincr' && $i > 0 )
437
                        {    # The first copy already contains the homebranch prefix
420
                        { # The first copy already contains the homebranch prefix
421
                             # This is terribly hacky but the easiest way to fix the way hbyymmincr is working
438
                             # This is terribly hacky but the easiest way to fix the way hbyymmincr is working
422
                             # Contrary to what one might think, the barcode plugin does not prefix the returned string with the homebranch
439
                             # Contrary to what one might think, the barcode plugin does not prefix the returned string with the homebranch
423
                             # For a single item, it is handled with some JS code (see cataloguing/value_builder/barcode.pl)
440
                             # For a single item, it is handled with some JS code (see cataloguing/value_builder/barcode.pl)
Lines 430-436 if ($op eq "cud-additem") { Link Here
430
                    }
447
                    }
431
448
432
                    # Checking if the barcode already exists
449
                    # Checking if the barcode already exists
433
                    $exist_itemnumber = Koha::Items->search({ barcode => $barcodevalue })->count;
450
                    $exist_itemnumber = Koha::Items->search( { barcode => $barcodevalue } )->count;
434
                }
451
                }
435
452
436
                # Updating record with the new copynumber
453
                # Updating record with the new copynumber
Lines 441-458 if ($op eq "cud-additem") { Link Here
441
                # Adding the item
458
                # Adding the item
442
                if ( !$exist_itemnumber ) {
459
                if ( !$exist_itemnumber ) {
443
                    delete $current_item->{itemnumber};
460
                    delete $current_item->{itemnumber};
444
                    $current_item = Koha::Item->new($current_item)->store(
461
                    $current_item = Koha::Item->new($current_item)->store( { skip_record_index => 1 } );
445
                        { skip_record_index => 1 } );
462
                    $current_item->discard_changes;    # Cannot chain discard_changes
446
                    $current_item->discard_changes; # Cannot chain discard_changes
447
                    $current_item = $current_item->unblessed;
463
                    $current_item = $current_item->unblessed;
448
                    add_item_to_item_group(
464
                    add_item_to_item_group(
449
                        $item->biblionumber, $item->itemnumber, $item_group,
465
                        $item->biblionumber,     $item->itemnumber, $item_group,
450
                        $item_group_description, $display_order
466
                        $item_group_description, $display_order
451
                    );
467
                    );
452
468
453
# We count the item only if it was really added
469
                    # We count the item only if it was really added
454
# That way, all items are added, even if there was some already existing barcodes
470
                    # That way, all items are added, even if there was some already existing barcodes
455
# FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode
471
                    # FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode
456
                    $i++;
472
                    $i++;
457
473
458
                    # Only increment copynumber if item was really added
474
                    # Only increment copynumber if item was really added
Lines 463-579 if ($op eq "cud-additem") { Link Here
463
                $oldbarcode = $barcodevalue;
479
                $oldbarcode = $barcodevalue;
464
            }
480
            }
465
481
466
            my $indexer = Koha::SearchEngine::Indexer->new(
482
            my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
467
                { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
483
            $indexer->index_records(
468
            $indexer->index_records( $biblionumber, "specialUpdate",
484
                $biblionumber, "specialUpdate",
469
                "biblioserver" );
485
                "biblioserver"
486
            );
470
487
471
            undef($current_item);
488
            undef($current_item);
472
        }
489
        }
473
    }
490
    }
474
    if ($frameworkcode eq 'FA' && $fa_circborrowernumber){
491
    if ( $frameworkcode eq 'FA' && $fa_circborrowernumber ) {
475
        print $input->redirect(
492
        print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?'
476
           '/cgi-bin/koha/circ/circulation.pl?'
493
                . 'borrowernumber='
477
           .'borrowernumber='.$fa_circborrowernumber
494
                . $fa_circborrowernumber
478
           .'&barcode='.uri_escape_utf8($fa_barcode)
495
                . '&barcode='
479
           .'&duedatespec='.$fa_duedatespec
496
                . uri_escape_utf8($fa_barcode)
480
           .'&stickyduedate='.$fa_stickyduedate
497
                . '&duedatespec='
481
        );
498
                . $fa_duedatespec
499
                . '&stickyduedate='
500
                . $fa_stickyduedate );
482
        exit;
501
        exit;
483
    }
502
    }
484
503
504
    #-------------------------------------------------------------------------------
505
} elsif ( $op eq "edititem" ) {
485
506
486
#-------------------------------------------------------------------------------
507
    #-------------------------------------------------------------------------------
487
} elsif ($op eq "edititem") {
508
    # retrieve item if exist => then, it's a modif
488
#-------------------------------------------------------------------------------
489
# retrieve item if exist => then, it's a modif
490
    $current_item = Koha::Items->find($itemnumber)->unblessed;
509
    $current_item = Koha::Items->find($itemnumber)->unblessed;
491
    $nextop       = "cud-saveitem";
510
    $nextop       = "cud-saveitem";
492
#-------------------------------------------------------------------------------
511
493
} elsif ($op eq "dupeitem") {
512
    #-------------------------------------------------------------------------------
494
#-------------------------------------------------------------------------------
513
} elsif ( $op eq "dupeitem" ) {
495
# retrieve item if exist => then, it's a modif
514
515
    #-------------------------------------------------------------------------------
516
    # retrieve item if exist => then, it's a modif
496
    $current_item = Koha::Items->find($itemnumber)->unblessed;
517
    $current_item = Koha::Items->find($itemnumber)->unblessed;
497
    if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
518
    if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
498
        my ($barcode) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
519
        my ($barcode) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
499
        $current_item->{barcode} = $barcode;
520
        $current_item->{barcode} = $barcode;
500
    }
521
    } else {
501
    else {
502
        $current_item->{barcode} = undef;    # Don't save it!
522
        $current_item->{barcode} = undef;    # Don't save it!
503
    }
523
    }
504
524
505
    $nextop = "cud-additem";
525
    $nextop = "cud-additem";
506
#-------------------------------------------------------------------------------
526
507
} elsif ($op eq "cud-delitem") {
527
    #-------------------------------------------------------------------------------
508
#-------------------------------------------------------------------------------
528
} elsif ( $op eq "cud-delitem" ) {
529
530
    #-------------------------------------------------------------------------------
509
    # check that there is no issue on this item before deletion.
531
    # check that there is no issue on this item before deletion.
510
    my $item = Koha::Items->find($itemnumber);
532
    my $item = Koha::Items->find($itemnumber);
511
    my $deleted;
533
    my $deleted;
512
    if( $item ) {
534
    if ($item) {
513
        $deleted = $item->safe_delete;
535
        $deleted = $item->safe_delete;
514
    } else {
536
    } else {
515
        $deleted = Koha::Result::Boolean->new(0)->add_message({ message => 'item_not_found' });
537
        $deleted = Koha::Result::Boolean->new(0)->add_message( { message => 'item_not_found' } );
516
    }
538
    }
517
    if ( $deleted ) {
539
    if ($deleted) {
518
        print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
540
        print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
519
        exit;
541
        exit;
520
    }
542
    } else {
521
    else {
522
        push @errors, @{ $deleted->messages }[0]->message;
543
        push @errors, @{ $deleted->messages }[0]->message;
523
        $nextop = "cud-additem";
544
        $nextop = "cud-additem";
524
    }
545
    }
525
#-------------------------------------------------------------------------------
546
526
} elsif ($op eq "cud-delallitems") {
547
    #-------------------------------------------------------------------------------
527
#-------------------------------------------------------------------------------
548
} elsif ( $op eq "cud-delallitems" ) {
528
    my $items = Koha::Items->search({ biblionumber => $biblionumber });
549
550
    #-------------------------------------------------------------------------------
551
    my $items = Koha::Items->search( { biblionumber => $biblionumber } );
529
    while ( my $item = $items->next ) {
552
    while ( my $item = $items->next ) {
530
        my $deleted = $item->safe_delete({ skip_record_index => 1 });
553
        my $deleted = $item->safe_delete( { skip_record_index => 1 } );
531
        push @errors, @{$deleted->messages}[0]->message unless $deleted;
554
        push @errors, @{ $deleted->messages }[0]->message unless $deleted;
532
    }
555
    }
533
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
556
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
534
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
557
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
535
    if ( @errors ) {
558
    if (@errors) {
536
        $nextop="cud-additem";
559
        $nextop = "cud-additem";
537
    } else {
560
    } else {
538
        my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
561
        my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
539
        my $views = { C4::Search::enabled_staff_search_views };
562
        my $views       = {C4::Search::enabled_staff_search_views};
540
        if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
563
        if ( $defaultview eq 'isbd' && $views->{can_view_ISBD} ) {
541
            print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
564
            print $input->redirect(
542
        } elsif  ($defaultview eq 'marc' && $views->{can_view_MARC}) {
565
                "/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
543
            print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
566
        } elsif ( $defaultview eq 'marc' && $views->{can_view_MARC} ) {
544
        } elsif  ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
567
            print $input->redirect(
545
            print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
568
                "/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
569
        } elsif ( $defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC} ) {
570
            print $input->redirect(
571
                "/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
546
        } else {
572
        } else {
547
            print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
573
            print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
548
        }
574
        }
549
        exit;
575
        exit;
550
    }
576
    }
551
#-------------------------------------------------------------------------------
577
552
} elsif ($op eq "cud-saveitem") {
578
    #-------------------------------------------------------------------------------
553
#-------------------------------------------------------------------------------
579
} elsif ( $op eq "cud-saveitem" ) {
580
581
    #-------------------------------------------------------------------------------
554
582
555
    my $itemnumber = $input->param('itemnumber');
583
    my $itemnumber = $input->param('itemnumber');
556
    my $item = Koha::Items->find($itemnumber);
584
    my $item       = Koha::Items->find($itemnumber);
557
    unless ($item) {
585
    unless ($item) {
558
        C4::Output::output_error( $input, '404' );
586
        C4::Output::output_error( $input, '404' );
559
        exit;
587
        exit;
560
    }
588
    }
561
    my $olditemlost = $item->itemlost;
589
    my $olditemlost = $item->itemlost;
562
    my @columns = Koha::Items->columns;
590
    my @columns     = Koha::Items->columns;
563
    my $new_values = $item->unblessed;
591
    my $new_values  = $item->unblessed;
564
    for my $c ( @columns ) {
592
    for my $c (@columns) {
565
        if ( $c eq 'more_subfields_xml' ) {
593
        if ( $c eq 'more_subfields_xml' ) {
566
            my @more_subfields_xml = $input->multi_param("items.more_subfields_xml");
594
            my @more_subfields_xml = $input->multi_param("items.more_subfields_xml");
567
            my @unlinked_item_subfields;
595
            my @unlinked_item_subfields;
568
            for my $subfield ( uniq @more_subfields_xml ) {
596
            for my $subfield ( uniq @more_subfields_xml ) {
569
                my @v = $input->multi_param('items.more_subfields_xml_' . encode_utf8($subfield));
597
                my @v = $input->multi_param( 'items.more_subfields_xml_' . encode_utf8($subfield) );
570
                push @unlinked_item_subfields, $subfield, $_ for @v;
598
                push @unlinked_item_subfields, $subfield, $_ for @v;
571
            }
599
            }
572
            if ( @unlinked_item_subfields ) {
600
            if (@unlinked_item_subfields) {
573
                my $marc = MARC::Record->new();
601
                my $marc = MARC::Record->new();
602
574
                # use of tag 999 is arbitrary, and doesn't need to match the item tag
603
                # use of tag 999 is arbitrary, and doesn't need to match the item tag
575
                # used in the framework
604
                # used in the framework
576
                $marc->append_fields(MARC::Field->new('999', ' ', ' ', @unlinked_item_subfields));
605
                $marc->append_fields( MARC::Field->new( '999', ' ', ' ', @unlinked_item_subfields ) );
577
                $marc->encoding("UTF-8");
606
                $marc->encoding("UTF-8");
578
                $new_values->{more_subfields_xml} = $marc->as_xml("USMARC");
607
                $new_values->{more_subfields_xml} = $marc->as_xml("USMARC");
579
                next;
608
                next;
Lines 583-589 if ($op eq "cud-additem") { Link Here
583
            my @v = map { ( defined $_ && $_ eq '' ) ? undef : $_ } $input->multi_param( "items." . $c );
612
            my @v = map { ( defined $_ && $_ eq '' ) ? undef : $_ } $input->multi_param( "items." . $c );
584
            next unless @v;
613
            next unless @v;
585
614
586
            if ( $c eq 'permanent_location' ) { # See 27837
615
            if ( $c eq 'permanent_location' ) {    # See 27837
587
                $item->make_column_dirty('permanent_location');
616
                $item->make_column_dirty('permanent_location');
588
            }
617
            }
589
618
Lines 605-615 if ($op eq "cud-additem") { Link Here
605
                itemnumber => { '!=' => $item->itemnumber }
634
                itemnumber => { '!=' => $item->itemnumber }
606
            }
635
            }
607
        )->count
636
        )->count
608
      )
637
        )
609
    {
638
    {
610
        # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
639
        # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
611
        push @errors,"barcode_not_unique";
640
        push @errors, "barcode_not_unique";
612
        $current_item = $item->unblessed; # Restore edit form for the same item
641
        $current_item = $item->unblessed;    # Restore edit form for the same item
613
    } else {
642
    } else {
614
        my $newitemlost = $item->itemlost;
643
        my $newitemlost = $item->itemlost;
615
        if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
644
        if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
Lines 618-645 if ($op eq "cud-additem") { Link Here
618
        $item->store;
647
        $item->store;
619
    }
648
    }
620
649
621
    $nextop="cud-additem";
650
    $nextop = "cud-additem";
622
} elsif ($op eq "delinkitem"){
651
} elsif ( $op eq "delinkitem" ) {
623
652
624
    my $analyticfield = '773';
653
    my $analyticfield = '773';
625
    if ($marcflavour  eq 'MARC21'){
654
    if ( $marcflavour eq 'MARC21' ) {
626
        $analyticfield = '773';
655
        $analyticfield = '773';
627
    } elsif ($marcflavour eq 'UNIMARC') {
656
    } elsif ( $marcflavour eq 'UNIMARC' ) {
628
        $analyticfield = '461';
657
        $analyticfield = '461';
629
    }
658
    }
630
    foreach my $field ($record->field($analyticfield)){
659
    foreach my $field ( $record->field($analyticfield) ) {
631
        if ($field->subfield('9') eq $hostitemnumber){
660
        if ( $field->subfield('9') eq $hostitemnumber ) {
632
            $record->delete_field($field);
661
            $record->delete_field($field);
633
            last;
662
            last;
634
        }
663
        }
635
    }
664
    }
636
	my $modbibresult = ModBiblio($record, $biblionumber,'');
665
    my $modbibresult = ModBiblio( $record, $biblionumber, '' );
637
}
666
}
638
667
639
# update OAI-PMH sets
668
# update OAI-PMH sets
640
if ($op) {
669
if ($op) {
641
    if (C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
670
    if ( C4::Context->preference("OAI-PMH:AutoUpdateSets") ) {
642
        C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record);
671
        C4::OAI::Sets::UpdateOAISetsBiblio( $biblionumber, $record );
643
    }
672
    }
644
}
673
}
645
674
Lines 653-659 if ($op) { Link Here
653
my @items;
682
my @items;
654
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
683
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
655
    my $i = $item->columns_to_str;
684
    my $i = $item->columns_to_str;
656
    $i->{nomod} = 1 unless $patron->can_edit_items_from($item->homebranch);
685
    $i->{nomod} = 1 unless $patron->can_edit_items_from( $item->homebranch );
657
    push @items, $i;
686
    push @items, $i;
658
}
687
}
659
688
Lines 669-682 for my $subfield_code ( keys %{ $tagslib->{$itemtagfield} } ) { Link Here
669
698
670
    my $subfield = $tagslib->{$itemtagfield}->{$subfield_code};
699
    my $subfield = $tagslib->{$itemtagfield}->{$subfield_code};
671
700
672
    next if IsMarcStructureInternal( $subfield );
701
    next if IsMarcStructureInternal($subfield);
673
    next unless $subfield->{tab} eq 10; # Is this really needed?
702
    next unless $subfield->{tab} eq 10;    # Is this really needed?
674
703
675
    my $attribute;
704
    my $attribute;
676
    if ( $subfield->{kohafield} ) {
705
    if ( $subfield->{kohafield} ) {
677
        ( $attribute = $subfield->{kohafield} ) =~ s|^items\.||;
706
        ( $attribute = $subfield->{kohafield} ) =~ s|^items\.||;
678
    } else {
707
    } else {
679
        $attribute = $subfield_code; # It's in more_subfields_xml
708
        $attribute = $subfield_code;       # It's in more_subfields_xml
680
    }
709
    }
681
    next unless grep { $attribute eq $_ } @witness_attributes;
710
    next unless grep { $attribute eq $_ } @witness_attributes;
682
    $subfieldcode_attribute_mappings->{$subfield_code} = $attribute;
711
    $subfieldcode_attribute_mappings->{$subfield_code} = $attribute;
Lines 691-714 my @header_value_loop = map { Link Here
691
} sort keys %$subfieldcode_attribute_mappings;
720
} sort keys %$subfieldcode_attribute_mappings;
692
721
693
# Using last created item if it exists
722
# Using last created item if it exists
694
if (
723
if (   $op ne "cud-additem"
695
    $op ne "cud-additem"
696
    && $op ne "edititem"
724
    && $op ne "edititem"
697
    && $op ne "dupeitem" )
725
    && $op ne "dupeitem" )
698
{
726
{
699
    if ( $template_id ) {
727
    if ($template_id) {
700
        my $item_from_template = get_item_from_template($template_id);
728
        my $item_from_template = get_item_from_template($template_id);
701
        $current_item = $item_from_template if $item_from_template;
729
        $current_item = $item_from_template if $item_from_template;
702
    }
730
    } elsif ($prefillitem) {
703
    elsif ( $prefillitem ) {
704
        my $item_from_cookie = get_item_from_cookie($input);
731
        my $item_from_cookie = get_item_from_cookie($input);
705
        $current_item = $item_from_cookie if $item_from_cookie;
732
        $current_item = $item_from_cookie if $item_from_cookie;
706
    }
733
    }
707
}
734
}
708
735
709
if ( $current_item->{more_subfields_xml} ) {
736
if ( $current_item->{more_subfields_xml} ) {
737
710
    # FIXME Use Maybe MARC::Record::new_from_xml if encoding issues on subfield (??)
738
    # FIXME Use Maybe MARC::Record::new_from_xml if encoding issues on subfield (??)
711
    $current_item->{marc_more_subfields_xml} = MARC::Record->new_from_xml($current_item->{more_subfields_xml}, 'UTF-8');
739
    $current_item->{marc_more_subfields_xml} =
740
        MARC::Record->new_from_xml( $current_item->{more_subfields_xml}, 'UTF-8' );
712
}
741
}
713
742
714
my $branchcode = $input->param('branch') || C4::Context->userenv->{branch};
743
my $branchcode = $input->param('branch') || C4::Context->userenv->{branch};
Lines 718-732 my $branchcode = $input->param('branch') || C4::Context->userenv->{branch}; Link Here
718
# If the subfield must be prefilled with last catalogued item
747
# If the subfield must be prefilled with last catalogued item
719
my @subfields_to_prefill;
748
my @subfields_to_prefill;
720
if ( $nextop eq 'cud-additem' && $op ne 'dupeitem' && $prefillitem ) {
749
if ( $nextop eq 'cud-additem' && $op ne 'dupeitem' && $prefillitem ) {
721
    @subfields_to_prefill = split(' ', C4::Context->preference('SubfieldsToUseWhenPrefill'));
750
    @subfields_to_prefill = split( ' ', C4::Context->preference('SubfieldsToUseWhenPrefill') );
722
}
751
}
723
752
724
# Getting list of subfields to keep when restricted editing is enabled
753
# Getting list of subfields to keep when restricted editing is enabled
725
my @subfields_to_allow = $restrictededition ? split ' ', C4::Context->preference('SubfieldsToAllowForRestrictedEditing') : ();
754
my @subfields_to_allow =
755
    $restrictededition
756
    ? split ' ', C4::Context->preference('SubfieldsToAllowForRestrictedEditing')
757
    : ();
726
758
727
my $subfields =
759
my $subfields =
728
  Koha::UI::Form::Builder::Item->new(
760
    Koha::UI::Form::Builder::Item->new( { biblionumber => $biblionumber, item => $current_item } )->edit_form(
729
    { biblionumber => $biblionumber, item => $current_item } )->edit_form(
730
    {
761
    {
731
        branchcode           => $branchcode,
762
        branchcode           => $branchcode,
732
        restricted_editition => $restrictededition,
763
        restricted_editition => $restrictededition,
Lines 741-784 my $subfields = Link Here
741
            : ()
772
            : ()
742
        ),
773
        ),
743
        prefill_with_default_values => 1,
774
        prefill_with_default_values => 1,
744
        branch_limit => C4::Context->userenv->{"branch"},
775
        branch_limit                => C4::Context->userenv->{"branch"},
745
        (
776
        (
746
            $op eq 'dupeitem'
777
            $op eq 'dupeitem'
747
            ? ( ignore_invisible_subfields => 1 )
778
            ? ( ignore_invisible_subfields => 1 )
748
            : ()
779
            : ()
749
        ),
780
        ),
750
    }
781
    }
751
);
782
    );
752
783
753
if (   $frameworkcode eq 'FA' ) {
784
if ( $frameworkcode eq 'FA' ) {
754
    my ( $barcode_field ) = grep {$_->{kohafield} eq 'items.barcode'} @$subfields;
785
    my ($barcode_field) = grep { $_->{kohafield} eq 'items.barcode' } @$subfields;
755
    $barcode_field->{marc_value}->{value} ||= $input->param('barcode');
786
    $barcode_field->{marc_value}->{value} ||= $input->param('barcode');
756
}
787
}
757
788
758
if( my $default_location = C4::Context->preference('NewItemsDefaultLocation') ) {
789
if ( my $default_location = C4::Context->preference('NewItemsDefaultLocation') ) {
759
    my ( $location_field ) = grep {$_->{kohafield} eq 'items.location'} @$subfields;
790
    my ($location_field) = grep { $_->{kohafield} eq 'items.location' } @$subfields;
760
    $location_field->{marc_value}->{value} ||= $default_location;
791
    $location_field->{marc_value}->{value} ||= $default_location;
761
}
792
}
762
793
763
my @ig = Koha::Biblio::ItemGroups->search({ biblio_id => $biblionumber })->as_list();
794
my @ig = Koha::Biblio::ItemGroups->search( { biblio_id => $biblionumber } )->as_list();
795
764
#sort by display order
796
#sort by display order
765
my @sorted_ig = sort { $a->display_order <=> $b->display_order } @ig;
797
my @sorted_ig = sort { $a->display_order <=> $b->display_order } @ig;
798
766
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
799
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
767
$template->param(
800
$template->param(
768
    biblio       => $biblio,
801
    biblio           => $biblio,
769
    items        => \@items,
802
    items            => \@items,
770
    item_groups      => \@sorted_ig,
803
    item_groups      => \@sorted_ig,
771
    item_header_loop => \@header_value_loop,
804
    item_header_loop => \@header_value_loop,
772
    subfields        => $subfields,
805
    subfields        => $subfields,
773
    itemnumber       => $itemnumber,
806
    itemnumber       => $itemnumber,
774
    barcode          => $current_item->{barcode},
807
    barcode          => $current_item->{barcode},
775
    op      => $nextop,
808
    op               => $nextop,
776
    popup => scalar $input->param('popup') ? 1: 0,
809
    popup            => scalar $input->param('popup') ? 1 : 0,
777
    C4::Search::enabled_staff_search_views,
810
    C4::Search::enabled_staff_search_views,
778
);
811
);
779
$template->{'VARS'}->{'searchid'} = $searchid;
812
$template->{'VARS'}->{'searchid'} = $searchid;
780
813
781
if ($frameworkcode eq 'FA'){
814
if ( $frameworkcode eq 'FA' ) {
815
782
    # fast cataloguing datas
816
    # fast cataloguing datas
783
    $template->param(
817
    $template->param(
784
        'circborrowernumber' => $fa_circborrowernumber,
818
        'circborrowernumber' => $fa_circborrowernumber,
Lines 790-795 if ($frameworkcode eq 'FA'){ Link Here
790
}
824
}
791
825
792
foreach my $error (@errors) {
826
foreach my $error (@errors) {
793
    $template->param($error => 1);
827
    $template->param( $error => 1 );
794
}
828
}
795
output_html_with_http_headers $input, $cookie, $template->output;
829
output_html_with_http_headers $input, $cookie, $template->output;
796
- 

Return to bug 36498