-=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. 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,
- notforloan,
- barcode
- FROM items
-';
-
- # generic href of any information on the item, href of href.
- my $iteminfos_of = get_infos_of($query, 'itemnumber');
- print $iteminfos_of->{$itemnumber}{barcode};
-
- # specific information, href of scalar
- my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
- print $barcode_of_item->{$itemnumber};
-
-=cut
-
-sub get_infos_of {
- my ( $query, $key_name, $value_name, $bind_params ) = @_;
-
- my $dbh = C4::Context->dbh;
-
- my $sth = $dbh->prepare($query);
- $sth->execute( @$bind_params );
-
- my %infos_of;
- while ( my $row = $sth->fetchrow_hashref ) {
- if ( defined $value_name ) {
- $infos_of{ $row->{$key_name} } = $row->{$value_name};
- }
- else {
- $infos_of{ $row->{$key_name} } = $row;
- }
- }
- $sth->finish;
-
- return \%infos_of;
-}
-
-=head2 get_notforloan_label_of
-
- my $notforloan_label_of = get_notforloan_label_of();
-
-Each authorised value of notforloan (information available in items and
-itemtypes) is link to a single label.
-
-Returns a href where keys are authorised values and values are corresponding
-labels.
-
- foreach my $authorised_value (keys %{$notforloan_label_of}) {
- printf(
- "authorised_value: %s => %s\n",
- $authorised_value,
- $notforloan_label_of->{$authorised_value}
- );
- }
-
-=cut
-
-# FIXME - why not use GetAuthorisedValues ??
-#
-sub get_notforloan_label_of {
- my $dbh = C4::Context->dbh;
-
- my $query = '
-SELECT authorised_value
- FROM marc_subfield_structure
- WHERE kohafield = \'items.notforloan\'
- LIMIT 0, 1
-';
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my ($statuscode) = $sth->fetchrow_array();
-
- $query = '
-SELECT lib,
- authorised_value
- FROM authorised_values
- WHERE category = ?
-';
- $sth = $dbh->prepare($query);
- $sth->execute($statuscode);
- my %notforloan_label_of;
- while ( my $row = $sth->fetchrow_hashref ) {
- $notforloan_label_of{ $row->{authorised_value} } = $row->{lib};
- }
- $sth->finish;
-
- return \%notforloan_label_of;
-}
-
-=head2 displayServers
-
- my $servers = displayServers();
- my $servers = displayServers( $position );
- my $servers = displayServers( $position, $type );
-
-displayServers returns a listref of hashrefs, each containing
-information about available z3950 servers. Each hashref has a format
-like:
-
- {
- 'checked' => 'checked',
- 'encoding' => 'utf8',
- 'icon' => undef,
- 'id' => 'LIBRARY OF CONGRESS',
- 'label' => '',
- 'name' => 'server',
- 'opensearch' => '',
- 'value' => 'lx2.loc.gov:210/',
- 'zed' => 1,
- },
-
-=cut
-
-sub displayServers {
- my ( $position, $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(@bind_params);
- my @primaryserverloop;
-
- while ( my $data = $rq->fetchrow_hashref ) {
- 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},
- zed => $data->{type} eq 'zed',
- opensearch => $data->{type} eq 'opensearch'
- };
- }
- return \@primaryserverloop;
-}
-
-
-=head2 GetKohaImageurlFromAuthorisedValues
-
-$authhorised_value = GetKohaImageurlFromAuthorisedValues( $category, $authvalcode );
-
-Return the first url of the authorised value image represented by $lib.
-
-=cut
-
-sub GetKohaImageurlFromAuthorisedValues {
- my ( $category, $lib ) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT imageurl FROM authorised_values WHERE category=? AND lib =?");
- $sth->execute( $category, $lib );
- while ( my $data = $sth->fetchrow_hashref ) {
- return $data->{'imageurl'};
- }
-}
-
-=head2 GetAuthValCode
-
- $authvalcode = GetAuthValCode($kohafield,$frameworkcode);
-
-=cut
-
-sub GetAuthValCode {
- my ($kohafield,$fwcode) = @_;
- my $dbh = C4::Context->dbh;
- $fwcode='' unless $fwcode;
- my $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield=? and frameworkcode=?');
- $sth->execute($kohafield,$fwcode);
- my ($authvalcode) = $sth->fetchrow_array;
- return $authvalcode;
-}
-
-=head2 GetAuthValCodeFromField
-
- $authvalcode = GetAuthValCodeFromField($field,$subfield,$frameworkcode);
-
-C<$subfield> can be undefined
-
-=cut
-
-sub GetAuthValCodeFromField {
- my ($field,$subfield,$fwcode) = @_;
- my $dbh = C4::Context->dbh;
- $fwcode='' unless $fwcode;
- my $sth;
- if (defined $subfield) {
- $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?');
- $sth->execute($field,$subfield,$fwcode);
- } else {
- $sth = $dbh->prepare('select authorised_value from marc_tag_structure where tagfield=? and frameworkcode=?');
- $sth->execute($field,$fwcode);
- }
- my ($authvalcode) = $sth->fetchrow_array;
- return $authvalcode;
-}
-