Adding a sprintf to format the fields involving currency to 2 decimal places
[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 use HTML::Template;
30
31 my $input = new CGI;
32
33 my ($template, $borrowernumber, $cookie)
34     = get_template_and_user({template_name => "admin/checkmarc.tmpl",
35                              query => $input,
36                              type => "intranet",
37                              authnotrequired => 0,
38                              flagsrequired => {parameters => 1},
39                              debug => 1,
40                              });
41
42 my $dbh = C4::Context->dbh;
43 my $total;
44 # checks itemnum field
45 my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
46 $sth->execute;
47 my ($res) = $sth->fetchrow;
48 if ($res==-1) {
49         $template->param(itemnum => 0);
50 } else {
51         $template->param(itemnum => 1);
52         $total++;
53 }
54
55 # checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1)
56 $sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblio.biblionumber\"");
57 $sth->execute;
58 my $tab;
59 ($res,$tab) = $sth->fetchrow;
60 $sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblioitems.biblioitemnumber\"");
61 $sth->execute;
62 my ($res2,$tab2) = $sth->fetchrow;
63 if ($res && $res2 && ($res eq $res2) && $tab==-1 && $tab2==-1) {
64         $template->param(biblionumber => 0);
65 } else {
66         $template->param(biblionumber => 1);
67         $total++;
68 }
69
70 # checks all item fields are in the same tag and in tab 10
71
72 $sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\"");
73 $sth->execute;
74 my $field;
75 ($res,$res2,$field) = $sth->fetchrow;
76 my $tagfield = $res;
77 my $tab = $res2;
78 my $subtotal=0;
79 warn "TAGF : $tagfield";
80 while (($res,$res2,$field) = $sth->fetchrow) {
81         # (ignore itemnumber, that must be in -1 tab)
82         if (($res ne $tagfield or $res2 ne $tab ) && $res2 ne -1) {
83                 $subtotal++;
84         }
85 }
86 $sth = $dbh->prepare("select kohafield from marc_subfield_structure where tagfield=?");
87 $sth->execute($tagfield);
88 while (($res2) = $sth->fetchrow) {
89         if (!$res2 || $res2 =~ /^items/) {
90         } else {
91                 $subtotal++;
92         }
93 }
94 if ($subtotal eq 0) {
95         $template->param(itemfields => 0);
96 } else {
97         $template->param(itemfields => 1);
98         $total++;
99 }
100
101 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where tab = 10");
102 $sth->execute;
103 my $totaltags = 0;
104 my $list = "";
105 while (($res2) = $sth->fetchrow) {
106         $totaltags++;
107         $list.=$res2.",";
108 }
109 if ($totaltags > 1) {
110         $template->param(itemtags => $list);
111         $total++;
112 } else {
113         $template->param(itemtags => 0);
114 }
115
116
117 # checks biblioitems.itemtype must be mapped and use authorised_value=itemtype
118 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\"");
119 $sth->execute;
120 ($res,$res2,$field) = $sth->fetchrow;
121 if ($res && $res2>=0 && $field eq "itemtypes") {
122         $template->param(itemtype => 0);
123 } else {
124         $template->param(itemtype => 1);
125         $total++;
126 }
127
128 # checks items.homebranch must be mapped and use authorised_value=branches
129 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\"");
130 $sth->execute;
131 ($res,$res2,$field) = $sth->fetchrow;
132 if ($res && $res2 eq 10 && $field eq "branches") {
133         $template->param(branch => 0);
134 } else {
135         $template->param(branch => 1);
136         $total++;
137 }
138 # checks items.homebranch must be mapped and use authorised_value=branches
139 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\"");
140 $sth->execute;
141 ($res,$res2,$field) = $sth->fetchrow;
142 if ($res && $res2 eq 10 && $field eq "branches") {
143         $template->param(holdingbranch => 0);
144 } else {
145         $template->param(holdingbranch => 1);
146         $total++;
147 }
148
149 # checks that itemtypes & branches tables are not empty
150 $sth = $dbh->prepare("select count(*) from itemtypes");
151 $sth->execute;
152 ($res) = $sth->fetchrow;
153 unless ($res) {
154         $template->param(itemtypes_empty =>1);
155         $total++;
156 }
157
158 $sth = $dbh->prepare("select count(*) from branches");
159 $sth->execute;
160 ($res) = $sth->fetchrow;
161 unless ($res) {
162         $template->param(branches_empty =>1);
163         $total++;
164 }
165
166 $sth = $dbh->prepare("select count(*) from marc_biblio where frameworkcode is NULL");
167 $sth->execute;
168 ($res) = $sth->fetchrow;
169 if ($res) {
170         $template->param(frameworknull =>1);
171         $total++;
172 }
173 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
174 $sth->execute;
175 ($res) = $sth->fetchrow;
176 if ($res) {
177         $template->param(frameworknull =>1);
178         $total++;
179 }
180 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
181 $sth->execute;
182 ($res) = $sth->fetchrow;
183 if ($res) {
184         $template->param(frameworknull =>1);
185         $total++;
186 }
187
188 $template->param(total => $total);
189 output_html_with_http_headers $input, $cookie, $template->output;