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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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.tt",
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;
62 my $cache = Koha
::Cache
->get_instance();
64 ################## ADD_FORM ##################################
65 # called by default. Used to create form to add or modify a record
66 if ( $op eq 'add_form' ) {
70 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=? AND frameworkcode=''"
72 $sth->execute( $tablename . "." . $kohafield );
73 my ( $defaulttagfield, $defaulttagsubfield, $defaultliblibrarian ) =
76 for ( my $i = 0 ; $i <= 9 ; $i++ ) {
79 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ? AND frameworkcode=''"
81 $sth2->execute("$i%");
84 while ( my ( $field, $tagsubfield, $liblibrarian ) =
85 $sth2->fetchrow_array )
87 push @marcarray, "$field $tagsubfield - $liblibrarian";
90 values => \
@marcarray,
91 default => "$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
93 $template->param( "marclist$i" => $marclist );
96 tablename
=> $tablename,
97 kohafield
=> $kohafield
100 # END $OP eq ADD_FORM
101 ################## ADD_VALIDATE ##################################
102 # called by add_form, used to insert/modify data in DB
104 elsif ( $op eq 'add_validate' ) {
106 #----- empty koha field :
108 "update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"
111 #---- reload if not empty
112 my @temp = split / /, $input->param('marc');
114 "update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
116 # We could get a list of all frameworks and do them one-by-one, or zap
119 print $input->redirect("/cgi-bin/koha/admin/koha2marclinks.pl?tablename=$tablename");
122 # END $OP eq ADD_VALIDATE
123 ################## DEFAULT ##################################
128 q
|select tagfield
,tagsubfield
,liblibrarian
,kohafield from marc_subfield_structure where kohafield is
not NULL
and kohafield
!= ''|
132 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 );
157 values => [ 'biblio', 'biblioitems', 'items' ],
158 default => $tablename,
162 tablename
=> $tablenames,
164 } #---- END $OP eq DEFAULT
165 output_html_with_http_headers
$input, $cookie, $template->output;