7 $main::lxdebug->enter_sub();
12 if ($params{mode} && ($params{mode} eq 'string')) {
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 'string')) {
23 my ($from_to, $to_from) = $params{from_ids} ? qw(from to) : qw(to from);
24 my %ids = ( $from_to => [ grep { $_ } map { $_ * 1 } split m/\s+/, $params{"${from_to}_ids"} ] );
26 if (my $num = scalar @{ $ids{$from_to} }) {
27 $main::lxdebug->message(0, "3");
28 $ids{$to_from} = [ ($params{"${to_from}_id"}) x $num ];
29 @links = map { { 'from_table' => $params{from_table},
30 'from_id' => $ids{from}->[$_],
31 'to_table' => $params{to_table},
32 'to_id' => $ids{to}->[$_], } } (0 .. $num - 1);
36 @links = @{ $params{links} };
40 $main::lxdebug->leave_sub();
44 my $myconfig = \%main::myconfig;
45 my $form = $main::form;
47 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
49 my $query = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|;
50 my $sth = prepare_query($form, $dbh, $query);
52 foreach my $link (@links) {
53 next if ('HASH' ne ref $link);
54 next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id});
56 do_statement($form, $sth, $query, $link->{from_table}, conv_i($link->{from_id}), $link->{to_table}, conv_i($link->{to_id}));
59 $dbh->commit() unless ($params{dbh});
61 $main::lxdebug->leave_sub();
65 $main::lxdebug->enter_sub();
70 Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]);
72 my $myconfig = \%main::myconfig;
73 my $form = $main::form;
75 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
80 foreach my $col (qw(from_table from_id to_table to_id)) {
81 next unless ($params{$col});
83 if ('ARRAY' eq ref $params{$col}) {
84 push @conditions, "$col IN (" . join(', ', ('?') x scalar(@{ $params{$col} })) . ")";
85 push @values, $col =~ m/table/ ? @{ $params{$col} } : map { conv_i($_) } @{ $params{$col} };
88 push @conditions, "$col = ?";
89 push @values, $col =~ m/table/ ? $params{$col} : conv_i($params{$col});
93 my $query = qq|SELECT from_table, from_id, to_table, to_id
96 if (scalar @conditions) {
97 $query .= qq| WHERE | . join(' AND ', map { "($_)" } @conditions);
100 my $links = selectall_hashref_query($form, $dbh, $query, @values);
102 $main::lxdebug->leave_sub();
104 return wantarray ? @{ $links } : $links;