Lines 124-141
if ($op eq 'add_form') {
Link Here
|
124 |
$imageurl = '' if $imageurl =~ /removeImage/; |
124 |
$imageurl = '' if $imageurl =~ /removeImage/; |
125 |
my $duplicate_entry = 0; |
125 |
my $duplicate_entry = 0; |
126 |
my @branches = $input->param('branches'); |
126 |
my @branches = $input->param('branches'); |
|
|
127 |
my $lib = $input->param('lib'); |
128 |
my $lib_opac = $input->param('lib_opac'); |
129 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
130 |
undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string |
131 |
my $category = $input->param('category'); |
132 |
my $authorised_value; |
127 |
|
133 |
|
128 |
if ( $id ) { # Update |
134 |
if ( $id ) { # Update |
129 |
my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id = ? "); |
135 |
my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id = ? "); |
130 |
$sth->execute($id); |
136 |
$sth->execute($id); |
131 |
my ($category, $authorised_value) = $sth->fetchrow_array(); |
137 |
($category, $authorised_value) = $sth->fetchrow_array(); |
132 |
if ( $authorised_value ne $new_authorised_value ) { |
138 |
if ( $authorised_value ne $new_authorised_value ) { |
133 |
my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " . |
139 |
my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " . |
134 |
"WHERE category = ? AND authorised_value = ? and id <> ? "); |
140 |
"WHERE category = ? AND authorised_value = ? and id <> ? "); |
135 |
$sth->execute($new_category, $new_authorised_value, $id); |
141 |
$sth->execute($new_category, $new_authorised_value, $id); |
136 |
($duplicate_entry) = $sth->fetchrow_array(); |
142 |
($duplicate_entry) = $sth->fetchrow_array(); |
137 |
} |
143 |
} |
138 |
unless ( $duplicate_entry ) { |
144 |
|
|
|
145 |
if ( !$duplicate_entry && defined($lib) && defined($lib_opac)) { |
139 |
my $sth=$dbh->prepare( 'UPDATE authorised_values |
146 |
my $sth=$dbh->prepare( 'UPDATE authorised_values |
140 |
SET category = ?, |
147 |
SET category = ?, |
141 |
authorised_value = ?, |
148 |
authorised_value = ?, |
Lines 143-152
if ($op eq 'add_form') {
Link Here
|
143 |
lib_opac = ?, |
150 |
lib_opac = ?, |
144 |
imageurl = ? |
151 |
imageurl = ? |
145 |
WHERE id=?' ); |
152 |
WHERE id=?' ); |
146 |
my $lib = $input->param('lib'); |
|
|
147 |
my $lib_opac = $input->param('lib_opac'); |
148 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
149 |
undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string |
150 |
$sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id); |
153 |
$sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id); |
151 |
if ( @branches ) { |
154 |
if ( @branches ) { |
152 |
$sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?"); |
155 |
$sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?"); |
Lines 171-184
if ($op eq 'add_form') {
Link Here
|
171 |
"WHERE category = ? AND authorised_value = ? "); |
174 |
"WHERE category = ? AND authorised_value = ? "); |
172 |
$sth->execute($new_category, $new_authorised_value); |
175 |
$sth->execute($new_category, $new_authorised_value); |
173 |
($duplicate_entry) = $sth->fetchrow_array(); |
176 |
($duplicate_entry) = $sth->fetchrow_array(); |
174 |
unless ( $duplicate_entry ) { |
177 |
|
|
|
178 |
if ( !$duplicate_entry && defined($lib) && defined($lib_opac)) { |
175 |
my $sth=$dbh->prepare( 'INSERT INTO authorised_values |
179 |
my $sth=$dbh->prepare( 'INSERT INTO authorised_values |
176 |
( category, authorised_value, lib, lib_opac, imageurl ) |
180 |
( category, authorised_value, lib, lib_opac, imageurl ) |
177 |
values (?, ?, ?, ?, ?)' ); |
181 |
values (?, ?, ?, ?, ?)' ); |
178 |
my $lib = $input->param('lib'); |
|
|
179 |
my $lib_opac = $input->param('lib_opac'); |
180 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
181 |
undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string |
182 |
$sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); |
182 |
$sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); |
183 |
$id = $dbh->{'mysql_insertid'}; |
183 |
$id = $dbh->{'mysql_insertid'}; |
184 |
if ( @branches ) { |
184 |
if ( @branches ) { |
Lines 192-198
if ($op eq 'add_form') {
Link Here
|
192 |
$sth->execute($id, $branchcode); |
192 |
$sth->execute($id, $branchcode); |
193 |
} |
193 |
} |
194 |
} |
194 |
} |
195 |
my $category = $input->param('category'); |
|
|
196 |
print $input->redirect("/cgi-bin/koha/admin/authorised_values.pl?searchfield=$category&offset=$offset"); |
195 |
print $input->redirect("/cgi-bin/koha/admin/authorised_values.pl?searchfield=$category&offset=$offset"); |
197 |
exit; |
196 |
exit; |
198 |
} |
197 |
} |
Lines 201-209
if ($op eq 'add_form') {
Link Here
|
201 |
$template->param(duplicate_category => $new_category, |
200 |
$template->param(duplicate_category => $new_category, |
202 |
duplicate_value => $new_authorised_value, |
201 |
duplicate_value => $new_authorised_value, |
203 |
else => 1); |
202 |
else => 1); |
204 |
default_form(); |
203 |
} |
205 |
} |
204 |
if ( !defined($lib) ) { |
206 |
|
205 |
$template->param(BadLib => 1, |
|
|
206 |
else => 1); |
207 |
} |
208 |
if ( !defined($lib_opac) ) { |
209 |
$template->param(BadLibOpac => 1, |
210 |
else => 1); |
211 |
} |
212 |
$searchfield=$category; |
213 |
default_form(); |
214 |
|
207 |
################## DELETE_CONFIRM ################################## |
215 |
################## DELETE_CONFIRM ################################## |
208 |
# called by default form, used to confirm deletion of data in DB |
216 |
# called by default form, used to confirm deletion of data in DB |
209 |
} elsif ($op eq 'delete_confirm') { |
217 |
} elsif ($op eq 'delete_confirm') { |