X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FKoha.pm;h=bb3efc7bc50bfdb0b792cab0410def99e51d18e3;hb=7362776897c702bbabe49e24a4875afae5d11a9a;hp=07c80c69aced8cf9ccf3805b1ab17550cbb03187;hpb=6eeb5180422d9439afb9e783aae70f7c1beb27e7;p=koha.git diff --git a/C4/Koha.pm b/C4/Koha.pm index 07c80c69ac..bb3efc7bc5 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -25,8 +25,8 @@ use strict; use C4::Context; use C4::Branch qw(GetBranchesCount); +use Koha::DateUtils qw(dt_from_string); use Memoize; -use DateTime; use DateTime::Format::MySQL; use autouse 'Data::Dumper' => qw(Dumper); @@ -41,7 +41,6 @@ BEGIN { &subfield_is_koha_internal_p &GetPrinters &GetPrinter &GetItemTypes &getitemtypeinfo - &GetCcodes &GetSupportName &GetSupportList &get_itemtypeinfos_of &getframeworks &getframeworkinfo @@ -57,12 +56,14 @@ BEGIN { &getitemtypeimagelocation &GetAuthorisedValues &GetAuthorisedValueCategories + &IsAuthorisedValueCategory &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValueLib &GetAuthorisedValueByCode &GetKohaImageurlFromAuthorisedValues &GetAuthValCode + &AddAuthorisedValue &GetNormalizedUPC &GetNormalizedISBN &GetNormalizedEAN @@ -172,16 +173,16 @@ build a HTML select with the following code : =head3 in TEMPLATE -
- - "> - -
+ =cut @@ -204,10 +205,15 @@ sub GetSupportList{ } =head2 GetItemTypes - $itemtypes = &GetItemTypes(); + $itemtypes = &GetItemTypes( style => $style ); Returns information about existing itemtypes. +Params: + style: either 'array' or 'hash', defaults to 'hash'. + 'array' returns an arrayref, + 'hash' return a hashref with the itemtype value as the key + build a HTML select with the following code : =head3 in PERL SCRIPT @@ -240,6 +246,8 @@ build a HTML select with the following code : =cut sub GetItemTypes { + my ( %params ) = @_; + my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash'; # returns a reference to a hash of references to itemtypes... my %itemtypes; @@ -250,10 +258,15 @@ sub GetItemTypes { |; my $sth = $dbh->prepare($query); $sth->execute; - while ( my $IT = $sth->fetchrow_hashref ) { - $itemtypes{ $IT->{'itemtype'} } = $IT; + + if ( $style eq 'hash' ) { + while ( my $IT = $sth->fetchrow_hashref ) { + $itemtypes{ $IT->{'itemtype'} } = $IT; + } + return ( \%itemtypes ); + } else { + return $sth->fetchall_arrayref({}); } - return ( \%itemtypes ); } sub get_itemtypeinfos_of { @@ -272,27 +285,6 @@ END_SQL return get_infos_of( $query, 'itemtype', undef, \@itemtypes ); } -# this is temporary until we separate collection codes and item types -sub GetCcodes { - my $count = 0; - my @results; - my $dbh = C4::Context->dbh; - my $sth = - $dbh->prepare( - "SELECT * FROM authorised_values ORDER BY authorised_value"); - $sth->execute; - while ( my $data = $sth->fetchrow_hashref ) { - if ( $data->{category} eq "CCODE" ) { - $count++; - $results[$count] = $data; - - #warn "data: $data"; - } - } - $sth->finish; - return ( $count, @results ); -} - =head2 getauthtypes $authtypes = &getauthtypes(); @@ -425,20 +417,22 @@ sub getframeworkinfo { =head2 getitemtypeinfo - $itemtype = &getitemtype($itemtype); + $itemtype = &getitemtypeinfo($itemtype, [$interface]); -Returns information about an itemtype. +Returns information about an itemtype. The optional $interface argument +sets which interface ('opac' or 'intranet') to return the imageurl for. +Defaults to intranet. =cut sub getitemtypeinfo { - my ($itemtype) = @_; + my ($itemtype, $interface) = @_; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("select * from itemtypes where itemtype=?"); $sth->execute($itemtype); my $res = $sth->fetchrow_hashref; - $res->{imageurl} = getitemtypeimagelocation( 'intranet', $res->{imageurl} ); + $res->{imageurl} = getitemtypeimagelocation( ( ( defined $interface && $interface eq 'opac' ) ? 'opac' : 'intranet' ), $res->{imageurl} ); return $res; } @@ -687,26 +681,26 @@ sub getFacets { { idx => 'su-to', label => 'Topics', - tags => [ qw/ 600a 601a 602a 603a 604a 605a 606ax 610a/ ], + tags => [ qw/ 600ab 601ab 602a 604at 605a 606ax 610a / ], sep => ' - ', }, { idx => 'su-geo', label => 'Places', - tags => [ qw/ 651a / ], + tags => [ qw/ 607a / ], sep => ' - ', }, { idx => 'su-ut', label => 'Titles', - tags => [ qw/ 500a 501a 502a 503a 504a / ], + tags => [ qw/ 500a 501a 503a / ], sep => ', ', }, { idx => 'au', label => 'Authors', tags => [ qw/ 700ab 701ab 702ab / ], - sep => ', ', + sep => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"), }, { idx => 'se', @@ -714,6 +708,11 @@ sub getFacets { tags => [ qw/ 225a / ], sep => ', ', }, + { + idx => 'location', + label => 'Location', + tags => [ qw/ 995c / ], + } ]; my $library_facet; @@ -723,12 +722,6 @@ sub getFacets { label => 'Libraries', tags => [ qw/ 995b / ], }; - } else { - $library_facet = { - idx => 'location', - label => 'Location', - tags => [ qw/ 995c / ], - }; } push( @$facets, $library_facet ); } @@ -776,6 +769,11 @@ sub getFacets { tags => [ qw/ 952y 942c / ], sep => ', ', }, + { + idx => 'location', + label => 'Location', + tags => [ qw / 952c / ], + }, ]; my $library_facet; @@ -785,12 +783,6 @@ sub getFacets { label => 'Libraries', tags => [ qw / 952b / ], }; - } else { - $library_facet = { - idx => 'location', - label => 'Location', - tags => [ qw / 952c / ], - }; } push( @$facets, $library_facet ); } @@ -909,13 +901,13 @@ like: { 'checked' => 'checked', - 'encoding' => 'MARC-8' + 'encoding' => 'utf8', 'icon' => undef, 'id' => 'LIBRARY OF CONGRESS', 'label' => '', 'name' => 'server', 'opensearch' => '', - 'value' => 'z3950.loc.gov:7090/', + 'value' => 'lx2.loc.gov:210/', 'zed' => 1, }, @@ -1036,28 +1028,54 @@ C<$opac> If set to a true value, displays OPAC descriptions rather than normal o =cut sub GetAuthorisedValues { - my ($category,$selected,$opac) = @_; + my ( $category, $selected, $opac ) = @_; + my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; my @results; my $dbh = C4::Context->dbh; - my $query = "SELECT * FROM authorised_values"; - $query .= " WHERE category = '" . $category . "'" if $category; - $query .= " ORDER BY category, lib, lib_opac"; + my $query = qq{ + SELECT * + FROM authorised_values + }; + $query .= qq{ + LEFT JOIN authorised_values_branches ON ( id = av_id ) + } if $branch_limit; + my @where_strings; + my @where_args; + if($category) { + push @where_strings, "category = ?"; + push @where_args, $category; + } + if($branch_limit) { + push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; + push @where_args, $branch_limit; + } + if(@where_strings > 0) { + $query .= " WHERE " . join(" AND ", @where_strings); + } + $query .= " GROUP BY lib"; + $query .= ' ORDER BY category, ' . ( + $opac ? 'COALESCE(lib_opac, lib)' + : 'lib, lib_opac' + ); + my $sth = $dbh->prepare($query); - $sth->execute; + + $sth->execute( @where_args ); while (my $data=$sth->fetchrow_hashref) { - if ( (defined($selected)) && ($selected eq $data->{'authorised_value'}) ) { - $data->{'selected'} = 1; + if ( defined $selected and $selected eq $data->{authorised_value} ) { + $data->{selected} = 1; } else { - $data->{'selected'} = 0; + $data->{selected} = 0; } - if ($opac && $data->{'lib_opac'}) { - $data->{'lib'} = $data->{'lib_opac'}; + + if ($opac && $data->{lib_opac}) { + $data->{lib} = $data->{lib_opac}; } push @results, $data; } - #my $data = $sth->fetchall_arrayref({}); - return \@results; #$data; + $sth->finish; + return \@results; } =head2 GetAuthorisedValueCategories @@ -1080,9 +1098,31 @@ sub GetAuthorisedValueCategories { return \@results; } +=head2 IsAuthorisedValueCategory + + $is_auth_val_category = IsAuthorisedValueCategory($category); + +Returns whether a given category name is a valid one + +=cut + +sub IsAuthorisedValueCategory { + my $category = shift; + my $query = ' + SELECT category + FROM authorised_values + WHERE BINARY category=? + LIMIT 1 + '; + my $sth = C4::Context->dbh->prepare($query); + $sth->execute($category); + $sth->fetchrow ? return 1 + : return 0; +} + =head2 GetAuthorisedValueByCode -$authhorised_value = GetAuthorisedValueByCode( $category, $authvalcode ); +$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac ); Return the lib attribute from authorised_values from the row identified by the passed category and code @@ -1202,6 +1242,26 @@ sub GetKohaAuthorisedValueLib { return $value; } +=head2 AddAuthorisedValue + + AddAuthorisedValue($category, $authorised_value, $lib, $lib_opac, $imageurl); + +Create a new authorised value. + +=cut + +sub AddAuthorisedValue { + my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_; + + my $dbh = C4::Context->dbh; + my $query = qq{ + INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) + VALUES (?,?,?,?,?) + }; + my $sth = $dbh->prepare($query); + $sth->execute($category, $authorised_value, $lib, $lib_opac, $imageurl); +} + =head2 display_marc_indicators my $display_form = C4::Koha::display_marc_indicators($field); @@ -1398,7 +1458,10 @@ sub GetDailyQuote { # update the timestamp for that quote $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?'; $sth = C4::Context->dbh->prepare($query); - $sth->execute(DateTime::Format::MySQL->format_datetime(DateTime->now), $quote->{'id'}); + $sth->execute( + DateTime::Format::MySQL->format_datetime( dt_from_string() ), + $quote->{'id'} + ); } return $quote; } @@ -1423,6 +1486,22 @@ sub _isbn_cleanup { return; } +=head2 Log( $message ); + + Writes data to /tmp/koha.log. + + This is useful for debugging forked processes + that do not write to the apache error log + +=cut + +sub Log { + my ($data) = @_; + warn $data; + open my $fh, '>>/tmp/koha.log'; + print $fh "$data\n"; + close $fh; +} 1; __END__