diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 960b6448..d8115b4f 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -827,6 +827,14 @@ OTHER CHANGES: 189. Added compatibility for DAHDI channelbank phones for agents in vicidial.php +190. Added Carrier Log and Hangup Reason reports to Admin Utilities screen + +191. Added Lead Loading File Templates + +192. Added "--daily" option to the ADMIN_archive_log_tables.pl script allowing + for the call_log and vicidial_log_extended tables to be archived every + night and only keep the last 24-hours of logs in the active table. + diff --git a/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl b/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl index 14240227..b02cd4f2 100644 --- a/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl +++ b/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl @@ -20,7 +20,7 @@ # Based on perl scripts in ViciDial from Matt Florell and post: # http://www.vicidial.org/VICIDIALforum/viewtopic.php?p=22506&sid=ca5347cffa6f6382f56ce3db9fb3d068#22506 # -# Copyright (C) 2011 I. Taushanov, Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2012 I. Taushanov, Matt Florell LICENSE: AGPLv2 # # CHANGES # 90615-1701 - First version @@ -34,6 +34,7 @@ # 110801-2140 - Added vicidial_url_log table purging and vicidial_log_extended to rolling processes # 110808-0055 - Added vicidial_log_noanswer process # 110822-1257 - Added did_agent_log process +# 120402-2144 - Added "--daily" flag that will archive call_log and vicidial_log_extended logs past 24 hours # ### begin parsing run-time options ### @@ -49,6 +50,7 @@ if (length($ARGV[0])>1) if ($args =~ /--help/i) { print "allowed run time options:\n"; + print " [--daily] = only archives call_log and vicidial_log_extended tables, only last 24 hours kept\n"; print " [--months=XX] = number of months to archive past, must be 12 or less, default is 2\n"; print " [--closer-log] = archive vicidial_closer_log records\n"; print " [--queue-log] = archive QM queue_log records\n"; @@ -67,6 +69,12 @@ if (length($ARGV[0])>1) $T=1; $TEST=1; print "\n-----TESTING-----\n\n"; } + if ($args =~ /--daily/i) + { + $daily=1; + if ($Q < 1) + {print "\n----- DAILY ONLY -----\n\n";} + } if ($args =~ /--months=/i) { @data_in = split(/--months=/,$args); @@ -119,6 +127,21 @@ if ($mday < 10) {$mday = "0$mday";} $del_time = "$year-$mon-$mday 01:00:00"; +if ($daily > 0) + { + $CLImonths = '*** DAILY MODE ***'; + $del_epoch = ($secX - 86400); # 24 hours ago + ($RMsec,$RMmin,$RMhour,$RMmday,$RMmon,$RMyear,$RMwday,$RMyday,$RMisdst) = localtime($del_epoch); + $RMyear = ($RMyear + 1900); + $RMmon++; + if ($RMmon < 10) {$RMmon = "0$RMmon";} + if ($RMmday < 10) {$RMmday = "0$RMmday";} + if ($RMhour < 10) {$RMhour = "0$RMhour";} + if ($RMmin < 10) {$RMmin = "0$RMmin";} + if ($RMsec < 10) {$RMsec = "0$RMsec";} + $del_time = "$RMyear-$RMmon-$RMmday $RMhour:$RMmin:$RMsec"; + } + if (!$Q) {print "\n\n-- ADMIN_archive_log_tables.pl --\n\n";} if (!$Q) {print "This program is designed to put all records from call_log, vicidial_log,\n";} if (!$Q) {print "server_performance, vicidial_agent_log, vicidial_carrier_log, \n";} @@ -175,6 +198,119 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA if (!$T) { + if ($daily > 0) + { + # The --daily option was added because these two tables(call_log and + # vicidial_log_extended) are not used for any processes or reports past + # 24 hours, and on systems dialing 500,000 calls per day or more, this + # can lead to system delay issues even if the 1-month archive process is + # run every weekend. This --daily option will keep only the last + # 24-hours and can improve DB performance greatly + + ##### BEGIN call_log DAILY processing ##### + $stmtA = "SELECT count(*) from call_log;"; + $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; + $call_log_count = $aryA[0]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) from call_log_archive;"; + $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; + $call_log_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "\nProcessing call_log table... ($call_log_count|$call_log_archive_count)\n";} + $stmtA = "INSERT IGNORE INTO call_log_archive SELECT * from call_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into call_log_archive table\n";} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM call_log WHERE start_time < '$del_time';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from call_log table \n";} + + $stmtA = "optimize table call_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + ##### END call_log DAILY processing ##### + + + ##### BEGIN vicidial_log_extended DAILY processing ##### + $stmtA = "SELECT count(*) from vicidial_log_extended;"; + $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; + $vicidial_log_extended_count = $aryA[0]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) from vicidial_log_extended_archive;"; + $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; + $vicidial_log_extended_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "\nProcessing vicidial_log_extended table... ($vicidial_log_extended_count|$vicidial_log_extended_archive_count)\n";} + $stmtA = "INSERT IGNORE INTO vicidial_log_extended_archive SELECT * from vicidial_log_extended;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_log_extended_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM vicidial_log_extended WHERE call_date < '$del_time';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_log_extended table \n";} + + $stmtA = "optimize table vicidial_log_extended;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + ##### END vicidial_log_extended DAILY processing ##### + + + ### calculate time to run script ### + $secY = time(); + $secZ = ($secY - $secX); + $secZm = ($secZ /60); + if (!$Q) {print "\nscript execution time in seconds: $secZ minutes: $secZm\n";} + + exit; + } + + + if ($queue_log > 0) { ############################################# diff --git a/agc_2-X/trunk/bin/AST_VDhopper.pl b/agc_2-X/trunk/bin/AST_VDhopper.pl index 4d1ef532..3cdf22dc 100644 --- a/agc_2-X/trunk/bin/AST_VDhopper.pl +++ b/agc_2-X/trunk/bin/AST_VDhopper.pl @@ -70,6 +70,7 @@ # 111006-1416 - Added call_count_limit option # 120109-1510 - Fixed list mix bug # 120210-1735 - Added vendor_lead_code duplication check per campaign option +# 120402-2211 - Fixed call count limit bug # # constants @@ -1964,7 +1965,7 @@ foreach(@campaign_id) if ($hopper_vlc_dup_check[$i] =~ /Y/) {$vlc_dup_check_SQL = "and vendor_lead_code NOT IN($live_vlc$vlc_lists)";} - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where $recycle_SQL[$i] and list_id IN($camp_lists[$i]) and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $DLTsql[$i] $order_stmt limit $hopper_level[$i];"; + $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where $recycle_SQL[$i] and list_id IN($camp_lists[$i]) and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $CCLsql[$i] $DLTsql[$i] $order_stmt limit $hopper_level[$i];"; if ($DBX) {print " |$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -2020,7 +2021,7 @@ foreach(@campaign_id) if ($hopper_vlc_dup_check[$i] =~ /Y/) {$vlc_dup_check_SQL = "and vendor_lead_code NOT IN($live_vlc$vlc_lists)";} - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists[$i]) and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $DLTsql[$i] $order_stmt limit $NEW_level;"; + $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where called_since_last_reset='N' and status IN('NEW') and list_id IN($camp_lists[$i]) and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $CCLsql[$i] $DLTsql[$i] $order_stmt limit $NEW_level;"; if ($DBX) {print " |$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -2073,7 +2074,7 @@ foreach(@campaign_id) if ($list_order_mix[$i] =~ /DISABLED/) { - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where called_since_last_reset='N' and status IN($STATUSsql[$i]) and list_id IN($camp_lists[$i]) and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $DLTsql[$i] $order_stmt limit $OTHER_level;"; + $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where called_since_last_reset='N' and status IN($STATUSsql[$i]) and list_id IN($camp_lists[$i]) and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $CCLsql[$i] $DLTsql[$i] $order_stmt limit $OTHER_level;"; if ($DBX) {print " |$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -2176,7 +2177,7 @@ foreach(@campaign_id) if ($hopper_vlc_dup_check[$i] =~ /Y/) {$vlc_dup_check_SQL = "and vendor_lead_code NOT IN($live_vlc$vlc_lists)";} - $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where called_since_last_reset='N' and $list_mix_dialableSQL and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $DLTsql[$i] $order_stmt limit $LM_step_goal[$x];"; + $stmtA = "SELECT lead_id,list_id,gmt_offset_now,phone_number,state,status,modify_date,user,vendor_lead_code FROM vicidial_list where called_since_last_reset='N' and $list_mix_dialableSQL and lead_id NOT IN($lead_id_lists) $vlc_dup_check_SQL and ($all_gmtSQL[$i]) $lead_filter_sql[$i] $CCLsql[$i] $DLTsql[$i] $order_stmt limit $LM_step_goal[$x];"; if ($DBX) {print " |$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; diff --git a/agc_2-X/trunk/docs/BASE_INSTALL.txt b/agc_2-X/trunk/docs/BASE_INSTALL.txt index 67e148bd..cab50d41 100644 --- a/agc_2-X/trunk/docs/BASE_INSTALL.txt +++ b/agc_2-X/trunk/docs/BASE_INSTALL.txt @@ -480,6 +480,9 @@ PHASE 6: ADDING CRONTAB ENTRIES FOR ASTGUICLIENT/VICIDIAL SCRIPTS ### roll logs monthly on high-volume dialing systems #30 1 1 * * /usr/share/astguiclient/ADMIN_archive_log_tables.pl +### roll call_log and vicidial_log_extended daily on very high-volume dialing systems +#20 1 * * * /usr/share/astguiclient/ADMIN_archive_log_tables.pl --daily + ### remove old vicidial logs and asterisk logs more than 2 days old 28 0 * * * /usr/bin/find /var/log/astguiclient -maxdepth 1 -type f -mtime +2 -print | xargs rm -f 29 0 * * * /usr/bin/find /var/log/asterisk -maxdepth 3 -type f -mtime +2 -print | xargs rm -f diff --git a/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt b/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt index e724997b..6e7388b7 100644 --- a/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt +++ b/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt @@ -2467,6 +2467,9 @@ SUBPHASE 6.5: setting up astguiclient scripts for continuous running ### roll logs monthly on high-volume dialing systems #30 1 1 * * /usr/share/astguiclient/ADMIN_archive_log_tables.pl +### roll call_log and vicidial_log_extended daily on very high-volume dialing systems +#20 1 * * * /usr/share/astguiclient/ADMIN_archive_log_tables.pl --daily + ### remove old vicidial logs and asterisk logs more than 2 days old 28 0 * * * /usr/bin/find /var/log/astguiclient -maxdepth 1 -type f -mtime +2 -print | xargs rm -f 29 0 * * * /usr/bin/find /var/log/asterisk -maxdepth 3 -type f -mtime +2 -print | xargs rm -f diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index b17943ad..03e970aa 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -2643,6 +2643,16 @@ index (stats_flag), index (user) ); +CREATE TABLE vicidial_custom_leadloader_templates ( +template_id VARCHAR(20) PRIMARY KEY NOT NULL, +template_name VARCHAR(30) DEFAULT NULL, +template_description VARCHAR(255) DEFAULT NULL, +list_id INT(10) UNSIGNED DEFAULT NULL, +standard_variables TEXT, +custom_table VARCHAR(20) DEFAULT NULL, +custom_variables TEXT +); + ALTER TABLE vicidial_campaign_server_stats ENGINE=MEMORY; @@ -2746,6 +2756,8 @@ INSERT INTO vicidial_call_menu_options SET menu_id='default---agent',option_valu INSERT INTO vicidial_scripts (script_id,script_name,script_comments,active,script_text) values('CALLNOTES','Call Notes and Appointment Setting','','Y',''); +INSERT INTO vicidial_custom_leadloader_templates VALUES ('SAMPLE_TEMPLATE','Sample template','',999,'phone_number,9|first_name,0|last_name,1|address1,3|address2,4|address3,5|city,6|state,7|postal_code,8|','custom_999','appointment_date,2|appointment_notes,9|nearest_city,2|'); + UPDATE system_settings SET qc_last_pull_time=NOW(); UPDATE system_settings SET voicemail_timezones="newzealand=Pacific/Auckland\naustraliaeast=Australia/Sydney\naustraliacentral=Australia/Adelaide\naustraliawest=Australia/Perth\njapan=Asia/Tokyo\nphilippines=Asia/Manila\nchina=Asia/Shanghai\nmalaysia=Asia/Kuala_Lumpur\nthailand=Asia/Bangkok\nindia=Asia/Calcutta\npakistan=Asia/Karachi\nrussiaeast=Europe/Moscow\nkenya=Africa/Nairobi\neuropeaneast=Europe/Kiev\nsouthafrica=Africa/Johannesburg\neuropean=Europe/Copenhagen\nnigeria=Africa/Lagos\nuk=Europe/London\nbrazil=America/Sao_Paulo\nnewfoundland=Canada/Newfoundland\ncarribeaneast=America/Santo_Domingo\natlantic=Canada/Atlantic\nchile=America/Santiago\neastern=America/New_York\nperu=America/Lima\ncentral=America/Chicago\nmexicocity=America/Mexico_City\nmountain=America/Denver\narizona=America/Phoenix\nsaskatchewan=America/Saskatchewan\npacific=America/Los_Angeles\nalaska=America/Anchorage\nhawaii=Pacific/Honolulu\neastern24=America/New_York\ncentral24=America/Chicago\nmountain24=America/Denver\npacific24=America/Los_Angeles\nmilitary=Zulu\n"; @@ -2797,7 +2809,7 @@ CREATE TABLE vicidial_log_noanswer_archive LIKE vicidial_log_noanswer; CREATE TABLE vicidial_did_agent_log_archive LIKE vicidial_did_agent_log; CREATE UNIQUE INDEX vdala on vicidial_did_agent_log_archive (uniqueid,call_date,did_route); -UPDATE system_settings SET db_schema_version='1315',db_schema_update_date=NOW(); +UPDATE system_settings SET db_schema_version='1316',db_schema_update_date=NOW(); GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@localhost; diff --git a/agc_2-X/trunk/extras/upgrade_2.4.sql b/agc_2-X/trunk/extras/upgrade_2.4.sql index b8e0a01a..f94bda13 100644 --- a/agc_2-X/trunk/extras/upgrade_2.4.sql +++ b/agc_2-X/trunk/extras/upgrade_2.4.sql @@ -1273,3 +1273,17 @@ ALTER TABLE dialable_inventory_snapshots ADD COLUMN list_description VARCHAR(255 UPDATE dialable_inventory_snapshots d, vicidial_lists v SET d.list_description=v.list_description where d.list_description is null and d.list_id=v.list_id; UPDATE system_settings SET db_schema_version='1315',db_schema_update_date=NOW() where db_schema_version < 1315; + +CREATE TABLE vicidial_custom_leadloader_templates ( +template_id VARCHAR(20) PRIMARY KEY NOT NULL, +template_name VARCHAR(30) DEFAULT NULL, +template_description VARCHAR(255) DEFAULT NULL, +list_id INT(10) UNSIGNED DEFAULT NULL, +standard_variables TEXT, +custom_table VARCHAR(20) DEFAULT NULL, +custom_variables TEXT +); + +INSERT INTO vicidial_custom_leadloader_templates VALUES ('SAMPLE_TEMPLATE','Sample template','',999,'phone_number,9|first_name,0|last_name,1|address1,3|address2,4|address3,5|city,6|state,7|postal_code,8|','custom_999','appointment_date,2|appointment_notes,9|nearest_city,2|'); + +UPDATE system_settings SET db_schema_version='1316',db_schema_update_date=NOW() where db_schema_version < 1316; diff --git a/agc_2-X/trunk/sounds/1400hz_200ms.wav b/agc_2-X/trunk/sounds/1400hz_200ms.wav new file mode 100644 index 00000000..4d19fbb9 Binary files /dev/null and b/agc_2-X/trunk/sounds/1400hz_200ms.wav differ diff --git a/agc_2-X/trunk/sounds/1400hz_200ms_half.wav b/agc_2-X/trunk/sounds/1400hz_200ms_half.wav new file mode 100644 index 00000000..02dc817c Binary files /dev/null and b/agc_2-X/trunk/sounds/1400hz_200ms_half.wav differ diff --git a/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.4.txt b/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.4.txt index d8b53c15..63954cde 100644 --- a/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.4.txt +++ b/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.4.txt @@ -837,6 +837,7 @@ If the Inventory Report is enabled on your system, this option will determine wh Report Rank|| This option allows you to rank shifts in selected reports that support this option|| You can also use a special variable IGNORENOSCROLL to force scroll bars on the script tab even if you are using an iframe within it|| +Carrier Log Report|| lead_report_export.php diff --git a/agc_2-X/trunk/www/vicidial/AST_admin_template_maker.php b/agc_2-X/trunk/www/vicidial/AST_admin_template_maker.php new file mode 100644 index 00000000..d40d6297 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/AST_admin_template_maker.php @@ -0,0 +1,447 @@ + LICENSE: AGPLv2 +# +# CHANGES +# 120402-2132 - First Build +# + +require("dbconnect.php"); + +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["standard_fields_layout"])) {$standard_fields_layout=$_GET["standard_fields_layout"];} + elseif (isset($_POST["standard_fields_layout"])) {$standard_fields_layout=$_POST["standard_fields_layout"];} +if (isset($_GET["custom_fields_layout"])) {$custom_fields_layout=$_GET["custom_fields_layout"];} + elseif (isset($_POST["custom_fields_layout"])) {$custom_fields_layout=$_POST["custom_fields_layout"];} +if (isset($_GET["template_id"])) {$template_id=$_GET["template_id"];} + elseif (isset($_POST["template_id"])) {$template_id=$_POST["template_id"];} +if (isset($_GET["template_name"])) {$template_name=$_GET["template_name"];} + elseif (isset($_POST["template_name"])) {$template_name=$_POST["template_name"];} +if (isset($_GET["template_description"])) {$template_description=$_GET["template_description"];} + elseif (isset($_POST["template_description"])) {$template_description=$_POST["template_description"];} +if (isset($_GET["file_format"])) {$file_format=$_GET["file_format"];} + elseif (isset($_POST["file_format"])) {$file_format=$_POST["file_format"];} +if (isset($_GET["file_delimiter"])) {$file_delimiter=$_GET["file_delimiter"];} + elseif (isset($_POST["file_delimiter"])) {$file_delimiter=$_POST["file_delimiter"];} +if (isset($_GET["template_list_id"])) {$template_list_id=$_GET["template_list_id"];} + elseif (isset($_POST["template_list_id"])) {$template_list_id=$_POST["template_list_id"];} +if (isset($_GET["standard_fields_layout"])) {$standard_fields_layout=$_GET["standard_fields_layout"];} + elseif (isset($_POST["standard_fields_layout"])) {$standard_fields_layout=$_POST["standard_fields_layout"];} +if (isset($_GET["custom_fields_layout"])) {$custom_fields_layout=$_GET["custom_fields_layout"];} + elseif (isset($_POST["custom_fields_layout"])) {$custom_fields_layout=$_POST["custom_fields_layout"];} +if (isset($_GET["submit_template"])) {$submit_template=$_GET["submit_template"];} + elseif (isset($_POST["submit_template"])) {$submit_template=$_POST["submit_template"];} +if (isset($_GET["delete_template"])) {$delete_template=$_GET["delete_template"];} + elseif (isset($_POST["delete_template"])) {$delete_template=$_POST["delete_template"];} + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; + +#$vicidial_list_fields = '|lead_id|vendor_lead_code|source_id|list_id|gmt_offset_now|called_since_last_reset|phone_code|phone_number|title|first_name|middle_initial|last_name|address1|address2|address3|city|state|province|postal_code|country_code|gender|date_of_birth|alt_phone|email|security_phrase|comments|called_count|last_local_call_time|rank|owner|entry_list_id|'; +$vicidial_listloader_fields = '|vendor_lead_code|source_id|phone_code|phone_number|title|first_name|middle_initial|last_name|address1|address2|address3|city|state|province|postal_code|country_code|gender|date_of_birth|alt_phone|email|security_phrase|comments|rank|owner|'; + +if ($submit_template=="SUBMIT TEMPLATE" && $template_id && $template_name && $template_list_id && $standard_fields_layout) { + $custom_table="custom_".$template_list_id; + $ins_stmt="insert into vicidial_custom_leadloader_templates(template_id, template_name, template_description, list_id, standard_variables, custom_table, custom_variables) values('$template_id', '$template_name', '$template_description', '$template_list_id', '$standard_fields_layout', '$custom_table', '$custom_fields_layout')"; + $ins_rslt=mysql_query($ins_stmt, $link); + if (mysql_affected_rows()>0) { + $success_msg="NEW TEMPLATE CREATED SUCCESSFULLY"; + if (!$custom_fields_layout) { + $success_msg.="
**NO CUSTOM FIELDS ASSIGNED**"; + } + } else { + $error_msg="TEMPLATE CREATION FAILED"; + } +} else if ($delete_template=="DELETE TEMPLATE" && $template_id) { + $delete_stmt="delete from vicidial_custom_leadloader_templates where template_id='$template_id'"; + $delete_rslt=mysql_query($delete_stmt, $link); +} + +$US='_'; +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,admin_web_directory,custom_fields_enabled,webroot_writable FROM system_settings;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysql_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysql_fetch_row($rslt); + $non_latin = $row[0]; + $admin_web_directory = $row[1]; + $custom_fields_enabled = $row[2]; + $webroot_writable = $row[3]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ($non_latin < 1) + { + $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); + $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); + $list_id_override = ereg_replace("[^0-9]","",$list_id_override); + } +else + { + $PHP_AUTH_PW = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_PW); + $PHP_AUTH_USER = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_USER); + } + +$STARTtime = date("U"); +$TODAY = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$FILE_datetime = $STARTtime; + +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7;"; +if ($DB) {echo "|$stmt|\n";} +if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$auth=$row[0]; + +if ($webroot_writable > 0) {$fp = fopen ("./project_auth_entries.txt", "a");} +$date = date("r"); +$ip = getenv("REMOTE_ADDR"); +$browser = getenv("HTTP_USER_AGENT"); + +if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) + { +# Header("WWW-Authenticate: Basic realm=\"VICIDIAL-LEAD-LOADER\""); + # Header("HTTP/1.0 401 Unauthorized"); + # echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; + exit; + } +else + { + 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 + + if($auth>0) + { + $office_no=strtoupper($PHP_AUTH_USER); + $password=strtoupper($PHP_AUTH_PW); + $stmt="SELECT load_leads,user_group from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGload_leads = $row[0]; + $LOGuser_group = $row[1]; + + if ($LOGload_leads < 1) + { + echo "You do not have permissions to load leads\n"; + exit; + } + if ($webroot_writable > 0) + { + fwrite ($fp, "LIST_LOAD|GOOD|$date|$PHP_AUTH_USER|XXXX|$ip|$browser|$LOGfullname|\n"); + fclose($fp); + } + } + else + { + if ($webroot_writable > 0) + { + fwrite ($fp, "LIST_LOAD|FAIL|$date|$PHP_AUTH_USER|XXXX|$ip|$browser|\n"); + fclose($fp); + } + exit; + } + + } + +$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; +$LOGadmin_viewable_groups = $row[2]; +$LOGadmin_viewable_call_times = $row[3]; + +$camp_lists=''; +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if (!eregi("-ALL",$LOGallowed_campaigns)) + { + echo "
**$LOGallowed_campaigns**"; + $rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns); + $rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL); + echo "
##$rawLOGallowed_campaignsSQL##"; + $LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')"; + $whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$script_name = getenv("SCRIPT_NAME"); +$server_name = getenv("SERVER_NAME"); +$server_port = getenv("SERVER_PORT"); +if (eregi("443",$server_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +$admDIR = "$HTTPprotocol$server_name$script_name"; +$admDIR = eregi_replace('AST_admin_template_maker.php','',$admDIR); +$admDIR = "/vicidial/"; +$admSCR = 'admin.php'; +$NWB = "   \"HELP\""; + +?> + + + + += 5.0) return $fontsize; else return ($fontsize+2); + } + else return $fontsize; /* Browser is not a Mac - don't touch fonts */ + } + +echo "\n"; +?> + + + +
+ + +
Listloader Custom Template Maker
+ +"; + echo ""; + echo ""; +} +if ($success_msg) { + echo ""; + echo ""; + echo ""; +} +?> + + + + + + + + + + + +
$error_msg
$success_msg
Create a new templateDelete an existing template
+
+ Sample file fitting template:
(needed for field assignation)


+
+
Select template to delete:


+
        BACK TO ADMIN         Go to Lead Loader    
+ +
+ + + + \ No newline at end of file diff --git a/agc_2-X/trunk/www/vicidial/AST_carrier_log_report.php b/agc_2-X/trunk/www/vicidial/AST_carrier_log_report.php new file mode 100644 index 00000000..8d180e31 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/AST_carrier_log_report.php @@ -0,0 +1,325 @@ + LICENSE: AGPLv2 +# +# CHANGES +# 120210-2202 - First build +# + + +require("dbconnect.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} + elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} +if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} + elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} +if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} + elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["lower_limit"])) {$lower_limit=$_GET["lower_limit"];} + elseif (isset($_POST["lower_limit"])) {$lower_limit=$_POST["lower_limit"];} +if (isset($_GET["upper_limit"])) {$upper_limit=$_GET["upper_limit"];} + elseif (isset($_POST["upper_limit"])) {$upper_limit=$_POST["upper_limit"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} + +$PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); +$PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$qm_conf_ct = mysql_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysql_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysql_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect.php"); + $MAIN.="\n"; + } + +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level >= 7 and view_reports='1' and active='Y';"; +if ($DB) {$MAIN.="|$stmt|\n";} +if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$auth=$row[0]; + +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level='7' and view_reports='1' and active='Y';"; +if ($DB) {$MAIN.="|$stmt|\n";} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$reports_only_user=$row[0]; + +if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) + { + Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; + exit; + } + + +if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} +if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} +$NOW_DATE = date("Y-m-d"); +if (!isset($query_date)) {$query_date = $NOW_DATE;} + +$server_ip_string='|'; +$server_ip_ct = count($server_ip); +$i=0; +while($i < $server_ip_ct) + { + $server_ip_string .= "$server_ip[$i]|"; + $i++; + } + +$server_stmt="select distinct s.server_ip, s.server_description from servers s, vicidial_carrier_log vcl where s.server_ip=vcl.server_ip order by server_ip asc"; +$server_rslt=mysql_query($server_stmt, $link); +$servers_to_print=mysql_num_rows($server_rslt); +$i=0; +while ($i < $servers_to_print) + { + $row=mysql_fetch_row($server_rslt); + $LISTserverIPs[$i] = $row[0]; + $LISTserver_names[$i] = $row[1]; + if (ereg("-ALL",$server_ip_string) ) + { + $server_ip[$i] = $LISTserverIPs[$i]; + } + $i++; + } + +$i=0; +$server_ips_string='|'; +$server_ip_ct = count($server_ip); +while($i < $server_ip_ct) + { + if ( (strlen($server_ip[$i]) > 0) and (preg_match("/\|$server_ip[$i]\|/",$server_ip_string)) ) + { + $server_ips_string .= "$server_ip[$i]|"; + $server_ip_SQL .= "'$server_ip[$i]',"; + $server_ipQS .= "&server_ip[]=$server_ip[$i]"; + } + $i++; + } + +if ( (ereg("--ALL--",$server_ip_string) ) or ($server_ip_ct < 1) ) + { + $server_ip_SQL = ""; + $server_rpt_string="- ALL servers "; + if (ereg("--ALL--",$server_ip_string)) {$server_ipQS="&server_ip[]=--ALL--";} + } +else + { + $server_ip_SQL = eregi_replace(",$",'',$server_ip_SQL); + $server_ip_SQL = "and server_ip IN($server_ip_SQL)"; + $server_rpt_string="- server(s) ".preg_replace('/\|/', ", ", substr($server_ip_string, 1, -1)); + } +if (strlen($server_ip_SQL)<3) {$server_ip_SQL="";} + +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="$report_name\n"; + +$short_header=1; + +$MAIN.="
"; +$MAIN.="
\n"; +$MAIN.="
\n"; +$MAIN.="\n"; +$MAIN.="Date:\n"; +$MAIN.=""; +$MAIN.="\n"; + +$MAIN.="

"; + +$MAIN.="
to
"; + +$MAIN.="
Server IP:
\n"; +$MAIN.="
\n"; +$MAIN.="

\n"; +$MAIN.="
\n"; +if ($SUBMIT && $server_ip_ct>0) { + $stmt="select hangup_cause, dialstatus, count(*) as ct From vicidial_carrier_log where call_date>='$query_date $query_date_D' and call_date<='$query_date $query_date_T' $server_ip_SQL group by hangup_cause, dialstatus order by hangup_cause, dialstatus"; + $rslt=mysql_query($stmt, $link); + $MAIN.="
\n";
+	if ($DB) {$MAIN.=$stmt."\n";}
+	if (mysql_num_rows($rslt)>0) {
+		$MAIN.="--- DIAL STATUS BREAKDOWN FOR $query_date, $query_date_D TO $query_date_T $server_rpt_string\n";
+		$MAIN.="+--------------+-------------+---------+\n";
+		$MAIN.="| HANGUP CAUSE | DIAL STATUS |  COUNT  |\n";
+		$MAIN.="+--------------+-------------+---------+\n";
+		$total_count=0;
+		while ($row=mysql_fetch_array($rslt)) {
+			$MAIN.="| ".sprintf("%-13s", $row["hangup_cause"]);
+			$MAIN.="| ".sprintf("%-12s", $row["dialstatus"]);
+			$MAIN.="| ".sprintf("%-8s", $row["ct"]);
+			$MAIN.="|\n";
+			$total_count+=$row["ct"];
+		}
+		$MAIN.="+--------------+-------------+---------+\n";
+		$MAIN.="|                      TOTAL | ".sprintf("%-8s", $total_count)."|\n";
+		$MAIN.="+--------------+-------------+---------+\n\n\n";
+
+		$rpt_stmt="select vicidial_carrier_log.*, vicidial_log.phone_number from vicidial_carrier_log left join vicidial_log on vicidial_log.uniqueid=vicidial_carrier_log.uniqueid where vicidial_carrier_log.call_date>='$query_date $query_date_D' and vicidial_carrier_log.call_date<='$query_date $query_date_T' $server_ip_SQL order by vicidial_carrier_log.call_date asc";
+		$rpt_rslt=mysql_query($rpt_stmt, $link);
+		if ($DB) {$MAIN.=$rpt_stmt."\n";}
+
+		if (!$lower_limit) {$lower_limit=1;}
+		if ($lower_limit+999>=mysql_num_rows($rpt_rslt)) {$upper_limit=($lower_limit+mysql_num_rows($rpt_rslt)%1000)-1;} else {$upper_limit=$lower_limit+999;}
+		
+		$MAIN.="--- CARRIER LOG RECORDS FOR $query_date, $query_date_D TO $query_date_T $server_rpt_string, RECORDS #$lower_limit-$upper_limit               [DOWNLOAD]\n";
+		$carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+-----------+---------------+--------------+\n";
+		$carrier_rpt.="| UNIQUE ID            | CALL DATE           | SERVER IP       | LEAD ID   | HANGUP CAUSE | DIAL STATUS | CHANNEL                                  | DIAL TIME | ANSWERED TIME | PHONE NUMBER |\n";
+		$carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+-----------+---------------+--------------+\n";
+		$CSV_text="\"UNIQUE ID\",\"CALL DATE\",\"SERVER IP\",\"LEAD ID\",\"HANGUP CAUSE\",\"DIAL STATUS\",\"CHANNEL\",\"DIAL TIME\",\"ANSWERED TIME\",\"PHONE NUMBER\"\n";
+
+		for ($i=1; $i<=mysql_num_rows($rpt_rslt); $i++) {
+			$row=mysql_fetch_array($rpt_rslt);
+			$phone_number=""; $phone_note="";
+
+			if (strlen($row["phone_number"])==0) {
+				$stmt2="select phone_number, alt_phone, address3 from vicidial_list where lead_id='$row[lead_id]'";
+				$rslt2=mysql_query($stmt2, $link);
+				$channel=$row["channel"];
+				while ($row2=mysql_fetch_array($rslt2)) {
+					if (strlen($row2["alt_phone"])>=7 && preg_match("/$row2[alt_phone]/", $channel)) {$phone_number=$row2["alt_phone"]; $phone_note="ALT";}
+					else if (strlen($row2["address3"])>=7 && preg_match("/$row2[address3]/", $channel)) {$phone_number=$row2["address3"]; $phone_note="ADDR3";}
+					else if (strlen($row2["phone_number"])>=7 && preg_match("/$row2[phone_number]/", $channel)) {$phone_number=$row2["phone_number"]; $phone_note="*";}
+				}
+			} else {
+				$phone_number=$row["phone_number"];
+			}
+
+			$CSV_text.="\"$row[uniqueid]\",\"$row[call_date]\",\"$row[server_ip]\",\"$row[lead_id]\",\"$row[hangup_cause]\",\"$row[dialstatus]\",\"$row[channel]\",\"$row[dial_time]\",\"$row[answered_time]\",\"$phone_number\"\n";
+			if ($i>=$lower_limit && $i<=$upper_limit) {
+				if (strlen($row["channel"])>37) {$row["channel"]=substr($row["channel"],0,37)."...";}
+				$carrier_rpt.="| ".sprintf("%-21s", $row["uniqueid"]); 
+				$carrier_rpt.="| ".sprintf("%-20s", $row["call_date"]); 
+				$carrier_rpt.="| ".sprintf("%-16s", $row["server_ip"]); 
+				$carrier_rpt.="| ".sprintf("%-10s", $row["lead_id"]); 
+				$carrier_rpt.="| ".sprintf("%-13s", $row["hangup_cause"]); 
+				$carrier_rpt.="| ".sprintf("%-12s", $row["dialstatus"]); 
+				$carrier_rpt.="| ".sprintf("%-41s", $row["channel"]); 
+				$carrier_rpt.="| ".sprintf("%-10s", $row["dial_time"]); 
+				$carrier_rpt.="| ".sprintf("%-14s", $row["answered_time"]); 
+				$carrier_rpt.="| ".sprintf("%-13s", $phone_number)."|\n"; 
+			}
+		}
+		$carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+-----------+---------------+--------------+\n";
+
+		$carrier_rpt_hf="";
+		$ll=$lower_limit-1000;
+		if ($ll>=1) {
+			$carrier_rpt_hf.="[<<< PREV 1000 records]";
+		} else {
+			$carrier_rpt_hf.=sprintf("%-23s", " ");
+		}
+		$carrier_rpt_hf.=sprintf("%-145s", " ");
+		if (($lower_limit+1000)=mysql_num_rows($rpt_rslt)) {$max_limit=mysql_num_rows($rpt_rslt)-$upper_limit;} else {$max_limit=1000;}
+			$carrier_rpt_hf.="[NEXT $max_limit records >>>]";
+		} else {
+			$carrier_rpt_hf.=sprintf("%23s", " ");
+		}
+		$carrier_rpt_hf.="\n";
+		$MAIN.=$carrier_rpt_hf.$carrier_rpt.$carrier_rpt_hf;
+	} else {
+		$MAIN.="*** NO RECORDS FOUND ***\n";
+	}
+	$MAIN.="
\n"; + + $MAIN.="
\n"; + + +} + if ($file_download>0) { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_carrier_log_report_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + + exit; + } else { + echo $HEADER; + require("admin_header.php"); + echo $MAIN; + } + +?> diff --git a/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php b/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php new file mode 100644 index 00000000..6f5d1104 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php @@ -0,0 +1,413 @@ + LICENSE: AGPLv2 +# +# CHANGES +# 120331-2301 - First build +# + + +require("dbconnect.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} + elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} +if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} + elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} +if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} + elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} +if (isset($_GET["hangup_cause"])) {$hangup_cause=$_GET["hangup_cause"];} + elseif (isset($_POST["hangup_cause"])) {$hangup_cause=$_POST["hangup_cause"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["lower_limit"])) {$lower_limit=$_GET["lower_limit"];} + elseif (isset($_POST["lower_limit"])) {$lower_limit=$_POST["lower_limit"];} +if (isset($_GET["upper_limit"])) {$upper_limit=$_GET["upper_limit"];} + elseif (isset($_POST["upper_limit"])) {$upper_limit=$_POST["upper_limit"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} + +$PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); +$PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$qm_conf_ct = mysql_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysql_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysql_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect.php"); + $MAIN.="\n"; + } + +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level >= 7 and view_reports='1' and active='Y';"; +if ($DB) {$MAIN.="|$stmt|\n";} +if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$auth=$row[0]; + +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level='7' and view_reports='1' and active='Y';"; +if ($DB) {$MAIN.="|$stmt|\n";} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$reports_only_user=$row[0]; + +if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) + { + Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; + exit; + } + + +if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} +if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} +$NOW_DATE = date("Y-m-d"); +if (!isset($query_date)) {$query_date = $NOW_DATE;} + +$server_ip_string='|'; +$server_ip_ct = count($server_ip); +$i=0; +while($i < $server_ip_ct) + { + $server_ip_string .= "$server_ip[$i]|"; + $i++; + } + +$server_stmt="select distinct s.server_ip, s.server_description from servers s, vicidial_carrier_log vcl where s.server_ip=vcl.server_ip order by server_ip asc"; +$server_rslt=mysql_query($server_stmt, $link); +$servers_to_print=mysql_num_rows($server_rslt); +$i=0; +while ($i < $servers_to_print) + { + $row=mysql_fetch_row($server_rslt); + $LISTserverIPs[$i] = $row[0]; + $LISTserver_names[$i] = $row[1]; + if (ereg("-ALL",$server_ip_string) ) + { + $server_ip[$i] = $LISTserverIPs[$i]; + } + $i++; + } + +$i=0; +$server_ips_string='|'; +$server_ip_ct = count($server_ip); +while($i < $server_ip_ct) + { + if ( (strlen($server_ip[$i]) > 0) and (preg_match("/\|$server_ip[$i]\|/",$server_ip_string)) ) + { + $server_ips_string .= "$server_ip[$i]|"; + $server_ip_SQL .= "'$server_ip[$i]',"; + $server_ipQS .= "&server_ip[]=$server_ip[$i]"; + } + $i++; + } + +if ( (ereg("--ALL--",$server_ip_string) ) or ($server_ip_ct < 1) ) + { + $server_ip_SQL = ""; + $server_rpt_string="- ALL servers "; + if (ereg("--ALL--",$server_ip_string)) {$server_ipQS="&server_ip[]=--ALL--";} + } +else + { + $server_ip_SQL = eregi_replace(",$",'',$server_ip_SQL); + $server_ip_SQL = "and server_ip IN($server_ip_SQL)"; + $server_rpt_string="- server(s) ".preg_replace('/\|/', ", ", substr($server_ip_string, 1, -1)); + } +if (strlen($server_ip_SQL)<3) {$server_ip_SQL="";} + +########### HANGUP CAUSES +$hangup_cause_string='|'; +$dialstatus_string='|'; +$hangup_and_dialstatus_string='|'; +$hangup_cause_ct = count($hangup_cause); + +$i=0; +while($i < $hangup_cause_ct) + { + $hangup_array=explode("!", $hangup_cause[$i]); + $hangup_and_dialstatus_string .= "$hangup_cause[$i]|"; + $hangup_cause_string .= "$hangup_array[0]|"; + $dialstatus_string .= "$hangup_array[1]|"; + $i++; + } + +$hangupcause_stmt="select distinct hangup_cause, dialstatus from vicidial_carrier_log order by dialstatus, hangup_cause asc"; +$hangupcause_rslt=mysql_query($hangupcause_stmt, $link); +$causes_to_print=mysql_num_rows($hangupcause_rslt); +$i=0; +while ($i < $causes_to_print) + { + $row=mysql_fetch_row($hangupcause_rslt); + $LISThangup_causes[$i] = $row[0]; + $LISTdialstatuses[$i] = $row[1]; + if (ereg("-ALL",$hangup_cause_string) ) + { + $hangup_cause[$i] = $LISThangup_causes[$i]; + $dialstatus[$i] = $LISTdialstatuses[$i]; + } + $i++; + } +$i=0; +$hangup_causes_string='|'; +$hangup_cause_ct = count($hangup_cause); +while($i < $hangup_cause_ct) + { + $hangup_array=explode("!", $hangup_cause[$i]); + if ( (strlen($hangup_array[0]) > 0) and (preg_match("/\|$hangup_array[0]\|/",$hangup_cause_string)) and (strlen($hangup_array[1]) > 0) and (preg_match("/\|$hangup_array[1]\|/",$dialstatus_string)) ) + { + $hangup_causes_string .= "$hangup_array[0]|"; + $hangup_cause_SQL .= "(hangup_cause='$hangup_array[0]' and dialstatus='$hangup_array[1]') OR"; + $hangup_causeQS .= "&hangup_cause[]=$hangup_cause[$i]"; + } + $i++; + } + +if ( (ereg("--ALL--",$hangup_cause_string) ) or ($hangup_cause_ct < 1) ) + { + $hangup_cause_SQL = ""; + $HC_rpt_string="- ALL hangup causes "; + if (ereg("--ALL--",$hangup_cause_string)) {$hangup_causeQS="&hangup_cause[]=--ALL--";} + } +else + { + $hangup_cause_SQL=preg_replace('/ OR$/', '', $hangup_cause_SQL); + $hangup_cause_SQL = eregi_replace(",$",'',$hangup_cause_SQL); + $hangup_cause_SQL = "and ($hangup_cause_SQL)"; + $hangup_and_dialstatus_string=preg_replace('/\!/', "-", $hangup_and_dialstatus_string); + $HC_rpt_string="AND hangup cause(s) ".preg_replace('/\|/', ", ", substr($hangup_and_dialstatus_string, 1, -1)); + } +if (strlen($hangup_cause_SQL)<3) {$hangup_cause_SQL="";} +######################## +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="$report_name\n"; + +$short_header=1; + +$MAIN.=">>
"; +$MAIN.="
\n"; +$MAIN.=""; + +$MAIN.=""; + +$MAIN.="\n"; + +$MAIN.="
\n"; +$MAIN.="\n"; +$MAIN.="Date:\n"; +$MAIN.=""; +$MAIN.="\n"; + +$MAIN.="

"; + +$MAIN.="
to
"; + +$MAIN.="
Server IP:
\n"; +$MAIN.="
Hangup Cause/Dial Status:
"; +$MAIN.="
"; + +$MAIN.="\n"; +$MAIN.="

\n"; +$MAIN.="
\n"; +if ($SUBMIT && $server_ip_ct>0) { + $stmt="select hangup_cause, dialstatus, count(*) as ct From vicidial_carrier_log where call_date>='$query_date $query_date_D' and call_date<='$query_date $query_date_T' $server_ip_SQL $hangup_cause_SQL group by hangup_cause, dialstatus order by hangup_cause, dialstatus"; + $rslt=mysql_query($stmt, $link); + $MAIN.="
\n";
+	if ($DB) {$MAIN.=$stmt."\n";}
+	if (mysql_num_rows($rslt)>0) {
+		$MAIN.="--- DIAL STATUS BREAKDOWN FOR $query_date, $query_date_D TO $query_date_T $server_rpt_string\n";
+		$MAIN.="+--------------+-------------+---------+\n";
+		$MAIN.="| HANGUP CAUSE | DIAL STATUS |  COUNT  |\n";
+		$MAIN.="+--------------+-------------+---------+\n";
+		$total_count=0;
+		while ($row=mysql_fetch_array($rslt)) {
+			$MAIN.="| ".sprintf("%-13s", $row["hangup_cause"]);
+			$MAIN.="| ".sprintf("%-12s", $row["dialstatus"]);
+			$MAIN.="| ".sprintf("%-8s", $row["ct"]);
+			$MAIN.="|\n";
+			$total_count+=$row["ct"];
+		}
+		$MAIN.="+--------------+-------------+---------+\n";
+		$MAIN.="|                      TOTAL | ".sprintf("%-8s", $total_count)."|\n";
+		$MAIN.="+--------------+-------------+---------+\n\n\n";
+
+		$rpt_stmt="select vicidial_carrier_log.*, vicidial_log.phone_number from vicidial_carrier_log left join vicidial_log on vicidial_log.uniqueid=vicidial_carrier_log.uniqueid where vicidial_carrier_log.call_date>='$query_date $query_date_D' and vicidial_carrier_log.call_date<='$query_date $query_date_T' $server_ip_SQL $hangup_cause_SQL order by vicidial_carrier_log.call_date asc";
+		$rpt_rslt=mysql_query($rpt_stmt, $link);
+		if ($DB) {$MAIN.=$rpt_stmt."\n";}
+
+		if (!$lower_limit) {$lower_limit=1;}
+		if ($lower_limit+999>=mysql_num_rows($rpt_rslt)) {$upper_limit=($lower_limit+mysql_num_rows($rpt_rslt)%1000)-1;} else {$upper_limit=$lower_limit+999;}
+		
+		$MAIN.="--- CARRIER LOG RECORDS FOR $query_date, $query_date_D TO $query_date_T $server_rpt_string, $HC_rpt_string\n --- RECORDS #$lower_limit-$upper_limit               [DOWNLOAD]\n";
+		$carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+-----------+---------------+--------------+\n";
+		$carrier_rpt.="| UNIQUE ID            | CALL DATE           | SERVER IP       | LEAD ID   | HANGUP CAUSE | DIAL STATUS | CHANNEL                                  | DIAL TIME | ANSWERED TIME | PHONE NUMBER |\n";
+		$carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+-----------+---------------+--------------+\n";
+		$CSV_text="\"UNIQUE ID\",\"CALL DATE\",\"SERVER IP\",\"LEAD ID\",\"HANGUP CAUSE\",\"DIAL STATUS\",\"CHANNEL\",\"DIAL TIME\",\"ANSWERED TIME\",\"PHONE NUMBER\"\n";
+
+		for ($i=1; $i<=mysql_num_rows($rpt_rslt); $i++) {
+			$row=mysql_fetch_array($rpt_rslt);
+			$phone_number=""; $phone_note="";
+
+			if (strlen($row["phone_number"])==0) {
+				$stmt2="select phone_number, alt_phone, address3 from vicidial_list where lead_id='$row[lead_id]'";
+				$rslt2=mysql_query($stmt2, $link);
+				$channel=$row["channel"];
+				while ($row2=mysql_fetch_array($rslt2)) {
+					if (strlen($row2["alt_phone"])>=7 && preg_match("/$row2[alt_phone]/", $channel)) {$phone_number=$row2["alt_phone"]; $phone_note="ALT";}
+					else if (strlen($row2["address3"])>=7 && preg_match("/$row2[address3]/", $channel)) {$phone_number=$row2["address3"]; $phone_note="ADDR3";}
+					else if (strlen($row2["phone_number"])>=7 && preg_match("/$row2[phone_number]/", $channel)) {$phone_number=$row2["phone_number"]; $phone_note="*";}
+				}
+			} else {
+				$phone_number=$row["phone_number"];
+			}
+
+			$CSV_text.="\"$row[uniqueid]\",\"$row[call_date]\",\"$row[server_ip]\",\"$row[lead_id]\",\"$row[hangup_cause]\",\"$row[dialstatus]\",\"$row[channel]\",\"$row[dial_time]\",\"$row[answered_time]\",\"$phone_number\"\n";
+			if ($i>=$lower_limit && $i<=$upper_limit) {
+				if (strlen($row["channel"])>37) {$row["channel"]=substr($row["channel"],0,37)."...";}
+				$carrier_rpt.="| ".sprintf("%-21s", $row["uniqueid"]); 
+				$carrier_rpt.="| ".sprintf("%-20s", $row["call_date"]); 
+				$carrier_rpt.="| ".sprintf("%-16s", $row["server_ip"]); 
+				$carrier_rpt.="| ".sprintf("%-10s", $row["lead_id"]); 
+				$carrier_rpt.="| ".sprintf("%-13s", $row["hangup_cause"]); 
+				$carrier_rpt.="| ".sprintf("%-12s", $row["dialstatus"]); 
+				$carrier_rpt.="| ".sprintf("%-41s", $row["channel"]); 
+				$carrier_rpt.="| ".sprintf("%-10s", $row["dial_time"]); 
+				$carrier_rpt.="| ".sprintf("%-14s", $row["answered_time"]); 
+				$carrier_rpt.="| ".sprintf("%-13s", $phone_number)."|\n"; 
+			}
+		}
+		$carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+-----------+---------------+--------------+\n";
+
+		$carrier_rpt_hf="";
+		$ll=$lower_limit-1000;
+		if ($ll>=1) {
+			$carrier_rpt_hf.="[<<< PREV 1000 records]";
+		} else {
+			$carrier_rpt_hf.=sprintf("%-23s", " ");
+		}
+		$carrier_rpt_hf.=sprintf("%-145s", " ");
+		if (($lower_limit+1000)=mysql_num_rows($rpt_rslt)) {$max_limit=mysql_num_rows($rpt_rslt)-$upper_limit;} else {$max_limit=1000;}
+			$carrier_rpt_hf.="[NEXT $max_limit records >>>]";
+		} else {
+			$carrier_rpt_hf.=sprintf("%23s", " ");
+		}
+		$carrier_rpt_hf.="\n";
+		$MAIN.=$carrier_rpt_hf.$carrier_rpt.$carrier_rpt_hf;
+	} else {
+		$MAIN.="*** NO RECORDS FOUND ***\n";
+	}
+	$MAIN.="
\n"; + + $MAIN.="
\n"; + + +} + if ($file_download>0) { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_carrier_log_report_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + + exit; + } else { + echo $HEADER; + require("admin_header.php"); + echo $MAIN; + } + +?> diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index 30fc577b..7ce7e0d9 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -3044,12 +3044,13 @@ else # 120221-0054 - Fixed Call Time and User Group restrictions on several pages # 120221-1647 - Added inventory report options to lists and shifts # 120316-1203 - Fixed DIALBLE counts for completed statuses +# 120402-2111 - Added lead loading template and two carrier log reports to the admin utils page # # make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time -$admin_version = '2.4-362a'; -$build = '120316-1203'; +$admin_version = '2.4-363a'; +$build = '120402-2111'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -7151,6 +7152,15 @@ if ($ADD==99999)
NOTES: The Excel Lead loader functionality is enabled by a series of perl scripts and needs to have a properly configured /etc/astguiclient.conf file in place on the web server. Also, a couple perl modules must be loaded for it to work as well - OLE-Storage_Lite and Spreadsheet-ParseExcel. You can check for runtime errors in these by looking at your apache error_log file. Also, for duplication checks against gampaign lists, the list that has new leads going into it does need to be created in the system before you start to load the leads. +
+ +
+ File layout - The layout of the file you are loading. "Standard Format" uses the pre-defined Vicidial standard file format. "Custom layout" allows the user to define the layout of the file themselves. "Custom template" is a hybrid of the previous two options, which allows the user to use a custom format they have defined previously and saved using the Custom Template Maker. + +
+
+
+ Template ID - If the user has selected "Custom layout" from the "File layout" options, then this the the template the lead loader will use. It will also override the selected list ID with the list ID that was assigned to the selected template when it was created. @@ -8437,6 +8447,49 @@ if ($ADD==99999) +



+ + VICIDIAL CUSTOM TEMPLATE MAKER

+
+
+ The Vicidial custom template maker allows you to define your own file layouts for use with the Vicidial listloader and also delete them, if necessary. If you frequently upload files that are in a consistent layout other than the Vicidial standard layout, you may find this tool helpful. The saved layout will work on any uploaded file it matches, regardless of file type or delimiter. + +
+
+
+ Create a new template - In order to begin creating your new listloader template, you must first load a lead file that has the layout you wish to create the template for. Click "Choose file", and open the file on your computer you wish to use. This will upload a copy to your server and process it to determine the file type and delimiter (for TXT files). + +
+
+
+ Delete template - If you have a template you no longer use or you mis-entered information on it and would like to re-enter it, select the template from the drop-down menu and click "DELETE TEMPLATE". + +
+
+
+ Template ID - This field is where you enter an arbitrary ID for your new custom template. It must be between 2 and 20 characters and consist of alphanumeric characters and underscores. + +
+
+
+ Template Name - This field is where you enter the name for your new custom template. Can be up to 30 characters long. + +
+
+
+ Template Description - This field is where you enter the description for your new custom template. It can be up to 255 characters long. + +
+
+
+ List ID - All templates must load their records into a list. Select a list ID to load leads into from this drop-down list, which will display any lists available to you given your user settings. + +
+
+
+ Assigning columns - Once you have loaded a sample file matching the layout you wish to make into a template and select a list ID to load leads into, all the available columns from the vicidial_list table and the custom table for the list you selected (if any) will be displayed here. Columns highlighted in blue are standard columns from the vicidial_list table. Columns highlighted in pink belong to the custom table for the selected list. Each column listed has a drop-down menu, which should be populated with the fields from the first row of the sample file you uploaded. Assign the appropriate fields to the appropriate columns and press "SUBMIT TEMPLATE" to create your template. You do not need to assign every field to a column, and you do not need to assign every column a field. For details on the standard vicidial_list columns, click
HERE. + +



Maximum System Stats Reports

@@ -32960,6 +33013,8 @@ if ($ADD==999994) echo "
    \n"; echo "
  • Welcome Languages Page\n"; echo "
  • Campaign Debug Page\n"; + echo "
  • Carrier Log Report\n"; + echo "
  • Hangup Cause Report\n"; echo "
  • Bulk Phone Insert Page\n"; echo "
  • Send a Call With Custom CID Page\n"; echo "
  • Speech Voice Lab Page\n"; diff --git a/agc_2-X/trunk/www/vicidial/admin_header.php b/agc_2-X/trunk/www/vicidial/admin_header.php index 771a49c5..ba22f78f 100644 --- a/agc_2-X/trunk/www/vicidial/admin_header.php +++ b/agc_2-X/trunk/www/vicidial/admin_header.php @@ -1,7 +1,7 @@ LICENSE: AGPLv2 +# Copyright (C) 2012 Matt Florell LICENSE: AGPLv2 # # CHANGES @@ -36,6 +36,7 @@ # 111015-2305 - Added Contacts menu to Admin # 111106-0939 - Changes for user group restrictions # 111116-0208 - Added ALT and ADDR3 in-group handle methods +# 120402-2134 - Changed lead loader link to fourth gen # @@ -1188,7 +1189,7 @@ $SScustom_fields_enabled = $row[3];
  >
  - > Load New Leads + > Load New Leads 0) { diff --git a/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php b/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php new file mode 100644 index 00000000..db265ad0 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/admin_listloader_fourth_gen.php @@ -0,0 +1,2862 @@ + LICENSE: AGPLv2 +# +# ViciDial web-based lead loader from formatted file +# +# CHANGES +# 50602-1640 - First version created by Joe Johnson +# 51128-1108 - Removed PHP global vars requirement +# 60113-1603 - Fixed a few bugs in Excel import +# 60421-1624 - check GET/POST vars lines with isset to not trigger PHP NOTICES +# 60616-1240 - added listID override +# 60616-1604 - added gmt lookup for each lead +# 60619-1651 - Added variable filtering to eliminate SQL injection attack threat +# 60822-1121 - fixed for nonwritable directories +# 60906-1100 - added filter of non-digits in alt_phone field +# 61110-1222 - added new USA-Canada DST scheme and Brazil DST scheme +# 61128-1149 - added postal code GMT lookup and duplicate check options +# 70417-1059 - Fixed default phone_code bug +# 70510-1518 - Added campaign and system duplicate check and phonecode override +# 80428-0417 - UTF8 changes +# 80514-1030 - removed filesize limit and raised number of errors to be displayed +# 80713-0023 - added last_local_call_time field default of 2008-01-01 +# 81011-2009 - a few bug fixes +# 90309-1831 - Added admin_log logging +# 90310-2128 - Added admin header +# 90508-0644 - Changed to PHP long tags +# 90522-0506 - Security fix +# 90721-1339 - Added rank and owner as vicidial_list fields +# 91112-0616 - Added title/alt-phone duplicate checking +# 100118-0543 - Added new Australian and New Zealand DST schemes (FSO-FSA and LSS-FSA) +# 100621-1026 - Added admin_web_directory variable +# 100630-1609 - Added a check for invalid ListIds and filtered out ' " ; ` \ from the field +# 100705-1507 - Added custom fields to field chooser, only when liast_id_override is used and only with TXT and CSV file formats +# 100706-1250 - Forked script to create new script that will only load TXT(tab- +# delimited files) and use a perl script to convert others to TXT +# 100707-1040 - Converted List Id Override and Phone Code Override to drop downs +# 100707-1156 - Made it so you cannot submit with no lead file selected. Also fixed Start Over Link +# 100712-1416 - Added entry_list_id field to vicidial_list to preserve link to custom fields if any +# 100728-0900 - Filtered uploaded filenames for unsupported characters +# 110424-0926 - Added option for time zone code in the owner field +# 110705-1947 - Added USACAN check for prefix and areacode +# 120221-0140 - Added User Group restrictions +# 120223-2318 - Removed logging of good login passwords if webroot writable is enabled +# 120402-2128 - Added template options +# + +$version = '2.4-44'; +$build = '120402-2128'; + + +require("dbconnect.php"); + + +$US='_'; + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +$leadfile=$_FILES["leadfile"]; + $LF_orig = $_FILES['leadfile']['name']; + $LF_path = $_FILES['leadfile']['tmp_name']; +if (isset($_GET["submit_file"])) {$submit_file=$_GET["submit_file"];} + elseif (isset($_POST["submit_file"])) {$submit_file=$_POST["submit_file"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["leadfile_name"])) {$leadfile_name=$_GET["leadfile_name"];} + elseif (isset($_POST["leadfile_name"])) {$leadfile_name=$_POST["leadfile_name"];} +if (isset($_FILES["leadfile"])) {$leadfile_name=$_FILES["leadfile"]['name'];} +if (isset($_GET["file_layout"])) {$file_layout=$_GET["file_layout"];} + elseif (isset($_POST["file_layout"])) {$file_layout=$_POST["file_layout"];} +if (isset($_GET["OK_to_process"])) {$OK_to_process=$_GET["OK_to_process"];} + elseif (isset($_POST["OK_to_process"])) {$OK_to_process=$_POST["OK_to_process"];} +if (isset($_GET["vendor_lead_code_field"])) {$vendor_lead_code_field=$_GET["vendor_lead_code_field"];} + elseif (isset($_POST["vendor_lead_code_field"])) {$vendor_lead_code_field=$_POST["vendor_lead_code_field"];} +if (isset($_GET["source_id_field"])) {$source_id_field=$_GET["source_id_field"];} + elseif (isset($_POST["source_id_field"])) {$source_id_field=$_POST["source_id_field"];} +if (isset($_GET["list_id_field"])) {$list_id_field=$_GET["list_id_field"];} + elseif (isset($_POST["list_id_field"])) {$list_id_field=$_POST["list_id_field"];} +if (isset($_GET["phone_code_field"])) {$phone_code_field=$_GET["phone_code_field"];} + elseif (isset($_POST["phone_code_field"])) {$phone_code_field=$_POST["phone_code_field"];} +if (isset($_GET["phone_number_field"])) {$phone_number_field=$_GET["phone_number_field"];} + elseif (isset($_POST["phone_number_field"])) {$phone_number_field=$_POST["phone_number_field"];} +if (isset($_GET["title_field"])) {$title_field=$_GET["title_field"];} + elseif (isset($_POST["title_field"])) {$title_field=$_POST["title_field"];} +if (isset($_GET["first_name_field"])) {$first_name_field=$_GET["first_name_field"];} + elseif (isset($_POST["first_name_field"])) {$first_name_field=$_POST["first_name_field"];} +if (isset($_GET["middle_initial_field"])) {$middle_initial_field=$_GET["middle_initial_field"];} + elseif (isset($_POST["middle_initial_field"])) {$middle_initial_field=$_POST["middle_initial_field"];} +if (isset($_GET["last_name_field"])) {$last_name_field=$_GET["last_name_field"];} + elseif (isset($_POST["last_name_field"])) {$last_name_field=$_POST["last_name_field"];} +if (isset($_GET["address1_field"])) {$address1_field=$_GET["address1_field"];} + elseif (isset($_POST["address1_field"])) {$address1_field=$_POST["address1_field"];} +if (isset($_GET["address2_field"])) {$address2_field=$_GET["address2_field"];} + elseif (isset($_POST["address2_field"])) {$address2_field=$_POST["address2_field"];} +if (isset($_GET["address3_field"])) {$address3_field=$_GET["address3_field"];} + elseif (isset($_POST["address3_field"])) {$address3_field=$_POST["address3_field"];} +if (isset($_GET["city_field"])) {$city_field=$_GET["city_field"];} + elseif (isset($_POST["city_field"])) {$city_field=$_POST["city_field"];} +if (isset($_GET["state_field"])) {$state_field=$_GET["state_field"];} + elseif (isset($_POST["state_field"])) {$state_field=$_POST["state_field"];} +if (isset($_GET["province_field"])) {$province_field=$_GET["province_field"];} + elseif (isset($_POST["province_field"])) {$province_field=$_POST["province_field"];} +if (isset($_GET["postal_code_field"])) {$postal_code_field=$_GET["postal_code_field"];} + elseif (isset($_POST["postal_code_field"])) {$postal_code_field=$_POST["postal_code_field"];} +if (isset($_GET["country_code_field"])) {$country_code_field=$_GET["country_code_field"];} + elseif (isset($_POST["country_code_field"])) {$country_code_field=$_POST["country_code_field"];} +if (isset($_GET["gender_field"])) {$gender_field=$_GET["gender_field"];} + elseif (isset($_POST["gender_field"])) {$gender_field=$_POST["gender_field"];} +if (isset($_GET["date_of_birth_field"])) {$date_of_birth_field=$_GET["date_of_birth_field"];} + elseif (isset($_POST["date_of_birth_field"])) {$date_of_birth_field=$_POST["date_of_birth_field"];} +if (isset($_GET["alt_phone_field"])) {$alt_phone_field=$_GET["alt_phone_field"];} + elseif (isset($_POST["alt_phone_field"])) {$alt_phone_field=$_POST["alt_phone_field"];} +if (isset($_GET["email_field"])) {$email_field=$_GET["email_field"];} + elseif (isset($_POST["email_field"])) {$email_field=$_POST["email_field"];} +if (isset($_GET["security_phrase_field"])) {$security_phrase_field=$_GET["security_phrase_field"];} + elseif (isset($_POST["security_phrase_field"])) {$security_phrase_field=$_POST["security_phrase_field"];} +if (isset($_GET["comments_field"])) {$comments_field=$_GET["comments_field"];} + elseif (isset($_POST["comments_field"])) {$comments_field=$_POST["comments_field"];} +if (isset($_GET["rank_field"])) {$rank_field=$_GET["rank_field"];} + elseif (isset($_POST["rank_field"])) {$rank_field=$_POST["rank_field"];} +if (isset($_GET["owner_field"])) {$owner_field=$_GET["owner_field"];} + elseif (isset($_POST["owner_field"])) {$owner_field=$_POST["owner_field"];} +if (isset($_GET["list_id_override"])) {$list_id_override=$_GET["list_id_override"];} + elseif (isset($_POST["list_id_override"])) {$list_id_override=$_POST["list_id_override"];} + $list_id_override = (preg_replace("/\D/","",$list_id_override)); +if (isset($_GET["lead_file"])) {$lead_file=$_GET["lead_file"];} + elseif (isset($_POST["lead_file"])) {$lead_file=$_POST["lead_file"];} +if (isset($_GET["dupcheck"])) {$dupcheck=$_GET["dupcheck"];} + elseif (isset($_POST["dupcheck"])) {$dupcheck=$_POST["dupcheck"];} +if (isset($_GET["postalgmt"])) {$postalgmt=$_GET["postalgmt"];} + elseif (isset($_POST["postalgmt"])) {$postalgmt=$_POST["postalgmt"];} +if (isset($_GET["phone_code_override"])) {$phone_code_override=$_GET["phone_code_override"];} + elseif (isset($_POST["phone_code_override"])) {$phone_code_override=$_POST["phone_code_override"];} + $phone_code_override = (preg_replace("/\D/","",$phone_code_override)); +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["template_id"])) {$template_id=$_GET["template_id"];} + elseif (isset($_POST["template_id"])) {$template_id=$_POST["template_id"];} +if (isset($_GET["usacan_check"])) {$usacan_check=$_GET["usacan_check"];} + elseif (isset($_POST["usacan_check"])) {$usacan_check=$_POST["usacan_check"];} + + +# if the didnt select an over ride wipe out in_file +if ( $list_id_override == "in_file" ) { $list_id_override = ""; } +if ( $phone_code_override == "in_file" ) { $phone_code_override = ""; } + +# $country_field=$_GET["country_field"]; if (!$country_field) {$country_field=$_POST["country_field"];} + +### REGEX to prevent weird characters from ending up in the fields +$field_regx = "['\"`\\;]"; + +$vicidial_list_fields = '|lead_id|vendor_lead_code|source_id|list_id|gmt_offset_now|called_since_last_reset|phone_code|phone_number|title|first_name|middle_initial|last_name|address1|address2|address3|city|state|province|postal_code|country_code|gender|date_of_birth|alt_phone|email|security_phrase|comments|called_count|last_local_call_time|rank|owner|entry_list_id|'; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,admin_web_directory,custom_fields_enabled,webroot_writable FROM system_settings;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysql_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysql_fetch_row($rslt); + $non_latin = $row[0]; + $admin_web_directory = $row[1]; + $custom_fields_enabled = $row[2]; + $webroot_writable = $row[3]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ($non_latin < 1) + { + $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); + $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); + $list_id_override = ereg_replace("[^0-9]","",$list_id_override); + } +else + { + $PHP_AUTH_PW = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_PW); + $PHP_AUTH_USER = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_USER); + } + +$STARTtime = date("U"); +$TODAY = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$FILE_datetime = $STARTtime; + +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7;"; +if ($DB) {echo "|$stmt|\n";} +if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$auth=$row[0]; + +if ($webroot_writable > 0) {$fp = fopen ("./project_auth_entries.txt", "a");} +$date = date("r"); +$ip = getenv("REMOTE_ADDR"); +$browser = getenv("HTTP_USER_AGENT"); + +if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) + { + Header("WWW-Authenticate: Basic realm=\"VICIDIAL-LEAD-LOADER\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; + exit; + } +else + { + 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 + + if($auth>0) + { + $office_no=strtoupper($PHP_AUTH_USER); + $password=strtoupper($PHP_AUTH_PW); + $stmt="SELECT load_leads,user_group from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGload_leads = $row[0]; + $LOGuser_group = $row[1]; + + if ($LOGload_leads < 1) + { + echo "You do not have permissions to load leads\n"; + exit; + } + if ($webroot_writable > 0) + { + fwrite ($fp, "LIST_LOAD|GOOD|$date|$PHP_AUTH_USER|XXXX|$ip|$browser|$LOGfullname|\n"); + fclose($fp); + } + } + else + { + if ($webroot_writable > 0) + { + fwrite ($fp, "LIST_LOAD|FAIL|$date|$PHP_AUTH_USER|XXXX|$ip|$browser|\n"); + fclose($fp); + } + exit; + } + } + +$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_query($stmt, $link); +$row=mysql_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; +$LOGadmin_viewable_groups = $row[2]; +$LOGadmin_viewable_call_times = $row[3]; + +$camp_lists=''; +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if (!eregi("-ALL",$LOGallowed_campaigns)) + { + $rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns); + $rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL); + $LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')"; + $whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$script_name = getenv("SCRIPT_NAME"); +$server_name = getenv("SERVER_NAME"); +$server_port = getenv("SERVER_PORT"); +if (eregi("443",$server_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +$admDIR = "$HTTPprotocol$server_name$script_name"; +$admDIR = eregi_replace('admin_listloader_fourth_gen.php','',$admDIR); +$admDIR = "/vicidial/"; +$admSCR = 'admin.php'; +$NWB = "   \"HELP\""; + +$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 server_ip = '$server_ip';"; +$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; + +#if ($DB) {print "SEED TIME $secX : $year-$mon-$mday $hour:$min:$sec LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";} + + +echo "\n"; +echo "\n"; +echo "\n"; +echo "\n"; + +function macfontfix($fontsize) + { + $browser = getenv("HTTP_USER_AGENT"); + $pctype = explode("(", $browser); + if (ereg("Mac",$pctype[1])) + { + /* Browser is a Mac. If not Netscape 6, raise fonts */ + $blownbrowser = explode('/', $browser); + $ver = explode(' ', $blownbrowser[1]); + $ver = $ver[0]; + if ($ver >= 5.0) return $fontsize; else return ($fontsize+2); + } + else return $fontsize; /* Browser is not a Mac - don't touch fonts */ + } + +echo "\n"; + +?> + + + +ADMINISTRATION: Lead Loader + + + +
"; + +if ( (!$OK_to_process) or ( ($leadfile) and ($file_layout!="standard" && $file_layout!="template") ) ) + { + ?> +
method=post onSubmit="ParseFileName()" enctype="multipart/form-data"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Load leads from this file:
List ID Override: + +
Phone Code Override: + +
File layout to use:Standard Format    Custom layout    Custom Template
Custom template to use: template builder
Lead Duplicate Check:
USA-Canada Check:
Lead Time Zone Lookup:
        
        BACK TO ADMIN         Old Lead Loader     LIST LOADER 4th Gen-     VERSION:     BUILD:    
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Lead file:
List ID Override:
Phone Code Override:
USA-Canada Check:
Lead Duplicate Check:
Lead Time Zone Lookup:
+ method=get onSubmit="ParseFileName()" enctype="multipart/form-data"> + + + Load Another Lead File         VERSION:     BUILD: +
+



+ document.forms[0].leadfile.disabled=true;document.forms[0].list_id_override.disabled=true;document.forms[0].phone_code_override.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;"; + flush(); + $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list=''; + + $file=fopen("$lead_file", "r"); + if ($webroot_writable > 0) + { + $stmt_file=fopen("listloader_stmts.txt", "w"); + } + $buffer=fgets($file, 4096); + $tab_count=substr_count($buffer, "\t"); + $pipe_count=substr_count($buffer, "|"); + + if ($tab_count>$pipe_count) {$delimiter="\t"; $delim_name="tab";} else {$delimiter="|"; $delim_name="pipe";} + $field_check=explode($delimiter, $buffer); + + if (count($field_check)>=2) + { + flush(); + $file=fopen("$lead_file", "r"); + print "
Processing file...\n"; + + if (strlen($list_id_override)>0) + { + print "

LIST ID OVERRIDE FOR THIS FILE: $list_id_override

"; + } + + if (strlen($phone_code_override)>0) + { + print "

PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override

"; + } + + if ($custom_fields_enabled > 0) + { + $tablecount_to_print=0; + $fieldscount_to_print=0; + $fields_to_print=0; + + $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $tablecount_to_print = mysql_num_rows($rslt); + + if ($tablecount_to_print > 0) + { + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fieldscount_to_print = mysql_num_rows($rslt); + + if ($fieldscount_to_print > 0) + { + $stmt="SELECT field_label,field_type from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fields_to_print = mysql_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysql_fetch_row($rslt); + $A_field_label[$o] = $rowx[0]; + $A_field_type[$o] = $rowx[1]; + $A_field_value[$o] = ''; + $o++; + } + } + } + } + + while (!feof($file)) + { + $record++; + $buffer=rtrim(fgets($file, 4096)); + $buffer=stripslashes($buffer); + + if (strlen($buffer)>0) + { + $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer)); + + $pulldate=date("Y-m-d H:i:s"); + $entry_date = "$pulldate"; + $modify_date = ""; + $status = "NEW"; + $user =""; + $vendor_lead_code = $row[$vendor_lead_code_field]; + $source_code = $row[$source_id_field]; + $source_id=$source_code; + $list_id = $row[$list_id_field]; + $gmt_offset = '0'; + $called_since_last_reset='N'; + $phone_code = eregi_replace("[^0-9]", "", $row[$phone_code_field]); + $phone_number = eregi_replace("[^0-9]", "", $row[$phone_number_field]); + $title = $row[$title_field]; + $first_name = $row[$first_name_field]; + $middle_initial = $row[$middle_initial_field]; + $last_name = $row[$last_name_field]; + $address1 = $row[$address1_field]; + $address2 = $row[$address2_field]; + $address3 = $row[$address3_field]; + $city =$row[$city_field]; + $state = $row[$state_field]; + $province = $row[$province_field]; + $postal_code = $row[$postal_code_field]; + $country_code = $row[$country_code_field]; + $gender = $row[$gender_field]; + $date_of_birth = $row[$date_of_birth_field]; + $alt_phone = eregi_replace("[^0-9]", "", $row[$alt_phone_field]); + $email = $row[$email_field]; + $security_phrase = $row[$security_phrase_field]; + $comments = trim($row[$comments_field]); + $rank = $row[$rank_field]; + $owner = $row[$owner_field]; + + # replace ' " ` \ ; with nothing + $vendor_lead_code = eregi_replace($field_regx, "", $vendor_lead_code); + $source_code = eregi_replace($field_regx, "", $source_code); + $source_id = eregi_replace($field_regx, "", $source_id); + $list_id = eregi_replace($field_regx, "", $list_id); + $phone_code = eregi_replace($field_regx, "", $phone_code); + $phone_number = eregi_replace($field_regx, "", $phone_number); + $title = eregi_replace($field_regx, "", $title); + $first_name = eregi_replace($field_regx, "", $first_name); + $middle_initial = eregi_replace($field_regx, "", $middle_initial); + $last_name = eregi_replace($field_regx, "", $last_name); + $address1 = eregi_replace($field_regx, "", $address1); + $address2 = eregi_replace($field_regx, "", $address2); + $address3 = eregi_replace($field_regx, "", $address3); + $city = eregi_replace($field_regx, "", $city); + $state = eregi_replace($field_regx, "", $state); + $province = eregi_replace($field_regx, "", $province); + $postal_code = eregi_replace($field_regx, "", $postal_code); + $country_code = eregi_replace($field_regx, "", $country_code); + $gender = eregi_replace($field_regx, "", $gender); + $date_of_birth = eregi_replace($field_regx, "", $date_of_birth); + $alt_phone = eregi_replace($field_regx, "", $alt_phone); + $email = eregi_replace($field_regx, "", $email); + $security_phrase = eregi_replace($field_regx, "", $security_phrase); + $comments = eregi_replace($field_regx, "", $comments); + $rank = eregi_replace($field_regx, "", $rank); + $owner = eregi_replace($field_regx, "", $owner); + + $USarea = substr($phone_number, 0, 3); + + if (strlen($list_id_override)>0) + { + # print "

LIST ID OVERRIDE FOR THIS FILE: $list_id_override

"; + $list_id = $list_id_override; + } + if (strlen($phone_code_override)>0) + { + $phone_code = $phone_code_override; + } + + ##### BEGIN custom fields columns list ### + $custom_SQL=''; + if ($custom_fields_enabled > 0) + { + if ($tablecount_to_print > 0) + { + if ($fieldscount_to_print > 0) + { + $o=0; + while ($fields_to_print > $o) + { + $A_field_value[$o] = ''; + $field_name_id = $A_field_label[$o] . "_field"; + + # if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";} + + if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') ) + { + if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) + { + if (isset($_GET["$field_name_id"])) {$form_field_value=$_GET["$field_name_id"];} + elseif (isset($_POST["$field_name_id"])) {$form_field_value=$_POST["$field_name_id"];} + + if ($form_field_value >= 0) + { + $A_field_value[$o] = $row[$form_field_value]; + # replace ' " ` \ ; with nothing + $A_field_value[$o] = eregi_replace($field_regx, "", $A_field_value[$o]); + + $custom_SQL .= "$A_field_label[$o]='$A_field_value[$o]',"; + } + } + } + $o++; + } + } + } + } + ##### END custom fields columns list ### + + $custom_SQL = preg_replace("/,$/","",$custom_SQL); + + + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### + if (eregi("DUPCAMP",$dupcheck)) + { + $dup_lead=0; + $dup_lists=''; + $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $ci_recs = mysql_num_rows($rslt); + if ($ci_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_camp = $row[0]; + + $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $rslt=mysql_query($stmt, $link); + $li_recs = mysql_num_rows($rslt); + if ($li_recs > 0) + { + $L=0; + while ($li_recs > $L) + { + $row=mysql_fetch_row($rslt); + $dup_lists .= "'$row[0]',"; + $L++; + } + $dup_lists = eregi_replace(",$",'',$dup_lists); + + $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (eregi("DUPSYS",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if (eregi("DUPLIST",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### + if (eregi("DUPTITLEALTPHONELIST",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (eregi("$alt_phone$title$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (eregi("DUPTITLEALTPHONESYS",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$alt_phone$title$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + $valid_number=1; + if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) ) + { + $valid_number=0; + $invalid_reason = "INVALID PHONE NUMBER LENGTH"; + } + if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) ) + { + $USprefix = substr($phone_number, 3, 1); + if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";} + if ($USprefix < 2) + { + $valid_number=0; + $invalid_reason = "INVALID PHONE NUMBER PREFIX"; + } + } + if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) ) + { + $phone_areacode = substr($phone_number, 0, 3); + $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';"; + if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $valid_number=$row[0]; + if ($valid_number < 1) + { + $invalid_reason = "INVALID PHONE NUMBER AREACODE"; + } + } + + if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 )) + { + if (strlen($phone_code)<1) {$phone_code = '1';} + + if (eregi("TITLEALTPHONE",$dupcheck)) + {$phone_list .= "$alt_phone$title$US$list_id|";} + else + {$phone_list .= "$phone_number$US$list_id|";} + + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner); + + if (strlen($custom_SQL)>3) + { + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values('','$entry_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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','$list_id');"; + $rslt=mysql_query($stmtZ, $link); + $affected_rows = mysql_affected_rows($link); + $lead_id = mysql_insert_id($link); + if ($DB > 0) {echo "";} + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + $multistmt=''; + + $custom_SQL_query = "INSERT INTO custom_$list_id_override SET lead_id='$lead_id',$custom_SQL;"; + $rslt=mysql_query($custom_SQL_query, $link); + $affected_rows = mysql_affected_rows($link); + if ($DB > 0) {echo "";} + } + else + { + if ($multi_insert_counter > 8) + { + ### insert good record into vicidial_list table ### + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');"; + $rslt=mysql_query($stmtZ, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + $multistmt=''; + $multi_insert_counter=0; + } + else + { + $multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),"; + $multi_insert_counter++; + } + } + $good++; + } + else + { + if ($bad < 1000000) + { + if ( $list_id < 100 ) + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID\n"; + } + else + { + if ($valid_number < 1) + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number\n"; + } + else + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead $dup_lead_list\n"; + } + } + } + $bad++; + } + $total++; + if ($total%100==0) + { + print ""; + usleep(1000); + flush(); + } + } + } + if ($multi_insert_counter!=0) + { + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";"; + mysql_query($stmtZ, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + } + + ### LOG INSERTION Admin Log Table ### + $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST CUSTOM', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + + print "

Done
GOOD: $good       BAD: $bad       TOTAL: $total
"; + } + else + { + print "
ERROR: The file does not have the required number of fields to process it.
"; + } + } +##### END custom fields submission ##### + +if (($leadfile) && ($LF_path)) + { + $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list=''; + + ### LOG INSERTION Admin Log Table ### + $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST', event_sql='', event_notes='File Name: $leadfile_name';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + + ##### BEGIN process TEMPLATE file layout ##### + if ($file_layout=="template" && $template_id) + { + + $template_stmt="select * from vicidial_custom_leadloader_templates where template_id='$template_id'"; + $template_rslt=mysql_query($template_stmt, $link); + if (mysql_num_rows($template_rslt)==0) + { + echo "Error - template no longer exists"; die; + } + else + { + $template_row=mysql_fetch_array($template_rslt); + $template_id=$template_row["template_id"]; + $template_name=$template_row["template_name"]; + $template_description=$template_row["template_description"]; + $list_id_override=$template_row["list_id"]; + $standard_variables=$template_row["standard_variables"]; + $custom_table=$template_row["custom_table"]; + $custom_variables=$template_row["custom_variables"]; + $standard_fields_ary=explode("|", $standard_variables); + for ($i=0; $i0) + { + $fieldno_ary=explode(",", $standard_fields_ary[$i]); + $varname=$fieldno_ary[0]."_field"; + $$varname=$fieldno_ary[1]; + } + } + $custom_fields_ary=explode("|", $custom_variables); + if (count($custom_fields_ary)>0 && strlen($custom_table)>0) + { + $custom_ins_stmt="INSERT INTO $custom_table("; + for ($i=0; $i0) + { + $fieldno_ary=explode(",", $custom_fields_ary[$i]); + $custom_ins_stmt.="$fieldno_ary[0],"; + $varname=$fieldno_ary[0]."_field"; + $$varname=$fieldno_ary[1]; + } + } + $custom_ins_stmt=substr($custom_ins_stmt, 0, -1).") VALUES ("; + } + } + + print ""; + flush(); + + $delim_set=0; + # csv xls xlsx ods sxc conversion + if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name)) + { + $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name); + copy($LF_path, "/tmp/$leadfile_name"); + $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name); + $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename"; + passthru("$convert_command"); + $lead_file = "/tmp/$new_filename"; + if ($DB > 0) {echo "|$convert_command|";} + + if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";} + if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";} + if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";} + if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";} + if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";} + $delim_set=1; + } + else + { + copy($LF_path, "/tmp/vicidial_temp_file.txt"); + $lead_file = "/tmp/vicidial_temp_file.txt"; + } + $file=fopen("$lead_file", "r"); + if ($webroot_writable > 0) + {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");} + + $buffer=fgets($file, 4096); + $tab_count=substr_count($buffer, "\t"); + $pipe_count=substr_count($buffer, "|"); + + if ($delim_set < 1) + { + if ($tab_count>$pipe_count) + {$delim_name="tab-delimited";} + else + {$delim_name="pipe-delimited";} + } + if ($tab_count>$pipe_count) + {$delimiter="\t";} + else + {$delimiter="|";} + + $field_check=explode($delimiter, $buffer); + + if (count($field_check)>=2) + { + flush(); + $file=fopen("$lead_file", "r"); + $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list=''; + print "
Processing $delim_name file using template $template_id... ($tab_count|$pipe_count)\n"; + if (strlen($list_id_override)>0) + { + print "

LIST ID OVERRIDE FOR THIS FILE: $list_id_override

"; + } + if (strlen($phone_code_override)>0) + { + print "

PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override

\n"; + } + while (!feof($file)) + { + $record++; + $buffer=rtrim(fgets($file, 4096)); + $buffer=stripslashes($buffer); + + if (strlen($buffer)>0) + { + $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer)); + $custom_fields_row=$row; + $pulldate=date("Y-m-d H:i:s"); + $entry_date = "$pulldate"; + $modify_date = ""; + $status = "NEW"; + $user =""; + $vendor_lead_code = $row[$vendor_lead_code_field]; + $source_code = $row[$source_id_field]; + $source_id=$source_code; + $list_id = $row[$list_id_field]; + $gmt_offset = '0'; + $called_since_last_reset='N'; + $phone_code = eregi_replace("[^0-9]", "", $row[$phone_code_field]); + $phone_number = eregi_replace("[^0-9]", "", $row[$phone_number_field]); + $title = $row[$title_field]; + $first_name = $row[$first_name_field]; + $middle_initial = $row[$middle_initial_field]; + $last_name = $row[$last_name_field]; + $address1 = $row[$address1_field]; + $address2 = $row[$address2_field]; + $address3 = $row[$address3_field]; + $city =$row[$city_field]; + $state = $row[$state_field]; + $province = $row[$province_field]; + $postal_code = $row[$postal_code_field]; + $country_code = $row[$country_code_field]; + $gender = $row[$gender_field]; + $date_of_birth = $row[$date_of_birth_field]; + $alt_phone = eregi_replace("[^0-9]", "", $row[$alt_phone_field]); + $email = $row[$email_field]; + $security_phrase = $row[$security_phrase_field]; + $comments = trim($row[$comments_field]); + $rank = $row[$rank_field]; + $owner = $row[$owner_field]; + + # replace ' " ` \ ; with nothing + $vendor_lead_code = eregi_replace($field_regx, "", $vendor_lead_code); + $source_code = eregi_replace($field_regx, "", $source_code); + $source_id = eregi_replace($field_regx, "", $source_id); + $list_id = eregi_replace($field_regx, "", $list_id); + $phone_code = eregi_replace($field_regx, "", $phone_code); + $phone_number = eregi_replace($field_regx, "", $phone_number); + $title = eregi_replace($field_regx, "", $title); + $first_name = eregi_replace($field_regx, "", $first_name); + $middle_initial = eregi_replace($field_regx, "", $middle_initial); + $last_name = eregi_replace($field_regx, "", $last_name); + $address1 = eregi_replace($field_regx, "", $address1); + $address2 = eregi_replace($field_regx, "", $address2); + $address3 = eregi_replace($field_regx, "", $address3); + $city = eregi_replace($field_regx, "", $city); + $state = eregi_replace($field_regx, "", $state); + $province = eregi_replace($field_regx, "", $province); + $postal_code = eregi_replace($field_regx, "", $postal_code); + $country_code = eregi_replace($field_regx, "", $country_code); + $gender = eregi_replace($field_regx, "", $gender); + $date_of_birth = eregi_replace($field_regx, "", $date_of_birth); + $alt_phone = eregi_replace($field_regx, "", $alt_phone); + $email = eregi_replace($field_regx, "", $email); + $security_phrase = eregi_replace($field_regx, "", $security_phrase); + $comments = eregi_replace($field_regx, "", $comments); + $rank = eregi_replace($field_regx, "", $rank); + $owner = eregi_replace($field_regx, "", $owner); + + $USarea = substr($phone_number, 0, 3); + + if (strlen($list_id_override)>0) + { + $list_id = $list_id_override; + } + if (strlen($phone_code_override)>0) + { + $phone_code = $phone_code_override; + } + + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### + if (eregi("DUPCAMP",$dupcheck)) + { + $dup_lead=0; + $dup_lists=''; + $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $ci_recs = mysql_num_rows($rslt); + if ($ci_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_camp = $row[0]; + + $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $rslt=mysql_query($stmt, $link); + $li_recs = mysql_num_rows($rslt); + if ($li_recs > 0) + { + $L=0; + while ($li_recs > $L) + { + $row=mysql_fetch_row($rslt); + $dup_lists .= "'$row[0]',"; + $L++; + } + $dup_lists = eregi_replace(",$",'',$dup_lists); + + $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (eregi("DUPSYS",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if (eregi("DUPLIST",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_lead = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### + if (eregi("DUPTITLEALTPHONELIST",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (eregi("$alt_phone$title$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (eregi("DUPTITLEALTPHONESYS",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$alt_phone$title$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + $valid_number=1; + if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) ) + { + $valid_number=0; + $invalid_reason = "INVALID PHONE NUMBER LENGTH"; + } + if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) ) + { + $USprefix = substr($phone_number, 3, 1); + if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";} + if ($USprefix < 2) + { + $valid_number=0; + $invalid_reason = "INVALID PHONE NUMBER PREFIX"; + } + } + if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) ) + { + $phone_areacode = substr($phone_number, 0, 3); + $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';"; + if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $valid_number=$row[0]; + if ($valid_number < 1) + { + $invalid_reason = "INVALID PHONE NUMBER AREACODE"; + } + } + + if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 )) + { + if (strlen($phone_code)<1) {$phone_code = '1';} + + if (eregi("TITLEALTPHONE",$dupcheck)) + {$phone_list .= "$alt_phone$title$US$list_id|";} + else + {$phone_list .= "$phone_number$US$list_id|";} + + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner); + +/* if ($multi_insert_counter > 8) +# { + ### insert good deal into pending_transactions table ### + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');"; + $rslt=mysql_query($stmtZ, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + $multistmt=''; */ + $multi_insert_counter=0; + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values('','$entry_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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','$list_id');"; + $rslt=mysql_query($stmtZ, $link); + $affected_rows = mysql_affected_rows($link); + $lead_id = mysql_insert_id($link); + if ($DB > 0) {echo "";} + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + $multistmt=''; + + #$custom_SQL_query = "INSERT INTO custom_$list_id_override SET lead_id='$lead_id',$custom_SQL;"; + #$rslt=mysql_query($custom_SQL_query, $link); + #$affected_rows = mysql_affected_rows($link); + + $custom_ins_stmt="INSERT INTO $custom_table(lead_id"; + $custom_SQL_values=""; + for ($q=0; $q0) + { + $fieldno_ary=explode(",", $custom_fields_ary[$q]); + $varname=$fieldno_ary[0]."_field"; + $$varname=$fieldno_ary[1]; + $custom_ins_stmt.=",$fieldno_ary[0]"; + $custom_SQL_values.=",'".$custom_fields_row[$$varname]."'"; + } + } + $custom_ins_stmt.=") VALUES('$lead_id'$custom_SQL_values)"; + $custom_rslt=mysql_query($custom_ins_stmt, $link); + $affected_rows = mysql_affected_rows($link); + echo "\n"; + if ($webroot_writable > 0) + {fwrite($stmt_file, $custom_ins_stmt."\r\n");} +/* + } + else + { + $multistmt .= "('','$entry_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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),"; + + $custom_multistmt.="("; + for ($q=0; $q0) + { + $custom_fieldno_ary=explode(",", $custom_fields_ary[$q]); + $varname=$custom_fieldno_ary[0]; + $$varname=$row[$custom_fieldno_ary[1]]; + $custom_multistmt.="'".$$varname."',"; + } + } + $custom_multistmt=substr($custom_multistmt, 0, -1)."),"; + $multi_insert_counter++; + } */ + $good++; + } + else + { + if ($bad < 1000000) + { + if ( $list_id < 100 ) + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID\n"; + } + else + { + if ($valid_number < 1) + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number\n"; + } + else + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead $dup_lead_list\n"; + } + } + } + $bad++; + } + $total++; + if ($total%100==0) + { + print ""; + usleep(1000); + flush(); + } + } + } + if ($multi_insert_counter!=0) + { + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";"; + mysql_query($stmtZ, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + + $custom_ins_stmt="INSERT INTO $custom_table("; + for ($q=0; $q0) + { + $fieldno_ary=explode(",", $custom_fields_ary[$q]); + $custom_ins_stmt.="$fieldno_ary[0],"; + $varname=$fieldno_ary[0]."_field"; + $$varname=$fieldno_ary[1]; + } + } + $custom_ins_stmt=substr($custom_ins_stmt, 0, -1).") VALUES".substr($custom_multistmt, 0, -1); + mysql_query($custom_ins_stmt, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $custom_ins_stmt."\r\n");} + } + ### LOG INSERTION Admin Log Table ### + $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST STANDARD', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + + print "

Done
GOOD: $good       BAD: $bad       TOTAL: $total
"; + } + else + { + print "
ERROR: The file does not have the required number of fields to process it.
"; + } + + } + + ##### BEGIN process standard file layout ##### + if ($file_layout=="standard") + { + print ""; + flush(); + + + $delim_set=0; + # csv xls xlsx ods sxc conversion + if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name)) + { + $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name); + copy($LF_path, "/tmp/$leadfile_name"); + $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name); + $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename"; + passthru("$convert_command"); + $lead_file = "/tmp/$new_filename"; + if ($DB > 0) {echo "|$convert_command|";} + + if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";} + if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";} + if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";} + if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";} + if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";} + $delim_set=1; + } + else + { + copy($LF_path, "/tmp/vicidial_temp_file.txt"); + $lead_file = "/tmp/vicidial_temp_file.txt"; + } + $file=fopen("$lead_file", "r"); + if ($webroot_writable > 0) + {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");} + + $buffer=fgets($file, 4096); + $tab_count=substr_count($buffer, "\t"); + $pipe_count=substr_count($buffer, "|"); + + if ($delim_set < 1) + { + if ($tab_count>$pipe_count) + {$delim_name="tab-delimited";} + else + {$delim_name="pipe-delimited";} + } + if ($tab_count>$pipe_count) + {$delimiter="\t";} + else + {$delimiter="|";} + + $field_check=explode($delimiter, $buffer); + + if (count($field_check)>=2) + { + flush(); + $file=fopen("$lead_file", "r"); + $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list=''; + print "
Processing $delim_name file... ($tab_count|$pipe_count)\n"; + if (strlen($list_id_override)>0) + { + print "

LIST ID OVERRIDE FOR THIS FILE: $list_id_override

"; + } + if (strlen($phone_code_override)>0) + { + print "

PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override

\n"; + } + while (!feof($file)) + { + $record++; + $buffer=rtrim(fgets($file, 4096)); + $buffer=stripslashes($buffer); + + if (strlen($buffer)>0) + { + $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer)); + + $pulldate=date("Y-m-d H:i:s"); + $entry_date = "$pulldate"; + $modify_date = ""; + $status = "NEW"; + $user =""; + $vendor_lead_code = $row[0]; + $source_code = $row[1]; + $source_id=$source_code; + $list_id = $row[2]; + $gmt_offset = '0'; + $called_since_last_reset='N'; + $phone_code = eregi_replace("[^0-9]", "", $row[3]); + $phone_number = eregi_replace("[^0-9]", "", $row[4]); + $title = $row[5]; + $first_name = $row[6]; + $middle_initial = $row[7]; + $last_name = $row[8]; + $address1 = $row[9]; + $address2 = $row[10]; + $address3 = $row[11]; + $city =$row[12]; + $state = $row[13]; + $province = $row[14]; + $postal_code = $row[15]; + $country_code = $row[16]; + $gender = $row[17]; + $date_of_birth = $row[18]; + $alt_phone = eregi_replace("[^0-9]", "", $row[19]); + $email = $row[20]; + $security_phrase = $row[21]; + $comments = trim($row[22]); + $rank = $row[23]; + $owner = $row[24]; + + # replace ' " ` \ ; with nothing + $vendor_lead_code = eregi_replace($field_regx, "", $vendor_lead_code); + $source_code = eregi_replace($field_regx, "", $source_code); + $source_id = eregi_replace($field_regx, "", $source_id); + $list_id = eregi_replace($field_regx, "", $list_id); + $phone_code = eregi_replace($field_regx, "", $phone_code); + $phone_number = eregi_replace($field_regx, "", $phone_number); + $title = eregi_replace($field_regx, "", $title); + $first_name = eregi_replace($field_regx, "", $first_name); + $middle_initial = eregi_replace($field_regx, "", $middle_initial); + $last_name = eregi_replace($field_regx, "", $last_name); + $address1 = eregi_replace($field_regx, "", $address1); + $address2 = eregi_replace($field_regx, "", $address2); + $address3 = eregi_replace($field_regx, "", $address3); + $city = eregi_replace($field_regx, "", $city); + $state = eregi_replace($field_regx, "", $state); + $province = eregi_replace($field_regx, "", $province); + $postal_code = eregi_replace($field_regx, "", $postal_code); + $country_code = eregi_replace($field_regx, "", $country_code); + $gender = eregi_replace($field_regx, "", $gender); + $date_of_birth = eregi_replace($field_regx, "", $date_of_birth); + $alt_phone = eregi_replace($field_regx, "", $alt_phone); + $email = eregi_replace($field_regx, "", $email); + $security_phrase = eregi_replace($field_regx, "", $security_phrase); + $comments = eregi_replace($field_regx, "", $comments); + $rank = eregi_replace($field_regx, "", $rank); + $owner = eregi_replace($field_regx, "", $owner); + + $USarea = substr($phone_number, 0, 3); + + if (strlen($list_id_override)>0) + { + $list_id = $list_id_override; + } + if (strlen($phone_code_override)>0) + { + $phone_code = $phone_code_override; + } + + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### + if (eregi("DUPCAMP",$dupcheck)) + { + $dup_lead=0; + $dup_lists=''; + $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $ci_recs = mysql_num_rows($rslt); + if ($ci_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_camp = $row[0]; + + $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $rslt=mysql_query($stmt, $link); + $li_recs = mysql_num_rows($rslt); + if ($li_recs > 0) + { + $L=0; + while ($li_recs > $L) + { + $row=mysql_fetch_row($rslt); + $dup_lists .= "'$row[0]',"; + $L++; + } + $dup_lists = eregi_replace(",$",'',$dup_lists); + + $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (eregi("DUPSYS",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if (eregi("DUPLIST",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_lead = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$phone_number$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### + if (eregi("DUPTITLEALTPHONELIST",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (eregi("$alt_phone$title$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (eregi("DUPTITLEALTPHONESYS",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysql_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (eregi("$alt_phone$title$US$list_id",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + $valid_number=1; + if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) ) + { + $valid_number=0; + $invalid_reason = "INVALID PHONE NUMBER LENGTH"; + } + if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) ) + { + $USprefix = substr($phone_number, 3, 1); + if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";} + if ($USprefix < 2) + { + $valid_number=0; + $invalid_reason = "INVALID PHONE NUMBER PREFIX"; + } + } + if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) ) + { + $phone_areacode = substr($phone_number, 0, 3); + $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';"; + if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $valid_number=$row[0]; + if ($valid_number < 1) + { + $invalid_reason = "INVALID PHONE NUMBER AREACODE"; + } + } + + if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 )) + { + if (strlen($phone_code)<1) {$phone_code = '1';} + + if (eregi("TITLEALTPHONE",$dupcheck)) + {$phone_list .= "$alt_phone$title$US$list_id|";} + else + {$phone_list .= "$phone_number$US$list_id|";} + + $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner); + + if ($multi_insert_counter > 8) + { + ### insert good deal into pending_transactions table ### + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');"; + $rslt=mysql_query($stmtZ, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + $multistmt=''; + $multi_insert_counter=0; + } + else + { + $multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$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_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),"; + $multi_insert_counter++; + } + $good++; + } + else + { + if ($bad < 1000000) + { + if ( $list_id < 100 ) + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID\n"; + } + else + { + if ($valid_number < 1) + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number\n"; + } + else + { + print "
record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead $dup_lead_list\n"; + } + } + } + $bad++; + } + $total++; + if ($total%100==0) + { + print ""; + usleep(1000); + flush(); + } + } + } + if ($multi_insert_counter!=0) + { + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";"; + mysql_query($stmtZ, $link); + if ($webroot_writable > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + } + ### LOG INSERTION Admin Log Table ### + $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST STANDARD', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_query($stmt, $link); + + print "

Done
GOOD: $good       BAD: $bad       TOTAL: $total
"; + } + else + { + print "
ERROR: The file does not have the required number of fields to process it.
"; + } + } + ##### END process standard file layout ##### + + + ##### BEGIN field chooser ##### + else if ($file_layout=="custom") + { + print "
"; + flush(); + print "\r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + + $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner from vicidial_list limit 1"; + + ##### BEGIN custom fields columns list ### + if ($custom_fields_enabled > 0) + { + $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $tablecount_to_print = mysql_num_rows($rslt); + if ($tablecount_to_print > 0) + { + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fieldscount_to_print = mysql_num_rows($rslt); + if ($fieldscount_to_print > 0) + { + $rowx=mysql_fetch_row($rslt); + $custom_records_count = $rowx[0]; + + $custom_SQL=''; + $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fields_to_print = mysql_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysql_fetch_row($rslt); + $A_field_label[$o] = $rowx[1]; + $A_field_type[$o] = $rowx[6]; + + if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";} + + if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') ) + { + if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) + { + $custom_SQL .= ",$A_field_label[$o]"; + } + } + $o++; + } + + $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner $custom_SQL from vicidial_list, custom_$list_id_override limit 1"; + + } + } + } + ##### END custom fields columns list ### + + + $rslt=mysql_query("$fields_stmt", $link); + + # csv xls xlsx ods sxc conversion + $delim_set=0; + if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name)) + { + $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name); + copy($LF_path, "/tmp/$leadfile_name"); + $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name); + $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename"; + passthru("$convert_command"); + $lead_file = "/tmp/$new_filename"; + if ($DB > 0) {echo "|$convert_command|";} + + if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";} + if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";} + if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";} + if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";} + if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";} + $delim_set=1; + } + else + { + copy($LF_path, "/tmp/vicidial_temp_file.txt"); + $lead_file = "/tmp/vicidial_temp_file.txt"; + } + $file=fopen("$lead_file", "r"); + if ($webroot_writable > 0) + {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");} + + $buffer=fgets($file, 4096); + $tab_count=substr_count($buffer, "\t"); + $pipe_count=substr_count($buffer, "|"); + + if ($delim_set < 1) + { + if ($tab_count>$pipe_count) + {$delim_name="tab-delimited";} + else + {$delim_name="pipe-delimited";} + } + if ($tab_count>$pipe_count) + {$delimiter="\t";} + else + {$delimiter="|";} + + $field_check=explode($delimiter, $buffer); + flush(); + $file=fopen("$lead_file", "r"); + print "
Processing $delim_name file...\n"; + + if (strlen($list_id_override)>0) + { + print "

LIST ID OVERRIDE FOR THIS FILE: $list_id_override

"; + } + if (strlen($phone_code_override)>0) + { + print "

PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override

"; + } + $buffer=rtrim(fgets($file, 4096)); + $buffer=stripslashes($buffer); + $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer)); + + for ($i=0; $i\n"; + } + else + { + print "
\r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + } + } + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print "
VICIDIAL ColumnFile data
".strtoupper(eregi_replace("_", " ", mysql_field_name($rslt, $i))).":
        
\r\n"; + + print ""; + } + ##### END field chooser ##### + + } + +?> + + + + + + + + +4) ) + { + if (preg_match('/^1$/', $phone_code)) + { + $stmt="select postal_code,state,GMT_offset,DST,DST_range,country,country_code 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=="TZCODE") && (strlen($owner)>1) ) + { + $dst_range=''; + $dst='N'; + $gmt_offset=0; + + $stmt="select GMT_offset from vicidial_phone_codes where tz_code='$owner' and country_code='$phone_code' limit 1;"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $gmt_offset = $row[0]; $gmt_offset = eregi_replace("\+","",$gmt_offset); + $PC_processed++; + $postalgmt_found++; + $post++; + } + + $stmt = "select distinct DST_range from vicidial_phone_codes where tz_code='$owner' and country_code='$phone_code' order by DST_range desc limit 1;"; + $rslt=mysql_query($stmt, $link); + $pc_recs = mysql_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysql_fetch_row($rslt); + $dst_range = $row[0]; + if (strlen($dst_range)>2) {$dst = 'Y';} + } + } + + if ($postalgmt_found < 1) + { + $PC_processed=0; + ### UNITED STATES ### + if ($phone_code =='1') + { + $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description 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 country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description 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 country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description 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 country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description 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-FSA') ) + { + if ($DBX) {print " Sunday in October to First Sunday in April\n";} + #********************************************************************** + # FSO-FSA + # 2008+ AUSTRALIA ONLY (country code 61) + # This is returns 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on first Sunday in October and first Sunday in April at 1 am. + #********************************************************************** + + $AUSE_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 4 or $mm > 10) { + $AUSE_DST=1; + } elseif ($mm >= 5 and $mm <= 9) { + $AUSE_DST=0; + } elseif ($mm == 4) { + if ($dd > 7) { + $AUSE_DST=0; + } elseif ($dd >= ($dow+1)) { + if ($timezone) { + if ($dow == 0 and $ns < (3600+$timezone*3600)) { + $AUSE_DST=1; + } else { + $AUSE_DST=0; + } + } else { + if ($dow == 0 and $ns < 7200) { + $AUSE_DST=1; + } else { + $AUSE_DST=0; + } + } + } else { + $AUSE_DST=1; + } + } elseif ($mm == 10) { + if ($dd >= 8) { + $AUSE_DST=1; + } elseif ($dd >= ($dow+1)) { + if ($timezone) { + if ($dow == 0 and $ns < (7200+$timezone*3600)) { + $AUSE_DST=0; + } else { + $AUSE_DST=1; + } + } else { + if ($dow == 0 and $ns < 3600) { + $AUSE_DST=0; + } else { + $AUSE_DST=1; + } + } + } else { + $AUSE_DST=0; + } + } # end of month checks + if ($DBX) {print " DST: $AUSE_DST\n";} + if ($AUSE_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 == 'LSS-FSA') ) + { + if ($DBX) {print " Last Sunday in September to First Sunday in April\n";} + #********************************************************************** + # LSS-FSA + # 2007+ NEW ZEALAND (country code 64) + # This is returns 1 if Daylight Savings Time is in effect and 0 if + # Standard time is in effect. + # Based on last Sunday in September and first Sunday in April at 1 am. + #********************************************************************** + + $NZLN_DST=0; + $mm = $mon; + $dd = $mday; + $ns = $dsec; + $dow= $wday; + + if ($mm < 4 || $mm > 9) { + $NZLN_DST=1; + } elseif ($mm >= 5 && $mm <= 9) { + $NZLN_DST=0; + } elseif ($mm == 4) { + if ($dd > 7) { + $NZLN_DST=0; + } elseif ($dd >= ($dow+1)) { + if ($timezone) { + if ($dow == 0 && $ns < (3600+$timezone*3600)) { + $NZLN_DST=1; + } else { + $NZLN_DST=0; + } + } else { + if ($dow == 0 && $ns < 7200) { + $NZLN_DST=1; + } else { + $NZLN_DST=0; + } + } + } else { + $NZLN_DST=1; + } + } elseif ($mm == 9) { + if ($dd < 25) { + $NZLN_DST=0; + } elseif ($dd < ($dow+25)) { + $NZLN_DST=0; + } elseif ($dow == 0) { + if ($timezone) { # UTC calculations + if ($ns < (3600+($timezone-1)*3600)) { + $NZLN_DST=0; + } else { + $NZLN_DST=1; + } + } else { # local time calculations + if ($ns < 3600) { + $NZLN_DST=0; + } else { + $NZLN_DST=1; + } + } + } else { + $NZLN_DST=1; + } + } # end of month checks + if ($DBX) {print " DST: $NZLN_DST\n";} + if ($NZLN_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; + } + +?> +