diff --git a/extras/admin_listloader_third_gen.php b/extras/admin_listloader_third_gen.php new file mode 100644 index 00000000..b3d1898c --- /dev/null +++ b/extras/admin_listloader_third_gen.php @@ -0,0 +1,1557 @@ + 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 +# 120525-1037 - Added uploaded filename filtering +# 120529-1347 - Filename filter fix +# 130610-1055 - Finalized changing of all ereg instances to preg +# 130621-1815 - Added filtering of input to prevent SQL injection attacks and new user auth +# 130902-0753 - Changed to mysqli PHP functions +# 170409-1534 - Added IP List validation code +# + +$version = '2.14-49'; +$build = '170409-1534'; + +require("dbconnect_mysqli.php"); +require("functions.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["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_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_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 = preg_replace('/[^0-9a-zA-Z]/', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^0-9a-zA-Z]/', '', $PHP_AUTH_PW); + } +else + { + $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); + $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); + } +$list_id_override = preg_replace('/[^0-9]/','',$list_id_override); + +$STARTtime = date("U"); +$TODAY = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$FILE_datetime = $STARTtime; +$date = date("r"); +$ip = getenv("REMOTE_ADDR"); +$browser = getenv("HTTP_USER_AGENT"); + +$auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth < 1) + { + $VDdisplayMESSAGE = "Login incorrect, please try again"; + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = "Too many login attempts, try again in 15 minutes"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +$stmt="SELECT load_leads,user_group from vicidial_users where user='$PHP_AUTH_USER';"; +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGload_leads = $row[0]; +$LOGuser_group = $row[1]; + +if ($LOGload_leads < 1) + { + Header ("Content-type: text/html; charset=utf-8"); + echo "You do not have permissions to load leads\n"; + exit; + } + +if (preg_match("/;|:|\/|\^|\[|\]|\"|\'|\*/",$LF_orig)) + { + echo "ERROR: Invalid File Name: $LF_orig\n"; + 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_to_mysqli($stmt, $link); +$row=mysqli_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 (!preg_match('/\-ALL/i', $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 (preg_match("/443/i",$server_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +$admDIR = "$HTTPprotocol$server_name$script_name"; +$admDIR = preg_replace('/admin_listloader_third_gen\.php/i', '',$admDIR); +$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_to_mysqli($stmt, $link); +$gmt_recs = mysqli_num_rows($rslt); +if ($gmt_recs > 0) + { + $row=mysqli_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 = preg_replace('/\+/i', '',$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 (preg_match('/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") ) ) + { + ?> +
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
Lead Duplicate Check:
USA-Canada Check:
Lead Time Zone Lookup:
        
        BACK TO ADMIN             LIST LOADER 3rd Gen-     VERSION:     BUILD:    
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Lead file:
List ID Override:
Phone Code Override:
USA-Canada Check:
Lead Duplicate Check:
Lead Time Zone Lookup:
+ method=post 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_to_mysqli($stmt, $link); + $tablecount_to_print = mysqli_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_to_mysqli($stmt, $link); + $fieldscount_to_print = mysqli_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_to_mysqli($stmt, $link); + $fields_to_print = mysqli_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysqli_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, preg_replace('/[\'\"]/i', '', $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 = preg_replace('/[^0-9]/i', '', $row[$phone_code_field]); + $phone_number = preg_replace('/[^0-9]/i', '', $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 = preg_replace('/[^0-9]/i', '', $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 = preg_replace("/$field_regx/i", "", $vendor_lead_code); + $source_code = preg_replace("/$field_regx/i", "", $source_code); + $source_id = preg_replace("/$field_regx/i", "", $source_id); + $list_id = preg_replace("/$field_regx/i", "", $list_id); + $phone_code = preg_replace("/$field_regx/i", "", $phone_code); + $phone_number = preg_replace("/$field_regx/i", "", $phone_number); + $title = preg_replace("/$field_regx/i", "", $title); + $first_name = preg_replace("/$field_regx/i", "", $first_name); + $middle_initial = preg_replace("/$field_regx/i", "", $middle_initial); + $last_name = preg_replace("/$field_regx/i", "", $last_name); + $address1 = preg_replace("/$field_regx/i", "", $address1); + $address2 = preg_replace("/$field_regx/i", "", $address2); + $address3 = preg_replace("/$field_regx/i", "", $address3); + $city = preg_replace("/$field_regx/i", "", $city); + $state = preg_replace("/$field_regx/i", "", $state); + $province = preg_replace("/$field_regx/i", "", $province); + $postal_code = preg_replace("/$field_regx/i", "", $postal_code); + $country_code = preg_replace("/$field_regx/i", "", $country_code); + $gender = preg_replace("/$field_regx/i", "", $gender); + $date_of_birth = preg_replace("/$field_regx/i", "", $date_of_birth); + $alt_phone = preg_replace("/$field_regx/i", "", $alt_phone); + $email = preg_replace("/$field_regx/i", "", $email); + $security_phrase = preg_replace("/$field_regx/i", "", $security_phrase); + $comments = preg_replace("/$field_regx/i", "", $comments); + $rank = preg_replace("/$field_regx/i", "", $rank); + $owner = preg_replace("/$field_regx/i", "", $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] = preg_replace("/$field_regx/i", "", $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 (preg_match("/DUPCAMP/i",$dupcheck)) + { + $dup_lead=0; + $dup_lists=''; + $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $ci_recs = mysqli_num_rows($rslt); + if ($ci_recs > 0) + { + $row=mysqli_fetch_row($rslt); + $dup_camp = $row[0]; + + $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $rslt=mysql_to_mysqli($stmt, $link); + $li_recs = mysqli_num_rows($rslt); + if ($li_recs > 0) + { + $L=0; + while ($li_recs > $L) + { + $row=mysqli_fetch_row($rslt); + $dup_lists .= "'$row[0]',"; + $L++; + } + $dup_lists = preg_replace('/,$/i', '',$dup_lists); + + $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysqli_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$phone_number$US$list_id/i", $phone_list)) + {$dup_lead++; $dup++;} + } + } + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (preg_match("/DUPSYS/i",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysqli_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$phone_number$US$list_id/i", $phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if (preg_match("/DUPLIST/i",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysqli_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (preg_match("/$phone_number$US$list_id/i", $phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### + if (preg_match("/DUPTITLEALTPHONELIST/i",$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_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysqli_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (preg_match("/$alt_phone$title$US$list_id/i",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (preg_match("/DUPTITLEALTPHONESYS/i",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysqli_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$alt_phone$title$US$list_id/i",$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_to_mysqli($stmt, $link); + $row=mysqli_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 (preg_match("/TITLEALTPHONE/i",$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_to_mysqli($stmtZ, $link); + $affected_rows = mysqli_affected_rows($link); + $lead_id = mysqli_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_to_mysqli($custom_SQL_query, $link); + $affected_rows = mysqli_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_to_mysqli($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_to_mysqli($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_to_mysqli($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_to_mysqli($stmt, $link); + + + + ##### 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 = preg_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, preg_replace('/[\'\"]/i', '', $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 = preg_replace('/[^0-9]/i', '', $row[3]); + $phone_number = preg_replace('/[^0-9]/i', '', $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 = preg_replace('/[^0-9]/i', '', $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 = preg_replace("/$field_regx/i", "", $vendor_lead_code); + $source_code = preg_replace("/$field_regx/i", "", $source_code); + $source_id = preg_replace("/$field_regx/i", "", $source_id); + $list_id = preg_replace("/$field_regx/i", "", $list_id); + $phone_code = preg_replace("/$field_regx/i", "", $phone_code); + $phone_number = preg_replace("/$field_regx/i", "", $phone_number); + $title = preg_replace("/$field_regx/i", "", $title); + $first_name = preg_replace("/$field_regx/i", "", $first_name); + $middle_initial = preg_replace("/$field_regx/i", "", $middle_initial); + $last_name = preg_replace("/$field_regx/i", "", $last_name); + $address1 = preg_replace("/$field_regx/i", "", $address1); + $address2 = preg_replace("/$field_regx/i", "", $address2); + $address3 = preg_replace("/$field_regx/i", "", $address3); + $city = preg_replace("/$field_regx/i", "", $city); + $state = preg_replace("/$field_regx/i", "", $state); + $province = preg_replace("/$field_regx/i", "", $province); + $postal_code = preg_replace("/$field_regx/i", "", $postal_code); + $country_code = preg_replace("/$field_regx/i", "", $country_code); + $gender = preg_replace("/$field_regx/i", "", $gender); + $date_of_birth = preg_replace("/$field_regx/i", "", $date_of_birth); + $alt_phone = preg_replace("/$field_regx/i", "", $alt_phone); + $email = preg_replace("/$field_regx/i", "", $email); + $security_phrase = preg_replace("/$field_regx/i", "", $security_phrase); + $comments = preg_replace("/$field_regx/i", "", $comments); + $rank = preg_replace("/$field_regx/i", "", $rank); + $owner = preg_replace("/$field_regx/i", "", $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 (preg_match("/DUPCAMP/i",$dupcheck)) + { + $dup_lead=0; + $dup_lists=''; + $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $ci_recs = mysqli_num_rows($rslt); + if ($ci_recs > 0) + { + $row=mysqli_fetch_row($rslt); + $dup_camp = $row[0]; + + $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; + $rslt=mysql_to_mysqli($stmt, $link); + $li_recs = mysqli_num_rows($rslt); + if ($li_recs > 0) + { + $L=0; + while ($li_recs > $L) + { + $row=mysqli_fetch_row($rslt); + $dup_lists .= "'$row[0]',"; + $L++; + } + $dup_lists = preg_replace('/,$/i', '',$dup_lists); + + $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysqli_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$phone_number$US$list_id/i", $phone_list)) + {$dup_lead++; $dup++;} + } + } + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (preg_match("/DUPSYS/i",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysqli_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$phone_number$US$list_id/i", $phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### + if (preg_match("/DUPLIST/i",$dupcheck)) + { + $dup_lead=0; + $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysqli_fetch_row($rslt); + $dup_lead = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$phone_number$US$list_id/i", $phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### + if (preg_match("/DUPTITLEALTPHONELIST/i",$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_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $row=mysqli_fetch_row($rslt); + $dup_lead = $row[0]; + $dup_lead_list = $list_id; + } + if ($dup_lead < 1) + { + if (preg_match("/$alt_phone$title$US$list_id/i",$phone_list)) + {$dup_lead++; $dup++;} + } + } + + ##### Check for duplicate phone numbers in vicidial_list table entire database ##### + if (preg_match("/DUPTITLEALTPHONESYS/i",$dupcheck)) + { + $dup_lead=0; + $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; + $rslt=mysql_to_mysqli($stmt, $link); + $pc_recs = mysqli_num_rows($rslt); + if ($pc_recs > 0) + { + $dup_lead=1; + $row=mysqli_fetch_row($rslt); + $dup_lead_list = $row[0]; + } + if ($dup_lead < 1) + { + if (preg_match("/$alt_phone$title$US$list_id/i",$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_to_mysqli($stmt, $link); + $row=mysqli_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 (preg_match("/TITLEALTPHONE/i",$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_to_mysqli($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_to_mysqli($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_to_mysqli($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 + { + 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_to_mysqli($stmt, $link); + $tablecount_to_print = mysqli_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_to_mysqli($stmt, $link); + $fieldscount_to_print = mysqli_num_rows($rslt); + if ($fieldscount_to_print > 0) + { + $rowx=mysqli_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_to_mysqli($stmt, $link); + $fields_to_print = mysqli_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysqli_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_to_mysqli("$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 = preg_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, preg_replace('/[\'\"]/i', '', $buffer)); + + while ($fieldinfo=mysqli_fetch_field($rslt)) + { + $rslt_field_name=$fieldinfo->name; + if ( ($rslt_field_name=="list_id" and $list_id_override!="") or ($rslt_field_name=="phone_code" and $phone_code_override!="") ) + { + print "\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(preg_replace('/_/i', ' ', $rslt_field_name)).":
        
\r\n"; + + print ""; + } + ##### END field chooser ##### + + } + +?> + + + diff --git a/www/vicidial/admin_listloader_fourth_gen.php b/www/vicidial/admin_listloader_fourth_gen.php index 7a29f088..c8cd3b08 100644 --- a/www/vicidial/admin_listloader_fourth_gen.php +++ b/www/vicidial/admin_listloader_fourth_gen.php @@ -71,10 +71,11 @@ # 170219-1427 - Added last-90-day duplicate check options # 170409-1553 - Added IP List validation code # 171001-0908 - Fixed issue #1041 +# 171204-1517 - Fix for custom field duplicate issue, removed link to old lead loader # -$version = '2.14-69'; -$build = '171001-0908'; +$version = '2.14-70'; +$build = '171204-1517'; require("dbconnect_mysqli.php"); require("functions.php"); @@ -762,7 +763,7 @@ if ( (!$OK_to_process) or ( ($leadfile) and ($file_layout!="standard" && $file_l " name='submit_file'>        " name='reload_page'> -                     -     :     :     +             -     :     :     0) { - $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override' and field_duplicate!='Y';"; if ($DB>0) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); $fieldscount_to_print = mysqli_num_rows($rslt); if ($fieldscount_to_print > 0) { - $stmt="SELECT field_label,field_type,field_encrypt from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + $stmt="SELECT field_label,field_type,field_encrypt from vicidial_lists_fields where list_id='$list_id_override' and field_duplicate!='Y' order by field_rank,field_order,field_label;"; if ($DB>0) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); $fields_to_print = mysqli_num_rows($rslt); @@ -2461,7 +2462,7 @@ if (($leadfile) && ($LF_path)) $tablecount_to_print = mysqli_num_rows($rslt); if ($tablecount_to_print > 0) { - $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override' and field_duplicate!='Y';"; if ($DB>0) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); $fieldscount_to_print = mysqli_num_rows($rslt); @@ -2471,7 +2472,7 @@ if (($leadfile) && ($LF_path)) $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,field_encrypt from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + $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,field_encrypt from vicidial_lists_fields where list_id='$list_id_override' and field_duplicate!='Y' order by field_rank,field_order,field_label;"; if ($DB>0) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); $fields_to_print = mysqli_num_rows($rslt); diff --git a/www/vicidial/admin_listloader_third_gen.php b/www/vicidial/admin_listloader_third_gen.php index b3d1898c..def2ebee 100644 --- a/www/vicidial/admin_listloader_third_gen.php +++ b/www/vicidial/admin_listloader_third_gen.php @@ -1,1557 +1 @@ - 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 -# 120525-1037 - Added uploaded filename filtering -# 120529-1347 - Filename filter fix -# 130610-1055 - Finalized changing of all ereg instances to preg -# 130621-1815 - Added filtering of input to prevent SQL injection attacks and new user auth -# 130902-0753 - Changed to mysqli PHP functions -# 170409-1534 - Added IP List validation code -# - -$version = '2.14-49'; -$build = '170409-1534'; - -require("dbconnect_mysqli.php"); -require("functions.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["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_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_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 = preg_replace('/[^0-9a-zA-Z]/', '', $PHP_AUTH_USER); - $PHP_AUTH_PW = preg_replace('/[^0-9a-zA-Z]/', '', $PHP_AUTH_PW); - } -else - { - $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); - $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); - } -$list_id_override = preg_replace('/[^0-9]/','',$list_id_override); - -$STARTtime = date("U"); -$TODAY = date("Y-m-d"); -$NOW_TIME = date("Y-m-d H:i:s"); -$FILE_datetime = $STARTtime; -$date = date("r"); -$ip = getenv("REMOTE_ADDR"); -$browser = getenv("HTTP_USER_AGENT"); - -$auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth < 1) - { - $VDdisplayMESSAGE = "Login incorrect, please try again"; - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = "Too many login attempts, try again in 15 minutes"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - -$stmt="SELECT load_leads,user_group from vicidial_users where user='$PHP_AUTH_USER';"; -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGload_leads = $row[0]; -$LOGuser_group = $row[1]; - -if ($LOGload_leads < 1) - { - Header ("Content-type: text/html; charset=utf-8"); - echo "You do not have permissions to load leads\n"; - exit; - } - -if (preg_match("/;|:|\/|\^|\[|\]|\"|\'|\*/",$LF_orig)) - { - echo "ERROR: Invalid File Name: $LF_orig\n"; - 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_to_mysqli($stmt, $link); -$row=mysqli_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 (!preg_match('/\-ALL/i', $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 (preg_match("/443/i",$server_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -$admDIR = "$HTTPprotocol$server_name$script_name"; -$admDIR = preg_replace('/admin_listloader_third_gen\.php/i', '',$admDIR); -$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_to_mysqli($stmt, $link); -$gmt_recs = mysqli_num_rows($rslt); -if ($gmt_recs > 0) - { - $row=mysqli_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 = preg_replace('/\+/i', '',$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 (preg_match('/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") ) ) - { - ?> -
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
Lead Duplicate Check:
USA-Canada Check:
Lead Time Zone Lookup:
        
        BACK TO ADMIN             LIST LOADER 3rd Gen-     VERSION:     BUILD:    
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Lead file:
List ID Override:
Phone Code Override:
USA-Canada Check:
Lead Duplicate Check:
Lead Time Zone Lookup:
- method=post 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_to_mysqli($stmt, $link); - $tablecount_to_print = mysqli_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_to_mysqli($stmt, $link); - $fieldscount_to_print = mysqli_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_to_mysqli($stmt, $link); - $fields_to_print = mysqli_num_rows($rslt); - $fields_list=''; - $o=0; - while ($fields_to_print > $o) - { - $rowx=mysqli_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, preg_replace('/[\'\"]/i', '', $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 = preg_replace('/[^0-9]/i', '', $row[$phone_code_field]); - $phone_number = preg_replace('/[^0-9]/i', '', $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 = preg_replace('/[^0-9]/i', '', $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 = preg_replace("/$field_regx/i", "", $vendor_lead_code); - $source_code = preg_replace("/$field_regx/i", "", $source_code); - $source_id = preg_replace("/$field_regx/i", "", $source_id); - $list_id = preg_replace("/$field_regx/i", "", $list_id); - $phone_code = preg_replace("/$field_regx/i", "", $phone_code); - $phone_number = preg_replace("/$field_regx/i", "", $phone_number); - $title = preg_replace("/$field_regx/i", "", $title); - $first_name = preg_replace("/$field_regx/i", "", $first_name); - $middle_initial = preg_replace("/$field_regx/i", "", $middle_initial); - $last_name = preg_replace("/$field_regx/i", "", $last_name); - $address1 = preg_replace("/$field_regx/i", "", $address1); - $address2 = preg_replace("/$field_regx/i", "", $address2); - $address3 = preg_replace("/$field_regx/i", "", $address3); - $city = preg_replace("/$field_regx/i", "", $city); - $state = preg_replace("/$field_regx/i", "", $state); - $province = preg_replace("/$field_regx/i", "", $province); - $postal_code = preg_replace("/$field_regx/i", "", $postal_code); - $country_code = preg_replace("/$field_regx/i", "", $country_code); - $gender = preg_replace("/$field_regx/i", "", $gender); - $date_of_birth = preg_replace("/$field_regx/i", "", $date_of_birth); - $alt_phone = preg_replace("/$field_regx/i", "", $alt_phone); - $email = preg_replace("/$field_regx/i", "", $email); - $security_phrase = preg_replace("/$field_regx/i", "", $security_phrase); - $comments = preg_replace("/$field_regx/i", "", $comments); - $rank = preg_replace("/$field_regx/i", "", $rank); - $owner = preg_replace("/$field_regx/i", "", $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] = preg_replace("/$field_regx/i", "", $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 (preg_match("/DUPCAMP/i",$dupcheck)) - { - $dup_lead=0; - $dup_lists=''; - $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; - $rslt=mysql_to_mysqli($stmt, $link); - $ci_recs = mysqli_num_rows($rslt); - if ($ci_recs > 0) - { - $row=mysqli_fetch_row($rslt); - $dup_camp = $row[0]; - - $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; - $rslt=mysql_to_mysqli($stmt, $link); - $li_recs = mysqli_num_rows($rslt); - if ($li_recs > 0) - { - $L=0; - while ($li_recs > $L) - { - $row=mysqli_fetch_row($rslt); - $dup_lists .= "'$row[0]',"; - $L++; - } - $dup_lists = preg_replace('/,$/i', '',$dup_lists); - - $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $dup_lead=1; - $row=mysqli_fetch_row($rslt); - $dup_lead_list = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$phone_number$US$list_id/i", $phone_list)) - {$dup_lead++; $dup++;} - } - } - } - } - - ##### Check for duplicate phone numbers in vicidial_list table entire database ##### - if (preg_match("/DUPSYS/i",$dupcheck)) - { - $dup_lead=0; - $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $dup_lead=1; - $row=mysqli_fetch_row($rslt); - $dup_lead_list = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$phone_number$US$list_id/i", $phone_list)) - {$dup_lead++; $dup++;} - } - } - - ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### - if (preg_match("/DUPLIST/i",$dupcheck)) - { - $dup_lead=0; - $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $row=mysqli_fetch_row($rslt); - $dup_lead = $row[0]; - $dup_lead_list = $list_id; - } - if ($dup_lead < 1) - { - if (preg_match("/$phone_number$US$list_id/i", $phone_list)) - {$dup_lead++; $dup++;} - } - } - - ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### - if (preg_match("/DUPTITLEALTPHONELIST/i",$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_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $row=mysqli_fetch_row($rslt); - $dup_lead = $row[0]; - $dup_lead_list = $list_id; - } - if ($dup_lead < 1) - { - if (preg_match("/$alt_phone$title$US$list_id/i",$phone_list)) - {$dup_lead++; $dup++;} - } - } - - ##### Check for duplicate phone numbers in vicidial_list table entire database ##### - if (preg_match("/DUPTITLEALTPHONESYS/i",$dupcheck)) - { - $dup_lead=0; - $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $dup_lead=1; - $row=mysqli_fetch_row($rslt); - $dup_lead_list = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$alt_phone$title$US$list_id/i",$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_to_mysqli($stmt, $link); - $row=mysqli_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 (preg_match("/TITLEALTPHONE/i",$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_to_mysqli($stmtZ, $link); - $affected_rows = mysqli_affected_rows($link); - $lead_id = mysqli_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_to_mysqli($custom_SQL_query, $link); - $affected_rows = mysqli_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_to_mysqli($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_to_mysqli($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_to_mysqli($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_to_mysqli($stmt, $link); - - - - ##### 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 = preg_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, preg_replace('/[\'\"]/i', '', $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 = preg_replace('/[^0-9]/i', '', $row[3]); - $phone_number = preg_replace('/[^0-9]/i', '', $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 = preg_replace('/[^0-9]/i', '', $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 = preg_replace("/$field_regx/i", "", $vendor_lead_code); - $source_code = preg_replace("/$field_regx/i", "", $source_code); - $source_id = preg_replace("/$field_regx/i", "", $source_id); - $list_id = preg_replace("/$field_regx/i", "", $list_id); - $phone_code = preg_replace("/$field_regx/i", "", $phone_code); - $phone_number = preg_replace("/$field_regx/i", "", $phone_number); - $title = preg_replace("/$field_regx/i", "", $title); - $first_name = preg_replace("/$field_regx/i", "", $first_name); - $middle_initial = preg_replace("/$field_regx/i", "", $middle_initial); - $last_name = preg_replace("/$field_regx/i", "", $last_name); - $address1 = preg_replace("/$field_regx/i", "", $address1); - $address2 = preg_replace("/$field_regx/i", "", $address2); - $address3 = preg_replace("/$field_regx/i", "", $address3); - $city = preg_replace("/$field_regx/i", "", $city); - $state = preg_replace("/$field_regx/i", "", $state); - $province = preg_replace("/$field_regx/i", "", $province); - $postal_code = preg_replace("/$field_regx/i", "", $postal_code); - $country_code = preg_replace("/$field_regx/i", "", $country_code); - $gender = preg_replace("/$field_regx/i", "", $gender); - $date_of_birth = preg_replace("/$field_regx/i", "", $date_of_birth); - $alt_phone = preg_replace("/$field_regx/i", "", $alt_phone); - $email = preg_replace("/$field_regx/i", "", $email); - $security_phrase = preg_replace("/$field_regx/i", "", $security_phrase); - $comments = preg_replace("/$field_regx/i", "", $comments); - $rank = preg_replace("/$field_regx/i", "", $rank); - $owner = preg_replace("/$field_regx/i", "", $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 (preg_match("/DUPCAMP/i",$dupcheck)) - { - $dup_lead=0; - $dup_lists=''; - $stmt="select campaign_id from vicidial_lists where list_id='$list_id';"; - $rslt=mysql_to_mysqli($stmt, $link); - $ci_recs = mysqli_num_rows($rslt); - if ($ci_recs > 0) - { - $row=mysqli_fetch_row($rslt); - $dup_camp = $row[0]; - - $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';"; - $rslt=mysql_to_mysqli($stmt, $link); - $li_recs = mysqli_num_rows($rslt); - if ($li_recs > 0) - { - $L=0; - while ($li_recs > $L) - { - $row=mysqli_fetch_row($rslt); - $dup_lists .= "'$row[0]',"; - $L++; - } - $dup_lists = preg_replace('/,$/i', '',$dup_lists); - - $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $dup_lead=1; - $row=mysqli_fetch_row($rslt); - $dup_lead_list = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$phone_number$US$list_id/i", $phone_list)) - {$dup_lead++; $dup++;} - } - } - } - } - - ##### Check for duplicate phone numbers in vicidial_list table entire database ##### - if (preg_match("/DUPSYS/i",$dupcheck)) - { - $dup_lead=0; - $stmt="select list_id from vicidial_list where phone_number='$phone_number';"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $dup_lead=1; - $row=mysqli_fetch_row($rslt); - $dup_lead_list = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$phone_number$US$list_id/i", $phone_list)) - {$dup_lead++; $dup++;} - } - } - - ##### Check for duplicate phone numbers in vicidial_list table for one list_id ##### - if (preg_match("/DUPLIST/i",$dupcheck)) - { - $dup_lead=0; - $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $row=mysqli_fetch_row($rslt); - $dup_lead = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$phone_number$US$list_id/i", $phone_list)) - {$dup_lead++; $dup++;} - } - } - - ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id ##### - if (preg_match("/DUPTITLEALTPHONELIST/i",$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_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $row=mysqli_fetch_row($rslt); - $dup_lead = $row[0]; - $dup_lead_list = $list_id; - } - if ($dup_lead < 1) - { - if (preg_match("/$alt_phone$title$US$list_id/i",$phone_list)) - {$dup_lead++; $dup++;} - } - } - - ##### Check for duplicate phone numbers in vicidial_list table entire database ##### - if (preg_match("/DUPTITLEALTPHONESYS/i",$dupcheck)) - { - $dup_lead=0; - $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';"; - $rslt=mysql_to_mysqli($stmt, $link); - $pc_recs = mysqli_num_rows($rslt); - if ($pc_recs > 0) - { - $dup_lead=1; - $row=mysqli_fetch_row($rslt); - $dup_lead_list = $row[0]; - } - if ($dup_lead < 1) - { - if (preg_match("/$alt_phone$title$US$list_id/i",$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_to_mysqli($stmt, $link); - $row=mysqli_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 (preg_match("/TITLEALTPHONE/i",$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_to_mysqli($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_to_mysqli($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_to_mysqli($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 - { - 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_to_mysqli($stmt, $link); - $tablecount_to_print = mysqli_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_to_mysqli($stmt, $link); - $fieldscount_to_print = mysqli_num_rows($rslt); - if ($fieldscount_to_print > 0) - { - $rowx=mysqli_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_to_mysqli($stmt, $link); - $fields_to_print = mysqli_num_rows($rslt); - $fields_list=''; - $o=0; - while ($fields_to_print > $o) - { - $rowx=mysqli_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_to_mysqli("$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 = preg_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, preg_replace('/[\'\"]/i', '', $buffer)); - - while ($fieldinfo=mysqli_fetch_field($rslt)) - { - $rslt_field_name=$fieldinfo->name; - if ( ($rslt_field_name=="list_id" and $list_id_override!="") or ($rslt_field_name=="phone_code" and $phone_code_override!="") ) - { - print "\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(preg_replace('/_/i', ' ', $rslt_field_name)).":
        
\r\n"; - - print ""; - } - ##### END field chooser ##### - - } - -?> - - - +this file has been removed \ No newline at end of file diff --git a/www/vicidial/leadloader_template_display.php b/www/vicidial/leadloader_template_display.php index 0735e2ac..ed7f8081 100644 --- a/www/vicidial/leadloader_template_display.php +++ b/www/vicidial/leadloader_template_display.php @@ -16,6 +16,7 @@ # 141229-2021 - Added code for on-the-fly language translations display # 150210-0619 - Fixed small display issue # 170409-1534 - Added IP List validation code +# 171204-1518 - Fix for custom field duplicate issue, removed link to old lead loader # require("dbconnect_mysqli.php"); @@ -280,7 +281,7 @@ else $tablecount_to_print = mysqli_num_rows($rslt); if ($tablecount_to_print > 0) { - $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id';"; + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id' and field_duplicate!='Y';"; if ($DB>0) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); $fieldscount_to_print = mysqli_num_rows($rslt); @@ -290,7 +291,7 @@ else $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' order by field_rank,field_order,field_label;"; + $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' and field_duplicate!='Y' order by field_rank,field_order,field_label;"; if ($DB>0) {echo "$stmt\n";} $rslt=mysql_to_mysqli($stmt, $link); $fields_to_print = mysqli_num_rows($rslt);