<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once('../includes/libs/xtea/xtea.class.php');
require_once('../includes/config.JTL-Shop.ini.php');
//Encrypted Fields
//Info: Passwort ist MD5-Encrypted und wird nach erstem Login in JTL5 in anderen Hash konvertiert
$encryptedFields = array(
"cNachname",
"cFirma",
"cZusatz",
"cStrasse",
);
$csvFile = fopen("tkunden.csv","w+");
$csvDataArray = array();
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Check connection
if($mysqli === false){
die("ERROR: Could not connect. " . $mysqli->connect_error);
}
// Print host information
echo "Connect Successfully. Host info: " . $mysqli->host_info;
// Query (Abweichung bei Newsletterfeld sonst = CSV)
$sql = "SELECT `cPasswort`,`cAnrede`,`cTitel`,`cVorname`,`cNachname`,`cFirma`,`cStrasse`,`cHausnummer`,`cAdressZusatz`,`cPLZ`,`cOrt`,`cBundesland`,`cLand`,`cTel`,`cMobil`,`cFax`,`cMail`,`cUSTID`,`cWWW`,`fGuthaben`,`nRegistriert`,`dGeburtstag`,`fRabatt`,`cHerkunft`,`dErstellt`,`cAktiv`,`cKundenNr`,`cZusatz` FROM `tkunde`";
//$sql .= " WHERE kKunde = '307'"; //Optionale Einschränkung für Tests
if($result = $mysqli->query($sql)){
if($result->num_rows > 0){
//Ausgabe CSV Header
$csvDataArray[] = array("cPasswort","cAnrede","cTitel","cVorname","cNachname","cFirma","cStrasse","cHausnummer","cAdressZusatz","cPLZ","cOrt","cBundesland","cLand","cTel","cMobil","cFax","cMail","cUSTID","cWWW","fGuthaben","cNewsletter","dGeburtstag","fRabatt","cHerkunft","dErstellt","cAktiv","cKundenNr","cZusatz");
//Field Info
$fieldInfo = $result->fetch_fields();
//print_r($fieldInfo);
while($row = $result->fetch_array()){
//CSV-Ausgabe
$tempArray = array();
for($i=0; $i < $result->field_count; $i++) {
//Datum mit 0000-00-00 bereinigen
if( $row[$i] == "0000-00-00" ) {
//Leeres Feld statt 0000..
array_push($tempArray, '');
continue;
}
if( in_array($fieldInfo[$i]->name, $encryptedFields) )
{
//Verschlüsseltes Feld
array_push($tempArray, Jtl4ToJtl5DB($row[$i], TRUE));
}
else
{
//Unverschlüsseltes Feld
array_push($tempArray, Jtl4ToJtl5DB($row[$i]));
}
}
$csvDataArray[] = $tempArray;
}
// Free result set
$result->free();
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
//CSV erzeugen
print_r($csvDataArray);
foreach ($csvDataArray as $row) {
fputcsv($csvFile, $row, ";","\"");
}
fclose($csvFile);
// Close connection
$mysqli->close();
function Jtl4ToJtl5DB($dbvalue, $enrcypted = 0) {
if($enrcypted) {
return utf8_encode(entschluesselXTEA($dbvalue));
}
//return utf8_encode($dbvalue);
return $dbvalue;
}
/**
* @param string $cText
* @return string
*/
function entschluesselXTEA($cText)
{
if (strlen($cText) > 0) {
$oXTEA = new XTEA(BLOWFISH_KEY);
return $oXTEA->decrypt($cText);
}
return $cText;
}
/**
* @param string $cText
* @return string
*/
function verschluesselXTEA($cText)
{
if (strlen($cText) > 0) {
$oXTEA = new XTEA(BLOWFISH_KEY);
return $oXTEA->encrypt($cText);
}
return $cText;
}
?>