3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
29 my $tablename = $input->param('tablename');
30 $tablename = "biblio" unless ($tablename);
31 my $kohafield = $input->param('kohafield');
32 my $op = $input->param('op');
33 my $script_name = 'koha2marclinks.pl';
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
37 template_name => "admin/koha2marclinks.tmpl",
41 flagsrequired => { parameters => 1 },
48 script_name => $script_name,
50 ); # we show only the TMPL_VAR names $op
54 script_name => $script_name,
56 ); # we show only the TMPL_VAR names $op
59 my $dbh = C4::Context->dbh;
61 ################## ADD_FORM ##################################
62 # called by default. Used to create form to add or modify a record
63 if ( $op eq 'add_form' ) {
67 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?"
69 $sth->execute( $tablename . "." . $kohafield );
70 my ( $defaulttagfield, $defaulttagsubfield, $defaultliblibrarian ) =
73 for ( my $i = 0 ; $i <= 9 ; $i++ ) {
76 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ?"
78 $sth2->execute("$i%");
81 while ( my ( $field, $tagsubfield, $liblibrarian ) =
82 $sth2->fetchrow_array )
84 push @marcarray, "$field $tagsubfield - $liblibrarian";
86 my $marclist = CGI::scrolling_list(
88 -values => \@marcarray,
90 "$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
95 $template->param( "marclist$i" => $marclist );
98 tablename => $tablename,
99 kohafield => $kohafield
102 # END $OP eq ADD_FORM
103 ################## ADD_VALIDATE ##################################
104 # called by add_form, used to insert/modify data in DB
106 elsif ( $op eq 'add_validate' ) {
108 #----- empty koha field :
110 "update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"
113 #---- reload if not empty
114 my @temp = split / /, $input->param('marc');
116 "update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
119 "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
122 # END $OP eq ADD_VALIDATE
123 ################## DEFAULT ##################################
128 "Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure"
132 while ( ( my $tagfield, my $tagsubfield, my $liblibrarian, my $kohafield ) =
135 $fields{$kohafield}->{tagfield} = $tagfield;
136 $fields{$kohafield}->{tagsubfield} = $tagsubfield;
137 $fields{$kohafield}->{liblibrarian} = $liblibrarian;
140 #XXX: This might not work. Maybe should use a DBI call instead of SHOW COLUMNS
141 my $sth2 = $dbh->prepare("SHOW COLUMNS from $tablename");
144 my $toggle = "white";
146 while ( ( my $field ) = $sth2->fetchrow_array ) {
147 if ( $toggle eq 'white' ) {
153 my %row_data; # get a fresh hash for the row data
154 $row_data{tagfield} = $fields{ $tablename . "." . $field }->{tagfield};
155 $row_data{tagsubfield} =
156 $fields{ $tablename . "." . $field }->{tagsubfield};
157 $row_data{liblibrarian} =
158 $fields{ $tablename . "." . $field }->{liblibrarian};
159 $row_data{kohafield} = $field;
161 "$script_name?op=add_form&tablename=$tablename&kohafield=$field";
162 $row_data{bgcolor} = $toggle;
163 push( @loop_data, \%row_data );
167 tablename => CGI::scrolling_list(
168 -name => 'tablename',
174 -default => $tablename,
180 } #---- END $OP eq DEFAULT
181 output_html_with_http_headers $input, $cookie, $template->output;