<?php
include_once("class.dbf.php");
include_once("../config.php");
include_once("helper.php");
global $sugar_config;
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);

mysql_query("set character set utf8;"); 

$path = dirname(__FILE__).'/st/_ODBIOR.DBF';
$dbfp = new dbf_class($path);

$num_recp=$dbfp->dbf_num_rec;

$sugar_fields = array ('id','index_dbf2','name','billing_address_postalcode','billing_address_street','to_vatid','phone_office','phone_fax','description','email','index_dbf','ownership','currency_id','invoice_type','account_type');

$insert = array();
$count =0;
//for($i=0;$i<$num_recp;$i++){
$j=0;
for($i=$num_recp;$i>0;$i--){

	$rowp=$dbfp->getRowAssoc($i);
	//print_r($rowp);
	//echo '<br>'.$rowp['ALBANIA'].'a<br>';
	//echo $back.' '.$rowp['FASTECH_SH'].'<br>';
//echo 'lol';
$nazwa=str_replace("'","",$rowp['NAZWA']);
 $row = array (
		addslashes(create_guid()), //id
		addslashes(ch($rowp['INDEKS'])),  //nazwa
		addslashes(ch($nazwa)),

		addslashes(ch($rowp['ADRES1'])), //kod pocz
		addslashes(ch($rowp['ADRES2'])), // ulica
		addslashes(ch($rowp['NIPBK'])),
		addslashes(ch($rowp['TEL'])), // TEL
		addslashes($rowp['FAX']), //kraj
		addslashes(ch($rowp['OPIS1']).' '.ch($rowp['OPIS2']).' '.ch($rowp['OPIS3']).' '.ch($rowp['OPIS4']).' '.ch($rowp['OPIS5']).' '.ch($rowp['ADRES1']).' '.ch($rowp['ADRES2']).' '.ch($rowp['UWAGI'])),
		addslashes(ch($rowp['EMAIL'])),
		addslashes(ch($rowp['NR_EWIDENC'])),
		addslashes(ch($rowp['DYR_WL'])),
		addslashes(ch('db82ba73-d907-3db3-560c-519364a3586e')),
		addslashes(ch('K')),
		addslashes(ch('rec')),
		
		
		
		);
		//echo 'add<br>';
		array_push($insert, $row);
	// echo ch($rowp['NAZWA']);

	//echo $a.'a<br>';
//END ROW ARRAY	
	
}

//CREATE QUERY
//echo sizeof($insert).'';

for ($i=0; $i<count($insert); $i++) {
//echo implode("','",$insert[$i]);
//PRODUCT INSERT
	$query = 'INSERT INTO ekomer.accounts ('.implode(",",$sugar_fields).',date_entered,date_modified,created_by,modified_user_id,assigned_user_id) VALUES (\''.implode("','",$insert[$i]).'\',\''.date("Y-m-d H:i:s").'\',\''.date("Y-m-d H:i:s").'\',\'cf3a00c2-807d-8e12-592e-4fe88f59cbf6\',\'cf3a00c2-807d-8e12-592e-4fe88f59cbf6\',\'cf3a00c2-807d-8e12-592e-4fe88f59cbf6\');';
	echo $query;
	//mysql_query(ch($query));
	if (mysql_error()) echo 'Database error: '.mysql_error().'
';
} 
mysql_close($sql);

?>