#!/usr/bin/perl use Asterisk::AGI; use DBI; my $dbh = DBI->connect("dbi:mysql:dialer:localhost:3306",'dialer','1234',{AutoCommit => 1, PrintError => 0, RaiseError => 0}); my $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); $attempts = 0; my $callerid = $input{'callerid'}; &what_dbs; exit; sub what_dbs { my $ret = 0; my $sth = $dbh->prepare("SHOW TABLES"); $sth->execute; my $total_hits=0; while(@table = $sth->fetchrow_array) { if ($table[0] ne 'cdr' && $table[0] ne 'CDR' &&$table[0] ne 'dnc' && $table[0] ne 'DNC') { $total_hits += search_table($table[0]); } } if ($total_hits lt 1) { $sth = $dbh->prepare("INSERT INTO INBOUND (id,phone) values (NULL,'$callerid')"); $sth->execute; $sth = $dbh->prepare("SELECT LAST_INSERT_ID()"); $sth->execute; while(@record = $sth->fetchrow_array) { print "SET VARIABLE CAMPAIGN INBOUND\n"; print "SET VARIABLE LEADID " . $record[0] . "\n"; print "SET CALLERID ~INBOUND-" . $record[0] . "-true~<$callerid>\n"; print "SET VARIABLE TOTALHITS " . $total_hits . "\n"; } } $sth->finish; return $ret; } sub search_table { local($thetable) = @_; my $mystring = "SELECT * FROM " . $thetable . " WHERE phone LIKE '%$callerid%'"; my $sth = $dbh->prepare("$mystring"); $sth->execute; my $hit_count=0; while(@record = $sth->fetchrow_array) { $hit_count++; print "SET VARIABLE CAMPAIGN " . $thetable . "\n"; print "SET VARIABLE LEADID " . $record[0] . "\n"; print "SET CALLERID ~" . $thetable . "-" . $record[0] . "-true~<$callerid>\n"; print "SET VARIABLE HITCOUNT " . $hit_count . "\n"; } $sth->finish; return $hit_count; }