From f11a1df1f77977ed00cab95f75e5b57c0a620dd2 Mon Sep 17 00:00:00 2001 From: mattf Date: Mon, 5 Jul 2010 23:39:00 +0000 Subject: [PATCH] Added ability to load lead data into custom fields of lists using the web-based lead loader, only works with CSV and TXT files, and you must use a list ID override and select Custom Format. git-svn-id: svn://192.168.202.10@1471 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 9 +- www/vicidial/new_listloader_superL.php | 299 ++++++++++++++++++++++--- 2 files changed, 268 insertions(+), 40 deletions(-) diff --git a/UPGRADE b/UPGRADE index eb52c1f6..ba7f1bfd 100644 --- a/UPGRADE +++ b/UPGRADE @@ -180,10 +180,11 @@ OTHER CHANGES: in a new tab in the agent interface, and there is a new option to have the Get Call Launch open this custom fields tab upon a call being sent to the agent. Also, the Calls Export Report and the List Download - feature include the custom fields values for the leads exported. There - is currently no way to import data through the lead loader into custom - fields, but you can import custom field data when using the non-agent - API add_lead function(see the NON-AGENT_API.txt doc for more info). + feature include the custom fields values for the leads exported. You + can import custom field data through the web-based lead loader in TXT + and CSV format(you must set a list ID override and you must select + Custom Format). You can also use the non-agent API add_lead function, + (see the NON-AGENT_API.txt doc for more info). 44. Added more options to agi-AGENT_route.agi to allow it to prompt for user IDs as well as set the number of digits to collect and check whether a user diff --git a/www/vicidial/new_listloader_superL.php b/www/vicidial/new_listloader_superL.php index 2ddb4f1f..8f736383 100644 --- a/www/vicidial/new_listloader_superL.php +++ b/www/vicidial/new_listloader_superL.php @@ -32,11 +32,12 @@ # 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 # # make sure vicidial_list exists and that your file follows the formatting correctly. This page does not dedupe or do any other lead filtering actions yet at this time. -$version = '2.2.0-35'; -$build = '100621-1026'; +$version = '2.4-36'; +$build = '100705-1507'; require("dbconnect.php"); @@ -129,16 +130,19 @@ if (isset($_GET["postalgmt"])) {$postalgmt=$_GET["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"];} # $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|'; ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,admin_web_directory FROM system_settings;"; +$stmt = "SELECT use_non_latin,admin_web_directory,custom_fields_enabled FROM system_settings;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $qm_conf_ct = mysql_num_rows($rslt); @@ -147,6 +151,7 @@ if ($qm_conf_ct > 0) $row=mysql_fetch_row($rslt); $non_latin = $row[0]; $admin_web_directory = $row[1]; + $custom_fields_enabled = $row[2]; } ##### END SETTINGS LOOKUP ##### ########################################### @@ -352,6 +357,7 @@ echo "
";
method=post onSubmit="ParseFileName()" enctype="multipart/form-data"> + @@ -510,6 +516,69 @@ echo "
"; $phone_code = $phone_code_override; } + ##### BEGIN custom fields columns list ### + $custom_SQL=''; + if ($custom_fields_enabled > 0) + { + $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $tablecount_to_print = mysql_num_rows($rslt); + if ($tablecount_to_print > 0) + { + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fieldscount_to_print = mysql_num_rows($rslt); + if ($fieldscount_to_print > 0) + { + $rowx=mysql_fetch_row($rslt); + $custom_records_count = $rowx[0]; + + $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fields_to_print = mysql_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysql_fetch_row($rslt); + $A_field_label[$o] = $rowx[1]; + $A_field_type[$o] = $rowx[6]; + $A_field_value[$o] = ''; + + $field_name_id = $A_field_label[$o] . "_field"; + + if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";} + + if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') ) + { + if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) + { + if (isset($_GET["$field_name_id"])) {$form_field_value=$_GET["$field_name_id"];} + elseif (isset($_POST["$field_name_id"])) {$form_field_value=$_POST["$field_name_id"];} + + if ($form_field_value >= 0) + { + $A_field_value[$o] = $row[$form_field_value]; + # replace ' " ` \ ; with nothing + $A_field_value[$o] = eregi_replace($field_regx, "", $A_field_value[$o]); + + $custom_SQL .= "$A_field_label[$o]='$A_field_value[$o]',"; + } + } + } + $o++; + } + } + } + } + ##### END custom fields columns list ### + + $custom_SQL = preg_replace("/,$/","",$custom_SQL); + + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### if (eregi("DUPCAMP",$dupcheck)) { @@ -647,19 +716,40 @@ echo "
"; $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code); - 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) 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');"; + 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) 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');"; $rslt=mysql_query($stmtZ, $link); + $affected_rows = mysql_affected_rows($link); + $lead_id = mysql_insert_id($link); + if ($DB > 0) {echo "";} if ($WeBRooTWritablE > 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'),"; - $multi_insert_counter++; - } + $custom_SQL_query = "INSERT INTO custom_$list_id_override SET lead_id='$lead_id',$custom_SQL;"; + $rslt=mysql_query($custom_SQL_query, $link); + $affected_rows = mysql_affected_rows($link); + if ($DB > 0) {echo "";} + } + else + { + if ($multi_insert_counter > 8) + { + ### insert good record into vicidial_list table ### + $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner) 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');"; + $rslt=mysql_query($stmtZ, $link); + if ($WeBRooTWritablE > 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'),"; + $multi_insert_counter++; + } + } $good++; } else { @@ -801,20 +891,82 @@ echo "
"; $owner = eregi_replace($field_regx, "", $owner); $USarea = substr($phone_number, 0, 3); - - - if (strlen($rank)<1) {$rank='0';} - if (strlen($list_id_override)>0) + if (strlen($rank)<1) {$rank='0';} + + if (strlen($list_id_override)>0) + { + $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) { - $list_id = $list_id_override; - } - if (strlen($phone_code_override)>0) - { - $phone_code = $phone_code_override; - } + $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $tablecount_to_print = mysql_num_rows($rslt); + if ($tablecount_to_print > 0) + { + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fieldscount_to_print = mysql_num_rows($rslt); + if ($fieldscount_to_print > 0) + { + $rowx=mysql_fetch_row($rslt); + $custom_records_count = $rowx[0]; + $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fields_to_print = mysql_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysql_fetch_row($rslt); + $A_field_label[$o] = $rowx[1]; + $A_field_type[$o] = $rowx[6]; + $A_field_value[$o] = ''; + + $field_name_id = $A_field_label[$o] . "_field"; + + if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";} + + if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') ) + { + if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) + { + if (isset($_GET["$field_name_id"])) {$form_field_value=$_GET["$field_name_id"];} + elseif (isset($_POST["$field_name_id"])) {$form_field_value=$_POST["$field_name_id"];} + + if ($form_field_value >= 0) + { + $A_field_value[$o] = $row[$form_field_value]; + # replace ' " ` \ ; with nothing + $A_field_value[$o] = eregi_replace($field_regx, "", $A_field_value[$o]); + + $custom_SQL .= "$A_field_label[$o]='$A_field_value[$o]',"; + } + } + } + $o++; + } + } + } + } + ##### END custom fields columns list ### + + $custom_SQL = preg_replace("/,$/","",$custom_SQL); + + ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign ##### if (eregi("DUPCAMP",$dupcheck)) { @@ -952,20 +1104,40 @@ echo "
"; $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code); - 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) 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');"; - $rslt=mysql_query($stmtZ, $link); - if ($WeBRooTWritablE > 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'),"; - $multi_insert_counter++; - } + 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) 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');"; + $rslt=mysql_query($stmtZ, $link); + $affected_rows = mysql_affected_rows($link); + $lead_id = mysql_insert_id($link); + if ($DB > 0) {echo "";} + if ($WeBRooTWritablE > 0) + {fwrite($stmt_file, $stmtZ."\r\n");} + $multistmt=''; + $custom_SQL_query = "INSERT INTO custom_$list_id_override SET lead_id='$lead_id',$custom_SQL;"; + $rslt=mysql_query($custom_SQL_query, $link); + $affected_rows = mysql_affected_rows($link); + if ($DB > 0) {echo "";} + } + else + { + if ($multi_insert_counter > 8) + { + ### insert good 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) 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');"; + $rslt=mysql_query($stmtZ, $link); + if ($WeBRooTWritablE > 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'),"; + $multi_insert_counter++; + } + } $good++; } else { if ($bad < 1000000) @@ -1626,6 +1798,7 @@ if ($leadfile) { print ""; } else { + ##### BEGIN field chooser ##### print "
"; flush(); print "\r\n"; @@ -1634,8 +1807,60 @@ if ($leadfile) { print " \r\n"; print " \r\n"; - $rslt=mysql_query("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", $link); - + $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner from vicidial_list limit 1"; + + ##### BEGIN custom fields columns list ### + if ($custom_fields_enabled > 0) + { + $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $tablecount_to_print = mysql_num_rows($rslt); + if ($tablecount_to_print > 0) + { + $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fieldscount_to_print = mysql_num_rows($rslt); + if ($fieldscount_to_print > 0) + { + $rowx=mysql_fetch_row($rslt); + $custom_records_count = $rowx[0]; + + $custom_SQL=''; + $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;"; + if ($DB>0) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $fields_to_print = mysql_num_rows($rslt); + $fields_list=''; + $o=0; + while ($fields_to_print > $o) + { + $rowx=mysql_fetch_row($rslt); + $A_field_label[$o] = $rowx[1]; + $A_field_type[$o] = $rowx[6]; + + if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";} + + if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') ) + { + if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields)) + { + $custom_SQL .= ",$A_field_label[$o]"; + } + } + $o++; + } + + $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner $custom_SQL from vicidial_list, custom_$list_id_override limit 1"; + + } + } + } + ##### END custom fields columns list ### + + + $rslt=mysql_query("$fields_stmt", $link); if (!eregi(".csv", $leadfile_name) && !eregi(".xls", $leadfile_name)) { @@ -1779,6 +2004,8 @@ if ($leadfile) { print "
File data
\r\n"; # } print ""; + + ##### END field chooser ##### } #} else if (filesize($leadfile)>8388608) { # print "
ERROR: File exceeds the 8MB limit.
";