8c4f6a899feab2bb8240078234b996153f103304
[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, $valid);
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       $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} = $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     my $valid_index = "$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid";
341     $self->save_custom_variables_validity(trans_id => $params{trans_id}, config_id => $config->{id},
342       validity => ($params{variables}{$valid_index} || $params{always_valid} ? 1 : 0)
343     );
344   }
345
346   $sth->finish();
347
348   $dbh->commit();
349
350   $main::lxdebug->leave_sub();
351 }
352
353 sub render_inputs {
354   $main::lxdebug->enter_sub(2);
355
356   my $self     = shift;
357   my %params   = @_;
358
359   Common::check_params(\%params, qw(variables));
360
361   my $myconfig = \%main::myconfig;
362   my $form     = $main::form;
363
364   my %options  = ( name_prefix       => "$params{name_prefix}",
365                    name_postfix      => "$params{name_postfix}",
366                    hide_non_editable => $params{hide_non_editable},
367                    show_disabled_message => $params{show_disabled_message},
368                  );
369
370   foreach my $var (@{ $params{variables} }) {
371     $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs',     { var => $var, %options });
372     $var->{VALID_BOX} = $form->parse_html_template('amcvar/render_checkboxes', { var => $var, %options });
373   }
374
375   $main::lxdebug->leave_sub(2);
376 }
377
378 sub render_search_options {
379   $main::lxdebug->enter_sub();
380
381   my $self     = shift;
382   my %params   = @_;
383
384   Common::check_params(\%params, qw(variables));
385
386   my $myconfig = \%main::myconfig;
387   my $form     = $main::form;
388
389   $params{hidden_cvar_filters} = $myconfig->{hide_cvar_search_options};
390
391   $params{include_prefix}   = 'l_' unless defined($params{include_prefix});
392   $params{include_value}  ||= '1';
393
394   my $filter  = $form->parse_html_template('amcvar/search_filter',  \%params);
395   my $include = $form->parse_html_template('amcvar/search_include', \%params);
396
397   $main::lxdebug->leave_sub();
398
399   return ($filter, $include);
400 }
401
402 sub build_filter_query {
403   $main::lxdebug->enter_sub();
404
405   my $self     = shift;
406   my %params   = @_;
407
408   Common::check_params(\%params, qw(module trans_id_field filter));
409
410   my $myconfig = \%main::myconfig;
411   my $form     = $main::form;
412
413   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
414
415   my $configs  = $self->get_configs(%params);
416
417   my (@where, @values);
418
419   foreach my $config (@{ $configs }) {
420     next unless ($config->{searchable});
421
422     my $name = "cvar_$config->{name}";
423
424     my (@sub_values, @sub_where, $not);
425
426     if (($config->{type} eq 'text') || ($config->{type} eq 'textfield')) {
427       next unless ($params{filter}->{$name});
428
429       push @sub_where,  qq|cvar.text_value ILIKE ?|;
430       push @sub_values, '%' . $params{filter}->{$name} . '%'
431
432     } elsif ($config->{type} eq 'select') {
433       next unless ($params{filter}->{$name});
434
435       push @sub_where,  qq|cvar.text_value = ?|;
436       push @sub_values, $params{filter}->{$name};
437
438     } elsif (($config->{type} eq 'date') || ($config->{type} eq 'timestamp')) {
439       my $name_from = "${name}_from";
440       my $name_to   = "${name}_to";
441
442       if ($params{filter}->{$name_from}) {
443         push @sub_where,  qq|cvar.timestamp_value >= ?|;
444         push @sub_values, conv_date($params{filter}->{$name_from});
445       }
446
447       if ($params{filter}->{$name_to}) {
448         push @sub_where,  qq|cvar.timestamp_value <= ?|;
449         push @sub_values, conv_date($params{filter}->{$name_to});
450       }
451
452     } elsif ($config->{type} eq 'number') {
453       next if ($params{filter}->{$name} eq '');
454
455       my $f_op = $params{filter}->{"${name}_qtyop"};
456
457       my $op;
458       if ($f_op eq '==') {
459         $op  = '=';
460
461       } elsif ($f_op eq '=/=') {
462         $not = 'NOT';
463         $op  = '<>';
464
465       } elsif ($f_op eq '<') {
466         $not = 'NOT';
467         $op  = '>=';
468
469       } elsif ($f_op eq '<=') {
470         $not = 'NOT';
471         $op  = '>';
472
473       } elsif (($f_op eq '>') || ($f_op eq '>=')) {
474         $op  = $f_op;
475
476       } else {
477         $op  = '=';
478       }
479
480       push @sub_where,  qq|cvar.number_value $op ?|;
481       push @sub_values, $form->parse_amount($myconfig, $params{filter}->{$name});
482
483     } elsif ($config->{type} eq 'bool') {
484       next unless ($params{filter}->{$name});
485
486       $not = 'NOT' if ($params{filter}->{$name} eq 'no');
487       push @sub_where,  qq|COALESCE(cvar.bool_value, false) = TRUE|;
488     }
489
490     if (@sub_where) {
491       add_token(\@sub_where, \@sub_values, col => 'cvar.sub_module', val => $params{sub_module} || '');
492
493       push @where,
494         qq|$not EXISTS(
495              SELECT cvar.id
496              FROM custom_variables cvar
497              LEFT JOIN custom_variable_configs cvarcfg ON (cvar.config_id = cvarcfg.id)
498              WHERE (cvarcfg.module = ?)
499                AND (cvarcfg.id     = ?)
500                AND (cvar.trans_id  = $params{trans_id_field})
501                AND | . join(' AND ', map { "($_)" } @sub_where) . qq|)|;
502       push @values, $params{module}, conv_i($config->{id}), @sub_values;
503     }
504   }
505
506   my $query = join ' AND ', @where;
507
508   $main::lxdebug->leave_sub();
509
510   return ($query, @values);
511 }
512
513 sub add_custom_variables_to_report {
514   $main::lxdebug->enter_sub();
515
516   my $self      = shift;
517   my %params    = @_;
518
519   Common::check_params(\%params, qw(module trans_id_field column_defs data configs));
520
521   my $myconfig  = \%main::myconfig;
522   my $form      = $main::form;
523   my $locale    = $main::locale;
524
525   my $dbh       = $params{dbh} || $form->get_standard_dbh($myconfig);
526
527   my $configs   = [ grep { $_->{includeable} && $params{column_defs}->{"cvar_$_->{name}"}->{visible} } @{ $params{configs} } ];
528
529   if (!scalar(@{ $params{data} }) || ! scalar(@{ $configs })) {
530     $main::lxdebug->leave_sub();
531     return;
532   }
533
534   # allow sub_module to be a coderef or a fixed value
535   if (ref $params{sub_module} ne 'CODE') {
536     my $sub_module = "$params{sub_module}";
537     $params{sub_module} = sub { $sub_module };
538   }
539
540   my %cfg_map   = map { $_->{id} => $_ } @{ $configs };
541   my @cfg_ids   = keys %cfg_map;
542
543   my $query     =
544     qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value, config_id
545        FROM custom_variables
546        WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|))
547          AND (trans_id = ?)
548          AND (sub_module = ?)|;
549   my $sth       = prepare_query($form, $dbh, $query);
550
551   foreach my $row (@{ $params{data} }) {
552     do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), $params{sub_module}->($row));
553
554     while (my $ref = $sth->fetchrow_hashref()) {
555       my $cfg = $cfg_map{$ref->{config_id}};
556
557       $row->{"cvar_$cfg->{name}"} =
558           $cfg->{type} eq 'date'      ? $ref->{date_value}
559         : $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value}
560         : $cfg->{type} eq 'number'    ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision})
561         : $cfg->{type} eq 'bool'      ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No'))
562         :                               $ref->{text_value};
563     }
564   }
565
566   $sth->finish();
567
568   $main::lxdebug->leave_sub();
569 }
570
571 sub get_field_format_list {
572   $main::lxdebug->enter_sub();
573
574   my $self          = shift;
575   my %params        = @_;
576
577   Common::check_params(\%params, qw(module));
578
579   my $myconfig      = \%main::myconfig;
580   my $form          = $main::form;
581
582   my $dbh           = $params{dbh} || $form->get_standard_dbh($myconfig);
583
584   my $configs       = $self->get_configs(%params);
585
586   my $date_fields   = [];
587   my $number_fields = {};
588
589   foreach my $config (@{ $configs }) {
590     my $name = "$params{prefix}cvar_$config->{name}";
591
592     if ($config->{type} eq 'date') {
593       push @{ $date_fields }, $name;
594
595     } elsif ($config->{type} eq 'number') {
596       $number_fields->{$config->{precision}} ||= [];
597       push @{ $number_fields->{$config->{precision}} }, $name;
598     }
599   }
600
601   $main::lxdebug->leave_sub();
602
603   return ($date_fields, $number_fields);
604 }
605
606 sub save_custom_variables_validity {
607   $main::lxdebug->enter_sub();
608
609   my $self     = shift;
610   my %params   = @_;
611
612   Common::check_params(\%params, qw(config_id trans_id validity));
613
614   my $myconfig = \%main::myconfig;
615   my $form     = $main::form;
616
617   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
618
619   my (@where, @values);
620   add_token(\@where, \@values, col => "config_id", val => $params{config_id}, esc => \&conv_i);
621   add_token(\@where, \@values, col => "trans_id",  val => $params{trans_id},  esc => \&conv_i);
622
623   my $where = scalar @where ? "WHERE " . join ' AND ', @where : '';
624   my $query = qq|DELETE FROM custom_variables_validity $where|;
625
626   do_query($form, $dbh, $query, @values);
627
628   $query  =
629     qq|INSERT INTO custom_variables_validity (config_id, trans_id)
630        VALUES                                (?,         ?       )|;
631   my $sth = prepare_query($form, $dbh, $query);
632
633   unless ($params{validity}) {
634     foreach my $config_id (listify $params{config_id}) {
635       foreach my $trans_id (listify $params{trans_id}) {
636         do_statement($form, $sth, $query, conv_i($config_id), conv_i($trans_id));
637       }
638     }
639   }
640
641   $sth->finish();
642
643   $dbh->commit();
644
645   $main::lxdebug->leave_sub();
646 }
647
648 sub get_custom_variables_validity {
649   $main::lxdebug->enter_sub(2);
650
651   my $self     = shift;
652   my %params   = @_;
653
654   Common::check_params(\%params, qw(config_id trans_id));
655
656   my $myconfig = \%main::myconfig;
657   my $form     = $main::form;
658
659   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
660
661   my $query    = qq|SELECT COUNT(*) FROM custom_variables_validity WHERE config_id = ? AND trans_id = ?|;
662
663   my ($invalid) = selectfirst_array_query($form, $dbh, $query, conv_i($params{config_id}), conv_i($params{trans_id}));
664
665   $main::lxdebug->leave_sub(2);
666
667   return !$invalid;
668 }
669
670 sub custom_variables_validity_by_trans_id {
671   $main::lxdebug->enter_sub(2);
672
673   my $self     = shift;
674   my %params   = @_;
675
676   return sub { 0 } unless $params{trans_id};
677
678   my $myconfig = \%main::myconfig;
679   my $form     = $main::form;
680
681   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
682
683   my $query    = qq|SELECT config_id, COUNT(*) FROM custom_variables_validity WHERE trans_id = ? GROUP BY config_id|;
684
685   my %invalids = selectall_as_map($form, $dbh, $query, 'config_id', 'count', $params{trans_id});
686
687   $main::lxdebug->leave_sub(2);
688
689   return sub { !$invalids{+shift} };
690 }
691
692 1;
693
694 __END__
695
696 =head1 NAME
697
698 SL::CVar.pm - Custom Variables module
699
700 =head1 SYNOPSIS
701
702   # dealing with configs
703
704   my $all_configs = CVar->get_configs()
705   my $config      = CVar->get_config(id => '1234')
706
707   CVar->save_config($config);
708   CVar->delete->config($config)
709
710   # dealing with custom vars
711
712   CVar->get_custom_variables(module => 'ic')
713
714 =head2 VALIDITY
715
716 Suppose the following scenario:
717
718 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.
719
720 Validity is assumed. If you modify validity, you actually save B<invalidity>.
721 Invalidity is saved as a function of config_id, and the trans_id
722
723 In the naive way, disable an attribute for a specific id (simple)
724
725 =cut