View | Details | Raw Unified | Return to bug 14445
Collapse All | Expand All

(-)a/tools/letter.pl (-56 / +42 lines)
Lines 4-21 Link Here
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
7
# Koha is free software; you can redistribute it and/or modify it
8
# terms of the GNU General Public License as published by the Free Software
8
# under the terms of the GNU General Public License as published by
9
# Foundation; either version 2 of the License, or (at your option) any later
9
# the Free Software Foundation; either version 3 of the License, or
10
# version.
10
# (at your option) any later version.
11
#
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# Koha is distributed in the hope that it will be useful, but
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
15
#
16
#
16
# You should have received a copy of the GNU General Public License along
17
# You should have received a copy of the GNU General Public License
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
=head1 tools/letter.pl
20
=head1 tools/letter.pl
21
21
Lines 42-48 Link Here
42
42
43
use strict;
43
use strict;
44
use warnings;
44
use warnings;
45
use CGI;
45
use CGI qw ( -utf8 );
46
use C4::Auth;
46
use C4::Auth;
47
use C4::Context;
47
use C4::Context;
48
use C4::Output;
48
use C4::Output;
Lines 50-83 use C4::Branch; # GetBranches Link Here
50
use C4::Letters;
50
use C4::Letters;
51
use C4::Members::Attributes;
51
use C4::Members::Attributes;
52
52
53
# _letter_from_where($branchcode,$module, $code, $mtt)
54
# - return FROM WHERE clause and bind args for a letter
55
sub _letter_from_where {
56
    my ($branchcode, $module, $code, $mtt) = @_;
57
    my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?};
58
    $sql .= q{ AND message_transport_type = ?} if $mtt ne '*';
59
    my @args = ( $branchcode || '', $module, $code, ($mtt ne '*' ? $mtt : ()) );
60
# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that
61
# work with foreign key constraint I wonder...
62
63
#   if ($branchcode) {
64
#       $sql .= " AND branchcode = ?";
65
#       push @args, $branchcode;
66
#   } else {
67
#       $sql .= " AND branchcode IS NULL";
68
#   }
69
70
    return ($sql, \@args);
71
}
72
73
# get_letters($branchcode,$module, $code, $mtt)
74
# - return letters with the given $branchcode, $module, $code and $mtt exists
75
sub get_letters {
76
    my ($sql, $args) = _letter_from_where(@_);
77
    my $dbh = C4::Context->dbh;
78
    my $letter = $dbh->selectall_hashref("SELECT * $sql", 'message_transport_type', undef, @$args);
79
    return $letter;
80
}
81
# $protected_letters = protected_letters()
53
# $protected_letters = protected_letters()
82
# - return a hashref of letter_codes representing letters that should never be deleted
54
# - return a hashref of letter_codes representing letters that should never be deleted
83
sub protected_letters {
55
sub protected_letters {
Lines 127-139 if ( $op eq 'add_validate' or $op eq 'copy_validate' ) { Link Here
127
if ($op eq 'copy_form') {
99
if ($op eq 'copy_form') {
128
    my $oldbranchcode = $input->param('oldbranchcode') || q||;
100
    my $oldbranchcode = $input->param('oldbranchcode') || q||;
129
    my $branchcode = $input->param('branchcode') || q||;
101
    my $branchcode = $input->param('branchcode') || q||;
130
    my $oldcode = $input->param('oldcode') || $input->param('code');
131
    add_form($oldbranchcode, $module, $code);
102
    add_form($oldbranchcode, $module, $code);
132
    $template->param(
103
    $template->param(
133
        oldbranchcode => $oldbranchcode,
104
        oldbranchcode => $oldbranchcode,
134
        branchcode => $branchcode,
105
        branchcode => $branchcode,
135
        branchloop => _branchloop($branchcode),
106
        branchloop => _branchloop($branchcode),
136
        oldcode => $oldcode,
137
        copying => 1,
107
        copying => 1,
138
        modify => 0,
108
        modify => 0,
139
    );
109
    );
Lines 145-152 elsif ( $op eq 'delete_confirm' ) { Link Here
145
    delete_confirm($branchcode, $module, $code);
115
    delete_confirm($branchcode, $module, $code);
146
}
116
}
147
elsif ( $op eq 'delete_confirmed' ) {
117
elsif ( $op eq 'delete_confirmed' ) {
148
    my $mtt = $input->param('message_transport_type');
118
    delete_confirmed($branchcode, $module, $code);
149
    delete_confirmed($branchcode, $module, $code, $mtt);
150
    $op = q{}; # next operation is to return to default screen
119
    $op = q{}; # next operation is to return to default screen
151
}
120
}
152
else {
121
else {
Lines 168-174 sub add_form { Link Here
168
    my $letters;
137
    my $letters;
169
    # if code has been passed we can identify letter and its an update action
138
    # if code has been passed we can identify letter and its an update action
170
    if ($code) {
139
    if ($code) {
171
        $letters = get_letters($branchcode,$module, $code, '*');
140
        $letters = C4::Letters::GetLetterTemplates(
141
            {
142
                branchcode => $branchcode,
143
                module     => $module,
144
                code       => $code,
145
            }
146
        );
172
    }
147
    }
173
148
174
    my $message_transport_types = GetMessageTransportTypes();
149
    my $message_transport_types = GetMessageTransportTypes();
Lines 218-226 sub add_form { Link Here
218
193
219
    my $field_selection;
194
    my $field_selection;
220
    push @{$field_selection}, add_fields('branches');
195
    push @{$field_selection}, add_fields('branches');
196
    $code //= '';
221
    if ($module eq 'reserves') {
197
    if ($module eq 'reserves') {
222
        push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
198
        push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
223
    }
199
    }
200
    elsif ( $module eq 'acquisition' ) {
201
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'items');
202
    }
224
    elsif ($module eq 'claimacquisition') {
203
    elsif ($module eq 'claimacquisition') {
225
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems');
204
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems');
226
    }
205
    }
Lines 278-289 sub add_validate { Link Here
278
        my $is_html = $input->param("is_html_$mtt");
257
        my $is_html = $input->param("is_html_$mtt");
279
        my $title   = shift @title;
258
        my $title   = shift @title;
280
        my $content = shift @content;
259
        my $content = shift @content;
281
        my $letter = get_letters($branchcode,$oldmodule, $code, $mtt);
260
        my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt);
261
262
        # getletter can return the default letter even if we pass a branchcode
263
        # If we got the default one and we needed the specific one, we didn't get the one we needed!
264
        if ( $letter and $branchcode ne $letter->{branchcode} ) {
265
            $letter = undef;
266
        }
282
        unless ( $title and $content ) {
267
        unless ( $title and $content ) {
268
            # Delete this mtt if no title or content given
283
            delete_confirmed( $branchcode, $oldmodule, $code, $mtt );
269
            delete_confirmed( $branchcode, $oldmodule, $code, $mtt );
284
            next;
270
            next;
285
        }
271
        }
286
        elsif ( exists $letter->{$mtt} ) {
272
        elsif ( $letter and $letter->{message_transport_type} eq $mtt ) {
287
            $dbh->do(
273
            $dbh->do(
288
                q{
274
                q{
289
                    UPDATE letter
275
                    UPDATE letter
Lines 310-332 sub add_validate { Link Here
310
sub delete_confirm {
296
sub delete_confirm {
311
    my ($branchcode, $module, $code) = @_;
297
    my ($branchcode, $module, $code) = @_;
312
    my $dbh = C4::Context->dbh;
298
    my $dbh = C4::Context->dbh;
313
    my $letter = get_letters($branchcode, $module, $code, '*');
299
    my $letter = C4::Letters::getletter($module, $code, $branchcode);
314
    my @values = values %$letter;
300
    my @values = values %$letter;
315
    $template->param(
301
    $template->param(
316
        branchcode => $branchcode,
302
        letter => $letter,
317
        branchname => GetBranchName($branchcode),
318
        code => $code,
319
        module => $module,
320
        name => $values[0]->{name},
321
    );
303
    );
322
    return;
304
    return;
323
}
305
}
324
306
325
sub delete_confirmed {
307
sub delete_confirmed {
326
    my ($branchcode, $module, $code, $mtt) = @_;
308
    my ($branchcode, $module, $code, $mtt) = @_;
327
    my ($sql, $args) = _letter_from_where($branchcode, $module, $code, $mtt);
309
    C4::Letters::DelLetter(
328
    my $dbh    = C4::Context->dbh;
310
        {
329
    $dbh->do("DELETE $sql", undef, @$args);
311
            branchcode => $branchcode,
312
            module     => $module,
313
            code       => $code,
314
            mtt        => $mtt
315
        }
316
    );
330
    # setup default display for screen
317
    # setup default display for screen
331
    default_display($branchcode);
318
    default_display($branchcode);
332
    return;
319
    return;
333
- 

Return to bug 14445