Lines 102-160
if ($op eq 'add_form') {
Link Here
|
102 |
my $imageurl = $input->param( 'imageurl' ) || ''; |
102 |
my $imageurl = $input->param( 'imageurl' ) || ''; |
103 |
$imageurl = '' if $imageurl =~ /removeImage/; |
103 |
$imageurl = '' if $imageurl =~ /removeImage/; |
104 |
my $duplicate_entry = 0; |
104 |
my $duplicate_entry = 0; |
|
|
105 |
my $bad_chars = 0; |
105 |
|
106 |
|
106 |
if ( $id ) { # Update |
107 |
if ( $new_authorised_value =~ /^[a-zA-Z0-9\-_]+$/ ) { |
107 |
my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id='$id' "); |
108 |
if ( $id ) { # Update |
108 |
$sth->execute(); |
109 |
my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id='$id' "); |
109 |
my ($category, $authorised_value) = $sth->fetchrow_array(); |
110 |
$sth->execute(); |
110 |
if ( $authorised_value ne $new_authorised_value ) { |
111 |
my ($category, $authorised_value) = $sth->fetchrow_array(); |
|
|
112 |
if ( $authorised_value ne $new_authorised_value ) { |
113 |
my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " . |
114 |
"WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' and id<>$id"); |
115 |
$sth->execute(); |
116 |
($duplicate_entry) = $sth->fetchrow_array(); |
117 |
warn "**** duplicate_entry = $duplicate_entry"; |
118 |
} |
119 |
unless ( $duplicate_entry ) { |
120 |
my $sth=$dbh->prepare( 'UPDATE authorised_values |
121 |
SET category = ?, |
122 |
authorised_value = ?, |
123 |
lib = ?, |
124 |
lib_opac = ?, |
125 |
imageurl = ? |
126 |
WHERE id=?' ); |
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 |
$sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id); |
132 |
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>"; |
133 |
exit; |
134 |
} |
135 |
} |
136 |
else { # Insert |
111 |
my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " . |
137 |
my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " . |
112 |
"WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' and id<>$id"); |
138 |
"WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' "); |
113 |
$sth->execute(); |
139 |
$sth->execute(); |
114 |
($duplicate_entry) = $sth->fetchrow_array(); |
140 |
($duplicate_entry) = $sth->fetchrow_array(); |
115 |
warn "**** duplicate_entry = $duplicate_entry"; |
141 |
unless ( $duplicate_entry ) { |
|
|
142 |
my $sth=$dbh->prepare( 'INSERT INTO authorised_values |
143 |
( id, category, authorised_value, lib, lib_opac, imageurl ) |
144 |
values (?, ?, ?, ?, ?, ?)' ); |
145 |
my $lib = $input->param('lib'); |
146 |
my $lib_opac = $input->param('lib_opac'); |
147 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
148 |
undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string |
149 |
$sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); |
150 |
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>"; |
151 |
exit; |
152 |
} |
116 |
} |
153 |
} |
117 |
unless ( $duplicate_entry ) { |
154 |
if ( $duplicate_entry ) { |
118 |
my $sth=$dbh->prepare( 'UPDATE authorised_values |
155 |
$template->param(duplicate_category => $new_category, |
119 |
SET category = ?, |
156 |
duplicate_value => $new_authorised_value, |
120 |
authorised_value = ?, |
157 |
else => 1); |
121 |
lib = ?, |
158 |
default_form(); |
122 |
lib_opac = ?, |
|
|
123 |
imageurl = ? |
124 |
WHERE id=?' ); |
125 |
my $lib = $input->param('lib'); |
126 |
my $lib_opac = $input->param('lib_opac'); |
127 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
128 |
undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string |
129 |
$sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id); |
130 |
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>"; |
131 |
exit; |
132 |
} |
159 |
} |
133 |
} |
160 |
} |
134 |
else { # Insert |
161 |
else { |
135 |
my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " . |
162 |
$template->param(rejected_category => $new_category, |
136 |
"WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' "); |
163 |
rejected_value => $new_authorised_value, |
137 |
$sth->execute(); |
|
|
138 |
($duplicate_entry) = $sth->fetchrow_array(); |
139 |
unless ( $duplicate_entry ) { |
140 |
my $sth=$dbh->prepare( 'INSERT INTO authorised_values |
141 |
( id, category, authorised_value, lib, lib_opac, imageurl ) |
142 |
values (?, ?, ?, ?, ?, ?)' ); |
143 |
my $lib = $input->param('lib'); |
144 |
my $lib_opac = $input->param('lib_opac'); |
145 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
146 |
undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string |
147 |
$sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); |
148 |
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>"; |
149 |
exit; |
150 |
} |
151 |
} |
152 |
if ( $duplicate_entry ) { |
153 |
$template->param(duplicate_category => $new_category, |
154 |
duplicate_value => $new_authorised_value, |
155 |
else => 1); |
164 |
else => 1); |
156 |
default_form(); |
165 |
default_form(); |
157 |
} |
166 |
} |
158 |
|
167 |
|
159 |
################## DELETE_CONFIRM ################################## |
168 |
################## DELETE_CONFIRM ################################## |
160 |
# called by default form, used to confirm deletion of data in DB |
169 |
# called by default form, used to confirm deletion of data in DB |