Datenabgleich
1. Upload
if($GP['action']=='upload') : // calc file and diff
#ini_set( 'memory_limit','100M');
////////////////////////////////////////////////////////////////////////////////
// prepeare catDb
$CatStr = file_get_contents('db/cat.csv');
$CatDB = array();
foreach(explode("\n",$CatStr) as $k => $l) {
if(!$k) continue;
$A = explode(";",$l);
$CatDB[$A[0]] = $A[3];
$CatDB[$A[1]] = $A[3];
$CatDB[$A[2]] = $A[3];
}
////////////////////////////////////////////////////////////////////////////////
// Upload
$newFileImport = 'tmp/zum-importieren.csv';
$file = 'tmp/'.mktime().'.csv';
move_uploaded_file ($_FILES['f']["tmp_name"],$file);
@chmod($file,0777);
////////////////////////////////////////////////////////////////////////////////
// CONFIG
$Config = array(
'SUPPLIER_AID' => 0,
'DESCRIPTION_SHORT' => 1,
'DESCRIPTION_LONG' => 2,
'MANUFACTURER_NAME' => 4,
'MANUFACTURER_AID' => false,
'PRICE_AMOUNT' => 3,
'EVP_AMOUNT' => false,
'SPECIAL_PRICE_AMOUNT' => false,
'AKTION' => false,
'AVAILABILITY' => 8,
'CATALOGID' => false,
'UDX_MATCHCODE' => false,
'WEIGHT' => false,
'PICTURE' => false,
'DATASHEET' => false,
);
////////////////////////////////////////////////////////////////////////////////
// CONVERT FUNCS
function buildCsvFile($filename,$R) {
$fileC = '';
foreach($R as $row) {
foreach($row as $c) {
$fileC.=$c.";";
}
$fileC = substr($fileC,0,-1);
$fileC.="\n";
}
$fileC = substr($fileC,0,-1);
file_put_contents($filename,$fileC);
}
function edit_DESCRIPTION_LONG($v,$k) {
global $Config;
$i = $Config[$k];
$R = $v[$i];
$R = preg_replace('|(.*)|','',$R);
$R = strip_tags($R);
$R = trim(strtr($R,array("\t"=>'','"'=>''," "=>"")));
$R = substr($R,0,255);
return $R;
}
function edit_CATALOGID($v,$k) {
global $CatDB;
$R = 1;
$Prio = array(6,5,7);
foreach($Prio as $col) {
if($CatDB[$v[$col]]) {
$R = $CatDB[$v[$col]];
break;
}
}
return trim($R);
}
function edit_PICTURE($v,$k) {
return '../DE15506245V2/images/'.$v[0].'.jpg';
}
function edit_SUPPLIER_AID($v,$k) {
global $IDs;
#if($IDs[$v[0]]) {
# print_rf($v);exit;
#}
$IDs[$v[0]] = true;
return $v[0];
}
////////////////////////////////////////////////////////////////////////////////
// BUILD OUTPUT
// header
$R = array();
foreach($Config as $k => $v) {
$R[0][] = $k;
}
// data
$A = file($file);
foreach($A as $i => $v) {
if(!$i) continue;
$B = explode(';',$v);
$r = array();
foreach($Config as $k => $v) {
$value = '';
if($v!==false) {
$value = $B[$v];
}
$func = 'edit_'.$k;
if(function_exists($func)) {
$value = $func($B,$k);
}
$value = strtr($value,array(";"=>'',"\t"=>'','"'=>''));
$r[] = $value;
}
$R[] = $r;
}
// build textfile
buildCsvFile($newFileImport,$R);
// delete uploaded file
unlink($file);
?>
2. Download
- Import File
- Änderungen
endif;
?>