diff --git a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_VDonly.pl b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_VDonly.pl index 267cee4d..d85c5aff 100644 --- a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_VDonly.pl +++ b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_VDonly.pl @@ -29,6 +29,7 @@ # # # 80302-1958 - First Build +# 80731-2253 - Changed size comparisons for more efficiency # ### begin parsing run-time options ### @@ -127,6 +128,7 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second use DBI; $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") @@ -137,25 +139,39 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA $dir1 = "$PATHmonitor"; $dir2 = "$PATHDONEmonitor"; - opendir(FILE, "$dir1/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir1/"); +@FILES = readdir(FILE); + +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $INfile = $FILES[$i]; $OUTfile = $FILES[$i]; @@ -195,6 +211,9 @@ foreach(@FILES) if($DBX){print STDERR "\n|$stmtA|\n";} $affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n"; + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); + } } $i++; diff --git a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_mix.pl b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_mix.pl index 734471b2..1f6eea74 100644 --- a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_mix.pl +++ b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_1_move_mix.pl @@ -28,6 +28,7 @@ # # # 80302-1958 - First Build +# 80731-2253 - Changed size comparisons for more efficiency # ### begin parsing run-time options ### @@ -126,6 +127,7 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second use DBI; $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") @@ -158,25 +160,39 @@ else $dir1 = "$PATHmonitor"; $dir2 = "$PATHDONEmonitor"; - opendir(FILE, "$dir1/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir1/"); +@FILES = readdir(FILE); + +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $INfile = $FILES[$i]; $OUTfile = $FILES[$i]; @@ -213,6 +229,9 @@ foreach(@FILES) `mv -f "$dir1/$INfile" "$dir2/ORIG/$INfile"`; `mv -f "$dir1/$OUTfile" "$dir2/ORIG/$OUTfile"`; } + + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); } } $i++; diff --git a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_2_compress.pl b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_2_compress.pl index 55143ed0..aff16c24 100644 --- a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_2_compress.pl +++ b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_2_compress.pl @@ -29,6 +29,7 @@ # # # 80302-1958 - First Build +# 80731-2253 - Changed size comparisons for more efficiency # $GSM=0; $MP3=0; $OGG=0; @@ -151,7 +152,8 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} -use DBI; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second +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; @@ -194,25 +196,39 @@ if ($MP3 > 0) ### directory where -all recordings are $dir2 = "$PATHDONEmonitor"; - opendir(FILE, "$dir2/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir2/"); +@FILES = readdir(FILE); + +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $recording_id=''; $ALLfile = $FILES[$i]; @@ -279,6 +295,9 @@ foreach(@FILES) { `mv -f "$dir2/$ALLfile" "$dir2/ORIG/$ALLfile"`; } + + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); } } $i++; diff --git a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_3_ftp.pl b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_3_ftp.pl index 6cc14f0e..1e5d32c2 100644 --- a/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_3_ftp.pl +++ b/agc_2-X/branches/agc_2.0.4/bin/AST_CRON_audio_3_ftp.pl @@ -34,6 +34,7 @@ # # 80302-1958 - First Build # 80317-2349 - Added FTP debug if debugX +# 80731-2253 - Changed size comparisons for more efficiency # $GSM=0; $MP3=0; $OGG=0; $WAV=0; $NODATEDIR=0; @@ -178,7 +179,8 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} -use DBI; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second +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; @@ -192,25 +194,38 @@ if ($MP3 > 0) {$dir2 = "$PATHDONEmonitor/MP3";} if ($GSM > 0) {$dir2 = "$PATHDONEmonitor/GSM";} if ($OGG > 0) {$dir2 = "$PATHDONEmonitor/OGG";} - opendir(FILE, "$dir2/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir2/"); +@FILES = readdir(FILE); +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $recording_id=''; $ALLfile = $FILES[$i]; @@ -266,6 +281,10 @@ foreach(@FILES) } } ### END Remote file transfer + + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); + } } $i++; diff --git a/agc_2-X/branches/agc_2.0.4/bin/VICIDIAL_IN_new_leads_file.pl b/agc_2-X/branches/agc_2.0.4/bin/VICIDIAL_IN_new_leads_file.pl index 0f2afc4d..659eabb8 100644 --- a/agc_2-X/branches/agc_2.0.4/bin/VICIDIAL_IN_new_leads_file.pl +++ b/agc_2-X/branches/agc_2.0.4/bin/VICIDIAL_IN_new_leads_file.pl @@ -27,6 +27,7 @@ # 70815-2128 - Added entry_date to import leads format (field 26) # 80128-0105 - Fixed bugs in file loading # 80428-0320 - UTF8 update +# 80730-1607 - added minicsv format # $secX = time(); @@ -42,7 +43,7 @@ if ($mday < 10) {$mday = "0$mday";} $pulldate0 = "$year-$mon-$mday $hour:$min:$sec"; $inSD = $pulldate0; $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); - +$MT[0]=''; # default path to astguiclient configuration file: @@ -109,6 +110,7 @@ if (length($ARGV[0])>1) print " [-t] = test\n"; print " [--forcegmt] = forces gmt value of column after comments column\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 " [--forcephonecode=44] = overrides the phone_code given in the lead with the 44\n"; print " [--duplicate-check] = checks for the same phone number in the same list id before inserting lead\n"; @@ -117,9 +119,13 @@ if (length($ARGV[0])>1) print " [--postal-code-gmt] = checks for the time zone based on the postal code given where available\n"; print " [-h] = this help screen\n\n"; print "\n"; - print "This script takes in lead files in the following order when they are placed in the $PATHhome/LEADS_IN directory to be imported into the vicidial_list table:\n\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\n"; + print "This script takes in lead files in the following order when they are placed in the $PATHhome/LEADS_IN directory to be imported into the vicidial_list table (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|105|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS|2|B|2007-08-09 00:00:00\n\n"; + print "minicsv:\n"; + print "address1,city,name,phone_number,state,postal_code\n"; + print "\"105 Fifth St\",\"Steinhatchee\",\"Frank Smith\",\"3525556601\",\"FL\",\"32359\"\n\n"; exit; } @@ -160,6 +166,16 @@ if (length($ARGV[0])>1) else {$forcelistid = '';} + 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 =~ /--forcephonecode=/i) { @data_in = split(/--forcephonecode=/,$args); @@ -198,6 +214,7 @@ print "no command line options set\n"; $args = ""; $i=0; $forcelistid = ''; +$format='standard'; } ### end parsing run-time options ### @@ -300,7 +317,7 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC #if ($DB) while () { - + @m=@MT; # print "$a| $number\n"; $number = $_; chomp($number); @@ -318,10 +335,44 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC $number =~ s/\"//gi; @m = split(/\|/, $number); -# This is the format for the lead files + +# This is the format for the minicsv lead files +#"105 Fifth St","Steinhatchee","Frank Smith","3525556601","FL","32359" + if ($format=='minicsv') + { + @name=@MT; + $vendor_lead_code = ''; + $source_code = ''; + $list_id = '995'; + $phone_code = '1'; + $phone_number = $m[3]; chomp($phone_number); $phone_number =~ s/\D//gi; + $USarea = substr($phone_number, 0, 3); + $title = ''; + $full_name = $m[2]; @name = split(/ /, $full_name); + $first_name = $name[1]; chomp($first_name); + $last_name = "$name[0] $name[2]"; chomp($first_name); + $middle_initial = ''; + $address1 = $m[0]; chomp($address1); + $address2 = ''; + $address3 = ''; + $city = $m[1]; chomp($city); + $state = $m[4]; chomp($state); + $province = ''; + $postal_code = $m[5]; chomp($postal_code); + $country = 'USA'; + $gender = 'U'; + $date_of_birth = '0000-00-00'; + $alt_phone = ''; + $email = ''; + $security_phrase = ''; + $comments = ''; + $called_count = 0; + $status = 'NEW'; + } +# This is the format for the standard lead files #3857822|31022|105|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS - - + else + { $vendor_lead_code = $m[0]; chomp($vendor_lead_code); $source_code = $m[1]; chomp($source_code); $source_id = $source_code; $list_id = $m[2]; chomp($list_id); @@ -356,361 +407,362 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC $iD[1] = sprintf("%02d", $iD[1]); $insert_date = "$iD[2]-$iD[0]-$iD[1]"; } + } - if (length($forcelistid) > 0) - { - $list_id = $forcelistid; # set list_id to override value - } - if (length($forcephonecode) > 0) - { - $phone_code = $forcephonecode; # set phone_code to override value - } + if (length($forcelistid) > 0) + { + $list_id = $forcelistid; # set list_id to override value + } + if (length($forcephonecode) > 0) + { + $phone_code = $forcephonecode; # set phone_code to override value + } - ##### Check for duplicate phone numbers in vicidial_list table entire database ##### - if ($dupchecksys > 0) + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if ($dupchecksys > 0) + { + $dup_lead=0; + $stmtA = "select count(*) from vicidial_list where phone_number='$phone_number';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) { - $dup_lead=0; - $stmtA = "select count(*) from vicidial_list where phone_number='$phone_number';"; + @aryA = $sthA->fetchrow_array; + $dup_lead = $aryA[0]; + $dup_lead_list=$list_id; + } + $sthA->finish(); + if ($dup_lead < 1) + { + if ($phone_list =~ /\|$phone_number$US$list_id\|/) + {$dup_lead++;} + } + } + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if ($dupcheck > 0) + { + $dup_lead=0; + $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id='$list_id' limit 1;"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $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; + $dup_lead_list = $aryA[0]; + $dup_lead++; + } + $sthA->finish(); + if ($dup_lead < 1) + { + if ($phone_list =~ /\|$phone_number$US$list_id\|/) + {$dup_lead++;} + } + } + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### + if ($dupcheckcamp > 0) + { + $dup_lead=0; + $dup_lists=''; + + $stmtA = "select count(*) from vicidial_lists where list_id='$list_id';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + @aryA = $sthA->fetchrow_array; + $ci_recs = $aryA[0]; + $sthA->finish(); + if ($ci_recs > 0) + { + $stmtA = "select campaign_id from vicidial_lists where list_id='$list_id';"; if($DBX){print STDERR "\n|$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + @aryA = $sthA->fetchrow_array; + $dup_camp = $aryA[0]; + $sthA->finish(); + + $stmtA = "select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - if ($sthArows > 0) + $rec_count=0; + while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $dup_lead = $aryA[0]; - $dup_lead_list=$list_id; + $dup_lists .= "'$aryA[0]',"; + $rec_count++; } $sthA->finish(); - if ($dup_lead < 1) - { - if ($phone_list =~ /\|$phone_number$US$list_id\|/) - {$dup_lead++;} - } - } - ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### - if ($dupcheck > 0) - { - $dup_lead=0; - $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id='$list_id' limit 1;"; - if($DBX){print STDERR "\n|$stmtA|\n";} + + chop($dup_lists); + $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - if ($sthArows > 0) + $rec_count=0; + while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $dup_lead_list = $aryA[0]; - $dup_lead++; + $dup_lead_list = "'$aryA[0]',"; + $rec_count++; + $dup_lead=1; } $sthA->finish(); - if ($dup_lead < 1) - { - if ($phone_list =~ /\|$phone_number$US$list_id\|/) - {$dup_lead++;} - } } - ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### - if ($dupcheckcamp > 0) + if ($dup_lead < 1) { - $dup_lead=0; - $dup_lists=''; - - $stmtA = "select count(*) from vicidial_lists where list_id='$list_id';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - @aryA = $sthA->fetchrow_array; - $ci_recs = $aryA[0]; - $sthA->finish(); - if ($ci_recs > 0) - { - $stmtA = "select campaign_id from vicidial_lists where list_id='$list_id';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - @aryA = $sthA->fetchrow_array; - $dup_camp = $aryA[0]; - $sthA->finish(); - - $stmtA = "select list_id from vicidial_lists where campaign_id='$dup_camp';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $dup_lists .= "'$aryA[0]',"; - $rec_count++; - } - $sthA->finish(); - - chop($dup_lists); - $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $dup_lead_list = "'$aryA[0]',"; - $rec_count++; - $dup_lead=1; - } - $sthA->finish(); - } - if ($dup_lead < 1) - { - if ($phone_list =~ /\|$phone_number$US$list_id\|/) - {$dup_lead++;} - } + if ($phone_list =~ /\|$phone_number$US$list_id\|/) + {$dup_lead++;} } + } - if ( (length($phone_number)>6) && ($dup_lead < 1) ) + if ( (length($phone_number)>6) && ($dup_lead < 1) ) + { + $phone_list .= "$phone_number$US$list_id|"; + # set default values + $modify_date = ""; + $user = ""; + $called_since_last_reset='N'; + $gmt_offset = '0'; + + if ($forcegmt > 0) { - $phone_list .= "$phone_number$US$list_id|"; - # set default values - $modify_date = ""; - $user = ""; - $called_since_last_reset='N'; - $gmt_offset = '0'; - - if ($forcegmt > 0) - { - $gmt_offset = $m[23]; # set GMT offset value to 24th field value - } - else - { - $postalgmt_found=0; - if ( ($postalgmt > 0) && (length($postal_code)>4) ) - { - if ($phone_code =~ /^1$/) - { - $stmtA = "select * from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[2]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[3]; - $dst_range = $aryA[4]; - $PC_processed++; - $rec_count++; - $postalgmt_found++; - if ($DBX) {print " Postal GMT record found for $postal_code: |$gmt_offset|$dst|$dst_range|\n";} - } - $sthA->finish(); - } - } - if ($postalgmt_found < 1) - { - $PC_processed=0; - ### UNITED STATES ### - if ($phone_code =~ /^1$/) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - ### MEXICO ### - if ($phone_code =~ /^52$/) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - ### AUSTRALIA ### - if ($phone_code =~ /^61$/) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and state='$state';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - ### ALL OTHER COUNTRY CODES ### - if (!$PC_processed) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - } - - ### Find out if DST to raise the gmt offset ### - $AC_GMT_diff = ($area_GMT - $LOCAL_GMT_OFF_STD); - $AC_localtime = ($secX + (3600 * $AC_GMT_diff)); - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($AC_localtime); - $year = ($year + 1900); - $mon++; - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} - $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); - - $AC_processed=0; - - if ( (!$AC_processed) && ($dst_range =~ /SSM-FSN/) ) - { - if ($DBX) {print " Second Sunday March to First Sunday November\n";} - &USACAN_dstcalc; - if ($DBX) {print " DST: $USACAN_DST\n";} - if ($USACAN_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /FSA-LSO/) ) - { - if ($DBX) {print " First Sunday April to Last Sunday October\n";} - &NA_dstcalc; - if ($DBX) {print " DST: $NA_DST\n";} - if ($NA_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /LSM-LSO/) ) - { - if ($DBX) {print " Last Sunday March to Last Sunday October\n";} - &GBR_dstcalc; - if ($DBX) {print " DST: $GBR_DST\n";} - if ($GBR_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /LSO-LSM/) ) - { - if ($DBX) {print " Last Sunday October to Last Sunday March\n";} - &AUS_dstcalc; - if ($DBX) {print " DST: $AUS_DST\n";} - if ($AUS_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /FSO-LSM/) ) - { - if ($DBX) {print " First Sunday October to Last Sunday March\n";} - &AUST_dstcalc; - if ($DBX) {print " DST: $AUST_DST\n";} - if ($AUST_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /FSO-TSM/) ) - { - if ($DBX) {print " First Sunday October to Third Sunday March\n";} - &NZL_dstcalc; - if ($DBX) {print " DST: $NZL_DST\n";} - if ($NZL_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /TSO-LSF/) ) - { - if ($DBX) {print " Third Sunday October to Last Sunday February\n";} - &BZL_dstcalc; - if ($DBX) {print " DST: $BZL_DST\n";} - if ($BZL_DST) {$gmt_offset++;} - $AC_processed++; - } - if (!$AC_processed) - { - if ($DBX) {print " No DST Method Found\n";} - if ($DBX) {print " DST: 0\n";} - $AC_processed++; - } - - } - if ($multi_insert_counter > 8) - { - ### insert good deal into pending_transactions table ### - $stmtZ = "INSERT INTO vicidial_list values$multistmt('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count');"; - if (!$T) {$affected_rows = $dbhA->do($stmtZ); } # or die "Couldn't execute query: |$stmtZ|\n"; - if($DB){print STDERR "\n|$affected_rows|$stmtZ|\n";} - - $multistmt=''; - $multi_insert_counter=0; - $c++; - } - else - { - $multistmt .= "('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count'),"; - $multi_insert_counter++; - } - - $b++; + $gmt_offset = $m[23]; # set GMT offset value to 24th field value } else { - if ($dup_lead > 0) - {print "DUPLICATE: $phone|$list_id|$dup_lead_list|"; $f++;} - else - {print "BAD Home_Phone: $phone|$vendor_id"; $e++;} - } - - $a++; + $postalgmt_found=0; + if ( ($postalgmt > 0) && (length($postal_code)>4) ) + { + if ($phone_code =~ /^1$/) + { + $stmtA = "select * from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[2]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[3]; + $dst_range = $aryA[4]; + $PC_processed++; + $rec_count++; + $postalgmt_found++; + if ($DBX) {print " Postal GMT record found for $postal_code: |$gmt_offset|$dst|$dst_range|\n";} + } + $sthA->finish(); + } + } + if ($postalgmt_found < 1) + { + $PC_processed=0; + ### UNITED STATES ### + if ($phone_code =~ /^1$/) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + ### MEXICO ### + if ($phone_code =~ /^52$/) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + ### AUSTRALIA ### + if ($phone_code =~ /^61$/) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and state='$state';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + ### ALL OTHER COUNTRY CODES ### + if (!$PC_processed) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + } - 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|$phone_number|\n";} + ### Find out if DST to raise the gmt offset ### + $AC_GMT_diff = ($area_GMT - $LOCAL_GMT_OFF_STD); + $AC_localtime = ($secX + (3600 * $AC_GMT_diff)); + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($AC_localtime); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$hour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} + $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); + + $AC_processed=0; + + if ( (!$AC_processed) && ($dst_range =~ /SSM-FSN/) ) + { + if ($DBX) {print " Second Sunday March to First Sunday November\n";} + &USACAN_dstcalc; + if ($DBX) {print " DST: $USACAN_DST\n";} + if ($USACAN_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /FSA-LSO/) ) + { + if ($DBX) {print " First Sunday April to Last Sunday October\n";} + &NA_dstcalc; + if ($DBX) {print " DST: $NA_DST\n";} + if ($NA_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /LSM-LSO/) ) + { + if ($DBX) {print " Last Sunday March to Last Sunday October\n";} + &GBR_dstcalc; + if ($DBX) {print " DST: $GBR_DST\n";} + if ($GBR_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /LSO-LSM/) ) + { + if ($DBX) {print " Last Sunday October to Last Sunday March\n";} + &AUS_dstcalc; + if ($DBX) {print " DST: $AUS_DST\n";} + if ($AUS_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /FSO-LSM/) ) + { + if ($DBX) {print " First Sunday October to Last Sunday March\n";} + &AUST_dstcalc; + if ($DBX) {print " DST: $AUST_DST\n";} + if ($AUST_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /FSO-TSM/) ) + { + if ($DBX) {print " First Sunday October to Third Sunday March\n";} + &NZL_dstcalc; + if ($DBX) {print " DST: $NZL_DST\n";} + if ($NZL_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /TSO-LSF/) ) + { + if ($DBX) {print " Third Sunday October to Last Sunday February\n";} + &BZL_dstcalc; + if ($DBX) {print " DST: $BZL_DST\n";} + if ($BZL_DST) {$gmt_offset++;} + $AC_processed++; + } + if (!$AC_processed) + { + if ($DBX) {print " No DST Method Found\n";} + if ($DBX) {print " DST: 0\n";} + $AC_processed++; + } + + } + if ($multi_insert_counter > 8) + { + ### insert good deal into pending_transactions table ### + $stmtZ = "INSERT INTO vicidial_list values$multistmt('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count');"; + if (!$T) {$affected_rows = $dbhA->do($stmtZ); } # or die "Couldn't execute query: |$stmtZ|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtZ|\n";} + + $multistmt=''; + $multi_insert_counter=0; + $c++; + } + else + { + $multistmt .= "('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count'),"; + $multi_insert_counter++; + } + + $b++; + } + else + { + if ($dup_lead > 0) + {print "DUPLICATE: $phone|$list_id|$dup_lead_list|"; $f++;} + else + {print "BAD Home_Phone: $phone|$vendor_id"; $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|$phone_number|\n";} } diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_1_move_VDonly.pl b/agc_2-X/trunk/bin/AST_CRON_audio_1_move_VDonly.pl index c221a45a..68b00cf9 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_1_move_VDonly.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_1_move_VDonly.pl @@ -29,6 +29,7 @@ # # # 80302-1958 - First Build +# 80731-2253 - Changed size comparisons for more efficiency # ### begin parsing run-time options ### @@ -127,6 +128,7 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second use DBI; $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") @@ -137,25 +139,39 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA $dir1 = "$PATHmonitor"; $dir2 = "$PATHDONEmonitor"; - opendir(FILE, "$dir1/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir1/"); +@FILES = readdir(FILE); + +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $INfile = $FILES[$i]; $OUTfile = $FILES[$i]; @@ -195,6 +211,9 @@ foreach(@FILES) if($DBX){print STDERR "\n|$stmtA|\n";} $affected_rows = $dbhA->do($stmtA); # or die "Couldn't execute query:|$stmtA|\n"; + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); + } } $i++; diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_1_move_mix.pl b/agc_2-X/trunk/bin/AST_CRON_audio_1_move_mix.pl index b26e349d..73885dce 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_1_move_mix.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_1_move_mix.pl @@ -28,6 +28,7 @@ # # # 80302-1958 - First Build +# 80731-2253 - Changed size comparisons for more efficiency # ### begin parsing run-time options ### @@ -126,6 +127,7 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second use DBI; $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") @@ -158,25 +160,39 @@ else $dir1 = "$PATHmonitor"; $dir2 = "$PATHDONEmonitor"; - opendir(FILE, "$dir1/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir1/"); +@FILES = readdir(FILE); + +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir1/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.wav|out\.gsm|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $INfile = $FILES[$i]; $OUTfile = $FILES[$i]; @@ -213,6 +229,9 @@ foreach(@FILES) `mv -f "$dir1/$INfile" "$dir2/ORIG/$INfile"`; `mv -f "$dir1/$OUTfile" "$dir2/ORIG/$OUTfile"`; } + + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); } } $i++; diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl b/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl index e4927c9e..560e111a 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_2_compress.pl @@ -29,6 +29,7 @@ # # # 80302-1958 - First Build +# 80731-2253 - Changed size comparisons for more efficiency # $GSM=0; $MP3=0; $OGG=0; @@ -151,7 +152,8 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} -use DBI; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second +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; @@ -194,25 +196,39 @@ if ($MP3 > 0) ### directory where -all recordings are $dir2 = "$PATHDONEmonitor"; - opendir(FILE, "$dir2/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir2/"); +@FILES = readdir(FILE); + +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $recording_id=''; $ALLfile = $FILES[$i]; @@ -279,6 +295,9 @@ foreach(@FILES) { `mv -f "$dir2/$ALLfile" "$dir2/ORIG/$ALLfile"`; } + + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); } } $i++; diff --git a/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl b/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl index d9daecaa..d4d5c753 100644 --- a/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl +++ b/agc_2-X/trunk/bin/AST_CRON_audio_3_ftp.pl @@ -34,6 +34,7 @@ # # 80302-1958 - First Build # 80317-2349 - Added FTP debug if debugX +# 80731-2253 - Changed size comparisons for more efficiency # $GSM=0; $MP3=0; $OGG=0; $WAV=0; $NODATEDIR=0; @@ -178,7 +179,8 @@ foreach(@conf) $server_ip = $VARserver_ip; # Asterisk server IP if (!$VARDB_port) {$VARDB_port='3306';} -use DBI; +use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second +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; @@ -192,25 +194,38 @@ if ($MP3 > 0) {$dir2 = "$PATHDONEmonitor/MP3";} if ($GSM > 0) {$dir2 = "$PATHDONEmonitor/GSM";} if ($OGG > 0) {$dir2 = "$PATHDONEmonitor/OGG";} - opendir(FILE, "$dir2/"); - @FILES = readdir(FILE); +opendir(FILE, "$dir2/"); +@FILES = readdir(FILE); +### Loop through files first to gather filesizes $i=0; foreach(@FILES) { - $size1 = 0; - $size2 = 0; + $FILEsize1[$i] = 0; + if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) + { + $FILEsize1[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize1[$i]\n";} + } + $i++; + } + +sleep(5); + + +### Loop through files a second time to gather filesizes again 5 seconds later +$i=0; +foreach(@FILES) + { + $FILEsize2[$i] = 0; if ( (length($FILES[$i]) > 4) && (!-d $FILES[$i]) ) { - $size1 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size1\n";} - sleep(1); - $size2 = (-s "$dir2/$FILES[$i]"); - if ($DBX) {print "$FILES[$i] $size2\n\n";} + $FILEsize2[$i] = (-s "$dir1/$FILES[$i]"); + if ($DBX) {print "$FILES[$i] $FILEsize2[$i]\n\n";} - if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($size1 eq $size2) && (length($FILES[$i]) > 4)) + if ( ($FILES[$i] !~ /out\.|in\.|lost\+found/i) && ($FILEsize1[$i] eq $FILEsize2[$i]) && (length($FILES[$i]) > 4)) { $recording_id=''; $ALLfile = $FILES[$i]; @@ -266,6 +281,10 @@ foreach(@FILES) } } ### END Remote file transfer + + ### sleep for twenty hundredths of a second to not flood the server with disk activity + usleep(1*200*1000); + } } $i++; diff --git a/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl b/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl index 46f902b7..09b4bd32 100644 --- a/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl +++ b/agc_2-X/trunk/bin/VICIDIAL_IN_new_leads_file.pl @@ -28,6 +28,7 @@ # 80128-0105 - Fixed bugs in file loading # 80428-0320 - UTF8 update # 80713-0023 - added last_local_call_time field default of 2008-01-01 +# 80730-1607 - added minicsv format # $secX = time(); @@ -43,7 +44,7 @@ if ($mday < 10) {$mday = "0$mday";} $pulldate0 = "$year-$mon-$mday $hour:$min:$sec"; $inSD = $pulldate0; $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); - +$MT[0]=''; # default path to astguiclient configuration file: @@ -110,6 +111,7 @@ if (length($ARGV[0])>1) print " [-t] = test\n"; print " [--forcegmt] = forces gmt value of column after comments column\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 " [--forcephonecode=44] = overrides the phone_code given in the lead with the 44\n"; print " [--duplicate-check] = checks for the same phone number in the same list id before inserting lead\n"; @@ -118,9 +120,13 @@ if (length($ARGV[0])>1) print " [--postal-code-gmt] = checks for the time zone based on the postal code given where available\n"; print " [-h] = this help screen\n\n"; print "\n"; - print "This script takes in lead files in the following order when they are placed in the $PATHhome/LEADS_IN directory to be imported into the vicidial_list table:\n\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\n"; + print "This script takes in lead files in the following order when they are placed in the $PATHhome/LEADS_IN directory to be imported into the vicidial_list table (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|105|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS|2|B|2007-08-09 00:00:00\n\n"; + print "minicsv:\n"; + print "address1,city,name,phone_number,state,postal_code\n"; + print "\"105 Fifth St\",\"Steinhatchee\",\"Frank Smith\",\"3525556601\",\"FL\",\"32359\"\n\n"; exit; } @@ -161,6 +167,16 @@ if (length($ARGV[0])>1) else {$forcelistid = '';} + 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 =~ /--forcephonecode=/i) { @data_in = split(/--forcephonecode=/,$args); @@ -199,6 +215,7 @@ print "no command line options set\n"; $args = ""; $i=0; $forcelistid = ''; +$format='standard'; } ### end parsing run-time options ### @@ -301,7 +318,7 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC #if ($DB) while () { - + @m=@MT; # print "$a| $number\n"; $number = $_; chomp($number); @@ -319,10 +336,44 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC $number =~ s/\"//gi; @m = split(/\|/, $number); -# This is the format for the lead files + +# This is the format for the minicsv lead files +#"105 Fifth St","Steinhatchee","Frank Smith","3525556601","FL","32359" + if ($format=='minicsv') + { + @name=@MT; + $vendor_lead_code = ''; + $source_code = ''; + $list_id = '995'; + $phone_code = '1'; + $phone_number = $m[3]; chomp($phone_number); $phone_number =~ s/\D//gi; + $USarea = substr($phone_number, 0, 3); + $title = ''; + $full_name = $m[2]; @name = split(/ /, $full_name); + $first_name = $name[1]; chomp($first_name); + $last_name = "$name[0] $name[2]"; chomp($first_name); + $middle_initial = ''; + $address1 = $m[0]; chomp($address1); + $address2 = ''; + $address3 = ''; + $city = $m[1]; chomp($city); + $state = $m[4]; chomp($state); + $province = ''; + $postal_code = $m[5]; chomp($postal_code); + $country = 'USA'; + $gender = 'U'; + $date_of_birth = '0000-00-00'; + $alt_phone = ''; + $email = ''; + $security_phrase = ''; + $comments = ''; + $called_count = 0; + $status = 'NEW'; + } +# This is the format for the standard lead files #3857822|31022|105|01144|1625551212|MRS|B||BURTON|249 MUNDON ROAD|MALDON|ESSEX||||CM9 6PW|UK||||||COMMENTS - - + else + { $vendor_lead_code = $m[0]; chomp($vendor_lead_code); $source_code = $m[1]; chomp($source_code); $source_id = $source_code; $list_id = $m[2]; chomp($list_id); @@ -357,376 +408,377 @@ if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOC $iD[1] = sprintf("%02d", $iD[1]); $insert_date = "$iD[2]-$iD[0]-$iD[1]"; } + } - if (length($forcelistid) > 0) - { - $list_id = $forcelistid; # set list_id to override value - } - if (length($forcephonecode) > 0) - { - $phone_code = $forcephonecode; # set phone_code to override value - } + if (length($forcelistid) > 0) + { + $list_id = $forcelistid; # set list_id to override value + } + if (length($forcephonecode) > 0) + { + $phone_code = $forcephonecode; # set phone_code to override value + } - ##### Check for duplicate phone numbers in vicidial_list table entire database ##### - if ($dupchecksys > 0) + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if ($dupchecksys > 0) + { + $dup_lead=0; + $stmtA = "select count(*) from vicidial_list where phone_number='$phone_number';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) { - $dup_lead=0; - $stmtA = "select count(*) from vicidial_list where phone_number='$phone_number';"; + @aryA = $sthA->fetchrow_array; + $dup_lead = $aryA[0]; + $dup_lead_list=$list_id; + } + $sthA->finish(); + if ($dup_lead < 1) + { + if ($phone_list =~ /\|$phone_number$US$list_id\|/) + {$dup_lead++;} + } + } + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if ($dupcheck > 0) + { + $dup_lead=0; + $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id='$list_id' limit 1;"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $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; + $dup_lead_list = $aryA[0]; + $dup_lead++; + } + $sthA->finish(); + if ($dup_lead < 1) + { + if ($phone_list =~ /\|$phone_number$US$list_id\|/) + {$dup_lead++;} + } + } + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### + if ($dupcheckcamp > 0) + { + $dup_lead=0; + $dup_lists=''; + + $stmtA = "select count(*) from vicidial_lists where list_id='$list_id';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + @aryA = $sthA->fetchrow_array; + $ci_recs = $aryA[0]; + $sthA->finish(); + if ($ci_recs > 0) + { + $stmtA = "select campaign_id from vicidial_lists where list_id='$list_id';"; if($DBX){print STDERR "\n|$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + @aryA = $sthA->fetchrow_array; + $dup_camp = $aryA[0]; + $sthA->finish(); + + $stmtA = "select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - if ($sthArows > 0) + $rec_count=0; + while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $dup_lead = $aryA[0]; - $dup_lead_list=$list_id; + $dup_lists .= "'$aryA[0]',"; + $rec_count++; } $sthA->finish(); - if ($dup_lead < 1) - { - if ($phone_list =~ /\|$phone_number$US$list_id\|/) - {$dup_lead++;} - } - } - ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### - if ($dupcheck > 0) - { - $dup_lead=0; - $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id='$list_id' limit 1;"; - if($DBX){print STDERR "\n|$stmtA|\n";} + + chop($dup_lists); + $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; - if ($sthArows > 0) + $rec_count=0; + while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $dup_lead_list = $aryA[0]; - $dup_lead++; + $dup_lead_list = "'$aryA[0]',"; + $rec_count++; + $dup_lead=1; } $sthA->finish(); - if ($dup_lead < 1) - { - if ($phone_list =~ /\|$phone_number$US$list_id\|/) - {$dup_lead++;} - } } - ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### - if ($dupcheckcamp > 0) + if ($dup_lead < 1) { - $dup_lead=0; - $dup_lists=''; - - $stmtA = "select count(*) from vicidial_lists where list_id='$list_id';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - @aryA = $sthA->fetchrow_array; - $ci_recs = $aryA[0]; - $sthA->finish(); - if ($ci_recs > 0) - { - $stmtA = "select campaign_id from vicidial_lists where list_id='$list_id';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - @aryA = $sthA->fetchrow_array; - $dup_camp = $aryA[0]; - $sthA->finish(); - - $stmtA = "select list_id from vicidial_lists where campaign_id='$dup_camp';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $dup_lists .= "'$aryA[0]',"; - $rec_count++; - } - $sthA->finish(); - - chop($dup_lists); - $stmtA = "select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $dup_lead_list = "'$aryA[0]',"; - $rec_count++; - $dup_lead=1; - } - $sthA->finish(); - } - if ($dup_lead < 1) - { - if ($phone_list =~ /\|$phone_number$US$list_id\|/) - {$dup_lead++;} - } + if ($phone_list =~ /\|$phone_number$US$list_id\|/) + {$dup_lead++;} } + } - if ( (length($phone_number)>6) && ($dup_lead < 1) ) + if ( (length($phone_number)>6) && ($dup_lead < 1) ) + { + $phone_list .= "$phone_number$US$list_id|"; + # set default values + $modify_date = ""; + $user = ""; + $called_since_last_reset='N'; + $gmt_offset = '0'; + + if ($forcegmt > 0) { - $phone_list .= "$phone_number$US$list_id|"; - # set default values - $modify_date = ""; - $user = ""; - $called_since_last_reset='N'; - $gmt_offset = '0'; - - if ($forcegmt > 0) - { - $gmt_offset = $m[23]; # set GMT offset value to 24th field value - } - else - { - $postalgmt_found=0; - if ( ($postalgmt > 0) && (length($postal_code)>4) ) - { - if ($phone_code =~ /^1$/) - { - $stmtA = "select * from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[2]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[3]; - $dst_range = $aryA[4]; - $PC_processed++; - $rec_count++; - $postalgmt_found++; - if ($DBX) {print " Postal GMT record found for $postal_code: |$gmt_offset|$dst|$dst_range|\n";} - } - $sthA->finish(); - } - } - if ($postalgmt_found < 1) - { - $PC_processed=0; - ### UNITED STATES ### - if ($phone_code =~ /^1$/) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - ### MEXICO ### - if ($phone_code =~ /^52$/) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - ### AUSTRALIA ### - if ($phone_code =~ /^61$/) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and state='$state';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - ### ALL OTHER COUNTRY CODES ### - if (!$PC_processed) - { - $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code';"; - if($DBX){print STDERR "\n|$stmtA|\n";} - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; - $dst = $aryA[5]; - $dst_range = $aryA[6]; - $PC_processed++; - $rec_count++; - } - $sthA->finish(); - } - } - - ### Find out if DST to raise the gmt offset ### - $AC_GMT_diff = ($area_GMT - $LOCAL_GMT_OFF_STD); - $AC_localtime = ($secX + (3600 * $AC_GMT_diff)); - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($AC_localtime); - $year = ($year + 1900); - $mon++; - if ($mon < 10) {$mon = "0$mon";} - if ($mday < 10) {$mday = "0$mday";} - if ($hour < 10) {$hour = "0$hour";} - if ($min < 10) {$min = "0$min";} - if ($sec < 10) {$sec = "0$sec";} - $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); - - $AC_processed=0; - - if ( (!$AC_processed) && ($dst_range =~ /SSM-FSN/) ) - { - if ($DBX) {print " Second Sunday March to First Sunday November\n";} - &USACAN_dstcalc; - if ($DBX) {print " DST: $USACAN_DST\n";} - if ($USACAN_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /FSA-LSO/) ) - { - if ($DBX) {print " First Sunday April to Last Sunday October\n";} - &NA_dstcalc; - if ($DBX) {print " DST: $NA_DST\n";} - if ($NA_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /LSM-LSO/) ) - { - if ($DBX) {print " Last Sunday March to Last Sunday October\n";} - &GBR_dstcalc; - if ($DBX) {print " DST: $GBR_DST\n";} - if ($GBR_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /LSO-LSM/) ) - { - if ($DBX) {print " Last Sunday October to Last Sunday March\n";} - &AUS_dstcalc; - if ($DBX) {print " DST: $AUS_DST\n";} - if ($AUS_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /FSO-LSM/) ) - { - if ($DBX) {print " First Sunday October to Last Sunday March\n";} - &AUST_dstcalc; - if ($DBX) {print " DST: $AUST_DST\n";} - if ($AUST_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /FSO-TSM/) ) - { - if ($DBX) {print " First Sunday October to Third Sunday March\n";} - &NZL_dstcalc; - if ($DBX) {print " DST: $NZL_DST\n";} - if ($NZL_DST) {$gmt_offset++;} - $AC_processed++; - } - if ( (!$AC_processed) && ($dst_range =~ /TSO-LSF/) ) - { - if ($DBX) {print " Third Sunday October to Last Sunday February\n";} - &BZL_dstcalc; - if ($DBX) {print " DST: $BZL_DST\n";} - if ($BZL_DST) {$gmt_offset++;} - $AC_processed++; - } - if (!$AC_processed) - { - if ($DBX) {print " No DST Method Found\n";} - if ($DBX) {print " DST: 0\n";} - $AC_processed++; - } - - } - if ($multi_insert_counter > 8) - { - ### insert good deal into pending_transactions table ### - $stmtZ = "INSERT INTO vicidial_list values$multistmt('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count','2008-01-01 00:00:00');"; - if (!$T) {$affected_rows = $dbhA->do($stmtZ); } # or die "Couldn't execute query: |$stmtZ|\n"; - if($DB){print STDERR "\n|$affected_rows|$stmtZ|\n";} - - $multistmt=''; - $multi_insert_counter=0; - $c++; - } - else - { - $multistmt .= "('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count','2008-01-01 00:00:00'),"; - $multi_insert_counter++; - } - - $b++; + $gmt_offset = $m[23]; # set GMT offset value to 24th field value } else { - if ($dup_lead > 0) - {print "DUPLICATE: $phone|$list_id|$dup_lead_list|"; $f++;} - else - {print "BAD Home_Phone: $phone|$vendor_id"; $e++;} - } - - $a++; + $postalgmt_found=0; + if ( ($postalgmt > 0) && (length($postal_code)>4) ) + { + if ($phone_code =~ /^1$/) + { + $stmtA = "select * from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[2]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[3]; + $dst_range = $aryA[4]; + $PC_processed++; + $rec_count++; + $postalgmt_found++; + if ($DBX) {print " Postal GMT record found for $postal_code: |$gmt_offset|$dst|$dst_range|\n";} + } + $sthA->finish(); + } + } + if ($postalgmt_found < 1) + { + $PC_processed=0; + ### UNITED STATES ### + if ($phone_code =~ /^1$/) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + ### MEXICO ### + if ($phone_code =~ /^52$/) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + ### AUSTRALIA ### + if ($phone_code =~ /^61$/) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code' and state='$state';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + ### ALL OTHER COUNTRY CODES ### + if (!$PC_processed) + { + $stmtA = "select * from vicidial_phone_codes where country_code='$phone_code';"; + if($DBX){print STDERR "\n|$stmtA|\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $gmt_offset = $aryA[4]; $gmt_offset =~ s/\+| //gi; + $dst = $aryA[5]; + $dst_range = $aryA[6]; + $PC_processed++; + $rec_count++; + } + $sthA->finish(); + } + } - 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|$phone_number|\n";} + ### Find out if DST to raise the gmt offset ### + $AC_GMT_diff = ($area_GMT - $LOCAL_GMT_OFF_STD); + $AC_localtime = ($secX + (3600 * $AC_GMT_diff)); + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($AC_localtime); + $year = ($year + 1900); + $mon++; + if ($mon < 10) {$mon = "0$mon";} + if ($mday < 10) {$mday = "0$mday";} + if ($hour < 10) {$hour = "0$hour";} + if ($min < 10) {$min = "0$min";} + if ($sec < 10) {$sec = "0$sec";} + $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); + + $AC_processed=0; + + if ( (!$AC_processed) && ($dst_range =~ /SSM-FSN/) ) + { + if ($DBX) {print " Second Sunday March to First Sunday November\n";} + &USACAN_dstcalc; + if ($DBX) {print " DST: $USACAN_DST\n";} + if ($USACAN_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /FSA-LSO/) ) + { + if ($DBX) {print " First Sunday April to Last Sunday October\n";} + &NA_dstcalc; + if ($DBX) {print " DST: $NA_DST\n";} + if ($NA_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /LSM-LSO/) ) + { + if ($DBX) {print " Last Sunday March to Last Sunday October\n";} + &GBR_dstcalc; + if ($DBX) {print " DST: $GBR_DST\n";} + if ($GBR_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /LSO-LSM/) ) + { + if ($DBX) {print " Last Sunday October to Last Sunday March\n";} + &AUS_dstcalc; + if ($DBX) {print " DST: $AUS_DST\n";} + if ($AUS_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /FSO-LSM/) ) + { + if ($DBX) {print " First Sunday October to Last Sunday March\n";} + &AUST_dstcalc; + if ($DBX) {print " DST: $AUST_DST\n";} + if ($AUST_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /FSO-TSM/) ) + { + if ($DBX) {print " First Sunday October to Third Sunday March\n";} + &NZL_dstcalc; + if ($DBX) {print " DST: $NZL_DST\n";} + if ($NZL_DST) {$gmt_offset++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($dst_range =~ /TSO-LSF/) ) + { + if ($DBX) {print " Third Sunday October to Last Sunday February\n";} + &BZL_dstcalc; + if ($DBX) {print " DST: $BZL_DST\n";} + if ($BZL_DST) {$gmt_offset++;} + $AC_processed++; + } + if (!$AC_processed) + { + if ($DBX) {print " No DST Method Found\n";} + if ($DBX) {print " DST: 0\n";} + $AC_processed++; + } + + } + if ($multi_insert_counter > 8) + { + ### insert good deal into pending_transactions table ### + $stmtZ = "INSERT INTO vicidial_list values$multistmt('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count','2008-01-01 00:00:00');"; + if (!$T) {$affected_rows = $dbhA->do($stmtZ); } # or die "Couldn't execute query: |$stmtZ|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtZ|\n";} + + $multistmt=''; + $multi_insert_counter=0; + $c++; + } + else + { + $multistmt .= "('','$insert_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments','$called_count','2008-01-01 00:00:00'),"; + $multi_insert_counter++; + } + + $b++; + } + else + { + if ($dup_lead > 0) + {print "DUPLICATE: $phone|$list_id|$dup_lead_list|"; $f++;} + else + {print "BAD Home_Phone: $phone|$vendor_id"; $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|$phone_number|\n";} } - if (length($multistmt) > 10) - { - chop($multistmt); - ### insert good deal into pending_transactions table ### - $stmtZ = "INSERT INTO vicidial_list values$multistmt;"; - if (!$T) {$affected_rows = $dbhA->do($stmtZ); } # or die "Couldn't execute query: |$stmtZ|\n"; - if($DB){print STDERR "\n|$affected_rows|$stmtZ|\n";} +if (length($multistmt) > 10) + { + chop($multistmt); + ### insert good deal into pending_transactions table ### + $stmtZ = "INSERT INTO vicidial_list values$multistmt;"; + if (!$T) {$affected_rows = $dbhA->do($stmtZ); } # or die "Couldn't execute query: |$stmtZ|\n"; + if($DB){print STDERR "\n|$affected_rows|$stmtZ|\n";} - $multistmt=''; - $multi_insert_counter=0; - $c++; - } + $multistmt=''; + $multi_insert_counter=0; + $c++; + } ### open the stats out file for writing ### open(Sout, ">>$VDHLOGfile") diff --git a/agc_2-X/trunk/docs/AGENT_API.txt b/agc_2-X/trunk/docs/AGENT_API.txt index f5863d99..c0d363c6 100644 --- a/agc_2-X/trunk/docs/AGENT_API.txt +++ b/agc_2-X/trunk/docs/AGENT_API.txt @@ -4,6 +4,9 @@ This document describes the functions of an API(Application Programming Interfac for the VICIDIAL Agent screen. This functionality will be rather limited at first and will be built upon as critical functions are identified and programmed into it. +There is also a new NON-agent API script, for more information on that, please +read the NON-AGENT_API.txt document. + API functions: diff --git a/agc_2-X/trunk/docs/LIST_SUGGESTIONS.txt b/agc_2-X/trunk/docs/LIST_SUGGESTIONS.txt new file mode 100644 index 00000000..85abd69b --- /dev/null +++ b/agc_2-X/trunk/docs/LIST_SUGGESTIONS.txt @@ -0,0 +1,213 @@ +PROCESS FOR LIST SUGGESTIONS FOR ROOM MANAGERS Started: 2008-07-14 + +This document goes over the process for making suggestions of what lists to use at what time in a special report linked from the vicidial Administration web site(vicidial/admin.php). + +The suggestions would group lists usage into eight 3-hour periods for each day according to server time. The actual number of 3-hour periods shown for each list would be restricted depending on the local call time scheme selected for the campaign and the area that the leads were present in. + +The list suggestion process would most likely not be real-time, although at companies with small lists that might be possible. Instead, a server process running after-hours will generate statistics and scores for each list for each of the 3-hour periods. Something like the following will be viewable after the stats have been run: + +LIST TIME TZ-DIAL% HA-SCORE SALE-SCORE +101 9AM-12PM 100 15 15 +101 12PM-3PM 100 25 35 * +101 3PM-6PM 100 35 30 +101 6PM-9PM 100 25 20 + +In the above example, the best time for a manager to call the list, for the highest rate of Human-Answered CONTACT, would be from 3-6PM. Or to maximixe SALEs they might want to call the list earlier at 12PM-3PM. the reason that you only see four 3-hour periods is that this specific list has only US Eastern time-zone leads in it and the campaign time scheme is set to 9AM-9PM so there is no possibility of calling past 9PM server time since the server is located in US Eastern Timezone, but a list with central or mountain time zone leads in it would show a fifth period(9PM-12AM) that would have score next to it(see example below). The Asterisk * is next to the time period that is happening right now, in the actual report that line would be highlighted with a different color. + +LIST TIME TZ-DIAL% HA-SCORE SALE-SCORE +102 9AM-12PM 67 20 15 +102 12PM-3PM 100 15 15 * +102 3PM-6PM 100 20 25 +102 6PM-9PM 100 15 10 +102 9PM-12AM 33 30 35 + +In this example you get some indication of how the TZ-DIAL % will work. In the real application it might be better to use some kind of graph or filled-in sections of the table that would indicate the time ranges and lead percentage covered in each of the time periods to give a better visual of when the leads are able to be dialed. + +There will also be the ability to see a comparison of the available lists for the current time period so that a manager can make a decision as to which of those lists to make active. + + +Factors to be taken into account by the scoring process: +- number of leads in the list +- number of leads in a callable time zone in the list +- number of sales and the sales ratio in each time period +- number of attempts by leads in the list in each time period +- the amount of dead leads(leads that cannot be called anymore) in the list +- the number of calls placed yesterday in the same time period +- the number of Human-Answered leads for each period + + + +Needed database changes: +!!! IMPORTANT !!! +THESE ARE FOR REFERENCE ONLY, DO NOT RUN THEM!!! + +ALTER TABLE vicidial_status_categories ADD sale_category ENUM('Y','N') default 'N'; +ALTER TABLE vicidial_status_categories ADD dead_lead_category ENUM('Y','N') default 'N'; + +CREATE TABLE vicidial_lists_suggestions ( +list_id BIGINT(14) UNSIGNED PRIMARY KEY NOT NULL, +last_update_time DATETIME, +leads_count INT(9) UNSIGNED, +calls_count INT(9) UNSIGNED, +sales_count INT(9) UNSIGNED, +contacts_count INT(9) UNSIGNED, +period_1_dialable MEDIUMINT(7) UNSIGNED, +period_1_tz_dial_pct TINYINT(3), +period_1_calls MEDIUMINT(7) UNSIGNED, +period_1_sales MEDIUMINT(7) UNSIGNED, +period_1_contacts MEDIUMINT(7) UNSIGNED, +period_1_avg_attempts TINYINT(3) UNSIGNED, +period_1_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_1_score_sale TINYINT(3), +period_1_score_contact TINYINT(3), +period_2_dialable MEDIUMINT(7) UNSIGNED, +period_2_tz_dial_pct TINYINT(3), +period_2_calls MEDIUMINT(7) UNSIGNED, +period_2_sales MEDIUMINT(7) UNSIGNED, +period_2_contacts MEDIUMINT(7) UNSIGNED, +period_2_avg_attempts TINYINT(3) UNSIGNED, +period_2_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_2_score_sale TINYINT(3), +period_2_score_contact TINYINT(3), +period_3_dialable MEDIUMINT(7) UNSIGNED, +period_3_tz_dial_pct TINYINT(3), +period_3_calls MEDIUMINT(7) UNSIGNED, +period_3_sales MEDIUMINT(7) UNSIGNED, +period_3_contacts MEDIUMINT(7) UNSIGNED, +period_3_avg_attempts TINYINT(3) UNSIGNED, +period_3_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_3_score_sale TINYINT(3), +period_3_score_contact TINYINT(3), +period_4_dialable MEDIUMINT(7) UNSIGNED, +period_4_tz_dial_pct TINYINT(3), +period_4_calls MEDIUMINT(7) UNSIGNED, +period_4_sales MEDIUMINT(7) UNSIGNED, +period_4_contacts MEDIUMINT(7) UNSIGNED, +period_4_avg_attempts TINYINT(3) UNSIGNED, +period_4_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_4_score_sale TINYINT(3), +period_4_score_contact TINYINT(3), +period_5_dialable MEDIUMINT(7) UNSIGNED, +period_5_tz_dial_pct TINYINT(3), +period_5_calls MEDIUMINT(7) UNSIGNED, +period_5_sales MEDIUMINT(7) UNSIGNED, +period_5_contacts MEDIUMINT(7) UNSIGNED, +period_5_avg_attempts TINYINT(3) UNSIGNED, +period_5_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_5_score_sale TINYINT(3), +period_5_score_contact TINYINT(3), +period_6_dialable MEDIUMINT(7) UNSIGNED, +period_6_tz_dial_pct TINYINT(3), +period_6_calls MEDIUMINT(7) UNSIGNED, +period_6_sales MEDIUMINT(7) UNSIGNED, +period_6_contacts MEDIUMINT(7) UNSIGNED, +period_6_avg_attempts TINYINT(3) UNSIGNED, +period_6_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_6_score_sale TINYINT(3), +period_6_score_contact TINYINT(3), +period_7_dialable MEDIUMINT(7) UNSIGNED, +period_7_tz_dial_pct TINYINT(3), +period_7_calls MEDIUMINT(7) UNSIGNED, +period_7_sales MEDIUMINT(7) UNSIGNED, +period_7_contacts MEDIUMINT(7) UNSIGNED, +period_7_avg_attempts TINYINT(3) UNSIGNED, +period_7_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_7_score_sale TINYINT(3), +period_7_score_contact TINYINT(3), +period_8_dialable MEDIUMINT(7) UNSIGNED, +period_8_tz_dial_pct TINYINT(3), +period_8_calls MEDIUMINT(7) UNSIGNED, +period_8_sales MEDIUMINT(7) UNSIGNED, +period_8_contacts MEDIUMINT(7) UNSIGNED, +period_8_avg_attempts TINYINT(3) UNSIGNED, +period_8_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_8_score_sale TINYINT(3), +period_8_score_contact TINYINT(3) +); + +CREATE TABLE vicidial_lists_suggestion_log ( +list_id BIGINT(14) UNSIGNED NOT NULL, +campaign_id VARCHAR(20) NOT NULL, +log_datetime DATETIME NOT NULL, +leads_count INT(9) UNSIGNED, +calls_count INT(9) UNSIGNED, +sales_count INT(9) UNSIGNED, +contacts_count INT(9) UNSIGNED, +period_1_dialable MEDIUMINT(7) UNSIGNED, +period_1_tz_dial_pct TINYINT(3), +period_1_calls MEDIUMINT(7) UNSIGNED, +period_1_sales MEDIUMINT(7) UNSIGNED, +period_1_contacts MEDIUMINT(7) UNSIGNED, +period_1_avg_attempts TINYINT(3) UNSIGNED, +period_1_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_1_score_sale TINYINT(3), +period_1_score_contact TINYINT(3), +period_2_dialable MEDIUMINT(7) UNSIGNED, +period_2_tz_dial_pct TINYINT(3), +period_2_calls MEDIUMINT(7) UNSIGNED, +period_2_sales MEDIUMINT(7) UNSIGNED, +period_2_contacts MEDIUMINT(7) UNSIGNED, +period_2_avg_attempts TINYINT(3) UNSIGNED, +period_2_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_2_score_sale TINYINT(3), +period_2_score_contact TINYINT(3), +period_3_dialable MEDIUMINT(7) UNSIGNED, +period_3_tz_dial_pct TINYINT(3), +period_3_calls MEDIUMINT(7) UNSIGNED, +period_3_sales MEDIUMINT(7) UNSIGNED, +period_3_contacts MEDIUMINT(7) UNSIGNED, +period_3_avg_attempts TINYINT(3) UNSIGNED, +period_3_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_3_score_sale TINYINT(3), +period_3_score_contact TINYINT(3), +period_4_dialable MEDIUMINT(7) UNSIGNED, +period_4_tz_dial_pct TINYINT(3), +period_4_calls MEDIUMINT(7) UNSIGNED, +period_4_sales MEDIUMINT(7) UNSIGNED, +period_4_contacts MEDIUMINT(7) UNSIGNED, +period_4_avg_attempts TINYINT(3) UNSIGNED, +period_4_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_4_score_sale TINYINT(3), +period_4_score_contact TINYINT(3), +period_5_dialable MEDIUMINT(7) UNSIGNED, +period_5_tz_dial_pct TINYINT(3), +period_5_calls MEDIUMINT(7) UNSIGNED, +period_5_sales MEDIUMINT(7) UNSIGNED, +period_5_contacts MEDIUMINT(7) UNSIGNED, +period_5_avg_attempts TINYINT(3) UNSIGNED, +period_5_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_5_score_sale TINYINT(3), +period_5_score_contact TINYINT(3), +period_6_dialable MEDIUMINT(7) UNSIGNED, +period_6_tz_dial_pct TINYINT(3), +period_6_calls MEDIUMINT(7) UNSIGNED, +period_6_sales MEDIUMINT(7) UNSIGNED, +period_6_contacts MEDIUMINT(7) UNSIGNED, +period_6_avg_attempts TINYINT(3) UNSIGNED, +period_6_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_6_score_sale TINYINT(3), +period_6_score_contact TINYINT(3), +period_7_dialable MEDIUMINT(7) UNSIGNED, +period_7_tz_dial_pct TINYINT(3), +period_7_calls MEDIUMINT(7) UNSIGNED, +period_7_sales MEDIUMINT(7) UNSIGNED, +period_7_contacts MEDIUMINT(7) UNSIGNED, +period_7_avg_attempts TINYINT(3) UNSIGNED, +period_7_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_7_score_sale TINYINT(3), +period_7_score_contact TINYINT(3), +period_8_dialable MEDIUMINT(7) UNSIGNED, +period_8_tz_dial_pct TINYINT(3), +period_8_calls MEDIUMINT(7) UNSIGNED, +period_8_sales MEDIUMINT(7) UNSIGNED, +period_8_contacts MEDIUMINT(7) UNSIGNED, +period_8_avg_attempts TINYINT(3) UNSIGNED, +period_8_calls_yesterday MEDIUMINT(7) UNSIGNED, +period_8_score_sale TINYINT(3), +period_8_score_contact TINYINT(3), +index (list_id), +index (campaign_id), +index (log_datetime) +); + + diff --git a/agc_2-X/trunk/docs/NON-AGENT_API.txt b/agc_2-X/trunk/docs/NON-AGENT_API.txt new file mode 100644 index 00000000..b9a6843a --- /dev/null +++ b/agc_2-X/trunk/docs/NON-AGENT_API.txt @@ -0,0 +1,84 @@ +NON-AGENT API DOCUMENT 2008-07-24 + +This document describes the functions of an API(Application Programming Interface) +for all functions NOT relating to the VICIDIAL Agent screen. This functionality +will be rather limited at first and will be built upon as critical functions are +identified and programmed into it. + +There is also a new agent API script, for more information on that, please read +the AGENT_API.txt document. + + + + +New scripts: +/vicidial/non_agent_api.php - the script that is accessed to execute commands + + + + +API Functions: + +NOTE: Just as with the Agent API, the non-agent API requires the user and pass of a +valid api-enabled vicidial_users account to execute actions. + + + +add_lead - adds a new lead to the vicidial_list table with several fields and options + +NOTE: api user for this function must have modify_leads set to 1 + +REQUIRED FIELDS- +phone_number - must be all numbers, 6-16 digits +phone_code - must be all numbers, 1-4 digits, defaults to 1 if not set +list_id - must be all numbers, 3-12 digits, defaults to 999 if not set + +SETTINGS FIELDS- +dnc_check - Y or N, default is N +add_to_hopper - Y or N, default is N +hopper_priority - 99 to -99, the higher number the higher priority, default is 0 +hopper_local_call_time_check - Y or N, default is N. Validate the local call time before inserting lead in the hopper + +OPTIONAL FIELDS- +vendor_lead_code - 1-20 characters +source_id - 1-50 characters +gmt_offset_now - overridden by auto-lookup of phone_code and area_code portion of phone number if applicable +title - 1-4 characters +first_name - 1-30 characters +middle_initial - 1 character +last_name - 1-30 characters +address1 - 1-100 characters +address2 - 1-100 characters +address3 - 1-100 characters +city - 1-50 characters +state - 2 characters +province - 1-50 characters +postal_code - 1-10 characters +country_code - 3 characters +gender - U, M, F (Undefined, Male, Female) - defaults to 'U' +date_of_birth - YYYY-MM-DD +alt_phone - 1-12 characters +email - 1-70 characters +security_phrase - 1-100 characters +comments - 1-255 characters + + +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?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 + + + +Example responses: +SUCCESS: add_lead LEAD HAS BEEN ADDED - 7275551111|6666|999|193715|-4 +NOTICE: add_lead ADDED TO HOPPER - 7275551111|6666|193715|1677922 + +SUCCESS: add_lead LEAD HAS BEEN ADDED - 7275551111|6666|999|193716|-4 +NOTICE: add_lead NOT ADDED TO HOPPER, OUTSIDE OF LOCAL TIME - 7275551111|6666|193716|-4|0 + +ERROR: add_lead INVALID PHONE NUMBER - 72755|6666 + +ERROR: add_lead USER DOES NOT HAVE PERMISSION TO ADD LEADS TO THE SYSTEM - 6666|0 diff --git a/agc_2-X/trunk/www/agc/api.php b/agc_2-X/trunk/www/agc/api.php index 92f1ee48..934edafa 100644 --- a/agc_2-X/trunk/www/agc/api.php +++ b/agc_2-X/trunk/www/agc/api.php @@ -66,6 +66,10 @@ if ($non_latin < 1) $user=ereg_replace("[^0-9a-zA-Z]","",$user); $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); +$extra_value = ereg_replace("[^-\_0-9a-zA-Z]","",$extra_value); +$format = ereg_replace("[^0-9a-zA-Z]","",$format); } $StarTtime = date("U"); diff --git a/agc_2-X/trunk/www/vicidial/non_agent_api.php b/agc_2-X/trunk/www/vicidial/non_agent_api.php new file mode 100644 index 00000000..188863d0 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/non_agent_api.php @@ -0,0 +1,1248 @@ + LICENSE: AGPLv2 +# +# This script is designed as an API(Application Programming Interface) to allow +# other programs to interact with all non-agent-screen VICIDIAL functions +# +# required variables: +# - $user +# - $pass +# - $function - ('add_lead') +# - $format - ('text','debug') + +# CHANGELOG: +# 80724-0021 - First build of script +# 80801-0047 - Added gmt lookup and hopper insert time validation +# + +$version = '2.0.5-2'; +$build = '80801-0047'; + +require("dbconnect.php"); + +### If you have globals turned off uncomment these lines +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["pass"])) {$pass=$_GET["pass"];} + elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];} +if (isset($_GET["function"])) {$function=$_GET["function"];} + elseif (isset($_POST["function"])) {$function=$_POST["function"];} +if (isset($_GET["format"])) {$format=$_GET["format"];} + elseif (isset($_POST["format"])) {$format=$_POST["format"];} +if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];} + elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];} +if (isset($_GET["phone_code"])) {$phone_code=$_GET["phone_code"];} + elseif (isset($_POST["phone_code"])) {$phone_code=$_POST["phone_code"];} +if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];} + elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];} +if (isset($_GET["vendor_lead_code"])) {$vendor_lead_code=$_GET["vendor_lead_code"];} + elseif (isset($_POST["vendor_lead_code"])) {$vendor_lead_code=$_POST["vendor_lead_code"];} +if (isset($_GET["source_id"])) {$source_id=$_GET["source_id"];} + elseif (isset($_POST["source_id"])) {$source_id=$_POST["source_id"];} +if (isset($_GET["gmt_offset_now"])) {$gmt_offset_now=$_GET["gmt_offset_now"];} + elseif (isset($_POST["gmt_offset_now"])) {$gmt_offset_now=$_POST["gmt_offset_now"];} +if (isset($_GET["title"])) {$title=$_GET["title"];} + elseif (isset($_POST["title"])) {$title=$_POST["title"];} +if (isset($_GET["first_name"])) {$first_name=$_GET["first_name"];} + elseif (isset($_POST["first_name"])) {$first_name=$_POST["first_name"];} +if (isset($_GET["middle_initial"])) {$middle_initial=$_GET["middle_initial"];} + elseif (isset($_POST["middle_initial"])) {$middle_initial=$_POST["middle_initial"];} +if (isset($_GET["last_name"])) {$last_name=$_GET["last_name"];} + elseif (isset($_POST["last_name"])) {$last_name=$_POST["last_name"];} +if (isset($_GET["address1"])) {$address1=$_GET["address1"];} + elseif (isset($_POST["address1"])) {$address1=$_POST["address1"];} +if (isset($_GET["address2"])) {$address2=$_GET["address2"];} + elseif (isset($_POST["address2"])) {$address2=$_POST["address2"];} +if (isset($_GET["address3"])) {$address3=$_GET["address3"];} + elseif (isset($_POST["address3"])) {$address3=$_POST["address3"];} +if (isset($_GET["city"])) {$city=$_GET["city"];} + elseif (isset($_POST["city"])) {$city=$_POST["city"];} +if (isset($_GET["state"])) {$state=$_GET["state"];} + elseif (isset($_POST["state"])) {$state=$_POST["state"];} +if (isset($_GET["province"])) {$province=$_GET["province"];} + elseif (isset($_POST["province"])) {$province=$_POST["province"];} +if (isset($_GET["postal_code"])) {$postal_code=$_GET["postal_code"];} + elseif (isset($_POST["postal_code"])) {$postal_code=$_POST["postal_code"];} +if (isset($_GET["country_code"])) {$country_code=$_GET["country_code"];} + elseif (isset($_POST["country_code"])) {$country_code=$_POST["country_code"];} +if (isset($_GET["gender"])) {$gender=$_GET["gender"];} + elseif (isset($_POST["gender"])) {$gender=$_POST["gender"];} +if (isset($_GET["date_of_birth"])) {$date_of_birth=$_GET["date_of_birth"];} + elseif (isset($_POST["date_of_birth"])) {$date_of_birth=$_POST["date_of_birth"];} +if (isset($_GET["alt_phone"])) {$alt_phone=$_GET["alt_phone"];} + elseif (isset($_POST["alt_phone"])) {$alt_phone=$_POST["alt_phone"];} +if (isset($_GET["email"])) {$email=$_GET["email"];} + elseif (isset($_POST["email"])) {$email=$_POST["email"];} +if (isset($_GET["security_phrase"])) {$security_phrase=$_GET["security_phrase"];} + elseif (isset($_POST["security_phrase"])) {$security_phrase=$_POST["security_phrase"];} +if (isset($_GET["comments"])) {$comments=$_GET["comments"];} + elseif (isset($_POST["comments"])) {$comments=$_POST["comments"];} +if (isset($_GET["dnc_check"])) {$dnc_check=$_GET["dnc_check"];} + elseif (isset($_POST["dnc_check"])) {$dnc_check=$_POST["dnc_check"];} +if (isset($_GET["add_to_hopper"])) {$add_to_hopper=$_GET["add_to_hopper"];} + elseif (isset($_POST["add_to_hopper"])) {$add_to_hopper=$_POST["add_to_hopper"];} +if (isset($_GET["hopper_priority"])) {$hopper_priority=$_GET["hopper_priority"];} + elseif (isset($_POST["hopper_priority"])) {$hopper_priority=$_POST["hopper_priority"];} +if (isset($_GET["hopper_local_call_time_check"])) {$hopper_local_call_time_check=$_GET["hopper_local_call_time_check"];} + elseif (isset($_POST["hopper_local_call_time_check"])) {$hopper_local_call_time_check=$_POST["hopper_local_call_time_check"];} + + +header ("Content-type: text/html; charset=utf-8"); +header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header ("Pragma: no-cache"); // HTTP/1.0 + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin FROM system_settings;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysql_num_rows($rslt); +$i=0; +while ($i < $qm_conf_ct) + { + $row=mysql_fetch_row($rslt); + $non_latin = $row[0]; + $i++; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ($non_latin < 1) + { + $user=ereg_replace("[^0-9a-zA-Z]","",$user); + $pass=ereg_replace("[^0-9a-zA-Z]","",$pass); + $function = ereg_replace("[^-\_0-9a-zA-Z]","",$function); + $format = ereg_replace("[^0-9a-zA-Z]","",$format); + $list_id = ereg_replace("[^0-9]","",$list_id); + $phone_code = ereg_replace("[^0-9]","",$phone_code); + $phone_number = ereg_replace("[^0-9]","",$phone_number); + $vendor_lead_code = ereg_replace(";","",$vendor_lead_code); + $source_id = ereg_replace(";","",$source_id); + $gmt_offset_now = ereg_replace("-\_\.0-9","",$gmt_offset_now); + $title = ereg_replace("[^- \_\.0-9a-zA-Z]","",$title); + $first_name = ereg_replace("[^- \_\.0-9a-zA-Z]","",$first_name); + $middle_initial = ereg_replace("[^0-9a-zA-Z]","",$middle_initial); + $last_name = ereg_replace("[^- \_\.0-9a-zA-Z]","",$last_name); + $address1 = ereg_replace("[^- \.\:\/\@\_0-9a-zA-Z]","",$address1); + $address2 = ereg_replace("[^- \.\:\/\@\_0-9a-zA-Z]","",$address2); + $address3 = ereg_replace("[^- \.\:\/\@\_0-9a-zA-Z]","",$address3); + $city = ereg_replace("[^- \.\:\/\@\_0-9a-zA-Z]","",$city); + $state = ereg_replace("[^- 0-9a-zA-Z]","",$state); + $province = ereg_replace("[^- \.\_0-9a-zA-Z]","",$province); + $postal_code = ereg_replace("[^- 0-9a-zA-Z]","",$postal_code); + $country_code = ereg_replace("[^A-Z]","",$country_code); + $gender = ereg_replace("[^A-Z]","",$gender); + $date_of_birth = ereg_replace("[^-0-9]","",$date_of_birth); + $alt_phone = ereg_replace("[^- \_\.0-9a-zA-Z]","",$alt_phone); + $email = ereg_replace("[^- \.\:\/\@\_0-9a-zA-Z]","",$email); + $security_phrase = ereg_replace("[^- \.\:\/\@\_0-9a-zA-Z]","",$security_phrase); + $comments = ereg_replace(";","",$comments); + $dnc_check = ereg_replace("[^A-Z]","",$dnc_check); + $add_to_hopper = ereg_replace("[^A-Z]","",$add_to_hopper); + $hopper_priority = ereg_replace("-0-9","",$hopper_priority); + $hopper_local_call_time_check = ereg_replace("[^A-Z]","",$hopper_local_call_time_check); + } + +if (strlen($list_id)<1) {$list_id='999';} +if (strlen($phone_code)<1) {$phone_code='1';} +$USarea = substr($phone_number, 0, 3); +if (strlen($hopper_priority)<1) {$hopper_priority=0;} +if (strlen($gender)<1) {$gender='U';} + +$StarTtime = date("U"); +$NOW_DATE = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$CIDdate = date("mdHis"); +$ENTRYdate = date("YmdHis"); +$MT[0]=''; +$postalgmt=''; + +$secX = date("U"); +$hour = date("H"); +$min = date("i"); +$sec = date("s"); +$mon = date("m"); +$mday = date("d"); +$year = date("Y"); +$isdst = date("I"); +$Shour = date("H"); +$Smin = date("i"); +$Ssec = date("s"); +$Smon = date("m"); +$Smday = date("d"); +$Syear = date("Y"); +$pulldate0 = "$year-$mon-$mday $hour:$min:$sec"; +$inSD = $pulldate0; +$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); + +### Grab Server GMT value from the database +$stmt="SELECT local_gmt FROM servers where active='Y' limit 1;"; +if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} +$rslt=mysql_query($stmt, $link); +$gmt_recs = mysql_num_rows($rslt); +if ($gmt_recs > 0) + { + $row=mysql_fetch_row($rslt); + $DBSERVER_GMT = "$row[0]"; + if (strlen($DBSERVER_GMT)>0) {$SERVER_GMT = $DBSERVER_GMT;} + if ($isdst) {$SERVER_GMT++;} + } +else + { + $SERVER_GMT = date("O"); + $SERVER_GMT = eregi_replace("\+","",$SERVER_GMT); + $SERVER_GMT = ($SERVER_GMT + 0); + $SERVER_GMT = ($SERVER_GMT / 100); + } + +$LOCAL_GMT_OFF = $SERVER_GMT; +$LOCAL_GMT_OFF_STD = $SERVER_GMT; + + + + + +################################################################################ +### add_lead - inserts a lead into the vicidial_list table +################################################################################ +if ($function == 'add_lead') + { + $stmt="SELECT count(*) from vicidial_users where user='$user' and pass='$pass' and vdc_agent_api_access='1' and modify_leads='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $modify_leads=$row[0]; + + if ($modify_leads < 1) + { + echo "ERROR: add_lead USER DOES NOT HAVE PERMISSION TO ADD LEADS TO THE SYSTEM - $user|$modify_leads\n"; + exit; + } + else + { + if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) ) + { + echo "ERROR: add_lead INVALID PHONE NUMBER - $phone_number|$user\n"; + exit; + } + else + { + if ($dnc_check == 'Y') + { + $stmt="SELECT count(*) from vicidial_dnc where phone_number='$phone_number';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $dnc_found=$row[0]; + + if ($dnc_found > 0) + { + echo "ERROR: add_lead PHONE NUMBER IN DNC - $phone_number|$user\n"; + exit; + } + } + + ### get current gmt_offset of the phone_number + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code); + + ### 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='NEW',user='$user',vendor_lead_code='$vendor_lead_code',source_id='$source_id',gmt_offset_now='$gmt_offset',title='$title',first_name='$first_name',middle_initial='$middle_initial',last_name='$last_name',address1='$address1',address2='$address2',address3='$address3',city='$city',state='$state',province='$province',postal_code='$postal_code',country_code='$country_code',gender='$gender',date_of_birth='$date_of_birth',alt_phone='$alt_phone',email='$email',security_phrase='$security_phrase',comments='$comments',called_since_last_reset='N',entry_date='$ENTRYdate',last_local_call_time='$NOW_TIME';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $affected_rows = mysql_affected_rows($link); + if ($affected_rows > 0) + { + $lead_id = mysql_insert_id($link); + + echo "SUCCESS: add_lead LEAD HAS BEEN ADDED - $phone_number|$user|$list_id|$lead_id|$gmt_offset\n"; + + if ($add_to_hopper == 'Y') + { + $dialable=1; + + $stmt="SELECT local_call_time,vicidial_campaigns.campaign_id from vicidial_campaigns,vicidial_lists where list_id='$list_id' and vicidial_campaigns.campaign_id=vicidial_lists.campaign_id;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $local_call_time=$row[0]; + $campaign_id=$row[1]; + + if ($hopper_local_call_time_check == 'Y') + { + ### call function to determine if lead is dialable + $dialable = dialable_gmt($DB,$link,$local_call_time,$gmt_offset,$state); + } + if ($dialable < 1) + { + echo "NOTICE: add_lead NOT ADDED TO HOPPER, OUTSIDE OF LOCAL TIME - $phone_number|$user|$lead_id|$gmt_offset|$dialable\n"; + } + else + { + ### code to insert into hopper goes here + + ### insert record into vicidial_hopper for alt_phone call attempt + $stmt = "INSERT INTO vicidial_hopper SET lead_id='$lead_id',campaign_id='$campaign_id',status='READY',list_id='$list_id',gmt_offset_now='$gmt_offset',state='$state',user='',priority='$hopper_priority';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $Haffected_rows = mysql_affected_rows($link); + if ($Haffected_rows > 0) + { + $hopper_id = mysql_insert_id($link); + + echo "NOTICE: add_lead ADDED TO HOPPER - $phone_number|$user|$lead_id|$hopper_id\n"; + } + else + { + echo "NOTICE: add_lead NOT ADDED TO HOPPER - $phone_number|$user|$lead_id|$stmt\n"; + } + } + } + } + else + { + echo "ERROR: add_lead LEAD HAS NOT BEEN ADDED - $phone_number|$user|$list_id|$stmt\n"; + } + } + } + } + + + + + + + + + + + +if ($format=='debug') +{ +$ENDtime = date("U"); +$RUNtime = ($ENDtime - $StarTtime); +echo "\n"; +echo "\n\n\n"; +} + +exit; + + + + + + + +##### FUNCTIONS ##### + +##### LOOKUP GMT, FINDS THE CURRENT GMT OFFSET FOR A PHONE NUMBER ##### + +function lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code) +{ +require("dbconnect.php"); + +$postalgmt_found=0; +if ( (eregi("POSTAL",$postalgmt)) && (strlen($postal_code)>4) ) + { + if (preg_match('/^1$/', $phone_code)) + { + $stmt="select * from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $gmt_offset = $row[2]; $gmt_offset = eregi_replace("\+","",$gmt_offset); + $dst = $row[3]; + $dst_range = $row[4]; + $PC_processed++; + $postalgmt_found++; + $post++; + } + } + } +if ($postalgmt_found < 1) + { + $PC_processed=0; + ### UNITED STATES ### + if ($phone_code =='1') + { + $stmt="select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $gmt_offset = $row[4]; $gmt_offset = eregi_replace("\+","",$gmt_offset); + $dst = $row[5]; + $dst_range = $row[6]; + $PC_processed++; + } + } + ### MEXICO ### + if ($phone_code =='52') + { + $stmt="select * from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $gmt_offset = $row[4]; $gmt_offset = eregi_replace("\+","",$gmt_offset); + $dst = $row[5]; + $dst_range = $row[6]; + $PC_processed++; + } + } + ### AUSTRALIA ### + if ($phone_code =='61') + { + $stmt="select * from vicidial_phone_codes where country_code='$phone_code' and state='$state';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $gmt_offset = $row[4]; $gmt_offset = eregi_replace("\+","",$gmt_offset); + $dst = $row[5]; + $dst_range = $row[6]; + $PC_processed++; + } + } + ### ALL OTHER COUNTRY CODES ### + if (!$PC_processed) + { + $PC_processed++; + $stmt="select * from vicidial_phone_codes where country_code='$phone_code';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $gmt_offset = $row[4]; $gmt_offset = eregi_replace("\+","",$gmt_offset); + $dst = $row[5]; + $dst_range = $row[6]; + $PC_processed++; + } + } + } + +### Find out if DST to raise the gmt offset ### +$AC_GMT_diff = ($gmt_offset - $LOCAL_GMT_OFF_STD); +$AC_localtime = mktime(($Shour + $AC_GMT_diff), $Smin, $Ssec, $Smon, $Smday, $Syear); + $hour = date("H",$AC_localtime); + $min = date("i",$AC_localtime); + $sec = date("s",$AC_localtime); + $mon = date("m",$AC_localtime); + $mday = date("d",$AC_localtime); + $wday = date("w",$AC_localtime); + $year = date("Y",$AC_localtime); +$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec ); + +$AC_processed=0; +if ( (!$AC_processed) and ($dst_range == 'SSM-FSN') ) + { + if ($DBX) {print " Second Sunday March to First Sunday November\n";} + #********************************************************************** + # SSM-FSN + # This is returns 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on Second Sunday March to First Sunday November at 2 am. + # INPUTS: + # mm INTEGER Month. + # dd INTEGER Day of the month. + # ns INTEGER Seconds into the day. + # dow INTEGER Day of week (0=Sunday, to 6=Saturday) + # OPTIONAL INPUT: + # timezone INTEGER hour difference UTC - local standard time + # (DEFAULT is blank) + # make calculations based on UTC time, + # which means shift at 10:00 UTC in April + # and 9:00 UTC in October + # OUTPUT: + # INTEGER 1 = DST, 0 = not DST + # + # S M T W T F S + # 1 2 3 4 5 6 7 + # 8 9 10 11 12 13 14 + #15 16 17 18 19 20 21 + #22 23 24 25 26 27 28 + #29 30 31 + # + # S M T W T F S + # 1 2 3 4 5 6 + # 7 8 9 10 11 12 13 + #14 15 16 17 18 19 20 + #21 22 23 24 25 26 27 + #28 29 30 31 + # + #********************************************************************** + + $USACAN_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 3 || $mm > 11) { + $USACAN_DST=0; + } elseif ($mm >= 4 and $mm <= 10) { + $USACAN_DST=1; + } elseif ($mm == 3) { + if ($dd > 13) { + $USACAN_DST=1; + } elseif ($dd >= ($dow+8)) { + if ($timezone) { + if ($dow == 0 and $ns < (7200+$timezone*3600)) { + $USACAN_DST=0; + } else { + $USACAN_DST=1; + } + } else { + if ($dow == 0 and $ns < 7200) { + $USACAN_DST=0; + } else { + $USACAN_DST=1; + } + } + } else { + $USACAN_DST=0; + } + } elseif ($mm == 11) { + if ($dd > 7) { + $USACAN_DST=0; + } elseif ($dd < ($dow+1)) { + $USACAN_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (7200+($timezone-1)*3600)) { + $USACAN_DST=1; + } else { + $USACAN_DST=0; + } + } else { # local time calculations + if ($ns < 7200) { + $USACAN_DST=1; + } else { + $USACAN_DST=0; + } + } + } else { + $USACAN_DST=0; + } + } # end of month checks + if ($DBX) {print " DST: $USACAN_DST\n";} + if ($USACAN_DST) {$gmt_offset++;} + $AC_processed++; + } + +if ( (!$AC_processed) and ($dst_range == 'FSA-LSO') ) + { + if ($DBX) {print " First Sunday April to Last Sunday October\n";} + #********************************************************************** + # FSA-LSO + # This is returns 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on first Sunday in April and last Sunday in October at 2 am. + #********************************************************************** + + $USA_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 4 || $mm > 10) { + $USA_DST=0; + } elseif ($mm >= 5 and $mm <= 9) { + $USA_DST=1; + } elseif ($mm == 4) { + if ($dd > 7) { + $USA_DST=1; + } elseif ($dd >= ($dow+1)) { + if ($timezone) { + if ($dow == 0 and $ns < (7200+$timezone*3600)) { + $USA_DST=0; + } else { + $USA_DST=1; + } + } else { + if ($dow == 0 and $ns < 7200) { + $USA_DST=0; + } else { + $USA_DST=1; + } + } + } else { + $USA_DST=0; + } + } elseif ($mm == 10) { + if ($dd < 25) { + $USA_DST=1; + } elseif ($dd < ($dow+25)) { + $USA_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (7200+($timezone-1)*3600)) { + $USA_DST=1; + } else { + $USA_DST=0; + } + } else { # local time calculations + if ($ns < 7200) { + $USA_DST=1; + } else { + $USA_DST=0; + } + } + } else { + $USA_DST=0; + } + } # end of month checks + + if ($DBX) {print " DST: $USA_DST\n";} + if ($USA_DST) {$gmt_offset++;} + $AC_processed++; + } + +if ( (!$AC_processed) and ($dst_range == 'LSM-LSO') ) + { + if ($DBX) {print " Last Sunday March to Last Sunday October\n";} + #********************************************************************** + # This is s 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on last Sunday in March and last Sunday in October at 1 am. + #********************************************************************** + + $GBR_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 3 || $mm > 10) { + $GBR_DST=0; + } elseif ($mm >= 4 and $mm <= 9) { + $GBR_DST=1; + } elseif ($mm == 3) { + if ($dd < 25) { + $GBR_DST=0; + } elseif ($dd < ($dow+25)) { + $GBR_DST=0; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $GBR_DST=0; + } else { + $GBR_DST=1; + } + } else { # local time calculations + if ($ns < 3600) { + $GBR_DST=0; + } else { + $GBR_DST=1; + } + } + } else { + $GBR_DST=1; + } + } elseif ($mm == 10) { + if ($dd < 25) { + $GBR_DST=1; + } elseif ($dd < ($dow+25)) { + $GBR_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $GBR_DST=1; + } else { + $GBR_DST=0; + } + } else { # local time calculations + if ($ns < 3600) { + $GBR_DST=1; + } else { + $GBR_DST=0; + } + } + } else { + $GBR_DST=0; + } + } # end of month checks + if ($DBX) {print " DST: $GBR_DST\n";} + if ($GBR_DST) {$gmt_offset++;} + $AC_processed++; + } +if ( (!$AC_processed) and ($dst_range == 'LSO-LSM') ) + { + if ($DBX) {print " Last Sunday October to Last Sunday March\n";} + #********************************************************************** + # This is s 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on last Sunday in October and last Sunday in March at 1 am. + #********************************************************************** + + $AUS_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 3 || $mm > 10) { + $AUS_DST=1; + } elseif ($mm >= 4 and $mm <= 9) { + $AUS_DST=0; + } elseif ($mm == 3) { + if ($dd < 25) { + $AUS_DST=1; + } elseif ($dd < ($dow+25)) { + $AUS_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $AUS_DST=1; + } else { + $AUS_DST=0; + } + } else { # local time calculations + if ($ns < 3600) { + $AUS_DST=1; + } else { + $AUS_DST=0; + } + } + } else { + $AUS_DST=0; + } + } elseif ($mm == 10) { + if ($dd < 25) { + $AUS_DST=0; + } elseif ($dd < ($dow+25)) { + $AUS_DST=0; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $AUS_DST=0; + } else { + $AUS_DST=1; + } + } else { # local time calculations + if ($ns < 3600) { + $AUS_DST=0; + } else { + $AUS_DST=1; + } + } + } else { + $AUS_DST=1; + } + } # end of month checks + if ($DBX) {print " DST: $AUS_DST\n";} + if ($AUS_DST) {$gmt_offset++;} + $AC_processed++; + } + +if ( (!$AC_processed) and ($dst_range == 'FSO-LSM') ) + { + if ($DBX) {print " First Sunday October to Last Sunday March\n";} + #********************************************************************** + # TASMANIA ONLY + # This is s 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on first Sunday in October and last Sunday in March at 1 am. + #********************************************************************** + + $AUST_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 3 || $mm > 10) { + $AUST_DST=1; + } elseif ($mm >= 4 and $mm <= 9) { + $AUST_DST=0; + } elseif ($mm == 3) { + if ($dd < 25) { + $AUST_DST=1; + } elseif ($dd < ($dow+25)) { + $AUST_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $AUST_DST=1; + } else { + $AUST_DST=0; + } + } else { # local time calculations + if ($ns < 3600) { + $AUST_DST=1; + } else { + $AUST_DST=0; + } + } + } else { + $AUST_DST=0; + } + } elseif ($mm == 10) { + if ($dd > 7) { + $AUST_DST=1; + } elseif ($dd >= ($dow+1)) { + if ($timezone) { + if ($dow == 0 and $ns < (7200+$timezone*3600)) { + $AUST_DST=0; + } else { + $AUST_DST=1; + } + } else { + if ($dow == 0 and $ns < 3600) { + $AUST_DST=0; + } else { + $AUST_DST=1; + } + } + } else { + $AUST_DST=0; + } + } # end of month checks + if ($DBX) {print " DST: $AUST_DST\n";} + if ($AUST_DST) {$gmt_offset++;} + $AC_processed++; + } +if ( (!$AC_processed) and ($dst_range == 'FSO-TSM') ) + { + if ($DBX) {print " First Sunday October to Third Sunday March\n";} + #********************************************************************** + # This is s 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on first Sunday in October and third Sunday in March at 1 am. + #********************************************************************** + + $NZL_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 3 || $mm > 10) { + $NZL_DST=1; + } elseif ($mm >= 4 and $mm <= 9) { + $NZL_DST=0; + } elseif ($mm == 3) { + if ($dd < 14) { + $NZL_DST=1; + } elseif ($dd < ($dow+14)) { + $NZL_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $NZL_DST=1; + } else { + $NZL_DST=0; + } + } else { # local time calculations + if ($ns < 3600) { + $NZL_DST=1; + } else { + $NZL_DST=0; + } + } + } else { + $NZL_DST=0; + } + } elseif ($mm == 10) { + if ($dd > 7) { + $NZL_DST=1; + } elseif ($dd >= ($dow+1)) { + if ($timezone) { + if ($dow == 0 and $ns < (7200+$timezone*3600)) { + $NZL_DST=0; + } else { + $NZL_DST=1; + } + } else { + if ($dow == 0 and $ns < 3600) { + $NZL_DST=0; + } else { + $NZL_DST=1; + } + } + } else { + $NZL_DST=0; + } + } # end of month checks + if ($DBX) {print " DST: $NZL_DST\n";} + if ($NZL_DST) {$gmt_offset++;} + $AC_processed++; + } + +if ( (!$AC_processed) and ($dst_range == 'TSO-LSF') ) + { + if ($DBX) {print " Third Sunday October to Last Sunday February\n";} + #********************************************************************** + # TSO-LSF + # This is returns 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. Brazil + # Based on Third Sunday October to Last Sunday February at 1 am. + #********************************************************************** + + $BZL_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 2 || $mm > 10) { + $BZL_DST=1; + } elseif ($mm >= 3 and $mm <= 9) { + $BZL_DST=0; + } elseif ($mm == 2) { + if ($dd < 22) { + $BZL_DST=1; + } elseif ($dd < ($dow+22)) { + $BZL_DST=1; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $BZL_DST=1; + } else { + $BZL_DST=0; + } + } else { # local time calculations + if ($ns < 3600) { + $BZL_DST=1; + } else { + $BZL_DST=0; + } + } + } else { + $BZL_DST=0; + } + } elseif ($mm == 10) { + if ($dd < 22) { + $BZL_DST=0; + } elseif ($dd < ($dow+22)) { + $BZL_DST=0; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $BZL_DST=0; + } else { + $BZL_DST=1; + } + } else { # local time calculations + if ($ns < 3600) { + $BZL_DST=0; + } else { + $BZL_DST=1; + } + } + } else { + $BZL_DST=1; + } + } # end of month checks + if ($DBX) {print " DST: $BZL_DST\n";} + if ($BZL_DST) {$gmt_offset++;} + $AC_processed++; + } + +if (!$AC_processed) + { + if ($DBX) {print " No DST Method Found\n";} + if ($DBX) {print " DST: 0\n";} + $AC_processed++; + } + +return $gmt_offset; +} + + + + + +##### DETERMINE IF LEAD IS DIALABLE ##### +function dialable_gmt($DB,$link,$local_call_time,$gmt_offset,$state) +{ +$dialable=0; + +$pzone=3600 * $gmt_offset; +$pmin=(gmdate("i", time() + $pzone)); +$phour=( (gmdate("G", time() + $pzone)) * 100); +$pday=gmdate("w", time() + $pzone); +$tz = sprintf("%.2f", $p); +$GMT_gmt = "$tz"; +$GMT_day = "$pday"; +$GMT_hour = ($phour + $pmin); + +$stmt="SELECT * FROM vicidial_call_times where call_time_id='$local_call_time';"; +if ($DB) {echo "$stmt\n";} +$rslt=mysql_query($stmt, $link); +$rowx=mysql_fetch_row($rslt); +$Gct_default_start = "$rowx[3]"; +$Gct_default_stop = "$rowx[4]"; +$Gct_sunday_start = "$rowx[5]"; +$Gct_sunday_stop = "$rowx[6]"; +$Gct_monday_start = "$rowx[7]"; +$Gct_monday_stop = "$rowx[8]"; +$Gct_tuesday_start = "$rowx[9]"; +$Gct_tuesday_stop = "$rowx[10]"; +$Gct_wednesday_start = "$rowx[11]"; +$Gct_wednesday_stop = "$rowx[12]"; +$Gct_thursday_start = "$rowx[13]"; +$Gct_thursday_stop = "$rowx[14]"; +$Gct_friday_start = "$rowx[15]"; +$Gct_friday_stop = "$rowx[16]"; +$Gct_saturday_start = "$rowx[17]"; +$Gct_saturday_stop = "$rowx[18]"; +$Gct_state_call_times = "$rowx[19]"; + +if ($GMT_day==0) #### Sunday local time + { + if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_sunday_start) and ($GMT_hour<$Gct_sunday_stop) ) + {$dialable=1;} + } + } +if ($GMT_day==1) #### Monday local time + { + if (($Gct_monday_start==0) and ($Gct_monday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_monday_start) and ($GMT_hour<$Gct_monday_stop) ) + {$dialable=1;} + } + } +if ($GMT_day==2) #### Tuesday local time + { + if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_tuesday_start) and ($GMT_hour<$Gct_tuesday_stop) ) + {$dialable=1;} + } + } +if ($GMT_day==3) #### Wednesday local time + { + if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_wednesday_start) and ($GMT_hour<$Gct_wednesday_stop) ) + {$dialable=1;} + } + } +if ($GMT_day==4) #### Thursday local time + { + if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_thursday_start) and ($GMT_hour<$Gct_thursday_stop) ) + {$dialable=1;} + } + } +if ($GMT_day==5) #### Friday local time + { + if (($Gct_friday_start==0) and ($Gct_friday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_friday_start) and ($GMT_hour<$Gct_friday_stop) ) + {$dialable=1;} + } + } +if ($GMT_day==6) #### Saturday local time + { + if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0)) + { + if ( ($GMT_hour>=$Gct_default_start) and ($GMT_hour<$Gct_default_stop) ) + {$dialable=1;} + } + else + { + if ( ($GMT_hour>=$Gct_saturday_start) and ($GMT_hour<$Gct_saturday_stop) ) + {$dialable=1;} + } + } + +return $dialable; +} + +/* + $ct_states = ''; + $ct_state_gmt_SQL = ''; + $ct_srs=0; + $b=0; + if (strlen($Gct_state_call_times)>2) + { + $state_rules = explode('|',$Gct_state_call_times); + $ct_srs = ((count($state_rules)) - 2); + } + while($ct_srs >= $b) + { + if ( (strlen($state_rules[$b])>1) and (strlen($state)>1) ) + { + $stmt="SELECT * from vicidial_state_call_times where state_call_time_id='$state_rules[$b]' and state_call_time_state='$state';"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $Gstate_call_time_id = "$row[0]"; + $Gstate_call_time_state = "$row[1]"; + $Gsct_default_start = "$row[4]"; + $Gsct_default_stop = "$row[5]"; + $Gsct_sunday_start = "$row[6]"; + $Gsct_sunday_stop = "$row[7]"; + $Gsct_monday_start = "$row[8]"; + $Gsct_monday_stop = "$row[9]"; + $Gsct_tuesday_start = "$row[10]"; + $Gsct_tuesday_stop = "$row[11]"; + $Gsct_wednesday_start = "$row[12]"; + $Gsct_wednesday_stop = "$row[13]"; + $Gsct_thursday_start = "$row[14]"; + $Gsct_thursday_stop = "$row[15]"; + $Gsct_friday_start = "$row[16]"; + $Gsct_friday_stop = "$row[17]"; + $Gsct_saturday_start = "$row[18]"; + $Gsct_saturday_stop = "$row[19]"; + + $ct_states .="'$Gstate_call_time_state',"; + + $r=0; + $state_gmt=''; + while($r < $g) + { + if ($GMT_day[$r]==0) #### Sunday local time + { + if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==1) #### Monday local time + { + if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==2) #### Tuesday local time + { + if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==3) #### Wednesday local time + { + if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==4) #### Thursday local time + { + if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==5) #### Friday local time + { + if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==6) #### Saturday local time + { + if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + $r++; + } + $state_gmt = "$state_gmt'99'"; + $ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; + } + + $b++; + } + if (strlen($ct_states)>2) + { + $ct_states = eregi_replace(",$",'',$ct_states); + $ct_statesSQL = "and state NOT IN($ct_states)"; + } + else + { + $ct_statesSQL = ""; + } + +*/ + +?>