3 use SL::GenericTranslations;
 
   4 use SL::Locale::String qw(t8);
 
   9 # preset_text_$formname will generate a input textarea
 
  10 # and will be preset in $form email dialog if the form name matches
 
  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'),
 
  26   $main::lxdebug->enter_sub();
 
  28   $main::auth->assert('config');
 
  30   my $form     = $main::form;
 
  31   my $locale   = $main::locale;
 
  33   $form->get_lists('languages' => 'LANGUAGES');
 
  35   my $translation_list = GenericTranslations->list();
 
  36   my %translations     = ();
 
  38   my @types            = qw(male female);
 
  40   foreach my $translation (@{ $translation_list }) {
 
  41     $translation->{language_id}                                                          ||= 'default';
 
  42     $translations{$translation->{language_id} . '::' . $translation->{translation_type}}   = $translation;
 
  45   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
 
  47   foreach my $language (@{ $form->{LANGUAGES} }) {
 
  48     foreach my $type (@types) {
 
  49       $language->{$type} = { };
 
  50       my $translation    = $translations{"$language->{id}::greetings::${type}"} || { };
 
  51       $language->{$type} = $translation->{translation};
 
  55   setup_generictranslations_edit_greetings_action_bar();
 
  57   $form->{title} = $locale->text('Edit greetings');
 
  59   print $form->parse_html_template('generictranslations/edit_greetings');
 
  61   $main::lxdebug->leave_sub();
 
  65   $main::lxdebug->enter_sub();
 
  67   $main::auth->assert('config');
 
  69   my $form     = $main::form;
 
  70   my $locale   = $main::locale;
 
  72   $form->get_lists('languages' => 'LANGUAGES');
 
  74   unshift @{ $form->{LANGUAGES} }, { };
 
  76   my @types  = qw(male female);
 
  78   foreach my $language (@{ $form->{LANGUAGES} }) {
 
  79     foreach my $type (@types) {
 
  80       GenericTranslations->save('translation_type' => "greetings::${type}",
 
  81                                 'translation_id'   => undef,
 
  82                                 'language_id'      => $language->{id},
 
  83                                 'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__${type}"},);
 
  87   $form->{message} = $locale->text('The greetings have been saved.');
 
  91   $main::lxdebug->leave_sub();
 
  94 sub edit_sepa_strings {
 
  95   $main::lxdebug->enter_sub();
 
  97   $main::auth->assert('config');
 
  99   my $form     = $main::form;
 
 100   my $locale   = $main::locale;
 
 102   $form->get_lists('languages' => 'LANGUAGES');
 
 104   my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
 
 105   my %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
 
 107   my $translation_list_vc = GenericTranslations->list(translation_type => 'sepa_remittance_vc_no_pfx');
 
 108   my %translations_vc     =  map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list_vc };
 
 110   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
 
 112   foreach my $language (@{ $form->{LANGUAGES} }) {
 
 113     $language->{translation}    = $translations{$language->{id}};
 
 114     $language->{translation_vc} = $translations_vc{$language->{id}};
 
 117   setup_generictranslations_edit_sepa_strings_action_bar();
 
 119   $form->{title} = $locale->text('Edit SEPA strings');
 
 121   print $form->parse_html_template('generictranslations/edit_sepa_strings');
 
 123   $main::lxdebug->leave_sub();
 
 126 sub save_sepa_strings {
 
 127   $main::lxdebug->enter_sub();
 
 129   $main::auth->assert('config');
 
 131   my $form     = $main::form;
 
 132   my $locale   = $main::locale;
 
 134   $form->get_lists('languages' => 'LANGUAGES');
 
 136   unshift @{ $form->{LANGUAGES} }, { };
 
 138   foreach my $language (@{ $form->{LANGUAGES} }) {
 
 139     GenericTranslations->save('translation_type' => 'sepa_remittance_info_pfx',
 
 140                               'translation_id'   => undef,
 
 141                               'language_id'      => $language->{id},
 
 142                               'translation'      => $form->{"translation__" . ($language->{id} || 'default')},);
 
 143     GenericTranslations->save('translation_type' => 'sepa_remittance_vc_no_pfx',
 
 144                               'translation_id'   => undef,
 
 145                               'language_id'      => $language->{id},
 
 146                               'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__vc" },);
 
 149   $form->{message} = $locale->text('The SEPA strings have been saved.');
 
 153   $main::lxdebug->leave_sub();
 
 155 sub edit_email_strings {
 
 156   $main::lxdebug->enter_sub();
 
 158   $main::auth->assert('config');
 
 160   my $form     = $main::form;
 
 161   my $locale   = $main::locale;
 
 163   $form->get_lists('languages' => 'LANGUAGES');
 
 164   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
 
 166   my (%translations, $translation_list);
 
 167   foreach (keys %mail_strings)  {
 
 168     $translation_list = GenericTranslations->list(translation_type => $_);
 
 169     %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
 
 171     foreach my $language (@{ $form->{LANGUAGES} }) {
 
 172       $language->{$_} = $translations{$language->{id}};
 
 175   setup_generictranslations_edit_email_strings_action_bar();
 
 177   $form->{title} = $locale->text('Edit preset email strings');
 
 179   print $form->parse_html_template('generictranslations/edit_email_strings',{ 'MAIL_STRINGS' => \%mail_strings });
 
 181   $main::lxdebug->leave_sub();
 
 184 sub save_email_strings {
 
 185   $main::lxdebug->enter_sub();
 
 187   $main::auth->assert('config');
 
 189   my $form     = $main::form;
 
 190   my $locale   = $main::locale;
 
 192   $form->get_lists('languages' => 'LANGUAGES');
 
 194   unshift @{ $form->{LANGUAGES} }, { };
 
 195   foreach my $language (@{ $form->{LANGUAGES} }) {
 
 196     foreach (keys %mail_strings)  {
 
 197       GenericTranslations->save('translation_type' => $_,
 
 198                                 'translation_id'   => undef,
 
 199                                 'language_id'      => $language->{id},
 
 200                                 'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__" . $_},
 
 204   $form->{message} = $locale->text('The Mail strings have been saved.');
 
 206   edit_email_strings();
 
 208   $main::lxdebug->leave_sub();
 
 211 sub setup_generictranslations_edit_greetings_action_bar {
 
 214   for my $bar ($::request->layout->get('actionbar')) {
 
 218         submit    => [ '#form', { action => "save_greetings" } ],
 
 219         accesskey => 'enter',
 
 225 sub setup_generictranslations_edit_sepa_strings_action_bar {
 
 228   for my $bar ($::request->layout->get('actionbar')) {
 
 232         submit    => [ '#form', { action => "save_sepa_strings" } ],
 
 233         accesskey => 'enter',
 
 238 sub setup_generictranslations_edit_email_strings_action_bar {
 
 241   for my $bar ($::request->layout->get('actionbar')) {
 
 245         submit    => [ '#form', { action => "save_email_strings" } ],
 
 246         accesskey => 'enter',