function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '')
 {
     if (empty($currency_type)) {
         $currency_type = SESSION_CURRENCY;
     }
     $currency = $this->currencies[$currency_type];
     if ($calculate_currency_value == true) {
         $rate = olc_not_null($currency_value) ? $currency_value : $currency['value'];
         $format_string = $currency[$this->symbol_left_text] . BLANK . number_format(olc_round($number * $rate, $currency[$this->decimal_places_text]), $currency[$this->decimal_places_text], $currency[$this->decimal_point_text], $currency[$this->thousands_point_text]) . BLANK . $currency[$this->symbol_right_text];
         // if the selected currency is in the european euro-conversion and the default currency is euro,
         // the currency will displayed in the national currency and euro currency
         if (DEFAULT_CURRENCY == 'EUR') {
             if (strpos('.DEM.BEF.LUF.ESP.FRF.IEP.ITL.NLG.ATS.PTE.FIM.GRD', $currency_type) > 0) {
                 $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
             }
         }
     } else {
         $format_string = $currency[$this->symbol_left_text] . BLANK . number_format(olc_round($number, $currency[$this->decimal_places_text]), $currency[$this->decimal_places_text], $currency[$this->decimal_point_text], $currency[$this->thousands_point_text]) . BLANK . $currency[$this->symbol_right_text];
     }
     $format_string = str_replace($currency[$this->decimal_zeroes_text], $currency[$this->decimal_zeroes_dashes_text], $format_string);
     return trim($format_string);
 }
<tr class="dataTableRow">
<?php 
    echo olc_draw_form('product_option_ins', FILENAME_ORDERS_EDIT, 'action=product_option_ins', 'post');
    echo olc_draw_hidden_field('cID', $_GET['cID']);
    echo olc_draw_hidden_field('oID', $_GET['oID']);
    echo olc_draw_hidden_field('pID', $_GET['pID']);
    echo olc_draw_hidden_field('pTX', $_GET['pTX']);
    echo olc_draw_hidden_field('aTX', $_GET['aTX']);
    echo olc_draw_hidden_field('qTY', $_GET['qTY']);
    echo olc_draw_hidden_field('opID', $_GET['opID']);
    echo olc_draw_hidden_field('aID', $products['products_attributes_id']);
    $brutto = PRICE_IS_BRUTTO;
    if ($brutto == TRUE_STRING_S) {
        $options_values_price = olc_round($products['options_values_price'] * (1 + $_GET['pTX'] / 100), PRICE_PRECISION);
    } else {
        $options_values_price = olc_round($products['options_values_price'], PRICE_PRECISION);
    }
    ?>
<td class="dataTableContent"><?php 
    echo $products['products_attributes_id'];
    ?>
</td>
<td class="dataTableContent"><?php 
    echo olc_oe_get_options_name($products['options_id']);
    ?>
</td>
<td class="dataTableContent"><?php 
    echo olc_oe_get_options_values_name($products['options_values_id']);
    ?>
</td>
<td class="dataTableContent">
// I found the easiest way to do this is just delete the current attributes & start over =)
olc_db_query(DELETE_FROM . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = '" . $current_product_id . APOS);
// Simple, yet effective.. loop through the selected Option Values.. find the proper price & prefix.. insert.. yadda yadda yadda.
for ($i = 0; $i < sizeof($_POST['optionValues']); $i++) {
    $optionValues = $_POST['optionValues'][$i];
    $query = "SELECT * FROM " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_values_id = '" . $optionValues . APOS;
    $result = olc_db_query($query);
    $matches = olc_db_num_rows($result);
    while ($line = olc_db_fetch_array($result, olc_db_ASSOC)) {
        $optionsID = $line['products_options_id'];
    }
    $value_price = $_POST[$optionValues . '_price'];
    if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
        $value_price = $value_price / (olc_get_tax_rate(olc_get_tax_class_id($current_product_id)) + 100) * 100;
    }
    $value_price = olc_round($value_price, PRICE_PRECISION);
    $value_prefix = $_POST[$optionValues . '_prefix'];
    $value_sortorder = $_POST[$optionValues . '_sortorder'];
    $value_weight_prefix = $_POST[$optionValues . '_weight_prefix'];
    $value_model = $_POST[$optionValues . '_model'];
    $value_stock = $_POST[$optionValues . '_stock'];
    $value_weight = $_POST[$optionValues . '_weight'];
    $insert_into = INSERT_INTO . TABLE_PRODUCTS_ATTRIBUTES . "(products_id,options_id,options_values_id,options_values_price,price_prefix" . COMMA;
    $comma_blank = "','";
    if ($optionTypeInstalled == '1') {
        $value_type = $_POST[$optionValues . '_type'];
        $value_qty = $_POST[$optionValues . '_qty'];
        $value_order = $_POST[$optionValues . '_order'];
        $value_linked = $_POST[$optionValues . '_linked'];
        olc_db_query($insert_into . "attributes_model,attributes_stock,options_type_id,options_values_qty,attribute_order,collegamento) VALUES ('" . $current_product_id . $comma_blank . optionsID . $comma_blank . $optionValues . $comma_blank . $value_price . $comma_blank . $value_model . $comma_blank . $value_stock . $comma_blank . $value_prefix . $comma_blank . $value_type . $comma_blank . $value_qty . $comma_blank . $value_order . $comma_blank . $value_linked . "')");
    } elseif ($optionSortCopyInstalled == '1') {
                <td nowrap="nowrap" width="142" class="main" style="border: 1px solid;">
<?php 
            $personal_offer0 = $staffel_values['personal_offer'];
            $personal_offer = $personal_offer0;
            if ($is_brutto) {
                /*
                $tax_query = olc_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_class_id = '" .
                	$pInfo->products_tax_class_id . "' ");
                $tax = olc_db_fetch_array($tax_query);
                */
                $personal_offer = $personal_offer * $tax_rate;
            }
            $products_price = olc_round($personal_offer, PRICE_PRECISION);
            echo $products_price;
            if ($is_brutto) {
                echo ' <br/>' . TEXT_NETTO . HTML_B_START . olc_format_price(olc_round($personal_offer0, PRICE_PRECISION), 1, 1) . '</b>  ';
            }
            ?>
 </td>
                <td width="80" align="left"><?php 
            echo olc_draw_separator('pixel_trans.gif', '1', '10');
            ?>
                	<a href="<?php 
            echo olc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&function=delete&quantity=' . $staffel_values['quantity'] . '&statusID=' . $products_id . '&action=new_product&pID=' . $_GET['pID']);
            ?>
">
                	<?php 
            echo olc_image_button('button_delete.gif', IMAGE_DELETE);
            ?>
</a>
                </td>
echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_6) . '\')">' . TEXT_SUMMARY_HELP . HTML_A_END;
?>
</td>
                  <td width="15%" class="dataTableContent"><?php 
echo $currencies->display_price($affiliate_average, '');
?>
</td>
                </tr>
                <tr>
                  <td width="35%" align="right" class="dataTableContent"><?php 
echo TEXT_COMMISSION_RATE;
echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_7) . '\')">' . TEXT_SUMMARY_HELP . HTML_A_END;
?>
</td>
                  <td width="15%" class="dataTableContent"><?php 
echo olc_round(AFFILIATE_PERCENT, 2) . ' %';
?>
</td>
                  <td width="35%" align="right" class="dataTableContent"><b><?php 
echo TEXT_COMMISSION;
echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_8) . '\')">' . TEXT_SUMMARY_HELP . HTML_A_END;
?>
</b></td>
                  <td width="15%" class="dataTableContent"><b><?php 
echo $currencies->display_price($affiliate_commission, '');
?>
</b></td>
                </tr>
                <tr>
                  <td colspan="4"><?php 
echo olc_draw_separator();
                $contents[] = array('align' => 'center', 'text' => HTML_A_START . olc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product') . '">' . olc_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . olc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=delete_product') . '">' . olc_image_button('button_delete.gif', IMAGE_DELETE) . '</a> <a href="' . olc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=move_product') . '">' . olc_image_button('button_move.gif', IMAGE_MOVE) . '</a> <a href="' . olc_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=copy_to') . '">' . olc_image_button('button_copy_to.gif', IMAGE_COPY_TO) . HTML_A_END . olc_draw_form('edit_attributes', FILENAME_NEW_ATTRIBUTES, EMPTY_STRING, 'post') . '
		<input type="hidden" name="action" value="edit"><input type="hidden" name="current_product_id" value="' . $pInfo->products_id . '"><input type="hidden" name="cpath" value="' . $cPath . '">' . olc_image_submit('button_edit_attributes.gif', 'edit_attributes') . '</form>');
                $contents[] = array('text' => HTML_BR . TEXT_DATE_ADDED . HTML_NBSP . olc_date_short($pInfo->products_date_added));
                if (olc_not_null($pInfo->products_last_modified)) {
                    $contents[] = array('text' => TEXT_LAST_MODIFIED . HTML_NBSP . olc_date_short($pInfo->products_last_modified));
                }
                if (date('Y-m-d') < $pInfo->products_date_available) {
                    $contents[] = array('text' => sprintf(TEXT_DATE_AVAILABLE, olc_date_short($pInfo->products_date_available)));
                }
                $contents[] = array('text' => HTML_BR . olc_product_info_image($pInfo->products_image, $pInfo->products_name) . HTML_BR . $pInfo->products_image);
                // START IN-SOLUTION Berechung des Bruttopreises
                $price = $pInfo->products_price;
                $price = olc_round($price, PRICE_PRECISION);
                $price_string = TEXT_PRODUCTS_PRICE_INFO . HTML_NBSP . $currencies->format($price);
                if (PRICE_IS_BRUTTO == TRUE_STRING_S && ($_GET['read'] == 'only' || $action != 'new_product_preview')) {
                    $price_netto = olc_round($price, PRICE_PRECISION);
                    $tax_query = olc_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_class_id = '" . $pInfo->products_tax_class_id . APOS);
                    $tax = olc_db_fetch_array($tax_query);
                    $price = $price * ($tax[tax_rate] + 100) / 100;
                    $price_string = TEXT_PRODUCTS_PRICE_INFO . $currencies->format($price) . ' - ' . TXT_NETTO . $currencies->format($price_netto);
                }
                $contents[] = array('text' => HTML_BR . $price_string . HTML_BR . TEXT_PRODUCTS_DISCOUNT_ALLOWED_INFO . HTML_NBSP . $pInfo->products_discount_allowed . HTML_BR . TEXT_PRODUCTS_QUANTITY_INFO . HTML_NBSP . $pInfo->products_quantity);
                // END IN-SOLUTION
                //            $contents[] = array('text' => HTML_BR . TEXT_PRODUCTS_PRICE_INFO . HTML_NBSP . $currencies->format($pInfo->products_price) . HTML_BR . TEXT_PRODUCTS_QUANTITY_INFO . HTML_NBSP . $pInfo->products_quantity);
                $contents[] = array('text' => HTML_BR . TEXT_PRODUCTS_AVERAGE_RATING . HTML_NBSP . number_format($pInfo->average_rating, 2) . '%');
            }
        } else {
            // create category/product info
            $heading[] = array('text' => HTML_B_START . EMPTY_CATEGORY . HTML_B_END);
            $contents[] = array('text' => sprintf(TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS, $parent_categories_name));
        }
             }
             $personal_price = olc_round($personal_price, PRICE_PRECISION);
         }
         olc_db_query(SQL_UPDATE . TABLE_PERSONAL_OFFERS_BY_CUSTOMERS_STATUS . $group_data_status_id . " SET personal_offer = '" . $personal_price . "' WHERE products_id = " . $products_id . " AND quantity = '1'");
     }
 }
 // end
 for ($col = 0, $n = sizeof($group_data); $col < $n + 1; $col++) {
     $group_data_status_id = $group_data[$col]['STATUS_ID'];
     if ($group_data_status_id != EMPTY_STRING) {
         $quantity = olc_db_prepare_input($_POST['products_quantity_staffel_' . $group_data_status_id]);
         $staffelpreis = olc_db_prepare_input($_POST['products_price_staffel_' . $group_data_status_id]);
         if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
             $staffelpreis = $staffelpreis / (olc_get_tax_rate($_POST['products_tax_class_id']) + 100) * 100;
         }
         $staffelpreis = olc_round($staffelpreis, PRICE_PRECISION);
         if ($staffelpreis != EMPTY_STRING && $quantity != EMPTY_STRING) {
             // ok, lets check entered data to get rid of user faults
             if ($quantity <= 1) {
                 $quantity = 2;
             }
             $table = TABLE_PERSONAL_OFFERS_BY_CUSTOMERS_STATUS . $group_data_status_id;
             $check_query = olc_db_query("SELECT quantity FROM " . $table . " WHERE products_id=" . $products_id . " and quantity=" . $quantity);
             // dont insert if same qty!
             if (olc_db_num_rows($check_query) < 1) {
                 olc_db_query(INSERT_INTO . $table . " (price_id, products_id, quantity, personal_offer) values ('', '" . $products_id . COMMA . $quantity . $comma_blank . $staffelpreis . "')");
             }
         }
     }
 }
 $products_promotion_title_text = 'products_promotion_title';
        $sql_data_array = array('orders_id' => olc_db_prepare_input($_POST['orders_id']), 'title' => olc_db_prepare_input($title), 'text' => olc_db_prepare_input($text), 'value' => olc_db_prepare_input($ust['tax_value_new']), 'class' => 'ot_tax');
        $insert_sql_data = array('sort_order' => $sort);
        $sql_data_array = olc_array_merge($sql_data_array, $insert_sql_data);
        olc_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
    }
    olc_db_query(DELETE_FROM . TABLE_ORDERS_RECALCULATE . " where orders_id = '" . olc_db_input($_POST['orders_id']) . APOS);
    // Neue UST Zusammenrechnen und in die DB Schreiben ENDE
    // Errechne neue MWSt. für die Bestellung Ende
    // Errechne neue Gesamtsumme für die Bestellung Anfang
    if ($allow_tax == '1') {
        $total_query = olc_db_query("select SUM(value) as value_new from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $_POST['orders_id'] . "' and class!='ot_coupon' and class!='ot_gv' and class!='ot_tax' and class!='ot_total'");
    } else {
        $total_query = olc_db_query("select SUM(value) as value_new from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $_POST['orders_id'] . "' and class!='ot_coupon' and class!='ot_gv' and class!='ot_subtotal_no_tax' and class!='ot_total'");
    }
    $total = olc_db_fetch_array($total_query);
    $text = $currencies->format(olc_round($total['value_new'], PRICE_PRECISION));
    $sql_data_array = array('orders_id' => olc_db_prepare_input($_POST['orders_id']), 'value' => olc_db_prepare_input($total['value_new']));
    $update_sql_data = array('text' => $text);
    $sql_data_array = olc_array_merge($sql_data_array, $update_sql_data);
    olc_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array, 'update', 'orders_id = \'' . olc_db_input($_POST['orders_id']) . '\' and class="ot_total"');
    olc_redirect(olc_href_link(FILENAME_ORDERS, 'action=edit&oID=' . $_POST['orders_id']));
}
// Errechne neue Gesamtsumme für die Bestellung Ende
// Löschfunktionen Anfang
if ($_GET['action'] == "product_delete") {
    olc_db_query(DELETE_FROM . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . olc_db_input($_POST['oID']) . "' and orders_products_id = '" . olc_db_input($_POST['opID']) . APOS);
    $products_attrbutes_query = olc_db_query("select orders_products_attributes_id from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_products_id = '" . olc_db_input($_POST['opID']) . APOS);
    if (olc_db_num_rows(products_attrbutes_query)) {
        olc_db_query(DELETE_FROM . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_products_id = '" . olc_db_input($_POST['opID']) . APOS);
    }
    olc_redirect(olc_href_link(FILENAME_ORDERS_EDIT, 'edit_action=products&cID=' . $_POST['cID'] . '&oID=' . $_POST['oID']));
}
$affiliate_total = olc_round($affiliate_total, 2);
// Check for individual commission
$affiliate_percentage = 0;
if (AFFILATE_INDIVIDUAL_PERCENTAGE == TRUE_STRING_S) {
    $affiliate_commission_query = olc_db_query("select affiliate_commission_percent from " . TABLE_AFFILIATE . " where affiliate_id = '" . $_SESSION['affiliate_ref'] . APOS);
    $affiliate_commission = olc_db_fetch_array($affiliate_commission_query);
    $affiliate_percent = $affiliate_commission['affiliate_commission_percent'];
}
if ($affiliate_percent < AFFILIATE_PERCENT) {
    $affiliate_percent = AFFILIATE_PERCENT;
}
$affiliate_payment = olc_round($affiliate_total * $affiliate_percent / 100, 2);
if (isset($_SESSION['affiliate_ref'])) {
    $sql_data_array = array('affiliate_id' => $_SESSION['affiliate_ref'], 'affiliate_date' => $affiliate_clientdate, 'affiliate_browser' => $affiliate_clientbrowser, 'affiliate_ipaddress' => $affiliate_clientip, 'affiliate_value' => $affiliate_total, 'affiliate_payment' => $affiliate_payment, 'affiliate_orders_id' => $insert_id, 'affiliate_clickthroughs_id' => $_SESSION['affiliate_clickthroughs_id'], 'affiliate_percent' => $affiliate_percent, 'affiliate_salesman' => $_SESSION['affiliate_ref'], 'affiliate_level' => '0');
    olc_db_perform(TABLE_AFFILIATE_SALES, $sql_data_array);
    if (AFFILATE_USE_TIER == TRUE_STRING_S) {
        $affiliate_tiers_query = olc_db_query("SELECT aa2.affiliate_id, (aa2.affiliate_rgt - aa2.affiliate_lft) as height\n                                                      FROM  " . TABLE_AFFILIATE . "  AS aa1, " . TABLE_AFFILIATE . "  AS aa2\n                                                      WHERE  aa1.affiliate_root = aa2.affiliate_root\n                                                            AND aa1.affiliate_lft BETWEEN aa2.affiliate_lft AND aa2.affiliate_rgt\n                                                            AND aa1.affiliate_rgt BETWEEN aa2.affiliate_lft AND aa2.affiliate_rgt\n                                                            AND aa1.affiliate_id =  '" . $_SESSION['affiliate_ref'] . "'\n                                                      ORDER by height asc limit 1, " . AFFILIATE_TIER_LEVELS);
        $affiliate_tier_percentage = split("[;]", AFFILIATE_TIER_PERCENTAGE);
        $i = 0;
        while ($affiliate_tiers_array = olc_db_fetch_array($affiliate_tiers_query)) {
            $affiliate_percent = $affiliate_tier_percentage[$i];
            $affiliate_payment = olc_round($affiliate_total * $affiliate_percent / 100, 2);
            if ($affiliate_payment > 0) {
                $sql_data_array = array('affiliate_id' => $affiliate_tiers_array['affiliate_id'], 'affiliate_date' => $affiliate_clientdate, 'affiliate_browser' => $affiliate_clientbrowser, 'affiliate_ipaddress' => $affiliate_clientip, 'affiliate_value' => $affiliate_total, 'affiliate_payment' => $affiliate_payment, 'affiliate_orders_id' => $insert_id, 'affiliate_clickthroughs_id' => $_SESSION['affiliate_clickthroughs_id'], 'affiliate_percent' => $affiliate_percent, 'affiliate_salesman' => $_SESSION['affiliate_ref'], 'affiliate_level' => $i + 1);
                olc_db_perform(TABLE_AFFILIATE_SALES, $sql_data_array);
            }
            $i++;
        }
    }
}
 function process_button()
 {
     global $order, $order_total_modules, $currencies, $currency, $languages_id;
     $result = olc_db_query("SELECT code FROM " . TABLE_LANGUAGES . " WHERE languages_id = '" . SESSION_LANGUAGE_ID . APOS);
     list($key, $lang_code) = olc_db_fetch_array($result);
     $mbLanguage = strtoupper($lang_code);
     if ($mbLanguage == "US") {
         $mbLanguage = "EN";
     }
     if (!in_array($mbLanguage, $this->mbLanguages)) {
         $mbLanguage = MODULE_PAYMENT_MONEYBOOKERS_LANGUAGE;
     }
     $mbCurrency = $currency;
     if (!in_array($currency, $this->mbCurrencies)) {
         $mbCurrency = MODULE_PAYMENT_MONEYBOOKERS_CURRENCY;
     }
     $result = olc_db_query("SELECT mb_cID FROM " . TABLE_PAYMENT_MONEYBOOKERS_COUNTRIES . ", " . TABLE_COUNTRIES . "  WHERE (osc_cID = countries_id) AND (countries_id = '{$order->billing['country']['id']}')");
     list($key, $mbCountry) = olc_db_fetch_array($result);
     $this->transaction_id = $this->generate_trid();
     $result = olc_db_query(INSERT_INTO . TABLE_PAYMENT_MONEYBOOKERS . " (mb_TRID, mb_DATE) VALUES ('{$this->transaction_id}', NOW())");
     if ($_SESSION['currency'] == $mbCurrency) {
         $amount = olc_round($order->info['total'], $currencies->get_decimal_places($mbCurrency));
     } else {
         $amount = olc_round($order->info['total'] * $currencies->get_value($mbCurrency), $currencies->get_decimal_places($mbCurrency));
     }
     $process_button_string = olc_draw_hidden_field('pay_to_email', MODULE_PAYMENT_MONEYBOOKERS_EMAILID) . olc_draw_hidden_field('transaction_id', $this->transaction_id) . olc_draw_hidden_field('return_url', olc_href_link(FILENAME_CHECKOUT_PROCESS, 'trid=' . $this->transaction_id, NONSSL, false)) . olc_draw_hidden_field('cancel_url', olc_href_link(FILENAME_CHECKOUT_PAYMENT, MODULE_PAYMENT_MONEYBOOKERS_ERRORTEXT1 . $this->code . MODULE_PAYMENT_MONEYBOOKERS_ERRORTEXT2, SSL, true, false)) . olc_draw_hidden_field('status_url', 'mailto:' . MODULE_PAYMENT_MONEYBOOKERS_EMAILID) . olc_draw_hidden_field('language', $mbLanguage) . olc_draw_hidden_field('pay_from_email', $order->customer['email_address']) . olc_draw_hidden_field('amount', $amount) . olc_draw_hidden_field('currency', $mbCurrency) . olc_draw_hidden_field('detail1_description', STORE_NAME) . olc_draw_hidden_field('detail1_text', MODULE_PAYMENT_MONEYBOOKERS_ORDER_TEXT . strftime(DATE_FORMAT_LONG)) . olc_draw_hidden_field('firstname', $order->billing['firstname']) . olc_draw_hidden_field('lastname', $order->billing['lastname']) . olc_draw_hidden_field('address', $order->billing['street_address']) . olc_draw_hidden_field('postal_code', $order->billing['postcode']) . olc_draw_hidden_field('city', $order->billing['city']) . olc_draw_hidden_field('state', $order->billing['state']) . olc_draw_hidden_field('country', $mbCountry) . olc_draw_hidden_field('confirmation_note', MODULE_PAYMENT_MONEYBOOKERS_CONFIRMATION_TEXT);
     if (ereg("[0-9]{6}", MODULE_PAYMENT_MONEYBOOKERS_REFID)) {
         $process_button_string .= olc_draw_hidden_field('rid', MODULE_PAYMENT_MONEYBOOKERS_REFID);
     }
     // moneyboocers.com payment gateway does not accept accented characters!
     // Please feel free to add any other accented characters to the list.
     return strtr($process_button_string, "áéíóöõúüûÁÉÍÓÖÕÚÜÛ", "aeiooouuuAEIOOOUUU");
 }
        <td class="main"><?php 
    echo TEXT_SPECIALS_PRODUCT;
    ?>
&nbsp;</td>
<?php 
    $price = abs($sInfo->products_price);
    $new_price = $sInfo->specials_new_products_price;
    if ($is_brutto) {
        $price_netto = olc_round($price, PRICE_PRECISION);
        $new_price_netto = olc_round($new_price, PRICE_PRECISION);
        $tax_factor = (olc_get_tax_rate($sInfo->products_tax_class_id) + 100) / 100;
        $price = $price * $tax_factor;
        $new_price = $new_price * $tax_factor;
    }
    $price = olc_round($price, PRICE_PRECISION);
    $new_price = olc_round($new_price, PRICE_PRECISION);
    echo olc_draw_hidden_field("products_up_id", $sInfo->products_id);
    ?>
	          <td class="main"><?php 
    echo $sInfo->products_name ? $sInfo->products_name . ' <small>(' . ltrim(olc_format_price($price, 1, 1)) . ')</small>' : olc_draw_products_pull_down('products_id', 'style="font-size:10px"', $specials_array);
    echo olc_draw_hidden_field($products_price_text, $sInfo->products_price);
    ?>
</td>
				  </tr>
          <tr>
            <td class="main"><?php 
    echo TEXT_SPECIALS_SPECIAL_PRICE;
    ?>
&nbsp;</td>
            <td class="main"><?php 
    echo olc_draw_input_field($specials_price_text, $new_price);
$smarty->assign('LINK_TRANSACTIONS', '<a href="javascript:popupWindow(\'' . olc_href_link(FILENAME_AFFILIATE_HELP_3) . '\')">');
$smarty->assign('LINK_CONVERSION', '<a href="javascript:popupWindow(\'' . olc_href_link(FILENAME_AFFILIATE_HELP_4) . '\')">');
$smarty->assign('LINK_AMOUNT', '<a href="javascript:popupWindow(\'' . olc_href_link(FILENAME_AFFILIATE_HELP_5) . '\')">');
$smarty->assign('LINK_AVERAGE', '<a href="javascript:popupWindow(\'' . olc_href_link(FILENAME_AFFILIATE_HELP_6) . '\')">');
$smarty->assign('LINK_COMISSION_RATE', '<a href="javascript:popupWindow(\'' . olc_href_link(FILENAME_AFFILIATE_HELP_7) . '\')">');
$smarty->assign('LINK_COMISSION', '<a href="javascript:popupWindow(\'' . olc_href_link(FILENAME_AFFILIATE_HELP_8) . '\')">');
if (AFFILATE_USE_TIER == TRUE_STRING_S) {
    $smarty->assign('AFFILIATE_USE_TIER', TRUE_STRING_S);
    for ($tier_number = 0; $tier_number <= AFFILIATE_TIER_LEVELS; $tier_number++) {
        if (is_null($affiliate_percent_tier[$tier_number - 1])) {
            $affiliate_percent_tier[$tier_number - 1] = $affiliate_percent;
        }
        $affiliate_percent_tier_table .= '<tr>';
        $affiliate_percent_tier_table .= '<td width="15%" class="boxtext"><a href=' . olc_href_link(FILENAME_AFFILIATE_SALES, 'a_level=' . $tier_number . '&a_period=' . $a_period, SSL) . '>' . TEXT_COMMISSION_LEVEL_TIER . $tier_number . '</a></td>';
        $affiliate_percent_tier_table .= '<td width="15%" align="right" class="boxtext"><a href=' . olc_href_link(FILENAME_AFFILIATE_SALES, 'a_level=' . $tier_number . '&a_period=' . $a_period, SSL) . '>' . TEXT_COMMISSION_RATE_TIER . '</a></td>';
        $affiliate_percent_tier_table .= '<td width="5%" class="boxtext">' . olc_round($affiliate_percent_tier[$tier_number - 1], 2) . '%' . '</td>';
        $affiliate_percent_tier_table .= '<td width="15%" align="right" class="boxtext"><a href=' . olc_href_link(FILENAME_AFFILIATE_SALES, 'a_level=' . $tier_number . '&a_period=' . $a_period, SSL) . '>' . TEXT_COMMISSION_TIER_COUNT . '</a></td>';
        $affiliate_percent_tier_table .= '<td width="5%" class="boxtext">' . ($affiliate_sales[$tier_number]['count'] > 0 ? $affiliate_sales[$tier_number]['count'] : '0') . '</td>';
        $affiliate_percent_tier_table .= '<td width="15%" align="right" class="boxtext"><a href=' . olc_href_link(FILENAME_AFFILIATE_SALES, 'a_level=' . $tier_number . '&a_period=' . $a_period, SSL) . '>' . TEXT_COMMISSION_TIER_TOTAL . '</a></td>';
        $affiliate_percent_tier_table .= '<td width="5%" class="boxtext">' . $currencies->display_price($affiliate_sales[$tier_number]['total'], '') . '</td>';
        $affiliate_percent_tier_table .= '<td width="20%" align="right" class="boxtext"><a href=' . olc_href_link(FILENAME_AFFILIATE_SALES, 'a_level=' . $tier_number . '&a_period=' . $a_period, SSL) . '>' . TEXT_COMMISSION_TIER . '</a></td>';
        $affiliate_percent_tier_table .= '<td width="5%" class="boxtext">' . $currencies->display_price($affiliate_sales[$tier_number]['payment'], '') . '</td>';
        $affiliate_percent_tier_table .= '</tr>';
    }
    $smarty->assign('affiliate_percent_tier_table', $affiliate_percent_tier_table);
}
$smarty->assign('LINK_BANNER', HTML_A_START . olc_href_link(FILENAME_AFFILIATE_BANNERS) . '">' . olc_image_button('button_affiliate_banners.gif', IMAGE_BANNERS) . HTML_A_END);
$smarty->assign('LINK_CLICKS', HTML_A_START . olc_href_link(FILENAME_AFFILIATE_CLICKS, '', SSL) . '">' . olc_image_button('button_affiliate_clickthroughs.gif', IMAGE_CLICKTHROUGHS) . HTML_A_END);
$smarty->assign('LINK_SALES', HTML_A_START . olc_href_link(FILENAME_AFFILIATE_SALES, 'a_period=' . $a_period, SSL) . '">' . olc_image_button('button_affiliate_sales.gif', IMAGE_SALES) . HTML_A_END);
$main_content = $smarty->fetch(CURRENT_TEMPLATE_MODULE . 'affiliate_summary' . HTML_EXT, SMARTY_CACHE_ID);
$smarty->assign(MAIN_CONTENT, $main_content);
$affiliate = olc_db_fetch_array($affiliate_query);
$affiliate_percent = 0;
$affiliate_percent = $affiliate['affiliate_commission_percent'];
if ($affiliate_percent < AFFILIATE_PERCENT) {
    $affiliate_percent = AFFILIATE_PERCENT;
}
$affiliate_clickthroughs_raw = "select count(*) as count from " . TABLE_AFFILIATE_CLICKTHROUGHS . " where affiliate_id = '" . $_GET['acID'] . APOS;
$affiliate_clickthroughs_query = olc_db_query($affiliate_clickthroughs_raw);
$affiliate_clickthroughs = olc_db_fetch_array($affiliate_clickthroughs_query);
$affiliate_clickthroughs = $affiliate_clickthroughs['count'];
$affiliate_sales_raw = "\n    select count(*) as count, sum(affiliate_value) as total, sum(affiliate_payment) as payment from " . TABLE_AFFILIATE_SALES . " a\n    left join " . TABLE_ORDERS . " o on (a.affiliate_orders_id=o.orders_id)\n    where a.affiliate_id = '" . $_GET['acID'] . "' and o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . "\n    ";
$affiliate_sales_query = olc_db_query($affiliate_sales_raw);
$affiliate_sales = olc_db_fetch_array($affiliate_sales_query);
$affiliate_transactions = $affiliate_sales['count'];
if ($affiliate_clickthroughs > 0) {
    $affiliate_conversions = olc_round($affiliate_transactions / $affiliate_clickthroughs * 100, 2) . "%";
} else {
    $affiliate_conversions = "n/a";
}
if ($affiliate_sales['total'] > 0) {
    $affiliate_average = $affiliate_sales['total'] / $affiliate_sales['count'];
} else {
    $affiliate_average = 0;
}
require DIR_WS_INCLUDES . 'header.php';
?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td class="columnLeft2" nowrap="nowrap" valign="top"><table border="0" cellspacing="1" cellpadding="1" class="columnLeft" nowrap="nowrap">
<!-- left_navigation //-->
<?php 
 function insert_product($products_data, $dest_category_id, $action = 'insert')
 {
     $products_id = olc_db_prepare_input($products_data['products_id']);
     $products_date_available = olc_db_prepare_input($products_data['products_date_available']);
     $products_date_available = date('Y-m-d') < $products_date_available ? $products_date_available : 'null';
     if ($products_data['products_startpage'] == 1) {
         $this->link_product($products_data['products_id'], 0);
         $products_status = 1;
     } else {
         $products_status = olc_db_prepare_input($products_data['products_status']);
     }
     if ($products_data['products_startpage'] == 0) {
         $products_status = olc_db_prepare_input($products_data['products_status']);
     }
     if (PRICE_IS_BRUTTO == TRUE_STRING_S && $products_data['products_price']) {
         $products_data['products_price'] = round($products_data['products_price'] / (olc_get_tax_rate($products_data['products_tax_class_id']) + 100) * 100, PRICE_PRECISION);
     }
     //
     $customers_statuses_array = olc_get_customers_statuses();
     $permission = array();
     for ($i = 0; $n = sizeof($customers_statuses_array), $i < $n; $i++) {
         if (isset($customers_statuses_array[$i]['id'])) {
             $permission[$customers_statuses_array[$i]['id']] = 0;
         }
     }
     if (isset($products_data['groups'])) {
         foreach ($products_data['groups'] as $dummy => $b) {
             $permission[$b] = 1;
         }
     }
     // build array
     if ($permission['all'] == 1) {
         $permission = array();
         end($customers_statuses_array);
         for ($i = 0; $n = key($customers_statuses_array), $i < $n + 1; $i++) {
             if (isset($customers_statuses_array[$i]['id'])) {
                 $permission[$customers_statuses_array[$i]['id']] = 1;
             }
         }
     }
     $permission_array = array();
     // set pointer to last key
     end($customers_statuses_array);
     for ($i = 0; $n = key($customers_statuses_array), $i < $n + 1; $i++) {
         if (isset($customers_statuses_array[$i]['id'])) {
             $permission_array = array_merge($permission_array, array('group_permission_' . $customers_statuses_array[$i]['id'] => $permission[$customers_statuses_array[$i]['id']]));
         }
     }
     //
     $sql_data_array = array('products_quantity' => olc_db_prepare_input($products_data['products_quantity']), 'products_model' => olc_db_prepare_input($products_data['products_model']), 'products_ean' => olc_db_prepare_input($products_data['products_ean']), 'products_price' => olc_db_prepare_input($products_data['products_price']), 'products_sort' => olc_db_prepare_input($products_data['products_sort']), 'products_shippingtime' => olc_db_prepare_input($products_data['shipping_status']), 'products_discount_allowed' => olc_db_prepare_input($products_data['products_discount_allowed']), 'products_date_available' => $products_date_available, 'products_weight' => olc_db_prepare_input($products_data['products_weight']), 'products_status' => $products_status, 'products_startpage' => olc_db_prepare_input($products_data['products_startpage']), 'products_startpage_sort' => olc_db_prepare_input($products_data['products_startpage_sort']), 'products_tax_class_id' => olc_db_prepare_input($products_data['products_tax_class_id']), 'product_template' => olc_db_prepare_input($products_data['info_template']), 'options_template' => olc_db_prepare_input($products_data['options_template']), 'manufacturers_id' => olc_db_prepare_input($products_data['manufacturers_id']), 'products_fsk18' => olc_db_prepare_input($products_data['fsk18']), 'products_vpe_value' => olc_db_prepare_input($products_data['products_vpe_value']), 'products_vpe_status' => olc_db_prepare_input($products_data['products_vpe_status']), 'products_vpe' => olc_db_prepare_input($products_data['products_vpe']), 'products_promotion_status' => olc_db_prepare_input($products_data['products_promotion_status']), 'products_promotion_product_title' => olc_db_prepare_input($products_data['products_promotion_product_title']), 'products_promotion_product_desc' => olc_db_prepare_input($products_data['products_promotion_product_desc']));
     $sql_data_array = array_merge($sql_data_array, $permission_array);
     //get the next ai-value from table products if no products_id is set
     if (!$products_id || $products_id == '') {
         $new_pid_query = olc_db_query("SHOW TABLE STATUS LIKE '" . TABLE_PRODUCTS . "'");
         $new_pid_query_values = olc_db_fetch_array($new_pid_query);
         $products_id = $new_pid_query_values['Auto_increment'];
     }
     //prepare products_image filename
     if ($products_image = olc_try_upload('products_image', DIR_FS_CATALOG_ORIGINAL_IMAGES, '777', '')) {
         $pname_arr = explode('.', $products_image->filename);
         $nsuffix = array_pop($pname_arr);
         $products_image_name = $products_id . '_0.' . $nsuffix;
         $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                               WHERE products_image = '" . $products_data['products_previous_image_0'] . "'");
         $dup_check = olc_db_fetch_array($dup_check_query);
         if ($dup_check['total'] < 2) {
             @olc_del_image_file($products_data['products_previous_image_0']);
         }
         //workaround if there are v2 images mixed with v3
         $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                               WHERE products_image = '" . $products_image->filename . "'");
         $dup_check = olc_db_fetch_array($dup_check_query);
         if ($dup_check['total'] == 0) {
             rename(DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image->filename, DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image_name);
         } else {
             copy(DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image->filename, DIR_FS_CATALOG_ORIGINAL_IMAGES . $products_image_name);
         }
         $sql_data_array['products_image'] = olc_db_prepare_input($products_image_name);
         require DIR_WS_INCLUDES . 'product_thumbnail_images.php';
         require DIR_WS_INCLUDES . 'product_info_images.php';
         require DIR_WS_INCLUDES . 'product_popup_images.php';
     } else {
         $products_image_name = $products_data['products_previous_image_0'];
     }
     //are we asked to delete some pics?
     if ($products_data['del_pic'] != '') {
         $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                               WHERE products_image = '" . $products_data['del_pic'] . "'");
         $dup_check = olc_db_fetch_array($dup_check_query);
         if ($dup_check['total'] < 2) {
             @olc_del_image_file($products_data['del_pic']);
         }
         olc_db_query("SQL_UPDATE " . TABLE_PRODUCTS . "\n\t\t\t\t\t\t\t\t                 SET products_image = ''\n\t\t\t\t\t\t\t\t               WHERE products_id    = '" . olc_db_input($products_id) . "'");
     }
     if ($products_data['del_mo_pic'] != '') {
         foreach ($products_data['del_mo_pic'] as $dummy => $val) {
             $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS_IMAGES . "\n\t\t\t\t\t\t\t\t\t\t\t                               WHERE image_name = '" . $val . "'");
             $dup_check = olc_db_fetch_array($dup_check_query);
             if ($dup_check['total'] < 2) {
                 @olc_del_image_file($val);
             }
             olc_db_query("DELETE FROM " . TABLE_PRODUCTS_IMAGES . "\n\t\t\t\t\t\t\t\t\t\t\t               WHERE products_id = '" . olc_db_input($products_id) . "'\n\t\t\t\t\t\t\t\t\t\t\t                 AND image_name  = '" . $val . "'");
         }
     }
     //MO_PICS
     for ($img = 0; $img < MO_PICS; $img++) {
         if ($pIMG =& olc_try_upload('mo_pics_' . $img, DIR_FS_CATALOG_ORIGINAL_IMAGES, '777', '')) {
             $pname_arr = explode('.', $pIMG->filename);
             $nsuffix = array_pop($pname_arr);
             $products_image_name = $products_id . '_' . ($img + 1) . '.' . $nsuffix;
             $dup_check_query = xtDBquery("SELECT COUNT(*) AS total\n\t\t\t\t\t\t\t\t\t\t\t                                FROM " . TABLE_PRODUCTS_IMAGES . "\n\t\t\t\t\t\t\t\t\t\t\t                               WHERE image_name = '" . $products_data['products_previous_image_' . ($img + 1)] . "'");
             $dup_check = olc_db_fetch_array($dup_check_query);
             if ($dup_check['total'] < 2) {
                 @olc_del_image_file($products_data['products_previous_image_' . ($img + 1)]);
             }
             @olc_del_image_file($products_image_name);
             rename(DIR_FS_CATALOG_ORIGINAL_IMAGES . '/' . $pIMG->filename, DIR_FS_CATALOG_ORIGINAL_IMAGES . '/' . $products_image_name);
             //get data & write to table
             $mo_img = array('products_id' => olc_db_prepare_input($products_id), 'image_nr' => olc_db_prepare_input($img + 1), 'image_name' => olc_db_prepare_input($products_image_name));
             if ($action == 'insert') {
                 olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img);
             } elseif ($action == 'update' && $products_data['products_previous_image_' . ($img + 1)]) {
                 if ($products_data['del_mo_pic']) {
                     foreach ($products_data['del_mo_pic'] as $dummy => $val) {
                         if ($val == $products_data['products_previous_image_' . ($img + 1)]) {
                             olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img);
                         }
                         break;
                     }
                 }
                 olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img, 'update', 'image_name = \'' . olc_db_input($products_data['products_previous_image_' . ($img + 1)]) . '\'');
             } elseif (!$products_data['products_previous_image_' . ($img + 1)]) {
                 olc_db_perform(TABLE_PRODUCTS_IMAGES, $mo_img);
             }
             //image processing
             require DIR_WS_INCLUDES . 'product_thumbnail_images.php';
             require DIR_WS_INCLUDES . 'product_info_images.php';
             require DIR_WS_INCLUDES . 'product_popup_images.php';
         }
     }
     if (isset($products_data['products_image']) && olc_not_null($products_data['products_image']) && $products_data['products_image'] != 'none') {
         $sql_data_array['products_image'] = olc_db_prepare_input($products_data['products_image']);
     }
     if ($action == 'insert') {
         $insert_sql_data = array('products_date_added' => 'now()');
         $sql_data_array = olc_array_merge($sql_data_array, $insert_sql_data);
         olc_db_perform(TABLE_PRODUCTS, $sql_data_array);
         $products_id = olc_db_insert_id();
         olc_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_CATEGORIES . "\n\t\t\t\t\t\t\t\t              SET products_id   = '" . $products_id . "',\n\t\t\t\t\t\t\t\t              categories_id = '" . $dest_category_id . "'");
     } elseif ($action == 'update') {
         $update_sql_data = array('products_last_modified' => 'now()');
         $sql_data_array = olc_array_merge($sql_data_array, $update_sql_data);
         olc_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', 'products_id = \'' . olc_db_input($products_id) . '\'');
     }
     $languages = olc_get_languages();
     // Here we go, lets write Group prices into db
     // start
     $i = 0;
     $group_query = olc_db_query("SELECT customers_status_id\n\t\t\t\t\t                               FROM " . TABLE_CUSTOMERS_STATUS . "\n\t\t\t\t\t                              WHERE language_id = '" . (int) $_SESSION['languages_id'] . "'\n\t\t\t\t\t                                AND customers_status_id != '0'");
     while ($group_values = olc_db_fetch_array($group_query)) {
         // load data into array
         $i++;
         $group_data[$i] = array('STATUS_ID' => $group_values['customers_status_id']);
     }
     for ($col = 0, $n = sizeof($group_data); $col < $n + 1; $col++) {
         if ($group_data[$col]['STATUS_ID'] != '') {
             $personal_price = olc_db_prepare_input($products_data['products_price_' . $group_data[$col]['STATUS_ID']]);
             if ($personal_price == '' || $personal_price == '0.0000') {
                 $personal_price = '0.00';
             } else {
                 if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
                     $personal_price = $personal_price / (olc_get_tax_rate($products_data['products_tax_class_id']) + 100) * 100;
                 }
                 $personal_price = olc_round($personal_price, PRICE_PRECISION);
             }
             if ($action == 'insert') {
                 olc_db_query("DELETE FROM personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . " WHERE products_id = '" . $products_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t                 AND quantity    = '1'");
                 $insert_array = array();
                 $insert_array = array('personal_offer' => $personal_price, 'quantity' => '1', 'products_id' => $products_id);
                 olc_db_perform("personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'], $insert_array);
             } else {
                 olc_db_query("SQL_UPDATE personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "\n\t\t\t\t\t\t\t\t\t\t\t\t                 SET personal_offer = '" . $personal_price . "'\n\t\t\t\t\t\t\t\t\t\t\t\t               WHERE products_id = '" . $products_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t                 AND quantity    = '1'");
             }
         }
     }
     // end
     // ok, lets check write new staffelpreis into db (if there is one)
     $i = 0;
     $group_query = olc_db_query("SELECT customers_status_id\n\t\t\t\t\t                               FROM " . TABLE_CUSTOMERS_STATUS . "\n\t\t\t\t\t                              WHERE language_id = '" . (int) $_SESSION['languages_id'] . "'\n\t\t\t\t\t                                AND customers_status_id != '0'");
     while ($group_values = olc_db_fetch_array($group_query)) {
         // load data into array
         $i++;
         $group_data[$i] = array('STATUS_ID' => $group_values['customers_status_id']);
     }
     for ($col = 0, $n = sizeof($group_data); $col < $n + 1; $col++) {
         if ($group_data[$col]['STATUS_ID'] != '') {
             $quantity = olc_db_prepare_input($products_data['products_quantity_staffel_' . $group_data[$col]['STATUS_ID']]);
             $staffelpreis = olc_db_prepare_input($products_data['products_price_staffel_' . $group_data[$col]['STATUS_ID']]);
             if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
                 $staffelpreis = $staffelpreis / (olc_get_tax_rate($products_data['products_tax_class_id']) + 100) * 100;
             }
             $staffelpreis = olc_round($staffelpreis, PRICE_PRECISION);
             if ($staffelpreis != '' && $quantity != '') {
                 // ok, lets check entered data to get rid of user faults
                 if ($quantity <= 1) {
                     $quantity = 2;
                 }
                 $check_query = olc_db_query("SELECT quantity\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t                               FROM personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t                              WHERE products_id = '" . $products_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                AND quantity    = '" . $quantity . "'");
                 // dont insert if same qty!
                 if (olc_db_num_rows($check_query) < 1) {
                     olc_db_query("INSERT INTO personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                 SET price_id       = '',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                     products_id    = '" . $products_id . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                     quantity       = '" . $quantity . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                     personal_offer = '" . $staffelpreis . "'");
                 }
             }
         }
     }
     //foreach ($languages AS $lang) {
     $n = sizeof($languages);
     for ($i = 0; $i < $n; $i++) {
         $language_id = $languages[$i]['id'];
         //--- PRODUCT PROMOTION
         if ($_FILES['products_promotion_image' . $i]['name'] != '') {
             if ($image =& olc_try_upload('products_promotion_image' . $i, DIR_FS_CATALOG_IMAGES . 'products_promotion/')) {
                 $paname_arr = explode('.', $image->filename);
                 $pnsuffix = array_pop($paname_arr);
                 $products_promotion_imagename = $products_id . '_' . $i . '.' . $pnsuffix;
                 @unlink(DIR_FS_CATALOG_IMAGES . 'products_promotion/' . $products_promotion_imagename);
                 rename(DIR_FS_CATALOG_IMAGES . 'products_promotion/' . $image->filename, DIR_FS_CATALOG_IMAGES . 'products_promotion/' . $products_promotion_imagename);
             }
         } elseif ($products_data['del_products_promotion_image' . $i] == true) {
             // bild loeschen
             $products_promotion_imagename = '';
         } else {
             $products_promotion_imagename = $products_data['products_promotion_image' . $i];
         }
         //--- PRODUCT PROMOTION eof
         $sql_data_array = array('products_name' => olc_db_prepare_input($products_data['products_name'][$language_id]), 'products_description' => olc_db_prepare_input($products_data['products_description_' . $language_id]), 'products_short_description' => olc_db_prepare_input($products_data['products_short_description_' . $language_id]), 'products_keywords' => olc_db_prepare_input($products_data['products_keywords'][$language_id]), 'products_url' => olc_db_prepare_input($products_data['products_url'][$language_id]), 'products_meta_title' => olc_db_prepare_input($products_data['products_meta_title'][$language_id]), 'products_meta_description' => olc_db_prepare_input($products_data['products_meta_description'][$language_id]), 'products_meta_keywords' => olc_db_prepare_input($products_data['products_meta_keywords'][$language_id]), 'products_promotion_title' => olc_db_prepare_input($products_data['products_promotion_title'][$language_id]), 'products_promotion_image' => $products_promotion_imagename, 'products_promotion_desc' => olc_db_prepare_input($products_data['products_promotion_desc'][$language_id]));
         if ($action == 'insert') {
             $insert_sql_data = array('products_id' => $products_id, 'language_id' => $language_id);
             $sql_data_array = olc_array_merge($sql_data_array, $insert_sql_data);
             olc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
         } elseif ($action == 'update') {
             olc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', 'products_id = \'' . olc_db_input($products_id) . '\' and language_id = \'' . $language_id . '\'');
         }
     }
 }
 function export()
 {
     global $heading, $lang_code, $export_data, $desc_data, $line, $cat_data;
     $this->filename = $this->ExportDir . $this->filename;
     $fp = fopen($this->filename, "w+");
     $heading = EMPTY_STRING;
     for ($i = 0; $i < PROD_FIELDS; $i++) {
         $this->add_header_field($this->prod_fields_array[$i]);
     }
     for ($i = 0; $i < GROUPS; $i++) {
         $this->add_header_field(PRICENOTAX_DOT . ($i + 1));
     }
     if (DO_GROUP_CHECK) {
         for ($i = 0; $i < GROUPS; $i++) {
             $this->add_header_field(GROUPACC . ($i + 1));
         }
     }
     // product additional images
     for ($i = 1; $i < MO_PICS + 1; $i++) {
         $this->add_header_field(IMAGE_DOT . $i);
     }
     // add lang fields
     for ($i = 0; $i < LANGUAGES; $i++) {
         $lang_code = $this->languages[$i][CODE];
         for ($k = 0; $k < PROD_DESC_FIELDS; $k++) {
             $this->add_header_field_desc($this->prod_desc_fields_array[$k]);
         }
     }
     // add categorie info fields
     for ($i = 0; $i < CAT_DEPTH; $i++) {
         $this->add_header_field(CAT . $i);
     }
     $this->add_header_field(CAT_IMAGE);
     for ($i = 0; $i < CAT_FIELDS; $i++) {
         $this->add_header_field($this->cat_fields_array[$i]);
     }
     $heading .= NEW_LINE;
     //print_r($heading);
     fputs($fp, $heading);
     // content
     $export_query = olc_db_query(SELECT_ALL . TABLE_PRODUCTS);
     //.' ORDER BY `products_model` ASC'
     while ($export_data = olc_db_fetch_array($export_query)) {
         $this->counter['prod_exp']++;
         $products_id = $export_data[P_ID];
         $where_products_id = WHERE_P_ID_EQUAL . $products_id;
         if (DO_PRICE_IS_BRUTTO) {
             $this->adjust_price_to_net($export_data[P_PRICENOTAX]);
         }
         //Export tax-rate
         $export_data[P_TAX_VALUE] = olc_round($this->tax_rates[$export_data[P_TAX]], 1);
         //Export tax-rate
         $line = EMPTY_STRING;
         for ($i = 0; $i < PROD_FIELDS; $i++) {
             $this->add_product_field($this->prod_fields_array[$i], $this->prod_fields_is_text[$i]);
         }
         $price_query0 = SELECT_ALL . TABLE_PERSONAL_OFFERS_BY . HASH . $where_products_id . SQL_ORDER_BY . "quantity";
         // group prices  Quantity:Price::Quantity:Price
         for ($i = 0; $i < GROUPS; $i++) {
             $price_query_sql = str_replace(HASH, $i, $price_query0);
             $price_query = olc_db_query($price_query_sql);
             $groupPrice = EMPTY_STRING;
             while ($price_data = olc_db_fetch_array($price_query)) {
                 $price_personal_offer = $price_data['personal_offer'];
                 if ($price_personal_offer > 0) {
                     if (DO_PRICE_IS_BRUTTO) {
                         $this->adjust_price_to_net($price_personal_offer);
                     }
                     $groupPrice .= $price_data['quantity'] . COLON . $price_personal_offer . TWO_COLON;
                 }
             }
             if ($groupPrice) {
                 $groupPrice .= COLON;
                 $groupPrice = str_replace(THREE_COLON, EMPTY_STRING, $groupPrice);
                 if ($groupPrice == COLON) {
                     $groupPrice = EMPTY_STRING;
                 }
             }
             $line .= CSV_TEXTSIGN . $groupPrice . CSV_TERM;
         }
         // group permissions
         if (DO_GROUP_CHECK) {
             if (IS_XTC) {
                 for ($i = 0; $i < GROUPS; $i++) {
                     //$line.=CSV_TEXTSIGN.$export_data[GROUP_PERMISSION.$this->Groups[$i+1][ID]].CSV_TERM;
                     $line .= CSV_TEXTSIGN . $export_data[GROUP_PERMISSION . ($i + 1)] . CSV_TERM;
                 }
             } else {
                 $permissions = $export_data[GROUP_IDS];
                 for ($i = 0; $i < GROUPS; $i++) {
                     if (strpos($permissions, str_replace(HASH, $i, GROUP_ID)) === false) {
                         $s = ZERO_STRING;
                     } else {
                         $s = ONE_STRING;
                     }
                     $line .= CSV_TEXTSIGN . $s . CSV_TERM;
                 }
             }
         }
         if (MO_PICS > 0) {
             $mo_query = SELECT_ALL . TABLE_PRODUCTS_IMAGES . $where_products_id;
             $mo_query = olc_db_query($mo_query);
             $img = array();
             while ($mo_data = olc_db_fetch_array($mo_query)) {
                 $img[$mo_data['image_nr']] = $mo_data['image_name'];
             }
             // product images
             for ($i = 1; $i <= MO_PICS; $i++) {
                 $line .= CSV_TEXTSIGN . $img[$i] . CSV_TERM;
             }
         }
         $desc_sql0 = SELECT_ALL . TABLE_PRODUCTS_DESCRIPTION . $where_products_id . SQL_AND . LANG_ID_EQUAL . HASH;
         for ($i = 0; $i < LANGUAGES; $i++) {
             $lang_id = $this->languages[$i][ID];
             $desc_sql = str_replace(HASH, $lang_id, $desc_sql0);
             $desc_query = olc_db_query($desc_sql);
             $desc_data = olc_db_fetch_array($desc_query);
             $desc_data[P_DESC] = str_replace($this->new_lines_array, BLANK, $desc_data[P_DESC]);
             $desc_data[P_SHORTDESC] = str_replace($this->new_lines_array, BLANK, $desc_data[P_SHORTDESC]);
             $lang_code = $this->languages[$i][CODE];
             for ($k = 0; $k < PROD_DESC_FIELDS; $k++) {
                 $this->add_product_desc_field($this->prod_desc_fields_array[$k]);
             }
         }
         $cat_query = olc_db_query(P2C_QUERY_I . $where_products_id);
         $cat_links = olc_db_num_rows($cat_query);
         $multi_cat = $cat_links > 1;
         if ($cat_links > 0) {
             if ($multi_cat) {
                 //Save products data
                 $line_save = $line;
             }
             while ($cat_data = olc_db_fetch_array($cat_query)) {
                 $line .= $this->buildCAT($cat_data[CAT_ID]);
                 if ($multi_cat) {
                     $line .= CSV_EOL;
                     fputs($fp, $line);
                     //Restore products data
                     $line = $line_save;
                 }
             }
         }
         if (!$multi_cat) {
             $line .= CSV_EOL;
             fputs($fp, $line);
         }
     }
     fclose($fp);
     /*
     if (COMPRESS_EXPORT==TRUE_STRING_S)
     {
     	$backup_file=$this->filename;
     	$this->filename=$backup_file . '.zip';
     	exec(LOCAL_EXE_ZIP . ' -j '.$this->filename.BLANK.$backup_file);
     	@unlink($backup_file);
     }
     */
     $this->result = array($this->counter, EMPTY_STRING, $this->calcElapsedTime($this->time_start));
 }
 }
 $orders_id = substr($orders_id, 0, -1) . RPAREN;
 // Set the Sales to Temp State (it may happen that an order happend while billing)
 $sql = SQL_UPDATE . TABLE_AFFILIATE_SALES . "\n        set affiliate_billing_status=99\n          where affiliate_id='" . $affiliate_payment['affiliate_id'] . "'\n          and affiliate_orders_id in " . $orders_id . "\n        ";
 olc_db_query($sql);
 // Get Sum of payment (Could have changed since last selects);
 $sql = "\n        SELECT sum(affiliate_payment) as affiliate_payment\n          FROM " . TABLE_AFFILIATE_SALES . "\n          WHERE affiliate_id='" . $affiliate_payment['affiliate_id'] . "' and  affiliate_billing_status=99\n        ";
 $affiliate_billing_query = olc_db_query($sql);
 $affiliate_billing = olc_db_fetch_array($affiliate_billing_query);
 // Get affiliate Informations
 $sql = "\n        SELECT a.*, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id\n          from " . TABLE_AFFILIATE . " a\n          left join " . TABLE_ZONES . " z on (a.affiliate_zone_id  = z.zone_id)\n          left join " . TABLE_COUNTRIES . " c on (a.affiliate_country_id = c.countries_id)\n          WHERE affiliate_id = '" . $affiliate_payment['affiliate_id'] . "'\n        ";
 $affiliate_query = olc_db_query($sql);
 $affiliate = olc_db_fetch_array($affiliate_query);
 // Get need tax informations for the affiliate
 $affiliate_tax_rate = olc_get_affiliate_tax_rate(AFFILIATE_TAX_ID, $affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id']);
 $affiliate_tax = olc_round($affiliate_billing['affiliate_payment'] * $affiliate_tax_rate / 100, 2);
 // Netto-Provision
 $affiliate_payment_total = $affiliate_billing['affiliate_payment'] + $affiliate_tax;
 // Bill the order
 $affiliate['affiliate_state'] = olc_get_zone_code($affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id'], $affiliate['affiliate_state']);
 $sql_data_array = array('affiliate_id' => $affiliate_payment['affiliate_id'], 'affiliate_payment' => $affiliate_billing['affiliate_payment'], 'affiliate_payment_tax' => $affiliate_tax, 'affiliate_payment_total' => $affiliate_payment_total, 'affiliate_payment_date' => 'now()', 'affiliate_payment_status' => '0', 'affiliate_firstname' => $affiliate['affiliate_firstname'], 'affiliate_lastname' => $affiliate['affiliate_lastname'], 'affiliate_street_address' => $affiliate['affiliate_street_address'], 'affiliate_suburb' => $affiliate['affiliate_suburb'], 'affiliate_city' => $affiliate['affiliate_city'], 'affiliate_country' => $affiliate['countries_name'], 'affiliate_postcode' => $affiliate['affiliate_postcode'], 'affiliate_company' => $affiliate['affiliate_company'], 'affiliate_state' => $affiliate['affiliate_state'], 'affiliate_address_format_id' => $affiliate['address_format_id']);
 olc_db_perform(TABLE_AFFILIATE_PAYMENT, $sql_data_array);
 $insert_id = olc_db_insert_id();
 // Set the Sales to Final State
 olc_db_query(SQL_UPDATE . TABLE_AFFILIATE_SALES . " set affiliate_payment_id = '" . $insert_id . "', affiliate_billing_status = 1, affiliate_payment_date = now() where affiliate_id = '" . $affiliate_payment['affiliate_id'] . "' and affiliate_billing_status = 99");
 // Notify Affiliate
 if (AFFILIATE_NOTIFY_AFTER_BILLING == TRUE_STRING_S) {
     $check_status_query = olc_db_query("select af.affiliate_email_address, ap.affiliate_lastname, ap.affiliate_firstname, ap.affiliate_payment_status, ap.affiliate_payment_date, ap.affiliate_payment_date from " . TABLE_AFFILIATE_PAYMENT . " ap, " . TABLE_AFFILIATE . " af where affiliate_payment_id  = '" . $insert_id . "' and af.affiliate_id = ap.affiliate_id ");
     $check_status = olc_db_fetch_array($check_status_query);
     $email = STORE_NAME . NEW_LINE . EMAIL_SEPARATOR . NEW_LINE . EMAIL_TEXT_AFFILIATE_PAYMENT_NUMBER . BLANK . $insert_id . NEW_LINE . EMAIL_TEXT_INVOICE_URL . BLANK . olc_catalog_href_link(FILENAME_CATALOG_AFFILIATE_PAYMENT_INFO, 'payment_id=' . $insert_id, SSL) . NEW_LINE . EMAIL_TEXT_PAYMENT_BILLED . BLANK . olc_date_long($check_status['affiliate_payment_date']) . "\n\n" . EMAIL_TEXT_NEW_PAYMENT;
     olc_mail($check_status['affiliate_firstname'] . BLANK . $check_status['affiliate_lastname'], $check_status['affiliate_email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, AFFILIATE_EMAIL_ADDRESS);
 echo "</td>";
 echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_sortorder\" value=\"" . $sortorder . "\" size=\"4\"></td>";
 echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_model\" value=\"" . $attribute_value_model . "\" size=\"15\"></td>";
 echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_stock\" value=\"" . $attribute_value_stock . "\" size=\"4\"></td>";
 echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_weight\" value=\"" . $attribute_value_weight . "\" size=\"10\"></td>";
 echo "<td class=\"main\" align=\"left\"><select name=\"" . $current_value_id . "_weight_prefix\"><option value=\"+\"" . $posCheck_weight . ">+<option value=\"-\"" . $negCheck_weight . ">-</SELECT></td>";
 // brutto Admin
 if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
     $attribute_value_price_calculate = olc_format_price(olc_round($attribute_value_price * ((100 + olc_get_tax_rate(olc_get_tax_class_id($_POST['current_product_id']))) / 100), PRICE_PRECISION), false, false);
 } else {
     $attribute_value_price_calculate = olc_round($attribute_value_price, PRICE_PRECISION);
 }
 echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_price\" value=\"" . $attribute_value_price_calculate . "\" size=\"10\">";
 // brutto Admin
 if (PRICE_IS_BRUTTO == TRUE_STRING_S) {
     echo TEXT_NETTO . HTML_B_START . olc_format_price(olc_round($attribute_value_price, PRICE_PRECISION), true, false) . '</b>  ';
 }
 echo "</td>";
 if ($optionTypeInstalled == '1') {
     extraValues($current_value_id, $_POST['current_product_id']);
     echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_prefix\" value=\"" . $attribute_prefix . "\" size=\"4\"></td>";
     echo "<td class=\"main\" align=\"left\"><select name=\"" . $current_value_id . "_type\">";
     displayOptionTypes($attribute_type);
     echo "</SELECT></td>";
     echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_qty\" value=\"" . $attribute_qty . "\" size=\"4\"></td>";
     echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_order\" value=\"" . $attribute_order . "\" size=\"4\"></td>";
     echo "<td class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_linked\" value=\"" . $attribute_linked . "\" size=\"4\"></td>";
     echo "<td class=\"main\" align=\"left\">" . $current_value_id . "</td>";
 } else {
     echo "<td class=\"main\" align=\"left\"><select name=\"" . $current_value_id . "_prefix\"> <option value=\"+\"" . $posCheck . ">+<option value=\"-\"" . $negCheck . ">-</SELECT></td>";
     if ($optionSortCopyInstalled == '1') {
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $order;
     switch ($method) {
         case 'Standard':
             $ratio1 = olc_round($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = olc_get_tax_rate_from_desc($key);
                 $total_net += $tax_rate * $order->info['tax_groups'][$key];
             }
             if ($od_amount > $total_net) {
                 $od_amount = $total_net;
             }
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = olc_get_tax_rate_from_desc($key);
                 $net = $tax_rate * $order->info['tax_groups'][$key];
                 if ($net > 0) {
                     $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                     $tod_amount += $god_amount;
                     $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                 }
             }
             $order->info['tax'] -= $tod_amount;
             $order->info['total'] -= $tod_amount;
             break;
         case 'Credit Note':
             $tax_rate = olc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_desc = olc_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             //          $order->info['total'] -= $tod_amount;   //// ????? Strider
             break;
         default:
     }
     return $tod_amount;
 }
function olc_calculate_tax($price, $tax)
{
    global $currencies;
    return olc_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}