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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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, $borrowernumber, $cookie ) = get_template_and_user
(
38 template_name
=> "admin/koha2marclinks.tmpl",
42 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
49 script_name
=> $script_name,
51 ); # we show only the TMPL_VAR names $op
55 script_name
=> $script_name,
57 ); # we show only the TMPL_VAR names $op
61 my $dbh = C4
::Context
->dbh;
63 ################## ADD_FORM ##################################
64 # called by default. Used to create form to add or modify a record
65 if ( $op eq 'add_form' ) {
69 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=? AND frameworkcode=''"
71 $sth->execute( $tablename . "." . $kohafield );
72 my ( $defaulttagfield, $defaulttagsubfield, $defaultliblibrarian ) =
75 for ( my $i = 0 ; $i <= 9 ; $i++ ) {
78 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ? AND frameworkcode=''"
80 $sth2->execute("$i%");
83 while ( my ( $field, $tagsubfield, $liblibrarian ) =
84 $sth2->fetchrow_array )
86 push @marcarray, "$field $tagsubfield - $liblibrarian";
88 my $marclist = CGI
::scrolling_list
(
90 -values => \
@marcarray,
92 "$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
96 $template->param( "marclist$i" => $marclist );
99 tablename
=> $tablename,
100 kohafield
=> $kohafield
103 # END $OP eq ADD_FORM
104 ################## ADD_VALIDATE ##################################
105 # called by add_form, used to insert/modify data in DB
107 elsif ( $op eq 'add_validate' ) {
109 #----- empty koha field :
111 "update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"
114 #---- reload if not empty
115 my @temp = split / /, $input->param('marc');
117 "update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
120 "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
123 # END $OP eq ADD_VALIDATE
124 ################## DEFAULT ##################################
129 q
|select tagfield
,tagsubfield
,liblibrarian
,kohafield from marc_subfield_structure where kohafield is
not NULL
and kohafield
!= ''|
133 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");
145 while ( ( my $field ) = $sth2->fetchrow_array ) {
146 my %row_data; # get a fresh hash for the row data
147 $row_data{tagfield
} = $fields{ $tablename . "." . $field }->{tagfield
};
148 $row_data{tagsubfield
} =
149 $fields{ $tablename . "." . $field }->{tagsubfield
};
150 $row_data{liblibrarian
} =
151 $fields{ $tablename . "." . $field }->{liblibrarian
};
152 $row_data{kohafield
} = $field;
154 "$script_name?op=add_form&tablename=$tablename&kohafield=$field";
155 push( @loop_data, \
%row_data );
159 tablename
=> CGI
::scrolling_list
(
160 -name
=> 'tablename',
166 -default => $tablename,
171 } #---- END $OP eq DEFAULT
172 output_html_with_http_headers
$input, $cookie, $template->output;