Bug 3723 Correct return of Institution in Patron Info Resp
[koha.git] / tools / csv-profiles.pl
blob15b90de586e18452a91c8ec0ec0cbe0ad8071135
1 #!/usr/bin/perl
3 # Copyright 2009 BibLibre
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 =head1 NAME
22 csv-profile.pl : Defines a CSV export profile
24 =head1 SYNOPSIS
27 =head1 DESCRIPTION
29 This script allow the user to define a new profile for CSV export
31 =head1 FUNCTIONS
33 =over 2
35 =cut
37 use strict;
38 use Data::Dumper;
39 use Encode;
41 use C4::Auth;
42 use C4::Context;
43 use C4::Output;
44 use CGI;
45 use C4::Koha;
46 use C4::Csv;
48 my $input = new CGI;
49 my $dbh = C4::Context->dbh;
51 # open template
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54 template_name => "tools/csv-profiles.tmpl",
55 query => $input,
56 type => "intranet",
57 authnotrequired => 0,
58 flagsrequired => { tools => 'manage_csv_profiles' },
59 debug => 1,
63 # Getting available encodings list
64 my @encodings = Encode->encodings();
65 my @encodings_loop = map{{encoding => $_}} @encodings;
66 $template->param(encodings => \@encodings_loop);
68 my $profile_name = $input->param("profile_name");
69 my $profile_description = $input->param("profile_description");
70 my $profile_content = $input->param("profile_content");
71 my $csv_separator = $input->param("csv_separator");
72 my $field_separator = $input->param("field_separator");
73 my $subfield_separator = $input->param("subfield_separator");
74 my $encoding = $input->param("encoding");
75 my $action = $input->param("action");
76 my $delete = $input->param("delete");
77 my $id = $input->param("id");
78 if ($delete) { $action = "delete"; }
80 if ($profile_name && $profile_content && $action) {
81 my $rows;
83 if ($action eq "create") {
84 my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator, encoding) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)";
85 my $sth = $dbh->prepare($query);
86 $rows = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding);
90 if ($action eq "edit") {
91 my $query = "UPDATE export_format SET description=?, marcfields=?, csv_separator=?, field_separator=?, subfield_separator=?, encoding=? WHERE export_format_id=? LIMIT 1";
92 my $sth = $dbh->prepare($query);
93 $rows = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $profile_name);
96 if ($action eq "delete") {
97 my $query = "DELETE FROM export_format WHERE export_format_id=? LIMIT 1";
98 my $sth = $dbh->prepare($query);
99 $rows = $sth->execute($profile_name);
103 $rows ? $template->param(success => 1) : $template->param(error => 1);
104 $template->param(profile_name => $profile_name);
105 $template->param(action => $action);
109 # If a profile has been selected for modification
110 if ($id) {
111 my $query = "SELECT export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator, encoding FROM export_format WHERE export_format_id = ?";
112 my $sth;
113 $sth = $dbh->prepare($query);
115 $sth->execute($id);
116 my $selected_profile = $sth->fetchrow_arrayref();
117 $template->param(
118 selected_profile_id => $selected_profile->[0],
119 selected_profile_name => $selected_profile->[1],
120 selected_profile_description => $selected_profile->[2],
121 selected_profile_marcfields => $selected_profile->[3],
122 selected_csv_separator => $selected_profile->[4],
123 selected_field_separator => $selected_profile->[5],
124 selected_subfield_separator => $selected_profile->[6],
125 selected_encoding => $selected_profile->[7]
130 # List of existing profiles
131 $template->param(existing_profiles => GetCsvProfilesLoop());
133 output_html_with_http_headers $input, $cookie, $template->output;