Adding Version variable to systempreferences.
[koha.git] / admin / checkmarc.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
16 #
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
20
21 use strict;
22 use C4::Output;
23 use C4::Interface::CGI::Output;
24 use C4::Auth;
25 use CGI;
26 use C4::Context;
27 use C4::Biblio;
28
29
30 my $input = new CGI;
31
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                              });
40
41 my $dbh = C4::Context->dbh;
42 my $total;
43 # checks itemnum field
44 my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
45 $sth->execute;
46 my ($res) = $sth->fetchrow;
47 if ($res==-1) {
48         $template->param(itemnum => 0);
49 } else {
50         $template->param(itemnum => 1);
51         $total++;
52 }
53
54 # checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1)
55 $sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblio.biblionumber\"");
56 $sth->execute;
57 my $tab;
58 ($res,$tab) = $sth->fetchrow;
59 $sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblioitems.biblioitemnumber\"");
60 $sth->execute;
61 my ($res2,$tab2) = $sth->fetchrow;
62 if ($res && $res2 && $tab==-1 && $tab2==-1) {
63         $template->param(biblionumber => 0);
64 } else {
65         $template->param(biblionumber => 1);
66         $total++;
67 }
68
69 # checks all item fields are in the same tag and in tab 10
70
71 $sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\"");
72 $sth->execute;
73 my $field;
74 ($res,$res2,$field) = $sth->fetchrow;
75 my $tagfield = $res;
76 my $tab = $res2;
77 my $subtotal=0;
78 #warn "TAGF : $tagfield";
79 while (($res,$res2,$field) = $sth->fetchrow) {
80         # (ignore itemnumber, that must be in -1 tab)
81         if (($res ne $tagfield or $res2 ne $tab ) && $res2 ne -1) {
82                 $subtotal++;
83         }
84 }
85 $sth = $dbh->prepare("select kohafield from marc_subfield_structure where tagfield=?");
86 $sth->execute($tagfield);
87 while (($res2) = $sth->fetchrow) {
88         if (!$res2 || $res2 =~ /^items/) {
89         } else {
90                 $subtotal++;
91         }
92 }
93 if ($subtotal eq 0) {
94         $template->param(itemfields => 0);
95 } else {
96         $template->param(itemfields => 1);
97         $total++;
98 }
99
100 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where tab = 10");
101 $sth->execute;
102 my $totaltags = 0;
103 my $list = "";
104 while (($res2) = $sth->fetchrow) {
105         $totaltags++;
106         $list.=$res2.",";
107 }
108 if ($totaltags > 1) {
109         $template->param(itemtags => $list);
110         $total++;
111 } else {
112         $template->param(itemtags => 0);
113 }
114
115
116 # checks biblioitems.itemtype must be mapped and use authorised_value=itemtype
117 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\"");
118 $sth->execute;
119 ($res,$res2,$field) = $sth->fetchrow;
120 if ($res && $res2>=0 && $field eq "itemtypes") {
121         $template->param(itemtype => 0);
122 } else {
123         $template->param(itemtype => 1);
124         $total++;
125 }
126
127 # checks items.homebranch must be mapped and use authorised_value=branches
128 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\"");
129 $sth->execute;
130 ($res,$res2,$field) = $sth->fetchrow;
131 if ($res && $res2 eq 10 && $field eq "branches") {
132         $template->param(branch => 0);
133 } else {
134         $template->param(branch => 1);
135         $total++;
136 }
137 # checks items.homebranch must be mapped and use authorised_value=branches
138 $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\"");
139 $sth->execute;
140 ($res,$res2,$field) = $sth->fetchrow;
141 if ($res && $res2 eq 10 && $field eq "branches") {
142         $template->param(holdingbranch => 0);
143 } else {
144         $template->param(holdingbranch => 1);
145         $total++;
146 }
147
148 # checks that itemtypes & branches tables are not empty
149 $sth = $dbh->prepare("select count(*) from itemtypes");
150 $sth->execute;
151 ($res) = $sth->fetchrow;
152 unless ($res) {
153         $template->param(itemtypes_empty =>1);
154         $total++;
155 }
156
157 $sth = $dbh->prepare("select count(*) from branches");
158 $sth->execute;
159 ($res) = $sth->fetchrow;
160 unless ($res) {
161         $template->param(branches_empty =>1);
162         $total++;
163 }
164
165 $sth = $dbh->prepare("select count(*) from marc_biblio where frameworkcode is NULL");
166 $sth->execute;
167 ($res) = $sth->fetchrow;
168 if ($res) {
169         $template->param(frameworknull =>1);
170         $total++;
171 }
172 $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL");
173 $sth->execute;
174 ($res) = $sth->fetchrow;
175 if ($res) {
176         $template->param(frameworknull =>1);
177         $total++;
178 }
179 $sth = $dbh->prepare("select count(*) from marc_tag_structure where frameworkcode is NULL");
180 $sth->execute;
181 ($res) = $sth->fetchrow;
182 if ($res) {
183         $template->param(frameworknull =>1);
184         $total++;
185 }
186
187 $template->param(total => $total,
188                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
189                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
190                 IntranetNav => C4::Context->preference("IntranetNav"),
191                 );
192 output_html_with_http_headers $input, $cookie, $template->output;