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
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 with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
31 my ($template, $borrowernumber, $cookie)
32 = get_template_and_user
({template_name
=> "admin/checkmarc.tmpl",
36 flagsrequired
=> {parameters
=> 1},
40 my $dbh = C4
::Context
->dbh;
42 # checks itemnum field
43 my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
45 while (my ($res) = $sth->fetchrow) {
47 $template->param(itemnum
=> 0);
49 $template->param(itemnum
=> 1);
55 # checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1)
56 $sth = $dbh->prepare("select tagfield,tab,frameworkcode from marc_subfield_structure where kohafield=\"biblio.biblionumber\"");
60 while (my ($res,$tab,$frameworkcode) = $sth->fetchrow) {
65 if ($bibliotag != $res) {
66 $template->param(biblionumber
=> 1);
71 my $sth2 = $dbh->prepare("SELECT tagfield,tab
72 FROM marc_subfield_structure
73 WHERE kohafield=\"biblioitems.biblioitemnumber\"
74 AND frameworkcode = ? ");
75 $sth2->execute($frameworkcode);
76 my ($res2,$tab2) = $sth2->fetchrow;
77 if ($res && $res2 && $tab==-1 && $tab2==-1) {
78 $template->param(biblionumber
=> 0);
80 $template->param(biblionumber
=> 1);
86 # checks all item fields are in the same tag and in tab 10
88 $sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\" and tab >=0");
94 ($res,$res2,$field) = $sth->fetchrow;
98 #warn "TAGF : $tagfield";
99 while (($res,$res2,$field) = $sth->fetchrow) {
100 # (ignore itemnumber, that must be in -1 tab)
101 if (($res ne $tagfield) or ($res2 ne $tab)) {
105 $sth = $dbh->prepare("select kohafield from marc_subfield_structure where tagfield=?");
106 $sth->execute($tagfield);
107 while (($res2) = $sth->fetchrow) {
108 if (!$res2 || $res2 =~ /^items/) {
113 if ($subtotal == 0) {
114 $template->param(itemfields
=> 0);
116 $template->param(itemfields
=> 1);
120 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where tab = 10");
124 while (($res2) = $sth->fetchrow) {
128 if ($totaltags > 1) {
129 $template->param(itemtags
=> $list);
132 $template->param(itemtags
=> 0);
136 # checks biblioitems.itemtype must be mapped and use authorised_value=itemtype
137 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\"");
139 while (($res,$res2,$field) = $sth->fetchrow) {
140 if ($res && $res2>=0 && $field eq "itemtypes") {
141 $template->param(itemtype
=> 0);
143 $template->param(itemtype
=> 1);
149 # checks items.homebranch must be mapped and use authorised_value=branches
150 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\"");
152 while (($res,$res2,$field) = $sth->fetchrow) {
153 if ($res && $res2 eq 10 && $field eq "branches") {
154 $template->param(branch
=> 0);
156 $template->param(branch
=> 1);
162 # checks items.homebranch must be mapped and use authorised_value=branches
163 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\"");
165 while (($res,$res2,$field) = $sth->fetchrow) {
166 if ($res && $res2 eq 10 && $field eq "branches") {
167 $template->param(holdingbranch
=> 0);
169 $template->param(holdingbranch
=> 1);
174 # checks that itemtypes & branches tables are not empty
175 $sth = $dbh->prepare("select count(*) from itemtypes");
177 ($res) = $sth->fetchrow;
179 $template->param(itemtypes_empty
=>0);
181 $template->param(itemtypes_empty
=>1);
186 $sth = $dbh->prepare("select count(*) from branches");
188 ($res) = $sth->fetchrow;
190 $template->param(branches_empty
=>0);
192 $template->param(branches_empty
=>1);
196 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
198 ($res) = $sth->fetchrow;
200 $template->param(frameworknull
=>1);
203 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
205 ($res) = $sth->fetchrow;
207 $template->param(frameworknull
=>1);
211 # verify that all of a field's subfields (except the ones explicitly ignored)
212 # are in the same tab
213 $sth = $dbh->prepare("SELECT tagfield, frameworkcode, frameworktext, GROUP_CONCAT(DISTINCT tab) AS tabs
214 FROM marc_subfield_structure
215 LEFT JOIN biblio_framework USING (frameworkcode)
217 GROUP BY tagfield, frameworkcode, frameworktext
218 HAVING COUNT(DISTINCT tab) > 1");
220 my $inconsistent_tabs = $sth->fetchall_arrayref({});
221 if (scalar(@
$inconsistent_tabs) > 0) {
223 $template->param(inconsistent_tabs
=> 1);
224 $template->param(tab_info
=> $inconsistent_tabs);
227 # verify that authtypecodes used in the framework
228 # are defined in auth_types
229 $sth = $dbh->prepare("SELECT frameworkcode, frameworktext, tagfield, tagsubfield, authtypecode
230 FROM marc_subfield_structure
231 LEFT JOIN biblio_framework USING (frameworkcode)
232 WHERE authtypecode IS NOT NULL
233 AND authtypecode <> ''
234 AND authtypecode NOT IN (SELECT authtypecode FROM auth_types)
235 ORDER BY frameworkcode, tagfield, tagsubfield");
237 my $invalid_authtypecodes = $sth->fetchall_arrayref({});
238 if (scalar(@
$invalid_authtypecodes) > 0) {
240 $template->param(invalid_authtypecodes
=> 1);
241 $template->param(authtypecode_info
=> $invalid_authtypecodes);
244 $template->param(total
=> $total,
247 output_html_with_http_headers
$input, $cookie, $template->output;