Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2024 Aleisha Amohia <aleisha@catalyst.net.nz> |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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>. |
19 |
|
20 |
use Modern::Perl; |
21 |
use CGI qw ( -utf8 ); |
22 |
|
23 |
use C4::Auth qw( get_template_and_user ); |
24 |
use C4::Output qw( output_html_with_http_headers ); |
25 |
use Koha::AuthorisedValues; |
26 |
|
27 |
=head1 DESCRIPTION |
28 |
|
29 |
This plugin allows the cataloguer to choose one or more authorised value categories that should be available for selection in the dropdown for this subfield. |
30 |
|
31 |
=cut |
32 |
|
33 |
my $builder = sub { |
34 |
my ( $params ) = @_; |
35 |
my $res = qq{ |
36 |
<script> |
37 |
function Click$params->{id}(ev) { |
38 |
ev.preventDefault(); |
39 |
var code = document.getElementById(ev.data.id); |
40 |
\$.ajax({ |
41 |
url: '/cgi-bin/koha/cataloguing/plugin_launcher.pl', |
42 |
type: 'POST', |
43 |
data: { |
44 |
'plugin_name': 'multipleAV.pl', |
45 |
'code' : code.value, |
46 |
}, |
47 |
success: function(data){ |
48 |
var field = document.getElementById(ev.data.id); |
49 |
field.value = data; |
50 |
return 1; |
51 |
} |
52 |
}); |
53 |
} |
54 |
</script> |
55 |
}; |
56 |
|
57 |
return $res; |
58 |
}; |
59 |
|
60 |
my $launcher = sub { |
61 |
my ( $params ) = @_; |
62 |
my $input = $params->{cgi}; |
63 |
my $code = $input->param('code'); |
64 |
|
65 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
66 |
{ template_name => "cataloguing/value_builder/ajax.tt", |
67 |
query => $input, |
68 |
type => "intranet", |
69 |
flagsrequired => { editcatalogue => '*' }, |
70 |
} |
71 |
); |
72 |
|
73 |
# If a prefix is submited, we look for the highest stocknumber with this prefix, and return it incremented |
74 |
$code =~ s/ *$//g; |
75 |
if ( $code =~ m/^[a-zA-Z]+$/ ) { |
76 |
my $av = Koha::AuthorisedValues->find({ |
77 |
'category' => 'INVENTORY', |
78 |
'authorised_value' => $code |
79 |
}); |
80 |
if ( $av ) { |
81 |
$av->lib($av->lib + 1); |
82 |
$av->store; |
83 |
$template->param( return => $code . ' ' . sprintf( '%010s', ( $av->lib ) ), ); |
84 |
} else { |
85 |
$template->param( return => "There is no defined value for $code"); |
86 |
} |
87 |
# The user entered a custom value, we don't touch it, this could be handled in js |
88 |
} else { |
89 |
$template->param( return => $code, ); |
90 |
} |
91 |
|
92 |
output_html_with_http_headers $input, $cookie, $template->output; |
93 |
}; |
94 |
|
95 |
return { builder => $builder, launcher => $launcher }; |