6 % # 'target_table' => 'table_name',
7 % # 'link_table' => 'table_name',
9 % # 'name_col' => 'name_column',
11 % # 'name_callback' => sub { },
14 % # recommended (required?)
16 % # 'source_obj' => $obj,
18 % # #'source_table' => 'table_name',
19 % # #'sourcenum' => '4', #current value of primary key in source_table
20 % # # # (none is okay, just pass it if you have it)
24 % # 'disable-able' => 1,
28 % my $target_pkey = dbdef->table($opt{'target_table'})->primary_key;
30 % my( $source_pkey, $sourcenum, $source_obj );
31 % if ( $opt{'source_obj'} || $opt{'object'} ) {
33 % $source_obj = $opt{'source_obj'} || $opt{'object'};
34 % #$source_table = $source_obj->dbdef_table->table;
35 % $source_pkey = $source_obj->dbdef_table->primary_key;
36 % $sourcenum = $source_obj->$source_pkey();
41 % $source_pkey = $opt{'source_table'}
42 % ? dbdef->table($opt{'source_table'})->primary_key
44 % $sourcenum = $opt{'sourcenum'};
47 % my $hashref = $opt{'hashref'} || {};
49 % my $extra_sql = $opt{'extra_sql'} || '';
51 % if ( $opt{'agent_virt'} ) {
52 % $extra_sql .= ' AND' . $FS::CurrentUser::CurrentUser->agentnums_sql(
53 % 'null_right' => $opt{'agent_null_right'}
57 % if ( $opt{'disable-able'} ) {
58 % $hashref->{'disabled'} = '';
60 % $extra_sql .= ( $sourcenum && $source_pkey )
61 % ? " OR $source_pkey = $sourcenum"
66 % foreach my $target_obj (
67 % qsearch({ 'table' => $opt{'target_table'},
68 % 'hashref' => $hashref,
69 % 'select' => $opt{'target_table'}. '.*',
70 % 'addl_from' => "LEFT JOIN $opt{'link_table'} USING ( $target_pkey )",
71 % 'extra_sql' => $extra_sql,
75 % my $targetnum = $target_obj->$target_pkey();
78 % if ( $cgi->param('error') ) {
80 % $checked = $cgi->param($target_pkey.$targetnum)
84 % } elsif ( !$sourcenum ) { # newly created object, has no links yet
86 % $checked = $opt{'default'} ? 'CHECKED' : ''
90 % $checked = qsearchs( $opt{'link_table'}, {
91 % $source_pkey => $sourcenum,
92 % $target_pkey => $targetnum,
102 <INPUT TYPE="checkbox" NAME="<% $target_pkey. $targetnum %>" <% $checked %> VALUE="ON">
103 % if ( $opt{'target_link'} ) {
106 <A HREF="<% $opt{'target_link'} %><% $targetnum %>">
112 % if ( $opt{'name_callback'} ) {
115 <% &{ $opt{'name_callback'} }( $target_obj ) %><% $opt{'target_link'} ? '</A>' : '' %>
117 % my $name_col = $opt{'name_col'};
121 <% $target_obj->$name_col() %><% $opt{'target_link'} ? '</A>' : '' %>
123 % if ( $opt{'disable-able'} ) {
126 <% $target_obj->disabled =~ /^Y/i ? ' (DISABLED)' : '' %>