Bug 7333 - Fixing up db_dependent/Search.t to use sample data Thanks to Chris N....
[koha.git] / tools / letter.pl
index ab6039c..f5dc0c6 100755 (executable)
@@ -172,13 +172,14 @@ sub add_form {
         push @{$field_selection}, add_fields('biblio','biblioitems'),
             {value => q{},             text => '---ITEMS---'  },
             {value => 'items.content', text => 'items.content'},
-            add_fields('borrowers');
+            add_fields('issues','borrowers');
     }
 
     $template->param(
         name    => $letter->{name},
         title   => $letter->{title},
         content => $letter->{content},
+        module  => $module,
         $module => 1,
         SQLfieldname => $field_selection,
     );
@@ -186,18 +187,19 @@ sub add_form {
 }
 
 sub add_validate {
-    my $dbh     = C4::Context->dbh;
-    my $module  = $input->param('module');
-    my $code    = $input->param('code');
-    my $name    = $input->param('name');
-    my $title   = $input->param('title');
-    my $content = $input->param('content');
-    if (letter_exists($module, $code)) {
+    my $dbh        = C4::Context->dbh;
+    my $module     = $input->param('module');
+    my $oldmodule  = $input->param('oldmodule');
+    my $code       = $input->param('code');
+    my $name       = $input->param('name');
+    my $title      = $input->param('title');
+    my $content    = $input->param('content');
+    if (letter_exists($oldmodule, $code)) {
         $dbh->do(
             q{UPDATE letter SET module = ?, code = ?, name = ?, title = ?, content = ? WHERE module = ? AND code = ?},
             undef,
             $module, $code, $name, $title, $content,
-            $module, $code
+            $oldmodule, $code
         );
     } else {
         $dbh->do(
@@ -309,6 +311,7 @@ sub get_columns_for {
     my $table_prefix = $table . q|.|;
     my $rows = C4::Context->dbh->selectall_arrayref($sql, { Slice => {} });
     for my $row (@{$rows}) {
+        next if $row->{'Field'} eq 'timestamp'; # this is really an irrelevant field and there may be other common fields that should be excluded from the list
         push @fields, {
             value => $table_prefix . $row->{Field},
             text  => $table_prefix . $row->{Field},