bug-2149, added new block to C4::Letters::SendAlerts() to email 'account creation...
[koha.git] / admin / koha2marclinks.pl
blobaa2e3682ffe01ab837b28f4d7229e707520f9b71
1 #!/usr/bin/perl
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
10 # version.
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
20 use strict;
21 use C4::Output;
22 use C4::Auth;
23 use CGI;
24 use C4::Context;
25 use C4::Biblio;
28 my $input = new CGI;
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",
38 query => $input,
39 type => "intranet",
40 authnotrequired => 0,
41 flagsrequired => { parameters => 1 },
42 debug => 1,
46 if ($op) {
47 $template->param(
48 script_name => $script_name,
49 $op => 1
50 ); # we show only the TMPL_VAR names $op
52 else {
53 $template->param(
54 script_name => $script_name,
55 else => 1
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' ) {
64 my $data;
65 my $sth =
66 $dbh->prepare(
67 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?"
69 $sth->execute( $tablename . "." . $kohafield );
70 my ( $defaulttagfield, $defaulttagsubfield, $defaultliblibrarian ) =
71 $sth->fetchrow;
73 for ( my $i = 0 ; $i <= 9 ; $i++ ) {
74 my $sth2 =
75 $dbh->prepare(
76 "select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ?"
78 $sth2->execute("$i%");
79 my @marcarray;
80 push @marcarray, " ";
81 while ( my ( $field, $tagsubfield, $liblibrarian ) =
82 $sth2->fetchrow_array )
84 push @marcarray, "$field $tagsubfield - $liblibrarian";
86 my $marclist = CGI::scrolling_list(
87 -name => "marc",
88 -values => \@marcarray,
89 -default =>
90 "$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
91 -size => 1,
92 -tabindex => '',
93 -multiple => 0,
95 $template->param( "marclist$i" => $marclist );
97 $template->param(
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 :
109 $dbh->do(
110 "update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"
113 #---- reload if not empty
114 my @temp = split / /, $input->param('marc');
115 $dbh->do(
116 "update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
118 print
119 "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
120 exit;
122 # END $OP eq ADD_VALIDATE
123 ################## DEFAULT ##################################
125 else { # DEFAULT
126 my $sth =
127 $dbh->prepare(
128 "Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure"
130 $sth->execute;
131 my %fields;
132 while ( ( my $tagfield, my $tagsubfield, my $liblibrarian, my $kohafield ) =
133 $sth->fetchrow )
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");
142 $sth2->execute;
144 my $toggle = 1;
145 my @loop_data = ();
146 while ( ( my $field ) = $sth2->fetchrow_array ) {
147 if ( $toggle eq 1 ) {
148 $toggle = 0;
150 else {
151 $toggle = 1;
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;
160 $row_data{edit} =
161 "$script_name?op=add_form&amp;tablename=$tablename&amp;kohafield=$field";
162 $row_data{toggle} = $toggle;
163 push( @loop_data, \%row_data );
165 $template->param(
166 loop => \@loop_data,
167 tablename => CGI::scrolling_list(
168 -name => 'tablename',
169 -values => [
170 'biblio',
171 'biblioitems',
172 'items',
174 -default => $tablename,
175 -size => 1,
176 -tabindex => '',
177 -multiple => 0
180 } #---- END $OP eq DEFAULT
181 output_html_with_http_headers $input, $cookie, $template->output;