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",
94 $template->param( "marclist$i" => $marclist );
97 tablename
=> $tablename,
98 kohafield
=> $kohafield
101 # END $OP eq ADD_FORM
102 ################## ADD_VALIDATE ##################################
103 # called by add_form, used to insert/modify data in DB
105 elsif ( $op eq 'add_validate' ) {
107 #----- empty koha field :
109 "update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"
112 #---- reload if not empty
113 my @temp = split / /, $input->param('marc');
115 "update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
118 "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
121 # END $OP eq ADD_VALIDATE
122 ################## DEFAULT ##################################
127 "Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure"
131 while ( ( my $tagfield, my $tagsubfield, my $liblibrarian, my $kohafield ) =
134 $fields{$kohafield}->{tagfield
} = $tagfield;
135 $fields{$kohafield}->{tagsubfield
} = $tagsubfield;
136 $fields{$kohafield}->{liblibrarian
} = $liblibrarian;
139 #XXX: This might not work. Maybe should use a DBI call instead of SHOW COLUMNS
140 my $sth2 = $dbh->prepare("SHOW COLUMNS from $tablename");
144 while ( ( my $field ) = $sth2->fetchrow_array ) {
145 my %row_data; # get a fresh hash for the row data
146 $row_data{tagfield
} = $fields{ $tablename . "." . $field }->{tagfield
};
147 $row_data{tagsubfield
} =
148 $fields{ $tablename . "." . $field }->{tagsubfield
};
149 $row_data{liblibrarian
} =
150 $fields{ $tablename . "." . $field }->{liblibrarian
};
151 $row_data{kohafield
} = $field;
153 "$script_name?op=add_form&tablename=$tablename&kohafield=$field";
154 push( @loop_data, \
%row_data );
158 tablename
=> CGI
::scrolling_list
(
159 -name
=> 'tablename',
165 -default => $tablename,
170 } #---- END $OP eq DEFAULT
171 output_html_with_http_headers
$input, $cookie, $template->output;