function generateXMLarticle($article_number, $sp_detail, $p, $uselength = false)
{
    global $component_length_id, $component_length_name;
    global $products_stock, $hide_extreme_flag, $hide_hard_flag, $hide_nostock_flag;
    $actual_stock = $products_stock[$p['products_id'] . '-' . $p['articles_id']];
    $stock_info = actualStockReport($sp_detail, $p['reported_stock'], $actual_stock, $p['delivery_days'], $p['is_bestselling'], $p['complexity'], $hide_extreme_flag, $hide_hard_flag, $hide_nostock_flag);
    $reported_stock = $p['active_status'] == '0' && $stock_info['stock_isreal'] == '0' ? '0' : $stock_info['stock'];
    //TODO: Remove 4 lines below to reactive bestselling in NM.DE
    //      It is currently deactivate to wait final confirmation
    //      on future partnership with NM.DE (sahat - 20.07.2012)
    //if($p['is_bestselling']=='1') {
    $reported_stock = '0';
    $stock_info['delivery_time'] = '14';
    //}
    //------------------------------------------------------------
    $result = '';
    //XML ARTICLES
    $result .= writeXMLopen('ARTICLEDATA', 1);
    $result .= writeLine();
    //XML ARTICLE DETAIL
    $article_number_used = $article_number;
    if ($p['length'] != '' && $p['length'] != '0') {
        $article_number_used .= '_' . textLength($p['length'], false);
    }
    if ($p['text'] != '' && $p['text_code'] != '') {
        $article_number_used .= '_' . $p['text_code'];
    }
    $billing_text = neckermannBillingText(15, $p['categories_id'], $p['name'], $p['length']);
    $result .= writeXMLline('A_SUP_ARTNO', $article_number_used, 2);
    $result .= writeXMLline('A_EAN', $p['products_ean'], 2);
    $result .= writeXMLline('A_BILLING_TEXT', $billing_text, 2);
    //XML ARTICLE COMPONENT
    if ($uselength) {
        //                $length = textLength($p['length'], false);
        //                if($p['categories_id']=='29') $length = ringSizeToDiameter($length);
        //                if($length>0) {
        //TEMPORARILY USING OLD SIZE ATTRIBUTES UNTIL NM.DE BUG IS FIXED
        if ($p['length'] > 0) {
            $length = textLength($p['length']);
            $component_id = '8571220';
            $component_name = 'Größe';
            //                    if(isset($component_length_id[$p['categories_id']])) {
            //                        $component_id = $component_length_id[$p['categories_id']];
            //                        $component_name = $component_length_name[$p['categories_id']];
            //                    } else {
            //                        $component_id = '970981';
            //                        $component_name = 'Länge (ca. cm)';
            //                    }
            $result .= writeXMLopen('A_COMPONENT', 2);
            $result .= writeXMLopen('COMPONENT', 3);
            $result .= writeXMLline('COMPONENT_ID', $component_id, 4);
            $result .= writeXMLline('COMPONENT_NAME', $component_name, 4);
            $result .= writeXMLclose('COMPONENT', 3);
            $result .= writeXMLline('COMPONENT_VALUE', $length, 3);
            $result .= writeXMLclose('A_COMPONENT', 2);
            $result .= writeLine();
        }
    }
    if ($p['text'] != '' && $p['text_code'] != '') {
        //                $component_id = '4053';
        //                $component_name = 'Text';
        $component_id = '976260';
        $component_name = 'Variante';
        $result .= writeXMLopen('A_COMPONENT', 2);
        $result .= writeXMLopen('COMPONENT', 3);
        $result .= writeXMLline('COMPONENT_ID', $component_id, 4);
        $result .= writeXMLline('COMPONENT_NAME', $component_name, 4);
        $result .= writeXMLclose('COMPONENT', 3);
        $text = $p['text'];
        $result .= writeXMLline('COMPONENT_VALUE', $text, 3);
        $result .= writeXMLclose('A_COMPONENT', 2);
        $result .= writeLine();
    }
    $valid_date = date('Y-m-d', strtotime($p['date_added']));
    $result .= writeXMLline('A_SEGMENT', '785', 2);
    $result .= writeXMLline('A_VALID_DATE', $valid_date, 2);
    $result .= writeLine();
    //XML ARTICLE STOCK
    $result .= writeXMLline('A_UNIT', 'ST', 2);
    //below additional stock is to handle neckermann error about hiding resourcable products when stock is 0
    //if($p['reported_stock']>0) $p['reported_stock'] += 49;
    //thile line above should be deleted once this error is fixed
    $result .= writeXMLline('A_STOCK', $reported_stock, 2);
    $result .= writeLine();
    //XML ARTICLE PRICING
    $result .= writeXMLopen('A_PRICE', 2);
    $result .= writeXMLline('PRICE_VK', $p['price'], 3);
    if ($p['price_old'] > 0 && $p['price_old'] > $p['price']) {
        $result .= writeXMLline('PRICE_VK_OLD', $p['price_old'], 3);
    }
    $result .= writeXMLline('PRICE_TAX', '2', 3);
    $result .= writeXMLline('PRICE_PROVISION_TYPE', $sp_detail['provision'], 3);
    $result .= writeXMLclose('A_PRICE', 2);
    $result .= writeLine();
    //XML ARTICLE ORDERING
    $result .= writeXMLopen('A_ORDER', 2);
    $result .= writeXMLline('ORDER_QUANTITY_MIN', '1', 3);
    $result .= writeXMLline('ORDER_QUANTITY_INTERVALL', '1', 3);
    $result .= writeXMLclose('A_ORDER', 2);
    $result .= writeLine();
    //XML DELIVERY
    //$delivery_time = ($p['delivery_days']==0) ? $sp_detail['delivery_time'] : $p['delivery_days'];
    $delivery_time = $stock_info['delivery_time'];
    if ($reported_stock == 0 || $p['reported_stock'] == 0) {
        $replacement = 'N';
        $delivery_replacement_time = '';
    } else {
        $replacement = 'J';
        $delivery_replacement_time = $delivery_time + 2;
    }
    $result .= writeXMLopen('A_DELIVERY', 2);
    $result .= writeXMLline('DELIVERY_TIME', $delivery_time, 3);
    $result .= writeXMLline('DELIVERY_REPLACEMENT', $replacement, 3);
    $result .= writeXMLline('DELIVERY_REPLACEMENT_TIME', $delivery_replacement_time, 3);
    $result .= writeXMLline('DELIVERY_PARCEL_TYPE', 'PAK', 3);
    $result .= writeXMLline('DELIVERY_CARRIER', '1', 3);
    $result .= writeXMLclose('A_DELIVERY', 2);
    $result .= writeLine();
    $result .= writeXMLclose('ARTICLEDATA', 1);
    $result .= writeLine();
    return $result;
}
 function generateXMLarticle($article_number, $sp_detail, $p, $uselength = false)
 {
     $result = '';
     //XML ARTICLES
     $result .= writeXMLopen('ARTICLEDATA', 1);
     $result .= writeLine();
     //XML ARTICLE DETAIL
     if ($p['length'] != '' && $p['length'] != 0) {
         $length = textLength($p['length']);
         $length = ' ' . strtoupper(str_replace(' ', '', $length));
         $len_pname = strlen($billing_text);
         $len_plength = strlen($length);
         $len_total = $len_pname + $len_plength;
         if ($len_total <= $billing_text_max) {
             $billing_text .= $length;
         }
     }
     $article_number_used = $article_number;
     if ($p['length'] != '' && $p['length'] != '0') {
         $article_number_used .= '_' . textLength($p['length'], false);
     }
     if ($p['text'] != '' && $p['text_code'] != '') {
         $article_number_used .= '_' . $p['text_code'];
     }
     $billing_text = neckermannBillingText(15, $p['categories_id'], $p['name'], $p['length']);
     $result .= writeXMLline('A_SUP_ARTNO', $article_number_used, 2);
     $result .= writeXMLline('A_EAN', $p['products_ean'], 2);
     $result .= writeXMLline('A_BILLING_TEXT', $billing_text, 2);
     //XML ARTICLE COMPONENT
     if ($uselength) {
         $result .= writeXMLopen('A_COMPONENT', 2);
         $result .= writeXMLopen('COMPONENT', 3);
         $result .= writeXMLline('COMPONENT_ID', '2', 4);
         $result .= writeXMLline('COMPONENT_NAME', 'Größe', 4);
         $result .= writeXMLclose('COMPONENT', 3);
         $length = textLength($p['length']);
         $result .= writeXMLline('COMPONENT_VALUE', $length, 3);
         $result .= writeXMLclose('A_COMPONENT', 2);
         $result .= writeLine();
     }
     if ($p['text'] != '' && $p['text_code'] != '') {
         $result .= writeXMLopen('A_COMPONENT', 2);
         $result .= writeXMLopen('COMPONENT', 3);
         $result .= writeXMLline('COMPONENT_ID', '4053', 4);
         $result .= writeXMLline('COMPONENT_NAME', 'Text', 4);
         $result .= writeXMLclose('COMPONENT', 3);
         $text = $p['text'];
         $result .= writeXMLline('COMPONENT_VALUE', $text, 3);
         $result .= writeXMLclose('A_COMPONENT', 2);
         $result .= writeLine();
     }
     $valid_date = date('Y-m-d', strtotime($p['date_added']));
     $result .= writeXMLline('A_SEGMENT', '785', 2);
     $result .= writeXMLline('A_VALID_DATE', $valid_date, 2);
     $result .= writeLine();
     //XML ARTICLE STOCK
     $result .= writeXMLline('A_UNIT', 'ST', 2);
     //below additional stock is to handle neckermann error about hiding resourcable products when stock is 0
     //if ($p['reported_stock']>0) $p['reported_stock'] += 49;
     //thile line above should be deleted once this error is fixed
     //TODO: uncomment below line and delete the line below it to reactivate NM.AT
     //$result .= writeXMLline('A_STOCK', $p['reported_stock'], 2);
     $result .= writeXMLline('A_STOCK', '0', 2);
     $result .= writeLine();
     //XML ARTICLE PRICING
     $result .= writeXMLopen('A_PRICE', 2);
     $result .= writeXMLline('PRICE_VK', $p['price'], 3);
     if ($p['price_old'] > 0 && $p['price_old'] > $p['price']) {
         $result .= writeXMLline('PRICE_VK_OLD', $p['price_old'], 3);
     }
     $result .= writeXMLline('PRICE_TAX', '2', 3);
     $result .= writeXMLline('PRICE_PROVISION_TYPE', $sp_detail['provision'], 3);
     $result .= writeXMLclose('A_PRICE', 2);
     $result .= writeLine();
     //XML ARTICLE ORDERING
     $result .= writeXMLopen('A_ORDER', 2);
     $result .= writeXMLline('ORDER_QUANTITY_MIN', '1', 3);
     $result .= writeXMLline('ORDER_QUANTITY_INTERVALL', '1', 3);
     $result .= writeXMLclose('A_ORDER', 2);
     $result .= writeLine();
     //XML DELIVERY
     $result .= writeXMLopen('A_DELIVERY', 2);
     $result .= writeXMLline('DELIVERY_TIME', $sp_detail['delivery_time'], 3);
     $result .= writeXMLline('DELIVERY_REPLACEMENT', 'N', 3);
     $result .= writeXMLline('DELIVERY_SCHEDULE', 'N', 3);
     $result .= writeXMLline('DELIVERY_SEPARATION', 'N', 3);
     $result .= writeXMLline('DELIVERY_PARCEL_TYPE', 'V99', 3);
     $result .= writeXMLline('DELIVERY_CARRIER', '6', 3);
     $result .= writeXMLclose('A_DELIVERY', 2);
     $result .= writeLine();
     //XML CROSSDOCK PACKAGE
     $result .= writeXMLopen('A_CROSSDOCK', 2);
     $result .= writeXMLline('CROSSDOCK_PACKAGE_WIDTH', '5', 3);
     $result .= writeXMLline('CROSSDOCK_PACKAGE_HEIGHT', '5', 3);
     $result .= writeXMLline('CROSSDOCK_PACKAGE_LENGTH', '5', 3);
     $result .= writeXMLline('CROSSDOCK_GROSS_WEIGHT', '0.05', 3);
     //$result .= writeXMLline('CROSSDOCK_PACKAGE_PIECES', '', 3);
     //$result .= writeXMLline('CROSSDOCK_PACKAGE_KEY', '', 3);
     //$result .= writeXMLline('CROSSDOCK_PROPERTY_KEY', '', 3);
     $result .= writeXMLclose('A_CROSSDOCK', 2);
     $result .= writeLine();
     //XML ELECTRIC APPLIANCE
     $result .= writeXMLopen('A_ELECTRIC_APPLIANCE', 2);
     $result .= writeXMLline('ELECTRIC_APPLIANCE_REGULATION', 'N', 3);
     $result .= writeXMLclose('A_ELECTRIC_APPLIANCE', 2);
     $result .= writeLine();
     //XML TRADESTAT
     $result .= writeXMLopen('A_TRADESTAT', 2);
     $result .= writeXMLline('TRADESTAT_ORG_COUNTRY', 'DEU', 3);
     $result .= writeXMLline('TRADESTAT_LABEL', '71131100', 3);
     $result .= writeXMLline('TRADESTAT_AMOUNT', '1', 3);
     $result .= writeXMLline('TRADESTAT_GROSS_WEIGHT', '50', 3);
     $result .= writeXMLclose('A_TRADESTAT', 2);
     $result .= writeLine();
     $result .= writeXMLclose('ARTICLEDATA', 1);
     $result .= writeLine();
     return $result;
 }