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

(-)a/C4/Letters.pm (-7 / +9 lines)
Lines 106-112 sub GetLetters { Link Here
106
    );
106
    );
107
107
108
    Return a hashref of letter templates.
108
    Return a hashref of letter templates.
109
    The key will be the message transport type.
110
109
111
=cut
110
=cut
112
111
Lines 117-132 sub GetLetterTemplates { Link Here
117
    my $code      = $params->{code};
116
    my $code      = $params->{code};
118
    my $branchcode = $params->{branchcode} // '';
117
    my $branchcode = $params->{branchcode} // '';
119
    my $dbh       = C4::Context->dbh;
118
    my $dbh       = C4::Context->dbh;
120
    my $letters   = $dbh->selectall_hashref(
119
    my $letters   = $dbh->selectall_arrayref(
121
        q|
120
        q|
122
            SELECT module, code, branchcode, name, is_html, title, content, message_transport_type
121
            SELECT module, code, branchcode, name, is_html, title, content, message_transport_type, lang
123
            FROM letter
122
            FROM letter
124
            WHERE module = ?
123
            WHERE module = ?
125
            AND code = ?
124
            AND code = ?
126
            and branchcode = ?
125
            and branchcode = ?
127
        |
126
        |
128
        , 'message_transport_type'
127
        , { Slice => {} }
129
        , undef
130
        , $module, $code, $branchcode
128
        , $module, $code, $branchcode
131
    );
129
    );
132
130
Lines 249-262 sub DelLetter { Link Here
249
    my $module     = $params->{module};
247
    my $module     = $params->{module};
250
    my $code       = $params->{code};
248
    my $code       = $params->{code};
251
    my $mtt        = $params->{mtt};
249
    my $mtt        = $params->{mtt};
250
    my $lang       = $params->{lang};
252
    my $dbh        = C4::Context->dbh;
251
    my $dbh        = C4::Context->dbh;
253
    $dbh->do(q|
252
    $dbh->do(q|
254
        DELETE FROM letter
253
        DELETE FROM letter
255
        WHERE branchcode = ?
254
        WHERE branchcode = ?
256
          AND module = ?
255
          AND module = ?
257
          AND code = ?
256
          AND code = ?
258
    | . ( $mtt ? q| AND message_transport_type = ?| : q|| )
257
    |
259
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ) );
258
    . ( $mtt ? q| AND message_transport_type = ?| : q|| )
259
    . ( $lang? q| AND lang = ?| : q|| )
260
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
260
}
261
}
261
262
262
=head2 addalert ($borrowernumber, $type, $externalid)
263
=head2 addalert ($borrowernumber, $type, $externalid)
Lines 685-690 sub GetPreparedLetter { Link Here
685
    my $letter_code = $params{letter_code} or croak "No letter_code";
686
    my $letter_code = $params{letter_code} or croak "No letter_code";
686
    my $branchcode  = $params{branchcode} || '';
687
    my $branchcode  = $params{branchcode} || '';
687
    my $mtt         = $params{message_transport_type} || 'email';
688
    my $mtt         = $params{message_transport_type} || 'email';
689
    my $lang        = $params{lang} || 'default';
688
690
689
    my $letter = getletter( $module, $letter_code, $branchcode, $mtt )
691
    my $letter = getletter( $module, $letter_code, $branchcode, $mtt )
690
        or warn( "No $module $letter_code letter transported by " . $mtt ),
692
        or warn( "No $module $letter_code letter transported by " . $mtt ),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (-4 / +32 lines)
Lines 105-115 $(document).ready(function() { Link Here
105
            $("#sms_counter").css("color", "black");
105
            $("#sms_counter").css("color", "black");
106
        }
106
        }
107
    });
107
    });
108
    $( "#transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
108
    $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
109
    $(".insert").on("click",function(){
109
    $(".insert").on("click",function(){
110
        var containerid = $(this).data("containerid");
110
        var containerid = $(this).data("containerid");
111
        insertValueQuery( containerid );
111
        insertValueQuery( containerid );
112
    })
112
    })
113
114
    $("#tabs").tabs();
113
});
115
});
114
[% IF add_form or copy_form %]
116
[% IF add_form or copy_form %]
115
	
117
	
Lines 374-381 $(document).ready(function() { Link Here
374
            </li>
376
            </li>
375
        </ol>
377
        </ol>
376
    </fieldset>
378
    </fieldset>
377
        <div id="transport-types" style="clear:both">
379
        [% IF Koha.Preference('TranslateNotices') %]
378
        [% FOREACH letter IN letters %]
380
        <div style="clear:both"></div>
381
            <div id="tabs">
382
                <ul>
383
                    <li><a href="#lang_default">Default</a></li>
384
                    [% FOR language IN languages %]
385
                        [% FOR sublanguage IN language.sublanguages_loop %]
386
                            [% IF language.plural %]
387
                                <li><a href="#lang_[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] [% sublanguage.region_description %] ([% sublanguage.rfc4646_subtag %])</a></li>
388
                            [% ELSE %]
389
                                <li><a href="#lang_[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] ([% sublanguage.rfc4646_subtag %])</a></li>
390
                            [% END %]
391
                        [% END %]
392
                    [% END %]
393
                </ul>
394
        [% END %]
395
396
        [% FOREACH lang IN letters.keys %]
397
            <div id="lang_[% lang %]">
398
        <div class="transport-types" style="clear:both">
399
        [% FOR mtt IN letters.$lang.templates.keys.sort %]
400
            [% SET letter = letters.$lang.templates.$mtt %]
379
            <h3>
401
            <h3>
380
                [% SWITCH letter.message_transport_type %]
402
                [% SWITCH letter.message_transport_type %]
381
                [% CASE 'email' %]
403
                [% CASE 'email' %]
Lines 404-409 $(document).ready(function() { Link Here
404
              <ol>
426
              <ol>
405
                <li>
427
                <li>
406
                  <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
428
                  <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
429
                  <input type="hidden" name="lang" value="[% lang %]" />
407
                  <label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
430
                  <label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
408
                  [% IF letter.is_html %]
431
                  [% IF letter.is_html %]
409
                    <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
432
                    <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
Lines 437-444 $(document).ready(function() { Link Here
437
                </li>
460
                </li>
438
              </ol>
461
              </ol>
439
            </fieldset>
462
            </fieldset>
440
        [% END %]
463
            [% END %]
464
            </div>
441
        </div> <!-- / #transport-types -->
465
        </div> <!-- / #transport-types -->
466
        [% END %]
467
        [% IF Koha.Preference('TranslateNotices') %]
468
        </div>
469
        [% END %]
442
470
443
        [% IF code.search('DGST') %] <span class="overdue">Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch.</span> [% END %]
471
        [% IF code.search('DGST') %] <span class="overdue">Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch.</span> [% END %]
444
        <fieldset class="action"><input type="submit" id="submit_form" value="Submit" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset>
472
        <fieldset class="action"><input type="submit" id="submit_form" value="Submit" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset>
(-)a/t/db_dependent/Letters/GetLetterTemplates.t (-10 / +10 lines)
Lines 105-130 for my $l (@$letters) { Link Here
105
105
106
my $letter_templates;
106
my $letter_templates;
107
$letter_templates = C4::Letters::GetLetterTemplates;
107
$letter_templates = C4::Letters::GetLetterTemplates;
108
is_deeply( $letter_templates, {},
108
is_deeply( $letter_templates, [],
109
    'GetLetterTemplates should not return templates if not param is given' );
109
    'GetLetterTemplates should not return templates if not param is given' );
110
110
111
$letter_templates = C4::Letters::GetLetterTemplates(
111
$letter_templates = C4::Letters::GetLetterTemplates(
112
    { module => 'circulation', code => 'code1', branchcode => '' } );
112
    { module => 'circulation', code => 'code1', branchcode => '' } );
113
is( scalar( keys %$letter_templates ),
113
is( scalar( @$letter_templates ),
114
    2, '2 default templates should exist for circulation code1' );
114
    2, '2 default templates should exist for circulation code1' );
115
is( exists( $letter_templates->{email} ),
115
my $has_email = grep { $_->{message_transport_type} eq 'email' } @$letter_templates;
116
    1, 'The mtt email should exist for circulation code1' );
116
is( $has_email, 1, 'The mtt email should exist for circulation code1' );
117
is( exists( $letter_templates->{sms} ),
117
my $has_sms = grep { $_->{message_transport_type} eq 'sms' } @$letter_templates;
118
    1, 'The mtt sms should exist for circulation code1' );
118
is( $has_sms, 1, 'The mtt sms should exist for circulation code1' );
119
119
120
$letter_templates = C4::Letters::GetLetterTemplates(
120
$letter_templates = C4::Letters::GetLetterTemplates(
121
    { module => 'circulation', code => 'code1', branchcode => 'CPL' } );
121
    { module => 'circulation', code => 'code1', branchcode => 'CPL' } );
122
is( scalar( keys %$letter_templates ),
122
is( scalar( @$letter_templates ),
123
    1, '1 template should exist for circulation CPL code1' );
123
    1, '1 template should exist for circulation CPL code1' );
124
is( exists( $letter_templates->{email} ),
124
$has_email = grep { $_->{message_transport_type} eq 'email' } @$letter_templates;
125
    1, 'The mtt should be email for circulation CPL code1' );
125
is( $has_email, 1, 'The mtt should be email for circulation CPL code1' );
126
126
127
$letter_templates = C4::Letters::GetLetterTemplates(
127
$letter_templates = C4::Letters::GetLetterTemplates(
128
    { module => 'circulation', code => 'code1' } );
128
    { module => 'circulation', code => 'code1' } );
129
is( scalar( keys %$letter_templates ),
129
is( scalar( @$letter_templates ),
130
    2, '2 default templates should exist for circulation code1 (even if branchcode is not given)' );
130
    2, '2 default templates should exist for circulation code1 (even if branchcode is not given)' );
(-)a/tools/letter.pl (-33 / +57 lines)
Lines 146-193 sub add_form { Link Here
146
    }
146
    }
147
147
148
    my $message_transport_types = GetMessageTransportTypes();
148
    my $message_transport_types = GetMessageTransportTypes();
149
    my @letter_loop;
149
    my $templates = { map { $_ => { message_transport_type => $_ } } sort @$message_transport_types };
150
    my %letters = ( default => { templates => $templates } );
151
152
    if ( C4::Context->preference('TranslateNotices') ) {
153
        my $translated_languages =
154
          C4::Languages::getTranslatedLanguages( 'opac',
155
            C4::Context->preference('template') );
156
        for my $language (@$translated_languages) {
157
            for my $sublanguage( @{ $language->{sublanguages_loop} } ) {
158
                if ( $language->{plural} ) {
159
                    $letters{ $sublanguage->{rfc4646_subtag} } = {
160
                        description => $sublanguage->{native_description}
161
                          . ' '
162
                          . $sublanguage->{region_description} . ' ('
163
                          . $sublanguage->{rfc4646_subtag} . ')',
164
                        templates => { %$templates },
165
                    };
166
                }
167
                else {
168
                    $letters{ $sublanguage->{rfc4646_subtag} } = {
169
                        description => $sublanguage->{native_description}
170
                          . ' ('
171
                          . $sublanguage->{rfc4646_subtag} . ')',
172
                        templates => { %$templates },
173
                    };
174
                }
175
            }
176
        }
177
        $template->param( languages => $translated_languages );
178
    }
150
    if ($letters) {
179
    if ($letters) {
151
        $template->param(
180
        $template->param(
152
            modify     => 1,
181
            modify     => 1,
153
            code       => $code,
182
            code       => $code,
154
            branchcode => $branchcode,
155
        );
183
        );
156
        my $first_flag = 1;
184
        my $first_flag_name = 1;
185
        my ( $lang, @templates );
157
        # The letter name is contained into each mtt row.
186
        # The letter name is contained into each mtt row.
158
        # So we can only sent the first one to the template.
187
        # So we can only sent the first one to the template.
159
        for my $mtt ( @$message_transport_types ) {
188
        for my $letter ( @$letters ) {
160
            # The letter_name
189
            # The letter_name
161
            if ( $first_flag and $letters->{$mtt}{name} ) {
190
            if ( $first_flag_name and $letter->{name} ) {
162
                $template->param(
191
                $template->param(
163
                    letter_name=> $letters->{$mtt}{name},
192
                    letter_name=> $letter->{name},
164
                );
193
                );
165
                $first_flag = 0;
194
                $first_flag_name = 0;
166
            }
195
            }
167
196
168
            push @letter_loop, {
197
            my $lang = $letter->{lang};
169
                message_transport_type => $mtt,
198
            my $mtt = $letter->{message_transport_type};
170
                is_html    => $letters->{$mtt}{is_html},
199
            $letters{ $lang }{templates}{$mtt} = {
171
                title      => $letters->{$mtt}{title},
200
                message_transport_type => $letter->{message_transport_type},
172
                content    => $letters->{$mtt}{content}//'',
201
                is_html    => $letter->{is_html},
202
                title      => $letter->{title},
203
                content    => $letter->{content} // '',
173
            };
204
            };
174
        }
205
        }
175
    }
206
    }
176
    else { # initialize the new fields
207
    else {
177
        for my $mtt ( @$message_transport_types ) {
178
            push @letter_loop, {
179
                message_transport_type => $mtt,
180
            }
181
        }
182
        $template->param(
183
            branchcode => $branchcode,
184
            module     => $module,
185
        );
186
        $template->param( adding => 1 );
208
        $template->param( adding => 1 );
187
    }
209
    }
188
210
189
    $template->param(
211
    $template->param(
190
        letters => \@letter_loop,
212
        letters => \%letters,
191
    );
213
    );
192
214
193
    my $field_selection;
215
    my $field_selection;
Lines 258-268 sub add_validate { Link Here
258
    my @mtt           = $input->multi_param('message_transport_type');
280
    my @mtt           = $input->multi_param('message_transport_type');
259
    my @title         = $input->multi_param('title');
281
    my @title         = $input->multi_param('title');
260
    my @content       = $input->multi_param('content');
282
    my @content       = $input->multi_param('content');
283
    my @lang          = $input->multi_param('lang');
261
    for my $mtt ( @mtt ) {
284
    for my $mtt ( @mtt ) {
262
        my $is_html = $input->param("is_html_$mtt");
285
        my $is_html = $input->param("is_html_$mtt");
263
        my $title   = shift @title;
286
        my $title   = shift @title;
264
        my $content = shift @content;
287
        my $content = shift @content;
265
        my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt);
288
        my $lang = shift @lang;
289
        my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt, $lang );
266
290
267
        # getletter can return the default letter even if we pass a branchcode
291
        # getletter can return the default letter even if we pass a branchcode
268
        # If we got the default one and we needed the specific one, we didn't get the one we needed!
292
        # If we got the default one and we needed the specific one, we didn't get the one we needed!
Lines 271-295 sub add_validate { Link Here
271
        }
295
        }
272
        unless ( $title and $content ) {
296
        unless ( $title and $content ) {
273
            # Delete this mtt if no title or content given
297
            # Delete this mtt if no title or content given
274
            delete_confirmed( $branchcode, $oldmodule, $code, $mtt );
298
            delete_confirmed( $branchcode, $oldmodule, $code, $mtt, $lang );
275
            next;
299
            next;
276
        }
300
        }
277
        elsif ( $letter and $letter->{message_transport_type} eq $mtt ) {
301
        elsif ( $letter and $letter->{message_transport_type} eq $mtt and $letter->{lang} eq $lang ) {
278
            $dbh->do(
302
            $dbh->do(
279
                q{
303
                q{
280
                    UPDATE letter
304
                    UPDATE letter
281
                    SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ?
305
                    SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ?, lang = ?
282
                    WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ?
306
                    WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ?
283
                },
307
                },
284
                undef,
308
                undef,
285
                $branchcode || '', $module, $name, $is_html || 0, $title, $content,
309
                $branchcode || '', $module, $name, $is_html || 0, $title, $content, $lang,
286
                $branchcode, $oldmodule, $code, $mtt
310
                $branchcode, $oldmodule, $code, $mtt
287
            );
311
            );
288
        } else {
312
        } else {
289
            $dbh->do(
313
            $dbh->do(
290
                q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)},
314
                q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type, lang) VALUES (?,?,?,?,?,?,?,?,?)},
291
                undef,
315
                undef,
292
                $branchcode || '', $module, $code, $name, $is_html || 0, $title, $content, $mtt
316
                $branchcode || '', $module, $code, $name, $is_html || 0, $title, $content, $mtt, $lang
293
            );
317
            );
294
        }
318
        }
295
    }
319
    }
Lines 310-322 sub delete_confirm { Link Here
310
}
334
}
311
335
312
sub delete_confirmed {
336
sub delete_confirmed {
313
    my ($branchcode, $module, $code, $mtt) = @_;
337
    my ($branchcode, $module, $code, $mtt, $lang) = @_;
314
    C4::Letters::DelLetter(
338
    C4::Letters::DelLetter(
315
        {
339
        {
316
            branchcode => $branchcode || '',
340
            branchcode => $branchcode || '',
317
            module     => $module,
341
            module     => $module,
318
            code       => $code,
342
            code       => $code,
319
            mtt        => $mtt
343
            mtt        => $mtt,
344
            lang       => $lang,
320
        }
345
        }
321
    );
346
    );
322
    # setup default display for screen
347
    # setup default display for screen
323
- 

Return to bug 17762