New XML API
[koha.git] / admin / checkmarc.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use C4::Output;
23 use C4::Interface::CGI::Output;
24 use C4::Auth;
25 use CGI;
26 use C4::Search;
27 use C4::Context;
28 use C4::Biblio;
29
30 my $input = new CGI;
31
32 my ($template, $borrowernumber, $cookie)
33     = get_template_and_user({template_name => "admin/checkmarc.tmpl",
34                              query => $input,
35                              type => "intranet",
36                              authnotrequired => 0,
37                              flagsrequired => {parameters => 1},
38                              debug => 1,
39                              });
40
41 my $dbh = C4::Context->dbh;
42 my $total;
43 # checks itemnumber field
44 my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"itemnumber\"");
45 $sth->execute;
46 my ($res) = $sth->fetchrow;
47 unless ($res) {
48         $template->param(itemnumber => 1);
49         $total++;
50 }
51 #check biblionumber
52 my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"biblionumber\"");
53 $sth->execute;
54 my ($res) = $sth->fetchrow;
55 if ($res ){
56         ($res) = $sth->fetchrow;
57         unless ($res){
58         $template->param(biblionumber => 1);
59         $total++;
60         }
61 }
62 #check barcode
63 my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"barcode\"");
64 $sth->execute;
65 my ($res) = $sth->fetchrow;
66 unless ($res){
67         $template->param(barcode=> 1);
68         $total++;
69 }
70 #check isbn
71 my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"isbn\"");
72 $sth->execute;
73 my ($res) = $sth->fetchrow;
74 unless ($res){
75         $template->param(isbn => 1);
76         $total++;
77 }
78 ## Check for itemtype
79 my $sth = $dbh->prepare("select tagfield,tagsubfield from koha_attr where marctokoha=\"itemtype\"");
80 $sth->execute;
81 my ($res,$res2) = $sth->fetchrow;
82 if ($res) {
83 $sth = $dbh->prepare("select authorised_value from biblios_subfield_structure where tagfield=? and tagsubfield=?");
84 $sth->execute($res,$res2);
85  my ($item)=$sth->fetchrow;
86     unless ($item eq "itemtypes"){
87         $template->param(itemtype => 1);
88         $total++;
89     }
90 }
91
92 ## Check for homebranch
93 my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"homebranch\"");
94 $sth->execute;
95 my ($res) = $sth->fetchrow;
96 unless  ($res) {
97         $template->param(branch => 1);
98         $total++;
99     
100 }
101
102 ## Check for holdingbranch
103 my $sth = $dbh->prepare("select tagfield,tagsubfield from koha_attr where marctokoha=\"holdingbranch\"");
104 $sth->execute;
105 my ($res,$res2) = $sth->fetchrow;
106 if ($res) {
107 $sth = $dbh->prepare("select authorised_value from biblios_subfield_structure where tagfield=? and tagsubfield=?");
108 $sth->execute($res,$res2);
109  my ($item)=$sth->fetchrow;
110     unless ($item eq "branches"){
111         $template->param(holdingbranch => 1);
112         $total++;
113     }
114 }
115
116
117
118 # checks that itemtypes & branches tables are not empty
119 $sth = $dbh->prepare("select count(*) from itemtypes");
120 $sth->execute;
121 ($res) = $sth->fetchrow;
122 unless ($res) {
123         $template->param(itemtypes_empty =>1);
124         $total++;
125 }
126
127 $sth = $dbh->prepare("select count(*) from branches");
128 $sth->execute;
129 ($res) = $sth->fetchrow;
130 unless ($res) {
131         $template->param(branches_empty =>1);
132         $total++;
133 }
134
135 $template->param(total => $total);
136 output_html_with_http_headers $input, $cookie, $template->output;