Bug 10181: Make string translatable
[koha.git] / tools / letter.pl
index 0f2b501..f4173dc 100755 (executable)
@@ -4,18 +4,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY 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.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 tools/letter.pl
 
@@ -42,7 +42,7 @@
 
 use strict;
 use warnings;
-use CGI;
+use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Context;
 use C4::Output;
@@ -196,6 +196,9 @@ sub add_form {
     if ($module eq 'reserves') {
         push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
     }
+    elsif ( $module eq 'acquisition' ) {
+        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'items');
+    }
     elsif ($module eq 'claimacquisition') {
         push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems');
     }
@@ -210,6 +213,9 @@ sub add_form {
             push @{$field_selection}, {value => "biblio.$_", text => ucfirst $_ };
         }
     }
+    elsif ($module eq 'serial') {
+        push @{$field_selection}, add_fields('branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial');
+    }
     elsif ($module eq 'suggestions') {
         push @{$field_selection}, add_fields('suggestions', 'borrowers', 'biblio');
     }
@@ -224,7 +230,7 @@ sub add_form {
 
         }
 
-        if ( $module eq 'circulation' && $code eq "CHECKIN" ) {
+        if ( $module eq 'circulation' and $code and $code eq "CHECKIN" ) {
             push @{$field_selection}, add_fields('old_issues');
         } else {
             push @{$field_selection}, add_fields('issues');
@@ -234,7 +240,8 @@ sub add_form {
     $template->param(
         module     => $module,
         branchloop => _branchloop($branchcode),
-        SQLfieldname => $field_selection,
+        SQLfieldnames => $field_selection,
+        branchcode => $branchcode,
     );
     return;
 }
@@ -254,12 +261,18 @@ sub add_validate {
         my $title   = shift @title;
         my $content = shift @content;
         my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt);
+
+        # getletter can return the default letter even if we pass a branchcode
+        # If we got the default one and we needed the specific one, we didn't get the one we needed!
+        if ( $letter and $branchcode ne $letter->{branchcode} ) {
+            $letter = undef;
+        }
         unless ( $title and $content ) {
             # Delete this mtt if no title or content given
             delete_confirmed( $branchcode, $oldmodule, $code, $mtt );
             next;
         }
-        elsif ( exists $letter->{$mtt} ) {
+        elsif ( $letter and $letter->{message_transport_type} eq $mtt ) {
             $dbh->do(
                 q{
                     UPDATE letter
@@ -289,11 +302,7 @@ sub delete_confirm {
     my $letter = C4::Letters::getletter($module, $code, $branchcode);
     my @values = values %$letter;
     $template->param(
-        branchcode => $branchcode,
-        branchname => GetBranchName($branchcode),
-        code => $code,
-        module => $module,
-        name => $values[0]->{name},
+        letter => $letter,
     );
     return;
 }
@@ -396,7 +405,7 @@ sub add_fields {
 
 sub get_columns_for {
     my $table = shift;
-# FIXME untranslateable
+# FIXME untranslatable
     my %column_map = (
         aqbooksellers => '---BOOKSELLERS---',
         aqorders      => '---ORDERS---',