New framework handling. New koha_attr table for mapping MARC to koha
[srvgit] / admin / checkmarc.pl
index 30cd2c5..8d71a1f 100755 (executable)
@@ -26,12 +26,11 @@ 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",
+    = get_template_and_user({template_name => "admin/checkmarc.tmpl",
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
@@ -41,93 +40,81 @@ my ($template, $borrowernumber, $cookie)
 
 my $dbh = C4::Context->dbh;
 my $total;
-# checks itemnum field
-my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\"");
+# checks itemnumber field
+my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"itemnumber\"");
 $sth->execute;
 my ($res) = $sth->fetchrow;
-if ($res==-1) {
-       $template->param(itemnum => 0);
-} else {
-       $template->param(itemnum => 1);
+unless ($res) {
+       $template->param(itemnumber => 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\"");
+#check biblionumber
+my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"biblionumber\"");
 $sth->execute;
-my ($res2,$tab2) = $sth->fetchrow;
-if ($res && $res2 && ($res eq $res2) && $tab==-1 && $tab2==-1) {
-       $template->param(biblionumber => 0);
-} else {
+my ($res) = $sth->fetchrow;
+if ($res ){
+       ($res) = $sth->fetchrow;
+       unless ($res){
        $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 ) && $res2 ne -1) {
-               $subtotal++;
        }
 }
-$sth = $dbh->prepare("select kohafield from marc_subfield_structure where tagfield=$tagfield");
+#check barcode
+my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"barcode\"");
 $sth->execute;
-while (($res2) = $sth->fetchrow) {
-       if (!$res2 || $res2 =~ /^items/) {
-       } else {
-               $subtotal++;
-       }
+my ($res) = $sth->fetchrow;
+unless ($res){
+       $template->param(barcode=> 1);
+       $total++;
 }
-if ($subtotal eq 0) {
-       $template->param(itemfields => 0);
-} else {
-       $template->param(itemfields => 1);
+#check isbn
+my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"isbn\"");
+$sth->execute;
+my ($res) = $sth->fetchrow;
+unless ($res){
+       $template->param(isbn => 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\"");
+## Check for itemtype
+my $sth = $dbh->prepare("select tagfield,tagsubfield from koha_attr where marctokoha=\"itemtype\"");
 $sth->execute;
-($res,$res2,$field) = $sth->fetchrow;
-if ($res && $res2>=0 && $field eq "itemtypes") {
-       $template->param(itemtype => 0);
-} else {
+my ($res,$res2) = $sth->fetchrow;
+if ($res) {
+$sth = $dbh->prepare("select authorised_value from biblios_subfield_structure where tagfield=? and tagsubfield=?");
+$sth->execute($res,$res2);
+ my ($item)=$sth->fetchrow;
+    unless ($item eq "itemtypes"){
        $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\"");
+## Check for homebranch
+my $sth = $dbh->prepare("select tagfield from koha_attr where marctokoha=\"homebranch\"");
 $sth->execute;
-($res,$res2,$field) = $sth->fetchrow;
-if ($res && $res2 eq 10 && $field eq "branches") {
-       $template->param(branch => 0);
-} else {
+my ($res) = $sth->fetchrow;
+unless  ($res) {
        $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\"");
+
+## Check for holdingbranch
+my $sth = $dbh->prepare("select tagfield,tagsubfield from koha_attr where marctokoha=\"holdingbranch\"");
 $sth->execute;
-($res,$res2,$field) = $sth->fetchrow;
-if ($res && $res2 eq 10 && $field eq "branches") {
-       $template->param(holdingbranch => 0);
-} else {
+my ($res,$res2) = $sth->fetchrow;
+if ($res) {
+$sth = $dbh->prepare("select authorised_value from biblios_subfield_structure where tagfield=? and tagsubfield=?");
+$sth->execute($res,$res2);
+ my ($item)=$sth->fetchrow;
+    unless ($item eq "branches"){
        $template->param(holdingbranch => 1);
        $total++;
+    }
 }
 
+
+
 # checks that itemtypes & branches tables are not empty
 $sth = $dbh->prepare("select count(*) from itemtypes");
 $sth->execute;