ZUGFeRD: allgemeine Notizen für alle Rechnungen in Übersetzungen anlegen können
[kivitendo-erp.git] / bin / mozilla / generictranslations.pl
1 use SL::Auth;
2 use SL::Form;
3 use SL::GenericTranslations;
4 use SL::Locale::String qw(t8);
5
6 use strict;
7
8 # convention:
9 # preset_text_$formname will generate a input textarea
10 # and will be preset in $form email dialog if the form name matches
11
12 my %mail_strings = (
13   salutation_male                             => t8('Salutation male'),
14   salutation_female                           => t8('Salutation female'),
15   salutation_general                          => t8('Salutation general'),
16   salutation_punctuation_mark                 => t8('Salutation punctuation mark'),
17   preset_text_sales_quotation                 => t8('Preset email text for sales quotations'),
18   preset_text_sales_order                     => t8('Preset email text for sales orders'),
19   preset_text_sales_delivery_order            => t8('Preset email text for sales delivery orders'),
20   preset_text_invoice                         => t8('Preset email text for sales invoices'),
21   preset_text_request_quotation               => t8('Preset email text for requests (rfq)'),
22   preset_text_purchase_order                  => t8('Preset email text for purchase orders'),
23   preset_text_periodic_invoices_email_body    => t8('Preset email body for periodic invoices'),
24   preset_text_periodic_invoices_email_subject => t8('Preset email subject for periodic invoices'),
25 );
26
27 sub edit_greetings {
28   $main::lxdebug->enter_sub();
29
30   $main::auth->assert('config');
31
32   my $form     = $main::form;
33   my $locale   = $main::locale;
34
35   $form->get_lists('languages' => 'LANGUAGES');
36
37   my $translation_list = GenericTranslations->list();
38   my %translations     = ();
39
40   my @types            = qw(male female);
41
42   foreach my $translation (@{ $translation_list }) {
43     $translation->{language_id}                                                          ||= 'default';
44     $translations{$translation->{language_id} . '::' . $translation->{translation_type}}   = $translation;
45   }
46
47   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
48
49   foreach my $language (@{ $form->{LANGUAGES} }) {
50     foreach my $type (@types) {
51       $language->{$type} = { };
52       my $translation    = $translations{"$language->{id}::greetings::${type}"} || { };
53       $language->{$type} = $translation->{translation};
54     }
55   }
56
57   setup_generictranslations_edit_greetings_action_bar();
58
59   $form->{title} = $locale->text('Edit greetings');
60   $form->header();
61   print $form->parse_html_template('generictranslations/edit_greetings');
62
63   $main::lxdebug->leave_sub();
64 }
65
66 sub save_greetings {
67   $main::lxdebug->enter_sub();
68
69   $main::auth->assert('config');
70
71   my $form     = $main::form;
72   my $locale   = $main::locale;
73
74   $form->get_lists('languages' => 'LANGUAGES');
75
76   unshift @{ $form->{LANGUAGES} }, { };
77
78   my @types  = qw(male female);
79
80   foreach my $language (@{ $form->{LANGUAGES} }) {
81     foreach my $type (@types) {
82       GenericTranslations->save('translation_type' => "greetings::${type}",
83                                 'translation_id'   => undef,
84                                 'language_id'      => $language->{id},
85                                 'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__${type}"},);
86     }
87   }
88
89   $form->{message} = $locale->text('The greetings have been saved.');
90
91   edit_greetings();
92
93   $main::lxdebug->leave_sub();
94 }
95
96 sub edit_sepa_strings {
97   $main::lxdebug->enter_sub();
98
99   $main::auth->assert('config');
100
101   my $form     = $main::form;
102   my $locale   = $main::locale;
103
104   $form->get_lists('languages' => 'LANGUAGES');
105
106   my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
107   my %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
108
109   my $translation_list_vc = GenericTranslations->list(translation_type => 'sepa_remittance_vc_no_pfx');
110   my %translations_vc     =  map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list_vc };
111
112   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
113
114   foreach my $language (@{ $form->{LANGUAGES} }) {
115     $language->{translation}    = $translations{$language->{id}};
116     $language->{translation_vc} = $translations_vc{$language->{id}};
117   }
118
119   setup_generictranslations_edit_sepa_strings_action_bar();
120
121   $form->{title} = $locale->text('Edit SEPA strings');
122   $form->header();
123   print $form->parse_html_template('generictranslations/edit_sepa_strings');
124
125   $main::lxdebug->leave_sub();
126 }
127
128 sub save_sepa_strings {
129   $main::lxdebug->enter_sub();
130
131   $main::auth->assert('config');
132
133   my $form     = $main::form;
134   my $locale   = $main::locale;
135
136   $form->get_lists('languages' => 'LANGUAGES');
137
138   unshift @{ $form->{LANGUAGES} }, { };
139
140   foreach my $language (@{ $form->{LANGUAGES} }) {
141     GenericTranslations->save('translation_type' => 'sepa_remittance_info_pfx',
142                               'translation_id'   => undef,
143                               'language_id'      => $language->{id},
144                               'translation'      => $form->{"translation__" . ($language->{id} || 'default')},);
145     GenericTranslations->save('translation_type' => 'sepa_remittance_vc_no_pfx',
146                               'translation_id'   => undef,
147                               'language_id'      => $language->{id},
148                               'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__vc" },);
149   }
150
151   $form->{message} = $locale->text('The SEPA strings have been saved.');
152
153   edit_sepa_strings();
154
155   $main::lxdebug->leave_sub();
156 }
157 sub edit_email_strings {
158   $main::lxdebug->enter_sub();
159
160   $main::auth->assert('config');
161
162   my $form     = $main::form;
163   my $locale   = $main::locale;
164
165   $form->get_lists('languages' => 'LANGUAGES');
166   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
167
168   my (%translations, $translation_list);
169   foreach (keys %mail_strings)  {
170     $translation_list = GenericTranslations->list(translation_type => $_);
171     %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
172
173     foreach my $language (@{ $form->{LANGUAGES} }) {
174       $language->{$_} = $translations{$language->{id}};
175     }
176   }
177   setup_generictranslations_edit_email_strings_action_bar();
178
179   $form->{title} = $locale->text('Edit preset email strings');
180   $form->header();
181   print $form->parse_html_template('generictranslations/edit_email_strings',{ 'MAIL_STRINGS' => \%mail_strings });
182
183   $main::lxdebug->leave_sub();
184 }
185
186 sub save_email_strings {
187   $main::lxdebug->enter_sub();
188
189   $main::auth->assert('config');
190
191   my $form     = $main::form;
192   my $locale   = $main::locale;
193
194   $form->get_lists('languages' => 'LANGUAGES');
195
196   unshift @{ $form->{LANGUAGES} }, { };
197   foreach my $language (@{ $form->{LANGUAGES} }) {
198     foreach (keys %mail_strings)  {
199       GenericTranslations->save('translation_type' => $_,
200                                 'translation_id'   => undef,
201                                 'language_id'      => $language->{id},
202                                 'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__" . $_},
203                                );
204     }
205   }
206   $form->{message} = $locale->text('The Mail strings have been saved.');
207
208   edit_email_strings();
209
210   $main::lxdebug->leave_sub();
211 }
212
213 sub edit_zugferd_notes {
214   $::auth->assert('config');
215
216   $::form->get_lists('languages' => 'LANGUAGES');
217
218   my $translation_list = GenericTranslations->list(translation_type => 'ZUGFeRD/notes');
219   my %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
220
221   unshift @{ $::form->{LANGUAGES} }, { 'id' => 'default', };
222
223   foreach my $language (@{ $::form->{LANGUAGES} }) {
224     $language->{translation} = $translations{$language->{id}};
225   }
226
227   setup_generictranslations_edit_zugferd_notes_action_bar();
228
229   $::form->{title} = $::locale->text('Edit ZUGFeRD notes');
230   $::form->header;
231   print $::form->parse_html_template('generictranslations/edit_zugferd_notes');
232 }
233
234 sub save_zugferd_notes {
235   $::auth->assert('config');
236
237   $::form->get_lists('languages' => 'LANGUAGES');
238
239   unshift @{ $::form->{LANGUAGES} }, { };
240
241   foreach my $language (@{ $::form->{LANGUAGES} }) {
242     GenericTranslations->save(
243       translation_type => 'ZUGFeRD/notes',
244       translation_id   => undef,
245       language_id      => $language->{id},
246       translation      => $::form->{"translation__" . ($language->{id} || 'default')},
247     );
248   }
249
250   $::form->{message} = $::locale->text('The ZUGFeRD notes have been saved.');
251
252   edit_zugferd_notes();
253 }
254
255 sub setup_generictranslations_edit_greetings_action_bar {
256   my %params = @_;
257
258   for my $bar ($::request->layout->get('actionbar')) {
259     $bar->add(
260       action => [
261         t8('Save'),
262         submit    => [ '#form', { action => "save_greetings" } ],
263         accesskey => 'enter',
264       ],
265     );
266   }
267 }
268
269 sub setup_generictranslations_edit_sepa_strings_action_bar {
270   my %params = @_;
271
272   for my $bar ($::request->layout->get('actionbar')) {
273     $bar->add(
274       action => [
275         t8('Save'),
276         submit    => [ '#form', { action => "save_sepa_strings" } ],
277         accesskey => 'enter',
278       ],
279     );
280   }
281 }
282
283 sub setup_generictranslations_edit_email_strings_action_bar {
284   my %params = @_;
285
286   for my $bar ($::request->layout->get('actionbar')) {
287     $bar->add(
288       action => [
289         t8('Save'),
290         submit    => [ '#form', { action => "save_email_strings" } ],
291         accesskey => 'enter',
292       ],
293     );
294   }
295 }
296
297 sub setup_generictranslations_edit_zugferd_notes_action_bar {
298   my %params = @_;
299
300   for my $bar ($::request->layout->get('actionbar')) {
301     $bar->add(
302       action => [
303         t8('Save'),
304         submit    => [ '#form', { action => "save_zugferd_notes" } ],
305         accesskey => 'enter',
306       ],
307     );
308   }
309 }
310
311 1;