|
Lines 29-35
use C4::Output;
Link Here
|
| 29 |
use C4::Dates; |
29 |
use C4::Dates; |
| 30 |
use XML::Simple; |
30 |
use XML::Simple; |
| 31 |
use XML::Dumper; |
31 |
use XML::Dumper; |
| 32 |
use Switch; |
|
|
| 33 |
use C4::Debug; |
32 |
use C4::Debug; |
| 34 |
# use Smart::Comments; |
33 |
# use Smart::Comments; |
| 35 |
# use Data::Dumper; |
34 |
# use Data::Dumper; |
|
Lines 311-380
sub get_criteria {
Link Here
|
| 311 |
my ($area,$cgi) = @_; |
310 |
my ($area,$cgi) = @_; |
| 312 |
my $dbh = C4::Context->dbh(); |
311 |
my $dbh = C4::Context->dbh(); |
| 313 |
my $crit = $criteria{$area}; |
312 |
my $crit = $criteria{$area}; |
| 314 |
my $column_defs = _get_column_defs($cgi); |
313 |
my $column_defs = _get_column_defs($cgi); |
| 315 |
my @criteria_array; |
314 |
my @criteria_array; |
| 316 |
foreach my $localcrit (@$crit) { |
315 |
foreach my $localcrit (@$crit) { |
| 317 |
my ( $value, $type ) = split( /\|/, $localcrit ); |
316 |
my ( $value, $type ) = split( /\|/, $localcrit ); |
| 318 |
my ( $table, $column ) = split( /\./, $value ); |
317 |
my ( $table, $column ) = split( /\./, $value ); |
| 319 |
switch ($type) { |
318 |
if ($type eq 'textrange') { |
| 320 |
case 'textrange' { |
319 |
my %temp; |
| 321 |
my %temp; |
320 |
$temp{'name'} = $value; |
| 322 |
$temp{'name'} = $value; |
321 |
$temp{'from'} = "from_" . $value; |
| 323 |
$temp{'from'} = "from_" . $value; |
322 |
$temp{'to'} = "to_" . $value; |
| 324 |
$temp{'to'} = "to_" . $value; |
323 |
$temp{'textrange'} = 1; |
| 325 |
$temp{'textrange'} = 1; |
324 |
$temp{'description'} = $column_defs->{$value}; |
| 326 |
$temp{'description'} = $column_defs->{$value}; |
325 |
push @criteria_array, \%temp; |
| 327 |
push @criteria_array, \%temp; |
326 |
} |
| 328 |
} |
327 |
elsif ($type eq 'date') { |
| 329 |
|
328 |
my %temp; |
| 330 |
case 'date' { |
329 |
$temp{'name'} = $value; |
| 331 |
my %temp; |
330 |
$temp{'date'} = 1; |
| 332 |
$temp{'name'} = $value; |
331 |
$temp{'description'} = $column_defs->{$value}; |
| 333 |
$temp{'date'} = 1; |
332 |
push @criteria_array, \%temp; |
| 334 |
$temp{'description'} = $column_defs->{$value}; |
333 |
} |
| 335 |
push @criteria_array, \%temp; |
334 |
elsif ($type eq 'daterange') { |
| 336 |
} |
335 |
my %temp; |
| 337 |
|
336 |
$temp{'name'} = $value; |
| 338 |
case 'daterange' { |
337 |
$temp{'from'} = "from_" . $value; |
| 339 |
my %temp; |
338 |
$temp{'to'} = "to_" . $value; |
| 340 |
$temp{'name'} = $value; |
339 |
$temp{'daterange'} = 1; |
| 341 |
$temp{'from'} = "from_" . $value; |
340 |
$temp{'description'} = $column_defs->{$value}; |
| 342 |
$temp{'to'} = "to_" . $value; |
341 |
push @criteria_array, \%temp; |
| 343 |
$temp{'daterange'} = 1; |
342 |
} |
| 344 |
$temp{'description'} = $column_defs->{$value}; |
343 |
else { |
| 345 |
push @criteria_array, \%temp; |
344 |
my $query = |
| 346 |
} |
345 |
"SELECT distinct($column) as availablevalues FROM $table"; |
| 347 |
|
346 |
my $sth = $dbh->prepare($query); |
| 348 |
else { |
347 |
$sth->execute(); |
| 349 |
my $query = |
348 |
my @values; |
| 350 |
"SELECT distinct($column) as availablevalues FROM $table"; |
349 |
# push the runtime choosing option |
| 351 |
my $sth = $dbh->prepare($query); |
350 |
my $list; |
| 352 |
$sth->execute(); |
351 |
$list='branches' if $column eq 'branchcode' or $column eq 'holdingbranch' or $column eq 'homebranch'; |
| 353 |
my @values; |
352 |
$list='categorycode' if $column eq 'categorycode'; |
| 354 |
# push the runtime choosing option |
353 |
$list='itemtype' if $column eq 'itype'; |
| 355 |
my $list; |
354 |
$list='ccode' if $column eq 'ccode'; |
| 356 |
$list='branches' if $column eq 'branchcode' or $column eq 'holdingbranch' or $column eq 'homebranch'; |
355 |
# TODO : improve to let the librarian choose the description at runtime |
| 357 |
$list='categorycode' if $column eq 'categorycode'; |
356 |
push @values, { availablevalues => "<<$column".($list?"|$list":'').">>" }; |
| 358 |
$list='itemtype' if $column eq 'itype'; |
357 |
while ( my $row = $sth->fetchrow_hashref() ) { |
| 359 |
$list='ccode' if $column eq 'ccode'; |
358 |
push @values, $row; |
| 360 |
# TODO : improve to let the librarian choose the description at runtime |
359 |
if ($row->{'availablevalues'} eq '') { $row->{'default'} = 1 }; |
| 361 |
push @values, { availablevalues => "<<$column".($list?"|$list":'').">>" }; |
360 |
} |
| 362 |
while ( my $row = $sth->fetchrow_hashref() ) { |
361 |
$sth->finish(); |
| 363 |
push @values, $row; |
|
|
| 364 |
if ($row->{'availablevalues'} eq '') { $row->{'default'} = 1 }; |
| 365 |
} |
| 366 |
$sth->finish(); |
| 367 |
|
362 |
|
| 368 |
my %temp; |
363 |
my %temp; |
| 369 |
$temp{'name'} = $value; |
364 |
$temp{'name'} = $value; |
| 370 |
$temp{'description'} = $column_defs->{$value}; |
365 |
$temp{'description'} = $column_defs->{$value}; |
| 371 |
$temp{'values'} = \@values; |
366 |
$temp{'values'} = \@values; |
| 372 |
|
367 |
|
| 373 |
push @criteria_array, \%temp; |
368 |
push @criteria_array, \%temp; |
| 374 |
|
369 |
} |
| 375 |
} |
|
|
| 376 |
|
370 |
|
| 377 |
} |
|
|
| 378 |
} |
371 |
} |
| 379 |
return ( \@criteria_array ); |
372 |
return ( \@criteria_array ); |
| 380 |
} |
373 |
} |