X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fkoha2marclinks.pl;h=e65e1e51ab970297569ec16b71ae190e04ae0b33;hb=c9ef8100a92eccbf136f7f8a218b11a85452ff3a;hp=070e44ba6bc61e3cd59c7a5a4fbe1b52d9279ba5;hpb=61368cb3909740220781a342d67cd4d20032131a;p=koha.git diff --git a/admin/koha2marclinks.pl b/admin/koha2marclinks.pl index 070e44ba6b..e65e1e51ab 100755 --- a/admin/koha2marclinks.pl +++ b/admin/koha2marclinks.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl - # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. @@ -20,122 +19,153 @@ 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 $tablename=$input->param('tablename'); -$tablename="biblio" unless ($tablename); -my $kohafield = $input->param('kohafield'); -my $op=$input->param('op'); + +my $input = new CGI; +my $tablename = $input->param('tablename'); +$tablename = "biblio" unless ($tablename); +my $kohafield = $input->param('kohafield'); +my $op = $input->param('op'); my $script_name = 'koha2marclinks.pl'; -my ($template, $borrowernumber, $cookie) - = get_template_and_user({template_name => "parameters/koha2marclinks.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {parameters => 1}, - debug => 1, - }); +my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( + { + template_name => "admin/koha2marclinks.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 1 }, + debug => 1, + } +); if ($op) { -$template->param(script_name => $script_name, - $op => 1); # we show only the TMPL_VAR names $op -} else { -$template->param(script_name => $script_name, - else => 1); # we show only the TMPL_VAR names $op + $template->param( + script_name => $script_name, + $op => 1 + ); # we show only the TMPL_VAR names $op +} +else { + $template->param( + script_name => $script_name, + else => 1 + ); # we show only the TMPL_VAR names $op } my $dbh = C4::Context->dbh; ################## ADD_FORM ################################## # called by default. Used to create form to add or modify a record -if ($op eq 'add_form') { - my $data; - my $sth = $dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?"); - $sth->execute($tablename.".".$kohafield); - my ($defaulttagfield, $defaulttagsubfield,$defaultliblibrarian) = $sth->fetchrow; +if ( $op eq 'add_form' ) { + my $data; + my $sth = + $dbh->prepare( +"select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?" + ); + $sth->execute( $tablename . "." . $kohafield ); + my ( $defaulttagfield, $defaulttagsubfield, $defaultliblibrarian ) = + $sth->fetchrow; - for (my $i=0;$i<=9;$i++) { - my $sth2=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like '$i%'"); - $sth2->execute; - my @marcarray; - push @marcarray," "; - while (my ($field, $tagsubfield, $liblibrarian) = $sth2->fetchrow_array) { - push @marcarray, "$field $tagsubfield - $liblibrarian"; - } - my $marclist = CGI::scrolling_list(-name=>"marc", - -values=> \@marcarray, - -default=>"$defaulttagfield $defaulttagsubfield - $defaultliblibrarian", - -size=>1, - -multiple=>0, - ); - $template->param("marclist$i" => $marclist); - } - $template->param( tablename => $tablename, - kohafield => $kohafield); + for ( my $i = 0 ; $i <= 9 ; $i++ ) { + my $sth2 = + $dbh->prepare( +"select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ?" + ); + $sth2->execute("$i%"); + my @marcarray; + push @marcarray, " "; + while ( my ( $field, $tagsubfield, $liblibrarian ) = + $sth2->fetchrow_array ) + { + push @marcarray, "$field $tagsubfield - $liblibrarian"; + } + my $marclist = CGI::scrolling_list( + -name => "marc", + -values => \@marcarray, + -default => + "$defaulttagfield $defaulttagsubfield - $defaultliblibrarian", + -size => 1, + -multiple => 0, + ); + $template->param( "marclist$i" => $marclist ); + } + $template->param( + tablename => $tablename, + kohafield => $kohafield + ); - # END $OP eq ADD_FORM + # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## -# called by add_form, used to insert/modify data in DB -} elsif ($op eq 'add_validate') { - #----- empty koha field : - $dbh->do("update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"); - #---- reload if not empty - my @temp = split / /,$input->param('marc'); - $dbh->do("update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"); - print "Content-Type: text/html\n\n"; - exit; + # called by add_form, used to insert/modify data in DB +} +elsif ( $op eq 'add_validate' ) { - # END $OP eq ADD_VALIDATE + #----- empty koha field : + $dbh->do( +"update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'" + ); + + #---- reload if not empty + my @temp = split / /, $input->param('marc'); + $dbh->do( +"update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'" + ); + print +"Content-Type: text/html\n\n"; + exit; + + # END $OP eq ADD_VALIDATE ################## DEFAULT ################################## -} else { # DEFAULT - my $env; - my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure"); - $sth->execute; - my %fields; - while ((my $tagfield,my $tagsubfield,my $liblibrarian,my $kohafield) = $sth->fetchrow) { - $fields{$kohafield}->{tagfield} = $tagfield; - $fields{$kohafield}->{tagsubfield} = $tagsubfield; - $fields{$kohafield}->{liblibrarian} = $liblibrarian; - } - my $sth2=$dbh->prepare("SHOW COLUMNS from $tablename"); - $sth2->execute; +} +else { # DEFAULT + my $sth = + $dbh->prepare( +"Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure" + ); + $sth->execute; + my %fields; + while ( ( my $tagfield, my $tagsubfield, my $liblibrarian, my $kohafield ) = + $sth->fetchrow ) + { + $fields{$kohafield}->{tagfield} = $tagfield; + $fields{$kohafield}->{tagsubfield} = $tagsubfield; + $fields{$kohafield}->{liblibrarian} = $liblibrarian; + } - my $toggle="white"; - my @loop_data = (); - while ((my $field) = $sth2->fetchrow_array) { - if ($toggle eq 'white'){ - $toggle="#ffffcc"; - } else { - $toggle="white"; - } - my %row_data; # get a fresh hash for the row data - $row_data{tagfield} = $fields{$tablename.".".$field}->{tagfield}; - $row_data{tagsubfield} = $fields{$tablename.".".$field}->{tagsubfield}; - $row_data{liblibrarian} = $fields{$tablename.".".$field}->{liblibrarian}; - $row_data{kohafield} = $field; - $row_data{edit} = "$script_name?op=add_form&tablename=$tablename&kohafield=$field"; - $row_data{bgcolor} = $toggle; - push(@loop_data,\%row_data); - } - $template->param(loop => \@loop_data, - tablename => CGI::scrolling_list(-name=>'tablename', - -values=>['biblio','biblioitems','items'], - -default=>$tablename, - -size=>1, - -multiple=>0 - ) - ); -} #---- END $OP eq DEFAULT + #XXX: This might not work. Maybe should use a DBI call instead of SHOW COLUMNS + my $sth2 = $dbh->prepare("SHOW COLUMNS from $tablename"); + $sth2->execute; -print $input->header( - -type => guesstype($template->output), - -cookie => $cookie -), $template->output; + my @loop_data = (); + while ( ( my $field ) = $sth2->fetchrow_array ) { + my %row_data; # get a fresh hash for the row data + $row_data{tagfield} = $fields{ $tablename . "." . $field }->{tagfield}; + $row_data{tagsubfield} = + $fields{ $tablename . "." . $field }->{tagsubfield}; + $row_data{liblibrarian} = + $fields{ $tablename . "." . $field }->{liblibrarian}; + $row_data{kohafield} = $field; + $row_data{edit} = +"$script_name?op=add_form&tablename=$tablename&kohafield=$field"; + push( @loop_data, \%row_data ); + } + $template->param( + loop => \@loop_data, + tablename => CGI::scrolling_list( + -name => 'tablename', + -values => [ + 'biblio', + 'biblioitems', + 'items', + ], + -default => $tablename, + -size => 1, + -multiple => 0 + ) + ); +} #---- END $OP eq DEFAULT +output_html_with_http_headers $input, $cookie, $template->output;