";
echo "objType : " . $objType . "
";
echo "objId : " . $objId . "
";
echo "hqId : " . $hqId . "
";
echo "csId : " . $csId . "
";
echo "
";
endif;
// Current file to be imported
$importFile = urldecode($importFile);
$posLastSlash = strripos($importFile, "/");
$posLastSlash++;
$pathname = substr($importFile, 0, $posLastSlash);
$filename = substr($importFile, $posLastSlash);
$outText = "" . getLngt("IMPORTDATEI:") . " " . $filename . "
";
if ($importFile != "") :
if ($hqId != "" && $csId != "") :
// Create internal representation
$srvpArray = array();
$zoneArray = array();
if (file_exists($importFile)) :
$currentTime = getDateTime("0");
// ********************
// * IMPORT FILE zone *
// ********************
if (!(strpos($filename, "import_ZONE_") === false)) :
// Gebietstyptyp; Land; PLZ; Preis
// Bsp.-Gebietstyptypen IKEA: 0=Kerngebiet, 1=Sekundärgebiet Nord, 2=Sekundärgebiet Süd, 3=Restgebiet Nord, 4=Restgebiet Süd, ...
// 0;DE;22844;
// 0;DE;22850;
// ...
// 1;DE;22xxx;
// ...
$rowToImport = array();
$rowToImport[0] = "f_zone_no";
$rowToImport[1] = "f_country";
$rowToImport[2] = "f_zipcode";
$rowToImport[3] = "f_price";
$rowToImport[4] = "f_price2";
$rowToImport[5] = "f_price3";
$rowToImport[6] = "f_dummy";
$rowToImportLen = count($rowToImport);
// read file to import
$data = importCSV($importFile, $delimiter);
$dataLen = count($data);
// loop all rows (EXCEPT header row [$j = 1])
for ($j = 0; $j < $dataLen; $j++) {
// loop for all fields of $fields of the row
for ($i = 0; $i < $rowToImportLen; $i++) {
${$rowToImport[$i]} = $data[$j][$i];
}
$f_zone_no = removeFieldSigns($f_zone_no);
$f_country = removeFieldSigns($f_country);
$f_zipcode = removeFieldSigns($f_zipcode);
$f_price = removeFieldSigns($f_price);
$f_price2 = removeFieldSigns($f_price2);
$f_price3 = removeFieldSigns($f_price3);
if ($f_zipcode != "") :
if ($f_country == "" || !existsEntry("phoenix_special.country",array("cou_iso_2",$f_country))) :
$f_country = "DE";
endif;
// Convert price(s)
$f_price = str_replace (",", ".", $f_price);
$f_price2 = str_replace (",", ".", $f_price2);
$f_price3 = str_replace (",", ".", $f_price3);
// Get srvp_id from serviceplz
$srvpId = getFieldValueFromId("phoenix.serviceplz", "srvp_plz", $f_zipcode, "srvp_id");
if ($srvpId != "") :
// If country "Germany" then fill zipcode with "0" up to 5 chars
if ($f_country == "DE") :
$f_zipcode = pad($f_zipcode, 5);
endif;
// Set arrays
$srvpArray[] = array($srvpId, $f_zipcode, $f_zone_no, $f_country, $f_price, $f_price2, $f_price3);
$x = array_search($f_zone_no, $zoneArray);
if ($x === FALSE) :
$zoneArray[] = $f_zone_no;
endif;
else :
$outText .= getLngt("PLZ " . $f_zipcode . " wird im Basisdatenbestand nicht geführt!") . "
";
endif;
else :
$outText .= getLngt("Keine PLZ im Datensatz!") . "
";
endif;
}
if ($debug) :
// print_r($zoneArray); echo "
";
// print_r($srvpArray); echo "
";
endif;
// Insert new zone zipcodes into the database from internal structure
if ($fire && $executeImportProcess == "1") :
$zoneArrayLen = count($zoneArray);
$srvpArrayLen = count($srvpArray);
TA("B");
// Delete all mapped entries of a zone for a special headquarters and customer to be reimported
// Check for zones existing for the headquarters and the customer.
$csZonesToBeImported = array();
for ($k = 0; $k < $zoneArrayLen; $k++) :
// Get zone id (primary key) of the current zone number regarding hqId, csId
$srvz_id = getFieldValueFromClause("phoenix.servicezone","srvz_id","hq_id = '" . $hqId . "' AND cs_id = '" . $csId . "' AND srvz_no = '" . $zoneArray[$k] . "'");
// Delete mapped zipcodes
if ($srvz_id != "") :
$csZonesToBeImported[$zoneArray[$k]] = $srvz_id; // Define zones for zone mapppings to be deleted and reimported only
deleteStmt("phoenix.servicezonemapping","srvz_id = '" . $srvz_id . "'");
$outText .= getLngt("Zone " . $zoneArray[$k] . " für den Kunden " . $csEid . " wurde im Basisdatenbestand entfernt!") . "
";
else :
$outText .= getLngt("Die Zone " . $zoneArray[$k] . " für den Kunden " . $csEid . " wurde nicht gefunden! Wurden die Zonendaten eingerichtet?") . "
";
endif;
endfor;
// Get zones to be imported
$csZonesKeys = array_keys($csZonesToBeImported);
// $csZonesKeysLen = count($csZonesKeys);
// Import new zipcodes
$executionCount = 0;
$existingCount = 0;
for ($k = 0; $k < $srvpArrayLen; $k++) :
$x = array_search($srvpArray[$k][2], $csZonesKeys);
if (!($x === FALSE)) :
// Check for existence of mapping entry
if (!existsEntry("phoenix.servicezonemapping",array("srvz_id", $csZonesToBeImported[$srvpArray[$k][2]], "srvp_id", $srvpArray[$k][0]))) :
insertStmt("phoenix.servicezonemapping", array("srvz_id", $csZonesToBeImported[$srvpArray[$k][2]], "srvp_id", $srvpArray[$k][0], "srvzm_mt_1", $srvpArray[$k][4], "srvzm_mt_2", $srvpArray[$k][5], "srvzm_mt_3", $srvpArray[$k][6]));
$executionCount++;
else :
$existingCount++;
endif;
endif;
endfor;
TA("C");
TA("E");
$outText .= getLngt("Einträge in der Importdatei: " . $dataLen . "
");
$outText .= getLngt("Eingefügte Einträge: " . $executionCount . "
");
$outText .= getLngt("Existierende Einträge: " . $existingCount . "
");
// $closeWindow = "1";
endif;
endif;
// ********************
// * IMPORT FILE xxxx *
// ********************
// if (!(strpos($filename, "import_xxxx") === false)) :
// endif;
else :
$statusMessage .= getLngt("Die angegebene Datei existiert nicht!");
endif;
else :
$statusMessage .= getLngt("Diese Datei muss für einen bestimmten Kunden verarbeitet werden!");
endif;
else :
$statusMessage .= getLngt("Es wurde keine Datei spezifiziert!");
endif;
/*
CREATE TABLE servicezone (
srvz_id int(10) NOT NULL auto_increment,
hq_id int(10) NOT NULL default '0',
cs_id int(10) NOT NULL default '0',
srvz_no tinyint(3) default '0',
srvz_name varchar(50) NOT NULL default '',
srvz_price float(10,4) NOT NULL default '0.0000',
srvz_price2 float(10,4) NOT NULL default '0.0000',
PRIMARY KEY (srvz_id)
) ENGINE=InnoDB;
CREATE TABLE servicezonemapping (
srvz_id int(10) NOT NULL default '0',
srvp_id int(10) NOT NULL default '0'
) ENGINE=InnoDB;
*/
?>