break;
    case 'delete':
        $heading[] = array('text' => HTML_B_START . TEXT_INFO_HEADING_DELETE_CUSTOMERS_STATUS . HTML_B_END);
        $contents = array('form' => olc_draw_form('status', FILENAME_CUSTOMERS_STATUS, 'page=' . $_GET['page'] . '&cID=' . $cInfo->customers_status_id . '&action=deleteconfirm'));
        $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
        $contents[] = array('text' => '<br/><b>' . $cInfo->customers_status_name . HTML_B_END);
        if ($remove_status) {
            $contents[] = array('align' => 'center', 'text' => HTML_BR . olc_image_submit('button_delete.gif', IMAGE_DELETE) . BLANK . HTML_A_START . olc_href_link(FILENAME_CUSTOMERS_STATUS, 'page=' . $_GET['page'] . '&cID=' . $cInfo->customers_status_id) . '">' . olc_image_button('button_cancel.gif', IMAGE_CANCEL) . HTML_A_END);
        }
        break;
    default:
        if (is_object($cInfo)) {
            $heading[] = array('text' => HTML_B_START . $cInfo->customers_status_name . HTML_B_END);
            $contents[] = array('align' => 'center', 'text' => HTML_A_START . olc_href_link(FILENAME_CUSTOMERS_STATUS, 'page=' . $_GET['page'] . '&cID=' . $cInfo->customers_status_id . '&action=edit') . '">' . olc_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . olc_href_link(FILENAME_CUSTOMERS_STATUS, 'page=' . $_GET['page'] . '&cID=' . $cInfo->customers_status_id . '&action=delete') . '">' . olc_image_button('button_delete.gif', IMAGE_DELETE) . HTML_A_END);
            $customers_status_inputs_string = '';
            $languages = olc_get_languages();
            for ($i = 0; $i < sizeof($languages); $i++) {
                $customers_status_inputs_string .= HTML_BR . olc_image(DIR_WS_CATALOG . 'lang/' . $languages[$i]['directory'] . '/admin/images/' . $languages[$i]['image'], $languages[$i]['name']) . HTML_NBSP . olc_get_customers_status_name($cInfo->customers_status_id, $languages[$i]['id']);
            }
            $contents[] = array('text' => $customers_status_inputs_string);
            $contents[] = array('text' => HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_DISCOUNT_PRICE_INTRO . HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_DISCOUNT_PRICE . BLANK . $cInfo->customers_status_discount . '%');
            $contents[] = array('text' => HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_DISCOUNT_OT_XMEMBER_INTRO . HTML_BR . ENTRY_OT_XMEMBER . BLANK . $customers_status_ot_discount_flag_array[$cInfo->customers_status_ot_discount_flag]['text'] . LPAREN . $cInfo->customers_status_ot_discount_flag . RPAREN . ' - ' . $cInfo->customers_status_ot_discount . '%');
            $contents[] = array('text' => HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_GRADUATED_PRICES_INTRO . HTML_BR . ENTRY_GRADUATED_PRICES . BLANK . $customers_status_graduated_prices_array[$cInfo->customers_status_graduated_prices]['text'] . LPAREN . $cInfo->customers_status_graduated_prices . RPAREN);
            $contents[] = array('text' => HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_DISCOUNT_ATTRIBUTES_INTRO . HTML_BR . ENTRY_CUSTOMERS_STATUS_DISCOUNT_ATTRIBUTES . BLANK . $customers_status_discount_attributes_array[$cInfo->customers_status_discount_attributes]['text'] . LPAREN . $cInfo->customers_status_discount_attributes . RPAREN);
            $contents[] = array('text' => HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_PAYMENT_UNALLOWED_INTRO . HTML_BR . ENTRY_CUSTOMERS_STATUS_PAYMENT_UNALLOWED . ':<b> ' . $cInfo->customers_status_payment_unallowed . HTML_B_END);
            $contents[] = array('text' => HTML_BR . TEXT_INFO_CUSTOMERS_STATUS_SHIPPING_UNALLOWED_INTRO . HTML_BR . ENTRY_CUSTOMERS_STATUS_SHIPPING_UNALLOWED . ':<b> ' . $cInfo->customers_status_shipping_unallowed . HTML_B_END);
        }
        break;
}
if (olc_not_null($heading) && olc_not_null($contents)) {
    echo '<td width="25%" valign="top">' . NEW_LINE;
 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 walk($item1)
{
    global $filelayout, $filelayout_count, $modelsize;
    global $active, $inactive, $langcode, $default_these, $deleteit, $zero_qty_inactive;
    global $epdlanguage_id, $price_with_tax, $replace_quotes;
    global $default_images, $default_image_manufacturer, $default_image_product, $default_image_category;
    global $separator, $max_categories;
    // first we clean up the row of data
    // chop blanks from each end
    $item1 = ltrim(rtrim($item1));
    // blow it into an array, splitting on the tabs
    $items = explode($separator, $item1);
    // make sure all non-set things are set to '';
    // and strip the quotes from the start and end of the stings.
    // escape any special chars for the database.
    foreach ($filelayout as $key => $value) {
        $i = $filelayout[$key];
        if (isset($items[$i]) == false) {
            $items[$i] = '';
        } else {
            // Check to see if either of the magic_quotes are turned on or off;
            // And apply filtering accordingly.
            if (function_exists('ini_get')) {
                //echo "Getting ready to check magic quotes<br/>";
                if (ini_get('magic_quotes_runtime') == 1) {
                    // The magic_quotes_runtime are on, so lets account for them
                    // check if the last character is a quote;
                    // if it is, chop off the quotes.
                    if (substr($items[$i], -1) == '"') {
                        $items[$i] = substr($items[$i], 2, strlen($items[$i]) - 4);
                    }
                    // now any remaining doubled double quotes should be converted to one doublequote
                    $items[$i] = str_replace('\\"\\"', "&#34", $items[$i]);
                    if ($replace_quotes) {
                        $items[$i] = str_replace('\\"', "&#34", $items[$i]);
                        $items[$i] = str_replace("\\'", "&#39", $items[$i]);
                    }
                } else {
                    // no magic_quotes are on
                    // check if the last character is a quote;
                    // if it is, chop off the 1st and last character of the string.
                    if (substr($items[$i], -1) == '"') {
                        $items[$i] = substr($items[$i], 1, strlen($items[$i]) - 2);
                    }
                    // now any remaining doubled double quotes should be converted to one doublequote
                    $items[$i] = str_replace('""', "&#34", $items[$i]);
                    if ($replace_quotes) {
                        $items[$i] = str_replace('"', "&#34", $items[$i]);
                        $items[$i] = str_replace(APOS, "&#39", $items[$i]);
                    }
                }
            }
        }
    }
    /*
    	if ( $items['v_status'] == $deleteit ){
    		// they want to delete this product.
    		echo "Deleting product " . $items['v_products_model'] . " from the database<br/>";
    		// Get the id
    
    		// kill in the products_to_categories
    
    		// Kill in the products table
    
    		return; // we're done deleteing!
    	}
    */
    // now do a query to get the record's current contents
    $sql = "SELECT\n\t\tp.products_id as v_products_id,\n\t\tp.products_model as v_products_model,\n\t\tp.products_image as v_products_image,\n\t\tp.products_price as v_products_price,\n\t\tp.products_weight as v_products_weight,\n\t\tp.products_date_added as v_date_added,\n        p.products_date_available as v_date_avail,\n\t\tp.products_tax_class_id as v_tax_class_id,\n\t\tp.products_quantity as v_products_quantity,\n\t\tp.manufacturers_id as v_manufacturers_id,\n\t\tsubc.categories_id as v_categories_id\n\t\tFROM\n\t\t" . TABLE_PRODUCTS . " as p,\n\t\t" . TABLE_CATEGORIES . " as subc,\n\t\t" . TABLE_PRODUCTS_TO_CATEGORIES . " as ptoc\n\t\tWHERE\n\t\tp.products_id = ptoc.products_id AND\n\t\tp.products_model = '" . $items[$filelayout['v_products_model']] . "' AND\n\t\tptoc.categories_id = subc.categories_id\n\t\t";
    $result = olc_db_query($sql);
    $row = olc_db_fetch_array($result);
    while ($row) {
        // OK, since we got a row, the item already exists.
        // Let's get all the data we need and fill in all the fields that need to be defaulted to the current values
        // for each language, get the description and set the vals
        foreach ($langcode as $key => $lang) {
            //echo "Inside defaulting loop";
            //echo "key is $key<br/>";
            //echo "langid is " . $lang['id'] . HTML_BR;
            //			$sql2 = "SELECT products_name, products_description
            //				FROM ".TABLE_PRODUCTS_DESCRIPTION."
            //				WHERE
            //					products_id = " . $row['v_products_id'] . " AND
            //					language_id = '" . $lang['id'] . "'
            //				";
            $sql2 = "SELECT *\n\t\t\t\tFROM " . TABLE_PRODUCTS_DESCRIPTION . "\n\t\t\t\tWHERE\n\t\t\t\t\tproducts_id = " . $row['v_products_id'] . " AND\n\t\t\t\t\tlanguage_id = '" . $lang['id'] . "'\n\t\t\t\t";
            $result2 = olc_db_query($sql2);
            $row2 = olc_db_fetch_array($result2);
            // Need to report from ......_name_1 not ..._name_0
            $row['v_products_name_' . $lang['id']] = $row2['products_name'];
            $row['v_products_description_' . $lang['id']] = $row2['products_description'];
            $row['v_products_short_description_' . $lang['id']] = $row2['products_short_description'];
            $row['v_products_url_' . $lang['id']] = $row2['products_url'];
            // support for Linda's Header Controller 2.0 here
            if (isset($filelayout['v_products_meta_title_' . $lang['id']])) {
                $row['v_products_meta_title_' . $lang['id']] = $row2['products_meta_title'];
                $row['v_products_meta_description_' . $lang['id']] = $row2['products_meta_description'];
                $row['v_products_meta_keywords_' . $lang['id']] = $row2['products_meta_keywords'];
            }
            // end support for Header Controller 2.0
        }
        // start with v_categories_id
        // Get the category description
        // set the appropriate variable name
        // if parent_id is not null, then follow it up.
        $thecategory_id = $row['v_categories_id'];
        for ($categorylevel = 1; $categorylevel < $max_categories + 1; $categorylevel++) {
            if ($thecategory_id) {
                $sql2 = "SELECT categories_name\n\t\t\t\t\tFROM " . TABLE_CATEGORIES_DESCRIPTION . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tcategories_id = " . $thecategory_id . " AND\n\t\t\t\t\t\tlanguage_id = " . $epdlanguage_id;
                $result2 = olc_db_query($sql2);
                $row2 = olc_db_fetch_array($result2);
                // only set it if we found something
                $temprow['v_categories_name_' . $categorylevel] = $row2['categories_name'];
                // now get the parent id if there was one
                $sql3 = "SELECT parent_id\n\t\t\t\t\tFROM " . TABLE_CATEGORIES . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tcategories_id = " . $thecategory_id;
                $result3 = olc_db_query($sql3);
                $row3 = olc_db_fetch_array($result3);
                $theparent_id = $row3['parent_id'];
                if ($theparent_id != '') {
                    // there was a parent id, lets set thecategoryid to get the next level
                    $thecategory_id = $theparent_id;
                } else {
                    // we have found the top level category for this item,
                    $thecategory_id = false;
                }
            } else {
                $temprow['v_categories_name_' . $categorylevel] = '';
            }
        }
        // temprow has the old style low to high level categories.
        $newlevel = 1;
        // let's turn them into high to low level categories
        for ($categorylevel = $max_categories + 1; $categorylevel > 0; $categorylevel--) {
            if ($temprow['v_categories_name_' . $categorylevel] != '') {
                $row['v_categories_name_' . $newlevel++] = $temprow['v_categories_name_' . $categorylevel];
            }
        }
        if ($row['v_manufacturers_id'] != '') {
            $sql2 = "SELECT manufacturers_name\n\t\t\t\tFROM " . TABLE_MANUFACTURERS . "\n\t\t\t\tWHERE\n\t\t\t\tmanufacturers_id = " . $row['v_manufacturers_id'];
            $result2 = olc_db_query($sql2);
            $row2 = olc_db_fetch_array($result2);
            $row['v_manufacturers_name'] = $row2['manufacturers_name'];
        }
        //elari -
        //We check the value of tax class and title instead of the id
        //Then we add the tax to price if $price_with_tax is set to true
        $row_tax_multiplier = olc_get_tax_class_rate($row['v_tax_class_id']);
        $row['v_tax_class_title'] = olc_get_tax_class_title($row['v_tax_class_id']);
        if ($price_with_tax) {
            $row['v_products_price'] = $row['v_products_price'] + olc_precision($row['v_products_price'] * $row_tax_multiplier / 100, 2);
        }
        // now create the internal variables that will be used
        // the $$thisvar is on purpose: it creates a variable named what ever was in $thisvar and sets the value
        foreach ($default_these as $thisvar) {
            ${$thisvar} = $row[$thisvar];
        }
        $row = olc_db_fetch_array($result);
    }
    // this is an important loop.  What it does is go thru all the fields in the incoming file and set the internal vars.
    // Internal vars not set here are either set in the loop above for existing records, or not set at all (null values)
    // the array values are handled separatly, although they will set variables in this loop, we won't use them.
    foreach ($filelayout as $key => $value) {
        ${$key} = $items[$value];
    }
    // so how to handle these?  we shouldn't built the array unless it's been giving to us.
    // The assumption is that if you give us names and descriptions, then you give us name and description for all applicable languages
    foreach ($langcode as $lang) {
        //echo "Langid is " . $lang['id'] . HTML_BR;
        $l_id = $lang['id'];
        if (isset($filelayout['v_products_name_' . $l_id])) {
            //we set dynamically the language values
            $v_products_name[$l_id] = $items[$filelayout['v_products_name_' . $l_id]];
            $v_products_description[$l_id] = $items[$filelayout['v_products_description_' . $l_id]];
            $v_products_short_description[$l_id] = $items[$filelayout['v_products_short_description_' . $l_id]];
            $v_products_url[$l_id] = $items[$filelayout['v_products_url_' . $l_id]];
            // support for Linda's Header Controller 2.0 here
            if (isset($filelayout['v_products_meta_title_' . $l_id])) {
                $v_products_meta_title[$l_id] = $items[$filelayout['v_products_meta_title_' . $l_id]];
                $v_products_meta_description[$l_id] = $items[$filelayout['v_products_meta_description_' . $l_id]];
                $v_products_meta_keywords[$l_id] = $items[$filelayout['v_products_meta_keywords_' . $l_id]];
            }
            // end support for Header Controller 2.0
        }
    }
    //elari... we get the tax_clas_id from the tax_title
    //on screen will still be displayed the tax_class_title instead of the id....
    if (isset($v_tax_class_title)) {
        $v_tax_class_id = olc_get_tax_title_class_id($v_tax_class_title);
    }
    //we check the tax rate of this tax_class_id
    $row_tax_multiplier = olc_get_tax_class_rate($v_tax_class_id);
    //And we recalculate price without the included tax...
    //Since it seems display is made before, the displayed price will still include tax
    //This is same problem for the tax_clas_id that display tax_class_title
    if ($price_with_tax) {
        $v_products_price = olc_precision($v_products_price / (1 + $row_tax_multiplier * $price_with_tax / 100), 2);
    }
    // if they give us one category, they give us all 6 categories
    unset($v_categories_name);
    // default to not set.
    if (isset($filelayout['v_categories_name_1'])) {
        $newlevel = 1;
        for ($categorylevel = 6; $categorylevel > 0; $categorylevel--) {
            if ($items[$filelayout['v_categories_name_' . $categorylevel]] != '') {
                $v_categories_name[$newlevel++] = $items[$filelayout['v_categories_name_' . $categorylevel]];
            }
        }
        while ($newlevel < $max_categories + 1) {
            $v_categories_name[$newlevel++] = '';
            // default the remaining items to nothing
        }
    }
    if (ltrim(rtrim($v_products_quantity)) == '') {
        $v_products_quantity = 1;
    }
    if ($v_date_avail == '') {
        $v_date_avail = "CURRENT_TIMESTAMP";
    } else {
        // we put the quotes aolc_precision it here because we can't put them into the query, because sometimes
        //   we will use the "current_timestamp", which can't have quotes aolc_precision it.
        $v_date_avail = '"' . $v_date_avail . '"';
    }
    if ($v_date_added == '') {
        $v_date_added = "CURRENT_TIMESTAMP";
    } else {
        // we put the quotes aolc_precision it here because we can't put them into the query, because sometimes
        //   we will use the "current_timestamp", which can't have quotes aolc_precision it.
        $v_date_added = '"' . $v_date_added . '"';
    }
    // default the stock if they spec'd it or if it's blank
    $v_db_status = '1';
    // default to active
    if ($v_status == $inactive) {
        // they told us to deactivate this item
        $v_db_status = '0';
    }
    if ($zero_qty_inactive && $v_products_quantity == 0) {
        // if they said that zero qty products should be deactivated, let's deactivate if the qty is zero
        $v_db_status = '0';
    }
    if ($v_manufacturer_id == '') {
        $v_manufacturer_id = "NULL";
    }
    if (trim($v_products_image) == '') {
        $v_products_image = $default_image_product;
    }
    if (strlen($v_products_model) > $modelsize) {
        echo "<font color='red'>" . strlen($v_products_model) . $v_products_model . "... ERROR! - Too many characters in the model number.<br/>\n\t\t\t12 is the maximum on a standard OSC install.<br/>\n\t\t\tYour maximum product_model length is set to {$modelsize}<br/>\n\t\t\tYou can either shorten your model numbers or increase the size of the field in the database.</font>";
        die;
    }
    // OK, we need to convert the manufacturer's name into id's for the database
    if (isset($v_manufacturers_name) && $v_manufacturers_name != '') {
        $sql = "SELECT man.manufacturers_id\n\t\t\tFROM " . TABLE_MANUFACTURERS . " as man\n\t\t\tWHERE\n\t\t\t\tman.manufacturers_name = '" . $v_manufacturers_name . APOS;
        $result = olc_db_query($sql);
        $row = olc_db_fetch_array($result);
        if ($row != '') {
            foreach ($row as $item) {
                $v_manufacturer_id = $item;
            }
        } else {
            // to add, we need to put stuff in categories and categories_description
            $sql = "SELECT MAX( manufacturers_id) max FROM " . TABLE_MANUFACTURERS;
            $result = olc_db_query($sql);
            $row = olc_db_fetch_array($result);
            $max_mfg_id = $row['max'] + 1;
            // default the id if there are no manufacturers yet
            if (!is_numeric($max_mfg_id)) {
                $max_mfg_id = 1;
            }
            // Uncomment this query if you have an older 2.2 codebase
            /*
            $sql = INSERT_INTO.TABLE_MANUFACTURERS."(
            	manufacturers_id,
            	manufacturers_name,
            	manufacturers_image
            	) VALUES (
            	$max_mfg_id,
            	'$v_manufacturers_name',
            	'$default_image_manufacturer'
            	)";
            */
            // Comment this query out if you have an older 2.2 codebase
            $sql = INSERT_INTO . TABLE_MANUFACTURERS . "(\n\t\t\t\tmanufacturers_id,\n\t\t\t\tmanufacturers_name,\n\t\t\t\tmanufacturers_image,\n\t\t\t\tdate_added,\n\t\t\t\tlast_modified\n\t\t\t\t) VALUES (\n\t\t\t\t{$max_mfg_id},\n\t\t\t\t'{$v_manufacturers_name}',\n\t\t\t\t'{$default_image_manufacturer}',\n\t\t\t\tCURRENT_TIMESTAMP,\n\t\t\t\tCURRENT_TIMESTAMP\n\t\t\t\t)";
            $result = olc_db_query($sql);
            $v_manufacturer_id = $max_mfg_id;
        }
    }
    // if the categories names are set then try to update them
    if (isset($v_categories_name_1)) {
        // start from the highest possible category and work our way down from the parent
        $v_categories_id = 0;
        $theparent_id = 0;
        for ($categorylevel = $max_categories + 1; $categorylevel > 0; $categorylevel--) {
            $thiscategoryname = $v_categories_name[$categorylevel];
            if ($thiscategoryname != '') {
                // we found a category name in this field
                // now the subcategory
                $sql = "SELECT cat.categories_id\n\t\t\t\t\tFROM " . TABLE_CATEGORIES . " as cat,\n\t\t\t\t\t     " . TABLE_CATEGORIES_DESCRIPTION . " as des\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tcat.categories_id = des.categories_id AND\n\t\t\t\t\t\tdes.language_id = {$epdlanguage_id} AND\n\t\t\t\t\t\tcat.parent_id = " . $theparent_id . " AND\n\t\t\t\t\t\tdes.categories_name = '" . $thiscategoryname . APOS;
                $result = olc_db_query($sql);
                $row = olc_db_fetch_array($result);
                if ($row != '') {
                    foreach ($row as $item) {
                        $thiscategoryid = $item;
                    }
                } else {
                    // to add, we need to put stuff in categories and categories_description
                    $sql = "SELECT MAX( categories_id) max FROM " . TABLE_CATEGORIES;
                    $result = olc_db_query($sql);
                    $row = olc_db_fetch_array($result);
                    $max_category_id = $row['max'] + 1;
                    if (!is_numeric($max_category_id)) {
                        $max_category_id = 1;
                    }
                    $sql = INSERT_INTO . TABLE_CATEGORIES . "(\n\t\t\t\t\t\tcategories_id,\n\t\t\t\t\t\tcategories_image,\n\t\t\t\t\t\tparent_id,\n\t\t\t\t\t\tsort_order,\n\t\t\t\t\t\tdate_added,\n\t\t\t\t\t\tlast_modified\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t{$max_category_id},\n\t\t\t\t\t\t'{$default_image_category}',\n\t\t\t\t\t\t{$theparent_id},\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tCURRENT_TIMESTAMP\n\t\t\t\t\t\t,CURRENT_TIMESTAMP\n\t\t\t\t\t\t)";
                    $result = olc_db_query($sql);
                    $sql = INSERT_INTO . TABLE_CATEGORIES_DESCRIPTION . "(\n\t\t\t\t\t\t\tcategories_id,\n\t\t\t\t\t\t\tlanguage_id,\n\t\t\t\t\t\t\tcategories_name\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t{$max_category_id},\n\t\t\t\t\t\t\t'{$epdlanguage_id}',\n\t\t\t\t\t\t\t'{$thiscategoryname}'\n\t\t\t\t\t\t)";
                    $result = olc_db_query($sql);
                    $thiscategoryid = $max_category_id;
                }
                // the current catid is the next level's parent
                $theparent_id = $thiscategoryid;
                $v_categories_id = $thiscategoryid;
                // keep setting this, we need the lowest level category id later
            }
        }
    }
    if ($v_products_model != "") {
        //   products_model exists!
        array_walk($items, 'print_el');
        // First we check to see if this is a product in the current db.
        $result = olc_db_query("SELECT products_id FROM " . TABLE_PRODUCTS . " WHERE (products_model = '" . $v_products_model . "')");
        if (olc_db_num_rows($result) == 0) {
            //   insert into products
            $sql = "SHOW TABLE STATUS LIKE '" . TABLE_PRODUCTS . APOS;
            $result = olc_db_query($sql);
            $row = olc_db_fetch_array($result);
            $max_product_id = $row['Auto_increment'];
            if (!is_numeric($max_product_id)) {
                $max_product_id = 1;
            }
            $v_products_id = $max_product_id;
            echo "<font color='green'> !New Product!</font><br/>";
            $query = INSERT_INTO . TABLE_PRODUCTS . " (\n\t\t\t\t\tproducts_image,\n\t\t\t\t\tproducts_model,\n\t\t\t\t\tproducts_price,\n\t\t\t\t\tproducts_status,\n\t\t\t\t\tproducts_last_modified,\n\t\t\t\t\tproducts_date_added,\n\t\t\t\t\tproducts_date_available,\n\t\t\t\t\tproducts_tax_class_id,\n\t\t\t\t\tproducts_weight,\n\t\t\t\t\tproducts_quantity,\n\t\t\t\t\tmanufacturers_id)\n\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t'{$v_products_image}',";
            // unmcomment these lines if you are running the image mods
            /*
            	$query .=		. $v_products_mimage . '", "'
            				. $v_products_bimage . '", "'
            				. $v_products_subimage1 . '", "'
            				. $v_products_bsubimage1 . '", "'
            				. $v_products_subimage2 . '", "'
            				. $v_products_bsubimage2 . '", "'
            				. $v_products_subimage3 . '", "'
            				. $v_products_bsubimage3 . '", "'
            */
            $query .= "\t\t\t\t'{$v_products_model}',\n\t\t\t\t\t\t\t\t'{$v_products_price}',\n\t\t\t\t\t\t\t\t'{$v_db_status}',\n\t\t\t\t\t\t\t\tCURRENT_TIMESTAMP,\n\t\t\t\t\t\t\t\t{$v_date_added},\n\t\t\t\t\t\t\t\t{$v_date_avail},\n\t\t\t\t\t\t\t\t'{$v_tax_class_id}',\n\t\t\t\t\t\t\t\t'{$v_products_weight}',\n\t\t\t\t\t\t\t\t'{$v_products_quantity}',\n\t\t\t\t\t\t\t\t'{$v_manufacturer_id}')\n\t\t\t\t\t\t\t";
            $result = olc_db_query($query);
        } else {
            // existing product, get the id from the query
            // and update the product data
            $row = olc_db_fetch_array($result);
            $v_products_id = $row['products_id'];
            echo "<font color='black'> Updated</font><br/>";
            $row = olc_db_fetch_array($result);
            $query = 'SQL_UPDATE ' . TABLE_PRODUCTS . '
					SET
					products_price="' . $v_products_price . '" ,products_image="' . $v_products_image;
            // uncomment these lines if you are running the image mods
            /*
            				$query .=
            					'" ,products_mimage="'.$v_products_mimage.
            					'" ,products_bimage="'.$v_products_bimage.
            					'" ,products_subimage1="'.$v_products_subimage1.
            					'" ,products_bsubimage1="'.$v_products_bsubimage1.
            					'" ,products_subimage2="'.$v_products_subimage2.
            					'" ,products_bsubimage2="'.$v_products_bsubimage2.
            					'" ,products_subimage3="'.$v_products_subimage3.
            					'" ,products_bsubimage3="'.$v_products_bsubimage3;
            */
            $query .= '", products_weight="' . $v_products_weight . '", products_tax_class_id="' . $v_tax_class_id . '", products_date_available= ' . $v_date_avail . ', products_date_added= ' . $v_date_added . ', products_last_modified=CURRENT_TIMESTAMP
					, products_quantity="' . $v_products_quantity . '" ,manufacturers_id=' . $v_manufacturer_id . ' , products_status=' . $v_db_status . '
					WHERE
						(products_id = "' . $v_products_id . '")';
            $result = olc_db_query($query);
        }
        // the following is common in both the updating an existing product and creating a new product
        if (isset($v_products_name)) {
            foreach ($v_products_name as $key => $name) {
                if ($name != '') {
                    $sql = "SELECT * FROM " . TABLE_PRODUCTS_DESCRIPTION . " WHERE\n\t\t\t\t\t\t\tproducts_id = {$v_products_id} AND\n\t\t\t\t\t\t\tlanguage_id = " . $key;
                    $result = olc_db_query($sql);
                    if (olc_db_num_rows($result) == 0) {
                        // nope, this is a new product description
                        $result = olc_db_query($sql);
                        $sql = INSERT_INTO . TABLE_PRODUCTS_DESCRIPTION . "\n\t\t\t\t\t\t\t\t(products_id,\n\t\t\t\t\t\t\t\tlanguage_id,\n\t\t\t\t\t\t\t\tproducts_name,\n\t\t\t\t\t\t\t\tproducts_description,\n                                products_short_description,\n\t\t\t\t\t\t\t\tproducts_url)\n\t\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t\t'" . $v_products_id . "',\n\t\t\t\t\t\t\t\t\t" . $key . ",\n\t\t\t\t\t\t\t\t\t'" . $name . "',\n\t\t\t\t\t\t\t\t\t'" . $v_products_description[$key] . "',\n                                    '" . $v_products_short_description[$key] . "',\n\t\t\t\t\t\t\t\t\t'" . $v_products_url[$key] . "'\n\t\t\t\t\t\t\t\t\t)";
                        // support for Linda's Header Controller 2.0
                        if (isset($v_products_meta_title)) {
                            // override the sql if we're using Linda's contrib
                            $sql = INSERT_INTO . TABLE_PRODUCTS_DESCRIPTION . "\n\t\t\t\t\t\t\t\t\t(products_id,\n\t\t\t\t\t\t\t\t\tlanguage_id,\n\t\t\t\t\t\t\t\t\tproducts_name,\n                                    products_description,\n\t\t\t\t\t\t\t\t\tproducts_short_description,\n\t\t\t\t\t\t\t\t\tproducts_url,\n\t\t\t\t\t\t\t\t\tproducts_meta_title,\n\t\t\t\t\t\t\t\t\tproducts_meta_description,\n\t\t\t\t\t\t\t\t\tproducts_meta_keywords)\n\t\t\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_id . "',\n\t\t\t\t\t\t\t\t\t\t" . $key . ",\n\t\t\t\t\t\t\t\t\t\t'" . $name . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_description[$key] . "',\n                                        '" . $v_products_short_description[$key] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_url[$key] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_meta_title[$key] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_meta_description[$key] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_meta_keywords[$key] . "')";
                        }
                        // end support for Linda's Header Controller 2.0
                        $result = olc_db_query($sql);
                    } else {
                        // already in the description, let's just update it
                        $sql = SQL_UPDATE . TABLE_PRODUCTS_DESCRIPTION . " SET\n\t\t\t\t\t\t\t\tproducts_name='{$name}',\n\t\t\t\t\t\t\t\tproducts_description='" . $v_products_description[$key] . "',\n                                products_short_description='" . $v_products_short_description[$key] . "',\n                                products_url='" . $v_products_url[$key] . "'\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tproducts_id = '{$v_products_id}' AND\n\t\t\t\t\t\t\t\tlanguage_id = '{$key}'";
                        // support for Lindas Header Controller 2.0
                        if (isset($v_products_meta_title)) {
                            // override the sql if we're using Linda's contrib
                            $sql = SQL_UPDATE . TABLE_PRODUCTS_DESCRIPTION . " SET\n\t\t\t\t\t\t\t\t\tproducts_name = '{$name}',\n\t\t\t\t\t\t\t\t\tproducts_description = '" . $v_products_description[$key] . "',\n                                    products_short_description = '" . $v_products_short_description[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_url = '" . $v_products_url[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_meta_title = '" . $v_products_meta_title[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_meta_description = '" . $v_products_meta_description[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_meta_keywords = '" . $v_products_meta_keywords[$key] . "'\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tproducts_id = '{$v_products_id}' AND\n\t\t\t\t\t\t\t\t\tlanguage_id = '{$key}'";
                        }
                        // end support for Linda's Header Controller 2.0
                        $result = olc_db_query($sql);
                    }
                }
            }
        }
        if (isset($v_categories_id)) {
            //find out if this product is listed in the category given
            $result_incategory = olc_db_query('SELECT
						' . TABLE_PRODUCTS_TO_CATEGORIES . '.products_id,
						' . TABLE_PRODUCTS_TO_CATEGORIES . '.categories_id
						FROM
							' . TABLE_PRODUCTS_TO_CATEGORIES . '
						WHERE
						' . TABLE_PRODUCTS_TO_CATEGORIES . '.products_id=' . $v_products_id . ' AND
						' . TABLE_PRODUCTS_TO_CATEGORIES . '.categories_id=' . $v_categories_id);
            if (olc_db_num_rows($result_incategory) == 0) {
                // nope, this is a new category for this product
                $res1 = olc_db_query('INSERT INTO ' . TABLE_PRODUCTS_TO_CATEGORIES . ' (products_id, categories_id)
							VALUES ("' . $v_products_id . '", "' . $v_categories_id . '")');
            } else {
                // already in this category, nothing to do!
            }
        }
        // for the separate prices per customer module
        $ll = 1;
        if (isset($v_customer_price_1)) {
            if ($v_customer_group_id_1 == '' and $v_customer_price_1 != '') {
                echo "<font color=red>ERROR - v_customer_group_id and v_customer_price must occur in pairs</font>";
                die;
            }
            // they spec'd some prices, so clear all existing entries
            $result = olc_db_query('
						DELETE
						FROM
							' . TABLE_PRODUCTS_GROUPS . '
						WHERE
							products_id = ' . $v_products_id);
            // and insert the new record
            if ($v_customer_price_1 != '') {
                $result = olc_db_query('
							INSERT INTO
								' . TABLE_PRODUCTS_GROUPS . '
							VALUES
							(
								' . $v_customer_group_id_1 . ',
								' . $v_customer_price_1 . ',
								' . $v_products_id . ',
								' . $v_products_price . '
								)');
            }
            if ($v_customer_price_2 != '') {
                $result = olc_db_query('
							INSERT INTO
								' . TABLE_PRODUCTS_GROUPS . '
							VALUES
							(
								' . $v_customer_group_id_2 . ',
								' . $v_customer_price_2 . ',
								' . $v_products_id . ',
								' . $v_products_price . '
								)');
            }
            if ($v_customer_price_3 != '') {
                $result = olc_db_query('
							INSERT INTO
								' . TABLE_PRODUCTS_GROUPS . '
							VALUES
							(
								' . $v_customer_group_id_3 . ',
								' . $v_customer_price_3 . ',
								' . $v_products_id . ',
								' . $v_products_price . '
								)');
            }
            if ($v_customer_price_4 != '') {
                $result = olc_db_query('
							INSERT INTO
								' . TABLE_PRODUCTS_GROUPS . '
							VALUES
							(
								' . $v_customer_group_id_4 . ',
								' . $v_customer_price_4 . ',
								' . $v_products_id . ',
								' . $v_products_price . '
								)');
            }
        }
        // VJ product attribs begin
        if (isset($v_attribute_options_id_1)) {
            $attribute_rows = 1;
            // master row count
            $languages = olc_get_languages();
            // product options count
            $attribute_options_count = 1;
            $v_attribute_options_id_var = 'v_attribute_options_id_' . $attribute_options_count;
            while (isset(${$v_attribute_options_id_var}) && !empty(${$v_attribute_options_id_var})) {
                // remove product attribute options linked to this product before proceeding further
                // this is useful for removing attributes linked to a product
                $attributes_clean_query = DELETE_FROM . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $v_products_id . "' and options_id = '" . (int) ${$v_attribute_options_id_var} . APOS;
                olc_db_query($attributes_clean_query);
                $attribute_options_query = "select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int) ${$v_attribute_options_id_var} . APOS;
                $attribute_options_values = olc_db_query($attribute_options_query);
                // option table update begin
                if ($attribute_rows == 1) {
                    // insert into options table if no option exists
                    if (olc_db_num_rows($attribute_options_values) <= 0) {
                        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
                            $lid = $languages[$i]['id'];
                            $v_attribute_options_name_var = 'v_attribute_options_name_' . $attribute_options_count . '_' . $lid;
                            if (isset(${$v_attribute_options_name_var})) {
                                $attribute_options_insert_query = INSERT_INTO . TABLE_PRODUCTS_OPTIONS . " (products_options_id, language_id, products_options_name) values ('" . (int) ${$v_attribute_options_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_options_name_var} . "')";
                                $attribute_options_insert = olc_db_query($attribute_options_insert_query);
                            }
                        }
                    } else {
                        // update options table, if options already exists
                        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
                            $lid = $languages[$i]['id'];
                            $v_attribute_options_name_var = 'v_attribute_options_name_' . $attribute_options_count . '_' . $lid;
                            if (isset(${$v_attribute_options_name_var})) {
                                $attribute_options_update_lang_query = "select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int) ${$v_attribute_options_id_var} . "' and language_id ='" . (int) $lid . APOS;
                                $attribute_options_update_lang_values = olc_db_query($attribute_options_update_lang_query);
                                // if option name doesn't exist for particular language, insert value
                                if (olc_db_num_rows($attribute_options_update_lang_values) <= 0) {
                                    $attribute_options_lang_insert_query = INSERT_INTO . TABLE_PRODUCTS_OPTIONS . " (products_options_id, language_id, products_options_name) values ('" . (int) ${$v_attribute_options_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_options_name_var} . "')";
                                    $attribute_options_lang_insert = olc_db_query($attribute_options_lang_insert_query);
                                } else {
                                    // if option name exists for particular language, update table
                                    $attribute_options_update_query = SQL_UPDATE . TABLE_PRODUCTS_OPTIONS . " set products_options_name = '" . ${$v_attribute_options_name_var} . "' where products_options_id ='" . (int) ${$v_attribute_options_id_var} . "' and language_id = '" . (int) $lid . APOS;
                                    $attribute_options_update = olc_db_query($attribute_options_update_query);
                                }
                            }
                        }
                    }
                }
                // option table update end
                // product option values count
                $attribute_values_count = 1;
                $v_attribute_values_id_var = 'v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count;
                while (isset(${$v_attribute_values_id_var}) && !empty(${$v_attribute_values_id_var})) {
                    $attribute_values_query = "select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int) ${$v_attribute_values_id_var} . APOS;
                    $attribute_values_values = olc_db_query($attribute_values_query);
                    // options_values table update begin
                    if ($attribute_rows == 1) {
                        // insert into options_values table if no option exists
                        if (olc_db_num_rows($attribute_values_values) <= 0) {
                            for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
                                $lid = $languages[$i]['id'];
                                $v_attribute_values_name_var = 'v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid;
                                if (isset(${$v_attribute_values_name_var})) {
                                    $attribute_values_insert_query = INSERT_INTO . TABLE_PRODUCTS_OPTIONS_VALUES . " (products_options_values_id, language_id, products_options_values_name) values ('" . (int) ${$v_attribute_values_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_values_name_var} . "')";
                                    $attribute_values_insert = olc_db_query($attribute_values_insert_query);
                                }
                            }
                            // insert values to pov2po table
                            $attribute_values_pov2po_query = INSERT_INTO . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " (products_options_id, products_options_values_id) values ('" . (int) ${$v_attribute_options_id_var} . "', '" . (int) ${$v_attribute_values_id_var} . "')";
                            $attribute_values_pov2po = olc_db_query($attribute_values_pov2po_query);
                        } else {
                            // update options table, if options already exists
                            for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
                                $lid = $languages[$i]['id'];
                                $v_attribute_values_name_var = 'v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid;
                                if (isset(${$v_attribute_values_name_var})) {
                                    $attribute_values_update_lang_query = "select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int) ${$v_attribute_values_id_var} . "' and language_id ='" . (int) $lid . APOS;
                                    $attribute_values_update_lang_values = olc_db_query($attribute_values_update_lang_query);
                                    // if options_values name doesn't exist for particular language, insert value
                                    if (olc_db_num_rows($attribute_values_update_lang_values) <= 0) {
                                        $attribute_values_lang_insert_query = INSERT_INTO . TABLE_PRODUCTS_OPTIONS_VALUES . " (products_options_values_id, language_id, products_options_values_name) values ('" . (int) ${$v_attribute_values_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_values_name_var} . "')";
                                        $attribute_values_lang_insert = olc_db_query($attribute_values_lang_insert_query);
                                    } else {
                                        // if options_values name exists for particular language, update table
                                        $attribute_values_update_query = SQL_UPDATE . TABLE_PRODUCTS_OPTIONS_VALUES . " set products_options_values_name = '" . ${$v_attribute_values_name_var} . "' where products_options_values_id ='" . (int) ${$v_attribute_values_id_var} . "' and language_id = '" . (int) $lid . APOS;
                                        $attribute_values_update = olc_db_query($attribute_values_update_query);
                                    }
                                }
                            }
                        }
                    }
                    // options_values table update end
                    // options_values price update begin
                    $v_attribute_values_price_var = 'v_attribute_values_price_' . $attribute_options_count . '_' . $attribute_values_count;
                    if (isset(${$v_attribute_values_price_var}) && ${$v_attribute_values_price_var} != '') {
                        $attribute_prices_query = "select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $v_products_id . "' and options_id ='" . (int) ${$v_attribute_options_id_var} . "' and options_values_id = '" . (int) ${$v_attribute_values_id_var} . APOS;
                        $attribute_prices_values = olc_db_query($attribute_prices_query);
                        $attribute_values_price_prefix = ${$v_attribute_values_price_var} < 0 ? '-' : '+';
                        // options_values_prices table update begin
                        // insert into options_values_prices table if no price exists
                        if (olc_db_num_rows($attribute_prices_values) <= 0) {
                            $attribute_prices_insert_query = INSERT_INTO . TABLE_PRODUCTS_ATTRIBUTES . " (products_id, options_id, options_values_id, options_values_price, price_prefix) values ('" . (int) $v_products_id . "', '" . (int) ${$v_attribute_options_id_var} . "', '" . (int) ${$v_attribute_values_id_var} . "', '" . (int) ${$v_attribute_values_price_var} . "', '" . $attribute_values_price_prefix . "')";
                            $attribute_prices_insert = olc_db_query($attribute_prices_insert_query);
                        } else {
                            // update options table, if options already exists
                            $attribute_prices_update_query = SQL_UPDATE . TABLE_PRODUCTS_ATTRIBUTES . " set options_values_price = '" . ${$v_attribute_values_price_var} . "', price_prefix = '" . $attribute_values_price_prefix . "' where products_id = '" . (int) $v_products_id . "' and options_id = '" . (int) ${$v_attribute_options_id_var} . "' and options_values_id ='" . (int) ${$v_attribute_values_id_var} . APOS;
                            $attribute_prices_update = olc_db_query($attribute_prices_update_query);
                        }
                    }
                    // options_values price update end
                    $attribute_values_count++;
                    $v_attribute_values_id_var = 'v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count;
                }
                $attribute_options_count++;
                $v_attribute_options_id_var = 'v_attribute_options_id_' . $attribute_options_count;
            }
            $attribute_rows++;
        }
        // VJ product attribs end
    } else {
        // this record was missing the product_model
        array_walk($items, 'print_el');
        echo "<p class=smallText>No products_model field in record. This line was not imported <br/>";
        echo HTML_BR;
    }
    // end of row insertion code
}
function olc_reset_cache_block($cache_block)
{
    global $cache_blocks;
    for ($i = 0, $n = sizeof($cache_blocks); $i < $n; $i++) {
        if ($cache_blocks[$i]['code'] == $cache_block) {
            if ($cache_blocks[$i]['multiple']) {
                if ($dir = @opendir(DIR_FS_CACHE)) {
                    while ($cache_file = readdir($dir)) {
                        $cached_file = $cache_blocks[$i]['file'];
                        $languages = olc_get_languages();
                        for ($j = 0, $k = sizeof($languages); $j < $k; $j++) {
                            $cached_file_unlink = ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
                            if (ereg('^' . $cached_file_unlink, $cache_file)) {
                                @unlink(DIR_FS_CACHE . $cache_file);
                            }
                        }
                    }
                    closedir($dir);
                }
            } else {
                $cached_file = $cache_blocks[$i]['file'];
                $languages = olc_get_languages();
                for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
                    $cached_file = ereg_replace('-language', '-' . $languages[$i]['directory'], $cached_file);
                    @unlink(DIR_FS_CACHE . $cached_file);
                }
            }
            break;
        }
    }
}