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