PHP-Code:
<?php //if (!defined('TL_ROOT')) die('You can not access this file directly!');
require_once('functions.php');
class blub {
public function bla() {
return 'blub';
}
}
// Gibt blub zurück
$obj = new blub();
echo $obj->bla();
// gibt nix zurück
$obj2 = new alka;
echo $obj2->alkaGetUpdatedFiles();
class alka extends Backend {
//class alka {
public function __construct() {
parent::__construct();
$this->Import('Logtabs');
}
/* Via FTP die aktuellen Daten von Alka laden */
public function alkaGetUpdatedFiles() {
// Variablen
$remote_file = 'plalkawws.txt';
$remote_path = 'pl';
$local_file = 'alka_update.txt';
$local_path = 'files/import/alka';
// Verbindung herstellen
$connection = ftp_connect("-");
// Am FTP Server anmelden
if (@ftp_login($connection, "-", "-")) {
//log_message('FTP-Verbindung erfolgreich', 'alka.log');
$this->Logtabs->addentry("FTP-Verbindung erfolgreich hergestellt", "importexport_alka", 'complete');
}
else {
//log_message('FTP-Verbindung nicht erfolgreich', 'alka.log');
$this->Logtabs->addentry("FTP-Verbindung konnte nicht hergestellt. Benutzername und Passwort überprüfen.", "importexport_alka", 'error');
}
// Verzeichnis wechseln
if(ftp_chdir($connection, $remote_path)) {
//log_message('Verzeichnis erfolgreich gewechselt', 'alka.log');
$this->Logtabs->addentry("FTP Verzeichniswechsel erfolgreich.", "importexport_alka", 'complete');
}
else {
//log_message('Verzeichnis nicht erfolgreich gewechselt', 'alka.log');
$this->Logtabs->addentry("Konnte FTP Verzeichnis nicht wechseln.", "importexport_alka", 'error');
}
// Datei löschen
unlink($local_file);
// Datei erstellen
$handle = fopen($local_file, 'w');
// Datei herunterladen und Inhalt speichern
if(ftp_fget($connection, $handle, $remote_file, FTP_ASCII,0)) {
//log_message('Alka Datei erfolgreich erzeugt', 'alka.log');
$this->Logtabs->addentry("Lokale ALKA Datei erfolgreich erzeugt.", "importexport_alka", 'complete');
}
else {
$this->Logtabs->addentry("Lokale ALKA Datei konnte nicht erzeugt werden.", "importexport_alka", 'error');
}
// FTP Verbindung schließen
ftp_close($connection);
// Datei verschieben
// Kommt noch
return 'test';
}
public function alkaImportUpdatedFiles() {
// Product Array
$products = array();
// Datei öffnen
$file = @fopen("alka_update.txt", "r");
if($file) {
$this->Logtabs->addentry("Lokale ALKA Datei erfolgreich geöffnet.", "importexport_alka", 'complete');
}
else {
$this->Logtabs->addentry("Lokale ALKA Datei kann nicht geöffnet werden.", "importexport_alka", 'error');
}
// Datei durchlaufen und product Array füllen
if ($file)
{
while(!feof($file))
{
$zeile = fgets($file,1000);
$products[] = explode("\t", $zeile); // TAB getrennt
//$products[] = explode(";", $zeile); // HCBS
}
// Over and out
fclose($file);
}
// Datensätze in der Wawi aktualisieren
foreach($products as $key => $val) {
if(count($val) < 24) continue;
if($val[9] == 0) continue;
// Build Price Array
if($val[17] != '' && $val[18] != '' && $val[19] == '' && $val[20] == '')
{
//$arrGroup = array(getSpNumber($db,$val[18]),"-1");
$arrValue = array(changeCtoP($val[12]),changeCtoP($val[17]));
}
elseif($val[17] != '' && $val[18] != '' && $val[19] != '' && $val[20] != '')
{
//$arrGroup = array(getSpNumber($db,$val[18]),getSpNumber($db,$val[20]),"-1");
$arrValue = array(changeCtoP($val[12]),changeCtoP($val[17]),changeCtoP($val[19]));
}
else
{
$arrGroup = array("-1");
$arrValue = array(changeCtoP($val[12]));
}
// Build Price Cost Array
if($val[13] != '' && $val[14] != '' && $val[15] == '' && $val[16] == '')
{
//$arrGroupCost = array(getSpNumber($db,$val[14]),"-1");
$arrValueCost = array(changeCtoP($val[11]),changeCtoP($val[13]));
}
elseif($val[13] != '' && $val[14] != '' && $val[15] != '' && $val[16] != '')
{
//$arrGroupCost = array(getSpNumber($db,$val[14]),getSpNumber($db,$val[16]),"-1");
$arrValueCost = array(changeCtoP($val[11]),changeCtoP($val[13]),changeCtoP($val[15]));
}
else
{
$arrGroupCost = array("-1");
$arrValueCost = array(changeCtoP($val[11]));
}
// Verkaufspreise erzeugen
$price = array("group" => $arrGroup, "value" => $arrValue);
$price = serialize($price);
// Einkaufspreise erzeugen
$priceCost = array("group" => $arrGroupCost, "value" => $arrValueCost);
$priceCost = serialize($priceCost);
//$priceCost = array("group" => array("-1"), "value" => array($val[11]));
$title = $val[6].' '.$val[7];
$title = utf8_encode($title);
//$checkSql = $this->Database->prepare("SELECT id, alka_nummer FROM tl_warenwirtschaft_products WHERE alka_nummer=?")->limit(1)->execute($val[0]);
if($checkQuery->numRows > 0) {
$this->Database->prepare("UPDATE tl_warenwirtschaft_products SET title=?, singlePrice=?, priceCost=?, alka_ean=? WHERE alka_nummer=?")->limit(1)->execute(addslashes($title), $price, $priceCost, addslashes($val[1]), $val[0]);
//$updateSql = "UPDATE tl_warenwirtschaft_products SET title = '".addslashes($title)."', singlePrice = '".$price."', priceCost = '".$priceCost."', alka_ean = '".addslashes($val[1])."' WHERE alka_nummer = '".$val[0]."' LIMIT 1;";
//$db->dbQuery($updateSql);
//echo $val[0].' upgedated<br />';
}
else {
// echo $val[0].' nicht upgedated<br />';
}
}
}
}
?>
Lesezeichen