|
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 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
224 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
| 278 |
exit; |
225 |
exit; |
|
Lines 280-341
if ($op eq 'add_form') {
Link Here
|
| 280 |
# END $OP eq ADD_VALIDATE |
227 |
# END $OP eq ADD_VALIDATE |
| 281 |
################## DELETE_CONFIRM ################################## |
228 |
################## DELETE_CONFIRM ################################## |
| 282 |
# called by default form, used to confirm deletion of data in DB |
229 |
# called by default form, used to confirm deletion of data in DB |
| 283 |
} elsif ($op eq 'delete_confirm') { |
230 |
} |
| 284 |
my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?"); |
231 |
elsif ( $op eq 'delete_confirm' ) { |
| 285 |
$sth->execute($tagfield,$tagsubfield,$authtypecode); |
232 |
my $ass = Koha::AuthSubfieldStructures->find( |
| 286 |
my $data=$sth->fetchrow_hashref; |
233 |
{ |
| 287 |
$template->param(liblibrarian => $data->{'liblibrarian'}, |
234 |
authtypecode => $authtypecode, |
| 288 |
tagsubfield => $data->{'tagsubfield'}, |
235 |
tagfield => $tagfield, |
| 289 |
delete_link => $script_name, |
236 |
tagsubfield => $tagsubfield |
| 290 |
tagfield =>$tagfield, |
237 |
} |
| 291 |
tagsubfield => $tagsubfield, |
238 |
); |
| 292 |
authtypecode => $authtypecode, |
239 |
$template->param( |
| 293 |
); |
240 |
ass => $ass, |
| 294 |
# END $OP eq DELETE_CONFIRM |
241 |
delete_link => $script_name, |
| 295 |
################## DELETE_CONFIRMED ################################## |
242 |
); |
| 296 |
# called by delete_confirm, used to effectively confirm deletion of data in DB |
243 |
} |
| 297 |
} elsif ($op eq 'delete_confirmed') { |
244 |
elsif ( $op eq 'delete_confirmed' ) { |
| 298 |
my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?"); |
245 |
Koha::AuthSubfieldStructures->find( |
| 299 |
$sth->execute($tagfield,$tagsubfield,$authtypecode); |
246 |
{ |
|
|
247 |
authtypecode => $authtypecode, |
| 248 |
tagfield => $tagfield, |
| 249 |
tagsubfield => $tagsubfield |
| 250 |
} |
| 251 |
)->delete; |
| 300 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
252 |
print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); |
| 301 |
exit; |
253 |
exit; |
| 302 |
# END $OP eq DELETE_CONFIRMED |
254 |
} |
| 303 |
################## DEFAULT ################################## |
255 |
else { # DEFAULT |
| 304 |
} else { # DEFAULT |
256 |
my $ass = Koha::AuthSubfieldStructures->search( |
| 305 |
my ($count,$results)=string_search($tagfield,$authtypecode); |
257 |
{ |
| 306 |
my @loop_data = (); |
258 |
tagfield => { -like => "$tagfield%" }, |
| 307 |
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ |
259 |
authtypecode => $authtypecode, |
| 308 |
my %row_data; # get a fresh hash for the row data |
260 |
}, |
| 309 |
$row_data{tagfield} = $results->[$i]{'tagfield'}; |
261 |
{ order_by => [ 'tagfield', 'display_order' ] } |
| 310 |
$row_data{tagsubfield} = $results->[$i]{'tagsubfield'}; |
262 |
)->unblessed; |
| 311 |
$row_data{liblibrarian} = $results->[$i]{'liblibrarian'}; |
263 |
|
| 312 |
$row_data{kohafield} = $results->[$i]{'kohafield'}; |
264 |
$template->param( loop => $ass ); |
| 313 |
$row_data{repeatable} = $results->[$i]{'repeatable'}; |
265 |
$template->param( |
| 314 |
$row_data{mandatory} = $results->[$i]{'mandatory'}; |
266 |
edit_tagfield => $tagfield, |
| 315 |
$row_data{tab} = $results->[$i]{'tab'}; |
267 |
edit_authtypecode => $authtypecode, |
| 316 |
$row_data{seealso} = $results->[$i]{'seealso'}; |
268 |
); |
| 317 |
$row_data{authorised_value} = $results->[$i]{'authorised_value'}; |
|
|
| 318 |
$row_data{authtypecode} = $results->[$i]{'authtypecode'}; |
| 319 |
$row_data{value_builder} = $results->[$i]{'value_builder'}; |
| 320 |
$row_data{hidden} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ; |
| 321 |
$row_data{isurl} = $results->[$i]{'isurl'}; |
| 322 |
if ($row_data{tab} eq -1) { |
| 323 |
$row_data{subfield_ignored} = 1; |
| 324 |
} |
| 325 |
|
269 |
|
| 326 |
push(@loop_data, \%row_data); |
|
|
| 327 |
} |
| 328 |
$template->param(loop => \@loop_data); |
| 329 |
$template->param(edit_tagfield => $tagfield, |
| 330 |
edit_authtypecode => $authtypecode); |
| 331 |
|
| 332 |
if ($offset>0) { |
| 333 |
my $prevpage = $offset-$pagesize; |
| 334 |
$template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">"); |
| 335 |
} |
| 336 |
if ($offset+$pagesize<$count) { |
| 337 |
my $nextpage =$offset+$pagesize; |
| 338 |
$template->param(next => "<a href=\"$script_name?offset=$nextpage\">"); |
| 339 |
} |
| 340 |
} #---- END $OP eq DEFAULT |
270 |
} #---- END $OP eq DEFAULT |
| 341 |
output_html_with_http_headers $input, $cookie, $template->output; |
271 |
output_html_with_http_headers $input, $cookie, $template->output; |