Bug 3921 - Add Intranet MARC21 XSL file based on OPAC one
[koha.git] / tools / csv-profiles.pl
blob1d54da9e7ac5bbf7debaef687404b51653cb6e3b
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;
40 use C4::Auth;
41 use C4::Context;
42 use C4::Output;
43 use CGI;
44 use C4::Koha;
45 use C4::Csv;
47 my $input = new CGI;
48 my $dbh = C4::Context->dbh;
50 # open template
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
53 template_name => "tools/csv-profiles.tmpl",
54 query => $input,
55 type => "intranet",
56 authnotrequired => 0,
57 flagsrequired => { tools => 'manage_csv_profiles' },
58 debug => 1,
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) {
72 my $rows;
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
102 if ($id) {
103 my $query = "SELECT export_format_id, profile, description, marcfields FROM export_format WHERE export_format_id = ?";
104 my $sth;
105 $sth = $dbh->prepare($query);
107 $sth->execute($id);
108 my $selected_profile = $sth->fetchrow_arrayref();
109 $template->param(
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;