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 |
- |
|
|