#
# 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
use strict;
use warnings;
-use CGI;
+use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
use C4::Letters;
use C4::Members::Attributes;
-# _letter_from_where($branchcode,$module, $code, $mtt)
-# - return FROM WHERE clause and bind args for a letter
-sub _letter_from_where {
- my ($branchcode, $module, $code, $mtt) = @_;
- my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?};
- $sql .= q{ AND message_transport_type = ?} if $mtt ne '*';
- my @args = ( $branchcode || '', $module, $code, ($mtt ne '*' ? $mtt : ()) );
-# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that
-# work with foreign key constraint I wonder...
-
-# if ($branchcode) {
-# $sql .= " AND branchcode = ?";
-# push @args, $branchcode;
-# } else {
-# $sql .= " AND branchcode IS NULL";
-# }
-
- return ($sql, \@args);
-}
-
-# get_letters($branchcode,$module, $code, $mtt)
-# - return letters with the given $branchcode, $module, $code and $mtt exists
-sub get_letters {
- my ($sql, $args) = _letter_from_where(@_);
- my $dbh = C4::Context->dbh;
- my $letter = $dbh->selectall_hashref("SELECT * $sql", 'message_transport_type', undef, @$args);
- return $letter;
-}
# $protected_letters = protected_letters()
# - return a hashref of letter_codes representing letters that should never be deleted
sub protected_letters {
our ( $template, $borrowernumber, $cookie, $staffflags ) = get_template_and_user(
{
- template_name => 'tools/letter.tmpl',
+ template_name => 'tools/letter.tt',
query => $input,
type => 'intranet',
authnotrequired => 0,
if ($op eq 'copy_form') {
my $oldbranchcode = $input->param('oldbranchcode') || q||;
my $branchcode = $input->param('branchcode') || q||;
- my $oldcode = $input->param('oldcode') || $input->param('code');
add_form($oldbranchcode, $module, $code);
$template->param(
oldbranchcode => $oldbranchcode,
branchcode => $branchcode,
branchloop => _branchloop($branchcode),
- oldcode => $oldcode,
copying => 1,
modify => 0,
);
delete_confirm($branchcode, $module, $code);
}
elsif ( $op eq 'delete_confirmed' ) {
- my $mtt = $input->param('message_transport_type');
- delete_confirmed($branchcode, $module, $code, $mtt);
+ delete_confirmed($branchcode, $module, $code);
$op = q{}; # next operation is to return to default screen
}
else {
my $letters;
# if code has been passed we can identify letter and its an update action
if ($code) {
- $letters = get_letters($branchcode,$module, $code, '*');
+ $letters = C4::Letters::GetLetterTemplates(
+ {
+ branchcode => $branchcode,
+ module => $module,
+ code => $code,
+ }
+ );
}
my $message_transport_types = GetMessageTransportTypes();
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');
}
my $is_html = $input->param("is_html_$mtt");
my $title = shift @title;
my $content = shift @content;
- my $letter = get_letters($branchcode,$oldmodule, $code, $mtt);
+ 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
sub delete_confirm {
my ($branchcode, $module, $code) = @_;
my $dbh = C4::Context->dbh;
- my $letter = get_letters($branchcode, $module, $code, '*');
+ 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;
}
sub delete_confirmed {
my ($branchcode, $module, $code, $mtt) = @_;
- my ($sql, $args) = _letter_from_where($branchcode, $module, $code, $mtt);
- my $dbh = C4::Context->dbh;
- $dbh->do("DELETE $sql", undef, @$args);
+ C4::Letters::DelLetter(
+ {
+ branchcode => $branchcode,
+ module => $module,
+ code => $code,
+ mtt => $mtt
+ }
+ );
# setup default display for screen
default_display($branchcode);
return;
sub get_columns_for {
my $table = shift;
-# FIXME untranslateable
+# FIXME untranslatable
my %column_map = (
aqbooksellers => '---BOOKSELLERS---',
aqorders => '---ORDERS---',