1 package GenericTranslations;
8 $main::lxdebug->enter_sub();
13 Common::check_params(\%params, qw(translation_type));
15 my $myconfig = \%main::myconfig;
16 my $form = $main::form;
18 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
22 my @values = ($params{translation_type});
23 my @where = ('gt.translation_type = ?');
25 if ($params{translation_id}) {
26 push @values, conv_i($params{translation_id});
27 push @where, 'gt.translation_id = ?';
30 push @where, 'gt.translation_id IS NULL';
33 if ($params{language_id}) {
34 push @values, conv_i($params{language_id});
35 push @where, $params{allow_fallback} ? '(gt.language_id IS NULL) OR (gt.language_id = ?)' : 'gt.language_id = ?';
38 push @where, 'gt.language_id IS NULL';
41 my $query = qq|SELECT gt.translation
42 FROM generic_translations gt
44 WHERE | . join(' AND ', map { "($_)" } @where) . qq|
45 ORDER BY gt.language_id ASC|;
47 my ($translation) = selectfirst_array_query($form, $dbh, $query, @values);
48 $translation ||= $params{default};
50 $main::lxdebug->leave_sub();
56 $main::lxdebug->enter_sub();
61 my $myconfig = \%main::myconfig;
62 my $form = $main::form;
64 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
69 if ($params{translation_type}) {
70 push @values, $params{translation_type};
71 push @where, 'translation_type = ?';
74 if ($params{translation_id}) {
75 push @values, conv_i($params{translation_id});
76 push @where, 'translation_id = ?';
79 my $where_s = scalar(@where) ? 'WHERE ' . join(' AND ', map { "($_)" } @where) : '';
81 my $query = qq|SELECT id, language_id, translation_type, translation_id, translation
82 FROM generic_translations
85 my $results = selectall_hashref_query($form, $dbh, $query, @values);
87 $main::lxdebug->leave_sub();
93 $main::lxdebug->enter_sub();
98 Common::check_params(\%params, qw(translation_type));
100 my $myconfig = \%main::myconfig;
101 my $form = $main::form;
103 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
105 $params{translation} =~ s/^\s+//;
106 $params{translation} =~ s/\s+$//;
108 my @v_insert = (conv_i($params{language_id}), $params{translation_type}, conv_i($params{translation_id}), $params{translation});
109 my @v_seldel = ($params{translation_type});
110 my @w_seldel = ('translation_type = ?');
112 foreach (qw(language_id translation_id)) {
114 push @v_seldel, conv_i($params{$_});
115 push @w_seldel, "$_ = ?";
117 push @w_seldel, "$_ IS NULL";
121 my $q_lookup = qq|SELECT id
122 FROM generic_translations
123 WHERE | . join(' AND ', map { "($_)" } @w_seldel);
124 my $q_delete = qq|DELETE FROM generic_translations
125 WHERE | . join(' AND ', map { "($_)" } @w_seldel);
126 my $q_update = qq|UPDATE generic_translations
129 my $q_insert = qq|INSERT INTO generic_translations (language_id, translation_type, translation_id, translation)
130 VALUES (?, ?, ?, ?)|;
132 my ($id) = selectfirst_array_query($form, $dbh, $q_lookup, @v_seldel);
134 if ($id && !$params{translation}) {
135 do_query($form, $dbh, $q_delete, @v_seldel);
137 do_query($form, $dbh, $q_update, $params{translation}, $id);
138 } elsif ($params{translation}) {
139 do_query($form, $dbh, $q_insert, @v_insert);
142 $dbh->commit() unless ($params{dbh});
144 $main::lxdebug->leave_sub();