1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
42 require "bin/mozilla/common.pl";
46 our %translations = ('text' => $locale->text('Free-form text'),
47 'textfield' => $locale->text('Text field'),
48 'number' => $locale->text('Number'),
49 'date' => $locale->text('Date'),
50 'timestamp' => $locale->text('Timestamp'),
51 'bool' => $locale->text('Yes/No (Checkbox)'),
52 'select' => $locale->text('Selection'),
55 our @types = qw(text textfield number date bool select); # timestamp
65 sub list_cvar_configs {
66 $lxdebug->enter_sub();
68 $auth->assert('config');
70 $form->{module} ||= $form->{cvar_module};
72 my @configs = grep { $_->{module} eq $form->{module} } @{ CVar->get_configs() };
76 foreach my $config (@configs) {
77 $config->{type_tr} = $translations{$config->{type}};
79 foreach my $flag (split m/:/, $config->{flags}) {
80 if ($flag =~ m/(.*?)=(.*)/) {
81 $config->{"flag_${1}"} = $2;
83 $config->{"flag_${flag}"} = 1;
87 if ($previous_config) {
88 $previous_config->{next_id} = $config->{id};
89 $config->{previous_id} = $previous_config->{id};
92 $previous_config = $config;
95 $form->{title} = $locale->text('List of custom variables');
97 print $form->parse_html_template('amcvar/list_cvar_configs', { 'CONFIGS' => \@configs });
99 $lxdebug->leave_sub();
102 sub add_cvar_config {
103 $lxdebug->enter_sub();
105 $auth->assert('config');
107 $form->{module} ||= $form->{cvar_module};
110 display_cvar_config_form();
112 $lxdebug->leave_sub();
115 sub edit_cvar_config {
116 $lxdebug->enter_sub();
118 $auth->assert('config');
120 my $config = CVar->get_config('id' => $form->{id});
122 map { $form->{$_} = $config->{$_} } keys %{ $config };
125 display_cvar_config_form();
127 $lxdebug->leave_sub();
131 $lxdebug->enter_sub();
133 $auth->assert('config');
135 $form->isblank('name', $locale->text('The name is missing.'));
136 $form->isblank('description', $locale->text('The description is missing.'));
137 $form->isblank('options', $locale->text('The option field is empty.')) if ($form->{type} eq 'select');
139 if ($form->{name} !~ /^[a-z][a-z0-9_]*$/i) {
140 $form->error($locale->text('The name must only consist of letters, numbers and underscores and start with a letter.'));
143 if (($form->{type} eq 'number') && ($form->{default_value} ne '')) {
144 $form->{default_value} = $form->parse_amount(\%myconfig, $form->{default_value});
147 $form->{included_by_default} = $form->{inclusion} eq 'yes_default_on';
148 $form->{includeable} = $form->{inclusion} ne 'no';
149 $form->{flags} = join ':', map { m/^flag_(.*)/; "${1}=" . $form->{$_} } grep { m/^flag_/ } keys %{ $form };
151 CVar->save_config('module' => $form->{module},
154 $form->{MESSAGE} = $locale->text('The custom variable has been saved.');
158 $lxdebug->leave_sub();
162 $lxdebug->enter_sub();
164 CVar->delete_config('id' => $form->{id});
166 $form->{MESSAGE} = $locale->text('The custom variable has been deleted.');
170 $lxdebug->leave_sub();
173 sub display_cvar_config_form {
174 $lxdebug->enter_sub();
176 $auth->assert('config');
178 my @types = map { { 'type' => $_, 'type_tr' => $translations{$_} } } @types;
180 if (($form->{type} eq 'number') && ($form->{default_value} ne '')) {
181 $form->{default_value} = $form->format_amount(\%myconfig, $form->{default_value});
184 $form->{title} = $form->{edit} ? $locale->text("Edit custom variable") : $locale->text("Add custom variable");
187 print $form->parse_html_template("amcvar/display_cvar_config_form", { 'TYPES' => \@types });
189 $lxdebug->leave_sub();
192 sub swap_cvar_configs {
193 $lxdebug->enter_sub();
195 AM->swap_sortkeys(\%myconfig, $form, 'custom_variable_configs');
199 $lxdebug->leave_sub();