$config->{precision} = $1 if ($config->{options} =~ m/precision=(\d+)/i);
}
+
+ $self->_unpack_flags($config);
}
$main::lxdebug->leave_sub();
my $config = selectfirst_hashref_query($form, $dbh, $query, conv_i($params{id})) || { };
+ $self->_unpack_flags($config);
+
$main::lxdebug->leave_sub();
return $config;
}
+sub _unpack_flags {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my $config = shift;
+
+ foreach my $flag (split m/:/, $config->{flags}) {
+ if ($flag =~ m/(.*?)=(.*)/) {
+ $config->{"flag_${1}"} = $2;
+ } else {
+ $config->{"flag_${flag}"} = 1;
+ }
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
sub save_config {
$main::lxdebug->enter_sub();
my $h_id = prepare_query($form, $dbh, $q_id);
my $q_new =
- qq|INSERT INTO custom_variable_configs (name, description, type, default_value, options, searchable, includeable, included_by_default, module, id, sortkey)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
+ qq|INSERT INTO custom_variable_configs (name, description, type, default_value, options, searchable, includeable, included_by_default, module, flags, id, sortkey)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
(SELECT COALESCE(MAX(sortkey) + 1, 1) FROM custom_variable_configs))|;
my $h_new = prepare_query($form, $dbh, $q_new);
type = ?, default_value = ?,
options = ?, searchable = ?,
includeable = ?, included_by_default = ?,
- module = ?
+ module = ?, flags = ?
WHERE id = ?|;
my $h_update = prepare_query($form, $dbh, $q_update);
do_statement($form, $h_actual, $q_actual, @{$config}{qw(name description type default_value options)},
$config->{searchable} ? 't' : 'f', $config->{includeable} ? 't' : 'f', $config->{included_by_default} ? 't' : 'f',
- $params{module}, conv_i($config->{id}));
+ $params{module}, $config->{flags}, conv_i($config->{id}));
}
$h_id->finish();
qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value
FROM custom_variables
WHERE (config_id = ?) AND (trans_id = ?)|;
+ $q_var .= qq| AND (sub_module = ?)| if $params{sub_module};
my $h_var = prepare_query($form, $dbh, $q_var);
my $custom_variables = selectall_hashref_query($form, $dbh, $q_cfg, $params{module});
my $act_var;
if ($params{trans_id}) {
- do_statement($form, $h_var, $q_var, conv_i($cvar->{id}), conv_i($params{trans_id}));
+ my @values = (conv_i($cvar->{id}), conv_i($params{trans_id}));
+ push @values, $params{sub_module} if $params{sub_module};
+
+ do_statement($form, $h_var, $q_var, @values);
$act_var = $h_var->fetchrow_hashref();
}
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
- my @configs = grep { $_->{module} eq $params{module} } @{ CVar->get_configs() };
+ my @configs = $params{configs} ? @{ $params{configs} } : grep { $_->{module} eq $params{module} } @{ CVar->get_configs() };
my $query =
qq|DELETE FROM custom_variables
AND (config_id IN (SELECT DISTINCT id
FROM custom_variable_configs
WHERE module = ?))|;
- do_query($form, $dbh, $query, conv_i($params{trans_id}), $params{module});
+ my @values = (conv_i($params{trans_id}), $params{module});
+
+ if ($params{sub_module}) {
+ $query .= qq| AND (sub_module = ?)|;
+ push @values, $params{sub_module};
+ }
+
+ do_query($form, $dbh, $query, @values);
$query =
- qq|INSERT INTO custom_variables (config_id, trans_id, bool_value, timestamp_value, text_value, number_value)
- VALUES (?, ?, ?, ?, ?, ?)|;
+ qq|INSERT INTO custom_variables (config_id, sub_module, trans_id, bool_value, timestamp_value, text_value, number_value)
+ VALUES (?, ?, ?, ?, ?, ?, ?)|;
my $sth = prepare_query($form, $dbh, $query);
foreach my $config (@configs) {
- my @values = (conv_i($config->{id}), conv_i($params{trans_id}));
+ my @values = (conv_i($config->{id}), "$params{sub_module}", conv_i($params{trans_id}));
- my $value = $params{variables}->{"cvar_$config->{name}"};
+ my $value = $params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}"};
if (($config->{type} eq 'text') || ($config->{type} eq 'textfield') || ($config->{type} eq 'select')) {
push @values, undef, undef, $value, undef;
my $myconfig = \%main::myconfig;
my $form = $main::form;
+ my %options = ( name_prefix => "$params{name_prefix}",
+ name_postfix => "$params{name_postfix}",
+ hide_non_editable => $params{hide_non_editable},
+ );
+
foreach my $var (@{ $params{variables} }) {
- $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { 'var' => $var });
+ $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { 'var' => $var, %options });
}
$main::lxdebug->leave_sub();
}
if (@sub_where) {
+ push @sub_where, qq|cvar.sub_module = ?|;
+ push @sub_values, "$params{sub_module}";
+
push @where,
qq|$not EXISTS(
SELECT cvar.id
my $query =
qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value, config_id
FROM custom_variables
- WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|)) AND (trans_id = ?)|;
+ WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|))
+ AND (trans_id = ?)
+ AND (sub_module = ?)|;
my $sth = prepare_query($form, $dbh, $query);
foreach my $row (@{ $params{data} }) {
- do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}));
+ do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), "$params{sub_module}");
while (my $ref = $sth->fetchrow_hashref()) {
my $cfg = $cfg_map{$ref->{config_id}};
foreach my $config (@{ $configs }) {
my $name = "$params{prefix}cvar_$config->{name}";
- $main::lxdebug->message(0, "name $name");
+
if ($config->{type} eq 'date') {
push @{ $date_fields }, $name;