0a92e4548292c24212742c27391b4ff7e9b79260
[freeside.git] / httemplate / elements / checkboxes-table-name.html
1 %
2 %
3 %  ##
4 %  # required
5 %  ##
6 %  # 'link_table'      => 'table_name',
7 %  #
8 %  # 'name_col' => 'name_column',
9 %  # #or
10 %  # 'name_callback' => sub { },
11 %  #
12 %  # 'names_list' => [ 'value', 'other value' ],
13 %  #
14 %  ##
15 %  # recommended (required?)
16 %  ##
17 %  # 'source_obj'   => $obj,
18 %  # #or?
19 %  # #'source_table' => 'table_name',
20 %  # #'sourcenum'    => '4', #current value of primary key in source_table
21 %  # #                       # (none is okay, just pass it if you have it)
22 %  ##
23 %  # optional
24 %  ##
25 %  # 'num_col' => 'col_name' #if column name is different in link_table than
26 %  #                         #source_table
27 %  # 'link_static' => { 'column' => 'value' },
28 %
29 %  my( %opt ) = @_;
30 %
31 %  my( $source_pkey, $sourcenum, $source_obj );
32 %  if ( $opt{'source_obj'} ) {
33 %
34 %    $source_obj = $opt{'source_obj'};
35 %    #$source_table = $source_obj->dbdef_table->table;
36 %    $source_pkey = $source_obj->dbdef_table->primary_key;
37 %    $sourcenum = $source_obj->$source_pkey();
38 %
39 %  } else {
40 %
41 %    #$source_obj?
42 %    $source_pkey = $opt{'source_table'}
43 %                     ? dbdef->table($opt{'source_table'})->primary_key
44 %                     : '';
45 %    $sourcenum = $opt{'sourcenum'};
46 %  }
47 %
48 %  $source_pkey = $opt{'num_col'} || $source_pkey;
49 %
50 %  my $link_static = $opt{'link_static'} || {};
51 %
52 %
53 % foreach my $name ( @{ $opt{'names_list'} } ) {
54 %
55 %     my $checked;
56 %     if ( $cgi->param('error') ) {
57 %
58 %       $checked = $cgi->param($opt{'link_table'}. ".$name" )
59 %                    ? 'CHECKED'
60 %                    : '';
61 %
62 %     } else {
63 %
64 %       $checked =
65 %         qsearchs( $opt{'link_table'}, {
66 %                                         $source_pkey     => $sourcenum,
67 %                                         $opt{'name_col'} => $name,
68 %                                         %$link_static,
69 %                                       }                                 )
70 %                    ? 'CHECKED'
71 %                    : ''
72 %
73 %     }
74 %
75 %
76
77
78   <INPUT TYPE="checkbox" NAME="<% $opt{'link_table'}. ".$name" %>" <% $checked %> VALUE="ON">
79
80   <% $name %>
81
82   <BR>
83 % } 
84
85