renamed 'biblios' directory for webservices to 'svc'
authorGalen Charlton <galen.charlton@liblime.com>
Fri, 23 Nov 2007 16:02:29 +0000 (10:02 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Sun, 25 Nov 2007 22:43:06 +0000 (16:43 -0600)
Directory changed to give a more generic name, particularly
for when new services are added later.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
biblios/authentication [deleted file]
biblios/bib [deleted file]
biblios/bib_profile [deleted file]
biblios/new_bib [deleted file]
svc/authentication [new file with mode: 0755]
svc/bib [new file with mode: 0755]
svc/bib_profile [new file with mode: 0755]
svc/new_bib [new file with mode: 0755]

diff --git a/biblios/authentication b/biblios/authentication
deleted file mode 100755 (executable)
index f36d133..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright 2007 LibLime
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
-#
-
-use strict;
-use CGI;
-use C4::Auth qw/check_api_auth/;
-use XML::Simple;
-
-my $query = new CGI;
-
-# The authentication strategy for the biblios web 
-# services is as follows.
-# 
-# 1. biblios POSTs to the authenticate API with URL-encoded
-# form parameters 'userid' and 'password'.  If the credentials
-# belong to a valid user with the 'editcatalogue' privilege,
-# a session cookie is returned and a Koha session created.  Otherwise, an 
-# appropriate error is returned.
-# 2. For subsequent calls to the biblios APIs, the user agent
-# should submit the same session cookie.  If the cookie is
-# not supplied or does not correspond to a valid session, the API
-# will redirect to this authentication API.
-# 3. The session cookie should not be (directly) sent back to the user's
-# web browser, but instead should be stored and submitted by biblios.
-
-
-my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
-
-if ($status eq "ok") {
-    print $query->header(-type => 'text/xml', cookie => $cookie);
-} else {
-    print $query->header(-type => 'text/xml');
-}
-print XMLout({ status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
diff --git a/biblios/bib b/biblios/bib
deleted file mode 100755 (executable)
index b6df2e5..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright 2007 LibLime
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
-#
-
-use strict;
-use CGI;
-use C4::Auth qw/check_api_auth/;
-use C4::Biblio;
-use XML::Simple;
-
-my $query = new CGI;
-
-my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
-unless ($status eq "ok") {
-    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
-    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
-    exit 0;
-}
-
-# do initial validation
-my $path_info = $query->path_info();
-
-my $biblionumber = undef;
-if ($path_info =~ m!^/(\d+)$!) {
-    $biblionumber = $1;
-} else {
-    print $query->header(-type => 'text/xml', -status => '400 Bad Request');
-}
-
-# are we retrieving or updating a bib?
-if ($query->request_method eq "GET") {
-    fetch_bib($query, $biblionumber);
-} else {
-    update_bib($query, $biblionumber);
-}
-
-exit 0;
-
-sub fetch_bib {
-    my $query = shift;
-    my $biblionumber = shift;
-    my $record = GetMarcBiblio($biblionumber);
-    if  (defined $record) {
-        print $query->header(-type => 'text/xml');
-        print $record->as_xml_record();
-    } else {
-        print $query->header(-type => 'text/xml', -status => '404 Not Found');
-    }
-}
-
-sub update_bib {
-    my $query = shift;
-    my $biblionumber = shift;
-    my $old_record = GetMarcBiblio($biblionumber);
-    unless  (defined $old_record) {
-        print $query->header(-type => 'text/xml', -status => '404 Not Found');
-        return;
-    }
-
-    my $result = {};
-    my $inxml = $query->param('POSTDATA');
-    print $query->header(-type => 'text/xml');
-
-    my $record = eval {MARC::Record::new_from_xml( $inxml, "utf8", C4::Context->preference('marcflavour'))};
-    my $do_not_escape = 0;
-    if ($@) {
-        $result->{'status'} = "failed";
-        $result->{'error'} = $@;
-    } else {
-        # delete any item tags
-        my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber", '');
-        foreach my $field ($record->field($itemtag)) {
-            $record->delete_field($field);
-        }
-        ModBiblio($record, $biblionumber, '');
-        my $new_record = GetMarcBiblio($biblionumber);
-        $result->{'status'} = "ok";
-        $result->{'biblionumber'} = $biblionumber;
-        my $xml = $new_record->as_xml_record();
-        $xml =~ s/<\?xml.*?\?>//i;
-        $result->{'marcxml'} =  $xml;
-        $do_not_escape = 1;
-    }
-   
-    print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => $do_not_escape); 
-}
diff --git a/biblios/bib_profile b/biblios/bib_profile
deleted file mode 100755 (executable)
index 41ea042..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright 2007 LibLime
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
-#
-
-use strict;
-use CGI;
-use C4::Auth qw/check_api_auth/;
-use C4::Context;
-use C4::Koha;
-use XML::Simple;
-
-my $query = new CGI;
-
-my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
-
-if ($status eq "ok") {
-    print $query->header(-type => 'text/xml', cookie => $cookie);
-} else {
-    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
-    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
-    exit 0;
-}
-
-my $dbh = C4::Context->dbh;
-
-# get list of required tags
-my $result = {};
-$result->{'auth_status'} = $status;
-_get_mandatory_tags($result);
-_get_mandatory_subfields($result);
-_get_reserved_tags($result);
-_get_bib_number_tag($result);
-_get_biblioitem_itemtypes($result);
-print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1,  
-        GroupTags => {mandatory_tags => 'tag', mandatory_subfields => 'subfield', reserved_tags => 'tag',
-                      valid_values => 'value'});
-
-exit 0;
-
-sub _get_mandatory_tags {
-    my $result = shift;
-    my $sth = $dbh->prepare_cached("SELECT tagfield FROM marc_tag_structure WHERE frameworkcode = '' AND mandatory = 1");
-    $sth->execute();
-    my @tags = ();
-    while (my $row = $sth->fetchrow_arrayref) {
-        push @tags, $row->[0];
-    }
-    $result->{'mandatory_tags'} = \@tags;
-}
-
-sub _get_mandatory_subfields {
-    my $result = shift;
-    my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield 
-                                    FROM marc_subfield_structure 
-                                    WHERE frameworkcode = '' 
-                                    AND tagsubfield <> '\@' 
-                                    AND mandatory = 1");
-    $sth->execute();
-    my @subfields = ();
-    while (my $row = $sth->fetchrow_arrayref) {
-        push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
-    }
-    $result->{'mandatory_subfields'} = \@subfields;
-}
-
-sub _get_reserved_tags {
-    my $result = shift;
-    my $sth = $dbh->prepare_cached("SELECT DISTINCT tagfield
-                                    FROM marc_subfield_structure 
-                                    WHERE frameworkcode = '' 
-                                    AND (kohafield = 'items.itemnumber' OR kohafield = 'biblioitems.itemtype' OR
-                                         kohafield = 'biblio.biblionumber')");
-    $sth->execute();
-    my @tags = ();
-    while (my $row = $sth->fetchrow_arrayref) {
-        push @tags, $row->[0];
-    }
-    $result->{'reserved_tags'} = \@tags;
-}
-
-sub _get_bib_number_tag {
-    my $result = shift;
-    my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
-                                    FROM marc_subfield_structure 
-                                    WHERE frameworkcode = '' 
-                                    AND kohafield = 'biblio.biblionumber'");
-    $sth->execute();
-    my @tags = ();
-    while (my $row = $sth->fetchrow_arrayref) {
-        push @tags, { tag => $row->[0], subfield => $row->[1] };
-    }
-    $result->{'bib_number'} = \@tags;
-}
-
-sub _get_biblioitem_itemtypes {
-    my $result = shift;
-    my $itemtypes = GetItemTypes;
-    my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
-                                    FROM marc_subfield_structure 
-                                    WHERE frameworkcode = '' 
-                                    AND kohafield = 'biblioitems.itemtype'");
-    $sth->execute();
-    my @tags = ();
-    while (my $row = $sth->fetchrow_arrayref) {
-        push @tags, { tag => $row->[0], subfield => $row->[1] };
-    }
-    my @valid_values = map { { code => $_,  description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
-    $result->{'special_entry'} = { field => \@tags,  valid_values => \@valid_values };
-    
-}
diff --git a/biblios/new_bib b/biblios/new_bib
deleted file mode 100755 (executable)
index ddcdb27..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright 2007 LibLime
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
-#
-
-use strict;
-use CGI;
-use C4::Auth qw/check_api_auth/;
-use C4::Biblio;
-use XML::Simple;
-
-my $query = new CGI;
-
-my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
-unless ($status eq "ok") {
-    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
-    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
-    exit 0;
-}
-
-if ($query->request_method eq "POST") {
-    add_bib($query);
-} else {
-    print $query->header(-type => 'text/xml', -status => '400 Bad Request');
-}
-
-exit 0;
-
-sub add_bib {
-    my $query = shift;
-
-    my $result = {};
-    my $inxml = $query->param('POSTDATA');
-    print $query->header(-type => 'text/xml');
-
-    my $record = eval {MARC::Record::new_from_xml( $inxml, "utf8", C4::Context->preference('marcflavour'))};
-    my $do_not_escape = 0;
-    if ($@) {
-        $result->{'status'} = "failed";
-        $result->{'error'} = $@;
-    } else {
-        # delete any item tags
-        my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber", '');
-        foreach my $field ($record->field($itemtag)) {
-            $record->delete_field($field);
-        }
-        my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
-        my $new_record = GetMarcBiblio($biblionumber);
-        $result->{'status'} = "ok";
-        $result->{'biblionumber'} = $biblionumber;
-        my $xml = $new_record->as_xml_record();
-        $xml =~ s/<\?xml.*?\?>//i;
-        $result->{'marcxml'} =  $xml;
-        $do_not_escape = 1;
-    }
-   
-    print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => $do_not_escape); 
-}
diff --git a/svc/authentication b/svc/authentication
new file mode 100755 (executable)
index 0000000..f36d133
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+
+# Copyright 2007 LibLime
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+#
+
+use strict;
+use CGI;
+use C4::Auth qw/check_api_auth/;
+use XML::Simple;
+
+my $query = new CGI;
+
+# The authentication strategy for the biblios web 
+# services is as follows.
+# 
+# 1. biblios POSTs to the authenticate API with URL-encoded
+# form parameters 'userid' and 'password'.  If the credentials
+# belong to a valid user with the 'editcatalogue' privilege,
+# a session cookie is returned and a Koha session created.  Otherwise, an 
+# appropriate error is returned.
+# 2. For subsequent calls to the biblios APIs, the user agent
+# should submit the same session cookie.  If the cookie is
+# not supplied or does not correspond to a valid session, the API
+# will redirect to this authentication API.
+# 3. The session cookie should not be (directly) sent back to the user's
+# web browser, but instead should be stored and submitted by biblios.
+
+
+my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
+
+if ($status eq "ok") {
+    print $query->header(-type => 'text/xml', cookie => $cookie);
+} else {
+    print $query->header(-type => 'text/xml');
+}
+print XMLout({ status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
diff --git a/svc/bib b/svc/bib
new file mode 100755 (executable)
index 0000000..b6df2e5
--- /dev/null
+++ b/svc/bib
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+
+# Copyright 2007 LibLime
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+#
+
+use strict;
+use CGI;
+use C4::Auth qw/check_api_auth/;
+use C4::Biblio;
+use XML::Simple;
+
+my $query = new CGI;
+
+my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
+unless ($status eq "ok") {
+    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
+    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
+    exit 0;
+}
+
+# do initial validation
+my $path_info = $query->path_info();
+
+my $biblionumber = undef;
+if ($path_info =~ m!^/(\d+)$!) {
+    $biblionumber = $1;
+} else {
+    print $query->header(-type => 'text/xml', -status => '400 Bad Request');
+}
+
+# are we retrieving or updating a bib?
+if ($query->request_method eq "GET") {
+    fetch_bib($query, $biblionumber);
+} else {
+    update_bib($query, $biblionumber);
+}
+
+exit 0;
+
+sub fetch_bib {
+    my $query = shift;
+    my $biblionumber = shift;
+    my $record = GetMarcBiblio($biblionumber);
+    if  (defined $record) {
+        print $query->header(-type => 'text/xml');
+        print $record->as_xml_record();
+    } else {
+        print $query->header(-type => 'text/xml', -status => '404 Not Found');
+    }
+}
+
+sub update_bib {
+    my $query = shift;
+    my $biblionumber = shift;
+    my $old_record = GetMarcBiblio($biblionumber);
+    unless  (defined $old_record) {
+        print $query->header(-type => 'text/xml', -status => '404 Not Found');
+        return;
+    }
+
+    my $result = {};
+    my $inxml = $query->param('POSTDATA');
+    print $query->header(-type => 'text/xml');
+
+    my $record = eval {MARC::Record::new_from_xml( $inxml, "utf8", C4::Context->preference('marcflavour'))};
+    my $do_not_escape = 0;
+    if ($@) {
+        $result->{'status'} = "failed";
+        $result->{'error'} = $@;
+    } else {
+        # delete any item tags
+        my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber", '');
+        foreach my $field ($record->field($itemtag)) {
+            $record->delete_field($field);
+        }
+        ModBiblio($record, $biblionumber, '');
+        my $new_record = GetMarcBiblio($biblionumber);
+        $result->{'status'} = "ok";
+        $result->{'biblionumber'} = $biblionumber;
+        my $xml = $new_record->as_xml_record();
+        $xml =~ s/<\?xml.*?\?>//i;
+        $result->{'marcxml'} =  $xml;
+        $do_not_escape = 1;
+    }
+   
+    print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => $do_not_escape); 
+}
diff --git a/svc/bib_profile b/svc/bib_profile
new file mode 100755 (executable)
index 0000000..41ea042
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/perl
+
+# Copyright 2007 LibLime
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+#
+
+use strict;
+use CGI;
+use C4::Auth qw/check_api_auth/;
+use C4::Context;
+use C4::Koha;
+use XML::Simple;
+
+my $query = new CGI;
+
+my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
+
+if ($status eq "ok") {
+    print $query->header(-type => 'text/xml', cookie => $cookie);
+} else {
+    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
+    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
+    exit 0;
+}
+
+my $dbh = C4::Context->dbh;
+
+# get list of required tags
+my $result = {};
+$result->{'auth_status'} = $status;
+_get_mandatory_tags($result);
+_get_mandatory_subfields($result);
+_get_reserved_tags($result);
+_get_bib_number_tag($result);
+_get_biblioitem_itemtypes($result);
+print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1,  
+        GroupTags => {mandatory_tags => 'tag', mandatory_subfields => 'subfield', reserved_tags => 'tag',
+                      valid_values => 'value'});
+
+exit 0;
+
+sub _get_mandatory_tags {
+    my $result = shift;
+    my $sth = $dbh->prepare_cached("SELECT tagfield FROM marc_tag_structure WHERE frameworkcode = '' AND mandatory = 1");
+    $sth->execute();
+    my @tags = ();
+    while (my $row = $sth->fetchrow_arrayref) {
+        push @tags, $row->[0];
+    }
+    $result->{'mandatory_tags'} = \@tags;
+}
+
+sub _get_mandatory_subfields {
+    my $result = shift;
+    my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield 
+                                    FROM marc_subfield_structure 
+                                    WHERE frameworkcode = '' 
+                                    AND tagsubfield <> '\@' 
+                                    AND mandatory = 1");
+    $sth->execute();
+    my @subfields = ();
+    while (my $row = $sth->fetchrow_arrayref) {
+        push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
+    }
+    $result->{'mandatory_subfields'} = \@subfields;
+}
+
+sub _get_reserved_tags {
+    my $result = shift;
+    my $sth = $dbh->prepare_cached("SELECT DISTINCT tagfield
+                                    FROM marc_subfield_structure 
+                                    WHERE frameworkcode = '' 
+                                    AND (kohafield = 'items.itemnumber' OR kohafield = 'biblioitems.itemtype' OR
+                                         kohafield = 'biblio.biblionumber')");
+    $sth->execute();
+    my @tags = ();
+    while (my $row = $sth->fetchrow_arrayref) {
+        push @tags, $row->[0];
+    }
+    $result->{'reserved_tags'} = \@tags;
+}
+
+sub _get_bib_number_tag {
+    my $result = shift;
+    my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
+                                    FROM marc_subfield_structure 
+                                    WHERE frameworkcode = '' 
+                                    AND kohafield = 'biblio.biblionumber'");
+    $sth->execute();
+    my @tags = ();
+    while (my $row = $sth->fetchrow_arrayref) {
+        push @tags, { tag => $row->[0], subfield => $row->[1] };
+    }
+    $result->{'bib_number'} = \@tags;
+}
+
+sub _get_biblioitem_itemtypes {
+    my $result = shift;
+    my $itemtypes = GetItemTypes;
+    my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
+                                    FROM marc_subfield_structure 
+                                    WHERE frameworkcode = '' 
+                                    AND kohafield = 'biblioitems.itemtype'");
+    $sth->execute();
+    my @tags = ();
+    while (my $row = $sth->fetchrow_arrayref) {
+        push @tags, { tag => $row->[0], subfield => $row->[1] };
+    }
+    my @valid_values = map { { code => $_,  description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
+    $result->{'special_entry'} = { field => \@tags,  valid_values => \@valid_values };
+    
+}
diff --git a/svc/new_bib b/svc/new_bib
new file mode 100755 (executable)
index 0000000..ddcdb27
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+
+# Copyright 2007 LibLime
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+#
+
+use strict;
+use CGI;
+use C4::Auth qw/check_api_auth/;
+use C4::Biblio;
+use XML::Simple;
+
+my $query = new CGI;
+
+my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
+unless ($status eq "ok") {
+    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
+    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
+    exit 0;
+}
+
+if ($query->request_method eq "POST") {
+    add_bib($query);
+} else {
+    print $query->header(-type => 'text/xml', -status => '400 Bad Request');
+}
+
+exit 0;
+
+sub add_bib {
+    my $query = shift;
+
+    my $result = {};
+    my $inxml = $query->param('POSTDATA');
+    print $query->header(-type => 'text/xml');
+
+    my $record = eval {MARC::Record::new_from_xml( $inxml, "utf8", C4::Context->preference('marcflavour'))};
+    my $do_not_escape = 0;
+    if ($@) {
+        $result->{'status'} = "failed";
+        $result->{'error'} = $@;
+    } else {
+        # delete any item tags
+        my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber", '');
+        foreach my $field ($record->field($itemtag)) {
+            $record->delete_field($field);
+        }
+        my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
+        my $new_record = GetMarcBiblio($biblionumber);
+        $result->{'status'} = "ok";
+        $result->{'biblionumber'} = $biblionumber;
+        my $xml = $new_record->as_xml_record();
+        $xml =~ s/<\?xml.*?\?>//i;
+        $result->{'marcxml'} =  $xml;
+        $do_not_escape = 1;
+    }
+   
+    print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => $do_not_escape); 
+}