3 # Copyright 2009 BibLibre
4 # Copyright 2015 Koha Development Team
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 csv-profile.pl : Defines a CSV export profile
31 This script allow the user to define a new profile for CSV export
45 use Koha
::CsvProfiles
;
48 my $export_format_id = $input->param('export_format_id');
49 my $op = $input->param('op') || 'list';
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
53 { template_name
=> "tools/csv-profiles.tt",
57 flagsrequired
=> { tools
=> 'manage_csv_profiles' },
62 # Getting available encodings list
63 $template->param( encodings
=> [ Encode
->encodings ] );
65 if ( $op eq 'add_form' ) {
67 if ($export_format_id) {
68 $csv_profile = Koha
::CsvProfiles
->find($export_format_id);
70 $template->param( csv_profile
=> $csv_profile, );
71 } elsif ( $op eq 'add_validate' ) {
72 my $profile = $input->param("profile");
73 my $description = $input->param("description");
74 my $type = $input->param("type");
77 ?
$input->param("marc_content")
78 : $input->param("sql_content");
79 my $csv_separator = $input->param("csv_separator");
80 my $field_separator = $input->param("field_separator");
81 my $subfield_separator = $input->param("subfield_separator");
82 my $encoding = $input->param("encoding");
84 if ($export_format_id) {
85 my $csv_profile = Koha
::CsvProfiles
->find($export_format_id)
86 or die "Something went wrong! This export_format_id does not match any existing CSV profile.";
87 $csv_profile->profile($profile);
88 $csv_profile->description($description);
89 $csv_profile->content($content);
90 $csv_profile->csv_separator($csv_separator);
91 $csv_profile->field_separator($field_separator);
92 $csv_profile->subfield_separator($subfield_separator);
93 $csv_profile->encoding($encoding);
94 $csv_profile->type($type);
95 eval { $csv_profile->store; };
98 push @messages, { type
=> 'error', code
=> 'error_on_update' };
100 push @messages, { type
=> 'message', code
=> 'success_on_update' };
103 my $csv_profile = Koha
::CsvProfile
->new(
104 { profile
=> $profile,
105 description
=> $description,
107 csv_separator
=> $csv_separator,
108 field_separator
=> $field_separator,
109 subfield_separator
=> $subfield_separator,
110 encoding
=> $encoding,
114 eval { $csv_profile->store; };
116 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
118 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
122 } elsif ( $op eq 'delete_confirm' ) {
123 my $csv_profile = Koha
::CsvProfiles
->find($export_format_id);
124 $template->param( csv_profile
=> $csv_profile, );
125 } elsif ( $op eq 'delete_confirmed' ) {
126 my $csv_profile = Koha
::CsvProfiles
->find($export_format_id);
127 my $deleted = eval { $csv_profile->delete; };
129 if ( $@
or not $deleted ) {
130 push @messages, { type
=> 'error', code
=> 'error_on_delete' };
132 push @messages, { type
=> 'message', code
=> 'success_on_delete' };
137 if ( $op eq 'list' ) {
138 my $csv_profiles = Koha
::CsvProfiles
->search;
139 $template->param( csv_profiles
=> $csv_profiles, );
143 messages
=> \
@messages,
147 output_html_with_http_headers
$input, $cookie, $template->output;