Lines 26-59
use C4::Koha;
Link Here
|
26 |
|
26 |
|
27 |
use Koha::Authority::Types; |
27 |
use Koha::Authority::Types; |
28 |
use Koha::AuthorisedValues; |
28 |
use Koha::AuthorisedValues; |
|
|
29 |
use Koha::AuthSubfieldStructures; |
29 |
|
30 |
|
30 |
use List::MoreUtils qw( uniq ); |
31 |
use List::MoreUtils qw( uniq ); |
31 |
|
32 |
|
32 |
sub string_search { |
|
|
33 |
my ($searchstring,$authtypecode)=@_; |
34 |
my $dbh = C4::Context->dbh; |
35 |
$searchstring=~ s/\'/\\\'/g; |
36 |
my @data=split(' ',$searchstring); |
37 |
my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield, display_order"); |
38 |
$sth->execute("$searchstring%",$authtypecode); |
39 |
my $results = $sth->fetchall_arrayref({}); |
40 |
return (scalar(@$results), $results); |
41 |
} |
42 |
|
43 |
sub auth_subfield_structure_exists { |
44 |
my ($authtypecode, $tagfield, $tagsubfield) = @_; |
45 |
my $dbh = C4::Context->dbh; |
46 |
my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?"; |
47 |
my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield); |
48 |
return @$rows > 0; |
49 |
} |
50 |
|
51 |
my $input = CGI->new; |
33 |
my $input = CGI->new; |
52 |
my $tagfield = $input->param('tagfield'); |
34 |
my $tagfield = $input->param('tagfield'); |
53 |
my $tagsubfield = $input->param('tagsubfield'); |
35 |
my $tagsubfield = $input->param('tagsubfield'); |
54 |
my $authtypecode = $input->param('authtypecode'); |
36 |
my $authtypecode = $input->param('authtypecode'); |
55 |
my $offset = $input->param('offset'); |
|
|
56 |
$offset = 0 if not defined $offset or $offset < 0; |
57 |
my $op = $input->param('op') || ''; |
37 |
my $op = $input->param('op') || ''; |
58 |
my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl"; |
38 |
my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl"; |
59 |
|
39 |
|
Lines 123-157
if ($op eq 'add_form') {
Link Here
|
123 |
@value_builder= sort {$a cmp $b} @value_builder; |
103 |
@value_builder= sort {$a cmp $b} @value_builder; |
124 |
closedir DIR; |
104 |
closedir DIR; |
125 |
|
105 |
|
126 |
# build values list |
106 |
my @loop_data; |
127 |
my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=? order by display_order"); # and tagsubfield='$tagsubfield'"); |
107 |
my $asses = Koha::AuthSubfieldStructures->search({ tagfield => $tagfield, authtypecode => $authtypecode}, {order_by => 'display_order'})->unblessed; |
128 |
$sth->execute($tagfield,$authtypecode); |
108 |
my $i; |
129 |
my @loop_data = (); |
109 |
for my $ass ( @$asses ) { |
130 |
my $i=0; |
110 |
my %row_data = %$ass; |
131 |
while ( my $data = $sth->fetchrow_hashref ) { |
|
|
132 |
my %row_data; # get a fresh hash for the row data |
133 |
$row_data{defaultvalue} = $data->{defaultvalue}; |
134 |
$row_data{tab} = $data->{tab}; |
135 |
$row_data{ohidden} = $data->{'hidden'}; |
136 |
$row_data{tagsubfield} = $data->{'tagsubfield'}; |
137 |
$row_data{liblibrarian} = $data->{'liblibrarian'}; |
138 |
$row_data{libopac} = $data->{'libopac'}; |
139 |
$row_data{seealso} = $data->{'seealso'}; |
140 |
$row_data{kohafields} = \@kohafields; |
111 |
$row_data{kohafields} = \@kohafields; |
141 |
$row_data{kohafield} = $data->{'kohafield'}; |
|
|
142 |
$row_data{authorised_values} = \@authorised_value_categories; |
112 |
$row_data{authorised_values} = \@authorised_value_categories; |
143 |
$row_data{authorised_value} = $data->{'authorised_value'}; |
|
|
144 |
$row_data{frameworkcodes} = \@authtypes; |
113 |
$row_data{frameworkcodes} = \@authtypes; |
145 |
$row_data{frameworkcode} = $data->{'frameworkcode'}; |
|
|
146 |
$row_data{value_builders} = \@value_builder; |
114 |
$row_data{value_builders} = \@value_builder; |
147 |
$row_data{value_builder} = $data->{'value_builder'}; |
115 |
$row_data{row} = $i++; |
148 |
$row_data{repeatable} = $data->{repeatable}; |
|
|
149 |
$row_data{mandatory} = $data->{mandatory}; |
150 |
$row_data{hidden} = $data->{hidden}; |
151 |
$row_data{isurl} = $data->{isurl}; |
152 |
$row_data{row} = $i; |
153 |
push( @loop_data, \%row_data ); |
116 |
push( @loop_data, \%row_data ); |
154 |
$i++; |
|
|
155 |
} |
117 |
} |
156 |
|
118 |
|
157 |
# Add a new row for the "New" tab |
119 |
# Add a new row for the "New" tab |
Lines 187-198
if ($op eq 'add_form') {
Link Here
|
187 |
# called by add_form, used to insert/modify data in DB |
149 |
# called by add_form, used to insert/modify data in DB |
188 |
} elsif ($op eq 'add_validate') { |
150 |
} elsif ($op eq 'add_validate') { |
189 |
$template->param(tagfield => "$input->param('tagfield')"); |
151 |
$template->param(tagfield => "$input->param('tagfield')"); |
190 |
# my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl) |
|
|
191 |
# values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); |
192 |
my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue, display_order) |
193 |
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); |
194 |
my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=?, display_order=? |
195 |
where authtypecode=? and tagfield=? and tagsubfield=?"); |
196 |
my @tagsubfield = $input->multi_param('tagsubfield'); |
152 |
my @tagsubfield = $input->multi_param('tagsubfield'); |
197 |
my @liblibrarian = $input->multi_param('liblibrarian'); |
153 |
my @liblibrarian = $input->multi_param('liblibrarian'); |
198 |
my @libopac = $input->multi_param('libopac'); |
154 |
my @libopac = $input->multi_param('libopac'); |
Lines 224-278
if ($op eq 'add_form') {
Link Here
|
224 |
my $defaultvalue = $defaultvalue[$i]; |
180 |
my $defaultvalue = $defaultvalue[$i]; |
225 |
my $hidden = $ohidden[$i]; #collate from 3 hiddens; |
181 |
my $hidden = $ohidden[$i]; #collate from 3 hiddens; |
226 |
my $isurl = $input->param("isurl$i")?1:0; |
182 |
my $isurl = $input->param("isurl$i")?1:0; |
227 |
if ($liblibrarian) { |
183 |
if ($liblibrarian) { |
228 |
if (auth_subfield_structure_exists($authtypecode, $tagfield, $tagsubfield)) { |
184 |
my $ass = Koha::AuthSubfieldStructures->find( |
229 |
$sth_update->execute( |
185 |
{ |
230 |
$authtypecode, |
186 |
authtypecode => $authtypecode, |
231 |
$tagfield, |
187 |
tagfield => $tagfield, |
232 |
$tagsubfield, |
188 |
tagsubfield => $tagsubfield |
233 |
$liblibrarian, |
189 |
} |
234 |
$libopac, |
190 |
); |
235 |
$repeatable, |
191 |
my $attributes = { |
236 |
$mandatory, |
192 |
liblibrarian => $liblibrarian, |
237 |
$kohafield, |
193 |
libopac => $libopac, |
238 |
$tab, |
194 |
repeatable => $repeatable, |
239 |
$seealso, |
195 |
mandatory => $mandatory, |
240 |
$authorised_value, |
196 |
kohafield => $kohafield, |
241 |
$frameworkcode, |
197 |
tab => $tab, |
242 |
$value_builder, |
198 |
seealso => $seealso, |
243 |
$hidden, |
199 |
authorised_value => $authorised_value, |
244 |
$isurl, |
200 |
frameworkcode => $frameworkcode, |
245 |
$defaultvalue, |
201 |
value_builder => $value_builder, |
246 |
$display_order->{$tagfield} || 0, |
202 |
hidden => $hidden, |
247 |
( |
203 |
isurl => $isurl, |
248 |
$authtypecode, |
204 |
defaultvalue => $defaultvalue, |
249 |
$tagfield, |
205 |
display_order => $display_order->{$tagfield} || 0, |
250 |
$tagsubfield |
206 |
}; |
251 |
), |
207 |
|
252 |
); |
208 |
if ($ass) { |
253 |
} else { |
209 |
$ass->update($attributes); |
254 |
$sth_insert->execute( |
210 |
} |
255 |
$authtypecode, |
211 |
else { |
256 |
$tagfield, |
212 |
Koha::AuthSubfieldStructure->new( |
257 |
$tagsubfield, |
213 |
{ |
258 |
$liblibrarian, |
214 |
authtypecode => $authtypecode, |
259 |
$libopac, |
215 |
tagfield => $tagfield, |
260 |
$repeatable, |
216 |
tagsubfield => $tagsubfield, |
261 |
$mandatory, |
217 |
%$attributes |
262 |
$kohafield, |
218 |
} |
263 |
$tab, |
219 |
)->store; |
264 |
$seealso, |
220 |
} |
265 |
$authorised_value, |
|
|
266 |
$frameworkcode, |
267 |
$value_builder, |
268 |
$hidden, |
269 |
$isurl, |
270 |
$defaultvalue, |
271 |
display_order => $display_order->{$tagfield} || 0, |
272 |
); |
273 |
} |
274 |
$display_order->{$tagfield}++; |
221 |
$display_order->{$tagfield}++; |
275 |
} |
222 |
} |
276 |
} |
223 |
} |
277 |
use Data::Printer colored => 1; warn p $display_order; |
224 |
use Data::Printer colored => 1; warn p $display_order; |
278 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
225 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
Lines 281-342
if ($op eq 'add_form') {
Link Here
|
281 |
# END $OP eq ADD_VALIDATE |
228 |
# END $OP eq ADD_VALIDATE |
282 |
################## DELETE_CONFIRM ################################## |
229 |
################## DELETE_CONFIRM ################################## |
283 |
# called by default form, used to confirm deletion of data in DB |
230 |
# called by default form, used to confirm deletion of data in DB |
284 |
} elsif ($op eq 'delete_confirm') { |
231 |
} |
285 |
my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?"); |
232 |
elsif ( $op eq 'delete_confirm' ) { |
286 |
$sth->execute($tagfield,$tagsubfield,$authtypecode); |
233 |
my $ass = Koha::AuthSubfieldStructures->find( |
287 |
my $data=$sth->fetchrow_hashref; |
234 |
{ |
288 |
$template->param(liblibrarian => $data->{'liblibrarian'}, |
235 |
authtypecode => $authtypecode, |
289 |
tagsubfield => $data->{'tagsubfield'}, |
236 |
tagfield => $tagfield, |
290 |
delete_link => $script_name, |
237 |
tagsubfield => $tagsubfield |
291 |
tagfield =>$tagfield, |
238 |
} |
292 |
tagsubfield => $tagsubfield, |
239 |
); |
293 |
authtypecode => $authtypecode, |
240 |
$template->param( |
294 |
); |
241 |
ass => $ass, |
295 |
# END $OP eq DELETE_CONFIRM |
242 |
delete_link => $script_name, |
296 |
################## DELETE_CONFIRMED ################################## |
243 |
); |
297 |
# called by delete_confirm, used to effectively confirm deletion of data in DB |
244 |
} |
298 |
} elsif ($op eq 'delete_confirmed') { |
245 |
elsif ( $op eq 'delete_confirmed' ) { |
299 |
my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?"); |
246 |
Koha::AuthSubfieldStructures->find( |
300 |
$sth->execute($tagfield,$tagsubfield,$authtypecode); |
247 |
{ |
|
|
248 |
authtypecode => $authtypecode, |
249 |
tagfield => $tagfield, |
250 |
tagsubfield => $tagsubfield |
251 |
} |
252 |
)->delete; |
301 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
253 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
302 |
exit; |
254 |
exit; |
303 |
# END $OP eq DELETE_CONFIRMED |
255 |
} |
304 |
################## DEFAULT ################################## |
256 |
else { # DEFAULT |
305 |
} else { # DEFAULT |
257 |
my $ass = Koha::AuthSubfieldStructures->search( |
306 |
my ($count,$results)=string_search($tagfield,$authtypecode); |
258 |
{ |
307 |
my @loop_data = (); |
259 |
tagfield => { -like => "$tagfield%" }, |
308 |
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ |
260 |
authtypecode => $authtypecode, |
309 |
my %row_data; # get a fresh hash for the row data |
261 |
}, |
310 |
$row_data{tagfield} = $results->[$i]{'tagfield'}; |
262 |
{ order_by => [ 'tagfield', 'display_order' ] } |
311 |
$row_data{tagsubfield} = $results->[$i]{'tagsubfield'}; |
263 |
)->unblessed; |
312 |
$row_data{liblibrarian} = $results->[$i]{'liblibrarian'}; |
264 |
|
313 |
$row_data{kohafield} = $results->[$i]{'kohafield'}; |
265 |
$template->param( loop => $ass ); |
314 |
$row_data{repeatable} = $results->[$i]{'repeatable'}; |
266 |
$template->param( |
315 |
$row_data{mandatory} = $results->[$i]{'mandatory'}; |
267 |
edit_tagfield => $tagfield, |
316 |
$row_data{tab} = $results->[$i]{'tab'}; |
268 |
edit_authtypecode => $authtypecode, |
317 |
$row_data{seealso} = $results->[$i]{'seealso'}; |
269 |
); |
318 |
$row_data{authorised_value} = $results->[$i]{'authorised_value'}; |
|
|
319 |
$row_data{authtypecode} = $results->[$i]{'authtypecode'}; |
320 |
$row_data{value_builder} = $results->[$i]{'value_builder'}; |
321 |
$row_data{hidden} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ; |
322 |
$row_data{isurl} = $results->[$i]{'isurl'}; |
323 |
if ($row_data{tab} eq -1) { |
324 |
$row_data{subfield_ignored} = 1; |
325 |
} |
326 |
|
270 |
|
327 |
push(@loop_data, \%row_data); |
|
|
328 |
} |
329 |
$template->param(loop => \@loop_data); |
330 |
$template->param(edit_tagfield => $tagfield, |
331 |
edit_authtypecode => $authtypecode); |
332 |
|
333 |
if ($offset>0) { |
334 |
my $prevpage = $offset-$pagesize; |
335 |
$template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">"); |
336 |
} |
337 |
if ($offset+$pagesize<$count) { |
338 |
my $nextpage =$offset+$pagesize; |
339 |
$template->param(next => "<a href=\"$script_name?offset=$nextpage\">"); |
340 |
} |
341 |
} #---- END $OP eq DEFAULT |
271 |
} #---- END $OP eq DEFAULT |
342 |
output_html_with_http_headers $input, $cookie, $template->output; |
272 |
output_html_with_http_headers $input, $cookie, $template->output; |