Files
ViciDialSVN/agc_1-X/trunk/VICIDIAL_web/listloader_super.pl
T
root 6ef43b97cf 1.1.10 release
git-svn-id: svn://192.168.202.10@1 3d104415-ff17-0410-8863-d5cf3c621b8a
2006-07-07 14:57:59 +00:00

135 lines
5.1 KiB
Perl

#!/usr/bin/perl
### listloader_super.pl
###
### Copyright (C) 2006 Matt Florell,Joe Johnson <vicidial@gmail.com> LICENSE: GPLv2
###
use Spreadsheet::ParseExcel;
use Time::Local;
use Net::MySQL;
### Make sure this file is in a libs path or put the absolute path to it
require("/home/cron/AST_SERVER_conf.pl"); # local configuration file
if (!$DB_port) {$DB_port='3306';}
$dbhA = Net::MySQL->new(hostname => "$DB_server", database => "$DB_database", user => "$DB_user", password => "$DB_pass", port => "$DB_port")
or die "Couldn't connect to database: $DB_server - $DB_database\n";
$vars=$ARGV[0];
@xls_fields=split(/\,/, $vars);
$|=0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
$pulldate="$year-$mon-$mday $hour:$min:$sec";
$total=0; $good=0; $bad=0;
open(STMT_FILE, "> listloader_stmts.txt");
$oBook = Spreadsheet::ParseExcel::Workbook->Parse("./vicidial_temp_file.xls");
my($iR, $iC, $oWkS, $oWkC);
foreach $oWkS (@{$oBook->{Worksheet}}) {
for($iR = 0 ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) {
$entry_date = "$pulldate";
$modify_date = "";
$status = "NEW";
$user = "";
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[0]];
if ($oWkC) {$vendor_lead_code=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[1]];
if ($oWkC) {$source_code=$oWkC->Value; }
$source_id=$source_code;
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[2]];
if ($oWkC) {$list_id=$oWkC->Value; }
$campaign_id = '';
$called_since_last_reset='N';
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[3]];
if ($oWkC) {$phone_code=$oWkC->Value; }
$phone_code=~s/[^0-9]//g;
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[4]];
if ($oWkC) {$phone_number=$oWkC->Value; }
$phone_number=~s/[^0-9]//g;
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[5]];
if ($oWkC) {$title=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[6]];
if ($oWkC) {$first_name=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[7]];
if ($oWkC) {$middle_initial=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[8]];
if ($oWkC) {$last_name=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[9]];
if ($oWkC) {$address1=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[10]];
if ($oWkC) {$address2=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[11]];
if ($oWkC) {$address3=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[12]];
if ($oWkC) {$city=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[13]];
if ($oWkC) {$state=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[14]];
if ($oWkC) {$province=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[15]];
if ($oWkC) {$postal_code=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[16]];
if ($oWkC) {$country_code=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[17]];
if ($oWkC) {$gender=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[18]];
if ($oWkC) {$date_of_birth=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[19]];
if ($oWkC) {$alt_phone=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[20]];
if ($oWkC) {$email=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[21]];
if ($oWkC) {$security_phrase=$oWkC->Value; }
$oWkC = $oWkS->{Cells}[$iR][$xls_fields[22]];
if ($oWkC) {$comments=$oWkC->Value; }
$comments=~s/^\s*(.*?)\s*$/$1/;
if (length($phone_number)>8) {
if ($multi_insert_counter > 8) {
### insert good deal into pending_transactions table ###
$stmtZ = "INSERT INTO vicidial_list values$multistmt('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$campaign_id','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0);";
$dbhA->query("$stmtZ");
print STMT_FILE $stmtZ."\r\n";
$multistmt='';
$multi_insert_counter=0;
} else {
$multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$campaign_id','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0),";
$multi_insert_counter++;
}
$good++;
} else {
if ($bad < 10) {print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]|</font><b>\n";}
$bad++;
}
$total++;
if ($total%100==0) {
print "<script language='JavaScript1.2'>ShowProgress($good, $bad, $total)</script>";
sleep(1);
# flush();
}
}
}
if ($multi_insert_counter > 0) {
$stmtZ = "INSERT INTO vicidial_list values ".substr($multistmt, 0, -1).";";
$dbhA->query("$stmtZ");
print STMT_FILE $stmtZ."\r\n";
}
print "<BR><BR>Done</B> GOOD: $good &nbsp; &nbsp; &nbsp; BAD: $bad &nbsp; &nbsp; &nbsp; TOTAL: $total</font></center>";