diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index d3274ebe..7615e642 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -219,7 +219,8 @@ NOTE: Upgrading from 1.1.12-3 to 2.0.1 is at the bottom 49. Updated Vtiger integration to version 5.0.4 and allow searching by leads/accounts/vendors. Also added user synchronization with vicidial_users. - Also added click-to-dial from Vtiger sending call to vicidial agent screen + Also added click-to-dial from Vtiger sending call to vicidial agent screen. + Also added batch synchronization of Accounts between Vtiger and VICIDIAL. 50. Added notification of time synchronization problems in the vicidial.php page diff --git a/agc_2-X/trunk/bin/Vtiger_IN_new_accounts_file.pl b/agc_2-X/trunk/bin/Vtiger_IN_new_accounts_file.pl new file mode 100644 index 00000000..6a489dc9 --- /dev/null +++ b/agc_2-X/trunk/bin/Vtiger_IN_new_accounts_file.pl @@ -0,0 +1,640 @@ +#!/usr/bin/perl +# +# Vtiger_IN_new_accounts_file.pl version 2.0.5 *DBI-version* +# +# DESCRIPTION: +# script lets you insert leads into the vtiger system table from a CSV-formatted +# file that is in the proper format. (for format see --help) +# +# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 +# +# +# CHANGES +# 90127-1206 - First build +# + +$secX = time(); +$MT[0]=''; +$Ealert=''; + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($hour < 10) {$hour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +$pulldate0 = "$year-$mon-$mday $hour:$min:$sec"; +$NOW_TIME = "$year-$mon-$mday $hour:$min:$sec"; +$inSD = $pulldate0; +$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); +$MT[0]=''; + + +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) + {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) + {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} + if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) + {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} + if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) + {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} + if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) + {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) ) + {$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) ) + {$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) ) + {$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) ) + {$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;} + $i++; + } + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + + +if (!$VDHLOGfile) {$VDHLOGfile = "$PATHlogs/newleads.$year-$mon-$mday";} + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help|-h/i) + { + print "allowed run time options:\n"; + print " [-q] = quiet\n"; + print " [-t] = test\n"; + print " [--debug] = debug output\n"; + print " [--format=standard] = ability to define a format, standard is default, formats allowed shown in examples\n"; + print " [--duplicate-system-check] = checks for the same phone number in the entire system before inserting lead\n"; + print " [--duplicate-system-siccode] = checks for the same SIC code in the entire system before inserting lead\n"; + print " [--duplicate-system-website] = checks for the same website in the entire system before inserting lead\n"; + print " [--ftp-pull] = grabs lead files from a remote FTP server, uses REPORTS FTP login information\n"; + print " [--ftp-dir=leads_in] = remote FTP server directory to grab files from, should have a DONE sub-directory\n"; + print " [--email-list=test@test.com:test2@test.com] = send email results for each file to these addresses\n"; + print " [--email-sender=vicidial@localhost] = sender for the email results\n"; + print " [-h] = this help screen\n\n"; + print "\n"; + print "This script takes in account CSV files in the following order when they are placed in the $PATHhome/VTIGER_IN directory to be imported into the vtiger system (examples):\n\n"; + print "standard:\n"; + print "employees,ticker_symbol,sic_code,revenue,account_name,address,po_box,city,state,post_code,phone_number,ownership,fax,email,other_phone,other_email,website\n"; + print "4,C03IMM001,39207955,2,ST MARK CHURCH,1710 W COLLEGE AVE,,CHICAGO,IL,61555,3095551111,PAUL SMITH,3095551212,TEST@VERIZON.NET,7775553333,test@1034.com,bigsite.com\n\n"; + print "minicsv:\n"; + print "business,contact,phone_number,address1,city,state,postal_code\n"; + print "\"CHURCH\",\"Bob Smith\",\"3525556601\",\"105 Fifth St\",\"Steinhatchee\",\"FL\",\"32359\"\n\n"; + + exit; + } + else + { + if ($args =~ /-debug/i) + { + $DB=1; + print "\n----- DEBUGGING -----\n\n"; + } + if ($args =~ /-debugX/i) + { + $DBX=1; + print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; + } + else {$DBX=0;} + + if ($args =~ /-q/i) + { + $q=1; + } + if ($args =~ /-t/i) + { + $T=1; + $TEST=1; + print "\n----- TESTING -----\n\n"; + } + + if ($args =~ /-format=/i) + { + @data_in = split(/-format=/,$args); + $format = $data_in[1]; + $format =~ s/ .*//gi; + print "\n----- FORMAT OVERRIDE: $format -----\n\n"; + } + else + {$format = 'standard';} + + if ($args =~ /-duplicate-system-check/i) + { + $dupchecksys=1; + print "\n----- DUPLICATE SYSTEM CHECK PHONE -----\n\n"; + } + if ($args =~ /-duplicate-system-siccode/i) + { + $dupchecksic=1; + print "\n----- DUPLICATE SYSTEM CHECK SICCODE -----\n\n"; + } + if ($args =~ /-duplicate-system-website/i) + { + $dupcheckweb=1; + print "\n----- DUPLICATE SYSTEM CHECK WEBSITE -----\n\n"; + } + if ($args =~ /-ftp-pull/i) + { + $ftp_pull=1; + print "\n----- FTP LEAD FILE PULL -----\n\n"; + } + if ($args =~ /--ftp-dir=/i) + { + @data_in = split(/--ftp-dir=/,$args); + $ftp_dir = $data_in[1]; + $ftp_dir =~ s/ .*//gi; + print "\n----- REMOTE FTP DIRECTORY: $ftp_dir -----\n\n"; + } + else + {$ftp_dir = '';} + + if ($args =~ /--email-list=/i) + { + @data_in = split(/--email-list=/,$args); + $email_list = $data_in[1]; + $email_list =~ s/ .*//gi; + $email_list =~ s/:/,/gi; + print "\n----- EMAIL NOTIFICATION: $email_list -----\n\n"; + } + else + {$email_list = '';} + + if ($args =~ /--email-sender=/i) + { + @data_in = split(/--email-sender=/,$args); + $email_sender = $data_in[1]; + $email_sender =~ s/ .*//gi; + $email_sender =~ s/:/,/gi; + print "\n----- EMAIL NOTIFICATION SENDER: $email_sender -----\n\n"; + } + else + {$email_sender = 'vicidial@localhost';} + + } + } +else + { + print "no command line options set\n"; + $args = ""; + $i=0; + $forcelistid = ''; + $format='standard'; + } +### end parsing run-time options ### + +if ($q < 1) + { + print "\n\n\n\n\n\n\n\n\n\n\n\n-- Vtiger_IN_new_accounts_file.pl --\n\n"; + print "This program is designed to take a CSV delimited file and import it into the Vtiger system. \n\n"; + } + +$i=0; +$US = '_'; +$phone_list = '|'; + +if (!$VARDB_port) {$VARDB_port='3306';} + +use DBI; + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmtA = "SELECT use_non_latin,vtiger_server_ip,vtiger_dbname,vtiger_login,vtiger_pass FROM system_settings;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $non_latin = "$aryA[0]"; + $vtiger_server_ip = "$aryA[1]"; + $vtiger_dbname = "$aryA[2]"; + $vtiger_login = "$aryA[3]"; + $vtiger_pass = "$aryA[4]"; + } +$sthA->finish(); +##### END SETTINGS LOOKUP ##### +########################################### + +$dbhB = DBI->connect("DBI:mysql:$vtiger_dbname:$vtiger_server_ip:$VARDB_port", "$vtiger_login", "$vtiger_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +if ($non_latin > 0) {$affected_rows = $dbhA->do("SET NAMES 'UTF8'");} + +$suf = '.txt'; +$people_packages_id_update=''; +$dir1 = "$PATHhome/VTIGER_IN"; +$dir2 = "$PATHhome/VTIGER_IN/DONE"; + + if($DBX){print STDERR "\nVTIGER_IN directory: |$dir1|\n";} + +if ($ftp_pull > 0) + { + $i=0; + use Net::FTP; + + $files_copied_count=0; + + $ftp = Net::FTP->new("$VARREPORT_host", Port => "$VARREPORT_port", Debug => "$DBX", Passive => 1) + or die "Can't connect: $@\n"; + $ftp->login("$VARREPORT_user","$VARREPORT_pass") or die "Cannot log in /: $!"; + @FILES = $ftp->dir("$ftp_dir") + or die "Can't get a list of files in $ftp_dir: $!"; + + foreach(@FILES) + { + if ($DBX > 0) {print "$FILES[$i]\n";} + if ($FILES[$i] !~ /^d/i) + { + chomp($FILES[$i]); + @FILEDETAILS = split(/ \d\d:\d\d /, $FILES[$i]); + $FILES[$i] = "$FILEDETAILS[1]"; + $FILES[$i] =~ s/ *$//gi; + + if (length($FILES[$i]) > 4) + { + $GOODfname = $FILES[$i]; + $FILES[$i] =~ s/ /_/gi; + $FILES[$i] =~ s/\(|\)|\||\\|\/|\'|\"|//gi; + $ftp->rename("$ftp_dir/$GOODfname","$ftp_dir/$FILES[$i]"); + $FILEname = $FILES[$i]; + $ftp->get("$ftp_dir/$FILES[$i]", "$dir1/$FILES[$i]"); + + if (!$TEST) {$ftp->rename("$ftp_dir/$FILES[$i]", "$ftp_dir/DONE/$FILES[$i]");} + if ($DB > 0) {print "FTP FILE COPIED: $FILES[$i]\n";} + $files_copied_count++; + } + } + $i++; + } + if (!$q) {print "$ftp_dir - $VARREPORT_host - $#FILES - $files_copied_count\n";} + } + + +$i=0; +@FILES=@MT; +opendir(FILE, "$dir1/"); +@FILES = readdir(FILE); + +foreach(@FILES) + { + $size1 = 0; + $size2 = 0; + $person_id_delete = ''; + $transaction_id_delete = ''; + + if (length($FILES[$i]) > 4) + { + + $size1 = (-s "$dir1/$FILES[$i]"); + if (!$q) {print "$FILES[$i] $size1\n";} + sleep(2); + $size2 = (-s "$dir1/$FILES[$i]"); + if (!$q) {print "$FILES[$i] $size2\n\n";} + + + if ( ($FILES[$i] !~ /^TRANSFERRED/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + { + $GOODfname = $FILES[$i]; + $FILES[$i] =~ s/ /_/gi; + $FILES[$i] =~ s/\(|\)|\||\\|\/|\'|\"|//gi; + rename("$dir1/$GOODfname","$dir1/$FILES[$i]"); + $FILEname = $FILES[$i]; + + `cp -f $dir1/$FILES[$i] $dir2/$source$FILES[$i]`; + + ### open the in file for reading ### + open(infile, "$dir2/$source$FILES[$i]") + || die "Can't open $source$FILES[$i]: $!\n"; + + $a=0; ### each line of input file counter ### + $b=0; ### status of 'APPROVED' counter ### + $c=0; ### status of 'DECLINED' counter ### + $d=0; ### status of 'REFERRED' counter ### + $e=0; ### status of 'ERROR' counter ### + $f=0; ### number of 'DUPLICATE' counter ### + $g=0; ### number of leads with multi-alt-entries + + $multi_insert_counter=0; + $multistmt=''; + + #if ($DB) + while () + { + @m=@MT; + # print "$a| $number\n"; + $number = $_; + chomp($number); + $number =~ s/\t/\|/gi; + $number =~ s/\'|\t|\r|\n|\l//gi; + $number =~ s/\'|\t|\r|\n|\l//gi; + $number =~ s/\",,,,,,,\"/\|\|\|\|\|\|\|/gi; + $number =~ s/\",,,,,,\"/\|\|\|\|\|\|/gi; + $number =~ s/\",,,,,\"/\|\|\|\|\|/gi; + $number =~ s/\",,,,\"/\|\|\|\|/gi; + $number =~ s/\",,,\"/\|\|\|/gi; + $number =~ s/\",,\"/\|\|/gi; + $number =~ s/\",\"/\|/gi; + $number =~ s/\"//gi; + $number =~ s/,/\|/gi; + @m = split(/\|/, $number); + + + # This is the format for the minicsv lead files + # business,contact,phone_number,address1,city,state,postal_code + # "CHURCH","Bob Smith","3525556601","105 Fifth St","Steinhatchee","FL","32359" + if ($format =~ /minicsv/) + { + $employees = '1'; + $ticker_symbol = ''; + $sic_code = ''; + $revenue = ''; + $account_name = $m[0]; chomp($account_name); + if (length($account_name)<1) {$account_name='NONE';} + $address = $m[3]; chomp($address); + $po_box = ''; + $city = $m[4]; chomp($city); + $state = $m[5]; chomp($state); + $post_code = $m[6]; chomp($post_code); + $phone_number = $m[2]; chomp($phone_number); $phone_number =~ s/\D//gi; + $ownership = $m[1]; chomp($ownership); + $other_phone = ''; + $email = ''; + $fax = ''; + $other_email = ''; + $website = ''; + $country = 'USA'; + } + # This is the format for the standard lead files + # employees,ticker_symbol,sic_code,revenue,account_name,address,po_box,city,state,post_code,phone_number,ownership,fax,email,other_phone,other_email,website + # 4,C03IMM001,39207955,2,ST MARK CHURCH,1710 W COLLEGE AVE,,CHICAGO,IL,61555,3095551111,PAUL SMITH,3095551212,TEST@VERIZON.NET,7775553333,test@1034.com,bigsite.com + else + { + $employees = $m[0]; chomp($employees); $employees =~ s/\D//gi; + $ticker_symbol = $m[1]; chomp($ticker_symbol); + $sic_code = $m[2]; chomp($sic_code); + $revenue = $m[3]; chomp($revenue); $revenue =~ s/\D//gi; + $account_name = $m[4]; chomp($account_name); + if (length($account_name)<1) {$account_name='NONE';} + $address = $m[5]; chomp($address); + $po_box = $m[6]; chomp($po_box); + $city = $m[7]; chomp($city); + $state = $m[8]; chomp($state); + $post_code = $m[9]; chomp($post_code); + $phone_number = $m[10]; chomp($phone_number); $phone_number =~ s/\D//gi; + $ownership = $m[11]; chomp($ownership); + $fax = $m[12]; chomp($fax); + $email = $m[13]; chomp($email); + $other_phone = $m[14]; chomp($other_phone); + $other_email = $m[15]; chomp($other_email); + $website = $m[16]; chomp($website); + if (length($website)<3) {$website="$sic_code-$revenue";} + $country = 'USA'; + } + + if ($DBX) {print "$a|$phone_number|$account_name|$website\n";} + + $dup_lead=0; + ##### Check for duplicate phone numbers in vtiger_account table ##### + if ($dupchecksys > 0) + { + $stmtB="SELECT count(*) from vtiger_account where phone='$phone_number';"; + if($DBX){print STDERR "\n|$stmtB|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $dup_lead = $aryB[0]; + } + $sthB->finish(); + } + ##### Check for duplicate sic code acct ID in vtiger_account table ##### + if ($dupchecksic > 0) + { + $stmtB="SELECT count(*) from vtiger_account where siccode='$sic_code';"; + if($DBX){print STDERR "\n|$stmtB|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $dup_lead = $aryB[0]; + } + $sthB->finish(); + } + ##### Check for duplicate website in vtiger_account table ##### + if ($dupcheckweb > 0) + { + $stmtB="SELECT count(*) from vtiger_account where website='$website';"; + if($DBX){print STDERR "\n|$stmtB|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $dup_lead = $aryB[0]; + } + $sthB->finish(); + } + + if ( (length($phone_number)>6) && ($dup_lead < 1) ) + { + $user='6666'; + + #Get logged in user ID + $stmtB="SELECT id from vtiger_users where user_name='$user';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $user_id = $aryB[0]; + } + $sthB->finish(); + + # Get current ID from vtiger_crmentity_seq + $stmtB="SELECT id from vtiger_crmentity_seq;"; + if($DBX){print STDERR "\n|$stmtB|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $crm_id = ($aryB[0] + 1); + } + $sthB->finish(); + + ### update the crm ID ### + $stmtB = "UPDATE vtiger_crmentity_seq SET id = '$crm_id';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + ### insert record into crmentity table ### + $stmtB = "INSERT INTO vtiger_crmentity SET crmid='$crm_id',smcreatorid='$user_id',smownerid='$user_id',modifiedby='$user_id',setype='Accounts',description='',createdtime='$NOW_TIME',modifiedtime='$NOW_TIME', viewedtime='$NOW_TIME';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + ### insert record into vtiger_account table ### + $stmtB = "INSERT INTO vtiger_account SET accountid='$crm_id',accountname='$account_name',account_type='Customer',industry='--None--',annualrevenue='$revenue',rating='--None--',ownership='$ownership',siccode='$sic_code',tickersymbol='$ticker_symbol',phone='$phone_number',otherphone='$other_phone',email1='$email',email2='$other_email',website='$website',fax='$fax',employees='$employees';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + ### insert record into vtiger_accountbillads table ### + $stmtB = "INSERT INTO vtiger_accountbillads SET accountaddressid='$crm_id',bill_city='$city',bill_code='$post_code',bill_country='$country',bill_state='$state',bill_street='$address',bill_pobox='$po_box';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + ### insert record into vtiger_accountscf table ### + $stmtB = "INSERT INTO vtiger_accountscf SET accountid='$crm_id';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + ### insert record into vtiger_accountshipads table ### + $stmtB = "INSERT INTO vtiger_accountshipads SET accountaddressid='$crm_id',ship_city='',ship_code='',ship_country='',ship_state='',ship_street='',ship_pobox='';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + ### insert record into vtiger_tracker table ### + $stmtB = "INSERT INTO vtiger_tracker SET user_id='$user_id',module_name='Accounts',item_id='$crm_id',item_summary='$account_name';"; + if (!$T) {$affected_rows = $dbhB->do($stmtB); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtB|\n";} + + $b++; + } + else + { + if ($dup_lead > 0) + {print "DUPLICATE: $phone_number|$sic_code|$website|$a\n"; $f++;} + else + {print "BAD Phone Number: $phone_number|$vendor_id|$a\n"; $e++;} + } + + $a++; + + if ($a =~ /100$/i) {print STDERR "0 $a\r";} + if ($a =~ /200$/i) {print STDERR "+ $a\r";} + if ($a =~ /300$/i) {print STDERR "| $a\r";} + if ($a =~ /400$/i) {print STDERR "\\ $a\r";} + if ($a =~ /500$/i) {print STDERR "- $a\r";} + if ($a =~ /600$/i) {print STDERR "/ $a\r";} + if ($a =~ /700$/i) {print STDERR "| $a\r";} + if ($a =~ /800$/i) {print STDERR "+ $a\r";} + if ($a =~ /900$/i) {print STDERR "0 $a\r";} + if ($a =~ /000$/i) {print "$a|$b|$c|$d|$e|$f|$g|$phone_number|\n";} + } + + + + ### open the stats out file for writing ### + open(Sout, ">>$VDHLOGfile") + || die "Can't open $VDHLOGfile: $!\n"; + + + ### close file handler and DB connections ### + $Falert = "\n\nTOTALS FOR $FILEname:\n"; + $Falert .= "Lines in file: $a\n"; + $Falert .= "INSERTED: $b\n"; + $Falert .= "INSERT STATEMENTS: $c\n"; + $Falert .= "ERROR: $e\n"; + $Falert .= "MULTI-ALT-PHONE: $g\n"; + if ($f > 0) + {$Falert .= "DUPLICATES: $f\n";} + + print "$Falert"; + print Sout "$Falert"; + $Ealert .= "$Falert"; + + close(infile); + close(Sout); + chmod 0777, "$VDHLOGfile"; + + ### Move file to the DONE directory locally + if (!$T) {`mv -f $dir1/$FILEname $dir2/$FILEname`;} + + } + } + $i++; + } + + +$dbhA->disconnect(); + +### calculate time to run script ### +$secY = time(); +$secZ = ($secY - $secX); +$secZm = ($secZ /60); + +if ($q < 1) + { + print "script execution time in seconds: $secZ minutes: $secZm\n"; + } + +###### EMAIL SECTION + +if ( (length($Ealert)>5) && (length($email_list) > 3) ) + { + print "Sending email: $email_list\n"; + + use MIME::QuotedPrint; + use MIME::Base64; + use Mail::Sendmail; + + $mailsubject = "VTIGER ACCOUNT FILE LOAD $pulldate0"; + + %mail = ( To => "$email_list", + From => "$email_sender", + Subject => "$mailsubject", + Message => "VTIGER ACCOUNT FILE LOAD $pulldate0\n\n$Ealert\n" + ); + sendmail(%mail) or die $mail::Sendmail::error; + print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status + } + +exit; + diff --git a/agc_2-X/trunk/bin/Vtiger_OUT_sync2VICIDIAL_file.pl b/agc_2-X/trunk/bin/Vtiger_OUT_sync2VICIDIAL_file.pl new file mode 100644 index 00000000..edec9726 --- /dev/null +++ b/agc_2-X/trunk/bin/Vtiger_OUT_sync2VICIDIAL_file.pl @@ -0,0 +1,491 @@ +#!/usr/bin/perl +# +# Vtiger_OUT_sync2VICIDIAL_file.pl version 2.0.5 *DBI-version* +# +# DESCRIPTION: +# script exports all accounts from the vtiger system table from a PIPE-formatted +# file that is in the proper format for VICIDIAL. (for format see --help) +# +# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 +# +# +# CHANGES +# 90128-0319 - First build +# + +$secX = time(); +$MT[0]=''; +$Ealert=''; + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($hour < 10) {$hour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +$pulldate0 = "$year-$mon-$mday $hour:$min:$sec"; +$NOW_TIME = "$year-$mon-$mday $hour:$min:$sec"; +$VDLfile = "Vtiger_account_sync_file_$year$mon$mday$hour$min$sec"; +$inSD = $pulldate0; +$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); +$MT[0]=''; + + +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) + {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) + {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} + if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) + {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} + if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) + {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} + if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) + {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) ) + {$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) ) + {$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) ) + {$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) ) + {$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;} + $i++; + } + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + + +if (!$VDHLOGfile) {$VDHLOGfile = "$PATHlogs/newleads.$year-$mon-$mday";} + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help|-h/i) + { + print "allowed run time options:\n"; + print " [-q] = quiet\n"; + print " [-t] = test\n"; + print " [--debug] = debug output\n"; + print " [--format=standard] = ability to define a format, standard is default, formats allowed shown in examples\n"; + print " [--forcelistid=1234] = overrides the listID given in the file with the 1234\n"; + print " [--duplicate-system-check] = checks for the same phone number in the entire system before inserting lead\n"; + print " [--duplicate-system-vendor] = checks for the same website in the entire system before inserting lead\n"; + print " [--ftp-pull] = grabs lead files from a remote FTP server, uses REPORTS FTP login information\n"; + print " [--ftp-dir=leads_in] = remote FTP server directory to grab files from, should have a DONE sub-directory\n"; + print " [--email-list=test@test.com:test2@test.com] = send email results for each file to these addresses\n"; + print " [--email-sender=vicidial@localhost] = sender for the email results\n"; + print " [-h] = this help screen\n\n"; + print "\n"; + print "This script takes in account CSV files in the following order when they are placed in the $PATHhome/VTIGER_IN directory to be imported into the vtiger system (examples):\n\n"; + print "standard:\n"; + print "vendor_lead_code|source_code|list_id|phone_code|phone_number|title|first_name|middle|last_name|address1|address2|address3|city|state|province|postal_code|country|gender|date_of_birth|alt_phone|email|security_phrase|COMMENTS|called_count|status|entry_date\n"; + print "3857822|31022|99|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS|2|B|2007-08-09 00:00:00|7275551212_1_work!7275551213_61_sister house!7275551214_44_neighbor\n\n"; + + exit; + } + else + { + if ($args =~ /-debug/i) + { + $DB=1; + print "\n----- DEBUGGING -----\n\n"; + } + if ($args =~ /-debugX/i) + { + $DBX=1; + print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; + } + else {$DBX=0;} + + if ($args =~ /-q/i) + { + $q=1; + } + if ($args =~ /-t/i) + { + $T=1; + $TEST=1; + print "\n----- TESTING -----\n\n"; + } + + if ($args =~ /-format=/i) + { + @data_in = split(/-format=/,$args); + $format = $data_in[1]; + $format =~ s/ .*//gi; + print "\n----- FORMAT OVERRIDE: $format -----\n\n"; + } + else + {$format = 'standard';} + + if ($args =~ /-forcelistid=/i) + { + @data_in = split(/-forcelistid=/,$args); + $forcelistid = $data_in[1]; + $forcelistid =~ s/ .*//gi; + print "\n----- FORCE LISTID OVERRIDE: $forcelistid -----\n\n"; + } + else + {$forcelistid = '';} + + if ($args =~ /-duplicate-system-check/i) + { + $dupchecksys=1; + print "\n----- DUPLICATE SYSTEM CHECK PHONE -----\n\n"; + } + if ($args =~ /-duplicate-system-vendor/i) + { + $dupcheckvend=1; + print "\n----- DUPLICATE SYSTEM CHECK VENDOR -----\n\n"; + } + if ($args =~ /-ftp-pull/i) + { + $ftp_pull=1; + print "\n----- FTP LEAD FILE PULL -----\n\n"; + } + if ($args =~ /--ftp-dir=/i) + { + @data_in = split(/--ftp-dir=/,$args); + $ftp_dir = $data_in[1]; + $ftp_dir =~ s/ .*//gi; + print "\n----- REMOTE FTP DIRECTORY: $ftp_dir -----\n\n"; + } + else + {$ftp_dir = '';} + + if ($args =~ /--email-list=/i) + { + @data_in = split(/--email-list=/,$args); + $email_list = $data_in[1]; + $email_list =~ s/ .*//gi; + $email_list =~ s/:/,/gi; + print "\n----- EMAIL NOTIFICATION: $email_list -----\n\n"; + } + else + {$email_list = '';} + + if ($args =~ /--email-sender=/i) + { + @data_in = split(/--email-sender=/,$args); + $email_sender = $data_in[1]; + $email_sender =~ s/ .*//gi; + $email_sender =~ s/:/,/gi; + print "\n----- EMAIL NOTIFICATION SENDER: $email_sender -----\n\n"; + } + else + {$email_sender = 'vicidial@localhost';} + + } + } +else + { + print "no command line options set\n"; + $args = ""; + $i=0; + $forcelistid = ''; + $format='standard'; + } +### end parsing run-time options ### + +if ($q < 1) + { + print "\n\n\n\n\n\n\n\n\n\n\n\n-- Vtiger_OUT_sync2VICIDIAL_file.pl --\n\n"; + print "This program is designed to export a PIPE delimited file of the Accounts from Vtiger and format it for import into the VICIDIAL system. \n\n"; + } + +$i=0; +$US = '_'; +$phone_list = '|'; + +if (!$VARDB_port) {$VARDB_port='3306';} + +use DBI; + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmtA = "SELECT use_non_latin,vtiger_server_ip,vtiger_dbname,vtiger_login,vtiger_pass FROM system_settings;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $non_latin = "$aryA[0]"; + $vtiger_server_ip = "$aryA[1]"; + $vtiger_dbname = "$aryA[2]"; + $vtiger_login = "$aryA[3]"; + $vtiger_pass = "$aryA[4]"; + } +$sthA->finish(); +##### END SETTINGS LOOKUP ##### +########################################### + +$dbhB = DBI->connect("DBI:mysql:$vtiger_dbname:$vtiger_server_ip:$VARDB_port", "$vtiger_login", "$vtiger_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +if ($non_latin > 0) {$affected_rows = $dbhA->do("SET NAMES 'UTF8'");} + +$list_id = '999'; +$phone_code = '1'; +$suf = '.txt'; +$people_packages_id_update=''; +$dir1 = "$PATHhome/LEADS_IN"; +$dir2 = "$PATHhome"; + +if($DBX){print STDERR "\nLEADS_IN directory: |$dir1|\n";} + + +$i=0; ### each Account counter ### +$b=0; ### status of 'APPROVED' counter ### +$c=0; ### status of 'DECLINED' counter ### +$d=0; ### status of 'REFERRED' counter ### +$e=0; ### status of 'DUPLICATE' vendor counter ### +$f=0; ### number of 'DUPLICATE' phone counter ### +$g=0; ### number of leads with multi-alt-entries + + +### open the output file for writing ### +open(out, ">$dir2/$VDLfile") + || die "Can't open $VDLfile: $!\n"; + + + + + +### Gather all non-deleted Accounts in Vtiger +$stmtB="SELECT crmid from vtiger_crmentity where setype='Accounts' and deleted='0' order by crmid limit 3000000;"; +$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; +$sthB->execute or die "executing: $stmtB ", $dbhB->errstr; +$sthBrowsC=$sthB->rows; +$i=0; +while ($sthBrowsC > $i) + { + @aryB = $sthB->fetchrow_array; + $crmid[$i] = $aryB[0]; + $i++; + } +$sthB->finish(); + +### Gather all account info and address info on those accounts, also checking for duplicates in vicidial_list if selected +$i=0; +while ($sthBrowsC > $i) + { + $VL_dup=0; + $VL_phone_dup=0; + + $stmtB="SELECT accountname,ownership,siccode,annualrevenue,tickersymbol,phone,otherphone,fax,email1,website from vtiger_account where accountid='$crmid[$i]';"; + if($DBX){print STDERR "\n|$stmtB|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $accountname = $aryB[0]; + $ownership = $aryB[1]; + $siccode = $aryB[2]; + $annualrevenue = $aryB[3]; + $tickersymbol = $aryB[4]; + $phone = $aryB[5]; + $otherphone = $aryB[6]; + $fax = $aryB[7]; + $email1 = $aryB[8]; + $website = $aryB[9]; + } + $sthB->finish(); + + $stmtB="SELECT bill_city,bill_code,bill_country,bill_state,bill_street,bill_pobox from vtiger_accountbillads where accountaddressid='$crmid[$i]';"; + if($DBX){print STDERR "\n|$stmtB|\n";} + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $sthBrows=$sthB->rows; + if ($sthBrows > 0) + { + @aryB = $sthB->fetchrow_array; + $bill_city = $aryB[0]; + $bill_code = $aryB[1]; + $bill_country = $aryB[2]; + $bill_state = $aryB[3]; + $bill_street = $aryB[4]; + $bill_pobox = $aryB[5]; + } + $sthB->finish(); + + if ($dupchecksys > 0) + { + $stmtA = "SELECT count(*) FROM vicidial_list where phone_number='$phone';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_phone_dup = "$aryA[0]"; + } + $sthA->finish(); + } + if ($dupcheckvend > 0) + { + $stmtA = "SELECT count(*) FROM vicidial_list where vendor_lead_code='$crmid[$i]';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_dup = "$aryA[0]"; + } + $sthA->finish(); + } + + if ($VL_phone_dup > 0) + { + if($DB){print "DUPLICATE PHONE: $phone|$crmid[$i]\n";} + $f++; + $affected_rowsA=0; + ### update the existing vicidial_list entry ### + $stmtA = "UPDATE vicidial_list SET first_name='$accountname',last_name='$ownership',address1='$bill_street',address2='$bill_pobox',city='$bill_city',state='$bill_state',postal_code='$bill_code',country='$bill_country',vendor_lead_code='$crmid[$i]',address3='$fax',alt_phone='$otherphone',email='$email1',province='$website',security_phrase='$tickersymbol',comments='$siccode|$annualrevenue' where phone_number='$phone' limit 1;"; + if (!$T) {$affected_rowsA = $dbhA->do($stmtA); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rowsA|$stmtA|\n";} + $c = ($affected_rowsA + $c); + } + else + { + if ($VL_dup > 0) + { + if($DB){print "DUPLICATE VENDOR_ID: $crmid[$i]\n";} + $e++; + $affected_rowsA=0; + ### update the existing vicidial_list entry ### + $stmtA = "UPDATE vicidial_list SET first_name='$accountname',last_name='$ownership',address1='$bill_street',address2='$bill_pobox',city='$bill_city',state='$bill_state',postal_code='$bill_code',country_code='$bill_country',phone_number='$phone',address3='$fax',alt_phone='$otherphone',email='$email1',province='$website',security_phrase='$tickersymbol',comments='$siccode $annualrevenue' where vendor_lead_code='$crmid[$i]' limit 1;"; + if (!$T) {$affected_rowsA = $dbhA->do($stmtA); } # or die "Couldn't execute query: |$stmtB|\n"; + if($DB){print STDERR "\n|$affected_rowsA|$stmtA|\n";} + $c = ($affected_rowsA + $c); + } + else + { + ### print the output file in proper format + print out "$crmid[$i]||$list_id|$phone_code|$phone||$accountname||$ownership|$bill_street|$bill_pobox|$fax|$bill_city|$bill_state|$website|$bill_code|$bill_country|||$otherphone|$email1|$ticketsymbol|$siccode $annualrevenue\n"; + $b++; + } + } + + $i++; + + if ($i =~ /10$/i) {print STDERR "0 $i\r";} + if ($i =~ /20$/i) {print STDERR "+ $i\r";} + if ($i =~ /30$/i) {print STDERR "| $i\r";} + if ($i =~ /40$/i) {print STDERR "\\ $i\r";} + if ($i =~ /50$/i) {print STDERR "- $i\r";} + if ($i =~ /60$/i) {print STDERR "/ $i\r";} + if ($i =~ /70$/i) {print STDERR "| $i\r";} + if ($i =~ /80$/i) {print STDERR "+ $i\r";} + if ($i =~ /90$/i) {print STDERR "0 $i\r";} + if ($i =~ /00$/i) {print "$i|$b|$c|$d|$e|$f|$g|$crmid[$i]|$phone_number|\n";} + } + + + + ### open the stats out file for writing ### + open(Sout, ">>$VDHLOGfile") + || die "Can't open $VDHLOGfile: $!\n"; + + + ### close file handler and DB connections ### + $Falert = "\n\nTOTALS FOR $FILEname:\n"; + $Falert .= "Records in System: $i\n"; + $Falert .= "LINES OUTPUTED: $b\n"; + $Falert .= "LIVE VL UPDATE: $c\n"; + $Falert .= "ERROR: $e\n"; +# $Falert .= "MULTI-ALT-PHONE: $g\n"; + if ($e > 0) + {$Falert .= "VENDOR DUPLICATES: $e\n";} + if ($f > 0) + {$Falert .= "PHONE DUPLICATES: $f\n";} + + print "$Falert"; + print Sout "$Falert"; + $Ealert .= "$Falert"; + + close(out); + close(Sout); + chmod 0777, "$VDHLOGfile"; + + ### Move file to the LEADS_IN directory locally + if (!$T) {`mv -f $dir2/$VDLfile $dir1/$VDLfile`;} + + +$dbhA->disconnect(); +$dbhB->disconnect(); + +### calculate time to run script ### +$secY = time(); +$secZ = ($secY - $secX); +$secZm = ($secZ /60); + +if ($q < 1) + { + print "script execution time in seconds: $secZ minutes: $secZm\n"; + } + +###### EMAIL SECTION + +if ( (length($Ealert)>5) && (length($email_list) > 3) ) + { + print "Sending email: $email_list\n"; + + use MIME::QuotedPrint; + use MIME::Base64; + use Mail::Sendmail; + + $mailsubject = "VTIGER ACCOUNT FILE LOAD $pulldate0"; + + %mail = ( To => "$email_list", + From => "$email_sender", + Subject => "$mailsubject", + Message => "VTIGER ACCOUNT FILE LOAD $pulldate0\n\n$Ealert\n" + ); + sendmail(%mail) or die $mail::Sendmail::error; + print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status + } + +exit; + diff --git a/agc_2-X/trunk/docs/AGENT_API.txt b/agc_2-X/trunk/docs/AGENT_API.txt index 11518a07..e5ffdf7a 100644 --- a/agc_2-X/trunk/docs/AGENT_API.txt +++ b/agc_2-X/trunk/docs/AGENT_API.txt @@ -134,7 +134,8 @@ preview - focus - YES - change the focus of the screen to the vicidial.php agent interface NO - do not change focus - +vendor_id - + Any valid Vendor lead code RESPONSES: ERROR: external_dial not valid - 7275551212|1|YES|6666 diff --git a/agc_2-X/trunk/docs/NON-AGENT_API.txt b/agc_2-X/trunk/docs/NON-AGENT_API.txt index 7302c86c..e7f87e25 100644 --- a/agc_2-X/trunk/docs/NON-AGENT_API.txt +++ b/agc_2-X/trunk/docs/NON-AGENT_API.txt @@ -88,13 +88,13 @@ The multi-alt-phones field is formatted as a field of phone-number/phone-code/ph Example URL strings for API calls: -http://server/vicidial/non_agent_api.php?user=6666&pass=1234&function=add_lead&phone_number=7275551111 +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=add_lead&phone_number=7275551111 -http://server/vicidial/non_agent_api.php?user=6666&pass=1234&function=add_lead&phone_number=7275551212&phone_code=1&list_id=999&dnc_check=N&first_name=Bob&last_name=Wilson +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=add_lead&phone_number=7275551212&phone_code=1&list_id=999&dnc_check=N&first_name=Bob&last_name=Wilson -http://server/vicidial/non_agent_api.php?user=6666&pass=1234&function=add_lead&phone_number=7275551111&phone_code=1&list_id=999&dnc_check=N&first_name=Bob&last_name=Wilson&add_to_hopper=Y&hopper_local_call_time_check=Y +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=add_lead&phone_number=7275551111&phone_code=1&list_id=999&dnc_check=N&first_name=Bob&last_name=Wilson&add_to_hopper=Y&hopper_local_call_time_check=Y -http://server/vicidial/non_agent_api.php?user=6666&pass=1234&function=add_lead&phone_number=7275551111&phone_code=1&list_id=999&dnc_check=N&campaign_dnc_check=Y&campaign_id=TESTCAMP&first_name=Bob&last_name=Wilson&address1=1234+Main+St.&city=Chicago+Heights&state=IL&add_to_hopper=Y&hopper_local_call_time_check=Y&multi_alt_phones=7275551212_1_work!7275551213_1_sister+house!1234567890_1_neighbor +http://server/vicidial/non_agent_api.php?source=test&user=6666&pass=1234&function=add_lead&phone_number=7275551111&phone_code=1&list_id=999&dnc_check=N&campaign_dnc_check=Y&campaign_id=TESTCAMP&first_name=Bob&last_name=Wilson&address1=1234+Main+St.&city=Chicago+Heights&state=IL&add_to_hopper=Y&hopper_local_call_time_check=Y&multi_alt_phones=7275551212_1_work!7275551213_1_sister+house!1234567890_1_neighbor Example responses: diff --git a/agc_2-X/trunk/docs/VTIGER.txt b/agc_2-X/trunk/docs/VTIGER.txt index 93d24aad..2a30b8a2 100644 --- a/agc_2-X/trunk/docs/VTIGER.txt +++ b/agc_2-X/trunk/docs/VTIGER.txt @@ -4,9 +4,14 @@ Current VICIDIAL integration with Vtiger is for the 5.0.4 release version of Vti Current integration features: - vicidial.php WEBFORM search for lead/account/vendor -- user synchronization of VICIDIAL users to Vtiger user database -- added activity event option(call logging in Vtiger) when going from VICIDIAL to Vtiger -- added ability to click-to-dial a phone number from a record in Vtiger screen to the vicidial.php screen +- User synchronization of VICIDIAL users to Vtiger user database +- Added activity event option(call logging in Vtiger) when going from VICIDIAL to Vtiger +- Ability to click-to-dial a phone number from a record in Vtiger screen to the vicidial.php screen +- Optional script to bulk load leads into Vtiger from a CSV file since Vtiger only seems to want to load 500 at a time: + Vtiger_IN_new_accounts_file.pl +- Batch Account synchronization through script to output new leads from Vtiger and update existing leads in the VICIDIAL system: + Vtiger_OUT_sync2VICIDIAL_file.pl then you run the VICIDIAL_IN_new_leads_file.pl script to load the new leads + There has been a basic vtiger integration option available in VICIDIAL since the 1.X release versions through the vtiger_search.php web script(when used as a web form in the campaign) that will search through the leads for the dialed phone number in vicidial.php and if it is not in the vtiger system as a lead then it will be put in as a new lead. @@ -23,6 +28,18 @@ There are options in the VICIDIAL Modify Campaign Detail screen that you can cho NOTE: For this to work, you must have the vtiger_search.php set as your webform page, i.e.(http://10.10.10.15/vicidial/vtiger_search.php) Multiple search options can be used for each campaign(in the VICIDIAL Campaign Detail screen), but on large databases this is not recommended. Default is LEAD. The order that you see the searching options above is the order in which they will be searched if you have selected multiple searching methods. If an account does not exist and you have LEAD selected as a search method, then(if the create lead option is enabled) it will insert the lead with that phone number and you will be taken to the edit screen for that lead when you go to the vtiger_search web page. There is also an option to log the call as an event in Vtiger that will associate with the Lead or Account that the agent screen is sent to. Vtiger recommends on standard equipment a limit of 50,000 account records, but many users report no issues with 100,000 or more account records in their Vtiger systems. + +Here are the procedures to load leads into Vtiger, then output them from Vtiger and then load them into VICIDIAL: +(the vicidial_list.vendor_lead_code field[=vtiger_accounts.accountid] is used as a key between systems) +- put properly formatted CSV file into /usr/share/astguiclient/VTIGER_IN/ +- /usr/share/astguiclient/Vtiger_IN_new_accounts_file.pl --duplicate-system-website +- /usr/share/astguiclient/Vtiger_OUT_sync2VICIDIAL_file.pl --duplicate-system-vendor +- /usr/share/astguiclient/VICIDIAL_IN_new_leads_file.pl --forcelistid=9988 + +Then to keep the two systems in sync you would run the last two steps every day or at some other interval. + + + Here are the SQL queries used by the vtiger_search.php script to find records in the vtiger system: ACCTID: diff --git a/agc_2-X/trunk/extras/Vtiger504_vicidial.patch b/agc_2-X/trunk/extras/Vtiger504_vicidial.patch index ed36179b..b353de88 100644 --- a/agc_2-X/trunk/extras/Vtiger504_vicidial.patch +++ b/agc_2-X/trunk/extras/Vtiger504_vicidial.patch @@ -119,12 +119,12 @@ + $log->debug('Current user is: '.$current_user->user_name); + } + -+ $phone = $_REQUEST['phone']; ++ $phone = $_REQUEST['phone']; $vendor_id = $_REQUEST['vendor_id']; + $user = $current_user->user_name; + + $VCapiURL = "/agc/api.php"; + $VCpauseQuery = "?source=vtiger&user=1000&pass=1234&agent_user=$user&function=external_pause&value=PAUSE"; -+ $VCcallQuery = "?source=vtiger&user=1000&pass=1234&agent_user=$user&function=external_dial&value=$phone&phone_code=1&search=YES&preview=NO&focus=YES"; ++ $VCcallQuery = "?source=vtiger&user=1000&pass=1234&agent_user=$user&function=external_dial&value=$phone&phone_code=1&search=YES&preview=NO&focus=YES&vendor_id=$vendor_id"; + $replyP = file("$URLbase$VCapiURL$VCpauseQuery"); +// sleep(1); + $replyC = file("$URLbase$VCapiURL$VCcallQuery"); @@ -185,7 +185,7 @@ + } +if (xmlhttp) + { -+ var VCcallQuery = "VCcall=1&phone=" + phone; ++ var VCcallQuery = "VCcall=1&phone=" + phone + "&vendor_id=" + record_id; + xmlhttp.open('POST', 'vtigerservice.php'); + xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8'); + xmlhttp.send(VCcallQuery); diff --git a/agc_2-X/trunk/install.pl b/agc_2-X/trunk/install.pl index 49d5ce6e..26969fd4 100644 --- a/agc_2-X/trunk/install.pl +++ b/agc_2-X/trunk/install.pl @@ -2109,6 +2109,9 @@ if ($WEBONLY < 1) `mkdir -p $PATHhome/LEADS_IN`; `mkdir -p $PATHhome/LEADS_IN/DONE`; `chmod -R 0766 $PATHhome/LEADS_IN`; + `mkdir -p $PATHhome/VTIGER_IN`; + `mkdir -p $PATHhome/VTIGER_IN/DONE`; + `chmod -R 0766 $PATHhome/VTIGER_IN`; print "Creating $PATHmonitor directories...\n"; `mkdir -p $PATHmonitor`; diff --git a/agc_2-X/trunk/www/agc/api.php b/agc_2-X/trunk/www/agc/api.php index c2be8a92..49db9b83 100644 --- a/agc_2-X/trunk/www/agc/api.php +++ b/agc_2-X/trunk/www/agc/api.php @@ -12,7 +12,7 @@ # - $agent_user # - $function - ('external_hangup','external_status','external_pause') # - $value -# - $value_a +# - $vendor_id # - $focus # - $preview # - $notes @@ -25,10 +25,11 @@ # 80703-2225 - First build of script # 90116-1229 - Added external_pause and external_dial functions # 90118-1051 - Added logging of API functions +# 90128-0229 - Added vendor_id to dial function # -$version = '2.0.5-3'; -$build = '90118-1051'; +$version = '2.0.5-4'; +$build = '90128-0229'; require("dbconnect.php"); @@ -43,8 +44,8 @@ if (isset($_GET["function"])) {$function=$_GET["function"];} elseif (isset($_POST["function"])) {$function=$_POST["function"];} if (isset($_GET["value"])) {$value=$_GET["value"];} elseif (isset($_POST["value"])) {$value=$_POST["value"];} -if (isset($_GET["value_a"])) {$value_a=$_GET["value_a"];} - elseif (isset($_POST["value_a"])) {$value_a=$_POST["value_a"];} +if (isset($_GET["vendor_id"])) {$vendor_id=$_GET["vendor_id"];} + elseif (isset($_POST["vendor_id"])) {$vendor_id=$_POST["vendor_id"];} if (isset($_GET["focus"])) {$focus=$_GET["focus"];} elseif (isset($_POST["focus"])) {$focus=$_POST["focus"];} if (isset($_GET["preview"])) {$preview=$_GET["preview"];} @@ -88,7 +89,7 @@ $pass=ereg_replace("[^0-9a-zA-Z]","",$pass); $agent_user=ereg_replace("[^0-9a-zA-Z]","",$agent_user); $function = ereg_replace("[^-\_0-9a-zA-Z]","",$function); $value = ereg_replace("[^-\_0-9a-zA-Z]","",$value); -$value_a = ereg_replace("[^-\_0-9a-zA-Z]","",$value_a); +$vendor_id = ereg_replace("[^-\_0-9a-zA-Z]","",$vendor_id); $focus = ereg_replace("[^-\_0-9a-zA-Z]","",$focus); $preview = ereg_replace("[^-\_0-9a-zA-Z]","",$preview); $notes = ereg_replace("\+"," ",$notes); @@ -397,12 +398,12 @@ if ($function == 'external_dial') $row=mysql_fetch_row($rslt); if ($row[0] > 0) { - $stmt="UPDATE vicidial_live_agents set external_dial='$value!$phone_code!$search!$preview!$focus!$epoch' where user='$agent_user';"; + $stmt="UPDATE vicidial_live_agents set external_dial='$value!$phone_code!$search!$preview!$focus!$vendor_id!$epoch' where user='$agent_user';"; if ($format=='debug') {echo "\n";} $rslt=mysql_query($stmt, $link); $result = 'SUCCESS'; $result_reason = "external_dial function set"; - $data = "$phone_code|$search|$preview|$focus|$epoch"; + $data = "$phone_code|$search|$preview|$focus|$vendor_id|$epoch"; echo "$result: $result_reason - $value|$agent_user|$data\n"; api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data); } diff --git a/agc_2-X/trunk/www/agc/vdc_db_query.php b/agc_2-X/trunk/www/agc/vdc_db_query.php index 80d5ae31..3da4bfe3 100644 --- a/agc_2-X/trunk/www/agc/vdc_db_query.php +++ b/agc_2-X/trunk/www/agc/vdc_db_query.php @@ -182,10 +182,11 @@ # 81211-0420 - Fixed Manual dial agent_log bug # 90120-1718 - Added external pause and dial option # 90126-1759 - Fixed QM section that wasn't qualified and added agent alert option +# 90128-0231 - Aded vendor_lead_code to manual dial lead lookup # -$version = '2.0.5-99'; -$build = '90126-1759'; +$version = '2.0.5-100'; +$build = '90128-0231'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=185; $one_mysql_log=0; @@ -745,11 +746,24 @@ if ($ACTION == 'manDiaLnextCaLL') } if ($stage=='lookup') { - $stmt="SELECT lead_id FROM vicidial_list where phone_number='$phone_number' order by modify_date desc LIMIT 1;"; - $rslt=mysql_query($stmt, $link); - if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);} - if ($DB) {echo "$stmt\n";} - $man_leadID_ct = mysql_num_rows($rslt); + if (strlen($vendor_lead_code)>0) + { + $stmt="SELECT lead_id FROM vicidial_list where vendor_lead_code='$vendor_lead_code' order by modify_date desc LIMIT 1;"; + $rslt=mysql_query($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);} + if ($DB) {echo "$stmt\n";} + $man_leadID_ct = mysql_num_rows($rslt); + if ( ($man_leadID_ct > 0) and (strlen($phone_number) > 5) ) + {$override_phone++;} + } + else + { + $stmt="SELECT lead_id FROM vicidial_list where phone_number='$phone_number' order by modify_date desc LIMIT 1;"; + $rslt=mysql_query($stmt, $link); + if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);} + if ($DB) {echo "$stmt\n";} + $man_leadID_ct = mysql_num_rows($rslt); + } if ($man_leadID_ct > 0) { $row=mysql_fetch_row($rslt); @@ -760,7 +774,7 @@ if ($ACTION == 'manDiaLnextCaLL') else { ### insert a new lead in the system with this phone number - $stmt = "INSERT INTO vicidial_list SET phone_code='$phone_code',phone_number='$phone_number',list_id='$list_id',status='QUEUE',user='$user',called_since_last_reset='Y',entry_date='$ENTRYdate',last_local_call_time='$NOW_TIME';"; + $stmt = "INSERT INTO vicidial_list SET phone_code='$phone_code',phone_number='$phone_number',list_id='$list_id',status='QUEUE',user='$user',called_since_last_reset='Y',entry_date='$ENTRYdate',last_local_call_time='$NOW_TIME',vendor_lead_code='$vendor_lead_code';"; if ($DB) {echo "$stmt\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00022',$user,$server_ip,$session_name,$one_mysql_log);} @@ -827,7 +841,8 @@ if ($ACTION == 'manDiaLnextCaLL') $gmt_offset_now = trim("$row[8]"); $called_since_last_reset = trim("$row[9]"); $phone_code = trim("$row[10]"); - $phone_number = trim("$row[11]"); + if ($override_phone < 1) + {$phone_number = trim("$row[11]");} $title = trim("$row[12]"); $first_name = trim("$row[13]"); $middle_initial = trim("$row[14]"); diff --git a/agc_2-X/trunk/www/agc/vicidial.php b/agc_2-X/trunk/www/agc/vicidial.php index 1f347b80..6c4fc077 100644 --- a/agc_2-X/trunk/www/agc/vicidial.php +++ b/agc_2-X/trunk/www/agc/vicidial.php @@ -215,10 +215,11 @@ # 90115-0619 - Added ability to send Local Closer to AGENTDIRECT agent_only # 90120-1719 - Added API pause/resume and number dial functionality # 90126-2302 - Added Vtiger login option and agent alert option +# 90128-0230 - Added vendor_lead_code to API dial and manuald dial with lookup # -$version = '2.0.5-194'; -$build = '90126-2302'; +$version = '2.0.5-195'; +$build = '90128-0230'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=53; $one_mysql_log=0; @@ -2802,16 +2803,17 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} if (APIDiaL.length > 8) { var APIDiaL_array_detail = APIDiaL.split("!"); - if (APIDiaL_ID == APIDiaL_array_detail[5]) + if (APIDiaL_ID == APIDiaL_array_detail[6]) { // alert("DiaL ALREADY RECEIVED: " + APIDiaL_ID + "|" + APIDiaL_array_detail[5]); } else { - APIDiaL_ID = APIDiaL_array_detail[5]; + APIDiaL_ID = APIDiaL_array_detail[6]; document.vicidial_form.MDDiaLCodE.value = APIDiaL_array_detail[1]; document.vicidial_form.phone_code.value = APIDiaL_array_detail[1]; document.vicidial_form.MDPhonENumbeR.value = APIDiaL_array_detail[0]; + document.vicidial_form.vendor_lead_code.value = APIDiaL_array_detail[5]; // alert(APIDiaL_array_detail[1] + "-----" + APIDiaL + "-----" + document.vicidial_form.MDDiaLCodE.value + "-----" + document.vicidial_form.phone_code.value); @@ -3664,6 +3666,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} var MDDiaLCodEform = document.vicidial_form.MDDiaLCodE.value; var MDPhonENumbeRform = document.vicidial_form.MDPhonENumbeR.value; var MDDiaLOverridEform = document.vicidial_form.MDDiaLOverridE.value; + var MDVendorLeadCode = document.vicidial_form.vendor_lead_code.value; var MDLookuPLeaD = 'new'; if (document.vicidial_form.LeadLookuP.checked==true) {MDLookuPLeaD = 'lookup';} @@ -3688,7 +3691,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} document.vicidial_form.LeadPreview.checked=true; document.vicidial_form.DiaLAltPhonE.checked=true; } - ManualDialNext("","",MDDiaLCodEform,MDPhonENumbeRform,MDLookuPLeaD); + ManualDialNext("","",MDDiaLCodEform,MDPhonENumbeRform,MDLookuPLeaD,MDVendorLeadCode); } document.vicidial_form.MDPhonENumbeR.value = ''; @@ -3701,6 +3704,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} { var MDDiaLCodEform = document.vicidial_form.phone_code.value; var MDPhonENumbeRform = document.vicidial_form.phone_number.value; + var MDVendorLeadCode = document.vicidial_form.vendor_lead_code.value; if ( (MDDiaLCodEform.length < 1) || (MDPhonENumbeRform.length < 5) ) { @@ -3720,7 +3724,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} buildDiv('DiaLDiaLAltPhonE'); document.vicidial_form.LeadPreview.checked=false; document.vicidial_form.DiaLAltPhonE.checked=true; - ManualDialNext("","",MDDiaLCodEform,MDPhonENumbeRform,MDLookuPLeaD); + ManualDialNext("","",MDDiaLCodEform,MDPhonENumbeRform,MDLookuPLeaD,MDVendorLeadCode); } } @@ -3891,7 +3895,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} // ################################################################################ // Send the Manual Dial Next Number request - function ManualDialNext(mdnCBid,mdnBDleadid,mdnDiaLCodE,mdnPhonENumbeR,mdnStagE) + function ManualDialNext(mdnCBid,mdnBDleadid,mdnDiaLCodE,mdnPhonENumbeR,mdnStagE,mdVendorid) { inOUT = 'OUT'; all_record = 'NO'; @@ -3942,9 +3946,9 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} } if (xmlhttp) { - manDiaLnext_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&ACTION=manDiaLnextCaLL&conf_exten=" + session_id + "&user=" + user + "&pass=" + pass + "&campaign=" + campaign + "&ext_context=" + ext_context + "&dial_timeout=" + dial_timeout + "&dial_prefix=" + dial_prefix + "&campaign_cid=" + campaign_cid + "&preview=" + man_preview + "&agent_log_id=" + agent_log_id + "&callback_id=" + mdnCBid + "&lead_id=" + mdnBDleadid + "&phone_code=" + mdnDiaLCodE + "&phone_number=" + mdnPhonENumbeR + "&list_id=" + mdnLisT_id + "&stage=" + mdnStagE + "&use_internal_dnc=" + use_internal_dnc + "&use_campaign_dnc=" + use_campaign_dnc + "&omit_phone_code=" + omit_phone_code + "&manual_dial_filter=" + manual_dial_filter; + manDiaLnext_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&ACTION=manDiaLnextCaLL&conf_exten=" + session_id + "&user=" + user + "&pass=" + pass + "&campaign=" + campaign + "&ext_context=" + ext_context + "&dial_timeout=" + dial_timeout + "&dial_prefix=" + dial_prefix + "&campaign_cid=" + campaign_cid + "&preview=" + man_preview + "&agent_log_id=" + agent_log_id + "&callback_id=" + mdnCBid + "&lead_id=" + mdnBDleadid + "&phone_code=" + mdnDiaLCodE + "&phone_number=" + mdnPhonENumbeR + "&list_id=" + mdnLisT_id + "&stage=" + mdnStagE + "&use_internal_dnc=" + use_internal_dnc + "&use_campaign_dnc=" + use_campaign_dnc + "&omit_phone_code=" + omit_phone_code + "&manual_dial_filter=" + manual_dial_filter + "&vendor_lead_code=" + mdVendorid; // alert(manual_dial_filter + "\n" +manDiaLnext_query); - xmlhttp.open('POST', 'vdc_db_query.php'); + xmlhttp.open('POST', 'vdc_db_query.php'); xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8'); xmlhttp.send(manDiaLnext_query); xmlhttp.onreadystatechange = function()