Lines 27-40
use C4::Context;
Link Here
|
27 |
use C4::Koha; |
27 |
use C4::Koha; |
28 |
use C4::Output; |
28 |
use C4::Output; |
29 |
|
29 |
|
30 |
|
|
|
31 |
sub AuthorizedValuesForCategory { |
30 |
sub AuthorizedValuesForCategory { |
32 |
my ($searchstring) = shift or return; |
31 |
my ($searchstring) = shift or return; |
33 |
my $dbh = C4::Context->dbh; |
32 |
my $dbh = C4::Context->dbh; |
34 |
$searchstring=~ s/\'/\\\'/g; |
33 |
$searchstring=~ s/\'/\\\'/g; |
35 |
my @data=split(' ',$searchstring); |
34 |
my @data=split(' ',$searchstring); |
36 |
my $sth=$dbh->prepare(' |
35 |
my $sth=$dbh->prepare(' |
37 |
SELECT id, category, authorised_value, lib, lib_opac, imageurl |
36 |
SELECT * |
38 |
FROM authorised_values |
37 |
FROM authorised_values |
39 |
WHERE (category = ?) |
38 |
WHERE (category = ?) |
40 |
ORDER BY category, authorised_value |
39 |
ORDER BY category, authorised_value |
Lines 70-76
if ($op eq 'add_form') {
Link Here
|
70 |
my $data; |
69 |
my $data; |
71 |
my @selected_branches; |
70 |
my @selected_branches; |
72 |
if ($id) { |
71 |
if ($id) { |
73 |
my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?"); |
72 |
my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, linked_with, imageurl from authorised_values where id=?"); |
74 |
$sth->execute($id); |
73 |
$sth->execute($id); |
75 |
$data=$sth->fetchrow_hashref; |
74 |
$data=$sth->fetchrow_hashref; |
76 |
$sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?;"); |
75 |
$sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?;"); |
Lines 114-120
if ($op eq 'add_form') {
Link Here
|
114 |
offset => $offset, |
113 |
offset => $offset, |
115 |
branches_loop => \@branches_loop, |
114 |
branches_loop => \@branches_loop, |
116 |
); |
115 |
); |
117 |
|
116 |
# Add borrower's categories select list, in case we'd like to bind a sort1 criteria to categories |
|
|
117 |
my @linked_with = split ('\|', $data->{'linked_with'} ); |
118 |
my @typeloop; |
119 |
$template->param('allcatcodes'=>1) unless $data->{'linked_with'}; |
120 |
if ($id){ |
121 |
foreach (qw(C A S P I X)) { |
122 |
my $action="WHERE category_type=?"; |
123 |
my ($categories,$labels) = C4::Members::GetborCatFromCatType($_,$action); |
124 |
my @categoryloop; |
125 |
foreach my $cat (@$categories){ |
126 |
my $selected = grep (/$cat/, @linked_with ) ? 1 : 0; |
127 |
push @categoryloop,{ |
128 |
'categorycode' => $cat, |
129 |
'categoryname' => $labels->{$cat}, |
130 |
'selected' => $selected, |
131 |
}; |
132 |
} |
133 |
my %typehash; |
134 |
$typehash{'typename'}=$_; |
135 |
my $typedescription = "typename_".$typehash{'typename'}; |
136 |
$typehash{'categoryloop'}=\@categoryloop; |
137 |
push @typeloop,{ |
138 |
'typename' => $_, |
139 |
$typedescription => 1, |
140 |
'categoryloop' => \@categoryloop |
141 |
}; |
142 |
} |
143 |
} |
144 |
$template->param('typeloop' => \@typeloop); |
145 |
|
118 |
################## ADD_VALIDATE ################################## |
146 |
################## ADD_VALIDATE ################################## |
119 |
# called by add_form, used to insert/modify data in DB |
147 |
# called by add_form, used to insert/modify data in DB |
120 |
} elsif ($op eq 'add_validate') { |
148 |
} elsif ($op eq 'add_validate') { |
Lines 141-153
if ($op eq 'add_form') {
Link Here
|
141 |
authorised_value = ?, |
169 |
authorised_value = ?, |
142 |
lib = ?, |
170 |
lib = ?, |
143 |
lib_opac = ?, |
171 |
lib_opac = ?, |
|
|
172 |
linked_with = ?, |
144 |
imageurl = ? |
173 |
imageurl = ? |
145 |
WHERE id=?' ); |
174 |
WHERE id=?' ); |
146 |
my $lib = $input->param('lib'); |
175 |
my $lib = $input->param('lib'); |
147 |
my $lib_opac = $input->param('lib_opac'); |
176 |
my $lib_opac = $input->param('lib_opac'); |
148 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
177 |
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 |
178 |
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); |
179 |
my @linked_with = $input->param('categorycode'); |
|
|
180 |
# pipe after each code is necessary for correct filtering in memberentrygen.tt |
181 |
my $linked_with = $linked_with[0] ne '' ? join ('|',@linked_with).'|' : ''; |
182 |
$sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl, $id); |
151 |
if ( @branches ) { |
183 |
if ( @branches ) { |
152 |
$sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?"); |
184 |
$sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?"); |
153 |
$sth->execute( $id ); |
185 |
$sth->execute( $id ); |
Lines 173-185
if ($op eq 'add_form') {
Link Here
|
173 |
($duplicate_entry) = $sth->fetchrow_array(); |
205 |
($duplicate_entry) = $sth->fetchrow_array(); |
174 |
unless ( $duplicate_entry ) { |
206 |
unless ( $duplicate_entry ) { |
175 |
my $sth=$dbh->prepare( 'INSERT INTO authorised_values |
207 |
my $sth=$dbh->prepare( 'INSERT INTO authorised_values |
176 |
( category, authorised_value, lib, lib_opac, imageurl ) |
208 |
( category, authorised_value, lib, lib_opac, linked_with, imageurl ) |
177 |
values (?, ?, ?, ?, ?)' ); |
209 |
values (?, ?, ?, ?, ?, ?)' ); |
178 |
my $lib = $input->param('lib'); |
210 |
my $lib = $input->param('lib'); |
179 |
my $lib_opac = $input->param('lib_opac'); |
211 |
my $lib_opac = $input->param('lib_opac'); |
180 |
undef $lib if ($lib eq ""); # to insert NULL instead of a blank string |
212 |
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 |
213 |
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 ); |
214 |
my @linked_with = $input->param('categorycode'); |
|
|
215 |
my $linked_with = $linked_with[0] ne '' ? join ('|',@linked_with).'|' : ''; |
216 |
$sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl ); |
183 |
$id = $dbh->{'mysql_insertid'}; |
217 |
$id = $dbh->{'mysql_insertid'}; |
184 |
if ( @branches ) { |
218 |
if ( @branches ) { |
185 |
$sth = $dbh->prepare( |
219 |
$sth = $dbh->prepare( |
Lines 275-285
sub default_form {
Link Here
|
275 |
while ( my $branch = $sth->fetchrow_hashref ) { |
309 |
while ( my $branch = $sth->fetchrow_hashref ) { |
276 |
push @selected_branches, $branch; |
310 |
push @selected_branches, $branch; |
277 |
} |
311 |
} |
|
|
312 |
|
313 |
|
314 |
|
278 |
my %row_data; # get a fresh hash for the row data |
315 |
my %row_data; # get a fresh hash for the row data |
279 |
$row_data{category} = $results->[$i]{'category'}; |
316 |
$row_data{category} = $results->[$i]{'category'}; |
280 |
$row_data{authorised_value} = $results->[$i]{'authorised_value'}; |
317 |
$row_data{authorised_value} = $results->[$i]{'authorised_value'}; |
281 |
$row_data{lib} = $results->[$i]{'lib'}; |
318 |
$row_data{lib} = $results->[$i]{'lib'}; |
282 |
$row_data{lib_opac} = $results->[$i]{'lib_opac'}; |
319 |
$row_data{lib_opac} = $results->[$i]{'lib_opac'}; |
|
|
320 |
$row_data{linked_with} = substr($results->[$i]{'linked_with'},0,-1) if $results->[$i]{'linked_with'} ;# remove last pipe just for display |
283 |
$row_data{imageurl} = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} ); |
321 |
$row_data{imageurl} = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} ); |
284 |
$row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'}."&offset=$offset"; |
322 |
$row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'}."&offset=$offset"; |
285 |
$row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'}."&offset=$offset"; |
323 |
$row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'}."&offset=$offset"; |