Jump to content
xt:Commerce Community Forum
Sign in to follow this  
flavor

Optimierung der Shop-Geschwindigkeit!

Recommended Posts

Hallo lieber Beitragsleser,

seit dem Update auf die neue Xt:C 4.1 läuft der Schop wieder ziemlich langsam, da viele alte optimierte Dateien nun überschrieben worden sind.

Vor und nach dem Update habe ich einen Speed-Test durchgeführt.

Getestet wird/wurde mit folgenden Seiten:

PageSpeed Insights

PageSpeed

Mit PageSpeed vor dem Update

4,351 Sek. - 6/10
Daten: 739,721 KB - 1/5
Speed: 53,881 KB/s - 5/5
Ping: 18.068 ms - 1/10
Erster Connect nach 19,188 ms
Transferstart nach Connect: 671,279 ms (Latenz*)
[/HTML]

[color="Red"]

Mit PageSpeed nach dem Update[/color]

[HTML]
8,766 Sek. - 6/10
Daten: 748,182 KB - 1/5
Speed: 26,994 KB/s - 5/5
Ping: 17.576 ms - 1/10
Erster Connect nach 18,763 ms
Transferstart nach Connect: 3677,256 ms (Latenz*)[/HTML]

[color="SeaGreen"]

Mit PageSpeed Insights vor dem Update[/color]

[HTML]84/100 Punkte und eine Antwortzeit von 1.7 Sek[/HTML]

[color="Red"]

Mit PageSpeed Insights nach dem Update[/color]

[HTML]49/100 Punkte und eine Antwortzeit von 4.8 Sek[/HTML]

Was natürlich sofort auffällt ist die enorme Latenz bzw. die Response-Zeit von ca. 5 Sekunden, daher möchte ich dieses Problem als erstes angehen. Bei dieser Antwortzeit könnte man annehmen, dass das Signal zweimal um den Globus geht, der Server steht allerdings in DE.

Meine erste Vermutung geht Richtung Datenbank-Abfrage, Indizes, SQL-Datenbank hängt, etcpp...

Gibt es hier Möglichkeiten, mit denen ich die Response-Zeit genauer untersuchen kann. Oder gibt es noch andere Ursachen für diese langsame Antwortzeit?

Vielen Dank für die Hilfe!

Der Server auf dem sich der Shop befindet ist ein

[color="Orange"]- Dedicated Server mit Ubuntu 12.04 LTS

- Datenbank MySQL 5.5.24-0ubuntu0.12.04.1

- PhpMyAdmin 3.5.8.2

- SSD HDD, Quad-Core AMD Opteron 1389 Prozessor, 8 GB RAM.

- Es laufen keine weiteren Projekte auf dem Server.

- Artikel im Shop, nicht mehr als 4000.

- PHP wird über fastCGI eingebunden. [/color]

Share this post


Link to post
Share on other sites

Parse Zeit liegt im Schnitt bei 4-5 Sekunden. Im Grunde das selbe wie in der FireBug Netzwerkverbindungsanalyse. Hierzu ein Bild im Anhang. Wie man sehen kann dauert die Antwort des Servers eine ganze Weile, das Laden selbst nur einen Bruchteil.

post-90820-14337915408993_thumb.jpg

Share this post


Link to post
Share on other sites

ich verstehe nicht wie man sollche timings hinbekommt

ich habe 4 mandanten und benutze die neue 4.1 bei mir läuft der shop

ohne probleme

ich denke mal irgenwas funktioniert mit deiner DB nicht oder du hast das update

nicht korekt gemacht

db hooks ist auch auf off ? oder?

Share this post


Link to post
Share on other sites

ich verstehe nicht wie man sollche timings hinbekommt

Wenigstens teilst du mein Unverständnis...

db hooks ist auch auf off ? oder?

Habe diesbezüglich schon alles ausprobiert.

_______________________________________________________

Ich habe mal zwei Schritte zurück gemacht und den Shop neu auf ein Unterverzeichnis mit einer neuen Datenbank (+Demodaten) installiert.

Jetzt bekomme ich eine "Wimpernschlag" schnelle ParseTime von Ø 0.15 ohne zusätzlicher Optimierung.

Jetzt erst mal weitersuchen und rantasten wo das Problem liegt!

Share this post


Link to post
Share on other sites

Ich habe den großen Bremsklotz ausfindig machen können. Wer hätte das gedacht, es war mein selbsterstelltes Flyout-Menu.

Irgendwo im Forum schrieb @oldbear mal, das die ganzen Kategorien und Unterkategorien bei einigen Flyout-Menus alle Subkategorien ziehen würden. Das selbe passiert offenbar auch bei mir. Folglich, die Datenbank wir überlastet.

Um die Subkategorien-Ausgabe zu erzeugen, hatte Ich damals die categories.php von

$tpl_data = array('_categories'=> $category->getCategoryBox(),'_deepest_level_display'=>$category->deepest_level_display);
[/PHP]

nach

[PHP]$tpl_data = array('_categories'=> $category->getCategoryBox(0, true, 0),'_deepest_level_display'=>$category->deepest_level_display);[/PHP]

geändert. [color="DarkRed"]Vielleicht hat ja einer ne Idee wie man das besser lösen könnte? [/color]Denn das Flyout ist schon schön anzusehen und hat einiges an Zeit gekostet.

Nächste Frage; [color="DarkRed"]zieht der Shop sich hierbei auch Kategorien/Subkategorien die nicht im Shop XY antiviert sind[/color], beziehungsweise durchforstet er sie in der DB was auch zu Verlangsamung führt? [color="DarkRed"]Wie kann ich in der DB prüfen welche Tabellen am meisten belastet werden?[/color] Habe mal den Begriff EXPLAIN irgendwo gelesen, welchen ich vor die Tabelle setze. Jemand Erfahrung damit?

Nun jetzt erst mal die Subkategorien-Ausgabe abgeschaltet und ich hab eine ParseTime von Ø 0,75, was noch zu erwähnen wert ist; mit aktivierten xt_bestseller & xt_newproducts Plugins und einer "rand()" Sortierung der Plugins. Denn diese Plugins sind auffällig DB hungrig. Wenn ich diese abschalte, bekomme ich einen ca. 0,2 Sek. schnelleren Seitenaufbau.

Was mir noch aufgefallen ist, das sich die DB Abfrage synchron mit der Zuname von Artikeln im Warenkorb verschlechtert.

Keine Artikel im Warenkorb = PT 0,75, und bei z.B. 10 Artikel im Warenkorb = PT 1,40. Why?

Wenn man dann noch mehrere Plugins von Drittanbietern wie z.B. das Plugin Merkzettel von Pixeleye hat, multipliziert sich das noch einmal und man hat gleich eine lahme Krücke! Nichts gegen das Merkzettel-Plugin von Pixeleye es ist super, aber hier könnte man zu mindestens die Unterstützung für das Combine & minify Verfahren nutzen.

Folglich sind mehrere Plugins, welche (im Content) die DB nutzen sparsam zu genießen. Und solange man die css & js der Plugin-Anbieter nicht selber tunen kann (da verschlüsselt), sollten man hier schnell die Combine & minify Unterstützung anbieten, sonnst schießen sich die Plugin-Anbieter selbst ins Knie. Da muss ich noch einmal bei den Anbietern nachhaken, denn ich nutze schon einige von denen und das belastet die DB enorm. Hier kann man sicherlich noch einiges rausholen. Denn ich bin mit der Geschwindigkeit des Shops momentan alles andere als zufrieden.

Share this post


Link to post
Share on other sites

 

Ich muss ein alten Hut aufgreifen. Bei unserem Schop ist die Antwortzeit der Datenbank bei 2,7-2,8 s.

 

Wie ist im Admin der "System/Datenbankmonitor/Query" zu verstehen und wie kann ich die Felder optimieren? Was bedutet hier max, min und Load?

Und warum bekomme ich bei der "Live Performance" nur ein "504 Gateway Time-out").

 

Vielen Dank und freundliche Grüße

 

Expensive SQL

Tuning the following SQL could reduce the server load substantially

Load Count SQL Max Min
32.984752 284 SELECT o.shop_id as shopid, p.products_id as pid, p.products_name as name, p.products_model as model, p.products_price as price, sum(p.products_quantity) as quantity, ((p.products_price)*sum(p.products_quantity)) as amount FROM xt_orders o, xt_orders_products p WHERE o.orders_id = p.orders_id GROUP BY pid ORDER BY amount DESC LIMIT 20 0.144876 0.105247
2.315218 2 DELETE FROM xt_products_description WHERE products_store_id=? 1.162182 1.153036
0.323596 2   INSERT INTO xt_google_categories (`google_category_id`,`language`,`country`,`sort_order`,`category_path`) VALUE   0.172476 0.151120
0.187035 2 ALTER TABLE `xt_orders` ADD `ratingchamp_review_sent_status` TINYINT NULL, ADD `ratingchamp_review_status` TINYINT NULL; 0.093832 0.093203
0.158897 2 DELETE FROM xt_seo_url WHERE store_id=? 0.081041 0.077856
0.123267 2 SELECT o.shop_id as shopid, p.products_id as pid, p.products_name as name, p.products_model as model, p.products_price as  0.073194 0.050073
0.110179 2 SELECT xt_orders.orders_id FROM xt_orders WHERE xt_orders.orders_id != 0 and ((orders_id LIKE '%botte%') or (... 0.055824 0.054355
0.106202 2 SELECT xt_orders.orders_id FROM xt_orders WHERE xt_orders.orders_id != 0 and ((orders_id LIKE '%schrader%') ... 0.053138 0.053064
0.105868 2 SELECT xt_orders.orders_id FROM xt_orders WHERE xt_orders.orders_id != 0 and ((orders_id LIKE '%abt%') or... 0.053196 0.052672
0.105641 2 SELECT sum(s.orders_stats_price) as sales, count(s.orders_id) as orders, o.shop_id as shopid FROM xt_orders o, xt_orders_stats s WHE,,... 0.054251 0.051390

Suspicious SQL

The following SQL have high average execution times

Avg Time Count SQL Max Min
1.157609 2 DELETE FROM xt_products_description WHERE products_store_id=? 1.162182 1.153036
0.177928 1 SELECT sum(s.orders_stats_price) as amount, o.shop_id as shopid FROM xt_orders o LEFT JOIN xt_orders_stats s USING(orders_id) LEFT JOIN xt_customers_addresses... 0.177928 0.177928
0.161798 2 INSERT INTO xt_google_categories (`google_category_id`,`language`,`country`,`sort_order`,`category_path`) VALUES 0.172476 0.151120
0.135056 1 ALTER TABLE xt_orders ADD `feedback_reminder` INT( 1 ) NOT NULL DEFAULT '0'; 0.135056 0.135056
0.123033 1 ALTER TABLE xt_orders ADD `feedback_hash` VARCHAR( 64 ) NOT NULL DEFAULT '0'; 0.123033 0.123033
0.116228 1 ALTER TABLE xt_orders ADD `feedback_life_circle_id` INT( 11 ) NOT NULL DEFAULT '0'; 0.116228 0.116228
0.116143 284 SELECT o.shop_id as shopid, p.products_id as pid, p.products_name as name, p.products_model as model, p.products_price as price, sum(p.products_quantity) as quantity, ((p.pro 0.144876 0.105247
0.099474 1 ALTER TABLE `xt_orders` DROP `ratingchamp_review_sent_status`, DROP `ratingchamp_review_status`; 0.099474 0.099474
0.093518 2 ALTER TABLE `xt_orders` ADD `ratingchamp_review_sent_status` TINYINT NULL, ADD `ratingchamp_review_status` TINYINT NULL; 0.093832 0.093203
0.079714 1 SELECT sum(s.orders_stats_price) as sales, count(s.orders_id) as orders, o.shop_id as shopid FROM xt_orders o,  0.079714 0.079714

Invalid SQL

count(*) sql1 error_msg
1 SELECT `ew_evelations_show_text_status` FROM `xt_content` LIMIT 1 ERROR: Unknown column 'ew_evelations_show_text_status' in 'field list'
...xtAdmin/plugin_install.php
1 SELECT `ew_evelations_hyperlink` FROM `xt_content` LIMIT 1 ERROR: Unknown column 'ew_evelations_hyperlink' in 'field list'
...xtAdmin/plugin_install.php
1 SELECT `ew_evelations_hyperlink_status` FROM `xt_content` LIMIT 1 ERROR: Unknown column 'ew_evelations_hyperlink_status' in 'field list'
...xtAdmin/plugin_install.php

 

Share this post


Link to post
Share on other sites
7 hours ago, flavor said:

Wie ist im Admin der "System/Datenbankmonitor/Query" zu verstehen und wie kann ich die Felder optimieren? Was bedutet hier max, min und Load?

Die Daten sind weitestgehend nicht aussagekräftig, da viele Querys ebenfalls geloggt werden die nicht für die Geschwindigkeit relevant sind.  

 

7 hours ago, flavor said:

Und warum bekomme ich bei der "Live Performance" nur ein "504 Gateway Time-out").

Weil dein Hoster dir keinen Zugriff auf diese Daten gib.

 

Share this post


Link to post
Share on other sites

Danke für die Info!

 

Habe gerade festgestellt, dass die Hersteller hier den Großteil der Geschwindigkeit ausmachen. Wenn ich   {box name=manufacturers order_by='m.manufacturers_name'} aus der index entferne geht der Kategorieaufruf ca. doppelt so schnell (von 2,8s auf 1,4s). Kann man das in der DB optimieren oder die Hersteller nachladen lassen?

Share this post


Link to post
Share on other sites

naja,

es wird ja in der class.manufacturers.php immer geprüft, ob es Artikel für den jeweiligen Hersteller gibt:

            $this->sql_manufacturer->setSQL_TABLE("LEFT JOIN ".TABLE_PRODUCTS." p ON p.manufacturers_id = m.manufacturers_id");
            $this->sql_manufacturer->setSQL_WHERE("AND p.products_status = 1");

das dauert natürlich etwas ( könnte man auch auskommentieren )

also nachprüfen, ob in der DB bei der xt_products auch ein Index auf die manufacturers_id vorhanden ist ( sollte so sein )

( ich habe ab und an das Problem, das bestimmte Tabellen nach einem Reimport in die DB "Disabled Keys" haben, das bremst auch unheimlich bis zum Stillstand / Shopausfall je nach Tabelle )

Grüsse

 

 

 

 

Share this post


Link to post
Share on other sites

Hallo oldbear!

 

Ja index ist gesetzt. Der Leistungseinbruch ist so krass, dass man das Ding eben nur ausklammern kann. Nachteil für die Kundeninformation, Bedienbarkeit und erheblicher Nachteil für SEO. Schade. Hätte mir eine andere Lösung gewünscht. Muss mir überlegen ob man da nicht eine extra Seite macht.

Ich könnte schwören die 4.1 Version lief bei mir deutlich schneller...hmm

 

Gibt es nicht ein Programm mit dem man messen kann warum die Datenbank so lange braucht? Welche Anfragen an die Datenbank so zeitintensiv sind?

Share this post


Link to post
Share on other sites

Ich habe nie solche schlechten timmings gehabt.  Selbst nicht mit eigenen plugins die noch mehr abfragen an die Datenbank gesetzt haben.

Wie sieht es überhaut beim hoster aus.  Ich hatte mal so einen hinterhof hoster da war es lahm aber.  Aber mit einem richtigen server hatte ich immer gutte timmings.

Intel® Core™ i7-3930K Hexa-Core
inkl. Hyper-Threading-Technologie
  • Arbeitsspeicher64 GB DDR3 RAM
  • Festplatten2 x 500 GB SATA 6 Gb/s SSD
    (Software-RAID 1)
  • Anbindung1 GBit/s-Port
  • Bandbreite garantiert1 GBit/s

also wie wird gehostet???????

Share this post


Link to post
Share on other sites

würde eher für mich persönlich das machen min.  https://www.hetzner.de/hosting/produkte_managed/mc40

ABER: Mit dem was du hast sollte es schon gehen ohne probleme.

Jetzt ist ja die Frage warum ist es langsam.

Wie viele Artikel?

Wie viele Kategorien?

Wie viele Mandanten?

Und wie viele seiten Aufrufe?

Ist alles mit relativ wenig zu beantworten vor allem die seiten aufrufe liegt es sehr nahe das etwas.

A: In der Configuration etwas falsch ist 

B: Durch Löschen oder Schreibfehler die Datenbank Strucktur nicht passt.(damit meine ich product kategorie oder media gallery fehler)

C: Ein plugin dies verursacht

D: Quel-Datein beschädigt sind

E: Datenbank nicht als localhost eingetragen ist obwohl sie es ist das gleiche gilt für Mailserver.

 

Share this post


Link to post
Share on other sites

Die 5er zu testen (und ggf. zu kaufen) bedeutet tausende von €uronen in den Sand zu setzen.

Plugins, Schnittstellenapassung und Template... da sträuben sich mir die Nackenhaare. Sehe noch keinen Vorteil die 5er zu kaufen.

 

Ganz ehrlich ich sehe keinen vorteil xtcommerce > 4  zu nutzen wenn man nicht selber Entwickler ist oder sich permanent welche leisten kann.  Ich liebe diese shopsystem ich finde es auch besser als magento was den unsinnigen weg über das zendframwork macht.  xtcommerce ist solide sehr umfangreich und an seine Bedürfnisse anzupassen.  Aber es ist auch sehr komplex grade darum ist diese software auch so gut aber für normale Anwender ist das nix.

In der werbung wirkt das immer so klick klack artikel rein fertig ganz einfach. Aber so ist es eben nicht.

Allein schon die Einstellung vom Mail-Server dort stellen viele einen externen server ein weil das so in ihrem Hosting-Panel steht das ist ja auch richtig wenn ich vom Büro zum MX verbinden will aber für den shop ist es in der Regel localhost.  Durch diese fehl Einstellung lädt dann der Shop-Admin Bereich langsam beim Aktualisieren des Bestellstatus.  Dann fehlt noch ein SPF Eintrag im DNS und schon landen nach kurzer zeit eh alle mails von dem shop im Spamordner der Kunden.

Also xtc ist grandios aber auch nicht jedermanns sache will man nur klein verkaufen sollte man lieber auf ebay gehen oder sich wordpress als shop einrichten.

Ich habe 5 Jahre Sexspielzeug verkauft nur aus jux und tollerei aber wenn man nicht ordentlich geld in die handnimmt oder nee ganz kleine nische bedient dann würde ich empfehlen auf amazon zu verkaufen und nicht selbst zu hosten ( höchstens um xtc als PIM zu nutzen).  da es im internet nur eine einkaufstraße gibt und zwar google.

Share this post


Link to post
Share on other sites

Vergleich xt:Commerce 5 und NEXT:

http://www.xt-commerce.com/vergleich-zwischen-saas-und-download

 

Zurück zum Thema: Wenn es Probleme mit der Geschwindigkeit gibt dann würde ich ein Hosting empfehlen welches mehr als diese verlinkten 256 MB bietet!

 

p.s. Die Vorteile von xt:Commerce 5 im Vergleich zu 4 sind immens. Auf der Version 4 stehen zu bleiben ist langfrisitig sowieso keine Option.

Share this post


Link to post
Share on other sites

p.s. Die Vorteile von xt:Commerce 5 im Vergleich zu 4 sind immens. Auf der Version 4 stehen zu bleiben ist langfrisitig sowieso keine Option.

Das ist es ja.  Oder eben anders verkaufen.

Share this post


Link to post
Share on other sites

Es ist aus meiner Sicht richtig - xt:C hat es bisher nicht geschafft, die Vorteile der 5 für den Anwender klar rüberzubringen.

Ewig auf der alten Version zu bleiben macht aber ebensowenig Sinn, wie im stationären Einzelhandel mit einer Ladeneinrichtung aus den 50er Jahren Geld sparen zu wollen. Ein Online-Shop verursacht Unterhaltskosten wie jeder andere Laden. Verglichen mit den Gebühren von Plattformen wie Amazon und Co. ist das aber spottbillig, sobald die Umsätze über den Hobby-Bereich hinausgehen.

Share this post


Link to post
Share on other sites

Um Nochmal drauf zurück zukommen: Optimierung der Shop-Geschwindigkeit!

Ich habe damals so gehostet (https://www.hetzner.de/hosting/produkte_managed/mx151ssd) und hatte nie Schwierigkeiten mit der Geschwindigkeit des Shops.  Wenn bei deinem Shop nicht viel los ist und er trotzdem lahmt ( dann sollte dein Hosting langen und es ist wohl eins von den oben genanten Problemen) wenn du es nicht selber lösen kannst! ist es ja auch die berechtigte frage ob dann selber hosten von einem xtc Shop der richtige Lösung für dich ist.

Ansonsten mal in der DB debug auf true stellen ober ich denke nicht das es viel nützen wird.

Share this post


Link to post
Share on other sites

Danke für die Antworten. Wie hat sich den die ganze Struktur von XTC 5 zu XTC 4 geändert. Ich meine, werde ich meine WAWI Schnittstelle irgendwie anpassen müssen?

Siehe Anhang:

 

<?php

// Standard-Defines
define('_VALID_CALL', 'true');
define('CHARSET', 'iso-8859-1');


// Skriptversion
$version_major = 4;
$version_minor = 1;
$version_datum = 'Mai 2016';


// Benötigte Konfigurationsdateien
require_once("../conf/config.php");
require_once("../conf/database.php");
require_once("../conf/paths.php");

// POST / GET auslesen
if (isset($_POST['action'])) {
    $aktion = $_POST['action'];
} else {
    $aktion = $_GET['action'];
}
if (isset($_POST['user'])) {
    $user = $_POST['user'];
} else {
    $user = $_GET['user'];
}
if (isset($_POST['password'])) {
    $password = $_POST['password'];
} else {
    $password = $_GET['password'];
}

// XML-Header erzeugen

header("Last-Modified:" . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: text/xml");

// Debug aktiv?
//if ($_GET['Debug']=="Y") { ShowDebug(); exit; }
// DB-Verbindung herstellen,
// Authentifizierung und Autorisierung durchführen
if (($mysqli = db_connect()) && login($user, $password)) {
    // Aufgerufene Aktion ausführen
    switch ($aktion) {
        case 'read_shopdata':   // Allgemeine Shopdaten auslesen
            readShopdata();
            exit;

        case 'read_languages':  // Sprachen auslesen
            readLanguages();
            exit;

        case 'read_hersteller':  // Hersteller auslesen
            readHersteller();
            exit;

        case 'read_categories':  // Kategorien auslesen
            readCategories();

            exit;

        case 'read_artikel':   // Artikeldaten auslesen
            readArtikel();

            exit;

        case 'write_categorie':  // Kategorie schreiben
            writeCategorie();

            exit;

        case 'write_artikel':   // Artikel schreiben
            writeArtikel();

            exit;

        case 'write_hersteller': // Hersteller schreiben
            WriteHersteller();

            exit;

        case 'delete_artikel':  // Artikel löschen
            deleteArtikel((integer) ($_POST['Artikel_ID']));

            exit;

        case 'orders_export':   // Bestellungen abrufen
            ordersExport();

            exit;

        case 'order_update':   // Bestellstatus ändern
            orderUpdate();

            exit;

        default:         // Default: Versionsinfo
            ReadVersion();

            exit;
    }
    $mysqli->close();
} else {
    ReadVersion();
}

// - - - Versionsinfo - - -
function ReadVersion() {
    global $action, $version_datum, $version_major, $version_minor, $n;
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<STATUS>" . $n .
    "  <STATUS_DATA>" . $n .
    "    <SCRIPT_VERSION_MAJOR>$version_major</SCRIPT_VERSION_MAJOR>" . $n .
    "    <SCRIPT_VERSION_MINOR>$version_minor</SCRIPT_VERSION_MINOR>" . $n .
    "    <SCRIPT_DATE>$version_datum</SCRIPT_DATE>" . $n .
    "    <SCRIPT_DEFAULTCHARSET>" . htmlspecialchars(ini_get('default_charset'), NULL, '') . "</SCRIPT_DEFAULTCHARSET>" . $n .
    "  </STATUS_DATA>" . $n .
    "</STATUS>" . $n . $n;
}

// - - - Shopdaten auslesen - - -
function readShopData() {
    global $n, $hk, $mysqli;
    $cmd = "SELECT languages_id, code FROM " . TABLE_LANGUAGES . " WHERE code = 'de'";
    $languages_query = $mysqli->query($cmd) or die(mysqli_error());
    $languages = $languages_query->fetch_array();

    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<SHOPDATA>" . $n .
    "    <TAXRATES>" . $n;

    $cmd = "select tax_class_id,tax_rate from " . TABLE_TAX_RATES;
    $tax_query = $mysqli->query($cmd) or die(mysqli_error());

    while ($tax = $tax_query->fetch_array()) {
        if ((int) ($tax['tax_rate']) > 0) {
            echo "        <TAX>" . $n .
            "            <ID>" . $tax['tax_class_id'] . "</ID>" . $n .
            "            <RATE>" . $tax['tax_rate'] . "</RATE>" . $n .
            "        </TAX>" . $n;
        }
    }
    echo "    </TAXRATES>" . $n .
    "    <SHIPPINGSTATUS>" . $n;


    $cmd = "SELECT a.status_id, b.status_name FROM " . TABLE_SYSTEM_STATUS . " a, " . TABLE_SYSTEM_STATUS_DESCRIPTION .
            " b WHERE a.status_id = b.status_id AND a.status_class = 'shipping_status'
            AND b.language_code = 'de' ";
    $status_query = $mysqli->query($cmd) or die(mysqli_error());
    while ($status = $status_query->fetch_array()) {
        echo "        <SHIPPINGSTATUS_DATA>" . $n .
        "            <ID>" . $status['status_id'] . "</ID>" . $n .
        "            <LANGUAGEID>" . $languages['languages_id'] . "</LANGUAGEID>" . $n .
        "            <NAME>" . htmlspecialchars($status['status_name'], NULL, '') . "</NAME>" . $n .
        "        </SHIPPINGSTATUS_DATA>" . $n;
    }

    echo "    </SHIPPINGSTATUS>" . $n .
    "    <CUSTOMERSSTATUS>" . $n;

    $cmd = "select * from " . TABLE_CUSTOMERS_STATUS_DESCRIPTION . " WHERE language_code = 'de'";
    $customer_query = $mysqli->query($cmd) or die(mysqli_error());
    while ($customer = $customer_query->fetch_array()) {
        echo "        <CUSTOMERSSTATUS_DATA>" . $n .
        "            <ID>" . $customer['customers_status_id'] . "</ID>" . $n .
        "            <LANGUAGEID>" . $languages['languages_id'] . "</LANGUAGEID>" . $n .
        "            <NAME>" . htmlspecialchars($customer['customers_status_name'], NULL, '') . "</NAME>" . $n .
        "        </CUSTOMERSSTATUS_DATA>" . $n;
    }
    echo "    </CUSTOMERSSTATUS>" . $n .
    "</SHOPDATA>" . $n;
    $customer_query->close();
    $status_query->close();
    $languages_query->close();
    $tax_query->close();
}

// - - - Sprachen auslesen - - -
function readLanguages() {
    global $n, $hk, $mysqli;

    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<LANGUAGES>" . $n;
    $cmd = "select languages_id, name, code from " . TABLE_LANGUAGES . " where allow_edit = '1'";
    $languages_query = $mysqli->query($cmd) or die(mysqli_error());
    while ($language = $languages_query->fetch_array()) {
        echo "    <LANGUAGES_DATA>" . $n .
        "        <ID>" . $language['languages_id'] . "</ID>" . $n .
        "        <NAME>" . htmlspecialchars($language["name"], NULL, '') . "</NAME>" . $n .
        "        <CODE>" . htmlspecialchars($language["code"], NULL, '') . "</CODE>" . $n .
        "    </LANGUAGES_DATA>" . $n;
    }
    echo "</LANGUAGES>" . $n;
    $languages_query->close();
}

// - - - Kategorien abrufen - - -
function readCategories() {
    global $n, $hk, $mysqli;
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<CATEGORIES>" . $n;
    $cmd = "select categories_id, parent_id from " . TABLE_CATEGORIES . " order by parent_id, categories_id";
    $cat_query = $mysqli->query($cmd) or die(mysqli_error());
    while ($cat = $cat_query->fetch_array()) {
        echo "    <CATEGORIES_DATA>" . $n .
        "        <ID>" . $cat['categories_id'] . "</ID>" . $n .
        "        <PARENT_ID>" . $cat['parent_id'] . "</PARENT_ID>" . $n .
        "        <NAMES>" . $n;

        $cmd = "select a.language_code, a.categories_name, b.languages_id from " . TABLE_CATEGORIES_DESCRIPTION . " a, " . TABLE_LANGUAGES .
                " b where categories_id=" . $cat['categories_id'] . " AND a.language_code = b.code AND b.allow_edit = '1'";
        $names_query = $mysqli->query($cmd) or die(mysqli_error());
        while ($names = $names_query->fetch_array()) {
            echo "            <NAMEENTRY>" . $n .
            "                <LANGUAGEID>" . $names['languages_id'] . "</LANGUAGEID>" . $n .
            "                <NAME>" . htmlspecialchars($names['categories_name'], NULL, '') . "</NAME>" . $n .
            "            </NAMEENTRY>" . $n;
        }
        echo "        </NAMES>" . $n;
        echo "    </CATEGORIES_DATA>" . $n;
    }
    echo "</CATEGORIES>" . $n;
    $cat_query->close();
    $names_query->close();
}

// - - - Hersteller abrufen - - -
function readHersteller() {
    global $n, $hk, $mysqli;
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<MANUFACTURERS>" . $n;

    $cmd = "select manufacturers_id,manufacturers_name from " . TABLE_MANUFACTURERS;
    $manufacturers_query = $mysqli->query($cmd) or die(mysqli_connect_error());
    while ($manufacturers = $manufacturers_query->fetch_array()) {
        echo "    <MANUFACTURERS_DATA>" . $n .
        "        <ID>" . $manufacturers['manufacturers_id'] . "</ID>" . $n .
        "        <NAME>" . htmlspecialchars($manufacturers["manufacturers_name"], NULL, '') . "</NAME>" . $n .
        "    </MANUFACTURERS_DATA>" . $n;
    }
    echo "</MANUFACTURERS>" . $n;
    $manufacturers_query->close();
}

// - - - Artikel auslesen - - -
function readArtikel() {
    global $n, $hk, $mysqli;
    $SkipImages = (bool) ($_GET['SkipImages']);
    if (defined('SET_TIME_LIMIT')) {
        xtc_set_time_limit(0);
    }

    $cmd = "select * from " . TABLE_PRODUCTS;

    if (isset($_GET['AbDatum'])) {
        $cmd .= " where last_modified>='" . $_GET['AbDatum'] . "'";
    }
    $HasLimit = (isset($_GET['LimitOffset']) && isset($_GET['LimitRowCount']));
    if ($HasLimit) {
        $cmd .= " limit " . (integer) ($_GET['LimitOffset']) . ', ' . (integer) ($_GET['LimitRowCount']);
    }
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<ARTIKEL";
    if ($HasLimit) {
        echo ' WithLimit="True"';
    }
    echo ">" . $n;
    $artikel_query = $mysqli->query($cmd);
    while ($artikel = $artikel_query->fetch_array()) {
        echo "  <ARTIKEL_DATA>" . $n .
        "        <ID>" . $artikel['products_id'] . "</ID>" . $n .
        "        <ARTIKELNR>" . htmlspecialchars($artikel['products_model'], NULL, '') . "</ARTIKELNR>" . $n .
        "        <TEXTE>" . $n;
        $cmd = "select * from " . TABLE_PRODUCTS_DESCRIPTION . " a, " . TABLE_LANGUAGES . " b where products_id=" . $artikel['products_id'] .
                " and a.language_code = b.code and b.allow_edit = '1'";
        $texte_query = $mysqli->query($cmd) or die($mysqli->error);
        while ($texte = $texte_query->fetch_array()) {
            // $cmd =  "SELECT languages_id FROM " . TABLE_LANGUAGES ." WHERE allow_edit ='1' AND code = '".$texte['language_code']. "'";
            // $languages_query = mysql_query($cmd) or die(mysql_error());
            // $languages = mysql_fetch_array($languages_query);
            $cmd = "SELECT * FROM " . TABLE_SEO_URL . " WHERE link_id = " . $artikel['products_id'] . " AND language_code = 'de'";
            $seo_query = $mysqli->query($cmd) or die($mysqli->error);
            $seo = $seo_query->fetch_array();
            echo "            <TEXT>" . $n .
            "                <LANGUAGEID>" . $texte['languages_id'] . "</LANGUAGEID>" . $n .
            "                <NAME>" . htmlspecialchars($texte['products_name'], NULL, '') . "</NAME>" . $n .
            "                <DESCRIPTION>" . htmlspecialchars($texte['products_description'], NULL, '') . "</DESCRIPTION>" . $n .
            "                <SHORTDESCRIPTION>" . htmlspecialchars($texte['products_short_description'], NULL, '') . "</SHORTDESCRIPTION>" . $n .
            "                <METATITLE>" . htmlspecialchars($seo['meta_title'], NULL, '') . "</METATITLE>" . $n .
            "                <METADESCRIPTION>" . htmlspecialchars($seo['meta_description'], NULL, '') . "</METADESCRIPTION>" . $n .
            "                <METAKEYWORDS>" . htmlspecialchars($seo['meta_keywords'], NULL, '') . "</METAKEYWORDS>" . $n .
            "                <URL>" . htmlspecialchars($texte['products_url'], NULL, '') . "</URL>" . $n .
            "            </TEXT>" . $n;
        }
        echo "        </TEXTE>" . $n .
        "        <PREISE>" . $n;
        $texte_query->close();
        $seo_query->close();

        $cmd = "select customers_status_id from " . TABLE_CUSTOMERS_STATUS;
        $ss_query = $mysqli->query($cmd);
        while ($ss = $ss_query->fetch_array()) {
            $cmd = "select discount_quantity, price from " . TABLE_PRODUCTS_PRICE_GROUP . $ss['customers_status_id'] .
                    " where products_id=" . $artikel['products_id'];
            $preise_query = $mysqli->query($cmd) or die($mysqli->error);
            while ($preise = $preise_query->fetch_array()) {
                echo "            <PREIS>" . $n .
                "                <GRUPPE>" . $ss['customers_status_id'] . "</GRUPPE>" . $n .
                "                <MENGE>" . $preise['discount_quantity'] . "</MENGE>" . $n .
                "                <PREIS>" . $preise['price'] . "</PREIS>" . $n .
                "            </PREIS>" . $n;
            }
        }
        echo "        </PREISE>" . $n .
        "        <GEWICHT>" . $artikel['products_weight'] . "</GEWICHT>" . $n .
        "        <EAN>" . htmlspecialchars($artikel['products_ean'], NULL, '') . "</EAN>" . $n .
        "        <PREIS>" . $artikel['products_price'] . "</PREIS>" . $n .
        "        <MENGE>" . round($artikel['products_quantity'], 0) . "</MENGE>" . $n .
        "        <STATUS>" . $artikel['products_status'] . "</STATUS>" . $n .
        "        <STEUERSATZ>" . $artikel['products_tax_class_id'] . "</STEUERSATZ>\n" .
        "        <HERSTELLER_ID>" . $artikel['manufacturers_id'] . "</HERSTELLER_ID>" . $n .
        "        <KATEGORIEN>" . $n;
        $preise_query->close();
        $ss_query->close();
        $cmd = "SELECT categories_id FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE products_id = $artikel[products_id]";
        $cats_query = $mysqli->query($cmd);
        while ($cats = $cats_query->fetch_array()) {
            echo "            <KATEGORIE>" . $cats['categories_id'] . "</KATEGORIE>" . $n;
        }
        echo "        </KATEGORIEN>" . $n;
        $cats_query->close();
        $bildname = $artikel['products_image'];
        $bild = '';
        $pfad = "../" . _SRV_WEB_IMAGES . _DIR_ORG;
        if ($bildname != '' && file_exists($pfad . $bildname)) {
            $bild = @implode("", @file($pfad . $bildname));
        }

        if (!$SkipImages) {
            echo "        <BILDDATEI>" . htmlspecialchars($artikel['products_image'], NULL, '') . "</BILDDATEI>" . $n .
            "        <BILD>" . base64_encode($bild) . "</BILD>" . $n;
            $cmd = "SELECT L.m_id, L.link_id, L.class, L.type, file FROM " . TABLE_MEDIA_LINK . " L " .
                    "INNER JOIN " . TABLE_MEDIA . " ON L.m_id = " . TABLE_MEDIA . ".id " .
                    "WHERE L.class='product' AND L.type='images' AND L.link_id='" . $artikel['products_id'] . "'";
            $bilder_query = $mysqli->query($cmd) or die($mysqli->error);
            while ($bilder = $bilder_query->fetch_array()) {
                $bildname = $bilder['file'];
                $bild = '';
                if ($bildname != '' && file_exists($pfad . $bildname)) {
                    $bild = @implode("", @file($pfad . $bildname));
                    echo "        <IMAGES>" . $n .
                    "            <IMAGE>" . $n .
                    "                <NAME>" . htmlspecialchars($bildname, NULL, '') . "</NAME>" . $n .
                    "                <BILD>" . base64_encode($bild) . "</BILD>" . $n .
                    "            </IMAGE>" . $n .
                    "        </IMAGES>\n";
                }
            }
            $bilder_query->close();
        }

        $cmd = "select status_name from " . TABLE_SYSTEM_STATUS_DESCRIPTION . "," . TABLE_PRODUCTS .
                " where status_id = products_shippingtime AND products_id =" . $artikel['products_id'] . " AND language_code = 'de'";
        $shipping_time_query = $mysqli->query($cmd) or die($mysqli->error);
        $shipping_time = $shipping_time_query->fetch_array();
        echo "        <LIEFERSTATUSTEXT>" . htmlspecialchars($shipping_time['status_name'], NULL, '') . "</LIEFERSTATUSTEXT>" . $n;
//            "        <STARTSEITE>".$artikel['products_startpage']."</STARTSEITE>" . $n;
        $shipping_time_query->close();
        if ($artikel['products_vpe_status'] == 1) {
            echo "        <VPEValue>" . $artikel['products_vpe_value'] . "</VPEValue>" . $n;
        }
        echo "    </ARTIKEL_DATA>" . $n;
    }
    $artikel_query->close();
    echo "</ARTIKEL>" . $n;
}

// - - - Artikel-Löschen - - -
function deleteArtikel() {
    global $action, $version_major, $version_minor, $version_datum, $mysqli, $n;

    $Artikel_ID = (integer) ($_POST['Artikel_ID']);
    $erg = bildloschen($Artikel_ID);
    if ($erg) {
        $cmd = " SELECT m.id, m.file FROM " . TABLE_MEDIA . " m, " . TABLE_PRODUCTS . " p, " . TABLE_MEDIA_TO_MEDIA_GALLERY . " mmg
                WHERE p.products_id = '$Artikel_ID' AND m.file = p.products_image AND m.id = mmg.m_id";
        $equery = $mysqli->query($cmd);
        while ($erg1 = $equery->fetch_array()) {
            $mysqli->query("delete from " . TABLE_MEDIA . " where id = '" . $erg1['id'] . "' AND type = 'images'");
            $mysqli->query("delete from " . TABLE_MEDIA_TO_MEDIA_GALLERY . " where m_id = '" . $erg1['id'] . "' and mg_id = 2");
        }
    }

    $bilddatei = bilderloschen($Artikel_ID);
    if (count($bilddatei) > 0) {
        for ($i = 0; $i < count($bilddatei); $i++) {
            echo $bilddatei[$i]['id'] . " -> id ";
            $mysqli->query("delete from " . TABLE_MEDIA . " where id = '" . $bilddatei[$i]['id'] . "' AND type = 'images'");
            $mysqli->query("delete from " . TABLE_MEDIA_LINK . " where m_id = '" . $bilddatei[$i]['id'] . "' and type = 'images'");
            $mysqli->query("delete from " . TABLE_MEDIA_TO_MEDIA_GALLERY . " where m_id = '" . $bilddatei[$i]['id'] . "' and mg_id = 2");
        }
    }
    $mysqli->query("DELETE FROM " . TABLE_PRODUCTS . " WHERE products_id='" . $Artikel_ID . "'");
    $mysqli->query("DELETE FROM " . TABLE_PRODUCTS_PRICE_SPECIAL . " WHERE products_id='" . $Artikel_ID . "'");

    $cmd = "select distinct(customers_status_id) from " . TABLE_CUSTOMERS_STATUS;
    $ss_query = $mysqli->query($cmd);
    while ($ss = $ss_query->fetch_array()) {
        $mysqli->query("delete from xt_products_price_group_all where products_id = '$Artikel_ID'");
    }
    $mysqli->query("DELETE FROM xt_products_price_group_all WHERE products_id='" . $Artikel_ID . "'");
    $mysqli->query("DELETE FROM " . TABLE_PRODUCTS_DESCRIPTION . " WHERE products_id='" . $Artikel_ID . "'");
    $mysqli->query("DELETE FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE products_id='" . $Artikel_ID . "'");
    $mysqli->query("DELETE FROM " . TABLE_PRODUCTS_CROSS_SELL . " WHERE products_id='" . $Artikel_ID
            . "' OR products_id_cross_sell='" . $Artikel_ID . "'");
    $mysqli->query("DELETE FROM " . TABLE_PRODUCTS_SERIAL . " WHERE products_id='" . $Artikel_ID . "'");
    $mysqli->query("DELETE FROM " . TABLE_SEO_URL . " WHERE link_type='1' AND link_id='" . $Artikel_ID . "'");
    $ss_query->close();

    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . "\n" .
    "<STATUS>\n" .
    "    <STATUS_DATA>" . $n;
    "        <MESSAGE>OK</MESSAGE>" . $n;
    "        <SCRIPT_VERSION_MAJOR>$version_major</SCRIPT_VERSION_MAJOR>" . $n;
    "        <SCRIPT_VERSION_MINOR>$version_minor</SCRIPT_VERSION_MINOR>\n" . $n;
    "        <SCRIPT_DATE>$version_datum</SCRIPT_DATE>" . $n;
    "    </STATUS_DATA>" . $n;
    "</STATUS>" . $n . $n;
}

// - - - Bestellungen abrufen - - -
function ordersExport() {
    global $n, $hk, $mysqli;
    if (isset($_GET['order_from']) ? $order_from = (int) ($_GET['order_from']) : $order_from = 0);

    $cmd = "SELECT * FROM " . TABLE_ORDERS . " where orders_id >= " . $hk . $order_from . $hk;
    $result = $mysqli->query($cmd);

    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    '<ORDER>' . $n;
    while ($orders = $result->fetch_array()) {
        echo '    <ORDER_INFO>' . $n .
        '        <ORDER_HEADER>' . $n .
        '            <ORDER_ID>' . $orders['orders_id'] . '</ORDER_ID>' . $n .
        '            <FREIFELD1>' . $orders['orders_id'] . '</FREIFELD1>' . $n .
        '            <CUSTOMER_ID>' . $orders['customers_id'] . '</CUSTOMER_ID>' . $n .
        '            <CUSTOMER_CID>' . $orders['customers_cid'] . '</CUSTOMER_CID>' . $n .
        '            <CUSTOMER_GROUP>' . $orders['customers_status'] . '</CUSTOMER_GROUP>' . $n .
        '            <ORDER_DATE>' . $orders['date_purchased'] . '</ORDER_DATE>' . $n .
        '            <ORDER_STATUS>' . $orders['orders_status'] . '</ORDER_STATUS>' . $n .
        '            <ORDER_IP>' . $orders['customers_ip'] . '</ORDER_IP>' . $n .
        '            <ORDER_CURRENCY>' . htmlspecialchars($orders['currency_code'], NULL, '') . '</ORDER_CURRENCY>' . $n .
        '            <ORDER_CURRENCY_VALUE>' . $orders['currency_value'] . '</ORDER_CURRENCY_VALUE>' . $n .
        '        </ORDER_HEADER>' . $n .
        '        <BILLING_ADDRESS>' . $n;
        if (htmlspecialchars($orders['billing_gender']) == "m") {
            $billing_gender = "Herr";
        } else if (htmlspecialchars($orders['billing_gender']) == "f") {
            $billing_gender = "Frau";
        } else if (htmlspecialchars($orders['billing_gender']) == "c") {
            $billing_gender = "Firma";
        } else {
            $billing_gender = "";
        }
        echo '            <GENDER>' . $billing_gender . '</GENDER>' . $n .
        '            <FIRSTNAME>' . htmlspecialchars($orders['billing_firstname'], NULL, '') . '</FIRSTNAME>' . $n .
        '            <LASTNAME>' . htmlspecialchars($orders['billing_lastname'], NULL, '') . '</LASTNAME>' . $n .
        '            <COMPANY>' . htmlspecialchars($orders['billing_company'], NULL, '') . '</COMPANY>' . $n .
        '            <COMPANY2>' . htmlspecialchars($orders['billing_company_2'], NULL, '') . " " . htmlspecialchars($orders['billing_company_3'], NULL, '') . '</COMPANY2>' . $n .
        '            <STREET>' . htmlspecialchars($orders['billing_street_address'], NULL, '') . '</STREET>' . $n .
        '            <CITY>' . htmlspecialchars($orders['billing_city'], NULL, '') . " " . htmlspecialchars($orders['billing_suburb'], NULL, '') . '</CITY>' . $n .
        '            <ZIP>' . htmlspecialchars($orders['billing_postcode'], NULL, '') . '</ZIP>' . $n .
        '            <ZONE>' . htmlspecialchars($orders['billing_zone'], NULL, '') . '</ZONE>' . $n .
        '            <ZONE_CODE>' . htmlspecialchars($orders['billing_zone_code'], NULL, '') . '</ZONE_CODE>' . $n .
        '            <COUNTRY>' . htmlspecialchars($orders['billing_country'], NULL, '') . '</COUNTRY>' . $n .
        '            <COUNTRY_CODE>' . htmlspecialchars($orders['billing_country_code'], NULL, '') . '</COUNTRY_CODE>' . $n .
        '            <EMAIL>' . htmlspecialchars($orders['customers_email_address'], NULL, '') . '</EMAIL>' . $n .
        '            <TELEPHONE>' . htmlspecialchars($orders['billing_phone'], NULL, '') . '</TELEPHONE>' . $n .
        '            <FAX>' . htmlspecialchars($orders['billing_fax'], NULL, '') . '</FAX>' . $n .
        '            <UID>' . htmlspecialchars($orders['customers_vat_id'], NULL, '') . '</UID>' . $n;
        $query_dob = "select customers_dob from " . TABLE_CUSTOMERS_ADDRESSES . " where address_book_id = " . $hk . $orders['billing_address_book_id'] . $hk;
        $result_dob = $mysqli->query($query_dob);
        $orders_dob = $result_dob->fetch_array();
        echo '            <DOB>' . $orders_dob['customers_dob'] . '</DOB>' . $n;
        $result_dob->close();
        echo '        </BILLING_ADDRESS>' . $n .
        '        <DELIVERY_ADDRESS>' . $n;
        if (htmlspecialchars($orders['delivery_gender']) == "m") {
            $delivery_gender = "Herr";
        } else if (htmlspecialchars($orders['delivery_gender']) == "f") {
            $delivery_gender = "Frau";
        } else if (htmlspecialchars($orders['delivery_gender']) == "c") {
            $delivery_gender = "Firma";
        } else {
            $delivery_gender = "";
        }
        echo '            <GENDER>' . $delivery_gender . '</GENDER>' . $n .
        '            <FIRSTNAME>' . htmlspecialchars($orders['delivery_firstname'], NULL, '') . '</FIRSTNAME>' . $n .
        '            <LASTNAME>' . htmlspecialchars($orders['delivery_lastname'], NULL, '') . '</LASTNAME>' . $n .
        '            <COMPANY>' . htmlspecialchars($orders['delivery_company'], NULL, '') . '</COMPANY>' . $n .
        '            <COMPANY2>' . htmlspecialchars($orders['delivery_company_2'], NULL, '') . " " . htmlspecialchars($orders['delivery_company_3'], NULL, '') . '</COMPANY2>' . $n .
        '            <STREET>' . htmlspecialchars($orders['delivery_street_address'], NULL, '') . '</STREET>' . $n .
        '            <CITY>' . htmlspecialchars($orders['delivery_city'], NULL, '') . " " . htmlspecialchars($orders['delivery_suburb'], NULL, '') . '</CITY>' . $n .
        '            <ZIP>' . htmlspecialchars($orders['delivery_postcode'], NULL, '') . '</ZIP>' . $n .
        '            <ZONE>' . htmlspecialchars($orders['delivery_zone'], NULL, '') . '</ZONE>' . $n .
        '            <ZONE_CODE>' . htmlspecialchars($orders['delivery_zone_code'], NULL, '') . '</ZONE_CODE>' . $n .
        '            <COUNTRY>' . htmlspecialchars($orders['delivery_country'], NULL, '') . '</COUNTRY>' . $n .
        '            <COUNTRY_CODE>' . htmlspecialchars($orders['delivery_country_code'], NULL, '') . '</COUNTRY_CODE>' . $n .
        '            <TELEPHONE>' . htmlspecialchars($orders['delivery_phone'], NULL, '') . '</TELEPHONE>' . $n .
        '            <FAX>' . htmlspecialchars($orders['delivery_fax'], NULL, '') . '</FAX>' . $n .
        '        </DELIVERY_ADDRESS>' . $n;
        echo '        <PAYMENT>' . $n .
        '            <PAYMENT_CODE>' . htmlspecialchars($orders['payment_code'], NULL, '') . '</PAYMENT_CODE>' . $n;

        switch ($orders['payment_code']) {
            case 'xt_banktransfer':
                $a = $orders['orders_data'];
                $a = unserialize($a);

                echo '            <PAYMENT_BANKTRANSFER_OWNER>' . htmlspecialchars($a['banktransfer_owner'], NULL, '') . '</PAYMENT_BANKTRANSFER_OWNER>' . $n .
                '            <PAYMENT_BANKTRANSFER_OWNER>' . htmlspecialchars($a['banktransfer_owner'], NULL, '') . '</PAYMENT_BANKTRANSFER_OWNER>' . $n .
                '            <PAYMENT_BANKTRANS_BNAME>' . htmlspecialchars($a['banktransfer_bank_name'], NULL, '') . '</PAYMENT_BANKTRANS_BNAME>' . $n .
                '            <PAYMENT_BANKTRANS_BLZ>' . htmlspecialchars($a['banktransfer_blz'], NULL, '') . '</PAYMENT_BANKTRANS_BLZ>' . $n .
                '            <PAYMENT_BANKTRANS_NUMBER>' . htmlspecialchars($a['banktransfer_number'], NULL, '') . '</PAYMENT_BANKTRANS_NUMBER>' . $n .
                '            <PAYMENT_BANKTRANS_BIC>' . htmlspecialchars($a['banktransfer_bic'], NULL, '') . '</PAYMENT_BANKTRANS_BIC>' . $n .
                '            <PAYMENT_BANKTRANS_IBAN>' . htmlspecialchars($a['banktransfer_iban'], NULL, '') . '</PAYMENT_BANKTRANS_IBAN>' . $n;
                break;
            case 'xt_paypal':
            case 'xt_payments':
                echo '            <PAYPAL_TXNID>' . htmlspecialchars($orders['orders_data'], NULL, '') . '</PAYPAL_TXNID>' . $n;
                break;
        }
        echo '        </PAYMENT>' . $n;
        $cmd = "SELECT * from xt_tracking, xt_shipper b WHERE tracking_order_id = '{$orders['orders_id']}' AND tracking_shipper_id = b.id ORDER BY `tracking_added` DESC";
        $query = $mysqli->query($cmd);
        echo '        <SHIPPING>' . $n .
            '            <SHIPPING_CODE>' . htmlspecialchars($orders['shipping_code'], NULL, '') . '</SHIPPING_CODE>' . $n;
        if ($tx_resultat = $query->fetch_array()) {
            echo '            <tracking_code>' .htmlspecialchars($tx_resultat['tracking_code']) . '</tracking_code>' . $n .
            '            <tracking_added>' .htmlspecialchars($tx_resultat['tracking_added']) . '</tracking_added>' . $n .
            '            <shipper_name>' .  htmlspecialchars($tx_resultat['shipper_name'], NULL, '') .'</shipper_name>' . $n;
        }
            echo '        </SHIPPING>' . $n .
            '        <ORDER_PRODUCTS>' . $n;
        $cmd = "SELECT customers_status_show_price_tax FROM " . TABLE_CUSTOMERS_STATUS .
                " WHERE customers_status_id = '" . $orders['customers_status'] . "'";
        $query = $mysqli->query($cmd);
        $resulte = $query->fetch_array();
        $cmd1 = "select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $orders['orders_id'] . "'";
        $prod_query = $mysqli->query($cmd1);
        if ($resulte && $produkt = $prod_query->fetch_array()) {
            if (($resulte['customers_status_show_price_tax'] == 0 && $produkt['allow_tax'] == 0 && $produkt['products_tax'] <= 0))
                $tax_flag = '0';
            if (($resulte['customers_status_show_price_tax'] == 0 && $produkt['allow_tax'] == 0 && $produkt['products_tax'] > 0))
                $tax_flag = 'N';
            if (($resulte['customers_status_show_price_tax'] == 1 && $produkt['allow_tax'] == 1))
                $tax_flag = 'J';
            if (($resulte['customers_status_show_price_tax'] == 1 && $produkt['allow_tax'] == 0))
                $tax_flag = 'N';
        }
        echo "        <TAX_FLAG>$tax_flag</TAX_FLAG>\n";

        $query_prod = "select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $orders['orders_id'] . "'";
        $result_prod = $mysqli->query($query_prod);
        while ($products = $result_prod->fetch_array()) {
            echo '        <PRODUCT>' . $n .
            '            <PRODUCTS_ID>' . $products['products_id'] . '</PRODUCTS_ID>' . $n .
            '            <PRODUCTS_QUANTITY>' . $products['products_quantity'] . '</PRODUCTS_QUANTITY>' . $n .
            '            <PRODUCTS_MODEL>' . htmlspecialchars($products['products_model'], NULL, '') . '</PRODUCTS_MODEL>' . $n .
            '            <PRODUCTS_NAME>' . htmlspecialchars($products['products_name'], NULL, '') . '</PRODUCTS_NAME>' . $n .
            '            <PRODUCTS_TAX>' . $products['products_tax'] . '</PRODUCTS_TAX>' . $n;
            if ($products['allow_tax'] == 1) {
                $steuer = ($products['products_tax'] * 0.01) + 1;
                $epreis = $products['products_price'] * $steuer;
            echo '            <PRODUCTS_EPRICE>' . $epreis . '</PRODUCTS_EPRICE>' . $n;
            } else {
                echo '            <PRODUCTS_EPRICE>' . $products['products_price'] . '</PRODUCTS_EPRICE>' . $n;
            }

            echo '            <PRODUCTS_TAX_CLASS>' . $products['products_tax_class'] . '</PRODUCTS_TAX_CLASS>' . $n .
            '            <PRODUCTS_DISCOUNT>' . $products['products_discount'] . '</PRODUCTS_DISCOUNT>' . $n .
            '        </PRODUCT>' . $n;
        }
        $result_prod->close();
        echo '        </ORDER_PRODUCTS>' . $n .
        '        <ORDER_TOTAL>' . $n;
        $query_total = "select * from " . TABLE_ORDERS_TOTAL . " where orders_id = " . $hk . $orders['orders_id'] . $hk;
        $result_total = $mysqli->query($query_total);
        while ($totals = $result_total->fetch_array()) {
            echo '            <TOTAL>' . $n .
            '                <TOTAL_KEY_ID>' . htmlspecialchars($totals['orders_total_key_id'], NULL, '') . '</TOTAL_KEY_ID>' . $n .
            '                <TOTAL_MODEL>' . htmlspecialchars($totals['orders_total_model'], NULL, '') . '</TOTAL_MODEL>' . $n;
            (($totals['orders_total_model'] == 'xt_cashondelivery') ?
                $totals['orders_total_key'] = 'ot_cod_fee' : $totals['orders_total_key'] = get_ot_class(htmlspecialchars($totals['orders_total_key'])));
            if ($tax_flag == 'J' ) {
                $totals_steuer = ($totals['orders_total_tax'] * 0.01) + 1;
                $totals_price = $totals['orders_total_price'] * $totals_steuer;
            } else {
                $totals_price = $totals['orders_total_price'];
            }
            echo '                <TOTAL_NAME>' . htmlspecialchars($totals['orders_total_name'], NULL, '') . '</TOTAL_NAME>' . $n .
            '                <TOTAL_PRICE>' . $totals_price . '</TOTAL_PRICE>' . $n .
            '                <TOTAL_KEY>' . $totals['orders_total_key'] . '</TOTAL_KEY>' . $n .
            '                <TOTAL_TAX>' . htmlspecialchars($totals['orders_total_tax'], NULL, '') . '</TOTAL_TAX>' . $n .
            '                <TOTAL_TAX_CLASS>' . htmlspecialchars($totals['orders_total_tax_class'], NULL, '') . '</TOTAL_TAX_CLASS>' . $n .
            '                <TOTAL_QUANTITY>' . htmlspecialchars($totals['orders_total_quantity'], NULL, '') . '</TOTAL_QUANTITY>' . $n .
            '                <TOTAL_ALLOW_TAX>' . htmlspecialchars($totals['allow_tax'], NULL, '') . '</TOTAL_ALLOW_TAX>' . $n .
            '            </TOTAL>' . $n;
        }
        echo '        </ORDER_TOTAL>' . $n;
        $result_total->close();
        $cmd = "select * from " . TABLE_ORDERS_STATS . " where orders_id = " . $orders['orders_id'];
        $resultsumme = $mysqli->query($cmd);
        if ($summe = $resultsumme->fetch_array()) {
            echo "        <ORDER_SUMME>" . $summe['orders_stats_price'] . "</ORDER_SUMME>" . $n;
        }
        $resultsumme->close();
        echo '        <ORDER_COMMENTS>' . htmlspecialchars($orders['comments'], NULL, '') . '</ORDER_COMMENTS>' . $n .
        '    </ORDER_INFO>' . $n;
    }
    echo '</ORDER>' . $n;
    $result->close();
}

// - - - xtc4 Klassenbezeichnung in xtc3 ot_Klasse umbenennen - - -
function get_ot_class($ot) {
    If ($ot == "shipping") {
        $otc = "ot_shipping";
    } elseif ($ot == "Coupon/Gutschein") {
        $otc = "ot_coupon";
    } elseif ($ot == "discount") {
        $otc = "ot_discount";
    } elseif ($ot == "loworderfee") {
        $otc = "ot_loworderfee";
    } elseif ($ot == "gv") {
        $otc = "ot_gv";
    } elseif ($ot == "total") {
        $otc = "ot_total";
    } elseif ($ot == "fixcod") {
        $otc = "ot_fixcod";
    } elseif ($ot == "cod_fee") {
        $otc = "ot_cod_fee";
    } elseif ($ot == "payment") {
        $otc = "ot_payment";
    } else {
        $otc = "ot_shipping";
    }
    return $otc;
}

// - - - Auftragsstatus setzen - - -
function orderUpdate() {
    global $action, $LangID, $version_major, $version_minor, $n, $hk, $mysqli;
    $Order_ID = (integer) ($_POST['Order_id']);
    $Status = (integer) ($_POST['Status']);
    $Sendungsnummer = $_POST['Sendungsnummer'];
    $Sendungsdienstleister = $_POST['Sendungsdienstleister'];
    $StatusText = "";

    if ($Status == 2) {
        $xtStatus = 17;
        $StatusText = "Auftrag in Bearbeitung.";
    } else if ($Status == 3) {
        $xtStatus = 46;
        $StatusText = "Bestellung Abgeschlossen.";
    }
    $btime = aftime();
    $orders_array = array('orders_status' => $xtStatus, 'last_modified' => $btime); //Fehler gefunden: xtStatus muss stehen und nicht Status
    db_insert(TABLE_ORDERS, $orders_array, 'update', " orders_id = " . $Order_ID);

    $cmd = "SELECT orders_id, customers_email_address, billing_gender, billing_firstname,
        billing_lastname, date_purchased, shop_id
            FROM " . TABLE_ORDERS . " WHERE orders_id = " . $Order_ID;
    $result = $mysqli->query($cmd) or die($mysqli->error);
    $order = $result->fetch_array();
    
    if (!empty($Sendungsnummer) && $Status == 3) {
        $cmd = "SELECT * from xt_shipper WHERE shipper_name LIKE '%{$Sendungsdienstleister}%' ";
        $query = $mysqli->query($cmd) or die($mysqli->error);
        $parcel = $query->fetch_array();
        if ($parcel) {
            $url = str_replace('[TRACKING_CODE]', $Sendungsnummer, $parcel['shipper_tracking_url']);
            $insert_tracking_data = array('tracking_shipper_id' => $parcel['id'],
                                    'tracking_code'=>$Sendungsnummer,
                                    'tracking_order_id' => $Order_ID,
                                    'tracking_status_id' => 1,
                                    'tracking_added' => $btime
                                );
            db_insert('xt_tracking', $insert_tracking_data);
            $tx_text = "Die Sendungsverfolgung für Ihre Bestellung können Sie über den unten stehenden Link aufrufen: \n {$url} \n";
            $p_status = true;
        }
    }

    $cmd = "SELECT config_value FROM " . TABLE_CONFIGURATION_MULTI . $order['shop_id'] .
            " WHERE config_key = '_STORE_CONTACT_EMAIL'";
    $result = $mysqli->query($cmd) or die($mysqli->error);
    $conf_mail = $result->fetch_array();

    $cmd = "SELECT config_value FROM " . TABLE_CONFIGURATION_MULTI . $order['shop_id'] .
            " WHERE config_key = '_STORE_EMAIL_FOOTER_TXT'";

    $result = $mysqli->query($cmd) or die($mysqli->error);
    $conf_txt = $result->fetch_array();

    $notified = 0;
    // $mail_absender = $store['_STORE_CONTACT_EMAIL'];
    $mail_absender = $conf_mail['config_value'];

    // $mail_empfaenger = $conf_mail['config_value'];
    /* (versendet Emails bei Auftragsbearbeitung) $mail_empfaenger = $order['customers_email_address'];
    $mail_footer = $conf_txt['config_value'];

    if ($order['billing_gender'] == "m") {
        $anrede = "Sehr geehrter Herr ";
    } else if ($order['billing_gender'] == "f") {
        $anrede = "Sehr geehrte Frau ";
    } else {
        $anrede = "Hallo ";
    }

    if ($order['customers_email_address'] <> "") {
        $betreff = "Ihre Bestellung Nr." . $Order_ID;
        $text = "\n" . $anrede . $order['billing_firstname'] . " " . $order['billing_lastname'] . ",\n"
                . "\nDer Status Ihrer Bestellung hat sich ge�ndert.\n Neuer Status: " . $StatusText ."\n";
        if ($p_status) {
            $text .= "\n{$tx_text}\n";
        }
        $text .= "\n" . $mail_footer;
      
        mail($mail_empfaenger, $betreff, $text, "from:$mail_absender");
        $notified = 1;
    }*/

    $orders_status_array = array('orders_id' => $Order_ID,
                            'orders_status_id' => $xtStatus,
                            'date_added' => $btime,
                            'customer_notified' => $notified,
                            'comments' => $StatusText,
                            'change_trigger' => 'Amicron Faktura',
                            'callback_id' => '0'
                        );
    db_insert(TABLE_ORDERS_STATUS_HISTORY, $orders_status_array);
    $result->close();

    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
    "<STATUS>" . $n .
    "  <STATUS_DATA>" . $n .
    "    <MESSAGE>OK</MESSAGE>" . $n .
    "    <ORDER_ID>$Order_ID</ORDER_ID>" . $n .
    "    <ORDER_STATUS>$Status</ORDER_STATUS>" . $n .
    "     <SCRIPT_VERSION_MAJOR>$version_major</SCRIPT_VERSION_MAJOR>" . $n .
    "    <SCRIPT_VERSION_MINOR>$version_minor</SCRIPT_VERSION_MINOR>" . $n .
    "  </STATUS_DATA>" . $n .
    "</STATUS>" . $n . $n;
}

// - - - Artikel-Export - - -
function writeArtikel() {
    global $action, $version_major, $version_minor, $version_datum, $mysqli;

    $ExportModus = $_POST['ExportModus'];

    $Hersteller_ID = (integer) ($_POST['Hersteller_ID']);
    $Artikel_Artikelnr = $_POST['Artikel_Artikelnr'];
    $Artikel_Menge = $_POST['Artikel_Menge'];
    $Artikel_Preis = $_POST['Artikel_Preis'];
    $Artikel_Gewicht = $_POST['Artikel_Gewicht'];
    $Artikel_Status = $_POST['Artikel_Status'];
    $Artikel_Steuersatz = $_POST['Artikel_Steuersatz'];
    $Artikel_Bilddatei = $_POST['Artikel_Bilddatei'];
    $Artikel_EAN = $_POST['Artikel_EAN'];
    $Artikel_Freifeld1 = $_POST['Artikel_Freifeld1'];
    $Artikel_Freifeld2 = $_POST['Artikel_Freifeld2'];
    $Artikel_Freifeld3 = $_POST['Artikel_Freifeld3'];
    $Artikel_Freifeld4 = $_POST['Artikel_Freifeld4'];
    $Artikel_Freifeld5 = $_POST['Artikel_Freifeld5'];
    $Artikel_Freifeld6 = $_POST['Artikel_Freifeld6'];
    $Artikel_Freifeld7 = $_POST['Artikel_Freifeld7'];
    $Artikel_Freifeld8 = $_POST['Artikel_Freifeld8'];
    $Artikel_Freifeld9 = $_POST['Artikel_Freifeld9'];
    $Artikel_Freifeld10 = $_POST['Artikel_Freifeld10'];
    $Artikel_Freifeld11 = $_POST['Artikel_Freifeld11'];
    $Artikel_Freifeld12 = $_POST['Artikel_Freifeld12'];
    $Artikel_Freifeld13 = $_POST['Artikel_Freifeld13'];
    $Artikel_Freifeld14 = $_POST['Artikel_Freifeld14'];
    $Artikel_Freifeld15 = $_POST['Artikel_Freifeld15'];
    $Artikel_Freifeld16 = $_POST['Artikel_Freifeld16'];
    $Artikel_Freifeld17 = $_POST['Artikel_Freifeld17'];
    $Artikel_Freifeld18 = $_POST['Artikel_Freifeld18'];
    $Artikel_Freifeld19 = $_POST['Artikel_Freifeld19'];
    $Artikel_Freifeld20 = $_POST['Artikel_Freifeld20'];
    $Artikel_Lieferstatus = (integer) ($_POST['Artikel_Lieferstatus']);
    //$Artikel_Startseite = (integer)($_POST['Artikel_Startseite']);
    $SkipImages = (bool) ($_POST['SkipImages']);
    $Artikel_ID = (integer) ($_POST['Artikel_ID']);
    $sql_data_array = array();

    if (isset($_POST['Artikel_Lieferstatustext']) && $ExportModus == 'Overwrite') {
        $Artikel_Lieferstatustext = $_POST['Artikel_Lieferstatustext'];
        $cmd = "select a.status_id, a.status_name, b.status_class from " . TABLE_SYSTEM_STATUS_DESCRIPTION . " a, " . TABLE_SYSTEM_STATUS . " b where
                a.status_id = b.status_id AND b.status_class = 'shipping_status' AND a.status_name = '$Artikel_Lieferstatustext'";
        $shipping_time_query = $mysqli->query($cmd) or die($mysqli->error);
        $shipping_time = $shipping_time_query->fetch_array();
        if (!$shipping_time) {
            $insert_system_status = array('status_class' => 'shipping_status');
            db_insert(TABLE_SYSTEM_STATUS, $insert_system_status);
            $status_id = $mysqli->insert_id;
            $insert_status_description = array('status_id' => $status_id, 'language_code' => 'de', 'status_name' => $Artikel_Lieferstatustext);
            db_insert(TABLE_SYSTEM_STATUS_DESCRIPTION, $insert_status_description);
            $sql_data_array['products_shippingtime'] = $status_id;
            $Artikel_Lieferstatus = $sql_data_array['products_shippingtime'];
        } else {
            $sql_data_array['products_shippingtime'] = $shipping_time['status_id'];
            $Artikel_Lieferstatus = $sql_data_array['products_shippingtime'];
        }
    } else {
        $sql_data_array['products_shippingtime'] = $Artikel_Lieferstatus;
    }

    $Artikel_Kategorien = array();
    $i = 1;
    while (isset($_POST["Artikel_KategorieID{$i}"])) {
        $Artikel_Kategorien[$i] = (integer) ($_POST["Artikel_KategorieID{$i}"]);
        $i++;
    }

    $Artikel_Texte = array();
    $i = 1;
    while (isset($_POST["Artikel_Bezeichnung{$i}"])) {

        $Artikel_Texte[$i] = array('B' => htmlspecialchars($_POST["Artikel_Bezeichnung{$i}"], NULL, ''),
            'T' => $_POST["Artikel_Text{$i}"],
            'S' => $_POST["Artikel_Kurztext{$i}"],
            'L' => (integer) ($_POST["Artikel_TextLanguage{$i}"]),
            'MT' => htmlspecialchars($_POST["Artikel_MetaTitle{$i}"], NULL, ''),
            'MD' => htmlspecialchars($_POST["Artikel_MetaDescription{$i}"], NULL, ''),
            'MK' => htmlspecialchars($_POST["Artikel_MetaKeywords{$i}"], NULL, ''),
            'URL' => $_POST["Artikel_URL{$i}"]
        );
        $i++;
    }

    $Artikel_Preise = array();
    $AnzahlPreisGrp = 0;
    $i = 1;
    while (isset($_POST["Artikelpreise_Preis{$i}"])) {
        $Artikel_Preise[$i] = array(
            'P' => $_POST["Artikelpreise_Preis{$i}"],
            'G' => 1,
            'M' => (integer) $_POST["Artikelpreise_Menge{$i}"],
            'Index' => $i
        );
        $AnzahlPreisGrp = $i;
        $i++;
    }

    $exists = FALSE;
    $mode = 'NONE';
    $cmd = "SELECT products_id, products_model FROM " . TABLE_PRODUCTS . " WHERE products_model = '" . $Artikel_Artikelnr . "'";

    // if ($Artikel_ID == 0) {

    $products_model_query = $mysqli->query($cmd);
    if ($products_model_query) {
        $products_model = $products_model_query->fetch_array();
        if ($products_model) {
            $exists = TRUE;
            $mode = 'UPDATED';
            $Artikel_ID = $products_model['products_id'];
        } else {
            $exists = FALSE;
            $mode = 'INSERTED';
        }
    }
    $cmd = "SELECT * from " . TABLE_MANDANT_CONFIG . " where shop_title ='Main Store'";
    
    //$cmd = "SELECT shop_id from ". TABLE_MANDANT_CONFIG . " where shop_titel = 'Main Store'";
    /*$store_id_query = $mysqli->query($cmd);
    $store_id = $store_id_query->fetch_array();
    if ($store_id) {
        $store_id = $store_id['shop_id'];
    } else {
        $store_id = 1;
    }*/
    
    //multistore mod JCP
    if (isset($_GET['store_id'])) {
        $store_id = $_GET['store_id'];
    } else {
        $store_id = 1;
    }
    
    // sofern es kein Datensatz gibt, oder er �berschrieben werden kann, weitermachen
    if (!$exists || $ExportModus != 'NoOverwrite') {
        // Array nur komplett f�llen, wenn ein Insert oder ein Komplettes Update
        // durchgef�hrt wird (und nicht nur der Preis)
        $btime = aftime();
        if (!$exists || $ExportModus == 'Overwrite' or 'PriceAndQuantityOnly') {
            
            $Artikel_Freifeld1 = str_replace(',', '.', $_POST['Artikel_Freifeld1']);
            
            $sql_data_array = array(
                'products_id' => $Artikel_ID,
                'permission_id' => $Artikel_ID,
                'products_price' => $Artikel_Preis,
                'products_quantity' => $Artikel_Menge,
                'products_shippingtime' => $Artikel_Lieferstatus,
                'products_model' => $Artikel_Artikelnr,
                'products_weight' => $Artikel_Gewicht,
                'products_ean' => $Artikel_EAN,

                'products_refund_price' => $Artikel_Freifeld1 / 1.19,

// Englische Notation ohne Tausendergruppierung
//$english_format_number = number_format($number, 2, '.', '');
// 1234.57
                  
                'products_Freifeld2' => $Artikel_Freifeld2,
                'products_Freifeld3' => $Artikel_Freifeld3,
                'products_Freifeld4' => $Artikel_Freifeld4,
                'products_Freifeld5' => $Artikel_Freifeld5,
                'products_Freifeld6' => $Artikel_Freifeld6,
                'products_Freifeld8' => $Artikel_Freifeld8,
                'products_Freifeld9' => $Artikel_Freifeld9,
                'products_Freifeld10' => $Artikel_Freifeld10,
                'products_Freifeld11' => $Artikel_Freifeld11,
                'products_Freifeld12' => $Artikel_Freifeld12,
                'products_Freifeld13' => $Artikel_Freifeld13,
                'products_Freifeld14' => $Artikel_Freifeld14,
                'products_Freifeld15' => $Artikel_Freifeld15,
                'products_Freifeld16' => $Artikel_Freifeld16,
                'products_Freifeld17' => $Artikel_Freifeld17,
                'products_Freifeld18' => $Artikel_Freifeld18,
                'products_Freifeld19' => $Artikel_Freifeld19,
                'products_Freifeld20' => $Artikel_Freifeld20,
                
                'products_status' => "1",
                'products_tax_class_id' => $Artikel_Steuersatz,
                //    'products_startpage' => $Artikel_Startseite,
                'product_template' => "",
                'product_list_template' => "",
                'products_option_template' => "",
                'products_option_list_template' => "",
                'manufacturers_id' => $Hersteller_ID
            );

            for ($i = 1; $i <= $AnzahlPreisGrp; $i++) {
                foreach ($Artikel_Preise as $i => $APreis) {
                    if (isset($APreis['G']) && $APreis > 0) {
                        $sql_data_array["price_flag_graduated_all"] = 1;
                    } else {
                        $sql_data_array["price_flag_graduated_$APreis[G]"] = 0;
                    }
                }
            }

            if (!$SkipImages) {
                $sql_data_array['products_image'] = $Artikel_Bilddatei;
            }

            if (isset($_POST['Artikel_Grundeinheit']) && isset($_POST['Artikel_Masseinheit'])) {
                $sql_data_array['products_vpe_value'] = $_POST['Artikel_Grundgewicht'];
                $sql_data_array['products_vpe_status'] = 1;
                $cmd = "SELECT * from " . TABLE_SYSTEM_STATUS_DESCRIPTION . " where status_name LIKE '" . $_POST['Artikel_Masseinheit'] . "' AND language_code = 'de'";
                $vpe_query = $mysqli->query($cmd);
                if ($vpe_id = $vpe_query->fetch_array()) {
                    $sql_data_array['products_vpe'] = $vpe_id['status_id'];
                }
            }
            if (isset($_POST['Artikel_Mengeneinheit'])) {
                $cmd = "SELECT * from " . TABLE_SYSTEM_STATUS_DESCRIPTION . " where status_name LIKE '" . $_POST['Artikel_Mengeneinheit'] . "' AND language_code = 'de'";
                $sql_data_array['products_vpe_status'] = 1;
                $unit_query = $mysqli->query($cmd);
                if ($unit_id = $unit_query->fetch_array()) {
                    $sql_data_array['products_unit'] = $unit_id['status_id'];
                }
            }
        } else {
            if ($ExportModus == 'PriceOnly') {
                $sql_data_array = array();
                // nur der Preis wird ge�ndert
                $sql_data_array['products_price'] = $Artikel_Preis;
                for ($i = 1; $i <= $AnzahlPreisGrp; $i++) {
                    foreach ($Artikel_Preise as $i => $APreis) {
                        if (isset($APreis['G']) && $APreis > 0) {
                            $sql_data_array["price_flag_graduated_all"] = 1;
                        } else {
                            $sql_data_array["price_flag_graduated_$APreis[G]"] = 0;
                        }
                    }
                }
            }
            if ($ExportModus == 'QuantityOnly') {
                $sql_data_array = array();
                // nur die Menge wird ge�ndert
                $sql_data_array['products_quantity'] = $Artikel_Menge;
            }
            if ($ExportModus == 'PriceAndQuantityOnly') {
                $sql_data_array = array();
                // nur der Preis und die Menge wird ge�ndert
                $sql_data_array = array('products_quantity' => $Artikel_Menge,
                    'products_price' => $Artikel_Preis
                );
                for ($i = 1; $i <= $AnzahlPreisGrp; $i++) {
                    foreach ($Artikel_Preise as $i => $APreis) {
                        if (isset($APreis['G']) && $APreis > 0) {
                            $sql_data_array["price_flag_graduated_all"] = 1;
                        } else {
                            $sql_data_array["price_flag_graduated_$APreis[G]"] = 0;
                        }
                    }
                }
            }
        }

        if (!$exists) { // Neuanlage (ID wird an Amicron-Faktura zurueckgegeben !!!)
            $mode = 'INSERTED';

            $insert_sql_data = array('date_added' => $btime);
            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
            $sql_data_array = array_slice($sql_data_array, 1);
            db_insert(TABLE_PRODUCTS, $sql_data_array);
            $Artikel_ID = $mysqli->insert_id;
        } elseif ($exists || ($ExportModus == 'Overwrite')) {
            $mode = 'UPDATED';

            $update_sql_data = array('last_modified' => $btime);
            $sql_data_array = array_merge($sql_data_array, $update_sql_data);

            db_insert(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '$Artikel_ID'");
        }
    
        if (!$exists || $ExportModus == 'Overwrite') {
            //multistore Rechte setzen (Blacklist)
            if(!$exists){

                $cmd = "select shop_id from xt_stores";
                $store_query = $mysqli->query($cmd);
                while ($store = $store_query->fetch_array()) {
                    if ($store['shop_id']!=$store_id) {
                    $multisstore_data_array = array(
                        'pid' => $Artikel_ID,
                        'permission' => 1,
                        'pgroup' => "shop_".$store['shop_id']
                    );
                    db_insert('xt_products_permission', $multisstore_data_array);
                    }
                }
            } else {
                $mysqli->query("delete from xt_products_permission where pid = '$Artikel_ID' and pgroup = 'shop_".$store_id."'");
            }
                
            
            foreach ($Artikel_Texte as $AText) {
                if ($AText['L'] <> 0) {
                    $sql_data_array = array(
                        'products_name' => $AText['B'],
                        'products_description' => $AText['T'],
                        'products_short_description' => $AText['S'],
                        'products_keywords' => $AText['B'],
                        'products_url' => $AText['URL'],
                        'products_store_id' => $store_id
                    );
                    $sql_seo_url = array(
                        'meta_title' => $AText['MT'],
                        'meta_description' => $AText['MD'],
                        'meta_keywords' => $AText['MK']
                    );
                    $cmd = "select languages_id,name,code from " . TABLE_LANGUAGES . "
                                WHERE languages_id = " . $AText['L'] . " AND allow_edit ='1'";
                    $language_query = $mysqli->query($cmd);
                    $language = $language_query->fetch_array();
                    $seoUrl = '';
                    $AText['B'] = ersetzen($AText['B']);
                    $seoUrl = $language['code'] . "/" . $AText['B'];
                    $cmd = "SELECT products_id FROM " . TABLE_PRODUCTS_DESCRIPTION . "
                                WHERE products_id = '" . $Artikel_ID . "'
                                AND language_code = '" . $language['code'] . "'";
                    $products_query = $mysqli->query($cmd);
                    
                    if ($products_query->fetch_array()) {
                        db_insert(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '$Artikel_ID' AND language_code = '" . $language['code'] . "' AND products_store_id='$store_id'");
                    } else {
                        
                        //multistore Texte in alle Shops wenn !exists
                        $cmd = "select shop_id from xt_stores";
                        $store_query = $mysqli->query($cmd);
                        while ($store = $store_query->fetch_array()) {
                            
                            $sql_data_array['products_id'] = $Artikel_ID;
                            $sql_data_array['language_code'] = $language['code'];
                            $sql_data_array['products_store_id'] = $store['shop_id'];
                            db_insert(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
                            
                        }
                        
                    
                    
                    }

                    $cmd = "SELECT link_id FROM " . TABLE_SEO_URL . "
                                WHERE link_id = '" . $Artikel_ID . "'
                                AND link_type = '1'
                                AND language_code = '" . $language['code'] . "'";
                    $seo_query = $mysqli->query($cmd);

                    $cmd = "SELECT url_text FROM " . TABLE_SEO_URL . "
                                WHERE link_id = '" . $Artikel_Kategorien[1] . "'
                                AND language_code = '" . $language['code'] . "'
                                AND link_type ='2'";
                    $catname_query = $mysqli->query($cmd);
                    $catname_Url = $catname_query->fetch_array();

                    if ($catname_Url) {
                        $catUrl = $catname_Url['url_text'];
                    } else {
                        $catUrl = $seoUrl;
                    }

                    if (!$seo_query->fetch_array()) {
                        $text = "{$catUrl}/" . $AText["B"];
                        $cmd = "SELECT url_md5 FROM " . TABLE_SEO_URL . " WHERE url_md5 = '" . md5($text) . "'";
                        $seo_query = $mysqli->query($cmd);
                        if (!$seo_query->fetch_array()) {
                            $sql_seo_url['url_md5'] = md5($text);
                        } else {
                            $text = $text . "{$Artikel_ID}";
                            $sql_seo_url['url_md5'] = md5($text);
                        }
                        $sql_seo_url['url_text'] = $text;
                        $sql_seo_url['link_id'] = $Artikel_ID;
                        $sql_seo_url['link_type'] = 1;
                        $sql_seo_url['language_code'] = $language['code'];
                        $sql_seo_url['store_id'] = $store_id;
                        //db_insert(TABLE_SEO_URL, $sql_seo_url);
                    }
                }
            }
            
             
            /* für nur Fotos - deaktivieren */
              if (count($Artikel_Kategorien) > 0) {
                $mysqli->query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE products_id='$Artikel_ID' AND store_id=$store_id");
                foreach ($Artikel_Kategorien as $i => $Kategorie_ID) {
                    $insert_sql_data = array('products_id' => $Artikel_ID,
                        'categories_id' => $Kategorie_ID,
                        'store_id' => $store_id
                    );
                    if ($i <= 1)
                        $insert_sql_data['master_link'] = 1;
                    else
                        $insert_sql_data['master_link'] = 0;

                    db_insert(TABLE_PRODUCTS_TO_CATEGORIES, $insert_sql_data);
                }
            }

            // Bilder laden
            if (!$SkipImages) {
                //Bildgr��en aus den Einstellungen einlesen
                $type_cmd = "select folder, width, height from " . TABLE_IMAGE_TYPE;
                $type_query = $mysqli->query($type_cmd);
                while ($typesize = $type_query->fetch_array()) {
                    if ($typesize['folder'] == "thumb") {
                        $width_thumb = $typesize['width'];
                        $height_thumb = $typesize['height'];
                    } elseif ($typesize['folder'] == "info") {
                        $width_info = $typesize['width'];
                        $height_info = $typesize['height'];
                    } elseif ($typesize['folder'] == "popup") {
                        $width_popup = $typesize['width'];
                        $height_popup = $typesize['height'];
                    } elseif ($typesize['folder'] == "icon") {
                        $width_icon = $typesize['width'];
                        $height_icon = $typesize['height'];
                    }
                    // Neu ab Ver 4.1
                    elseif ($typesize['folder'] == "smallproduct") {
                        $width_smallproduct = $typesize['width'];
                        $height_smallproduct = $typesize['height'];
                    }
                }
                //MediaGallery Standards holen
                $mg_cmd = "select mg_id from " . TABLE_MEDIA_GALLERY . " where class='product'";
                $mg_query = $mysqli->query($mg_cmd);
                if ($mg = $mg_query->fetch_array()) {
                    $mg_id = $mg['mg_id'];
                }

                if (isset($_POST['Artikel_Bilddatei'])) {
                    bildloschen($Artikel_ID);
                    // Tempor�res Bild im Ordner Originale ablegen und Typ ermitteln    
                    $filename = $_FILES['artikel_image']['name'];
                    $uploaddir = _SRV_WEB_IMAGES . _DIR_ORG;
                    $uploadfile = "../" . $uploaddir . $filename;
                    move_uploaded_file($_FILES['artikel_image']['tmp_name'], $uploadfile);
                    $typename = strtolower($filename);
                    bildbearbeiten($filename, $uploaddir, $uploadfile, $typename, $width_thumb, $width_info, $width_popup, $width_icon, $height_thumb, $height_info, $height_icon, $height_popup, $width_smallproduct, $height_smallproduct);
                    //Die neue Bildern in DB Media, Media Gallery eintragen
                    $insert_sql_data = array(
                        'file' => $filename,
                        'type' => "images",
                        'class' => "product",
                        'download_status' => "free",
                        'status' => "true",
                        'owner' => 1
                    );
                    $cmd = "SELECT id from " . TABLE_MEDIA . ", " . TABLE_PRODUCTS . " where file = '" . $filename . "' AND products_image = '" . $filename . "'";
                    $bquery = $mysqli->query($cmd);

                    if ($media = $bquery->fetch_array()) {
                        // 'update';
                        $data = array('file' => $filename);
                        db_insert(TABLE_MEDIA, $data, 'update', "id = '" . $media['id'] . "'");
                        //db_insert(TABLE_MEDIA_TO_MEDIA_GALLERY,array('m_id'=>),'update',"m_id = '" . $media['id'] ."'");
                    } else {
                        // $bmodus = 'insert';
                        db_insert(TABLE_MEDIA, $insert_sql_data);
                        $m_id = $mysqli->insert_id;
                        $insert_sql_data = array(
                            'm_id' => $m_id,
                            'mg_id' => $mg_id
                        );
                        db_insert(TABLE_MEDIA_TO_MEDIA_GALLERY, $insert_sql_data);
                    }
                }

                $bilddatei = bilderloschen($Artikel_ID);
                $anzUpdates = count($bilddatei);
                $anzInsert = 0;

                if (isset($_POST['Artikel_Bilddateien'])) {
                    for ($i = 0; $i < (integer) ($_POST['Artikel_Bilddateien']); $i++) {
                        // Tempor�res Bild im Ordner Originale ablegen und Typ ermitteln    
                        $filename = $_FILES["artikel_images$i"]["name"];
                        $uploaddir = _SRV_WEB_IMAGES . _DIR_ORG;
                        $uploadfile = "../" . $uploaddir . $filename;
                        move_uploaded_file($_FILES["artikel_images$i"]["tmp_name"], $uploadfile);
                        $typename = strtolower($filename);
                        bildbearbeiten($filename, $uploaddir, $uploadfile, $typename, $width_thumb, $width_info, $width_popup, $width_icon, $height_thumb, $height_info, $height_icon, $height_popup, $width_smallproduct, $height_smallproduct);
                        //Die neue Bildern in DB Media, Media Link und Gallery eintragen

                        if ($anzUpdates > $i) {
                            $cmd = "SELECT id, file from " . TABLE_MEDIA . " WHERE id = '" . $bilddatei[$i]['id'] . "'";
                            $bquery = $mysqli->query($cmd);
                            if ($media = $bquery->fetch_array()) {
                                //update
                                $data = array('file' => $filename);
                                db_insert(TABLE_MEDIA, $data, 'update', "id = '" . $bilddatei[$i]['id'] . "'");
                            }
                        } else {
                            $insert_sql_data = array(
                                'file' => $filename,
                                'type' => "images",
                                'class' => "product",
                                'download_status' => "free",
                                'status' => "true",
                                'owner' => 1
                            );
                            db_insert(TABLE_MEDIA, $insert_sql_data);
                            $m_id = $mysqli->insert_id;
                            $insert_sql_data = array(
                                'm_id' => $m_id,
                                'mg_id' => $mg_id
                            );
                            db_insert(TABLE_MEDIA_TO_MEDIA_GALLERY, $insert_sql_data);
                            $insert_sql_data = array(
                                'm_id' => $m_id,
                                'link_id' => $Artikel_ID,
                                'class' => "product",
                                'type' => "images",
                                'sort_order' => $i + 1
                            );
                            db_insert(TABLE_MEDIA_LINK, $insert_sql_data);
                        }
                    }
                    $anzInsert = $i;
                }

                if ($anzUpdates > $anzInsert) {
                    for ($k = $anzInsert; $k < $anzUpdates; $k++) {
                        $mysqli->query("delete from " . TABLE_MEDIA . " where id = '" . $bilddatei[$k]['id'] . "' AND type = 'images'");
                        $mysqli->query("delete from " . TABLE_MEDIA_LINK . " where m_id = '" . $bilddatei[$k]['id'] . "' and type = 'images'");
                        $mysqli->query("delete from " . TABLE_MEDIA_TO_MEDIA_GALLERY . " where m_id = '" . $bilddatei[$k]['id'] . "' and mg_id = 2");
                    }
                }
            } // Bilder laden
        } // Ende OverWrite
    }

    if (!$exists || $ExportModus == 'Overwrite' || $ExportModus == 'PriceOnly' || $ExportModus == 'PriceAndQuantityOnly') {

        $cmd = "select distinct(customers_status_id) from " . TABLE_CUSTOMERS_STATUS;
        $ss_query = $mysqli->query($cmd);
        while ($ss = $ss_query->fetch_array()) {
            $mysqli->query("delete from xt_products_price_group_all where products_id = '$Artikel_ID'");
        }
        
        foreach ($Artikel_Preise as $i => $APreis) {
            $sql_data_array = array(
                'products_id' => $Artikel_ID,
                'discount_quantity' => $APreis['M'],
                'price' => $APreis['P']
            );
            
            db_insert('xt_products_price_group_all', $sql_data_array);
        }
        $sql_data_array = array(
                'products_id' => $Artikel_ID,
                'discount_quantity' => 1,
                'price' => $Artikel_Preis
            );
            
        db_insert('xt_products_price_group_all', $sql_data_array);
        
    }
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . "\n" .
    "<STATUS>\n" .
    "    <STATUS_DATA>\n" .
    "        <MESSAGE>OK</MESSAGE>\n" .
    "        <MODE>$mode</MODE>\n" .
    "        <ID>$Artikel_ID</ID>\n" .
    "        <SCRIPT_VERSION_MAJOR>$version_major</SCRIPT_VERSION_MAJOR>\n" .
    "        <SCRIPT_VERSION_MINOR>$version_minor</SCRIPT_VERSION_MINOR>\n" .
    "        <SCRIPT_DATE>$version_datum</SCRIPT_DATE>\n" .
    "    </STATUS_DATA>\n" .
    "</STATUS>\n\n";
}

function writeCategorie() {
    global $action, $version_major, $version_minor, $version_datum, $mysqli;
    $Kategorie_ID = (integer) ($_POST['Artikel_Kategorie_ID']);
    $Kategorie_Vater_ID = (integer) ($_POST['Kategorie_Vater_ID']);
    $Kategorie_Names = array(
        1 => array(
            'N' => $_POST['Kategorie_Name1'],
            'L' => (integer) ($_POST['Kategorie_NameLanguage1'])
        ),
        2 => array(
            'N' => $_POST['Kategorie_Name2'],
            'L' => (integer) ($_POST['Kategorie_NameLanguage2'])
        ),
        3 => array(
            'N' => $_POST['Kategorie_Name3'],
            'L' => (integer) ($_POST['Kategorie_NameLanguage3'])
        ),
        4 => array(
            'N' => $_POST['Kategorie_Name4'],
            'L' => (integer) ($_POST['Kategorie_NameLanguage4'])
        )
    );

    $exists = FALSE;

    // Kategorie wurde von AF schon angelegt
    if ($Kategorie_ID != 0) {
        $cmd = "SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE categories_id='" . $Kategorie_ID . "'";
        $cat_query = $mysqli->query($cmd);
        if ($cat = $cat_query->fetch_array())
            ; {
            $exists = TRUE;
        }
    }
    /*$cmd = "SELECT * from " . TABLE_MANDANT_CONFIG . " where shop_title ='Main Store'";
    //$cmd = "SELECT shop_id from ". TABLE_MANDANT_CONFIG . " where shop_titel = 'Main Store'";
    $store_id_query = $mysqli->query($cmd);
    $store_id = $store_id_query->fetch_array();
    if ($store_id) {
        $store_id = $store_id['shop_id'];
    } else {
        $store_id = 1;
    }*/
    
    //multistore mod JCP
    if (isset($_GET['store_id'])) {
        $store_id = $_GET['store_id'];
    } else {
        $store_id = 1;
    }
    
    $btime = aftime();

    if (!$exists) {
        $insert_categorie = array('permission_id' => 0,
            'categories_owner' => 1,
            'parent_id' => $Kategorie_Vater_ID,
            'categories_status' => 1,
            'date_added' => $btime
        );

        // Kategorie erzeugen und ID ermitteln
        db_insert(TABLE_CATEGORIES, $insert_categorie);
        $Kategorie_ID = $mysqli->insert_id;
        // $id = array('permission_id' => $Kategorie_ID);
        // db_insert(TABLE_CATEGORIES, $id['permission_id'], 'update',"categories_id='$Kategorie_ID'");
        // Namen eintragen
        foreach ($Kategorie_Names as $i => $KName) {
            if ($KName['L'] <> 0) {
                // language_code ermitteln
                $cmd = "SELECT code FROM " . TABLE_LANGUAGES . "
                            WHERE languages_id = " . $KName['L'] . "
                            AND allow_edit= 1";
                $result_language_code = $mysqli->query($cmd);
                $language_code = $result_language_code->fetch_array();

                // Daten in die Tabelle TABLE_CATEGORIES_DESCRIPTION schreiben
                $insert_categorieDescription = array('categories_id' => $Kategorie_ID,
                    'language_code' => $language_code['code'],
                    'categories_name' => $KName['N'],
                    'categories_heading_title' => $KName['N'],
                    'categories_store_id' => $store_id
                );

                db_insert(TABLE_CATEGORIES_DESCRIPTION, $insert_categorieDescription);

                /*                     $sql_seo_url = array('meta_title' => $KName['N'],
                  'meta_description' => $KName['N'],
                  'meta_keywords' => $KName['N']
                  );

                 */
                $lcode = $language_code['code'];
                $cat_seo_Url = kategoriebaum($Kategorie_ID, $lcode);

                $cmd = "SELECT url_md5 FROM " . TABLE_SEO_URL . "
                            WHERE link_id = '" . $Kategorie_ID . "'
                            AND link_type ='2'
                            AND language_code = '$lcode'";
                $seo_query = $mysqli->query($cmd);

//                    $KName['N'] = ersetzen($KName['N']);

                $url_categorie = "$lcode/" . $cat_seo_Url;
                /*                     if (mysql_fetch_array($seo_query)) {
                  //$sql_seo_url['url_text'] = $seoUrl;
                  //$sql_seo_url['url_md5'] = md5($url_categorie);
                  $sql_seo_url['url_text'] = $url_categorie;
                  $sql_seo_url['link_type'] = 2;
                  db_insert(TABLE_SEO_URL, $sql_seo_url, 'update', "link_id = '$Kategorie_ID' AND language_code = '$lcode'");

                  } else {
                 */ if (!$seo_query->fetch_array()) {
                    $sql_seo_url = array('url_md5' => md5($url_categorie),
                        'url_text' => $url_categorie,
                        'link_id' => $Kategorie_ID,
                        'link_type' => 2,
                        'language_code' => $lcode,
                        'store_id' => $store_id
                    );

                    db_insert(TABLE_SEO_URL, $sql_seo_url);
                }
            }
        }
    }

    if (isset($_POST['Kategorie_Bildextension'])) {
        $Kategorie_Bildextension = $_POST['Kategorie_Bildextension'];
        //Bildgr��en aus den Einstellungen einlesen
        $type_cmd = "select folder, width, height from " . TABLE_IMAGE_TYPE . " WHERE class='category'";
        $type_query = $mysqli->query($type_cmd);
        while ($typesize = $type_query->fetch_array()) {
            if ($typesize['folder'] == "category/thumb") {
                $width_thumb = $typesize['width'];
                $height_thumb = $typesize['height'];
            } elseif ($typesize['folder'] == "category/info") {
                $width_info = $typesize['width'];
                $height_info = $typesize['height'];
            } elseif ($typesize['folder'] == "category/popup") {
                $width_popup = $typesize['width'];
                $height_popup = $typesize['height'];
            } elseif ($typesize['folder'] == "category/icon") {
                $width_icon = $typesize['width'];
                $height_icon = $typesize['height'];
            }
        }

        $filename = "cat" . $Kategorie_ID . $Kategorie_Bildextension;
        //    $filename = $_FILES['artikel_image']['name'];
        $uploaddir = _SRV_WEB_IMAGES . _DIR_ORG;
        // Tempor�res Bild im Ordner Originale ablegen und Typ ermitteln
        $uploadfile = "../" . $uploaddir . $filename;
        move_uploaded_file($_FILES['Kategorie_image']['tmp_name'], $uploadfile);
        // move_uploaded_file($filename, $uploadfile);
        $typename = strtolower($filename);
        catbildbearbeiten($filename, $uploaddir, $uploadfile, $typename, $width_thumb, $width_info, $width_popup, $width_icon, $height_thumb, $height_info, $height_icon, $height_popup);
        //    }
        $sql_data_array['categories_image'] = $filename;
        db_insert(TABLE_CATEGORIES, $sql_data_array, 'update', "categories_id='$Kategorie_ID'");

        $insert_cat_media = array('file' => $filename,
            'type' => 'images',
            'class' => 'category',
            'status' => 'true',
            'owner' => 1
        );
        db_insert(TABLE_MEDIA, $insert_cat_media);
        $Kat_MID = $mysqli->insert_id;

        $sql_catmedia_array = array('m_id' => $Kat_MID,
            'mg_id' => 3
        );
        db_insert(TABLE_MEDIA_TO_MEDIA_GALLERY, $sql_catmedia_array, 'insert', "ml_id='$Kat_MID'");
    }

    $mode = 'INSERTED';
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . "\n" .
    "<STATUS>\n" .
    "    <STATUS_DATA>\n" .
    "        <MESSAGE>OK</MESSAGE>\n" .
    "        <MODE>$mode</MODE>\n" .
    "        <ID>$Kategorie_ID</ID>\n" .
    "        <SCRIPT_VERSION_MAJOR>$version_major</SCRIPT_VERSION_MAJOR>\n" .
    "        <SCRIPT_VERSION_MINOR>$version_minor</SCRIPT_VERSION_MINOR>\n" .
    "        <SCRIPT_DATE>$version_datum</SCRIPT_DATE>\n" .
    "    </STATUS_DATA>\n" .
    "</STATUS>\n\n";
}

function writeHersteller() {
    global $action, $version_major, $version_minor, $version_datum, $mysqli;
    $Hersteller_Name = $_POST['Hersteller_Name'];
    $mode = 'NONE';
    /*$cmd = "SELECT * from " . TABLE_MANDANT_CONFIG . " where shop_title ='Main Store'";
    // $cmd = "SELECT shop_id from ". TABLE_MANDANT_CONFIG . " where shop_titel = 'Main Store'";
    $store_id_query = $mysqli->query($cmd);
    $store_id = $store_id_query->fetch_array();
    if ($store_id) {
        $store_id = $store_id['shop_id'];
    } else {
        $store_id = 1;
    }*/
    
    //multistore mod JCP
    if (isset($_GET['store_id'])) {
        $store_id = $_GET['store_id'];
    } else {
        $store_id = 1;
    }
    
    $cmd = "SELECT manufacturers_id,manufacturers_name FROM " . TABLE_MANUFACTURERS .
            " WHERE manufacturers_name='$Hersteller_Name'";
    $manufacturers_query = $mysqli->query($cmd);

    // Datensatz schon vorhanden
    if ($manufacturers = $manufacturers_query->fetch_array()) {
        $Hersteller_ID = $manufacturers['manufacturers_id'];
    } else {
        $mode = 'INSERTED';

        $btime = aftime();

        $insert_sql_data = array('manufacturers_name' => $Hersteller_Name,
            'manufacturers_status' => 1,
            'external_id' => 'TEXT_EXTERNAL_ID',
            'date_added' => $btime
        );
        db_insert(TABLE_MANUFACTURERS, $insert_sql_data);
        $Hersteller_ID = $mysqli->insert_id;

        //$cmd = "select languages_id,name,code from " . TABLE_LANGUAGES . " WHERE language_status = '1'";
        //$languages_query = mysql_query($cmd) or die(mysql_error());
        //while ($language = mysql_fetch_array($languages_query))
        $language['code'] = 'de';
        $cmd = "SELECT manufacturers_id FROM " . TABLE_MANUFACTURERS_DESCRIPTION . " WHERE manufacturers_id = '$Hersteller_ID'" .
                " AND language_code = '" . $language['code'] . "'";
        $result_query = $mysqli->query($cmd);
        if (!$result = $result_query->fetch_array()) {
            $insert_sql_info = array('manufacturers_id' => $Hersteller_ID,
                'language_code' => $language['code'],
                'manufacturers_description' => $Hersteller_Name,
                'manufacturers_url' => '',
                'manufacturers_store_id' => $store_id
            );
            db_insert(TABLE_MANUFACTURERS_DESCRIPTION, $insert_sql_info);
        }

        $sql_seo_url = array('meta_title' => $Hersteller_Name,
            'meta_description' => $Hersteller_Name,
            'meta_keywords' => $Hersteller_Name
        );
        $seoUrl = $language['code'] . "/" . ersetzen($Hersteller_Name);

        $cmd = "SELECT url_md5 FROM " . TABLE_SEO_URL . " WHERE language_code = '" . $language['code'] . "' AND link_type = 4 AND link_id = '" . $Hersteller_ID . "'";
        $result_query = $mysqli->query($cmd);
        /*         if(mysql_fetch_array($result)) {
          $sql_seo_url['url_md5'] = md5($seoUrl);
          $sql_seo_url['url_text'] = $seoUrl;
          $sql_seo_url['link_type'] = 4;
          db_insert(TABLE_SEO_URL, $sql_seo_url,'update', "link_id = '$Hersteller_ID' AND link_type='4' AND language_code = '".$language_code['code']."'");

          }
          else {
         */
        if (!$result = $result_query->fetch_array()) {
            $sql_seo_url = array('url_md5' => md5($seoUrl),
                'url_text' => $seoUrl,
                'language_code' => $language['code'],
                'link_type' => 4,
                'link_id' => $Hersteller_ID,
                'store_id' => $store_id
            );
            db_insert(TABLE_SEO_URL, $sql_seo_url);
        }
    }

    $cmd = "SELECT pid FROM " . TABLE_MANUFACTURERS_PERMISSION . " WHERE pid = '$Hersteller_ID'" .
            " AND (pgroup = 'group_permission_1' OR pgroup = 'shop_1')";
    $result_query = $mysqli->query($cmd);
    // Info noch nicht enthalten
    if (!$result = $result_query->fetch_array()) {
        $insert_sql_permission = array('pid' => $Hersteller_ID,
            'permission' => '1',
            'pgroup' => 'shop_1'
        );

        db_insert(TABLE_MANUFACTURERS_PERMISSION, $insert_sql_permission);

        for ($i = 1; $i <= 3; $i++) {
            $insert_sql_permission = array('pid' => $Hersteller_ID,
                'permission' => '1',
                'pgroup' => 'group_permission_' . $i);
            db_insert(TABLE_MANUFACTURERS_PERMISSION, $insert_sql_permission);
        }
    }
    echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . "\n" .
    "<STATUS>\n" .
    "    <STATUS_DATA>\n" .
    "        <MESSAGE>OK</MESSAGE>\n" .
    "        <ID>$Hersteller_ID</ID>\n" .
    "        <SCRIPT_VERSION_MAJOR>$version_major</SCRIPT_VERSION_MAJOR>\n" .
    "        <SCRIPT_VERSION_MINOR>$version_minor</SCRIPT_VERSION_MINOR>\n" .
    "        <SCRIPT_DATE>$version_datum</SCRIPT_DATE>\n" .
    "    </STATUS_DATA>\n" .
    "</STATUS>\n\n";
}

function db_insert($tabelle, $data, $action = 'insert', $parameters = '') {
    global $mysqli;
    // #### Datensatz einfuegen #####
    if ($action == 'insert') {

        $insert_query = 'INSERT INTO ' . $tabelle . ' (';
        while (list($columns, ) = each($data)) {
            $insert_query .= $columns . ', ';
        }
        $insert_query = substr($insert_query, 0, -2) . ') VALUES (';
        reset($data);
        while (list(, $value) = each($data)) {
            $insert_query .= "'" . $mysqli->real_escape_string($value) . "'" . ', ';
        }
        $insert_query = substr($insert_query, 0, -2) . ')';


        return $insert = $mysqli->query($insert_query) or die("MySQLFehler: $insert_query;\n" . $mysqli->error);
    }

    // #### Datensatz aendern #####
    elseif ($action == 'update') {

        $update_query = 'UPDATE ' . $tabelle . ' SET ';
        while (list($columns, $value) = each($data)) {

            $update_query .= $columns . ' = ' . "'" . $mysqli->real_escape_string($value) . "'" . ', ';
        }

        $update_query = substr($update_query, 0, -2) . ' ';
        $update_query .= ' WHERE ' . $parameters;

        return $update = $mysqli->query($update_query) or die("MySQLFehler: $update_query;\n" . $mysqli->error);
    }
}

// - - - Verbindung zur Datenbank - - -
function db_connect() {
    try {
        $c = false;
//        $db=mysql_connect(_SYSTEM_DATABASE_HOST,_SYSTEM_DATABASE_USER,_SYSTEM_DATABASE_PWD);
        $mysqli = new mysqli(_SYSTEM_DATABASE_HOST, _SYSTEM_DATABASE_USER, _SYSTEM_DATABASE_PWD, _SYSTEM_DATABASE_DATABASE);
        if ($mysqli->connect_error) {
            echo "Datenbankverbindungsfehler:" . mysqli_connect_error();
            exit;
        } else {
            $c = TRUE;
            return $mysqli;
        }
        /*
          if (!$db)
          {
          die('Keine Verbindung m�glich: ' . mysql_error());
          } else {
          mysql_select_db(_SYSTEM_DATABASE_DATABASE);
          $c=true;
          }
         */
    } catch (Exception $e) {
        echo "==> Es ist ein Fehler aufgetreten: " . $e->getMessage();
        $c = false;
        //exit();
        return $c;
    }
    //return $mysqli;
}

// - - - Login - - -
function login($user, $pass) {
    global $n, $hk;
    $n = "\n";
    $hk = "'";
    $c = false;
    if ($mysqli = db_connect()) {
        $query_login = $mysqli->query("SELECT handle, user_password FROM " . TABLE_ADMIN_ACL_AREA_USER . " where handle = " . $hk . $user . $hk);
        $login = $query_login->fetch_array();
        if (($user != $login['handle']) OR ( $pass != $login['user_password']) OR ( $user == "") OR ( $login == "")) {
            if ($_GET['error'] == '')
                $_GET['error'] = 'FALSCHES PASSWORT ODER BENUTZERNAME';
            if ($_GET['code'] == '')
                $_GET['code'] = '100';
            echo '<?xml version="1.0" encoding="' . CHARSET . '"?>' . $n .
            "<STATUS>" . $n .
            "    <STATUS_DATA>" . $n .
            "        <CODE>" . $_GET['code'] . "</CODE>" . $n .
            "        <MESSAGE>" . $_GET['error'] . "</MESSAGE>" . $n .
            "    </STATUS_DATA>" . $n .
            "</STATUS>" . $n;
            exit();
        }
        else {
            $c = true;
        }
    }
    return $c;
}

// - - - Debuginfo - - -
function ShowDebug() {
    global $action, $version_major, $version_minor, $n;
    echo "<DEBUG>" . $n .
    "    <GetAction>$_GET[action]</GetAction>" . $n .
    "    <PostAction>$_POST[action]</PostAction>" . $n .
    "    <GetDaten>" . $n;
    foreach ($_GET as $Key => $Value) {
        echo "        <$Key>$Value</$Key>" . $n;
    }
    echo "    </GetDaten>" . $n;
    echo "    <PostDaten>" . $n;
    foreach ($_POST as $Key => $Value) {
        echo "        <$Key>$Value</$Key>" . $n;
    }
    echo "    </PostDaten>" . $n;
    echo "</DEBUG>" . $n;
}

function bildbearbeiten($filename, $uploaddir, $uploadfile, $typename, $width_thumb, $width_info, $width_popup, $width_icon, $height_thumb, $height_info, $height_icon, $height_popup, $width_smallproduct, $height_smallproduct) {

    if (strstr($typename, '.gif')) {
        $image = imagecreatefromgif($uploadfile);
    } elseif ((strstr($typename, '.jpg')) || (strstr($typename, '.jpeg'))) {
        $image = imagecreatefromjpeg($uploadfile);
    } elseif (strstr($typename, '.png')) {
        $image = imagecreatefrompng($uploadfile);
    }

    //Originalgr��e und Ratio ermitteln
    $width = imagesx($image);
    $height = imagesy($image);

    $imgratio = ($width / $height);
    if ($imgratio > 1) {
        $new_width_thumb = $width_thumb;
        $new_height_thumb = ($width_thumb / $imgratio);
        $new_width_info = $width_info;
        $new_height_info = ($width_info / $imgratio);
        $new_width_popup = $width_popup;
        $new_height_popup = ($width_popup / $imgratio);
        $new_width_icon = $width_icon;
        $new_height_icon = ($width_icon / $imgratio);
        // Neu ab Ver 4.1
        $new_width_smallproduct = $width_smallproduct;
        $new_height_smallproduct = ($width_smallproduct / $imgratio);
    } else {
        $new_height_thumb = $height_thumb;
        $new_width_thumb = ($height_thumb * $imgratio);
        $new_height_info = $height_info;
        $new_width_info = ($height_info * $imgratio);
        $new_height_popup = $height_popup;
        $new_width_popup = ($height_popup * $imgratio);
        $new_height_icon = $height_icon;
        $new_width_icon = ($height_icon * $imgratio);
        // Neu ab Ver 4.1
        $new_height_smallproduct = $height_smallproduct;
        $new_width_smallproduct = ($height_smallproduct * $imgratio);
    }

    //Neue Resizebilder erstellen und speichern
    $new_image_thumb = imagecreatetruecolor($new_width_thumb, $new_height_thumb);
    ImageCopyResized($new_image_thumb, $image, 0, 0, 0, 0, $new_width_thumb, $new_height_thumb, $width, $height);
    $new_image_info = imagecreatetruecolor($new_width_info, $new_height_info);
    ImageCopyResized($new_image_info, $image, 0, 0, 0, 0, $new_width_info, $new_height_info, $width, $height);
    $new_image_popup = imagecreatetruecolor($new_width_popup, $new_height_popup);
    ImageCopyResized($new_image_popup, $image, 0, 0, 0, 0, $new_width_popup, $new_height_popup, $width, $height);
    $new_image_icon = imagecreatetruecolor($new_width_icon, $new_height_icon);
    ImageCopyResized($new_image_icon, $image, 0, 0, 0, 0, $new_width_icon, $new_height_icon, $width, $height);
    // Neu ab Ver 4.1
    $new_image_smallproduct = imagecreatetruecolor($new_width_smallproduct, $new_height_smallproduct);
    ImageCopyResized($new_image_smallproduct, $image, 0, 0, 0, 0, $new_width_smallproduct, $new_height_smallproduct, $width, $height);

    $path_info = "../" . _SRV_WEB_IMAGES . _DIR_INFO . $filename;
    $path_popup = "../" . _SRV_WEB_IMAGES . "popup/" . $filename;
    $path_thumb = "../" . _SRV_WEB_IMAGES . _DIR_THUMB . $filename;
    $path_icon = "../" . _SRV_WEB_IMAGES . _DIR_ICON . $filename;
    // Neu ab Ver 4.1
    $path_smallproduct = "../" . _SRV_WEB_IMAGES . "smallproduct/" . $filename;


    if (strstr($typename, '.gif')) {
        imagegif($new_image_thumb, $path_thumb);
        imagegif($new_image_info, $path_info);
        imagegif($new_image_popup, $path_popup);
        imagegif($new_image_icon, $path_icon);
        // Neu ab Ver 4.1
        imagegif($new_image_smallproduct, $path_smallproduct);
    } elseif ((strstr($typename, '.jpg')) || (strstr($typename, '.jpeg'))) {
        imagejpeg($new_image_thumb, $path_thumb, 90);
        imagejpeg($new_image_info, $path_info, 90);
        imagejpeg($new_image_popup, $path_popup, 90);
        imagejpeg($new_image_icon, $path_icon, 90);
        // Neu ab Ver 4.1
        imagejpeg($new_image_smallproduct, $path_smallproduct, 90);
    } elseif (strstr($typename, '.png')) {
        imagepng($new_image_thumb, $path_thumb, 9);
        imagepng($new_image_info, $path_info, 9);
        imagepng($new_image_popup, $path_popup, 9);
        imagepng($new_image_icon, $path_icon, 9);
        // Neu ab Ver 4.1
        imagepng($new_image_smallproduct, $path_smallproduct, 9);
    }

    //Images freigeben
    imagedestroy($new_image_thumb);
    imagedestroy($new_image_info);
    imagedestroy($new_image_popup);
    imagedestroy($new_image_icon);
    // Neu ab Ver 4.1
    imagedestroy($new_image_smallproduct);
    imagedestroy($image);

    return $filename;
}

function catbildbearbeiten($filename, $uploaddir, $uploadfile, $typename, $width_thumb, $width_info, $width_popup, $width_icon, $height_thumb, $height_info, $height_icon, $height_popup) {

    if (strstr($typename, '.gif')) {
        $image = imagecreatefromgif($uploadfile);
    } elseif ((strstr($typename, '.jpg')) || (strstr($typename, '.jpeg'))) {
        $image = imagecreatefromjpeg($uploadfile);
    } elseif (strstr($typename, '.png')) {
        $image = imagecreatefrompng($uploadfile);
    }

    //Originalgr��e und Ratio ermitteln
    $width = imagesx($image);
    $height = imagesy($image);

    $imgratio = ($width / $height);

    if ($imgratio > 1) {
        $new_width_thumb = $width_thumb;
        $new_height_thumb = ($width_thumb / $imgratio);
        $new_width_info = $width_info;
        $new_height_info = ($width_info / $imgratio);
        $new_width_popup = $width_popup;
        $new_height_popup = ($width_popup / $imgratio);
        $new_width_icon = $width_icon;
        $new_height_icon = ($width_icon / $imgratio);
    } else {
        $new_height_thumb = $height_thumb;
        $new_width_thumb = ($height_thumb * $imgratio);
        $new_height_info = $height_info;
        $new_width_info = ($height_info * $imgratio);
        $new_height_popup = $height_popup;
        $new_width_popup = ($height_popup * $imgratio);
        $new_height_icon = $height_icon;
        $new_width_icon = ($height_icon * $imgratio);
    }

    //Neue Resizebilder erstellen und speichern
    $new_image_thumb = imagecreatetruecolor($new_width_thumb, $new_height_thumb);
    ImageCopyResized($new_image_thumb, $image, 0, 0, 0, 0, $new_width_thumb, $new_height_thumb, $width, $height);
    $new_image_info = imagecreatetruecolor($new_width_info, $new_height_info);
    ImageCopyResized($new_image_info, $image, 0, 0, 0, 0, $new_width_info, $new_height_info, $width, $height);
    $new_image_popup = imagecreatetruecolor($new_width_popup, $new_height_popup);
    ImageCopyResized($new_image_popup, $image, 0, 0, 0, 0, $new_width_popup, $new_height_popup, $width, $height);
    $new_image_icon = imagecreatetruecolor($new_width_icon, $new_height_icon);
    ImageCopyResized($new_image_icon, $image, 0, 0, 0, 0, $new_width_icon, $new_height_icon, $width, $height);

    $path_info = "../" . _SRV_WEB_IMAGES . "category/" . _DIR_INFO . $filename;
    $path_popup = "../" . _SRV_WEB_IMAGES . "category/popup/" . $filename;
    $path_thumb = "../" . _SRV_WEB_IMAGES . "category/" . _DIR_THUMB . $filename;
    $path_icon = "../" . _SRV_WEB_IMAGES . "category/" . _DIR_ICON . $filename;

    if (strstr($typename, '.gif')) {
        imagegif($new_image_thumb, $path_thumb);
        imagegif($new_image_info, $path_info);
        imagegif($new_image_popup, $path_popup);
        imagegif($new_image_icon, $path_icon);
    } elseif ((strstr($typename, '.jpg')) || (strstr($typename, '.jpeg'))) {
        imagejpeg($new_image_thumb, $path_thumb);
        imagejpeg($new_image_info, $path_info);
        imagejpeg($new_image_popup, $path_popup);
        imagejpeg($new_image_icon, $path_icon);
    } elseif (strstr($typename, '.png')) {
        imagepng($new_image_thumb, $path_thumb);
        imagepng($new_image_info, $path_info);
        imagepng($new_image_popup, $path_popup);
        imagepng($new_image_icon, $path_icon);
    }

    //Images freigeben
    imagedestroy($new_image_thumb);
    imagedestroy($new_image_info);
    imagedestroy($new_image_popup);
    imagedestroy($new_image_icon);
    imagedestroy($image);

    return $filename;
}

function ersetzen($text) {
    $text = strtolower($text);
    $suche = array(' ', '(', ')', '�', '�', '�', '�', '�', '�', '�', '+', '/', '*', '\'', '?', '"', '\\');
    $ersetzen = array('-', '', '', 'AE', 'OE', 'UE', 'ae', 'ss', 'oe', 'ue', '', '', '', '', '', '', '');
    return str_replace($suche, $ersetzen, $text);
}

function aftime() {
    return date('Y-m-d H:i:s', time());
}

function kategoriebaum($Kategorie_ID, $language_code) {
    global $mysqli;
    $cmd = "SELECT tc.categories_id, tc.parent_id, tcd.language_code, tcd.categories_name
            FROM " . TABLE_CATEGORIES . " tc, " . TABLE_CATEGORIES_DESCRIPTION . " tcd
            WHERE tc.categories_id = '$Kategorie_ID'
            AND tc.categories_id=tcd.categories_id            
            AND tcd.language_code = '" . $language_code . "'";
    $result_query = $mysqli->query($cmd);
    $result = $result_query->fetch_array();
    if ($result['parent_id'] <> 0) {
        $result['categories_name'] = ersetzen($result['categories_name']);
        $result = kategoriebaum($result['parent_id'], $result['language_code']) . '/' . $result['categories_name'];
        return $result;
    } else
        return ersetzen($result['categories_name']);
}

function bildloschen($Artikel_ID) {
    global $mysqli;
    $dirIcon = "../" . _SRV_WEB_IMAGES . "icon/";
    $dirInfo = "../" . _SRV_WEB_IMAGES . "info/";
    $dirOrg = "../" . _SRV_WEB_IMAGES . "org/";
    $dirPopup = "../" . _SRV_WEB_IMAGES . "popup/";
    $dirThumb = "../" . _SRV_WEB_IMAGES . "thumb/";
    // Neu ab Vers.4.1
    $dirSmalproduct = "../" . _SRV_WEB_IMAGES . "smallproduct/";
    $cmd = "select products_id, products_image, count(*) as total from " . TABLE_PRODUCTS . " where products_id = '$Artikel_ID'";
    $duplicate_image_query = $mysqli->query($cmd);
    $duplicate_image = $duplicate_image_query->fetch_array();
    $Bilddatei = $duplicate_image['products_image'];

    // Bild ist weniger als 2 Artikeln zugewiesen
    if ($duplicate_image['total'] < 1) {
        if (file_exists($dirIcon . $Bilddatei)) {
            @unlink($dirIcon . $Bilddatei);
        }
        if (file_exists($dirInfo . $Bilddatei)) {
            @unlink($dirInfo . $Bilddatei);
        }
        if (file_exists($dirOrg . $Bilddatei)) {
            @unlink($dirOrg . $Bilddatei);
        }
        if (file_exists($dirPopup . $Bilddatei)) {
            @unlink($dirPopup . $Bilddatei);
        }
        if (file_exists($dirThumb . $Bilddatei)) {
            @unlink($dirThumb . $Bilddatei);
        }
        //if (file_exists($dirSmalproduct . $Bilddatei)) { @unlink($dirSmalproduct . $Bilddatei); }
    }
    return true;
}

function bilderloschen($Artikel_ID) {
    global $mysqli;
    $dirIcon = "../" . _SRV_WEB_IMAGES . "icon/";
    $dirInfo = "../" . _SRV_WEB_IMAGES . "info/";
    $dirOrg = "../" . _SRV_WEB_IMAGES . "org/";
    $dirPopup = "../" . _SRV_WEB_IMAGES . "popup/";
    $dirThumb = "../" . _SRV_WEB_IMAGES . "thumb/";
    // Neu ab Vers.4.1
    //$dirSmalproduct = "../"._SRV_WEB_IMAGES."smallproduct/";
    $bilder2 = array();
    //$cmd = "select a.id, a.file from " .TABLE_MEDIA. " a, " .TABLE_MEDIA_LINK. " b, " .TABLE_MEDIA_TO_MEDIA_GALLERY .
    //        " c where b.link_id = $Artikel_ID AND b.m_id = a.id AND b.m_id = c.m_id";
    $cmd = "SELECT m.id, m.file from " . TABLE_MEDIA . " m, " . TABLE_MEDIA_LINK . " ml
            WHERE ml.link_id = '$Artikel_ID' AND m.id = ml.m_id";
    $result = $mysqli->query($cmd) or die($mysqli->error);

    while ($bilder = $result->fetch_array()) {
        if (file_exists($dirIcon . $bilder['file'])) {
            @unlink($dirIcon . $bilder['file']);
        }
        if (file_exists($dirInfo . $bilder['file'])) {
            @unlink($dirInfo . $bilder['file']);
        }
        if (file_exists($dirOrg . $bilder['file'])) {
            @unlink($dirOrg . $bilder['file']);
        }
        if (file_exists($dirPopup . $bilder['file'])) {
            @unlink($dirPopup . $bilder['file']);
        }

        if (file_exists($dirThumb . $bilder['file'])) {
            @unlink($dirThumb . $bilder['file']);
        }
        // Neu ab Vers.4.1.
        //if (file_exists($dirSmalproduct . $bilder['file'])) { @unlink($dirSmalproduct . $bilder['file']); }
        $bilder2[] = array('id' => $bilder['id'], 'file' => $bilder['file']);
    }

    return $bilder2;
}

?>

Share this post


Link to post
Share on other sites

ich habe das nur überflogen aber ich glaube die datenbank ist immer noch so struckturiert

die tabelle für die kategorie hat sich glaube ich geändert??

p.s für die bilder gibt es doch eine media resize function

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...