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 with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
30 my $tablename=$input->param('tablename');
31 $tablename="biblio." unless ($tablename);
32 my $kohafield = $input->param('kohafield');
33 my $op=$input->param('op');
34 my $script_name = 'koha2marclinks.pl';
36 my $template = gettemplate("parameters/koha2marclinks.tmpl",0);
39 $template->param(script_name => $script_name,
40 $op => 1); # we show only the TMPL_VAR names $op
42 $template->param(script_name => $script_name,
43 else => 1); # we show only the TMPL_VAR names $op
46 my $dbh = C4::Context->dbh;
48 ################## ADD_FORM ##################################
49 # called by default. Used to create form to add or modify a record
50 if ($op eq 'add_form') {
52 my $sth = $dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?");
53 $sth->execute($tablename.".".$kohafield);
54 my ($defaulttagfield, $defaulttagsubfield,$defaultliblibrarian) = $sth->fetchrow;
56 for (my $i=0;$i<=9;$i++) {
57 my $sth2=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like '$i%'");
61 while (my ($field, $tagsubfield, $liblibrarian) = $sth2->fetchrow_array) {
62 # warn "$field$tagsubfield - $liblibrarian";
63 push @marcarray, "$field $tagsubfield - $liblibrarian";
65 my $marclist = CGI::scrolling_list(-name=>"marc",
66 -values=> \@marcarray,
67 -default=>"$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
71 $template->param("marclist$i" => $marclist);
73 $template->param( tablename => $tablename,
74 kohafield => $kohafield);
77 ################## ADD_VALIDATE ##################################
78 # called by add_form, used to insert/modify data in DB
79 } elsif ($op eq 'add_validate') {
80 #----- empty koha field :
81 $dbh->do("update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'");
82 #---- reload if not empty
83 my @temp = split / /,$input->param('marc');
84 $dbh->do("update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'");
85 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
88 # END $OP eq ADD_VALIDATE
89 ################## DEFAULT ##################################
92 my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure");
95 while ((my $tagfield,my $tagsubfield,my $liblibrarian,my $kohafield) = $sth->fetchrow) {
96 $fields{$kohafield}->{tagfield} = $tagfield;
97 $fields{$kohafield}->{tagsubfield} = $tagsubfield;
98 $fields{$kohafield}->{liblibrarian} = $liblibrarian;
100 my $sth2=$dbh->prepare("SHOW COLUMNS from $tablename");
105 while ((my $field) = $sth2->fetchrow_array) {
106 if ($toggle eq 'white'){
111 my %row_data; # get a fresh hash for the row data
112 $row_data{tagfield} = $fields{$tablename.".".$field}->{tagfield};
113 $row_data{tagsubfield} = $fields{$tablename.".".$field}->{tagsubfield};
114 $row_data{liblibrarian} = $fields{$tablename.".".$field}->{liblibrarian};
115 $row_data{kohafield} = $field;
116 $row_data{edit} = "$script_name?op=add_form&tablename=$tablename&kohafield=$field";
117 $row_data{bgcolor} = $toggle;
118 push(@loop_data,\%row_data);
120 $template->param(loop => \@loop_data,
121 tablename => CGI::scrolling_list(-name=>'tablename',
122 -values=>['biblio','biblioitems','items'],
123 -default=>$tablename,
128 } #---- END $OP eq DEFAULT
130 print "Content-Type: text/html\n\n", $template->output;