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