Bug 4470 Patron search result pagination bar
[koha.git] / admin / checkmarc.pl
blobca91164cde47580a4b3a33df471c8fb3ce64f1fc
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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.
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.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Output;
24 use C4::Auth;
25 use CGI;
26 use C4::Context;
27 use C4::Biblio;
30 my $input = new CGI;
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 });
41 my $dbh = C4::Context->dbh;
42 my $total = 0;
43 # checks itemnum field
44 my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
45 $sth->execute;
46 while (my ($res) = $sth->fetchrow) {
47 if ($res==-1) {
48 $template->param(itemnum => 0);
49 } else {
50 $template->param(itemnum => 1);
51 $total++;
52 last;
56 # checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1)
57 $sth = $dbh->prepare("select tagfield,tab,frameworkcode from marc_subfield_structure where kohafield=\"biblio.biblionumber\"");
58 $sth->execute;
59 my $first = 1;
60 my $bibliotag = '';
61 while (my ($res,$tab,$frameworkcode) = $sth->fetchrow) {
62 if ($first) {
63 $bibliotag = $res;
64 $first = 0;
65 } else {
66 if ($bibliotag != $res) {
67 $template->param(biblionumber => 1);
68 $total++;
69 last;
72 my $sth2 = $dbh->prepare("SELECT tagfield,tab
73 FROM marc_subfield_structure
74 WHERE kohafield=\"biblioitems.biblioitemnumber\"
75 AND frameworkcode = ? ");
76 $sth2->execute($frameworkcode);
77 my ($res2,$tab2) = $sth2->fetchrow;
78 if ($res && $res2 && $tab==-1 && $tab2==-1) {
79 $template->param(biblionumber => 0);
80 } else {
81 $template->param(biblionumber => 1);
82 $total++;
83 last;
87 # checks all item fields are in the same tag and in tab 10
89 $sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\" and tab >=0");
90 $sth->execute;
91 my $field;
92 my $res;
93 my $res2;
94 my $tab;
95 ($res,$res2,$field) = $sth->fetchrow;
96 my $tagfield = $res;
97 $tab = $res2;
98 my $subtotal=0;
99 #warn "TAGF : $tagfield";
100 while (($res,$res2,$field) = $sth->fetchrow) {
101 # (ignore itemnumber, that must be in -1 tab)
102 if (($res ne $tagfield) or ($res2 ne $tab)) {
103 $subtotal++;
106 $sth = $dbh->prepare("select kohafield from marc_subfield_structure where tagfield=?");
107 $sth->execute($tagfield);
108 while (($res2) = $sth->fetchrow) {
109 if (!$res2 || $res2 =~ /^items/) {
110 } else {
111 $subtotal++;
114 if ($subtotal == 0) {
115 $template->param(itemfields => 0);
116 } else {
117 $template->param(itemfields => 1);
118 $total++;
121 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where tab = 10");
122 $sth->execute;
123 my $totaltags = 0;
124 my $list = "";
125 while (($res2) = $sth->fetchrow) {
126 $totaltags++;
127 $list.=$res2.",";
129 if ($totaltags > 1) {
130 $template->param(itemtags => $list);
131 $total++;
132 } else {
133 $template->param(itemtags => 0);
137 # checks biblioitems.itemtype must be mapped and use authorised_value=itemtype
138 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\"");
139 $sth->execute;
140 while (($res,$res2,$field) = $sth->fetchrow) {
141 if ($res && $res2>=0 && $field eq "itemtypes") {
142 $template->param(itemtype => 0);
143 } else {
144 $template->param(itemtype => 1);
145 $total++;
146 last;
150 # checks items.homebranch must be mapped and use authorised_value=branches
151 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\"");
152 $sth->execute;
153 while (($res,$res2,$field) = $sth->fetchrow) {
154 if ($res && $res2 eq 10 && $field eq "branches") {
155 $template->param(branch => 0);
156 } else {
157 $template->param(branch => 1);
158 $total++;
159 last;
163 # checks items.homebranch must be mapped and use authorised_value=branches
164 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\"");
165 $sth->execute;
166 while (($res,$res2,$field) = $sth->fetchrow) {
167 if ($res && $res2 eq 10 && $field eq "branches") {
168 $template->param(holdingbranch => 0);
169 } else {
170 $template->param(holdingbranch => 1);
171 $total++;
175 # checks that itemtypes & branches tables are not empty
176 $sth = $dbh->prepare("select count(*) from itemtypes");
177 $sth->execute;
178 ($res) = $sth->fetchrow;
179 if ($res) {
180 $template->param(itemtypes_empty =>0);
181 } else {
182 $template->param(itemtypes_empty =>1);
183 $total++;
187 $sth = $dbh->prepare("select count(*) from branches");
188 $sth->execute;
189 ($res) = $sth->fetchrow;
190 if ($res) {
191 $template->param(branches_empty =>0);
192 } else {
193 $template->param(branches_empty =>1);
194 $total++;
197 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
198 $sth->execute;
199 ($res) = $sth->fetchrow;
200 if ($res) {
201 $template->param(frameworknull =>1);
202 $total++;
204 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
205 $sth->execute;
206 ($res) = $sth->fetchrow;
207 if ($res) {
208 $template->param(frameworknull =>1);
209 $total++;
212 # verify that all of a field's subfields (except the ones explicitly ignored)
213 # are in the same tab
214 $sth = $dbh->prepare("SELECT tagfield, frameworkcode, frameworktext, GROUP_CONCAT(DISTINCT tab) AS tabs
215 FROM marc_subfield_structure
216 LEFT JOIN biblio_framework USING (frameworkcode)
217 WHERE tab != -1
218 GROUP BY tagfield, frameworkcode, frameworktext
219 HAVING COUNT(DISTINCT tab) > 1");
220 $sth->execute;
221 my $inconsistent_tabs = $sth->fetchall_arrayref({});
222 if (scalar(@$inconsistent_tabs) > 0) {
223 $total++;
224 $template->param(inconsistent_tabs => 1);
225 $template->param(tab_info => $inconsistent_tabs);
228 # verify that authtypecodes used in the framework
229 # are defined in auth_types
230 $sth = $dbh->prepare("SELECT frameworkcode, frameworktext, tagfield, tagsubfield, authtypecode
231 FROM marc_subfield_structure
232 LEFT JOIN biblio_framework USING (frameworkcode)
233 WHERE authtypecode IS NOT NULL
234 AND authtypecode <> ''
235 AND tab > '-1'
236 AND authtypecode NOT IN (SELECT authtypecode FROM auth_types)
237 ORDER BY frameworkcode, tagfield, tagsubfield");
238 $sth->execute;
239 my $invalid_authtypecodes = $sth->fetchall_arrayref({});
240 if (scalar(@$invalid_authtypecodes) > 0) {
241 $total++;
242 $template->param(invalid_authtypecodes => 1);
243 $template->param(authtypecode_info => $invalid_authtypecodes);
246 $template->param(total => $total,
249 output_html_with_http_headers $input, $cookie, $template->output;