use C4::Context;
use C4::Output;
-use MIME::Base64 qw(encode_base64 decode_base64);
-use Encode qw(encode decode);
-
use vars qw($VERSION @ISA @EXPORT $DEBUG);
BEGIN {
&GetKohaAuthorisedValues
&GetAuthValCode
&GetManagedTagSubfields
- &str_to_base64
- &base64_to_str
$DEBUG
);
sub get_itemtypeinfos_of {
my @itemtypes = @_;
- my $query = '
+ my $placeholders = join( ', ', map { '?' } @itemtypes );
+ my $query = <<"END_SQL";
SELECT itemtype,
description,
imageurl,
notforloan
FROM itemtypes
- WHERE itemtype IN (' . join( ',', map( { "'" . $_ . "'" } @itemtypes ) ) . ')
-';
+ WHERE itemtype IN ( $placeholders )
+END_SQL
- return get_infos_of( $query, 'itemtype' );
+ return get_infos_of( $query, 'itemtype', undef, \@itemtypes );
}
# this is temporary until we separate collection codes and item types
return $imageurl;
}
+=head2 getitemtypeimagedir
+
+=over
+
+=item 4
+
+ my $directory = getitemtypeimagedir( 'opac' );
+
+pass in 'opac' or 'intranet'. Defaults to 'opac'.
+
+returns the full path to the appropriate directory containing images.
+
+=back
+
+=cut
+
sub getitemtypeimagedir {
my $src = shift;
+ $src = 'opac' unless defined $src;
+
if ($src eq 'intranet') {
return C4::Context->config('intrahtdocs') . '/' .C4::Context->preference('template') . '/img/itemtypeimg';
}
=head2 get_infos_of
-Return a href where a key is associated to a href. You give a query, the
-name of the key among the fields returned by the query. If you also give as
-third argument the name of the value, the function returns a href of scalar.
+Return a href where a key is associated to a href. You give a query,
+the name of the key among the fields returned by the query. If you
+also give as third argument the name of the value, the function
+returns a href of scalar. The optional 4th argument is an arrayref of
+items passed to the C<execute()> call. It is designed to bind
+parameters to any placeholders in your SQL.
my $query = '
SELECT itemnumber,
=cut
sub get_infos_of {
- my ( $query, $key_name, $value_name ) = @_;
+ my ( $query, $key_name, $value_name, $bind_params ) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare($query);
- $sth->execute();
+ $sth->execute( @$bind_params );
my %infos_of;
while ( my $row = $sth->fetchrow_hashref ) {
sub displayServers {
my ( $position, $type ) = @_;
- my $dbh = C4::Context->dbh;
- my $strsth = "SELECT * FROM z3950servers where 1";
- $strsth .= " AND position=\"$position\"" if ($position);
- $strsth .= " AND type=\"$type\"" if ($type);
+ my $dbh = C4::Context->dbh;
+
+ my $strsth = 'SELECT * FROM z3950servers';
+ my @where_clauses;
+ my @bind_params;
+
+ if ($position) {
+ push @bind_params, $position;
+ push @where_clauses, ' position = ? ';
+ }
+
+ if ($type) {
+ push @bind_params, $type;
+ push @where_clauses, ' type = ? ';
+ }
+
+ # reassemble where clause from where clause pieces
+ if (@where_clauses) {
+ $strsth .= ' WHERE ' . join( ' AND ', @where_clauses );
+ }
+
my $rq = $dbh->prepare($strsth);
- $rq->execute;
+ $rq->execute(@bind_params);
my @primaryserverloop;
while ( my $data = $rq->fetchrow_hashref ) {
- my %cell;
- $cell{label} = $data->{'description'};
- $cell{id} = $data->{'name'};
- $cell{value} =
- $data->{host}
- . ( $data->{port} ? ":" . $data->{port} : "" ) . "/"
- . $data->{database}
- if ( $data->{host} );
- $cell{checked} = $data->{checked};
push @primaryserverloop,
- {
- label => $data->{description},
- id => $data->{name},
- name => "server",
- value => $data->{host} . ":"
- . $data->{port} . "/"
- . $data->{database},
- encoding => ($data->{encoding}?$data->{encoding}:"iso-5426"),
- checked => "checked",
- icon => $data->{icon},
+ { label => $data->{description},
+ id => $data->{name},
+ name => "server",
+ value => $data->{host} . ":" . $data->{port} . "/" . $data->{database},
+ encoding => ( $data->{encoding} ? $data->{encoding} : "iso-5426" ),
+ checked => "checked",
+ icon => $data->{icon},
zed => $data->{type} eq 'zed',
opensearch => $data->{type} eq 'opensearch'
};
return $data;
}
-=head2 str_to_base64
-
-=over 4
-
-my $base64 = str_to_base64($string_containing_unicode);
-
-=back
-
-Get a Base64 version of a string that is in UTF-8. This
-function can be used to convert an arbitrary coded value
-(like a branch code) into a form that can be safely concatenated
-with similarly encoded values for a HTML form input name, as
-in admin/issuingrules.pl.
-
-=cut
-
-sub str_to_base64 {
- my $in = shift;
- return encode_base64(encode("UTF-8", $in), '');
-}
-
-=head2 base64_to_str
-
-=over 4
-
-my $base64 = base64_to_str($string_containing_unicode);
-
-=back
-
-Converse of C<str_to_base64()>.
-
-=cut
-
-sub base64_to_str {
- my $in = shift;
- return decode("UTF-8", decode_base64($in));
-}
-
=head2 display_marc_indicators
=over 4