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() };
77 $_->{type_tr} = $translations{$_->{type}};
79 if ($previous_config) {
80 $previous_config->{next_id} = $_->{id};
81 $_->{previous_id} = $previous_config->{id};
84 $previous_config = $_;
87 $form->{title} = $locale->text('List of custom variables');
89 print $form->parse_html_template('amcvar/list_cvar_configs', { 'CONFIGS' => \@configs });
91 $lxdebug->leave_sub();
95 $lxdebug->enter_sub();
97 $auth->assert('config');
99 $form->{module} ||= $form->{cvar_module};
102 display_cvar_config_form();
104 $lxdebug->leave_sub();
107 sub edit_cvar_config {
108 $lxdebug->enter_sub();
110 $auth->assert('config');
112 my $config = CVar->get_config('id' => $form->{id});
114 map { $form->{$_} = $config->{$_} } keys %{ $config };
117 display_cvar_config_form();
119 $lxdebug->leave_sub();
123 $lxdebug->enter_sub();
125 $auth->assert('config');
127 $form->isblank('name', $locale->text('The name is missing.'));
128 $form->isblank('description', $locale->text('The description is missing.'));
129 $form->isblank('options', $locale->text('The option field is empty.')) if ($form->{type} eq 'select');
131 if ($form->{name} !~ /^[a-z][a-z0-9_]*$/i) {
132 $form->error($locale->text('The name must only consist of letters, numbers and underscores and start with a letter.'));
135 if (($form->{type} eq 'number') && ($form->{default_value} ne '')) {
136 $form->{default_value} = $form->parse_amount(\%myconfig, $form->{default_value});
139 $form->{included_by_default} = $form->{inclusion} eq 'yes_default_on';
140 $form->{includeable} = $form->{inclusion} ne 'no';
142 CVar->save_config('module' => $form->{module},
145 $form->{MESSAGE} = $locale->text('The custom variable has been saved.');
149 $lxdebug->leave_sub();
153 $lxdebug->enter_sub();
155 CVar->delete_config('id' => $form->{id});
157 $form->{MESSAGE} = $locale->text('The custom variable has been deleted.');
161 $lxdebug->leave_sub();
164 sub display_cvar_config_form {
165 $lxdebug->enter_sub();
167 $auth->assert('config');
169 my @types = map { { 'type' => $_, 'type_tr' => $translations{$_} } } @types;
171 if (($form->{type} eq 'number') && ($form->{default_value} ne '')) {
172 $form->{default_value} = $form->format_amount(\%myconfig, $form->{default_value});
175 $form->{title} = $form->{edit} ? $locale->text("Edit custom variable") : $locale->text("Add custom variable");
178 print $form->parse_html_template("amcvar/display_cvar_config_form", { 'TYPES' => \@types });
180 $lxdebug->leave_sub();
183 sub swap_cvar_configs {
184 $lxdebug->enter_sub();
186 AM->swap_sortkeys(\%myconfig, $form, 'custom_variable_configs');
190 $lxdebug->leave_sub();