Project

General

Profile

Bug #7980 » goUploadMe.php

Enzo Zazzaro, 04/10/2020 11:58 AM

 
1
<?php
2
 /**
3
 * @file 		goUploadMe.php
4
 * @brief 		API for Uploading Leads
5
 * @copyright 	Copyright (C) GOautodial Inc.
6
 * @author		Jericho James Milo  <james@goautodial.com>
7
 * @author     	Chris Lomuntad  <chris@goautodial.com>
8
 *
9
 * @par <b>License</b>:
10
 *  This program is free software: you can redistribute it and/or modify
11
 *  it under the terms of the GNU Affero General Public License as published by
12
 *  the Free Software Foundation, either version 3 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Affero General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU Affero General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
*/
23
	include_once ("goAPI.php");
24

    
25
	ini_set('memory_limit','1024M');
26
	ini_set('upload_max_filesize', '600M');
27
	ini_set('post_max_size', '600M');
28
        ini_set('max_execution_time', 0);
29
	
30
	$thefile = $_FILES['goFileMe']['tmp_name'];
31
	$theList = $astDB->escape($_REQUEST["goListId"]);
32
	$goDupcheck = $astDB->escape($_REQUEST["goDupcheck"]);
33
	$goCountInsertedLeads = 0;
34
	$default_delimiter = ";";
35
	$phone_code_override = $astDB->escape($_REQUEST["phone_code_override"]);
36
	
37
	$lead_mapping = NULL;
38
	if(!empty($_REQUEST["lead_mapping"]))	
39
		$lead_mapping = $astDB->escape($_REQUEST["lead_mapping"]);
40

    
41
	$alex = array();
42
	$goGetCheckcustomFieldNamesCorrect = ""; //constant
43
	
44
	// path where your CSV file is located
45
	define('CSV_PATH','/tmp/');
46

    
47
	// Name of your CSV file
48
	//$csv_file = CSV_PATH . "$thefile"; 
49
	$csv_file = $thefile;
50

    
51
	// REPLACE DELIMITER to SEMI-COLON -- CUSTOMIZATION!!!!!
52
        if(!empty($_REQUEST["custom_delimiter"]) && isset($_REQUEST["custom_delimiter"])){
53
           //$default_delimiter = $_REQUEST["custom_delimiter"];
54
		
55
	   $delimiters = explode(" ", $_REQUEST["custom_delimiter"]);
56
           $str = file_get_contents($csv_file);
57
           $str1 = str_replace($delimiters, $default_delimiter, $str);
58
           file_put_contents($csv_file, $str1);
59
        }
60

    
61
	// REGEX to prevent weird characters from ending up in the fields
62
        $field_regx = "/['\"`\\;]/";
63
        $field_regx = str_replace($delimiters, "", $field_regx);
64

    
65
	$duplicates = 0;
66

    
67
	//die($theList."<br>".$thefile."<br>".$csv_file);
68
	if (($handle = fopen($csv_file, "r")) !== FALSE) {
69
		$getHeder = fgetcsv($handle);
70
		//$goInsertSuccess = 0;
71
		//$array 21 last column
72
		
73
		//for custom fields start GLOBAL varaibles
74
		$goCountTheHeader = count($getHeder);
75
		
76
		if($goCountTheHeader > 21 && !empty($lead_mapping)) {
77
			for($x=21; $x < count($getHeder); $x++) {
78
				$goGetLastHeader .= $x.","; #get digits for specific data
79
				$goGetLastCustomFiledsName .= $getHeder[$x].","; #get the digits for specific custom field
80
			}
81
			
82
			$goGetLastHeader = preg_replace("/,$/",'',$goGetLastHeader);
83
			$goGetLastHeader2 = explode(",",$goGetLastHeader);
84
			$goGetLastCustomFiledsName = preg_replace("/,$/",'',$goGetLastCustomFiledsName);
85
			$goGetLastCustomFiledsName2 = explode(",",$goGetLastCustomFiledsName);
86
				
87
		} elseif($goCountTheHeader > 21) {
88
			for($x=21; $x < count($getHeder); $x++) {
89
				$goGetLastHeader .= $x.","; #get digits for specific data
90
				$goGetLastCustomFiledsName .= $getHeder[$x].","; #get the digits for specific custom field
91
			}
92
			
93
			$goGetLastHeader = preg_replace("/,$/",'',$goGetLastHeader);
94
			$goGetLastHeader2 = explode(",",$goGetLastHeader);
95
			
96
			$goGetLastCustomFiledsName = preg_replace("/,$/",'',$goGetLastCustomFiledsName);
97
			$goGetLastCustomFiledsName2 = explode(",",$goGetLastCustomFiledsName);
98
			
99
			# check custom field names are correct
100
			$goGetLastCustomFiledsNameWithLeadID = "lead_id,".$goGetLastCustomFiledsName;
101
			$goGetCheckcustomFieldNamesCorrect = goCheckCustomFieldsName($astDB, $theList, $goGetLastCustomFiledsNameWithLeadID);
102
			
103
			if($goGetCheckcustomFieldNamesCorrect === "error") {
104
				fclose($handle);
105
			}
106
		}
107
		//end for custom fields start GLOBAL varaibles
108
		
109
		
110
		while (($data = fgetcsv($handle, 1000, $default_delimiter)) !== FALSE) {
111
			$num = count($data);
112
			for ($c=0; $c < $num; $c++) {
113
				$col[$c] = $data[$c];
114
			}
115
			# REGEX to prevent weird characters from ending up in the fields
116
			$field_regx = "/['\"`\\;]/";
117
			
118
			# SQL Query to insert data into DataBase
119
			$entry_date = date("Y-m-d H:i:s");
120
			$status = "NEW";
121
			$vendor_lead_code = preg_replace($field_regx, "", $col[1]);
122
			$list_id = $theList;
123
			$gmt_offset = "0";
124
			// PHONE CODE OVERRIDE
125
			if(!empty($phone_code_override))
126
				$phone_code = "39";
127
			else
128
			$phone_code = "39";
129
			$phone_number = preg_replace($field_regx, "", $col[0]);
130
			$title = preg_replace($field_regx, "", $col[3]);
131
			$first_name = preg_replace($field_regx, "", $col[4]);
132
			$middle_initial = preg_replace($field_regx, "", $col[5]);
133
			$last_name = preg_replace($field_regx, "", $col[6]);
134
			$address1 = preg_replace($field_regx, "", $col[7]);
135
			$address2 = preg_replace($field_regx, "", $col[8]);
136
			$address3 = preg_replace($field_regx, "", $col[9]);
137
			$city = preg_replace($field_regx, "", $col[10]);
138
			$state = preg_replace($field_regx, "", $col[11]);
139
			$province = preg_replace($field_regx, "", $col[12]);
140
			$postal_code = preg_replace($field_regx, "", $col[13]);
141
			$country_code = preg_replace($field_regx, "", $col[14]);
142
			$gender = preg_replace($field_regx, "", $col[15]);
143
			$date_of_birth = preg_replace($field_regx, "", $col[16]);
144
			$date_of_birth = date("Y-m-d", strtotime($date_of_birth));
145
			$alt_phone = preg_replace($field_regx, "", $col[17]);
146
			$email = preg_replace($field_regx, "", $col[18]);
147
			$security_phrase = preg_replace($field_regx, "", $col[19]);
148
			$comments = preg_replace($field_regx, "", $col[20]);
149
			$entry_list_id = 0;
150
			$called_since_last_reset = "N";
151
			
152
			// LEAD MAPPING -- CUSTOMIZATION!!!!!
153
			if(!empty($lead_mapping)){
154
				$lead_mapping_data = explode(",",$_REQUEST["lead_mapping_data"]);
155
				$lead_mapping_fields = explode(",", $_REQUEST["lead_mapping_fields"]);
156
				
157
				$standard_fields = array("Phone","VendorLeadCode","PhoneCode","Title","FirstName","MiddleInitial","LastName","Address1","Address2","Address3","City","State","Province","PostalCode","CountryCode","Gender","DateOfBirth","AltPhone","Email","SecurityPhrase","Comments");
158
			
159

    
160
				
161

    
162

    
163
				// MAKE MAP FIELDS AN INDEX OF MAP DATA & SEPARATE STANDARD FROM CUSTOM ARRAYS
164

    
165
				for($l=0; $l < count($lead_mapping_fields);$l++){
166
					if(in_array($lead_mapping_fields[$l], $standard_fields))
167
						$standard_array[$lead_mapping_fields[$l]] = $lead_mapping_data[$l];
168
					else
169
						$custom_array[$lead_mapping_fields[$l]] = $lead_mapping_data[$l];
170
				}
171
				//set default values to none
172
				$phone_number = "";
173
                                        $vendor_lead_code = "";
174
				if(!empty($phone_code_override))
175
				$phone_code = "39";
176
				else
177
                                        $phone_code = 39;
178
				$log = $phone_code_override;
179
                                        $title = "";
180
                                        $first_name = "";
181
                                        $middle_initial = "";
182
                                        $last_name = "";
183
                                        $address1 = "";
184
                                        $address2 = "";
185
                                        $address3 = "";
186
                                        $city = "";
187
                                        $state = "";
188
                                        $province = "";
189
                                        $postal_code = "";
190
                                        $country_code = "";
191
                                        $gender = "";
192
                                        $date_of_birth = "";
193
                                        $alt_phone = "";
194
                                        $email = "";
195
                                        $security_phrase = "";
196
                                        $comments = "";				
197
				
198
				//get arrayed lead mapping requests
199
				foreach($standard_array as $l => $map_data){
200
					//$logthis[] = $map_data;
201
					if($map_data !== "" || $map_data !== "."){
202
						// one by one sort through columns to overwrite lead mapping data
203
						if($l == "Phone")
204
                                                                $phone_number = $col[$map_data];
205
                                                        if($l == "VendorLeadCode")
206
                                                                $vendor_lead_code = $col[$map_data];
207
                                                        if($l == "PhoneCode"){
208
                                                                if(!empty($phone_code_override))
209
																$phone_code = "39";
210
                                                                else
211
                                                                $phone_code = "39";
212
                                                        }if($l == "Title")
213
                                                                $title = $col[$map_data];
214
                                                        if($l == "FirstName")
215
                                                                $first_name = $col[$map_data];
216
                                                        if($l == "MiddleInitial")
217
                                                                $middle_initial = $col[$map_data];
218
                                                        if($l == "LastName")
219
                                                                $last_name = $col[$map_data];
220
                                                        if($l == "Address1")
221
                                                                $address1 = $col[$map_data];
222
                                                        if($l == "Address2")
223
                                                                $address2 = $col[$map_data];
224
                                                        if($l == "Address3")
225
                                                                $address3 = $col[$map_data];
226
                                                        if($l == "City")
227
                                                                $city = $col[$map_data];
228
                                                         if($l == "State")
229
                                                                $state = $col[$map_data];
230
                                                        if($l == "Province")
231
                                                                $province = $col[$map_data];
232
                                                        if($l == "PostalCode")
233
                                                                $postal_code = $col[$map_data];
234
                                                        if($l == "CountryCode")
235
                                                                $country_code = $col[$map_data];
236
                                                        if($l == "Gender")
237
                                                                $gender = $col[$map_data];
238
                                                        if($l == "DateOfBirth")
239
                                                                $date_of_birth = $col[$map_data];
240
                                                        if($l == "AltPhone")
241
                                                                $alt_phone = $col[$map_data];
242
                                                        if($l == "Email")
243
                                                                $email = $col[$map_data];
244
                                                        if($l == "SecurityPhrase")
245
                                                                $security_phrase = $col[$map_data];
246
                                                        if($l == "Comments")
247
                                                                $comments = $col[$map_data];
248
					}// end if
249
				}// end loop
250
			} // END OF LEAD MAPPING
251
			
252

    
253
			if($goDupcheck === "DUPSYS"){ // Duplicate check all phone numbers in entire system
254
				if($goGetCheckcustomFieldNamesCorrect == "error" && empty($lead_mapping)) {
255
                                        fclose($handle);
256
                                } else {
257
					//check in vicidial_list
258
					$astDB->where('phone_number', $phone_number);
259
					$resultCheckPhone = $astDB->getOne('vicidial_list', 'phone_number');
260
					$countCheck1 = $astDB->getRowCount();
261
					
262
					//check in vicidial_dnc
263
					$astDB->where('phone_number', $phone_number);
264
                                        $resultCheckPhone = $astDB->getOne('vicidial_dnc', 'phone_number');
265
                                        $countCheck2 = $astDB->getRowCount();
266

    
267
					if($countCheck1 < 1 && $countCheck2 < 1){
268
						$USarea = substr($phone_number, 0, 3);
269
                                                $gmt_offset = lookup_gmt($astDB, $phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
270
                                                $insertData = array(
271
                                                        'lead_id' => '',
272
                                                        'entry_date' => $entry_date,
273
                                                        'status' => $status,
274
                                                        'vendor_lead_code' => $vendor_lead_code,
275
                                                        'list_id' => $list_id,
276
                                                        'gmt_offset_now' => $gmt_offset,
277
                                                        'phone_code' => $phone_code,
278
                                                        'phone_number' => $phone_number,
279
                                                        'title' => $title,
280
                                                        'first_name' => utf8_encode($first_name),
281
                                                        'middle_initial' => utf8_encode($middle_initial),
282
                                                        'last_name' => utf8_encode($last_name),
283
                                                        'address1' => $address1,
284
                                                        'address2' => $address2,
285
                                                        'address3' => $address3,
286
                                                        'city' => $city,
287
                                                        'state' => $state,
288
                                                        'province' => $province,
289
                                                        'postal_code' => $postal_code,
290
                                                        'country_code' => $country_code,
291
                                                        'gender' => $gender,
292
                                                        'date_of_birth' => $date_of_birth,
293
                                                        'alt_phone' => $alt_phone,
294
                                                        'email' => $email,
295
                                                        'security_phrase' => $security_phrase,
296
                                                        'comments' => $comments,
297
                                                        'entry_list_id' => $entry_list_id,
298
                                                        'last_local_call_time' => '0000-00-00 00:00:00'
299
												);
300
												//TOGLIAMO I NUMERI IN DB E LI SOSTIUIAMO
301
												$deleteQueryLeads = "DELETE FROM vicidial_list WHERE phone_number='$phone_number';"; 
302
												$deleteResultLeads = $astDB->rawQuery($deleteQueryLeads);
303

    
304
                                                $insertQuery = $astDB->insert('vicidial_list', $insertData);
305
                                                $goLastInsertedLeadIDDUPSYS = $astDB->getInsertId();
306
                                                
307
                                                # start set query for custom fields
308
                                                if(!empty($lead_mapping)){ // LEAD MAPPING CUSTOMIZATION
309
                                                        $goCustomKeyData = array();
310
                                                        $goCustomValuesData = array();
311
                                                        $goCustomUpdateData = array();
312

    
313
                                                        foreach($custom_array as $custom_key => $map_data){
314
                                                                $goCustomValues = $col[$map_data];
315
								array_push($goCustomKeyData, "$custom_key");
316
                                                                array_push($goCustomValuesData, "'$goCustomValues'");
317
                                                                array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
318
                                                        }
319

    
320
                                                        $custom_keyValues = implode(",", $goCustomKeyData);
321
                                                        $goCustomValues = implode(",", $goCustomValuesData);
322
                                                        $goCustomUpdate = implode(", ",  $goCustomUpdateData);
323

    
324
                                                        $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_keyValues) 
325
										VALUES('$goLastInsertedLeadIDDUPSYS', $goCustomValues) 
326
										ON DUPLICATE KEY UPDATE $goCustomUpdate";
327
                                                        $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
328

    
329
                                                }elseif($goCountTheHeader > 21) {
330
                                                        $goShowCustomFields = "DESC custom_$list_id;";
331
                                                        $rsltgoShowCustomFields = $astDB->rawQuery($goShowCustomFields);
332
                                                        $countResultrsltgoShowCustomFields = $astDB->getRowCount();
333

    
334
                                                        if($countResultrsltgoShowCustomFields > 1) {
335
                                                                $totalExplode = count($goGetLastHeader2);
336

    
337
                                                                $goCustomValuesData = array();
338
                                                                $goCustomUpdateData = array();
339

    
340
                                                                for($ax=0; $ax < $totalExplode; $ax++) {
341
                                                                        $goHeaderOfCustomFields = $goGetLastCustomFiledsName2[$ax]; #get the header name of the custom fields
342
                                                                        $goCustomValues = $col[$goGetLastHeader2[$ax]]; #get the values of the custom fields
343
                                                                        array_push($goCustomValuesData, "'$goCustomValues'");
344
                                                                        array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
345

    
346
                                                                }
347
                                                                $goHeaderOfCustomFields = implode(",", $goGetLastCustomFiledsName2);
348
                                                                $goCustomValues = implode(",", $goCustomValuesData);
349
                                                                $goCustomUpdate = implode(", ",  $goCustomUpdateData);
350
                                                                $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) 
351
											VALUES('$goLastInsertedLeadIDDUPSYS', $goCustomValues) 
352
											ON DUPLICATE KEY UPDATE $goCustomUpdate";
353
                                                                $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
354
                                                        }
355
						}// end set query for custom fields
356
						$goCountInsertedLeads++;						
357
					}else{
358
						$duplicates++;
359
					}
360
				}// end else dupsys
361

    
362

    
363

    
364
			}
365
			
366
			//MIO CODICE
367
			//SALE = VENDITA CBHOLD = RICHIAMO
368
			if($goDupcheck === "DUPBLOCK"){ // Duplicate check all phone numbers in entire system
369
				if($goGetCheckcustomFieldNamesCorrect == "error" && empty($lead_mapping)) {
370
                                        fclose($handle);
371
                                } else {
372
					//check in vicidial_list
373
					$status_check="SALE,CBHOLD";
374
					$status_check = preg_replace("/,$/",'',$status_check);
375
					$astDB->where('phone_number', $phone_number);
376
					$astDB->where('status', explode(',', $status_check), 'in');
377
					$resultCheckPhone = $astDB->getOne('vicidial_list', 'phone_number');
378
					$countCheck1 = $astDB->getRowCount();
379
/*
380
					$countQueryLeads = "select lead_id FROM vicidial_list WHERE phone_number='$phone_number' and status not in ('SALE','CBHOLD');"; 
381
					$countCheck1 = $astDB->rawQuery($countQueryLeads);
382
*/					
383
					//check in vicidial_dnc
384
					$astDB->where('phone_number', $phone_number);
385
                                        $resultCheckPhone = $astDB->getOne('vicidial_dnc', 'phone_number');
386
                                        $countCheck2 = $astDB->getRowCount();
387

    
388
					if($countCheck1 < 1 && $countCheck2 < 1){
389
						$USarea = substr($phone_number, 0, 3);
390
                                                $gmt_offset = lookup_gmt($astDB, $phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
391
                                                $insertData = array(
392
                                                        'lead_id' => '',
393
                                                        'entry_date' => $entry_date,
394
                                                        'status' => $status,
395
                                                        'vendor_lead_code' => $vendor_lead_code,
396
                                                        'list_id' => $list_id,
397
                                                        'gmt_offset_now' => $gmt_offset,
398
                                                        'phone_code' => $phone_code,
399
                                                        'phone_number' => $phone_number,
400
                                                        'title' => $title,
401
                                                        'first_name' => utf8_encode($first_name),
402
                                                        'middle_initial' => utf8_encode($middle_initial),
403
                                                        'last_name' => utf8_encode($last_name),
404
                                                        'address1' => $address1,
405
                                                        'address2' => $address2,
406
                                                        'address3' => $address3,
407
                                                        'city' => $city,
408
                                                        'state' => $state,
409
                                                        'province' => $province,
410
                                                        'postal_code' => $postal_code,
411
                                                        'country_code' => $country_code,
412
                                                        'gender' => $gender,
413
                                                        'date_of_birth' => $date_of_birth,
414
                                                        'alt_phone' => $alt_phone,
415
                                                        'email' => $email,
416
                                                        'security_phrase' => $security_phrase,
417
                                                        'comments' => $comments,
418
                                                        'entry_list_id' => $entry_list_id,
419
                                                        'last_local_call_time' => '0000-00-00 00:00:00'
420
												);
421
												//TOGLIAMO I NUMERI IN DB E LI SOSTIUIAMO
422
												$deleteQueryLeads = "DELETE FROM vicidial_list WHERE phone_number='$phone_number';"; 
423
												$deleteResultLeads = $astDB->rawQuery($deleteQueryLeads);
424

    
425
                                                $insertQuery = $astDB->insert('vicidial_list', $insertData);
426
                                                $goLastInsertedLeadIDDUPBLOCK = $astDB->getInsertId();
427
                                                
428
                                                # start set query for custom fields
429
                                                if(!empty($lead_mapping)){ // LEAD MAPPING CUSTOMIZATION
430
                                                        $goCustomKeyData = array();
431
                                                        $goCustomValuesData = array();
432
                                                        $goCustomUpdateData = array();
433

    
434
                                                        foreach($custom_array as $custom_key => $map_data){
435
                                                                $goCustomValues = $col[$map_data];
436
								array_push($goCustomKeyData, "$custom_key");
437
                                                                array_push($goCustomValuesData, "'$goCustomValues'");
438
                                                                array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
439
                                                        }
440

    
441
                                                        $custom_keyValues = implode(",", $goCustomKeyData);
442
                                                        $goCustomValues = implode(",", $goCustomValuesData);
443
                                                        $goCustomUpdate = implode(", ",  $goCustomUpdateData);
444

    
445
                                                        $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_keyValues) 
446
										VALUES('$goLastInsertedLeadIDDUPBLOCK', $goCustomValues) 
447
										ON DUPLICATE KEY UPDATE $goCustomUpdate";
448
                                                        $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
449

    
450
                                                }elseif($goCountTheHeader > 21) {
451
                                                        $goShowCustomFields = "DESC custom_$list_id;";
452
                                                        $rsltgoShowCustomFields = $astDB->rawQuery($goShowCustomFields);
453
                                                        $countResultrsltgoShowCustomFields = $astDB->getRowCount();
454

    
455
                                                        if($countResultrsltgoShowCustomFields > 1) {
456
                                                                $totalExplode = count($goGetLastHeader2);
457

    
458
                                                                $goCustomValuesData = array();
459
                                                                $goCustomUpdateData = array();
460

    
461
                                                                for($ax=0; $ax < $totalExplode; $ax++) {
462
                                                                        $goHeaderOfCustomFields = $goGetLastCustomFiledsName2[$ax]; #get the header name of the custom fields
463
                                                                        $goCustomValues = $col[$goGetLastHeader2[$ax]]; #get the values of the custom fields
464
                                                                        array_push($goCustomValuesData, "'$goCustomValues'");
465
                                                                        array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
466

    
467
                                                                }
468
                                                                $goHeaderOfCustomFields = implode(",", $goGetLastCustomFiledsName2);
469
                                                                $goCustomValues = implode(",", $goCustomValuesData);
470
                                                                $goCustomUpdate = implode(", ",  $goCustomUpdateData);
471
                                                                $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) 
472
											VALUES('$goLastInsertedLeadIDDUPBLOCK', $goCustomValues) 
473
											ON DUPLICATE KEY UPDATE $goCustomUpdate";
474
                                                                $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
475
                                                        }
476
						}// end set query for custom fields
477
						$goCountInsertedLeads++;						
478
					}else{
479
						$duplicates++;
480
					}
481
				}// end else DUPBLOCK
482

    
483

    
484

    
485
			}
486
			
487
			elseif($goDupcheck == "DUPCAMP") {
488
				#Duplicate check all LIST in CAMPAIGN
489
				if($goGetCheckcustomFieldNamesCorrect == "error" && empty($lead_mapping)) {
490
					fclose($handle);
491
				} else {
492
					//$goQueryCheckDupPhone = "SELECT campaign_id, list_id FROM vicidial_lists WHERE list_id='$list_id';";
493
						$astDB->where('list_id', $list_id);
494
						$rsltCheckDupPhone = $astDB->get('vicidial_lists', null, 'campaign_id');
495
						$countResult = $astDB->getRowCount();
496
						
497
						if($countResult > 0) {
498
							foreach ($rsltCheckDupPhone as $fresults){
499
								$goCampaignID = $fresults['campaign_id'];								
500
								$goReturnCampList = goGetCampaignList($astDB, $goCampaignID);
501
							}
502
							$CampLists = $goReturnCampList;
503
							
504
							$goDUPLists = preg_replace("/,$/",'',$CampLists);
505
							
506
							//$goCheckCampPhoneList = "SELECT phone_number FROM vicidial_list WHERE phone_number='$phone_number' AND list_id IN($goDUPLists) LIMIT 1;";
507
							$astDB->where('phone_number', $phone_number);
508
							$astDB->where('list_id', explode(',', $goDUPLists), 'in');
509
							$rsltgoCheckCampPhoneList = $astDB->getOne('vicidial_list', 'phone_number');
510
							$countCheckCampPhoneList = $astDB->getRowCount();
511
							
512
							if($countCheckCampPhoneList < 1) {
513
								$USarea = substr($phone_number, 0, 3);
514
								$gmt_offset = lookup_gmt($astDB, $phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);				
515
								//$goQueryInsNotDUP = "INSERT INTO vicidial_list (lead_id, entry_date, status, vendor_lead_code, list_id, gmt_offset_now, 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, entry_list_id) VALUES ('', '$entry_date', '$status', '$vendor_lead_code', '$list_id', '$gmt_offset', '$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', '$entry_list_id');";
516
								$insertData = array(
517
									'lead_id' => '',
518
									'entry_date' => $entry_date,
519
									'status' => $status,
520
									'vendor_lead_code' => $vendor_lead_code,
521
									'list_id' => $list_id,
522
									'gmt_offset_now' => $gmt_offset,
523
									'phone_code' => $phone_code,
524
									'phone_number' => $phone_number,
525
									'title' => $title,
526
									'first_name' => utf8_encode($first_name),
527
									'middle_initial' => utf8_encode($middle_initial),
528
									'last_name' => utf8_encode($last_name),
529
									'address1' => $address1,
530
									'address2' => $address2,
531
									'address3' => $address3,
532
									'city' => $city,
533
									'state' => $state,
534
									'province' => $province,
535
									'postal_code' => $postal_code,
536
									'country_code' => $country_code,
537
									'gender' => $gender,
538
									'date_of_birth' => $date_of_birth,
539
									'alt_phone' => $alt_phone,
540
									'email' => $email,
541
									'security_phrase' => $security_phrase,
542
									'comments' => $comments,
543
									'entry_list_id' => $entry_list_id,
544
									'last_local_call_time' => '0000-00-00 00:00:00'
545
								);
546

    
547
								//TOGLIAMO I NUMERI IN DB E LI SOSTIUIAMO
548
								$deleteQueryLeads = "DELETE FROM vicidial_list WHERE phone_number='$phone_number';"; 
549
								$deleteResultLeads = $astDB->rawQuery($deleteQueryLeads);
550

    
551
								$rsltGoQueryInsNotDUP = $astDB->insert('vicidial_list', $insertData);
552
								$goLastInsertedLeadIDDUPCAMP = $astDB->getInsertId();
553
								
554
								# start set query for custom fields
555
								if(!empty($lead_mapping)){ // LEAD MAPPING CUSTOMIZATION
556
                                		        	        $goCustomKeyData = array();
557
                        	                	        	$goCustomValuesData = array();
558
			                                                $goCustomUpdateData = array();
559

    
560
                        			                        foreach($custom_array as $custom_key => $map_data){
561
        		                                        	        $goCustomValues = $col[$map_data];
562
	                                        	        	        array_push($goCustomKeyData, "$custom_key");
563
                                	                        		array_push($goCustomValuesData, "'$goCustomValues'");
564
        			                                                array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
565
	
566
			                                                        //$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_key) VALUES('$goLastInsertedLeadIDNODUP', '$goCustomValues') ON DUPLICATE KEY UPDATE $custom_key='$goCustomValues'";
567
                                                			        //$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
568
                        			                        }
569

    
570
			                                                $custom_keyValues = implode(",", $goCustomKeyData);
571
			                                                $goCustomValues = implode(",", $goCustomValuesData);
572
                                                			$goCustomUpdate = implode(", ",  $goCustomUpdateData);
573

    
574
                        			                        $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_keyValues) VALUES('$goLastInsertedLeadIDDUPCAMP', $goCustomValues) ON DUPLICATE KEY UPDATE $goCustomUpdate";
575
			                                                $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
576

    
577
                                                                }elseif($goCountTheHeader > 21) {
578
									$goShowCustomFields = "DESC custom_$list_id;";
579
									$rsltgoShowCustomFields = $astDB->rawQuery($goShowCustomFields);
580
									$countResultrsltgoShowCustomFields = $astDB->getRowCount();
581
									
582
									if($countResultrsltgoShowCustomFields > 1) {
583
										$totalExplode = count($goGetLastHeader2);
584
										$goCustomValuesData = array();
585
	                                                                        $goCustomUpdateData = array();
586

    
587
										for($ax=0; $ax < $totalExplode; $ax++) {
588
											$goHeaderOfCustomFields = $goGetLastCustomFiledsName2[$ax]; #get the header name of the custom fields
589
											$goCustomValues = $col[$goGetLastHeader2[$ax]]; #get the values of the custom fields
590
											#$goQueryCustomFields .= "INSERT INTO custom_$theList (lead_id,".$goHeaderOfCustomFields.") VALUES ('$goLastInsertedLeadIDDUPCAMP','".$goCustomValues."');";
591
											#$rsltGoQueryCustomFields = mysqli_query($link, $goQueryCustomFields);
592
											
593
											#$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) VALUES('$goLastInsertedLeadIDDUPCAMP', '$goCustomValues') ON DUPLICATE KEY UPDATE $goHeaderOfCustomFields='$goCustomValues'";
594
											#$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
595
											
596
											#$apiresults = array("result" => "success", "message" => "$goCountInsertedLeads");
597
											array_push($goCustomValuesData, "'$goCustomValues'");
598
	                                                                                array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
599

    
600
										}
601

    
602
										$goHeaderOfCustomFields = implode(",", $goGetLastCustomFiledsName2);
603
                                        	        		        $goCustomValues = implode(",", $goCustomValuesData);
604
                        		        	                        $goCustomUpdate = implode(", ",  $goCustomUpdateData);
605
			                                                        $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) VALUES('$goLastInsertedLeadIDDUPCAMP', $goCustomValues) ON DUPLICATE KEY UPDATE $goCustomUpdate";
606
										$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
607
	
608
									} 
609
								} 
610
								# end set query for custom fields
611
								$goCountInsertedLeads++;
612
                                                                $apiresults = array("result" => "success", "message" => "$goCountInsertedLeads");
613
							}// end of IF
614
							else{
615
								$duplicates++;
616
							}
617
						}
618
				}
619
				
620
			} elseif ($goDupcheck == "DUPLIST") {
621
				
622
				#Duplicate check within the LIST
623
				if($goGetCheckcustomFieldNamesCorrect === "error" && empty($lead_mapping)) {
624
					fclose($handle);
625
				} else {
626
					//$goQueryCheckDupPhone = "SELECT phone_number FROM vicidial_list WHERE phone_number='$phone_number' AND list_id='$list_id';";
627
					$astDB->where('phone_number', $phone_number);
628
					$astDB->where('list_id', $list_id);
629
					$rsltCheckDupPhone = $astDB->get('vicidial_list', null, 'phone_number');
630
					$countResult = $astDB->getRowCount();
631
						
632
					if($countResult < 1) {
633
						$USarea = substr($phone_number, 0, 3);
634
						$gmt_offset = lookup_gmt($astDB, $phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
635
						
636
						//$goQueryInsDupList = "INSERT INTO vicidial_list (lead_id, entry_date, status, vendor_lead_code, list_id, gmt_offset_now, 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, entry_list_id) VALUES ('', '$entry_date', '$status', '$vendor_lead_code', '$list_id', '$gmt_offset', '$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', '$entry_list_id');";
637
						$insertData = array(
638
							'lead_id' => '',
639
							'entry_date' => $entry_date,
640
							'status' => $status,
641
							'vendor_lead_code' => $vendor_lead_code,
642
							'list_id' => $list_id,
643
							'gmt_offset_now' => $gmt_offset,
644
							'phone_code' => $phone_code,
645
							'phone_number' => $phone_number,
646
							'title' => $title,
647
							'first_name' => utf8_encode($first_name),
648
							'middle_initial' => utf8_encode($middle_initial),
649
							'last_name' => utf8_encode($last_name),
650
							'address1' => $address1,
651
							'address2' => $address2,
652
							'address3' => $address3,
653
							'city' => $city,
654
							'state' => $state,
655
							'province' => $province,
656
							'postal_code' => $postal_code,
657
							'country_code' => $country_code,
658
							'gender' => $gender,
659
							'date_of_birth' => $date_of_birth,
660
							'alt_phone' => $alt_phone,
661
							'email' => $email,
662
							'security_phrase' => $security_phrase,
663
							'comments' => $comments,
664
							'entry_list_id' => $entry_list_id,
665
							'last_local_call_time' => '0000-00-00 00:00:00'
666
						);
667
												//TOGLIAMO I NUMERI IN DB E LI SOSTIUIAMO
668
												$deleteQueryLeads = "DELETE FROM vicidial_list WHERE phone_number='$phone_number';"; 
669
												$deleteResultLeads = $astDB->rawQuery($deleteQueryLeads);
670

    
671
						$rsltGoQueryInsDupList = $astDB->insert('vicidial_list', $insertData);
672
						$goLastInsertedLeadIDDUPLIST = $astDB->getInsertId();
673
						$alex["insertquery"] = $astDB->getLastQuery();
674
						# start set query for custom fields
675
						if(!empty($lead_mapping)){ // LEAD MAPPING CUSTOMIZATION
676
                                                	$goCustomKeyData = array();
677
                                                        $goCustomValuesData = array();
678
                                                        $goCustomUpdateData = array();
679

    
680
                                                        foreach($custom_array as $custom_key => $map_data){
681
                                                        	$goCustomValues = $col[$map_data];
682
                                                                array_push($goCustomKeyData, "$custom_key");
683
                                                                array_push($goCustomValuesData, "'$goCustomValues'");
684
                                                                array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
685

    
686
                                                                //$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_key) VALUES('$goLastInsertedLeadIDNODUP', '$goCustomValues') ON DUPLICATE KEY UPDATE $custom_key='$goCustomValues'";
687
                                                                //$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
688
                                                        }
689

    
690
                                                        $custom_keyValues = implode(",", $goCustomKeyData);
691
                                                        $goCustomValues = implode(",", $goCustomValuesData);
692
                                                        $goCustomUpdate = implode(", ",  $goCustomUpdateData);
693

    
694
                                                        $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_keyValues) VALUES('$goLastInsertedLeadIDDUPLIST', $goCustomValues) ON DUPLICATE KEY UPDATE $goCustomUpdate";
695
                                                        $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
696

    
697
                                                }elseif($goCountTheHeader > 21) {
698
							$goShowCustomFields = "DESC custom_$list_id;";
699
							$rsltgoShowCustomFields = $astDB->rawQuery($goShowCustomFields);
700
							$countResultrsltgoShowCustomFields = $astDB->getRowCount();
701
							
702
							if($countResultrsltgoShowCustomFields > 1) {
703
								$totalExplode = count($goGetLastHeader2);
704

    
705
								$goCustomValuesData = array();
706
	                                                        $goCustomUpdateData = array();
707

    
708
								for($ax=0; $ax < $totalExplode; $ax++) {
709
									$goHeaderOfCustomFields = $goGetLastCustomFiledsName2[$ax]; #get the header name of the custom fields
710
									$goCustomValues = $col[$goGetLastHeader2[$ax]]; #get the values of the custom fields
711
										
712
									#$goQueryCustomFields = "INSERT INTO custom_$theList (lead_id,".$goHeaderOfCustomFields.") VALUES ('$goLastInsertedLeadIDDUPLIST','".$goCustomValues."');";
713
									#$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) VALUES('$goLastInsertedLeadIDDUPLIST', '$goCustomValues') ON DUPLICATE KEY UPDATE $goHeaderOfCustomFields='$goCustomValues'";
714
									#$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
715
									
716
									#$apiresults = array("result" => "success", "message" => "$goCountInsertedLeads");
717
									array_push($goCustomValuesData, "'$goCustomValues'");
718
                                                                        array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
719

    
720
								}
721
								$goHeaderOfCustomFields = implode(",", $goGetLastCustomFiledsName2);
722
                	                                        $goCustomValues = implode(",", $goCustomValuesData);
723
        	                                                $goCustomUpdate = implode(", ",  $goCustomUpdateData);
724
	                                                        $goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) VALUES('$goLastInsertedLeadIDDUPLIST', $goCustomValues) ON DUPLICATE KEY UPDATE $goCustomUpdate";
725

    
726
								$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
727
							}
728
						}
729
						$goCountInsertedLeads++;
730
                                                $apiresults = array("result" => "success", "message" => "$goCountInsertedLeads"); 
731
						# end set query for custom fields
732
					}//end if
733
					else{
734
						//fclose($handle);
735
						$duplicates++;
736
						//$apiresults = array("result" => "error" , "message" => "Error: Lead File Contains Duplicates in List");
737
					}
738
				}
739
			} else {
740
				#NO DUPLICATE CHECK
741
				if($goGetCheckcustomFieldNamesCorrect === "error" && empty($lead_mapping)) {
742
					fclose($handle);
743
				} else {
744
					$USarea = substr($phone_number, 0, 3);
745
					$gmt_offset = lookup_gmt($astDB, $phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
746
			
747
					$test_query = "INSERT INTO vicidial_list (lead_id, entry_date, status, vendor_lead_code, list_id, gmt_offset_now, 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, entry_list_id, last_local_call_time) VALUES ('', '$entry_date', '$status', '$vendor_lead_code', '$list_id', '$gmt_offset', '$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', '$entry_list_id', '0000-00-00 00:00:00');";
748
					$insertData = array(
749
						'lead_id' => '',
750
						'entry_date' => $entry_date,
751
						'status' => $status,
752
						'vendor_lead_code' => $vendor_lead_code,
753
						'list_id' => $list_id,
754
						'gmt_offset_now' => $gmt_offset,
755
						'phone_code' => $phone_code,
756
						'phone_number' => $phone_number,
757
						'title' => $title,
758
						'first_name' => utf8_encode($first_name),
759
						'middle_initial' => utf8_encode($middle_initial),
760
						'last_name' => utf8_encode($last_name),
761
						'address1' => $address1,
762
						'address2' => $address2,
763
						'address3' => $address3,
764
						'city' => $city,
765
						'state' => $state,
766
						'province' => $province,
767
						'postal_code' => $postal_code,
768
						'country_code' => $country_code,
769
						'gender' => $gender,
770
						'date_of_birth' => $date_of_birth,
771
						'alt_phone' => $alt_phone,
772
						'email' => $email,
773
						'security_phrase' => $security_phrase,
774
						'comments' => $comments,
775
						'entry_list_id' => $entry_list_id,
776
						'last_local_call_time' => '0000-00-00 00:00:00'
777
					);
778

    
779
					//TOGLIAMO I NUMERI IN DB E LI SOSTIUIAMO
780
					$deleteQueryLeads = "DELETE FROM vicidial_list WHERE phone_number='$phone_number';"; 
781
					$deleteResultLeads = $astDB->rawQuery($deleteQueryLeads);
782

    
783
					$rsltGoQueryIns = $astDB->insert('vicidial_list', $insertData);
784
					$goLastInsertedLeadIDNODUP = $astDB->getInsertId();
785

    
786
					$alex["query_insert"] = $astDB->getLastQuery();
787
					$alex["error_insert"] = $astDB->getLastError();
788
	
789
					# start set query for custom fields
790
					if(!empty($lead_mapping)){ //LEAD MAPPING CUSTOMIZATION
791
						$goCustomKeyData = array();
792
						$goCustomValuesData = array();
793
                                                $goCustomUpdateData = array();
794

    
795
						foreach($custom_array as $custom_key => $map_data){
796
							$goCustomValues = $col[$map_data];
797
							array_push($goCustomKeyData, "$custom_key");
798
							array_push($goCustomValuesData, "'$goCustomValues'");
799
                                                        array_push($goCustomUpdateData, "$custom_key='$goCustomValues'");
800

    
801
							//$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_key) VALUES('$goLastInsertedLeadIDNODUP', '$goCustomValues') ON DUPLICATE KEY UPDATE $custom_key='$goCustomValues'";
802
                                                        //$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
803
						}
804

    
805
						$custom_keyValues = implode(",", $goCustomKeyData);
806
                                                $goCustomValues = implode(",", $goCustomValuesData);
807
                                                $goCustomUpdate = implode(", ",  $goCustomUpdateData);
808
					
809
						$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $custom_keyValues) VALUES('$goLastInsertedLeadIDNODUP', $goCustomValues) ON DUPLICATE KEY UPDATE $goCustomUpdate";
810
                                                $rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
811
					
812
					}elseif($goCountTheHeader > 21) {
813
						$goShowCustomFields = "DESC custom_$list_id;";
814
						$rsltgoShowCustomFields = $astDB->rawQuery($goShowCustomFields);
815
						$countResultrsltgoShowCustomFields = $astDB->getRowCount();
816
						
817
						if($countResultrsltgoShowCustomFields > 1) {
818
							$totalExplode = count($goGetLastHeader2);
819

    
820
							$goCustomValuesData = array();
821
							$goCustomUpdateData = array();
822

    
823
							for($ax=0; $ax < $totalExplode; $ax++) {
824
								$goHeaderOfCustomFields = $goGetLastCustomFiledsName2[$ax]; #get the header name of the custom fields
825
								$goCustomValues = $col[$goGetLastHeader2[$ax]]; #get the values of the custom fields
826
									
827
								#$rsltGoQueryCustomFields = mysqli_query($link, $goQueryCustomFields);
828
								
829
//								$goQueryCustomFields .= "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) VALUES('$goLastInsertedLeadIDNODUP', '$goCustomValues') ON DUPLICATE KEY UPDATE $goHeaderOfCustomFields='$goCustomValues';";
830
								//$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
831

    
832
								#$apiresults = array("result" => "success", "message" => "$goCountInsertedLeads");
833

    
834
                                                                array_push($goCustomValuesData, "'$goCustomValues'");
835
                                                                array_push($goCustomUpdateData, "$goHeaderOfCustomFields='$goCustomValues'");
836

    
837
							}
838

    
839
							$goHeaderOfCustomFields = implode(",", $goGetLastCustomFiledsName2);
840
							$goCustomValues = implode(",", $goCustomValuesData);
841
							$goCustomUpdate = implode(", ",  $goCustomUpdateData);
842
							$goQueryCustomFields = "INSERT INTO custom_$theList(lead_id, $goHeaderOfCustomFields) VALUES('$goLastInsertedLeadIDNODUP', $goCustomValues) ON DUPLICATE KEY UPDATE $goCustomUpdate";
843

    
844
							$rsltGoQueryCustomFields = $astDB->rawQuery($goQueryCustomFields);
845
						} 	
846
					}
847
					
848
                                        $goCountInsertedLeads++;
849
                                        $apiresults = array("result" => "success", "message" => "$goCountInsertedLeads", "alex_data" => $alex);
850

    
851
				# end set query for custom fields
852
				}
853
			} #end No Duplicate check
854
		//fclose($handle);
855
			$counter++;
856
		} #end while
857
	
858
		fclose($handle);
859

    
860
		if($goCountInsertedLeads > 0 && $duplicates < 1) {
861
			$apiresults = array("result" => "success", "message" => "Total Uploaded Leads: $goCountInsertedLeads" , "alex_data" => $alex);
862
		}elseif($goCountInsertedLeads > 0 && $duplicates > 0){
863
			$apiresults = array("result" => "success", "message" => "Uploaded:$goCountInsertedLeads    Duplicates:$duplicates");
864
		} elseif($goGetCheckcustomFieldNamesCorrect === "error"){
865
			$apiresults = array("result" => "error" , "message" => "Error: Lead File Not Compatible with List. Incompatible Field Names. Check the File Headers");
866
		}elseif($duplicates > 0){
867
			$apiresults = array("result" => "error" , "message" => "Duplicates Found : $duplicates");
868
		}else {
869
			$apiresults = array("result" => "error", "message" => "$goCountInsertedLeads", "duplicates" => $duplicates, "alex_data" => $alex);
870
		}
871
		
872
		$log_id = log_action($goDB, 'UPLOAD', $log_user, $log_ip, "Uploaded {$goCountInsertedLeads} leads on List ID $theList", $log_group);
873
		
874
	} // END IF handle
875
	
876
	function goGetCampaignList($link, $goCampaignID) {
877
		//$goCheckCamp = "SELECT list_id FROM vicidial_lists WHERE campaign_id='$goCampaignID';";
878
		$link->where('campaign_id', $goCampaignID);
879
		$rsltgoCheckCamp = $link->get('vicidial_lists', null, 'list_id');
880
		$countResultCamp = $link->getRowCount();
881
		
882
		foreach ($rsltgoCheckCamp as $fresultsDup) {
883
			$goDUPLists .= $fresultsDup['list_id'].",";
884
		}
885
		return $goDUPLists;
886
	}
887
	
888
	function goCheckCustomFieldsName($link, $goCClistID, $gocustomFieldsCSV) {
889
		// check fieldnames are correct
890
		//$goSQLCheckFieldsCustom = "SELECT $gocustomFieldsCSV FROM custom_$goCClistID;";
891

    
892
		$goCustomCheckQuery = "SELECT EXISTS(SELECT $gocustomFieldsCSV FROM custom_$goCClistID)";
893
		$customCheck = $link->rawQuery($goCustomCheckQuery);
894
		$countCustomCheck = $link->getRowCount();
895

    
896
		if( $countCustomCheck === 0 ){
897
			return "error";
898
		}
899

    
900
		$rsltSQLCHECK = $link->get("custom_$goCClistID", null, "$gocustomFieldsCSV");
901
		
902
		if(!$rsltSQLCHECK){
903
			$goRetMessage = "error";
904
		} else {
905
			/*$goShowCustomFields = "DESC custom_$goCClistID;";
906
			$rsltgoShowCustomFields = $link->rawQuery($goShowCustomFields);
907
			$countResultrsltgoShowCustomFields = $link->getRowCount();
908
				
909
			if($countResultrsltgoShowCustomFields > 1) {
910
				foreach ($rsltgoShowCustomFields as $fresultsShow){
911
					$goCustomFields .= $fresultsShow['Field'].",";
912
				}
913
				
914
				$goRetMessage = preg_replace("/,$/",'',$goCustomFields);
915
			}*/
916
			$goRetMessage = "success";
917
		}
918
				
919
		return $goRetMessage;
920
	}
921
	
922
	// check 1st if fields are not less than 21
923
	// check 2nd if greater than 21 check the field name spelling from csv vs on the DB custom_LISTID
924
	// lookup_gmt extgetval
925
	// $field_regx = "/['\"`\\;]/";
926
	// $vendor_lead_code =             preg_match($field_regx, "", $vendor_lead_code);
927
	// $vendor_lead_code =             preg_replace($field_regx, "", $vendor_lead_code);
928

    
929
//echo "File data successfully imported to database!!";
930
?>
(3-3/3) Go to top