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
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
22 csv-profile.pl : Defines a CSV export profile
29 This script allow the user to define a new profile for CSV export
48 my $dbh = C4
::Context
->dbh;
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
53 template_name
=> "tools/csv-profiles.tmpl",
57 flagsrequired
=> { tools
=> 'manage_csv_profiles' },
63 my $profile_name = $input->param("profile_name");
64 my $profile_description = $input->param("profile_description");
65 my $profile_content = $input->param("profile_content");
66 my $action = $input->param("action");
67 my $delete = $input->param("delete");
68 my $id = $input->param("id");
69 if ($delete) { $action = "delete"; }
71 if ($profile_name && $profile_content && $action) {
74 if ($action eq "create") {
75 my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields) VALUES (NULL, ?, ?, ?)";
76 my $sth = $dbh->prepare($query);
77 $rows = $sth->execute($profile_name, $profile_description, $profile_content);
81 if ($action eq "edit") {
82 my $query = "UPDATE export_format SET description=?, marcfields=? WHERE export_format_id=? LIMIT 1";
83 my $sth = $dbh->prepare($query);
84 $rows = $sth->execute($profile_description, $profile_content, $profile_name);
88 if ($action eq "delete") {
89 my $query = "DELETE FROM export_format WHERE export_format_id=? LIMIT 1";
90 my $sth = $dbh->prepare($query);
91 $rows = $sth->execute($profile_name);
95 $rows ?
$template->param(success
=> 1) : $template->param(error
=> 1);
96 $template->param(profile_name
=> $profile_name);
97 $template->param(action
=> $action);
101 # If a profile has been selected for modification
103 my $query = "SELECT export_format_id, profile, description, marcfields FROM export_format WHERE export_format_id = ?";
105 $sth = $dbh->prepare($query);
108 my $selected_profile = $sth->fetchrow_arrayref();
110 selected_profile_id
=> $selected_profile->[0],
111 selected_profile_name
=> $selected_profile->[1],
112 selected_profile_description
=> $selected_profile->[2],
113 selected_profile_marcfields
=> $selected_profile->[3]
118 # List of existing profiles
119 $template->param(existing_profiles
=> GetCsvProfilesLoop
());
121 output_html_with_http_headers
$input, $cookie, $template->output;