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
);
=head1 FUNCTIONS
-=over 2
-
=cut
+
=head2 slashifyDate
$slash_date = &slashifyDate($dash_date);
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';
}
return $printer;
}
-=item getnbpages
+=head2 getnbpages
Returns the number of pages to display in a pagination bar, given the number
of items and the number of items per page.
return int( ( $nb_items - 1 ) / $nb_items_per_page ) + 1;
}
-=item getallthemes
+=head2 getallthemes
(@themes) = &getallthemes('opac');
(@themes) = &getallthemes('intranet');
=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 ) {
return \%notforloan_label_of;
}
+=head2 displayServers
+
+=over 4
+
+my $servers = displayServers();
+
+my $servers = displayServers( $position );
+
+my $servers = displayServers( $position, $type );
+
+=back
+
+displayServers returns a listref of hashrefs, each containing
+information about available z3950 servers. Each hashref has a format
+like:
+
+ {
+ 'checked' => 'checked',
+ 'encoding' => 'MARC-8'
+ 'icon' => undef,
+ 'id' => 'LIBRARY OF CONGRESS',
+ 'label' => '',
+ 'name' => 'server',
+ 'opensearch' => '',
+ 'value' => 'z3950.loc.gov:7090/',
+ 'zed' => 1,
+ },
+
+
+=cut
+
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
+=head2 display_marc_indicators
=over 4
-my $base64 = str_to_base64($string_containing_unicode);
+# field is a MARC::Field object
+my $display_form = C4::Koha::display_marc_indicators($field);
=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.
+Generate a display form of the indicators of a variable
+MARC field, replacing any blanks with '#'.
=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));
+sub display_marc_indicators {
+ my $field = shift;
+ my $indicators = '';
+ if ($field->tag() >= 10) {
+ $indicators = $field->indicator(1) . $field->indicator(2);
+ $indicators =~ s/ /#/g;
+ }
+ return $indicators;
}
1;