Project

General

Profile

Bug #7980 » goReadUpload.php

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

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

    
24
	ini_set('memory_limit','1024M');
25
	ini_set('upload_max_filesize', '6000M');
26
	ini_set('post_max_size', '6000M');
27
	
28
	//ini_set('display_errors', 'on');
29
    	//error_reporting(E_ALL);
30
	
31
	$thefile = $_FILES['goFileMe']['tmp_name'];
32
	$theList = $_REQUEST["goListId"];
33
	$goDupcheck = $_REQUEST["goDupcheck"];
34
	$default_delimiter = ";";
35
	
36
	// path where your CSV file is located
37
	define('CSV_PATH','/tmp/');
38

    
39
	// Name of your CSV file
40
	$csv_file = $thefile;
41

    
42
	// REPLACE DELIMITER to SEMI-COLON -- CUSTOMIZATION!!!!!
43
        if(!empty($_REQUEST["custom_delimiter"]) && isset($_REQUEST["custom_delimiter"])){
44
           //$delimiters = $_REQUEST["custom_delimiter"];
45
           $delimiters = explode(" ", $_REQUEST["custom_delimiter"]);
46
           $str = file_get_contents($csv_file);
47
           $str1 = str_replace($delimiters, $default_delimiter, $str);
48
           file_put_contents($csv_file, $str1);
49
        }
50
    	// REGEX to prevent weird characters from ending up in the fields
51
	$field_regx = "/['\"`\\;]/";
52
	$field_regx = str_replace($delimiters, "", $field_regx);	
53
	
54
	
55
	// STANDARD FIELDS
56
	$getSF = array("Phone","VendorLeadCode","PhoneCode","Title","FirstName","MiddleInitial","LastName","Address1","Address2","Address3","City","State","Province","PostalCode","CountryCode","Gender","DateOfBirth","AltPhone","Email","SecurityPhrase","Comments");
57

    
58
/*
59
		// MODIFICATO
60
		$getSF = array("Telefono","CodVendita","Prefissointernazionale","Titolo","Cognome","Inziali","Nome","Indirizzo1","Indirizzo2","Indirizzo3","Citta","Stato","Provincia","CAP","Nazione","SESSO","DataCompleanno","Telefono2","Email","SecurityCode","Note");
61
*/	
62

    
63
	// GET CUSTOM FIELDS OF LIST
64
	$astDB->where('list_id', $theList);
65
        $rsltv = $astDB->get('vicidial_lists_fields', null, 'field_label, field_name');
66
	
67
	if(!empty($rsltv)){
68

    
69
	foreach($rsltv as $fresults){
70
		$getCF[] = $fresults['field_label'];
71
	}
72

    
73
	}else{
74
		$getCF[] = "";
75
	}
76

    
77
	if (($file = fopen($csv_file, "r")) !== FALSE) { //$handle = $file
78
		$getHeader = fgetcsv($file, 1000, $default_delimiter);
79
		fclose($file);
80
		$apiresults = array("result" => "success", "data" => $getHeader, "standard_fields" => $getSF, "custom_fields" => $getCF);
81
	}else{
82
		$apiresults = array("result" => "csv read fail");
83
	}
84

    
85
?>
(2-2/3) Go to top