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 my ($res) = $sth->fetchrow;
47 $template->param(itemnum => 0);
49 $template->param(itemnum => 1);
53 # checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1)
54 $sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblio.biblionumber\"");
57 ($res,$tab) = $sth->fetchrow;
58 $sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblioitems.biblioitemnumber\"");
60 my ($res2,$tab2) = $sth->fetchrow;
61 if ($res && $res2 && $tab==-1 && $tab2==-1) {
62 $template->param(biblionumber => 0);
64 $template->param(biblionumber => 1);
68 # checks all item fields are in the same tag and in tab 10
70 $sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\" and tab >=0");
73 ($res,$res2,$field) = $sth->fetchrow;
77 #warn "TAGF : $tagfield";
78 while (($res,$res2,$field) = $sth->fetchrow) {
79 # (ignore itemnumber, that must be in -1 tab)
80 if (($res ne $tagfield) or ($res2 ne $tab)) {
84 $sth = $dbh->prepare("select kohafield from marc_subfield_structure where tagfield=?");
85 $sth->execute($tagfield);
86 while (($res2) = $sth->fetchrow) {
87 if (!$res2 || $res2 =~ /^items/) {
93 $template->param(itemfields => 0);
95 $template->param(itemfields => 1);
99 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where tab = 10");
103 while (($res2) = $sth->fetchrow) {
107 if ($totaltags > 1) {
108 $template->param(itemtags => $list);
111 $template->param(itemtags => 0);
115 # checks biblioitems.itemtype must be mapped and use authorised_value=itemtype
116 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\"");
118 ($res,$res2,$field) = $sth->fetchrow;
119 if ($res && $res2>=0 && $field eq "itemtypes") {
120 $template->param(itemtype => 0);
122 $template->param(itemtype => 1);
126 # checks items.homebranch must be mapped and use authorised_value=branches
127 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\"");
129 ($res,$res2,$field) = $sth->fetchrow;
130 if ($res && $res2 eq 10 && $field eq "branches") {
131 $template->param(branch => 0);
133 $template->param(branch => 1);
136 # checks items.homebranch must be mapped and use authorised_value=branches
137 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\"");
139 ($res,$res2,$field) = $sth->fetchrow;
140 if ($res && $res2 eq 10 && $field eq "branches") {
141 $template->param(holdingbranch => 0);
143 $template->param(holdingbranch => 1);
147 # checks that itemtypes & branches tables are not empty
148 $sth = $dbh->prepare("select count(*) from itemtypes");
150 ($res) = $sth->fetchrow;
152 $template->param(itemtypes_empty =>0);
154 $template->param(itemtypes_empty =>1);
159 $sth = $dbh->prepare("select count(*) from branches");
161 ($res) = $sth->fetchrow;
163 $template->param(branches_empty =>0);
165 $template->param(branches_empty =>1);
169 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
171 ($res) = $sth->fetchrow;
173 $template->param(frameworknull =>1);
176 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
178 ($res) = $sth->fetchrow;
180 $template->param(frameworknull =>1);
184 $template->param(total => $total,
186 output_html_with_http_headers $input, $cookie, $template->output;