Bug 7298: (follow-up) fix uninitialized variable warning
[koha.git] / tools / csv-profiles.pl
index 1e037f3..45b1285 100755 (executable)
@@ -13,9 +13,9 @@
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 =head1 NAME
 
@@ -23,6 +23,7 @@ csv-profile.pl : Defines a CSV export profile
 
 =head1 SYNOPSIS
 
+=cut
 
 =head1 DESCRIPTION
 
@@ -30,12 +31,12 @@ This script allow the user to define a new profile for CSV export
 
 =head1 FUNCTIONS
 
-=over 2
-
 =cut
 
 use strict;
+#use warnings; FIXME - Bug 2505
 use Data::Dumper;
+use Encode;
 
 use C4::Auth;
 use C4::Context;
@@ -59,30 +60,41 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
+# Getting available encodings list
+my @encodings = Encode->encodings();
+my @encodings_loop = map{{encoding => $_}} @encodings;
+$template->param(encodings => \@encodings_loop);
 
 my $profile_name        = $input->param("profile_name");
 my $profile_description = $input->param("profile_description");
-my $profile_content     = $input->param("profile_content");
+my $csv_separator       = $input->param("csv_separator");
+my $field_separator     = $input->param("field_separator");
+my $subfield_separator  = $input->param("subfield_separator");
+my $encoding            = $input->param("encoding");
+my $type                = $input->param("profile_type");
 my $action              = $input->param("action");
 my $delete              = $input->param("delete");
 my $id                  = $input->param("id");
 if ($delete) { $action = "delete"; }
 
-if ($profile_name && $profile_content && $profile_description && $action) {
+my $profile_content = $type eq "marc"
+    ? $input->param("profile_marc_content")
+    : $input->param("profile_sql_content");
+
+if ($profile_name && $profile_content && $action) {
     my $rows;
 
     if ($action eq "create") {
-       my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields) VALUES (NULL, ?, ?, ?)";
+    my $query = "INSERT INTO export_format(export_format_id, profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)";
        my $sth   = $dbh->prepare($query);
-       $rows  = $sth->execute($profile_name, $profile_description, $profile_content);
+    $rows  = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $type);
     
     }
 
     if ($action eq "edit") {
-       my $query = "UPDATE export_format SET description=?, marcfields=? WHERE export_format_id=? LIMIT 1";
+    my $query = "UPDATE export_format SET description=?, content=?, csv_separator=?, field_separator=?, subfield_separator=?, encoding=?, type=? WHERE export_format_id=? LIMIT 1";
        my $sth   = $dbh->prepare($query);
-       $rows  = $sth->execute($profile_description, $profile_content, $profile_name);
-
+    $rows  = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $type, $profile_name);
     }
 
     if ($action eq "delete") {
@@ -100,7 +112,7 @@ if ($profile_name && $profile_content && $profile_description && $action) {
 
     # If a profile has been selected for modification
     if ($id) {
-       my $query = "SELECT export_format_id, profile, description, marcfields FROM export_format WHERE export_format_id = ?";
+    my $query = "SELECT export_format_id, profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type FROM export_format WHERE export_format_id = ?";
        my $sth;
        $sth = $dbh->prepare($query);
 
@@ -110,7 +122,12 @@ if ($profile_name && $profile_content && $profile_description && $action) {
            selected_profile_id          => $selected_profile->[0],
            selected_profile_name        => $selected_profile->[1],
            selected_profile_description => $selected_profile->[2],
-           selected_profile_marcfields  => $selected_profile->[3]
+        selected_profile_content     => $selected_profile->[3],
+           selected_csv_separator       => $selected_profile->[4],
+           selected_field_separator     => $selected_profile->[5],
+           selected_subfield_separator  => $selected_profile->[6],
+        selected_encoding            => $selected_profile->[7],
+        selected_profile_type        => $selected_profile->[8]
        );
 
     }