add in parameters a "check marc" link.

this script checks MARC parameters and try to detect tome errors in configuration.
currently checks 7 differents things.

The 1.3.3 MARC21 parameters fails miserabily to this test : 3 errors !!!
This commit is contained in:
tipaul 2003-01-21 13:45:37 +00:00
parent 219c8df7d1
commit e0a3a53e5b
3 changed files with 176 additions and 5 deletions

127
admin/checkmarc.pl Executable file
View file

@ -0,0 +1,127 @@
#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use C4::Output;
use C4::Charset;
use C4::Auth;
use CGI;
use C4::Search;
use C4::Context;
use C4::Biblio;
use HTML::Template;
my $input = new CGI;
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => "parameters/checkmarc.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 1},
debug => 1,
});
my $dbh = C4::Context->dbh;
my $total;
# checks itemnum field
my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
$sth->execute;
my ($res) = $sth->fetchrow;
if ($res==-1) {
$template->param(itemnum => 0);
} else {
$template->param(itemnum => 1);
$total++;
}
# checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1)
$sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblio.biblionumber\"");
$sth->execute;
my $tab;
($res,$tab) = $sth->fetchrow;
$sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblioitems.biblioitemnumber\"");
$sth->execute;
my ($res2,$tab2) = $sth->fetchrow;
if ($res && $res2 && ($res eq $res2) && $tab==-1 && $tab2==-1) {
$template->param(biblionumber => 0);
} else {
$template->param(biblionumber => 1);
$total++;
}
# checks all item fields are in the same tag and in tab 10
$sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\"");
$sth->execute;
my $field;
($res,$res2,$field) = $sth->fetchrow;
my $tagfield = $res;
my $tab = $res2;
my $subtotal=0;
while (($res,$res2,$field) = $sth->fetchrow) {
# (ignore itemnumber, that must be in -1 tab)
if (($res ne $tagfield or $res2 ne $tab ) && $field ne "items.itemnumber") {
$subtotal++;
}
}
if ($subtotal eq 0) {
$template->param(itemfields => 0);
} else {
$template->param(itemfields => 1);
$total++;
}
# checks biblioitems.itemtype must be mapped and use authorised_value=itemtype
$sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\"");
$sth->execute;
($res,$res2,$field) = $sth->fetchrow;
warn "==> $res / $res2 / $field";
if ($res && $res2>=0 && $field eq "itemtypes") {
$template->param(itemtype => 0);
} else {
$template->param(itemtype => 1);
$total++;
}
# checks items.homebranch must be mapped and use authorised_value=branches
$sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\"");
$sth->execute;
($res,$res2,$field) = $sth->fetchrow;
if ($res && $res2 eq 10 && $field eq "branches") {
$template->param(branch => 0);
} else {
$template->param(branch => 1);
$total++;
}
# checks items.homebranch must be mapped and use authorised_value=branches
$sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\"");
$sth->execute;
($res,$res2,$field) = $sth->fetchrow;
if ($res && $res2 eq 10 && $field eq "branches") {
$template->param(holdingbranch => 0);
} else {
$template->param(holdingbranch => 1);
$total++;
}
$template->param(total => $total);
print $input->header(
-type => guesstype($template->output),
-cookie => $cookie
), $template->output;

View file

@ -295,7 +295,7 @@ function active(numlayer)
function Check(f) {
var total_errors=0;
// alert(f.field_value.length);
for (i=0 ; i<f.field_value.length ; i++) {
for (i=0 ; i<f.field_value.length-2 ; i++) {
// alert (f.field_value[i].value);
if (f.field_value[i].value.length==0 && f.mandatory[i].value==1) {
document.getElementById("error"+i).style.backgroundColor="#FF0000";

View file

@ -6,7 +6,7 @@
font-size:10pt;}
</STYLE>
<form method="post" action="additem.pl">
<form method="post" action="additem.pl" name="f">
<table width=100% cellspacing=0 cellpadding=5 border=1>
<tr background="/images/background-mem.gif">
<th>MARC biblio : <TMPL_VAR name="bibid"></th>
@ -69,21 +69,65 @@
<TMPL_VAR name="marc_value">
<input type="hidden" name="tag" value="<TMPL_VAR name="tag">">
<input type="hidden" name="subfield" value="<TMPL_VAR name="subfield">">
<input type="hidden" name="mandatory" value="<TMPL_VAR name="mandatory">">
</td>
</tr>
</tmpl_loop>
</table>
<input type="hidden" name="itemnum" value="<TMPL_VAR name="itemnum">">
<TMPL_IF name="opisadd">
<input type="submit" value="Add item">
<input type="button" value="Add item" onClick='Check(this.form)' accesskey="w">
<TMPL_ELSE>
<input type="hidden" name="tag" value="<TMPL_VAR name="itemtagfield">">
<input type="hidden" name="subfield" value="<TMPL_VAR name="itemtagsubfield">">
<input type="hidden" name="field_value" value="<TMPL_VAR name="itemnum">">
<input type="submit" value="Modify item">
<input type="button" value="Modify item" onClick='Check(this.form)' accesskey="w">
</TMPL_IF>
</center>
</form>
<script LANGUAGE="JavaScript">
function active(numlayer)
{
for (i=0; i < 10 ; i++ ) {
ong = i+"XX";
link = "link"+i;
if (numlayer==i) {
document.getElementById(ong).style.visibility="visible";
document.getElementById(link).style.backgroundColor="#11AA11";
document.getElementById(link).style.backgroundImage="url(/images/background-mem.gif)";
} else {
document.getElementById(ong).style.visibility="hidden";
document.getElementById(link).style.backgroundColor="#FFFFFF";
document.getElementById(link).style.backgroundImage="";
}
}
}
function Check(f) {
var total_errors=0;
// alert(f.field_value.length);
for (i=0 ; i<f.field_value.length ; i++) {
// alert (f.field_value[i].value);
if (f.field_value[i].value.length==0 && f.mandatory[i].value==1) {
document.getElementById("error"+i).style.backgroundColor="#FF0000";
total_errors++;
} else {
document.getElementById("error"+i).style.backgroundColor="#FFFFFF";
}
}
var alertString2;
if (total_errors==0) {
document.f.submit();
} else {
alertString2 = "Form not submitted because of the following problem(s)\n";
alertString2 += "------------------------------------------------------------------------------------\n\n";
alertString2 += "- "+ total_errors+" mandatory fields empty (see bold subfields)";
alert(alertString2);
}
}
function Dopop(link,i) {
defaultvalue=document.forms[0].field_value[i].value;
newin=window.open(link+"&result="+defaultvalue,"value builder",'width=500,height=400,toolbar=false,scrollbars=yes');
}
</script>
</body>
</html>