Пример #1
0
function read_csv_files($type)
{
    $ret = array();
    foreach (glob(dirname(__FILE__) . "/isco*codes.csv") as $file) {
        $match = array();
        preg_match("{isco(\\d+)codes.csv}", $file, $match);
        $code = $match[1];
        $ret[$code] = parse_csv_file($file, $type);
    }
    return $ret;
}
Пример #2
0
 function do_import()
 {
     $filename = $_FILES['file']['tmp_name'];
     $address_fields = array('street1', 'street2', 'street3', 'town', 'county', 'postcode');
     $req_address_fields = array('street1', 'town', 'county', 'postcode');
     $db =& DB::Instance();
     $flash = Flash::Instance();
     $db->StartTrans();
     $columnheadings = false;
     if (isset($this->_data['contains_headings'])) {
         $columnheadings = true;
     } else {
         if (count($this->_data['headings']) > 0) {
             $columnheadings = $this->_data['headings'];
         }
     }
     $data = parse_csv_file($filename, $columnheadings);
     $co_loaded = false;
     $errors = array();
     $try_address = false;
     if (in_array_all($req_address_fields, $columnheadings)) {
         $try_address = true;
     }
     foreach ($data as $person_data) {
         $company = DataObjectFactory::Factory('Company');
         if (in_array('company', $columnheadings)) {
             if (isset($this->_data['unique_companies'])) {
                 $co_loaded = $company->loadBy('name', $person_data['company']);
             }
             if ($co_loaded === false) {
                 $co_data = array('name' => $person_data['company']);
                 $company = DataObject::Factory($co_data, $errors, 'Company');
                 if ($company !== false) {
                     $company->save();
                 }
             }
             if ($company !== false) {
                 $person_data['company_id'] = $company->id;
             }
         }
         parent::save('Person', $person_data);
         if ($try_address && in_array_all($req_address_fields, array_keys($person_data))) {
             $address_data = array();
             foreach ($address_fields as $fieldname) {
                 if (isset($person_data[$fieldname])) {
                     $address_data[$fieldname] = $person_data[$fieldname];
                 }
             }
             $address_data['main'] = true;
             $address_data['name'] = 'Main';
             $address_data['person_id'] = $this->_data['id'];
             $address_data['countrycode'] = 'GB';
             $address = DataObject::Factory($address_data, $errors, 'Personaddress');
             if ($address !== false) {
                 $address->save();
             }
         }
     }
     $success = $db->CompleteTrans();
     if ($success) {
         $flash->clearMessages();
         $flash->addMessage(count($data) . ' contacts imported');
         $this->import();
         $this->setTemplateName('import');
     } else {
         $flash->addErrors($errors);
         $this->import();
         $this->setTemplateName('import');
     }
 }
Пример #3
0
$db_production_database = "test_mv2";
$link = mysql_connect($db_production_hostname, $db_production_username, $db_production_password) or die(mysql_error());
mysql_selectdb($db_production_database, $link);
/**************************************************************************************************/
$db_account_hostname = 'localhost';
//$db_account_hostname = '107.22.255.187';
$db_account_username = '******';
$db_account_password = '******';
$db_account_database = 'sticky_accounts';
$link2 = mysql_connect($db_account_hostname, $db_account_username, $db_account_password) or die(mysql_error());
mysql_selectdb($db_account_database, $link2);
/**************************************************************************************************/
$sampleUrls = $cache = $arrSql = array();
$filename = 'Threshold_price_catalog 11-5-14 csvREADY FOR IMPORT.csv';
echo "{$filename}\n";
$arrData = parse_csv_file($filename);
//print_r($arrData[0]); exit;
foreach ($arrData as $row) {
    $description = '';
    //$row['Description'];
    $upc = '';
    //$row['UPC'];
    $brand = '';
    //$row['Brand'];
    $sku = '';
    //$row['SKU'];
    foreach ($row as $k => $v) {
        $k = ucfirst($k);
        //echo "$k=>$v\n";
        if ($k == 'Final Desc') {
            //Verbose_description
Пример #4
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/faker/src/autoload.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_user.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_item.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_auction.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_country.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_auction_view.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_bid.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_auction_watch.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/class.db_feedback.php";
include $_SERVER['DOCUMENT_ROOT'] . "/config/env_variables.php";
set_time_limit(0);
$csvFile = $_SERVER['DOCUMENT_ROOT'] . "/scripts/db_seed/items.csv";
$itemData = parse_csv_file($csvFile);
//var_dump($itemData);
/*$a = DbAuction::find(195);
$a->setField("numBids", 100);

/*return;*/
$faker = Faker\Factory::create();
$reportFrequencies = $_env_reportFrequencies;
seedUsersItemsAndAuctions(1000, 20, 5);
//now get the userIds and auctions for next steps
$userIds = DbUser::listIds();
$auctions = DbAuction::withConditions()->getAsClasses();
seedAuctionBids();
//seedAuctionViews();
seedAuctionWatches();
$soldAuctions = getSoldAuctions($auctions);
seedFeedbacks($soldAuctions);
Пример #5
0
<?php

// This is just an example of reading server side data and sending it to the client.
// It reads a json formatted text file and outputs it.
$dataType = $_GET['data_type'];
//$string = file_get_contents('../data/' . $dataType . 'data.json');
//echo $string;
$file = '../data/test.csv';
// . $dataType . 'data.json';
$csv = file_get_contents($file);
$array = parse_csv_file($file);
$json = json_encode($array);
$returnArray = array_combine(array("c"), array($json));
$json2 = json_encode($returnArray);
print_r($json2);
function parse_csv_file($csvfile)
{
    $csv = array();
    $rowcount = 0;
    if (($handle = fopen($csvfile, "r")) !== FALSE) {
        $max_line_length = defined('MAX_LINE_LENGTH') ? MAX_LINE_LENGTH : 10000;
        $header = fgetcsv($handle, $max_line_length);
        $header_colcount = count($header);
        while (($row = fgetcsv($handle, $max_line_length)) !== FALSE) {
            $row_colcount = count($row);
            if ($row_colcount == $header_colcount) {
                $entry = array_combine($header, $row);
                $csv[] = $entry;
            } else {
                error_log("csvreader: Invalid number of columns at line " . ($rowcount + 2) . " (row " . ($rowcount + 1) . "). Expected={$header_colcount} Got={$row_colcount}");
                return null;
Пример #6
0
    return $csv;
}
/************************* BEGIN *************************/
$req = $_REQUEST;
$currentDir = str_replace("\\", "/", __DIR__);
$rootDir = $currentDir . '/..';
$entries = scandir($rootDir . '/public/files');
$directories = array();
foreach ($entries as $entry) {
    if ('..' == $entry || '.' == $entry) {
        continue;
    }
    $directories[] = $entry;
}
$files = array();
foreach ($directories as $entry) {
    $fileEntries = glob($rootDir . '/public/files/' . $entry . '/*.csv');
    $files[] = $fileEntries[0];
}
//print_r($files);
$arrJson = array();
foreach ($files as $key => $entry) {
    $res = parse_csv_file($entry);
    $arrJson[$directories[$key]] = $res;
    //  print_r($res);
}
//print_r($arrJson);
$toJson = json_encode($arrJson);
echo $toJson;
//
//echo $toJson;
Пример #7
0
echo '<pre>';
print_r($contents);
echo '</pre>';
foreach ($contents as $file) {
    if (substr($file, -4, 4) == '.csv') {
        $arrayCsvFiles[] = $arrayCsvFilesClear[] = $file;
    }
}
foreach ($arrayCsvFiles as $file) {
    if (isset($result["{$file}"])) {
        continue;
    }
    $localFileNeme = time() . rand(1, 1000);
    $downloadFilePath = AF::path($localFileNeme, array('files', 'csv', 'rockets'), 'csv');
    if ($sftp->get($dPath . '/' . $file, $downloadFilePath)) {
        parse_csv_file($downloadFilePath);
        $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
        $msql->query($sql, $fulfillmentID, $file);
    }
}
$sftp->_disconnect(0);
function parse_csv_file($downloadFilePath)
{
    global $fulfillmentID, $msql;
    $header = NULL;
    $data = array();
    if (($handle = fopen($downloadFilePath, 'r')) !== FALSE) {
        while (($row = fgetcsv($handle, 1000, ',')) !== FALSE) {
            if (!$header) {
                $header = $row;
            } else {