1 package GenericTranslations;
6 $main::lxdebug->enter_sub();
11 Common::check_params(\%params, qw(translation_type));
13 my $myconfig = \%main::myconfig;
14 my $form = $main::form;
16 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
20 my @values = ($params{translation_type});
21 my @where = ('gt.translation_type = ?');
23 if ($params{translation_id}) {
24 push @values, conv_i($params{translation_id});
25 push @where, 'gt.translation_id = ?';
28 push @where, 'gt.translation_id IS NULL';
31 if ($params{language_id}) {
32 push @values, conv_i($params{language_id});
33 push @where, $params{allow_fallback} ? '(gt.language_id IS NULL) OR (gt.language_id = ?)' : 'gt.language_id = ?';
36 push @where, 'gt.language_id IS NULL';
39 my $query = qq|SELECT gt.translation
40 FROM generic_translations gt
42 WHERE | . join(' AND ', map { "($_)" } @where) . qq|
43 ORDER BY gt.language_id ASC|;
45 my ($translation) = selectfirst_array_query($form, $dbh, $query, @values);
46 $translation ||= $params{default};
48 $main::lxdebug->leave_sub();
54 $main::lxdebug->enter_sub();
59 my $myconfig = \%main::myconfig;
60 my $form = $main::form;
62 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
67 if ($params{translation_type}) {
68 push @values, $params{translation_type};
69 push @where, 'translation_type = ?';
72 if ($params{translation_id}) {
73 push @values, conv_i($params{translation_id});
74 push @where, 'translation_id = ?';
77 my $where_s = scalar(@where) ? 'WHERE ' . join(' AND ', map { "($_)" } @where) : '';
79 my $query = qq|SELECT id, language_id, translation_type, translation_id, translation
80 FROM generic_translations
83 my $results = selectall_hashref_query($form, $dbh, $query, @values);
85 $main::lxdebug->leave_sub();
91 $main::lxdebug->enter_sub();
96 Common::check_params(\%params, qw(translation_type));
98 my $myconfig = \%main::myconfig;
99 my $form = $main::form;
101 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
103 $params{translation} =~ s/^\s+//;
104 $params{translation} =~ s/\s+$//;
106 my @v_insert = (conv_i($params{language_id}), $params{translation_type}, conv_i($params{translation_id}), $params{translation});
107 my @v_seldel = ($params{translation_type});
108 my @w_seldel = ('translation_type = ?');
110 foreach (qw(language_id translation_id)) {
112 push @v_seldel, conv_i($params{$_});
113 push @w_seldel, "$_ = ?";
115 push @w_seldel, "$_ IS NULL";
119 my $q_lookup = qq|SELECT id
120 FROM generic_translations
121 WHERE | . join(' AND ', map { "($_)" } @w_seldel);
122 my $q_delete = qq|DELETE FROM generic_translations
123 WHERE | . join(' AND ', map { "($_)" } @w_seldel);
124 my $q_update = qq|UPDATE generic_translations
127 my $q_insert = qq|INSERT INTO generic_translations (language_id, translation_type, translation_id, translation)
128 VALUES (?, ?, ?, ?)|;
130 my ($id) = selectfirst_array_query($form, $dbh, $q_lookup, @v_seldel);
132 if ($id && !$params{translation}) {
133 do_query($form, $dbh, $q_delete, @v_seldel);
135 do_query($form, $dbh, $q_update, $params{translation}, $id);
136 } elsif ($params{translation}) {
137 do_query($form, $dbh, $q_insert, @v_insert);
140 $dbh->commit() unless ($params{dbh});
142 $main::lxdebug->leave_sub();