$outbound_trunk = "IAX2/xxx\@NuFone/"; $outbound_context = "xxxxxxxx"; $outbound_exten = "1"; $outbound_priority = "1"; $testing = 1; $DBhostname = "localhost"; $DBpassword = "xxxxxxxx"; $DBuser = "xxxxxxx"; $DBtable = "xxxxxxxx"; use DBI; $drh = DBI->install_driver('mysql') or die("Unable to install driver"); $dbh = DBI->connect("DBI:mysql:$DBtable",$DBuser,$DBpassword) or die("Unable to connect"); ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = (localtime(time))[0,1,2,3,4,5,6,7,8]; $mydatetimestamp = sprintf("%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d", $year+1900, $month, $mday, $hour, $min, $sec); ################################################################### sub getdate { my $sth = $dbh->prepare("SELECT LEFT(NOW(),8)"); $sth->execute; ( $now ) = $sth->fetchrow(); $now =~ s/://g; $now =~ s/-//g; $now =~ s/\s//g; return $now; } ################################################################### sub getdatetime { my $sth = $dbh->prepare("SELECT NOW()"); $sth->execute; ( $now ) = $sth->fetchrow(); $now =~ s/://g; $now =~ s/-//g; $now =~ s/\s//g; return $now; } ################################################################### sub getnow { my $sth = $dbh->prepare("SELECT NOW()"); $sth->execute; ( $now ) = $sth->fetchrow(); return $now; } ################################################################### sub generate_outbound_call { # requires entries for # outbound_trunk = "IAX2/xxxxx@NuFone/"; or "Zap/g2/"; # outbound_context = "your_context"; # outbound_exten = "1"; # outbound_priority = "1"; my $mgrCTS = shift; my $numtodial = shift; $numtodial = load_num_to_dial(); if ($numtodial ne "" && !$testing) { my $dial_string = $outbound_trunk . $numtodial; $mgrCTS = "Action: Originate\r\n"; $mgrCTS .= "Channel: $dial_string\r\n"; $mgrCTS .= "Context: $outbound_context\r\n"; $mgrCTS .= "Exten: $outbound_exten\r\n"; $mgrCTS .= "Priority: $outbound_priority\r\n"; $mgrCTS .= "\r\n"; send_command_to_manager($mgrCTS); log_debug("originate call: $numtodial completed", 128); } else { log_debug("originate call: $numtodial failed", 128); } } ################################################################### sub load_num_to_dial { my $numtodial = shift; my $db_id; my $db_org; my $db_num; my $db_called; my $now = getnow(); my $select_string = "SELECT * FROM night WHERE ( (called < '6') AND (LEFT(lastcalled,10) <> LEFT(NOW(),10) AND rectype = 'R') AND fullphone > '1' ) LIMIT 1"; my $sth = $dbh->prepare($select_string); $sth->execute or die("Unable to excute query"); while(@record = $sth->fetchrow_array) { $db_id = $record[0]; $db_org = $record[6]; $db_called = $record[9]; $db_called++; $db_num = $db_org; $db_num =~ s/-//g; $numtodial = "1" . $db_num; } $sth = $dbh->prepare("UPDATE night SET called = '$db_called', lastcalled = '$now' WHERE rec_id = '$db_id' "); $sth->execute or die("Unable to excute query"); $sth->finish; return $numtodial; } ################################################################### 1;