PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/svc/bib_profile

https://code.google.com/
Perl | 127 lines | 94 code | 14 blank | 19 comment | 7 complexity | e827abd7134d7b087a7eae6d4afbccee MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. #!/usr/bin/perl
  2. # Copyright 2007 LibLime
  3. #
  4. # This file is part of Koha.
  5. #
  6. # Koha is free software; you can redistribute it and/or modify it under the
  7. # terms of the GNU General Public License as published by the Free Software
  8. # Foundation; either version 2 of the License, or (at your option) any later
  9. # version.
  10. #
  11. # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
  12. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  13. # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along with
  16. # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  17. # Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. use strict;
  20. use CGI;
  21. use C4::Auth qw/check_api_auth/;
  22. use C4::Context;
  23. use C4::Koha;
  24. use XML::Simple;
  25. my $query = new CGI;
  26. my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
  27. if ($status eq "ok") {
  28. print $query->header(-type => 'text/xml', cookie => $cookie);
  29. } else {
  30. print $query->header(-type => 'text/xml', -status => '403 Forbidden');
  31. print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
  32. exit 0;
  33. }
  34. my $dbh = C4::Context->dbh;
  35. # get list of required tags
  36. my $result = {};
  37. $result->{'auth_status'} = $status;
  38. _get_mandatory_tags($result);
  39. _get_mandatory_subfields($result);
  40. _get_reserved_tags($result);
  41. _get_bib_number_tag($result);
  42. _get_biblioitem_itemtypes($result);
  43. print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1,
  44. GroupTags => {mandatory_tags => 'tag', mandatory_subfields => 'subfield', reserved_tags => 'tag',
  45. valid_values => 'value'});
  46. exit 0;
  47. sub _get_mandatory_tags {
  48. my $result = shift;
  49. my $sth = $dbh->prepare_cached("SELECT tagfield FROM marc_tag_structure WHERE frameworkcode = '' AND mandatory = 1");
  50. $sth->execute();
  51. my @tags = ();
  52. while (my $row = $sth->fetchrow_arrayref) {
  53. push @tags, $row->[0];
  54. }
  55. $result->{'mandatory_tags'} = \@tags;
  56. }
  57. sub _get_mandatory_subfields {
  58. my $result = shift;
  59. my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
  60. FROM marc_subfield_structure
  61. WHERE frameworkcode = ''
  62. AND tagsubfield <> '\@'
  63. AND kohafield <> 'biblioitems.itemtype'
  64. AND mandatory = 1");
  65. $sth->execute();
  66. my @subfields = ();
  67. while (my $row = $sth->fetchrow_arrayref) {
  68. push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
  69. }
  70. $result->{'mandatory_subfields'} = \@subfields;
  71. }
  72. sub _get_reserved_tags {
  73. my $result = shift;
  74. my $sth = $dbh->prepare_cached("SELECT DISTINCT tagfield
  75. FROM marc_subfield_structure
  76. WHERE frameworkcode = ''
  77. AND (kohafield = 'items.itemnumber' OR kohafield = 'biblioitems.itemtype' OR
  78. kohafield = 'biblio.biblionumber')");
  79. $sth->execute();
  80. my @tags = ();
  81. while (my $row = $sth->fetchrow_arrayref) {
  82. push @tags, $row->[0];
  83. }
  84. $result->{'reserved_tags'} = \@tags;
  85. }
  86. sub _get_bib_number_tag {
  87. my $result = shift;
  88. my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
  89. FROM marc_subfield_structure
  90. WHERE frameworkcode = ''
  91. AND kohafield = 'biblio.biblionumber'");
  92. $sth->execute();
  93. my @tags = ();
  94. while (my $row = $sth->fetchrow_arrayref) {
  95. push @tags, { tag => $row->[0], subfield => $row->[1] };
  96. }
  97. $result->{'bib_number'} = \@tags;
  98. }
  99. sub _get_biblioitem_itemtypes {
  100. my $result = shift;
  101. my $itemtypes = GetItemTypes;
  102. my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
  103. FROM marc_subfield_structure
  104. WHERE frameworkcode = ''
  105. AND kohafield = 'biblioitems.itemtype'");
  106. $sth->execute();
  107. my @tags = ();
  108. while (my $row = $sth->fetchrow_arrayref) {
  109. push @tags, { tag => $row->[0], subfield => $row->[1] };
  110. }
  111. my @valid_values = map { { code => $_, description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
  112. $result->{'special_entry'} = { field => \@tags, valid_values => \@valid_values };
  113. }