CVar->get_configs cached jetzt so, wie es io.pl eh schon tut.
[kivitendo-erp.git] / SL / CVar.pm
1 package CVar;
2
3 use strict;
4
5 use List::Util qw(first);
6 use Data::Dumper;
7
8 use SL::DBUtils;
9 use SL::MoreCommon qw(listify);
10
11 sub get_configs {
12   $main::lxdebug->enter_sub();
13
14   my $self     = shift;
15   my %params   = @_;
16
17   my $myconfig = \%main::myconfig;
18   my $form     = $main::form;
19
20   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
21
22   my ($where, @values);
23   if ($params{module}) {
24     $where = 'WHERE module = ?';
25     push @values, $params{module};
26   }
27
28   my $query    = <<SQL;
29     SELECT *, date_trunc('seconds', localtimestamp) AS current_timestamp
30     FROM custom_variable_configs $where ORDER BY sortkey
31 SQL
32
33   if (!$::form->{CVAR_CONFIGS}->{$params{module}}) {
34     my $configs  = selectall_hashref_query($form, $dbh, $query, @values);
35
36     foreach my $config (@{ $configs }) {
37       if ($config->{type} eq 'select') {
38         $config->{OPTIONS} = [ map { { 'value' => $_ } } split(m/\#\#/, $config->{options}) ];
39
40       } elsif ($config->{type} eq 'number') {
41         $config->{precision} = $1 if ($config->{options} =~ m/precision=(\d+)/i);
42
43       }
44
45       $self->_unpack_flags($config);
46     }
47     $::form->{CVAR_CONFIGS}->{$params{module}} = $configs;
48   }
49
50   $main::lxdebug->leave_sub();
51
52   return $::form->{CVAR_CONFIGS}->{$params{module}};
53 }
54
55 sub get_config {
56   $main::lxdebug->enter_sub();
57
58   my $self     = shift;
59   my %params   = @_;
60
61   Common::check_params(\%params, qw(id));
62
63   my $myconfig = \%main::myconfig;
64   my $form     = $main::form;
65
66   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
67
68   my $query    = qq|SELECT * FROM custom_variable_configs WHERE id = ?|;
69
70   my $config   = selectfirst_hashref_query($form, $dbh, $query, conv_i($params{id})) || { };
71
72   $self->_unpack_flags($config);
73
74   $main::lxdebug->leave_sub();
75
76   return $config;
77 }
78
79 sub _unpack_flags {
80   $main::lxdebug->enter_sub();
81
82   my $self   = shift;
83   my $config = shift;
84
85   foreach my $flag (split m/:/, $config->{flags}) {
86     if ($flag =~ m/(.*?)=(.*)/) {
87       $config->{"flag_${1}"}    = $2;
88     } else {
89       $config->{"flag_${flag}"} = 1;
90     }
91   }
92
93   $main::lxdebug->leave_sub();
94 }
95
96 sub save_config {
97   $main::lxdebug->enter_sub();
98
99   my $self     = shift;
100   my %params   = @_;
101
102   Common::check_params(\%params, qw(module config));
103
104   my $myconfig = \%main::myconfig;
105   my $form     = $main::form;
106
107   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
108
109   my $q_id     = qq|SELECT nextval('custom_variable_configs_id')|;
110   my $h_id     = prepare_query($form, $dbh, $q_id);
111
112   my $q_new    =
113     qq|INSERT INTO custom_variable_configs (name, description, type, default_value, options, searchable, includeable, included_by_default, module, flags, id, sortkey)
114        VALUES                              (?,    ?,           ?,    ?,             ?,       ?,          ?,           ?,                   ?,      ?,     ?,
115          (SELECT COALESCE(MAX(sortkey) + 1, 1) FROM custom_variable_configs))|;
116   my $h_new    = prepare_query($form, $dbh, $q_new);
117
118   my $q_update =
119     qq|UPDATE custom_variable_configs SET
120          name        = ?, description         = ?,
121          type        = ?, default_value       = ?,
122          options     = ?, searchable          = ?,
123          includeable = ?, included_by_default = ?,
124          module      = ?, flags               = ?
125        WHERE id  = ?|;
126   my $h_update = prepare_query($form, $dbh, $q_update);
127
128   my @configs;
129   if ('ARRAY' eq ref $params{config}) {
130     @configs = @{ $params{config} };
131   } else {
132     @configs = ($params{config});
133   }
134
135   foreach my $config (@configs) {
136     my ($h_actual, $q_actual);
137
138     if (!$config->{id}) {
139       do_statement($form, $h_id, $q_id);
140       ($config->{id}) = $h_id->fetchrow_array();
141
142       $h_actual       = $h_new;
143       $q_actual       = $q_new;
144
145     } else {
146       $h_actual       = $h_update;
147       $q_actual       = $q_update;
148     }
149
150     do_statement($form, $h_actual, $q_actual, @{$config}{qw(name description type default_value options)},
151                  $config->{searchable} ? 't' : 'f', $config->{includeable} ? 't' : 'f', $config->{included_by_default} ? 't' : 'f',
152                  $params{module}, $config->{flags}, conv_i($config->{id}));
153   }
154
155   $h_id->finish();
156   $h_new->finish();
157   $h_update->finish();
158
159   $dbh->commit();
160
161   $main::lxdebug->leave_sub();
162 }
163
164 sub delete_config {
165   $main::lxdebug->enter_sub();
166
167   my $self     = shift;
168   my %params   = @_;
169
170   Common::check_params(\%params, qw(id));
171
172   my $myconfig = \%main::myconfig;
173   my $form     = $main::form;
174
175   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
176
177   do_query($form, $dbh, qq|DELETE FROM custom_variables        WHERE config_id = ?|, conv_i($params{id}));
178   do_query($form, $dbh, qq|DELETE FROM custom_variable_configs WHERE id        = ?|, conv_i($params{id}));
179
180   $dbh->commit();
181
182   $main::lxdebug->leave_sub();
183 }
184
185 sub get_custom_variables {
186   $main::lxdebug->enter_sub();
187
188   my $self     = shift;
189   my %params   = @_;
190
191   Common::check_params(\%params, qw(module));
192
193   my $myconfig = \%main::myconfig;
194   my $form     = $main::form;
195
196   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
197
198   my $trans_id = $params{trans_id} ? 'OR (v.trans_id = ?) ' : '';
199
200   my $q_var    =
201     qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value
202        FROM custom_variables
203        WHERE (config_id = ?) AND (trans_id = ?)|;
204   $q_var      .= qq| AND (sub_module = ?)| if $params{sub_module};
205   my $h_var    = prepare_query($form, $dbh, $q_var);
206
207   my $custom_variables = $self->get_configs(module => $params{module});
208
209   foreach my $cvar (@{ $custom_variables }) {
210     if ($cvar->{type} eq 'textfield') {
211       $cvar->{width}  = 30;
212       $cvar->{height} =  5;
213
214       $cvar->{width}  = $1 if ($cvar->{options} =~ m/width=(\d+)/i);
215       $cvar->{height} = $1 if ($cvar->{options} =~ m/height=(\d+)/i);
216
217     } elsif ($cvar->{type} eq 'text') {
218       $cvar->{maxlength} = $1 if ($cvar->{options} =~ m/maxlength=(\d+)/i);
219
220     } elsif ($cvar->{type} eq 'number') {
221       $cvar->{precision} = $1 if ($cvar->{options} =~ m/precision=(\d+)/i);
222
223     } elsif ($cvar->{type} eq 'select') {
224       $cvar->{OPTIONS} = [ map { { 'value' => $_ } } split(m/\#\#/, $cvar->{options}) ];
225     }
226
227     my $act_var;
228     if ($params{trans_id}) {
229       my @values = (conv_i($cvar->{id}), conv_i($params{trans_id}));
230       push @values, $params{sub_module} if $params{sub_module};
231
232       do_statement($form, $h_var, $q_var, @values);
233       $act_var = $h_var->fetchrow_hashref();
234
235       $act_var->{valid} = $self->get_custom_variables_validity(config_id => $cvar->{id}, trans_id => $params{trans_id});
236     }
237
238     if ($act_var) {
239       $cvar->{value} = $cvar->{type} eq 'date'      ? $act_var->{date_value}
240                      : $cvar->{type} eq 'timestamp' ? $act_var->{timestamp_value}
241                      : $cvar->{type} eq 'number'    ? $act_var->{number_value}
242                      : $cvar->{type} eq 'bool'      ? $act_var->{bool_value}
243                      :                                $act_var->{text_value};
244       $cvar->{valid} = $act_var->{valid};
245     } else {
246       $cvar->{valid}  =  1;
247
248       if ($cvar->{type} eq 'date') {
249         if ($cvar->{default_value} eq 'NOW') {
250           $cvar->{value} = $cvar->{current_date};
251         } else {
252           $cvar->{value} = $cvar->{default_value};
253         }
254
255       } elsif ($cvar->{type} eq 'timestamp') {
256         if ($cvar->{default_value} eq 'NOW') {
257           $cvar->{value} = $cvar->{current_timestamp};
258         } else {
259           $cvar->{value} = $cvar->{default_value};
260         }
261
262       } elsif ($cvar->{type} eq 'bool') {
263         $cvar->{value} = $cvar->{default_value} * 1;
264
265       } elsif ($cvar->{type} eq 'number') {
266         $cvar->{value} = $cvar->{default_value} * 1 if ($cvar->{default_value} ne '');
267
268       } else {
269         $cvar->{value} = $cvar->{default_value};
270       }
271     }
272
273     if ($cvar->{type} eq 'number') {
274       $cvar->{value} = $form->format_amount($myconfig, $cvar->{value} * 1, $cvar->{precision});
275     }
276   }
277
278   $h_var->finish();
279
280   $main::lxdebug->leave_sub();
281
282   return $custom_variables;
283 }
284
285 sub save_custom_variables {
286   $main::lxdebug->enter_sub();
287
288   my $self     = shift;
289   my %params   = @_;
290
291   Common::check_params(\%params, qw(module trans_id variables));
292
293   my $myconfig = \%main::myconfig;
294   my $form     = $main::form;
295
296   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
297
298   my @configs  = $params{configs} ? @{ $params{configs} } : grep { $_->{module} eq $params{module} } @{ CVar->get_configs() };
299
300   my $query    =
301     qq|DELETE FROM custom_variables
302        WHERE (trans_id  = ?)
303          AND (config_id IN (SELECT DISTINCT id
304                             FROM custom_variable_configs
305                             WHERE module = ?))|;
306   my @values   = (conv_i($params{trans_id}), $params{module});
307
308   if ($params{sub_module}) {
309     $query .= qq| AND (sub_module = ?)|;
310     push @values, $params{sub_module};
311   }
312
313   do_query($form, $dbh, $query, @values);
314
315   $query  =
316     qq|INSERT INTO custom_variables (config_id, sub_module, trans_id, bool_value, timestamp_value, text_value, number_value)
317        VALUES                       (?,         ?,          ?,        ?,          ?,               ?,          ?)|;
318   my $sth = prepare_query($form, $dbh, $query);
319
320   foreach my $config (@configs) {
321     my @values = (conv_i($config->{id}), "$params{sub_module}", conv_i($params{trans_id}));
322
323     my $value  = $params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}"};
324
325     if (($config->{type} eq 'text') || ($config->{type} eq 'textfield') || ($config->{type} eq 'select')) {
326       push @values, undef, undef, $value, undef;
327
328     } elsif (($config->{type} eq 'date') || ($config->{type} eq 'timestamp')) {
329       push @values, undef, conv_date($value), undef, undef;
330
331     } elsif ($config->{type} eq 'number') {
332       push @values, undef, undef, undef, conv_i($form->parse_amount($myconfig, $value));
333
334     } elsif ($config->{type} eq 'bool') {
335       push @values, $value ? 't' : 'f', undef, undef, undef;
336     }
337
338     do_statement($form, $sth, $query, @values);
339
340     unless ($params{always_valid}) {
341       $self->save_custom_variables_validity(trans_id => $params{trans_id}, config_id => $config->{id},
342         validity => ($params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid"} ? 1 : 0)
343       );
344     };
345   }
346
347   $sth->finish();
348
349   $dbh->commit();
350
351   $main::lxdebug->leave_sub();
352 }
353
354 sub render_inputs {
355   $main::lxdebug->enter_sub(2);
356
357   my $self     = shift;
358   my %params   = @_;
359
360   Common::check_params(\%params, qw(variables));
361
362   my $myconfig = \%main::myconfig;
363   my $form     = $main::form;
364
365   my %options  = ( name_prefix       => "$params{name_prefix}",
366                    name_postfix      => "$params{name_postfix}",
367                    hide_non_editable => $params{hide_non_editable},
368                    show_disabled_message => $params{show_disabled_message},
369                  );
370
371   foreach my $var (@{ $params{variables} }) {
372     $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs',     { var => $var, %options });
373     $var->{VALID_BOX} = $form->parse_html_template('amcvar/render_checkboxes', { var => $var, %options });
374   }
375
376   $main::lxdebug->leave_sub(2);
377 }
378
379 sub render_search_options {
380   $main::lxdebug->enter_sub();
381
382   my $self     = shift;
383   my %params   = @_;
384
385   Common::check_params(\%params, qw(variables));
386
387   my $myconfig = \%main::myconfig;
388   my $form     = $main::form;
389
390   $params{hidden_cvar_filters} = $myconfig->{hide_cvar_search_options};
391
392   $params{include_prefix}   = 'l_' unless defined($params{include_prefix});
393   $params{include_value}  ||= '1';
394
395   my $filter  = $form->parse_html_template('amcvar/search_filter',  \%params);
396   my $include = $form->parse_html_template('amcvar/search_include', \%params);
397
398   $main::lxdebug->leave_sub();
399
400   return ($filter, $include);
401 }
402
403 sub build_filter_query {
404   $main::lxdebug->enter_sub();
405
406   my $self     = shift;
407   my %params   = @_;
408
409   Common::check_params(\%params, qw(module trans_id_field filter));
410
411   my $myconfig = \%main::myconfig;
412   my $form     = $main::form;
413
414   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
415
416   my $configs  = $self->get_configs(%params);
417
418   my (@where, @values);
419
420   foreach my $config (@{ $configs }) {
421     next unless ($config->{searchable});
422
423     my $name = "cvar_$config->{name}";
424
425     my (@sub_values, @sub_where, $not);
426
427     if (($config->{type} eq 'text') || ($config->{type} eq 'textfield')) {
428       next unless ($params{filter}->{$name});
429
430       push @sub_where,  qq|cvar.text_value ILIKE ?|;
431       push @sub_values, '%' . $params{filter}->{$name} . '%'
432
433     } elsif ($config->{type} eq 'select') {
434       next unless ($params{filter}->{$name});
435
436       push @sub_where,  qq|cvar.text_value = ?|;
437       push @sub_values, $params{filter}->{$name};
438
439     } elsif (($config->{type} eq 'date') || ($config->{type} eq 'timestamp')) {
440       my $name_from = "${name}_from";
441       my $name_to   = "${name}_to";
442
443       if ($params{filter}->{$name_from}) {
444         push @sub_where,  qq|cvar.timestamp_value >= ?|;
445         push @sub_values, conv_date($params{filter}->{$name_from});
446       }
447
448       if ($params{filter}->{$name_to}) {
449         push @sub_where,  qq|cvar.timestamp_value <= ?|;
450         push @sub_values, conv_date($params{filter}->{$name_to});
451       }
452
453     } elsif ($config->{type} eq 'number') {
454       next if ($params{filter}->{$name} eq '');
455
456       my $f_op = $params{filter}->{"${name}_qtyop"};
457
458       my $op;
459       if ($f_op eq '==') {
460         $op  = '=';
461
462       } elsif ($f_op eq '=/=') {
463         $not = 'NOT';
464         $op  = '<>';
465
466       } elsif ($f_op eq '<') {
467         $not = 'NOT';
468         $op  = '>=';
469
470       } elsif ($f_op eq '<=') {
471         $not = 'NOT';
472         $op  = '>';
473
474       } elsif (($f_op eq '>') || ($f_op eq '>=')) {
475         $op  = $f_op;
476
477       } else {
478         $op  = '=';
479       }
480
481       push @sub_where,  qq|cvar.number_value $op ?|;
482       push @sub_values, $form->parse_amount($myconfig, $params{filter}->{$name});
483
484     } elsif ($config->{type} eq 'bool') {
485       next unless ($params{filter}->{$name});
486
487       $not = 'NOT' if ($params{filter}->{$name} eq 'no');
488       push @sub_where,  qq|COALESCE(cvar.bool_value, false) = TRUE|;
489     }
490
491     if (@sub_where) {
492       add_token(\@sub_where, \@sub_values, col => 'cvar.sub_module', val => $params{sub_module} || '');
493
494       push @where,
495         qq|$not EXISTS(
496              SELECT cvar.id
497              FROM custom_variables cvar
498              LEFT JOIN custom_variable_configs cvarcfg ON (cvar.config_id = cvarcfg.id)
499              WHERE (cvarcfg.module = ?)
500                AND (cvarcfg.id     = ?)
501                AND (cvar.trans_id  = $params{trans_id_field})
502                AND | . join(' AND ', map { "($_)" } @sub_where) . qq|)|;
503       push @values, $params{module}, conv_i($config->{id}), @sub_values;
504     }
505   }
506
507   my $query = join ' AND ', @where;
508
509   $main::lxdebug->leave_sub();
510
511   return ($query, @values);
512 }
513
514 sub add_custom_variables_to_report {
515   $main::lxdebug->enter_sub();
516
517   my $self      = shift;
518   my %params    = @_;
519
520   Common::check_params(\%params, qw(module trans_id_field column_defs data configs));
521
522   my $myconfig  = \%main::myconfig;
523   my $form      = $main::form;
524   my $locale    = $main::locale;
525
526   my $dbh       = $params{dbh} || $form->get_standard_dbh($myconfig);
527
528   my $configs   = [ grep { $_->{includeable} && $params{column_defs}->{"cvar_$_->{name}"}->{visible} } @{ $params{configs} } ];
529
530   if (!scalar(@{ $params{data} }) || ! scalar(@{ $configs })) {
531     $main::lxdebug->leave_sub();
532     return;
533   }
534
535   # allow sub_module to be a coderef or a fixed value
536   if (ref $params{sub_module} ne 'CODE') {
537     my $sub_module = "$params{sub_module}";
538     $params{sub_module} = sub { $sub_module };
539   }
540
541   my %cfg_map   = map { $_->{id} => $_ } @{ $configs };
542   my @cfg_ids   = keys %cfg_map;
543
544   my $query     =
545     qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value, config_id
546        FROM custom_variables
547        WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|))
548          AND (trans_id = ?)
549          AND (sub_module = ?)|;
550   my $sth       = prepare_query($form, $dbh, $query);
551
552   foreach my $row (@{ $params{data} }) {
553     do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), $params{sub_module}->($row));
554
555     while (my $ref = $sth->fetchrow_hashref()) {
556       my $cfg = $cfg_map{$ref->{config_id}};
557
558       $row->{"cvar_$cfg->{name}"} =
559           $cfg->{type} eq 'date'      ? $ref->{date_value}
560         : $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value}
561         : $cfg->{type} eq 'number'    ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision})
562         : $cfg->{type} eq 'bool'      ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No'))
563         :                               $ref->{text_value};
564     }
565   }
566
567   $sth->finish();
568
569   $main::lxdebug->leave_sub();
570 }
571
572 sub get_field_format_list {
573   $main::lxdebug->enter_sub();
574
575   my $self          = shift;
576   my %params        = @_;
577
578   Common::check_params(\%params, qw(module));
579
580   my $myconfig      = \%main::myconfig;
581   my $form          = $main::form;
582
583   my $dbh           = $params{dbh} || $form->get_standard_dbh($myconfig);
584
585   my $configs       = $self->get_configs(%params);
586
587   my $date_fields   = [];
588   my $number_fields = {};
589
590   foreach my $config (@{ $configs }) {
591     my $name = "$params{prefix}cvar_$config->{name}";
592
593     if ($config->{type} eq 'date') {
594       push @{ $date_fields }, $name;
595
596     } elsif ($config->{type} eq 'number') {
597       $number_fields->{$config->{precision}} ||= [];
598       push @{ $number_fields->{$config->{precision}} }, $name;
599     }
600   }
601
602   $main::lxdebug->leave_sub();
603
604   return ($date_fields, $number_fields);
605 }
606
607 sub save_custom_variables_validity {
608   $main::lxdebug->enter_sub();
609
610   my $self     = shift;
611   my %params   = @_;
612
613   Common::check_params(\%params, qw(config_id trans_id validity));
614
615   my $myconfig = \%main::myconfig;
616   my $form     = $main::form;
617
618   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
619
620   my (@where, @values);
621   add_token(\@where, \@values, col => "config_id", val => $params{config_id}, esc => \&conv_i);
622   add_token(\@where, \@values, col => "trans_id",  val => $params{trans_id},  esc => \&conv_i);
623
624   my $where = scalar @where ? "WHERE " . join ' AND ', @where : '';
625   my $query = qq|DELETE FROM custom_variables_validity $where|;
626
627   do_query($form, $dbh, $query, @values);
628
629   $query  =
630     qq|INSERT INTO custom_variables_validity (config_id, trans_id)
631        VALUES                                (?,         ?       )|;
632   my $sth = prepare_query($form, $dbh, $query);
633
634   unless ($params{validity}) {
635     foreach my $config_id (listify $params{config_id}) {
636       foreach my $trans_id (listify $params{trans_id}) {
637         do_statement($form, $sth, $query, conv_i($config_id), conv_i($trans_id));
638       }
639     }
640   }
641
642   $sth->finish();
643
644   $dbh->commit();
645
646   $main::lxdebug->leave_sub();
647 }
648
649 sub get_custom_variables_validity {
650   $main::lxdebug->enter_sub(2);
651
652   my $self     = shift;
653   my %params   = @_;
654
655   Common::check_params(\%params, qw(config_id trans_id));
656
657   my $myconfig = \%main::myconfig;
658   my $form     = $main::form;
659
660   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
661
662   my $query    = qq|SELECT COUNT(*) FROM custom_variables_validity WHERE config_id = ? AND trans_id = ?|;
663
664   my ($invalid) = selectfirst_array_query($form, $dbh, $query, conv_i($params{config_id}), conv_i($params{trans_id}));
665
666   $main::lxdebug->leave_sub(2);
667
668   return !$invalid;
669 }
670
671 sub custom_variables_validity_by_trans_id {
672   $main::lxdebug->enter_sub(2);
673
674   my $self     = shift;
675   my %params   = @_;
676
677   return sub { 0 } unless $params{trans_id};
678
679   my $myconfig = \%main::myconfig;
680   my $form     = $main::form;
681
682   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
683
684   my $query    = qq|SELECT config_id, COUNT(*) FROM custom_variables_validity WHERE trans_id = ? GROUP BY config_id|;
685
686   my %invalids = selectall_as_map($form, $dbh, $query, 'config_id', 'count', $params{trans_id});
687
688   $main::lxdebug->leave_sub(2);
689
690   return sub { !$invalids{+shift} };
691 }
692
693 1;
694
695 __END__
696
697 =head1 NAME
698
699 SL::CVar.pm - Custom Variables module
700
701 =head1 SYNOPSIS
702
703   # dealing with configs
704
705   my $all_configs = CVar->get_configs()
706   my $config      = CVar->get_config(id => '1234')
707
708   CVar->save_config($config);
709   CVar->delete->config($config)
710
711   # dealing with custom vars
712
713   CVar->get_custom_variables(module => 'ic')
714
715 =head2 VALIDITY
716
717 Suppose the following scenario:
718
719 You have a lot of parts in your database, and a set of properties cofigured. Now not every part has every of these properties, some combinations will just make no sense. In order to clean up your inputs a bit, you want to mark certain combinations as invalid, blocking them from modification and possibly display.
720
721 Validity is assumed. If you modify validity, you actually save B<invalidity>.
722 Invalidity is saved as a function of config_id, and the trans_id
723
724 In the naive way, disable an attribute for a specific id (simple)
725
726 =cut