7   $main::lxdebug->enter_sub();
 
  12   if ($params{mode} && ($params{mode} eq 'ids')) {
 
  13     Common::check_params_x(\%params, [ qw(from_ids to_ids) ]);
 
  16     Common::check_params(\%params, qw(links));
 
  22   if ($params{mode} && ($params{mode} eq 'ids')) {
 
  23     my ($from_to, $to_from) = $params{from_ids} ? qw(from to) : qw(to from);
 
  26     if ('ARRAY' eq ref $params{"${from_to}_ids"}) {
 
  27       $ids{$from_to} = $params{"${from_to}_ids"};
 
  29       $ids{$from_to} = [ grep { $_ } map { $_ * 1 } split m/\s+/, $params{"${from_to}_ids"} ];
 
  32     if (my $num = scalar @{ $ids{$from_to} }) {
 
  33       $ids{$to_from} = [ ($params{"${to_from}_id"}) x $num ];
 
  34       @links         = map { { 'from_table' => $params{from_table},
 
  35                                'from_id'    => $ids{from}->[$_],
 
  36                                'to_table'   => $params{to_table},
 
  37                                'to_id'      => $ids{to}->[$_],      } } (0 .. $num - 1);
 
  41     @links = @{ $params{links} };
 
  45     $main::lxdebug->leave_sub();
 
  49   my $myconfig = \%main::myconfig;
 
  50   my $form     = $main::form;
 
  52   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
 
  54   my $query    = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|;
 
  55   my $sth      = prepare_query($form, $dbh, $query);
 
  57   foreach my $link (@links) {
 
  58     next if ('HASH' ne ref $link);
 
  59     next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id});
 
  61     do_statement($form, $sth, $query, $link->{from_table}, conv_i($link->{from_id}), $link->{to_table}, conv_i($link->{to_id}));
 
  64   $dbh->commit() unless ($params{dbh});
 
  66   $main::lxdebug->leave_sub();
 
  70   $main::lxdebug->enter_sub();
 
  75   Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]);
 
  77   my $myconfig   = \%main::myconfig;
 
  78   my $form       = $main::form;
 
  80   my $dbh        = $params{dbh} || $form->get_standard_dbh($myconfig);
 
  85   foreach my $col (qw(from_table from_id to_table to_id)) {
 
  86     next unless ($params{$col});
 
  88     if ('ARRAY' eq ref $params{$col}) {
 
  89       push @conditions, "$col IN (" . join(', ', ('?') x scalar(@{ $params{$col} })) . ")";
 
  90       push @values,     $col =~ m/table/ ? @{ $params{$col} } : map { conv_i($_) } @{ $params{$col} };
 
  93       push @conditions, "$col = ?";
 
  94       push @values,     $col =~ m/table/ ? $params{$col} : conv_i($params{$col});
 
  98   my $query = qq|SELECT from_table, from_id, to_table, to_id
 
 101   if (scalar @conditions) {
 
 102     $query .= qq| WHERE | . join(' AND ', map { "($_)" } @conditions);
 
 105   my $links = selectall_hashref_query($form, $dbh, $query, @values);
 
 107   $main::lxdebug->leave_sub();
 
 109   return wantarray ? @{ $links } : $links;