Lines 22-60
Link Here
|
22 |
use Modern::Perl; |
22 |
use Modern::Perl; |
23 |
|
23 |
|
24 |
use CGI qw ( -utf8 ); |
24 |
use CGI qw ( -utf8 ); |
|
|
25 |
|
25 |
use C4::Auth qw( get_template_and_user haspermission ); |
26 |
use C4::Auth qw( get_template_and_user haspermission ); |
26 |
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers ); |
|
|
27 |
use C4::Biblio qw( |
28 |
GetFrameworkCode |
29 |
GetMarcFromKohaField |
30 |
GetMarcStructure |
31 |
IsMarcStructureInternal |
32 |
ModBiblio |
33 |
); |
34 |
use C4::Context; |
35 |
use C4::Circulation qw( barcodedecode LostItem ); |
36 |
use C4::Barcodes; |
37 |
use C4::Barcodes::ValueBuilder; |
27 |
use C4::Barcodes::ValueBuilder; |
|
|
28 |
use C4::Barcodes; |
29 |
use C4::Biblio qw( GetFrameworkCode GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal ModBiblio ); |
30 |
use C4::Circulation qw( barcodedecode LostItem ); |
31 |
use C4::Context; |
32 |
use C4::Members; |
33 |
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers ); |
34 |
use C4::Search qw( enabled_staff_search_views ); |
38 |
use Koha::Biblios; |
35 |
use Koha::Biblios; |
39 |
use Koha::Items; |
36 |
use Koha::Item::Templates; |
40 |
use Koha::ItemTypes; |
37 |
use Koha::ItemTypes; |
41 |
use Koha::Items; |
38 |
use Koha::Items; |
|
|
39 |
use Koha::Items; |
42 |
use Koha::Libraries; |
40 |
use Koha::Libraries; |
43 |
use Koha::Patrons; |
41 |
use Koha::Patrons; |
44 |
use Koha::SearchEngine::Indexer; |
42 |
use Koha::SearchEngine::Indexer; |
45 |
use C4::Search qw( enabled_staff_search_views ); |
|
|
46 |
use Storable qw( freeze thaw ); |
47 |
use URI::Escape qw( uri_escape_utf8 ); |
48 |
use C4::Members; |
49 |
use Koha::UI::Form::Builder::Item; |
43 |
use Koha::UI::Form::Builder::Item; |
50 |
use Koha::Result::Boolean; |
44 |
use Koha::Result::Boolean; |
51 |
|
45 |
|
52 |
use MARC::File::XML; |
|
|
53 |
use URI::Escape qw( uri_escape_utf8 ); |
54 |
use Encode qw( encode_utf8 ); |
46 |
use Encode qw( encode_utf8 ); |
55 |
use MIME::Base64 qw( decode_base64url encode_base64url ); |
|
|
56 |
use List::Util qw( first ); |
57 |
use List::MoreUtils qw( any uniq ); |
47 |
use List::MoreUtils qw( any uniq ); |
|
|
48 |
use List::Util qw( first ); |
49 |
use MARC::File::XML; |
50 |
use MIME::Base64 qw( decode_base64url encode_base64url ); |
51 |
use Storable qw( freeze thaw ); |
52 |
use URI::Escape qw( uri_escape_utf8 ); |
53 |
use URI::Escape qw( uri_escape_utf8 ); |
58 |
|
54 |
|
59 |
our $dbh = C4::Context->dbh; |
55 |
our $dbh = C4::Context->dbh; |
60 |
|
56 |
|
Lines 86-91
sub add_item_to_item_group {
Link Here
|
86 |
)->store(); |
82 |
)->store(); |
87 |
} |
83 |
} |
88 |
|
84 |
|
|
|
85 |
sub get_item_from_template { |
86 |
my ( $template_id ) = @_; |
87 |
|
88 |
my $template = Koha::Item::Templates->find($template_id); |
89 |
|
90 |
return $template->decoded_contents if $template; |
91 |
} |
92 |
|
89 |
sub get_item_from_cookie { |
93 |
sub get_item_from_cookie { |
90 |
my ( $input ) = @_; |
94 |
my ( $input ) = @_; |
91 |
|
95 |
|
Lines 175-186
my @errors; # store errors found while checking data BEFORE saving item.
Link Here
|
175 |
# Getting last created item cookie |
179 |
# Getting last created item cookie |
176 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
180 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
177 |
|
181 |
|
|
|
182 |
my $load_template_submit = $input->param('load_template_submit'); |
183 |
my $delete_template_submit = $input->param('delete_template_submit'); |
184 |
my $unload_template_submit = $input->param('unload_template_submit'); |
185 |
my $use_template_for_session = $input->param('use_template_for_session') || $input->cookie('ItemEditorSessionTemplateId'); |
186 |
my $template_id = $input->param('template_id') || $input->cookie('ItemEditorSessionTemplateId'); |
187 |
if ( $delete_template_submit ) { |
188 |
my $t = Koha::Item::Templates->find($template_id); |
189 |
$t->delete if $t && $t->borrowernumber eq $loggedinuser; |
190 |
$template_id = undef; |
191 |
$use_template_for_session = undef; |
192 |
} |
193 |
if ($load_template_submit || $unload_template_submit) { |
194 |
$op = q{} if $template_id; |
195 |
|
196 |
$template_id = undef if !$input->param('template_id'); |
197 |
$template_id = undef if $unload_template_submit; |
198 |
|
199 |
# Unset the cookie if either no template id as submitted, or "use for session" checkbox as unchecked |
200 |
my $cookie_value = $input->param('use_template_for_session') && $template_id ? $template_id : q{}; |
201 |
$use_template_for_session = $cookie_value; |
202 |
|
203 |
# Update the cookie |
204 |
my $template_cookie = $input->cookie( |
205 |
-name => 'ItemEditorSessionTemplateId', |
206 |
-value => $cookie_value, |
207 |
-HttpOnly => 1, |
208 |
-expires => '', |
209 |
-sameSite => 'Lax' |
210 |
); |
211 |
|
212 |
$cookie = [ $cookie, $template_cookie ]; |
213 |
} |
214 |
$template->param( |
215 |
template_id => $template_id, |
216 |
item_templates => Koha::Item::Templates->get_available($loggedinuser), |
217 |
use_template_for_session => $use_template_for_session, |
218 |
); |
219 |
|
178 |
#------------------------------------------------------------------------------- |
220 |
#------------------------------------------------------------------------------- |
179 |
if ($op eq "additem") { |
221 |
if ($op eq "additem") { |
180 |
|
222 |
|
181 |
my $add_submit = $input->param('add_submit'); |
223 |
my $add_submit = $input->param('add_submit'); |
182 |
my $add_duplicate_submit = $input->param('add_duplicate_submit'); |
224 |
my $add_duplicate_submit = $input->param('add_duplicate_submit'); |
183 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
225 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
|
|
226 |
my $save_as_template_submit = $input->param('save_as_template_submit'); |
184 |
my $number_of_copies = $input->param('number_of_copies'); |
227 |
my $number_of_copies = $input->param('number_of_copies'); |
185 |
|
228 |
|
186 |
my @columns = Koha::Items->columns; |
229 |
my @columns = Koha::Items->columns; |
Lines 226-233
if ($op eq "additem") {
Link Here
|
226 |
|
269 |
|
227 |
$item->barcode(barcodedecode($item->barcode)); |
270 |
$item->barcode(barcodedecode($item->barcode)); |
228 |
|
271 |
|
|
|
272 |
if ($save_as_template_submit) { |
273 |
my $template_name = $input->param('template_name'); |
274 |
my $template_is_shared = $input->param('template_is_shared'); |
275 |
my $replace_template_id = $input->param('replace_template_id'); |
276 |
|
277 |
if ($replace_template_id) { |
278 |
my $template = Koha::Item::Templates->find($replace_template_id); |
279 |
if ($template) { |
280 |
$template->update( |
281 |
{ |
282 |
id => $replace_template_id, |
283 |
is_shared => $template_is_shared ? 1 : 0, |
284 |
contents => $item->unblessed, |
285 |
} |
286 |
); |
287 |
} |
288 |
} |
289 |
else { |
290 |
my $template = Koha::Item::Template->new( |
291 |
{ |
292 |
name => $template_name, |
293 |
borrowernumber => $loggedinuser, |
294 |
is_shared => $template_is_shared ? 1 : 0, |
295 |
contents => $item->unblessed, |
296 |
} |
297 |
)->store(); |
298 |
} |
299 |
} |
229 |
# If we have to add or add & duplicate, we add the item |
300 |
# If we have to add or add & duplicate, we add the item |
230 |
if ( $add_submit || $add_duplicate_submit || $prefillitem) { |
301 |
elsif ( $add_submit || $add_duplicate_submit || $prefillitem) { |
231 |
|
302 |
|
232 |
# check for item barcode # being unique |
303 |
# check for item barcode # being unique |
233 |
if ( defined $item->barcode |
304 |
if ( defined $item->barcode |
Lines 591-603
my @header_value_loop = map {
Link Here
|
591 |
} sort keys %$subfieldcode_attribute_mappings; |
662 |
} sort keys %$subfieldcode_attribute_mappings; |
592 |
|
663 |
|
593 |
# Using last created item if it exists |
664 |
# Using last created item if it exists |
594 |
if ( $prefillitem |
665 |
if ( |
595 |
&& $op ne "additem" |
666 |
$op ne "additem" |
596 |
&& $op ne "edititem" |
667 |
&& $op ne "edititem" |
597 |
&& $op ne "dupeitem" ) |
668 |
&& $op ne "dupeitem" ) |
598 |
{ |
669 |
{ |
599 |
my $item_from_cookie = get_item_from_cookie($input); |
670 |
if ( $template_id ) { |
600 |
$current_item = $item_from_cookie if $item_from_cookie; |
671 |
my $item_from_template = get_item_from_template($template_id); |
|
|
672 |
$current_item = $item_from_template if $item_from_template; |
673 |
} |
674 |
elsif ( $prefillitem ) { |
675 |
my $item_from_cookie = get_item_from_cookie($input); |
676 |
$current_item = $item_from_cookie if $item_from_cookie; |
677 |
} |
601 |
} |
678 |
} |
602 |
|
679 |
|
603 |
if ( $current_item->{more_subfields_xml} ) { |
680 |
if ( $current_item->{more_subfields_xml} ) { |