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
23 use C4::Interface::CGI::Output;
32 my $tablename=$input->param('tablename');
33 $tablename="biblio" unless ($tablename);
34 my $kohafield = $input->param('kohafield');
35 my $op=$input->param('op');
36 my $script_name = 'koha2marclinks.pl';
38 my ($template, $borrowernumber, $cookie)
39 = get_template_and_user({template_name => "admin/koha2marclinks.tmpl",
43 flagsrequired => {parameters => 1},
48 $template->param(script_name => $script_name,
49 $op => 1); # we show only the TMPL_VAR names $op
51 $template->param(script_name => $script_name,
52 else => 1); # we show only the TMPL_VAR names $op
55 my $dbh = C4::Context->dbh;
57 ################## ADD_FORM ##################################
58 # called by default. Used to create form to add or modify a record
59 if ($op eq 'add_form') {
61 my $sth = $dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?");
62 $sth->execute($tablename.".".$kohafield);
63 my ($defaulttagfield, $defaulttagsubfield,$defaultliblibrarian) = $sth->fetchrow;
65 for (my $i=0;$i<=9;$i++) {
66 my $sth2=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ?");
67 $sth2->execute("$i%");
70 while (my ($field, $tagsubfield, $liblibrarian) = $sth2->fetchrow_array) {
71 push @marcarray, "$field $tagsubfield - $liblibrarian";
73 my $marclist = CGI::scrolling_list(-name=>"marc",
74 -values=> \@marcarray,
75 -default=>"$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
79 $template->param("marclist$i" => $marclist);
81 $template->param( tablename => $tablename,
82 kohafield => $kohafield);
85 ################## ADD_VALIDATE ##################################
86 # called by add_form, used to insert/modify data in DB
87 } elsif ($op eq 'add_validate') {
88 #----- empty koha field :
89 $dbh->do("update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'");
90 #---- reload if not empty
91 my @temp = split / /,$input->param('marc');
92 $dbh->do("update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'");
93 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
96 # END $OP eq ADD_VALIDATE
97 ################## DEFAULT ##################################
100 my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure");
103 while ((my $tagfield,my $tagsubfield,my $liblibrarian,my $kohafield) = $sth->fetchrow) {
104 $fields{$kohafield}->{tagfield} = $tagfield;
105 $fields{$kohafield}->{tagsubfield} = $tagsubfield;
106 $fields{$kohafield}->{liblibrarian} = $liblibrarian;
108 #XXX: This might not work. Maybe should use a DBI call instead of SHOW COLUMNS
109 my $sth2=$dbh->prepare("SHOW COLUMNS from $tablename");
114 while ((my $field) = $sth2->fetchrow_array) {
115 if ($toggle eq 'white'){
120 my %row_data; # get a fresh hash for the row data
121 $row_data{tagfield} = $fields{$tablename.".".$field}->{tagfield};
122 $row_data{tagsubfield} = $fields{$tablename.".".$field}->{tagsubfield};
123 $row_data{liblibrarian} = $fields{$tablename.".".$field}->{liblibrarian};
124 $row_data{kohafield} = $field;
125 $row_data{edit} = "$script_name?op=add_form&tablename=$tablename&kohafield=$field";
126 $row_data{bgcolor} = $toggle;
127 push(@loop_data,\%row_data);
129 $template->param(loop => \@loop_data,
130 tablename => CGI::scrolling_list(-name=>'tablename',
131 -values=>['biblio','biblioitems','items','bibliosubject','bibliosubtitle','additionalauthors'],
132 -default=>$tablename,
137 } #---- END $OP eq DEFAULT
139 output_html_with_http_headers $input, $cookie, $template->output;