ACLs: finish group edit (agents + rights) & browse
[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
54 <% foreach my $name ( @{ $opt{'names_list'} } ) {
55
56      my $checked;
57      if ( $cgi->param('error') ) {
58
59        $checked = $cgi->param($opt{'link_table'}. ".$name" )
60                     ? 'CHECKED'
61                     : '';
62
63      } else {
64
65        $checked =
66          qsearchs( $opt{'link_table'}, {
67                                          $source_pkey     => $sourcenum,
68                                          $opt{'name_col'} => $name,
69                                          %$link_static,
70                                        }                                 )
71                     ? 'CHECKED'
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