Lines 69-75
my $input = new CGI;
Link Here
|
69 |
my $searchfield = $input->param('description'); |
69 |
my $searchfield = $input->param('description'); |
70 |
my $script_name = "/cgi-bin/koha/admin/itemtypes.pl"; |
70 |
my $script_name = "/cgi-bin/koha/admin/itemtypes.pl"; |
71 |
my $itemtype = $input->param('itemtype'); |
71 |
my $itemtype = $input->param('itemtype'); |
72 |
my $op = $input->param('op'); |
72 |
my $op = $input->param('op') // 'list'; |
|
|
73 |
my @messages; |
73 |
$searchfield =~ s/\,//g; |
74 |
$searchfield =~ s/\,//g; |
74 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
75 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
75 |
{ |
76 |
{ |
Lines 85-92
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Link Here
|
85 |
$template->param(script_name => $script_name); |
86 |
$template->param(script_name => $script_name); |
86 |
if ($op) { |
87 |
if ($op) { |
87 |
$template->param($op => 1); # we show only the TMPL_VAR names $op |
88 |
$template->param($op => 1); # we show only the TMPL_VAR names $op |
88 |
} else { |
|
|
89 |
$template->param(else => 1); |
90 |
} |
89 |
} |
91 |
|
90 |
|
92 |
my $dbh = C4::Context->dbh; |
91 |
my $dbh = C4::Context->dbh; |
Lines 132-145
if ( $op eq 'add_form' ) {
Link Here
|
132 |
# called by add_form, used to insert/modify data in DB |
131 |
# called by add_form, used to insert/modify data in DB |
133 |
} |
132 |
} |
134 |
elsif ( $op eq 'add_validate' ) { |
133 |
elsif ( $op eq 'add_validate' ) { |
135 |
my $query = " |
134 |
my $is_a_modif = $input->param('is_a_modif'); |
|
|
135 |
my ( $already_exists ) = $dbh->selectrow_array(q| |
136 |
SELECT itemtype |
136 |
SELECT itemtype |
137 |
FROM itemtypes |
137 |
FROM itemtypes |
138 |
WHERE itemtype = ? |
138 |
WHERE itemtype = ? |
139 |
"; |
139 |
|, undef, $itemtype ); |
140 |
my $sth = $dbh->prepare($query); |
140 |
if ( $already_exists and $is_a_modif ) { # it's a modification |
141 |
$sth->execute($itemtype); |
|
|
142 |
if ( $sth->fetchrow ) { # it's a modification |
143 |
my $query2 = ' |
141 |
my $query2 = ' |
144 |
UPDATE itemtypes |
142 |
UPDATE itemtypes |
145 |
SET description = ? |
143 |
SET description = ? |
Lines 152-158
elsif ( $op eq 'add_validate' ) {
Link Here
|
152 |
, sip_media_type = ? |
150 |
, sip_media_type = ? |
153 |
WHERE itemtype = ? |
151 |
WHERE itemtype = ? |
154 |
'; |
152 |
'; |
155 |
$sth = $dbh->prepare($query2); |
153 |
my $sth = $dbh->prepare($query2); |
156 |
$sth->execute( |
154 |
$sth->execute( |
157 |
$input->param('description'), |
155 |
$input->param('description'), |
158 |
$input->param('rentalcharge'), |
156 |
$input->param('rentalcharge'), |
Lines 171-177
elsif ( $op eq 'add_validate' ) {
Link Here
|
171 |
$input->param('itemtype') |
169 |
$input->param('itemtype') |
172 |
); |
170 |
); |
173 |
} |
171 |
} |
174 |
else { # add a new itemtype & not modif an old |
172 |
elsif ( not $already_exists and not $is_a_modif ) { |
175 |
my $query = " |
173 |
my $query = " |
176 |
INSERT INTO itemtypes |
174 |
INSERT INTO itemtypes |
177 |
(itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type) |
175 |
(itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type) |
Lines 194-203
elsif ( $op eq 'add_validate' ) {
Link Here
|
194 |
$sip_media_type, |
192 |
$sip_media_type, |
195 |
); |
193 |
); |
196 |
} |
194 |
} |
|
|
195 |
else { |
196 |
push @messages, { |
197 |
type => 'error', |
198 |
code => 'already_exists', |
199 |
}; |
200 |
} |
197 |
|
201 |
|
198 |
print $input->redirect('itemtypes.pl'); |
202 |
$searchfield = ''; |
199 |
exit; |
203 |
$op = 'list'; |
200 |
|
|
|
201 |
# END $OP eq ADD_VALIDATE |
204 |
# END $OP eq ADD_VALIDATE |
202 |
################## DELETE_CONFIRM ################################## |
205 |
################## DELETE_CONFIRM ################################## |
203 |
# called by default form, used to confirm deletion of data in DB |
206 |
# called by default form, used to confirm deletion of data in DB |
Lines 244-250
elsif ( $op eq 'delete_confirmed' ) {
Link Here
|
244 |
# END $OP eq DELETE_CONFIRMED |
247 |
# END $OP eq DELETE_CONFIRMED |
245 |
################## DEFAULT ################################## |
248 |
################## DEFAULT ################################## |
246 |
} |
249 |
} |
247 |
else { # DEFAULT |
250 |
|
|
|
251 |
if ( $op eq 'list' ) { |
248 |
my ($results) = StringSearch( $searchfield, 'web' ); |
252 |
my ($results) = StringSearch( $searchfield, 'web' ); |
249 |
my @loop; |
253 |
my @loop; |
250 |
foreach my $itemtype ( @{$results} ) { |
254 |
foreach my $itemtype ( @{$results} ) { |
Lines 254-261
else { # DEFAULT
Link Here
|
254 |
} |
258 |
} |
255 |
|
259 |
|
256 |
$template->param( |
260 |
$template->param( |
257 |
loop => \@loop, |
261 |
loop => \@loop, |
|
|
262 |
else => 1, |
263 |
messages => \@messages, |
258 |
); |
264 |
); |
259 |
} #---- END $OP eq DEFAULT |
265 |
} |
260 |
|
266 |
|
261 |
output_html_with_http_headers $input, $cookie, $template->output; |
267 |
output_html_with_http_headers $input, $cookie, $template->output; |