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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
31 my ($template, $borrowernumber, $cookie)
32 = get_template_and_user
({template_name
=> "admin/checkmarc.tt",
36 flagsrequired
=> {parameters
=> 'parameters_remaining_permissions'},
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);
175 # checks that itemtypes & branches tables are not empty
176 $sth = $dbh->prepare("select count(*) from itemtypes");
178 ($res) = $sth->fetchrow;
180 $template->param(itemtypes_empty
=>0);
182 $template->param(itemtypes_empty
=>1);
187 $sth = $dbh->prepare("select count(*) from branches");
189 ($res) = $sth->fetchrow;
191 $template->param(branches_empty
=>0);
193 $template->param(branches_empty
=>1);
197 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
199 ($res) = $sth->fetchrow;
201 $template->param(frameworknull
=>1);
204 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
206 ($res) = $sth->fetchrow;
208 $template->param(frameworknull
=>1);
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)
218 GROUP BY tagfield, frameworkcode, frameworktext
219 HAVING COUNT(DISTINCT tab) > 1");
221 my $inconsistent_tabs = $sth->fetchall_arrayref({});
222 if (scalar(@
$inconsistent_tabs) > 0) {
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 <> ''
236 AND authtypecode NOT IN (SELECT authtypecode FROM auth_types)
237 ORDER BY frameworkcode, tagfield, tagsubfield");
239 my $invalid_authtypecodes = $sth->fetchall_arrayref({});
240 if (scalar(@
$invalid_authtypecodes) > 0) {
242 $template->param(invalid_authtypecodes
=> 1);
243 $template->param(authtypecode_info
=> $invalid_authtypecodes);
246 # checks items.permanent_location is not mapped
247 $sth = $dbh->prepare("SELECT frameworkcode, frameworktext, tagfield, tagsubfield
248 FROM marc_subfield_structure
249 LEFT JOIN biblio_framework USING (frameworkcode)
250 WHERE kohafield='permanent_location' OR
251 kohafield='items.permanent_location'");
253 my $permanent_location_mapped = $sth->fetchall_arrayref({});
254 if (scalar(@
$permanent_location_mapped) > 0) {
256 $template->param(permanent_location_mapped
=> 1);
257 $template->param(mapped_permanent_location
=> $permanent_location_mapped);
261 $template->param(total
=> $total,
264 output_html_with_http_headers
$input, $cookie, $template->output;