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
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #use warnings; FIXME - Bug 2505
32 my ($template, $borrowernumber, $cookie)
33 = get_template_and_user
({template_name
=> "admin/checkmarc.tmpl",
37 flagsrequired
=> {parameters
=> 'parameters_remaining_permissions'},
41 my $dbh = C4
::Context
->dbh;
43 # checks itemnum field
44 my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
46 while (my ($res) = $sth->fetchrow) {
48 $template->param(itemnum
=> 0);
50 $template->param(itemnum
=> 1);
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\"");
61 while (my ($res,$tab,$frameworkcode) = $sth->fetchrow) {
66 if ($bibliotag != $res) {
67 $template->param(biblionumber
=> 1);
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);
81 $template->param(biblionumber
=> 1);
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");
95 ($res,$res2,$field) = $sth->fetchrow;
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)) {
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/) {
114 if ($subtotal == 0) {
115 $template->param(itemfields
=> 0);
117 $template->param(itemfields
=> 1);
121 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where tab = 10");
125 while (($res2) = $sth->fetchrow) {
129 if ($totaltags > 1) {
130 $template->param(itemtags
=> $list);
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\"");
140 while (($res,$res2,$field) = $sth->fetchrow) {
141 if ($res && $res2>=0 && $field eq "itemtypes") {
142 $template->param(itemtype
=> 0);
144 $template->param(itemtype
=> 1);
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\"");
153 while (($res,$res2,$field) = $sth->fetchrow) {
154 if ($res && $res2 eq 10 && $field eq "branches") {
155 $template->param(branch
=> 0);
157 $template->param(branch
=> 1);
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\"");
166 while (($res,$res2,$field) = $sth->fetchrow) {
167 if ($res && $res2 eq 10 && $field eq "branches") {
168 $template->param(holdingbranch
=> 0);
170 $template->param(holdingbranch
=> 1);
176 # checks that itemtypes & branches tables are not empty
177 $sth = $dbh->prepare("select count(*) from itemtypes");
179 ($res) = $sth->fetchrow;
181 $template->param(itemtypes_empty
=>0);
183 $template->param(itemtypes_empty
=>1);
188 $sth = $dbh->prepare("select count(*) from branches");
190 ($res) = $sth->fetchrow;
192 $template->param(branches_empty
=>0);
194 $template->param(branches_empty
=>1);
198 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
200 ($res) = $sth->fetchrow;
202 $template->param(frameworknull
=>1);
205 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
207 ($res) = $sth->fetchrow;
209 $template->param(frameworknull
=>1);
213 # verify that all of a field's subfields (except the ones explicitly ignored)
214 # are in the same tab
215 $sth = $dbh->prepare("SELECT tagfield, frameworkcode, frameworktext, GROUP_CONCAT(DISTINCT tab) AS tabs
216 FROM marc_subfield_structure
217 LEFT JOIN biblio_framework USING (frameworkcode)
219 GROUP BY tagfield, frameworkcode, frameworktext
220 HAVING COUNT(DISTINCT tab) > 1");
222 my $inconsistent_tabs = $sth->fetchall_arrayref({});
223 if (scalar(@
$inconsistent_tabs) > 0) {
225 $template->param(inconsistent_tabs
=> 1);
226 $template->param(tab_info
=> $inconsistent_tabs);
229 # verify that authtypecodes used in the framework
230 # are defined in auth_types
231 $sth = $dbh->prepare("SELECT frameworkcode, frameworktext, tagfield, tagsubfield, authtypecode
232 FROM marc_subfield_structure
233 LEFT JOIN biblio_framework USING (frameworkcode)
234 WHERE authtypecode IS NOT NULL
235 AND authtypecode <> ''
237 AND authtypecode NOT IN (SELECT authtypecode FROM auth_types)
238 ORDER BY frameworkcode, tagfield, tagsubfield");
240 my $invalid_authtypecodes = $sth->fetchall_arrayref({});
241 if (scalar(@
$invalid_authtypecodes) > 0) {
243 $template->param(invalid_authtypecodes
=> 1);
244 $template->param(authtypecode_info
=> $invalid_authtypecodes);
247 $template->param(total
=> $total,
250 output_html_with_http_headers
$input, $cookie, $template->output;