From 8db9910e9a6520f63a59c40f4562ebd9c832963c Mon Sep 17 00:00:00 2001 From: mattf Date: Thu, 29 Jan 2009 18:33:54 +0000 Subject: [PATCH] Added option to use NANPA prefix data to set time zone coding. Data file must be purchased from the VICIDIAL Group git-svn-id: svn://192.168.202.10@1040 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 4 + .../trunk/bin/ADMIN_adjust_GMTnow_on_leads.pl | 406 ++++++++++++++---- agc_2-X/trunk/bin/ADMIN_area_code_populate.pl | 312 ++++++++++---- agc_2-X/trunk/docs/VTIGER.txt | 2 +- agc_2-X/trunk/extras/upgrade_2.0.5.sql | 17 + 5 files changed, 563 insertions(+), 178 deletions(-) diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 7615e642..6fcf8e6f 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -233,6 +233,10 @@ NOTE: Upgrading from 1.1.12-3 to 2.0.1 is at the bottom 52. Added agent alert option to agent screen. sends browser alert prompt when a call is send to the agent screen. +53. Added option for using North American NANPA prefix timezone encoding for + more accurate time zone encoding. The data is NOT included but can be + purchased from the VICIDIAL Group. + diff --git a/agc_2-X/trunk/bin/ADMIN_adjust_GMTnow_on_leads.pl b/agc_2-X/trunk/bin/ADMIN_adjust_GMTnow_on_leads.pl index bd3bd4ab..e749bfc7 100644 --- a/agc_2-X/trunk/bin/ADMIN_adjust_GMTnow_on_leads.pl +++ b/agc_2-X/trunk/bin/ADMIN_adjust_GMTnow_on_leads.pl @@ -7,7 +7,7 @@ # # run every time you load leads into the vicidial_list table # -# Copyright (C) 2008 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 # # # CHANGES @@ -22,6 +22,7 @@ # 70823-1633 - Added ability to restrict by list_id # 80917-2202 - Added FSO-FSA for Eastern Australia (not active) # Added LSS-FSA for New Zealand (not active) +# 90129-1114 - Added NANPA prefix lookup option # $MT[0]=''; @@ -44,6 +45,7 @@ if (length($ARGV[0])>1) print " [--debug] = debugging messages\n"; print " [--debugX] = Super debugging messages\n"; print " [--postal-code-gmt] = Attempt postal codes lookup for timezones\n"; + print " [--nanpa-prefix-gmt] = Attempt nanpa prefix lookup for timezones\n"; print " [--singlelistid=XXX] = Only lookup and alter leads in one list_id\n"; print "\n"; @@ -75,6 +77,11 @@ if (length($ARGV[0])>1) $searchPOST=1; print "\n----- DO POSTAL CODE LOOKUP -----\n\n"; } + if ($args =~ /--nanpa-prefix-gmt/i) + { + $searchNANPA=1; + print "\n----- DO NANPA PREFIX LOOKUP -----\n\n"; + } if ($args =~ /-singlelistid=/i) { @data_in = split(/-singlelistid=/,$args); @@ -159,59 +166,59 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA or die "Couldn't connect to database: " . DBI->errstr; - ### Grab Server values from the database - $stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrUSERNAMElisten,ASTmgrUSERNAMEsend,max_vicidial_trunks,answer_transfer_agent,local_gmt,ext_context FROM servers where server_ip = '$server_ip';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_countY=0; - while ($sthArows > $rec_countY) +### Grab Server values from the database +$stmtA = "SELECT telnet_host,telnet_port,ASTmgrUSERNAME,ASTmgrSECRET,ASTmgrUSERNAMEupdate,ASTmgrUSERNAMElisten,ASTmgrUSERNAMEsend,max_vicidial_trunks,answer_transfer_agent,local_gmt,ext_context FROM servers where server_ip = '$server_ip';"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_countY=0; +while ($sthArows > $rec_countY) { - @aryA = $sthA->fetchrow_array; - $DBtelnet_host = "$aryA[0]"; - $DBtelnet_port = "$aryA[1]"; - $DBASTmgrUSERNAME = "$aryA[2]"; - $DBASTmgrSECRET = "$aryA[3]"; - $DBASTmgrUSERNAMEupdate = "$aryA[4]"; - $DBASTmgrUSERNAMElisten = "$aryA[5]"; - $DBASTmgrUSERNAMEsend = "$aryA[6]"; - $DBmax_vicidial_trunks = "$aryA[7]"; - $DBanswer_transfer_agent= "$aryA[8]"; - $DBSERVER_GMT = "$aryA[9]"; - $DBext_context = "$aryA[10]"; - if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} - if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} - if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} - if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} - if ($DBASTmgrUSERNAMEupdate) {$ASTmgrUSERNAMEupdate = $DBASTmgrUSERNAMEupdate;} - if ($DBASTmgrUSERNAMElisten) {$ASTmgrUSERNAMElisten = $DBASTmgrUSERNAMElisten;} - if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} - if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} - if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} - if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} - if ($DBext_context) {$ext_context = $DBext_context;} - $rec_countY++; - } - $sthA->finish(); + @aryA = $sthA->fetchrow_array; + $DBtelnet_host = "$aryA[0]"; + $DBtelnet_port = "$aryA[1]"; + $DBASTmgrUSERNAME = "$aryA[2]"; + $DBASTmgrSECRET = "$aryA[3]"; + $DBASTmgrUSERNAMEupdate = "$aryA[4]"; + $DBASTmgrUSERNAMElisten = "$aryA[5]"; + $DBASTmgrUSERNAMEsend = "$aryA[6]"; + $DBmax_vicidial_trunks = "$aryA[7]"; + $DBanswer_transfer_agent= "$aryA[8]"; + $DBSERVER_GMT = "$aryA[9]"; + $DBext_context = "$aryA[10]"; + if ($DBtelnet_host) {$telnet_host = $DBtelnet_host;} + if ($DBtelnet_port) {$telnet_port = $DBtelnet_port;} + if ($DBASTmgrUSERNAME) {$ASTmgrUSERNAME = $DBASTmgrUSERNAME;} + if ($DBASTmgrSECRET) {$ASTmgrSECRET = $DBASTmgrSECRET;} + if ($DBASTmgrUSERNAMEupdate) {$ASTmgrUSERNAMEupdate = $DBASTmgrUSERNAMEupdate;} + if ($DBASTmgrUSERNAMElisten) {$ASTmgrUSERNAMElisten = $DBASTmgrUSERNAMElisten;} + if ($DBASTmgrUSERNAMEsend) {$ASTmgrUSERNAMEsend = $DBASTmgrUSERNAMEsend;} + if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;} + if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} + if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;} + if ($DBext_context) {$ext_context = $DBext_context;} + $rec_countY++; + } +$sthA->finish(); - $LOCAL_GMT_OFF = $SERVER_GMT; - $LOCAL_GMT_OFF_STD = $SERVER_GMT; +$LOCAL_GMT_OFF = $SERVER_GMT; +$LOCAL_GMT_OFF_STD = $SERVER_GMT; if ($isdst) {$LOCAL_GMT_OFF++;} if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";} if (length($singlelistid)> 0) {$listSQL = "where list_id='$singlelistid'"; $XlistSQL=" and list_id='$singlelistid' ";} else {$listSQL = ''; $XlistSQL='';} - $stmtA = "select distinct phone_code from vicidial_list $listSQL;"; - 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_countY=0; - @phone_codes=@MT; - $phone_codes_list='|'; - - while ($sthArows > $rec_countY) +$stmtA = "select distinct phone_code from vicidial_list $listSQL;"; +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_countY=0; + @phone_codes=@MT; + $phone_codes_list='|'; + +while ($sthArows > $rec_countY) { @aryA = $sthA->fetchrow_array; @@ -232,7 +239,7 @@ else {$listSQL = ''; $XlistSQL='';} if ($DB) {print " - Unique Country dial codes found: $rec_countY\n";} - ##### Put all country/are code records into an array for speed + ##### Put all country/area code records into an array for speed $stmtA = "select * from vicidial_phone_codes;"; if($DBX){print STDERR "\n|$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -240,37 +247,61 @@ else {$listSQL = ''; $XlistSQL='';} $sthArows=$sthA->rows; $rec_countZ=0; @codefile=@MT; - while ($sthArows > $rec_countZ) - { - @aryA = $sthA->fetchrow_array; - + { + @aryA = $sthA->fetchrow_array; $codefile[$rec_countZ] = "$aryA[0]\t$aryA[1]\t$aryA[2]\t$aryA[3]\t$aryA[4]\t$aryA[5]\t$aryA[6]\t$aryA[7]\n"; $rec_countZ++; - } + } - ##### Put all postal code records into an array for speed - $stmtA = "select * from vicidial_postal_codes;"; - 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_countT=0; - @postalfile=@MT; - - while ($sthArows > $rec_countT) - { - @aryA = $sthA->fetchrow_array; - - $postalfile[$rec_countT] = "$aryA[0]\t$aryA[1]\t$aryA[2]\t$aryA[3]\t$aryA[4]\t$aryA[5]\t$aryA[6]"; - $rec_countT++; - } + if ($searchPOST > 0) + { + ##### Put all postal code records into an array for speed + $stmtA = "select * from vicidial_postal_codes;"; + 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_countT=0; + @postalfile=@MT; + while ($sthArows > $rec_countT) + { + @aryA = $sthA->fetchrow_array; + $postalfile[$rec_countT] = "$aryA[0]\t$aryA[1]\t$aryA[2]\t$aryA[3]\t$aryA[4]\t$aryA[5]\t$aryA[6]"; + $rec_countT++; + } + $sthA->finish(); + if ($DB) {print " - GMT postal codes records: $rec_countT\n";} + } - $sthA->finish(); - if ($DB) {print " - GMT postal codes records: $rec_countT\n";} + if ($searchNANPA > 0) + { + ##### Put all nanpa prefix records into an array for speed + $stmtA = "select areacode,prefix,GMT_offset,DST from vicidial_nanpa_prefix_codes;"; + 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_countN=0; + @nanpafile=@MT; + while ($sthArows > $rec_countN) + { + if ($DST =~ /Y/) {$DST_method = 'SSM-FSN';} + else {$DST_method = '';} + @aryA = $sthA->fetchrow_array; + $nanpafile[$rec_countN] = "$aryA[0]\t$aryA[1]\t$aryA[2]\t$DST_method"; + $rec_countN++; + } + $sthA->finish(); + if ($DB) {print " - NANPA prefix records: $rec_countN\n";} + } $ep=0; $ei=0; $ee=0; $d=0; +$TOTALpostal_updated_count=0; +$TOTALarea_updated_count=0; +$TOTALnanpa_updated_count=0; + foreach (@phone_codes) { $match_code = $phone_codes[$d]; @@ -460,37 +491,42 @@ foreach (@phone_codes) $e++; } ##### END RUN LOOP FOR EACH COUNTRY CODE/AREA CODE RECORD THAT IS INSIDE THIS COUNTRY CODE ##### + if($DB){print "Area Code Updates: $area_updated_count\n";} + $TOTALarea_updated_count = ($TOTALarea_updated_count + $area_updated_count); + + + + ##### BEGIN RUN LOOP FOR EACH POSTAL CODE RECORD THAT IS INSIDE THIS COUNTRY CODE ##### + $postal_updated_count=0; if ($searchPOST > 0) { - ##### BEGIN RUN LOOP FOR EACH POSTAL CODE RECORD THAT IS INSIDE THIS COUNTRY CODE ##### if ($DB) {print "POSTAL CODE RUN START...\n";} - $postal_updated_count=0; $e=0; foreach (@postalfile) { chomp($postalfile[$e]); if ($postalfile[$e] =~ /\t$match_code$/) { - @m = split(/\t/, $postalfile[$e]); - $postal_code = $m[0]; - $postal_state = $m[1]; - $area_GMT = $m[2]; $area_GMT =~ s/\+//gi; $area_GMT = ($area_GMT + 0); - $area_GMT_method = $m[4]; - $AC_match = " and postal_code LIKE \"$postal_code%\""; - if ($DBX) {print "PROCESSING THIS LINE: $postalfile[$e]\n";} - - $stmtA = "select count(*) from vicidial_list where phone_code='$match_code_ORIG' $AC_match $XlistSQL;"; - 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_countZ=0; - @aryA = $sthA->fetchrow_array; - $rec_countZ = $aryA[0]; - $sthA->finish(); + @m = split(/\t/, $postalfile[$e]); + $postal_code = $m[0]; + $postal_state = $m[1]; + $area_GMT = $m[2]; $area_GMT =~ s/\+//gi; $area_GMT = ($area_GMT + 0); + $area_GMT_method = $m[4]; + $AC_match = " and postal_code LIKE \"$postal_code%\""; + if ($DBX) {print "PROCESSING THIS LINE: $postalfile[$e]\n";} + + $stmtA = "select count(*) from vicidial_list where phone_code='$match_code_ORIG' $AC_match $XlistSQL;"; + 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_countZ=0; + @aryA = $sthA->fetchrow_array; + $rec_countZ = $aryA[0]; + $sthA->finish(); if (!$rec_countZ) { @@ -636,8 +672,188 @@ foreach (@phone_codes) } $e++; } - ##### END RUN LOOP FOR EACH POSTAL CODE RECORD THAT IS INSIDE THIS COUNTRY CODE ##### } + ##### END RUN LOOP FOR EACH POSTAL CODE RECORD THAT IS INSIDE THIS COUNTRY CODE ##### + if($DB){print "Postal Updates: $postal_updated_count\n";} + $TOTALpostal_updated_count = ($TOTALpostal_updated_count + $postal_updated_count); + + + + + + ##### START RUN LOOP FOR EACH NANPA PREFIX RECORD ##### + # areacode,prefix,GMT_offset,DST,SSM-FSN + $nanpa_updated_count=0; + if ( ($searchNANPA > 0) && ($match_code =~ /^1$/) ) + { + if ($DB) {print "NANPA PREFIX RUN START...\n";} + $e=0; + foreach (@nanpafile) + { + chomp($nanpafile[$e]); + @m = split(/\t/, $nanpafile[$e]); + $nanpa_areacode = $m[0]; + $nanpa_prefix = $m[1]; + $area_GMT = $m[2]; $area_GMT =~ s/\+//gi; $area_GMT = ($area_GMT + 0); + $area_GMT_method = $m[3]; + $AC_match = " and phone_number LIKE \"$nanpa_areacode$nanpa_prefix%\""; + if ($DBX) {print "PROCESSING THIS LINE: $nanpafile[$e]\n";} + + $stmtA = "select count(*) from vicidial_list where phone_code='$match_code_ORIG' $AC_match $XlistSQL;"; + 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_countZ=0; + @aryA = $sthA->fetchrow_array; + $rec_countZ = $aryA[0]; + $sthA->finish(); + + if (!$rec_countZ) + { + # if ($DB) {print " IGNORING: $nanpafile[$e]\n";} + $ei++; + } + else + { + $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) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /FSO-FSA/) ) + { + if ($DBX) {print " First Sunday October to First Sunday April\n";} + &AUSE_dstcalc; + if ($DBX) {print " DST: $AUSE_DST\n";} + if ($AUSE_DST) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /LSS-FSA/) ) + { + if ($DBX) {print " Last Sunday September to First Sunday April\n";} + &NZLN_dstcalc; + if ($DBX) {print " DST: $NZLN_DST\n";} + if ($NZLN_DST) {$area_GMT++;} + $AC_processed++; + } + if ( (!$AC_processed) && ($area_GMT_method =~ /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) {$area_GMT++;} + $AC_processed++; + } + if (!$AC_processed) + { + if ($DBX) {print " No DST Method Found\n";} + if ($DBX) {print " DST: 0\n";} + $AC_processed++; + } + + + if ($AC_processed) + { + $stmtA = "select count(*) from vicidial_list where phone_code='$match_code_ORIG' $AC_match and (gmt_offset_now != '$area_GMT' or gmt_offset_now IS NULL) $XlistSQL;"; + 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_countW=0; + @aryA = $sthA->fetchrow_array; + $rec_countW = $aryA[0]; + $sthA->finish(); + + if (!$rec_countW) + { + if ($DBX) {print " ALL GMT ALREADY CORRECT FOR : $match_code_ORIG $nanpa_code $area_GMT\n";} + $ei++; + } + else + { + $stmtA = "update vicidial_list set gmt_offset_now='$area_GMT' where phone_code='$match_code_ORIG' $AC_match and (gmt_offset_now != '$area_GMT' or gmt_offset_now IS NULL) $XlistSQL;"; + if($DBX){print STDERR "\n|$stmtA|\n";} + if (!$T) + { + $affected_rows = $dbhA->do($stmtA); + $nanpa_updated_count = ($nanpa_updated_count + $affected_rows); + } + $Prec_countW = sprintf("%8s", $rec_countW); + if ($DB) {print " $Prec_countW records in $match_code_ORIG $nanpa_areacode $nanpa_prefix updated to $area_GMT\n";} + $ee++; + # sleep(1); + } + } + } + + $ep++; + $e++; + } + } + ##### START RUN LOOP FOR EACH NANPA PREFIX RECORD ##### + if($DB){print "NANPA Updates: $nanpa_updated_count\n";} + $TOTALnanpa_updated_count = ($TOTALnanpa_updated_count + $nanpa_updated_count); + + $d++; } @@ -645,11 +861,13 @@ foreach (@phone_codes) $dbhA->disconnect(); -if($DB){print "Postal Updates: $postal_updated_count\n";} -if($DB){print "Area Code Updates: $area_updated_count\n";} +if($DB){print "\nGRAND TOTALS:\n";} +if($DB){print "Postal Updates: $TOTALpostal_updated_count\n";} +if($DB){print "Area Code Updates: $TOTALarea_updated_count\n";} +if($DB){print "NANPA Updates: $TOTALnanpa_updated_count\n";} if($DB){print "\nDONE\n";} $secy = time(); $secz = ($secy - $secX); $minz = ($secz/60); # calculate script runtime so far -print "\n - process runtime ($secz sec) ($minz minutes)\n"; +print " - process runtime ($secz sec) ($minz minutes)\n"; exit; diff --git a/agc_2-X/trunk/bin/ADMIN_area_code_populate.pl b/agc_2-X/trunk/bin/ADMIN_area_code_populate.pl index 3a260834..d42a1832 100644 --- a/agc_2-X/trunk/bin/ADMIN_area_code_populate.pl +++ b/agc_2-X/trunk/bin/ADMIN_area_code_populate.pl @@ -2,7 +2,7 @@ # # ADMIN_area_code_populate.pl version 2.0.5 # -# Copyright (C) 2008 Joe Johnson,Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2009 Matt Florell LICENSE: AGPLv2 # # Description: # server application that allows load areacodes into to asterisk list database @@ -12,7 +12,9 @@ # 60807-1003 - Changed to DBI # - changed to use /etc/astguiclient.conf for configs # 61122-1902 - Added GMT_USA_zip.txt data import for USA postal GMT data -# 80416-1017 - +# 80416-1017 - Added download of phone codes from remote host +# 90129-0932 - Added optional NANP prefix/time date import "--load-NANPA-prefix" flag +# # default path to astguiclient configuration file: @@ -21,6 +23,80 @@ $domain = "http://phonecodes.vicidial.com"; $URL1 = "$domain/phone_codes_GMT-latest.txt"; $URL2 = "$domain/GMT_USA_zip-latest.txt"; + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help|-h/i) + { + print "allowed run time options:\n"; + print " [-q] = quiet\n"; + print " [-t] = test\n"; + print " [--debug] = debug output\n"; + print " [--use-local-files] = Do not download files, use local copies\n"; + print " [--load-NANPA-prefix] = Only loads the special NANPA list into the database\n"; + print "\n files used by this script are:\n"; + print " phone_codes_GMT-latest.txt - Phone codes and country codes with time zone data\n"; + print " GMT_USA_zip-latest.txt - USA zip code and time zone data\n"; + print " NANPA_prefix-latest.txt - North American areacode, prefix and time zone data\n"; + + exit; + } + else + { + if ($args =~ /-debug/i) + { + $DB=1; + print "\n----- DEBUGGING -----\n\n"; + } + if ($args =~ /-debugX/i) + { + $DBX=1; + print "\n----- SUPER-DUPER DEBUGGING -----\n\n"; + } + else {$DBX=0;} + + if ($args =~ /-q/i) + { + $q=1; + } + if ($args =~ /-t/i) + { + $T=1; + $TEST=1; + print "\n----- TESTING -----\n\n"; + } + if ($args =~ /--use-local-files/i) + { + $use_local_files=1; + print "\n----- USING LOCAL DATA FILES -----\n\n"; + } + if ($args =~ /--load-NANPA-prefix/i) + { + $nanpa_load=1; + print "\n----- NANPA PHONE PREFIX DATA LOAD -----\n\n"; + } + } + } +else + { + print "no command line options set\n"; + $args = ""; + $i=0; + $forcelistid = ''; + $format='standard'; + } +### end parsing run-time options ### + + + open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; @conf = ; close(conf); @@ -58,6 +134,7 @@ foreach(@conf) # Customized Variables $server_ip = $VARserver_ip; # Asterisk server IP +$slash_star = '\*'; use Time::HiRes ('gettimeofday','usleep','sleep'); # needed to have perl sleep in increments of less than one second @@ -68,97 +145,166 @@ if (!$VARDB_port) {$VARDB_port='3306';} $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr; -$slash_star = '\*'; -#### download the latest phone code table #### -chdir("$PATHhome"); -$wget = `which wget`; -print "$wget\n"; -if ( $wget eq "" ) { - print STDERR "Please install the wget command\n"; - exit(); -} - -print STDERR "Downloading latest phone codes tables\n"; - -`wget $URL1`; -`wget $URL2`; - -#### BEGIN vicidial_phone_codes population from phone_codes_GMT.txt file #### -open(codefile, "$PATHhome/phone_codes_GMT-latest.txt") || die "can't open $PATHhome/phone_codes_GMT-latest.txt: $!\n"; -@codefile = ; -close(codefile); -$pc=0; -$ins_stmt="insert into vicidial_phone_codes VALUES "; -foreach (@codefile) -{ - @row=split(/\t/, $codefile[$pc]); - if ($codefile[$pc] !~ /GEOGRAPHIC DESCRIPTION/) +if ($nanpa_load > 0) { - $pc++; - $row[7] =~ s/\r|\n|\t| $//gi; - $row[6] =~ s/\r|\n|\t| $//gi; - $row[5] =~ s/\r|\n|\t| $//gi; - $row[4] =~ s/\r|\n|\t| $//gi; - $row[3] =~ s/\r|\n|\t| $//gi; - $row[2] =~ s/\r|\n|\t| $//gi; - $row[1] =~ s/\r|\n|\t| $//gi; - $row[0] =~ s/\r|\n|\t| $//gi; - $ins_stmt.="('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[4]', '$row[5]', '$row[6]', '$row[7]'), "; - if ($pc =~ /00$/) + #### load special North American phone code prefix table #### + # LONG # NPA,NXX,,,,,,,,,,,,,TZ,DST,,,,,,,,,,,,LATITUDE,LONGITUDE,,,,, + # SHORT # NPA,NXX,TZ,DST,LATITUDE,LONGITUDE + + #### BEGIN vicidial_nanpa_prefix_codes population from NANPA_prefix-latest.txt file #### + open(prefixfile, "$PATHhome/NANPA_prefix-latest.txt") || die "can't open $PATHhome/NANPA_prefix-latest.txt: $!\n"; + @prefixfile = ; + close(prefixfile); + $pc=0; $full_file=0; + $ins_stmt="insert into vicidial_nanpa_prefix_codes VALUES "; + foreach (@prefixfile) { + if (length($prefixfile[$pc])>60) + {$full_file++;} + if ( ($prefixfile[$pc] !~ /XXXXX/) && ($prefixfile[$pc] !~ /^\D|^0|^1/) ) + { + $prefixfile[$pc] =~ s/\r|\n|\t| $//gi; + @row=split(/,/, $prefixfile[$pc]); + $pc++; + if ($full_file > 0) + { + if ($row[14] !~ /XX/) + { + $row[14] =~ s/NT/-3.50/gi; + $row[14] =~ s/AT/-4.00/gi; + $row[14] =~ s/ET/-5.00/gi; + $row[14] =~ s/CT/-6.00/gi; + $row[14] =~ s/MT/-7.00/gi; + $row[14] =~ s/PT/-8.00/gi; + $row[14] =~ s/AK/-9.00/gi; + $row[14] =~ s/HT/-10.00/gi; + $row[14] =~ s/AS/-11.00/gi; + $row[14] =~ s/CH/10.00/gi; + $row[15] =~ s/X/N/gi; + $ins_stmt.="('$row[0]', '$row[1]', '$row[14]', '$row[15]', '$row[27]', '$row[28]'), "; + } + } + else + {$ins_stmt.="('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[4]', '$row[5]'), ";} + if ($pc =~ /000$/) + { + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt) || die "can't execute query: |$ins_stmt| $!\n"; + $ins_stmt="insert into vicidial_nanpa_prefix_codes VALUES "; + print STDERR "$pc\n"; + } + } + else + {$pc++;} + } + + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt); + $ins_stmt="insert into vicidial_nanpa_prefix_codes VALUES "; + print STDERR "$pc\n"; + #### END vicidial_nanpa_prefix_codes population #### + + } +else + { + #### download the latest phone code table #### + chdir("$PATHhome"); + + if ($use_local_files < 1) + { + $wget = `which wget`; + print "$wget\n"; + if ( $wget eq "" ) + { + print STDERR "Please install the wget command\n"; + exit(); + } + + print STDERR "Downloading latest phone codes tables\n"; + + `wget $URL1`; + `wget $URL2`; + } + + #### BEGIN vicidial_phone_codes population from phone_codes_GMT-latest.txt file #### + open(codefile, "$PATHhome/phone_codes_GMT-latest.txt") || die "can't open $PATHhome/phone_codes_GMT-latest.txt: $!\n"; + @codefile = ; + close(codefile); + $pc=0; + $ins_stmt="insert into vicidial_phone_codes VALUES "; + foreach (@codefile) + { + @row=split(/\t/, $codefile[$pc]); + if ($codefile[$pc] !~ /GEOGRAPHIC DESCRIPTION/) + { + $pc++; + $row[7] =~ s/\r|\n|\t| $//gi; + $row[6] =~ s/\r|\n|\t| $//gi; + $row[5] =~ s/\r|\n|\t| $//gi; + $row[4] =~ s/\r|\n|\t| $//gi; + $row[3] =~ s/\r|\n|\t| $//gi; + $row[2] =~ s/\r|\n|\t| $//gi; + $row[1] =~ s/\r|\n|\t| $//gi; + $row[0] =~ s/\r|\n|\t| $//gi; + $ins_stmt.="('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[4]', '$row[5]', '$row[6]', '$row[7]'), "; + if ($pc =~ /00$/) + { + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt) || die "can't execute query: |$ins_stmt| $!\n"; + $ins_stmt="insert into vicidial_phone_codes VALUES "; + print STDERR "$pc\n"; + } + } + else {$pc++;} + } + + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt); + $ins_stmt="insert into vicidial_phone_codes VALUES "; + print STDERR "$pc\n"; + #### END vicidial_phone_codes population #### + + + #### BEGIN vicidial_postal_codes population from GMT_USA_zip-latest.txt file #### + open(zipfile, "$PATHhome/GMT_USA_zip-latest.txt") || die "can't open $PATHhome/GMT_USA_zip-latest.txt: $!\n"; + @zipfile = ; + close(zipfile); + $pc=0; + $ins_stmt="insert into vicidial_postal_codes VALUES "; + foreach (@zipfile) + { + @row=split(/\t/, $zipfile[$pc]); + $pc++; + $row[0] =~ s/\r|\n|\t| $//gi; + $row[1] =~ s/\r|\n|\t| $//gi; + $row[2] =~ s/\r|\n|\t| $//gi; + $row[3] =~ s/\r|\n|\t| $//gi; + if ($row[3] =~ /Y/i) {$DST_range = 'SSM-FSN';} + else {$DST_range = '';} + $ins_stmt.="('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$DST_range', 'USA', '1'), "; + if ($pc =~ /00$/) + { chop($ins_stmt); chop($ins_stmt); $affected_rows = $dbhA->do($ins_stmt) || die "can't execute query: |$ins_stmt| $!\n"; - $ins_stmt="insert into vicidial_phone_codes VALUES "; + $ins_stmt="insert into vicidial_postal_codes VALUES "; print STDERR "$pc\n"; + } } + + chop($ins_stmt); + chop($ins_stmt); + $affected_rows = $dbhA->do($ins_stmt); + $ins_stmt="insert into vicidial_postal_codes VALUES "; + print STDERR "$pc\n"; + #### END vicidial_postal_codes population #### } - else {$pc++;} -} - -chop($ins_stmt); -chop($ins_stmt); -$affected_rows = $dbhA->do($ins_stmt); -$ins_stmt="insert into vicidial_phone_codes VALUES "; -print STDERR "$pc\n"; -#### END vicidial_phone_codes population from phone_codes_GMT.txt file #### - - -#### BEGIN vicidial_postal_codes population from GMT_USA_zip.txt file #### -open(zipfile, "$PATHhome/GMT_USA_zip-latest.txt") || die "can't open $PATHhome/GMT_USA_zip-latest.txt: $!\n"; -@zipfile = ; -close(zipfile); -$pc=0; -$ins_stmt="insert into vicidial_postal_codes VALUES "; -foreach (@zipfile) -{ - @row=split(/\t/, $zipfile[$pc]); - $pc++; - $row[0] =~ s/\r|\n|\t| $//gi; - $row[1] =~ s/\r|\n|\t| $//gi; - $row[2] =~ s/\r|\n|\t| $//gi; - $row[3] =~ s/\r|\n|\t| $//gi; - if ($row[3] =~ /Y/i) {$DST_range = 'SSM-FSN';} - else {$DST_range = '';} - $ins_stmt.="('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$DST_range', 'USA', '1'), "; - if ($pc =~ /00$/) - { - chop($ins_stmt); - chop($ins_stmt); - $affected_rows = $dbhA->do($ins_stmt) || die "can't execute query: |$ins_stmt| $!\n"; - $ins_stmt="insert into vicidial_postal_codes VALUES "; - print STDERR "$pc\n"; - } -} - -chop($ins_stmt); -chop($ins_stmt); -$affected_rows = $dbhA->do($ins_stmt); -$ins_stmt="insert into vicidial_postal_codes VALUES "; -print STDERR "$pc\n"; -#### END vicidial_postal_codes population from GMT_USA_zip.txt file #### $dbhA->disconnect(); diff --git a/agc_2-X/trunk/docs/VTIGER.txt b/agc_2-X/trunk/docs/VTIGER.txt index 2a30b8a2..9fd4d344 100644 --- a/agc_2-X/trunk/docs/VTIGER.txt +++ b/agc_2-X/trunk/docs/VTIGER.txt @@ -15,7 +15,7 @@ Current integration features: There has been a basic vtiger integration option available in VICIDIAL since the 1.X release versions through the vtiger_search.php web script(when used as a web form in the campaign) that will search through the leads for the dialed phone number in vicidial.php and if it is not in the vtiger system as a lead then it will be put in as a new lead. -More in-depth integration with Vtiger is a bit complicated due to the fact that it has 312 database tables(and you though VICIDIAL had a lot with about 70). Attempts at using the built-in 5.0.4 API structure were unsuccessful because of inaccurate documentation and the inability to use the modules easily outside of the vtiger directory tree without major reworking of the vtiger code, so we decided to have VICIDIAL work directly with the database instead. Unfortunately, working only with the database doesn't get you the whole way with Vtiger. For user synchronization you need to make sure that the patch(Vtiger504_vicidial.patch) is applied to Vtiger(see instructions below). This patch is used to create blank user profile files so Vtiger will load properly with synchronized users from VICIDIAL. Vtiger doesn't check to see if these user profile files exist before trying to use them, so one thing this patch does is check if the files exist for each user, and if they do not, it will create them with a simple placeholder. Another purpose of this patch is to allow for click-to-dial phone numbers in Vtiger, so that the numbers will be dialed as manual dial calls in a VICIDIAL agent screen. For this to work you must have applied the patch and the agent needs to be logged into vicidial.php(there is also a VICIDIAL Campaign Detail option to automatically login to Vtiger when an agent logs into vicidial.php) then when the agent clicks on any phone number with a "VCcall:" lable bext to it, a call will be placed in their vicidial.php agent screen and the Vtiger window will be closed so that they can open it up again with the vicidial.php WEB FORM button in VICIDIAL. +More in-depth integration with Vtiger is a bit complicated due to the fact that it has 312 database tables(and you though VICIDIAL had a lot with about 70). Attempts at using the built-in 5.0.4 API structure were unsuccessful because of inaccurate documentation and the inability to use the modules easily outside of the vtiger directory tree without major reworking of the vtiger code, so we decided to have VICIDIAL work directly with the database instead. Unfortunately, working only with the database doesn't get you the whole way with Vtiger. For user synchronization you need to make sure that the patch(Vtiger504_vicidial.patch) is applied to Vtiger(see instructions below). This patch is used to create blank user profile files so Vtiger will load properly with synchronized users from VICIDIAL. Vtiger doesn't check to see if these user profile files exist before trying to use them, so one thing this patch does is check if the files exist for each user, and if they do not, it will create them with a simple placeholder. Another purpose of this patch is to allow for click-to-dial phone numbers in Vtiger, so that the numbers will be dialed as manual dial calls in a VICIDIAL agent screen. For this to work you must have applied the patch, you need to have user 1000 set up in VICIDIAL with a password of 1234 and Agent API set to '1', and the agent needs to be logged into vicidial.php(there is also a VICIDIAL Campaign Detail option to automatically login to Vtiger when an agent logs into vicidial.php) then when the agent clicks on any phone number with a "VCcall:" lable bext to it, a call will be placed in their vicidial.php agent screen and the Vtiger window will be closed so that they can open it up again with the vicidial.php WEB FORM button in VICIDIAL. as of 2008-12-31, several user synchronization features have been added to allow for the creation of vtiger users from the vicidial_users user database. The vtiger_search.php script has also been updated to work with the current vtiger release 5.0.4. To enable the Vtiger integration features you will need to go to the Admin -> System Settings section of the admin.php Administration web page to set Vtiger Integration to enabled and configure the connection details for the Vtiger database. diff --git a/agc_2-X/trunk/extras/upgrade_2.0.5.sql b/agc_2-X/trunk/extras/upgrade_2.0.5.sql index d0e73693..780ff987 100644 --- a/agc_2-X/trunk/extras/upgrade_2.0.5.sql +++ b/agc_2-X/trunk/extras/upgrade_2.0.5.sql @@ -646,3 +646,20 @@ ALTER TABLE vicidial_campaigns ADD vtiger_screen_login ENUM('Y','N') default 'Y' ALTER TABLE vicidial_users ADD alert_enabled ENUM('1','0') default '0'; UPDATE system_settings SET db_schema_version='1126'; + + + + + +CREATE TABLE vicidial_nanpa_prefix_codes ( +areacode CHAR(3), +prefix CHAR(3), +GMT_offset VARCHAR(6), +DST enum('Y','N'), +latitude VARCHAR(17), +longitude VARCHAR(17) +); + +CREATE INDEX areaprefix on vicidial_nanpa_prefix_codes (areacode,prefix); + +UPDATE system_settings SET db_schema_version='1127';