Пример #1
0
    case 'deleteconfirm':
        $manufacturers_id = vam_db_prepare_input($_GET['mID']);
        if ($_POST['delete_image'] == 'on') {
            $manufacturer_query = vam_db_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . vam_db_input($manufacturers_id) . "'");
            $manufacturer = vam_db_fetch_array($manufacturer_query);
            $image_location = DIR_FS_DOCUMENT_ROOT . DIR_WS_IMAGES . $manufacturer['manufacturers_image'];
            if (file_exists($image_location)) {
                @unlink($image_location);
            }
        }
        vam_db_query("delete from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . vam_db_input($manufacturers_id) . "'");
        vam_db_query("delete from " . TABLE_MANUFACTURERS_INFO . " where manufacturers_id = '" . vam_db_input($manufacturers_id) . "'");
        if ($_POST['delete_products'] == 'on') {
            $products_query = vam_db_query("select products_id from " . TABLE_PRODUCTS . " where manufacturers_id = '" . vam_db_input($manufacturers_id) . "'");
            while ($products = vam_db_fetch_array($products_query)) {
                vam_remove_product($products['products_id']);
            }
        } else {
            vam_db_query("update " . TABLE_PRODUCTS . " set manufacturers_id = '' where manufacturers_id = '" . vam_db_input($manufacturers_id) . "'");
        }
        if (USE_CACHE == 'true') {
            vam_reset_cache_block('manufacturers');
        }
        vam_redirect(vam_href_link(FILENAME_MANUFACTURERS, 'page=' . $_GET['page']));
        break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html <?php 
echo HTML_PARAMS;
?>
Пример #2
0
function process_row($item1, $filelayout, $filelayout_count, $default_these, $ep_separator, $languages, $custom_fields)
{
    // first we clean up the row of data
    if (EP_EXCEL_SAFE_OUTPUT == true) {
        $items = $item1;
    } else {
        // chop blanks from each end
        $item1 = ltrim(rtrim($item1));
        // blow it into an array, splitting on the tabs
        $items = explode($ep_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 first & last character are quotes;
                    // if it is, chop off the quotes.
                    if (substr($items[$i], -1) == '"' && substr($items[$i], 0, 1) == '"') {
                        $items[$i] = substr($items[$i], 2, strlen($items[$i]) - 4);
                    }
                    // now any remaining doubled double quotes should be converted to one doublequote
                    if (EP_REPLACE_QUOTES == true) {
                        if (EP_EXCEL_SAFE_OUTPUT == true) {
                            $items[$i] = str_replace('\\"\\"', "&#34;", $items[$i]);
                        }
                        $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) == '"' && substr($items[$i], 0, 1) == '"') {
                        $items[$i] = substr($items[$i], 1, strlen($items[$i]) - 2);
                    }
                    // now any remaining doubled double quotes should be converted to one doublequote
                    if (EP_REPLACE_QUOTES == true) {
                        if (EP_EXCEL_SAFE_OUTPUT == true) {
                            $items[$i] = str_replace('""', "&#34;", $items[$i]);
                        }
                        $items[$i] = str_replace('"', "&#34;", $items[$i]);
                        $items[$i] = str_replace("'", "&#39;", $items[$i]);
                    }
                }
            }
        }
    }
    // /////////////////////////////////////////////////////////////
    // Do specific functions without processing entire range of vars
    // /////////////////////////////
    // first do product extra fields
    if (isset($items[$filelayout['v_products_extra_fields_id']])) {
        $v_products_model = $items[$filelayout['v_products_model']];
        // EP for product extra fields Contrib by minhmaster DEVSOFTVN ==========
        $v_products_extra_fields_id = $items[$filelayout['v_products_extra_fields_id']];
        //        $v_products_id    =    $items[$filelayout['v_products_id']];
        $v_products_extra_fields_value = $items[$filelayout['v_products_extra_fields_value']];
        $sql = "SELECT p.products_id as v_products_id FROM " . TABLE_PRODUCTS . " as p WHERE p.products_model = '" . $v_products_model . "'";
        $result = vam_db_query($sql);
        $row = vam_db_fetch_array($result);
        $sql_exist = "SELECT products_extra_fields_value FROM " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " WHERE (products_id ='" . $row['v_products_id'] . "') AND (products_extra_fields_id ='" . $v_products_extra_fields_id . "')";
        if (vam_db_num_rows(vam_db_query($sql_exist)) > 0) {
            $sql_extra_field = "UPDATE " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " SET products_extra_fields_value='" . $v_products_extra_fields_value . "' WHERE (products_id ='" . $row['v_products_id'] . "') AND (products_extra_fields_id ='" . $v_products_extra_fields_id . "')";
            $str_err_report = " {$v_products_extra_fields_id} | {$v_products_id}  | {$v_products_model} | {$v_products_extra_fields_value} | <b><font color=black>" . EASY_EXTRA_FIELD_UPDATED . "</font></b><br />";
        } else {
            $sql_extra_field = "INSERT INTO " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . "(products_id,products_extra_fields_id,products_extra_fields_value) VALUES ('" . $row['v_products_id'] . "','" . $v_products_extra_fields_id . "','" . $v_products_extra_fields_value . "')";
            $str_err_report = " {$v_products_extra_fields_id} | {$v_products_id} | {$v_products_model} | {$v_products_extra_fields_value} | <b><font color=green>" . EASY_EXTRA_FIELD_ADDED . "</font></b><br />";
        }
        $result = vam_db_query($sql_extra_field);
        echo $str_err_report;
        // end (EP for product extra fields Contrib by minhmt DEVSOFTVN) ============
        // /////////////////////
        // or do product deletes
    } elseif ($items[$filelayout['v_status']] == EP_DELETE_IT) {
        // Get the ID
        $sql = "SELECT p.products_id as v_products_id    FROM " . TABLE_PRODUCTS . " as p WHERE p.products_model = '" . $items[$filelayout['v_products_model']] . "'";
        $result = vam_db_query($sql);
        $row = vam_db_fetch_array($result);
        if (vam_db_num_rows($result) == 1) {
            vam_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'");
            $product_categories_query = vam_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'");
            $product_categories = vam_db_fetch_array($product_categories_query);
            if ($product_categories['total'] == '0') {
                // gather product attribute data
                $result = vam_db_query("select pov.products_options_values_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov on pa.options_values_id=pov.products_options_values_id where pa.products_id = '" . (int) $row['v_products_id'] . "'");
                $remove_attribs = array();
                while ($tmp_attrib = vam_db_fetch_array($result)) {
                    $remove_attribs[] = $tmp_attrib;
                }
                // check each attribute name for links to other products
                foreach ($remove_attribs as $rakey => $ravalue) {
                    $product_attribs_query = vam_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " where options_values_id = '" . (int) $ravalue['products_options_values_id'] . "'");
                    $product_attribs = vam_db_fetch_array($product_attribs_query);
                    // if no other products linked, remove attribute name
                    if ((int) $product_attribs['total'] == 1) {
                        vam_db_query("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int) $ravalue['products_options_values_id'] . "'");
                    }
                }
                // remove attribute records
                vam_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $row['v_products_id'] . "'");
                // remove product
                vam_remove_product($row['v_products_id']);
            }
            if (USE_CACHE == 'true') {
                vam_reset_cache_block('categories');
                vam_reset_cache_block('also_purchased');
            }
            echo EASY_TEXT_DELETED . $items[$filelayout['v_products_model']] . EASY_TEXT_DELETED . "<br />";
        } else {
            echo EASY_TEXT_NOT_DELETE . $items['v_products_model'] . EASY_TEXT_NOT_DELETE . "<br> ";
        }
        // //////////////////////////////////
        // or do regular product processing
        // //////////////////////////////////
    } else {
        // /////////////////////////////////////////////////////////////////////
        //
        // Start: Support for other contributions in products table
        //
        // /////////////////////////////////////////////////////////////////////
        $ep_additional_select = '';
        if (EP_ADDITIONAL_IMAGES == true) {
            $ep_additional_select .= 'p.products_image_description as v_products_image_description,';
        }
        if (EP_MORE_PICS_6_SUPPORT == true) {
            $ep_additional_select .= 'p.products_subimage1 as v_products_subimage1,p.products_subimage2 as v_products_subimage2,p.products_subimage3 as v_products_subimage3,p.products_subimage4 as v_products_subimage4,p.products_subimage5 as v_products_subimage5,p.products_subimage6 as v_products_subimage6,';
        }
        if (EP_UNLIMITED_IMAGES == true) {
            $ep_additional_select .= 'p.products_image_array as v_products_image_array,';
        }
        if (EP_ULTRPICS_SUPPORT == true) {
            $ep_additional_select .= 'products_image_med as v_products_image_med,products_image_lrg as v_products_image_lrg,products_image_sm_1 as v_products_image_sm_1,products_image_xl_1 as v_products_image_xl_1,products_image_sm_2 as v_products_image_sm_2,products_image_xl_2 as v_products_image_xl_2,products_image_sm_3 as v_products_image_sm_3,products_image_xl_3 as v_products_image_xl_3,products_image_sm_4 as v_products_image_sm_4,products_image_xl_4 as v_products_image_xl_4,products_image_sm_5 as v_products_image_sm_5,products_image_xl_5 as v_products_image_xl_5,products_image_sm_6 as v_products_image_sm_6,products_image_xl_6 as v_products_image_xl_6,';
        }
        if (EP_PDF_UPLOAD_SUPPORT == true) {
            $ep_additional_select .= 'p.products_pdfupload as v_products_pdfupload, p.products_fileupload as v_products_fileupload,';
        }
        if (EP_MVS_SUPPORT == true) {
            $ep_additional_select .= 'vendors_id as v_vendor_id,';
        }
        foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) {
            $ep_additional_select .= 'p.' . $key . ' as v_' . $key . ',';
        }
        // /////////////////////////////////////////////////////////////////////
        // End: Support for other contributions in products table
        // /////////////////////////////////////////////////////////////////////
        // now do a query to get the record's current contents
        $sql = "SELECT\n                    p.products_id as v_products_id,\n                    p.products_model as v_products_model,\n                    p.products_image as v_products_image,\n                    {$ep_additional_select}\n                    p.products_price as v_products_price,\n                    p.products_weight as v_products_weight,\n                    p.products_date_available as v_date_avail,\n                    p.products_date_added as v_date_added,\n                    p.products_tax_class_id as v_tax_class_id,\n                    p.products_quantity as v_products_quantity,\n                    p.manufacturers_id as v_manufacturers_id,\n                    subc.categories_id as v_categories_id,\n                    p.products_status as v_status_current\n                FROM\n                    " . TABLE_PRODUCTS . " as p,\n                    " . TABLE_CATEGORIES . " as subc,\n                    " . TABLE_PRODUCTS_TO_CATEGORIES . " as ptoc\n                WHERE\n                    p.products_model = '" . $items[$filelayout['v_products_model']] . "' AND\n                    p.products_id = ptoc.products_id AND\n                    ptoc.categories_id = subc.categories_id\n                LIMIT 1\n            ";
        $result = vam_db_query($sql);
        $row = vam_db_fetch_array($result);
        // determine processing status based on dropdown choice on EP menu
        // Delete product included in normal & update options
        if (sizeof($row) > 1 && ($_POST['imput_mode'] == "normal" || $_POST['imput_mode'] == "update")) {
            $process_product = true;
            // For Delete Only option (product exists) & (v_status = EP_DELETE_IT) & (Delete Only)
        } elseif (sizeof($row) > 1 && $items[$filelayout['v_status']] == EP_DELETE_IT && $_POST['imput_mode'] == "delete") {
            $process_product = true;
        } elseif (sizeof($row) == 1 && ($_POST['imput_mode'] == "normal" || $_POST['imput_mode'] == "addnew")) {
            $process_product = true;
        } else {
            $process_product = false;
        }
        if ($process_product == true) {
            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 ($languages as $key => $lang) {
                    // products_name, products_description, products_url
                    $sql2 = "SELECT * \n                            FROM " . TABLE_PRODUCTS_DESCRIPTION . "\n                            WHERE\n                                products_id = " . $row['v_products_id'] . " AND\n                                language_id = '" . $lang['id'] . "'\n                            LIMIT 1\n                            ";
                    $result2 = vam_db_query($sql2);
                    $row2 = vam_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_url_' . $lang['id']] = $row2['products_url'];
                    foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) {
                        $row['v_' . $key . '_' . $lang['id']] = $row2[$key];
                    }
                    // header tags controller support
                    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: header tags controller support
                }
                // 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 <= EP_MAX_CATEGORIES + 1; $categorylevel++) {
                    if ($thecategory_id) {
                        $sql3 = "SELECT parent_id, \n\t\t\t\t\t\t                categories_image\n\t\t\t\t\t\t\t     FROM " . TABLE_CATEGORIES . "\n\t\t\t\t\t\t\t     WHERE    \n\t\t\t\t\t\t\t\t        categories_id = " . $thecategory_id . '';
                        $result3 = vam_db_query($sql3);
                        if ($row3 = vam_db_fetch_array($result3)) {
                            $temprow['v_categories_image_' . $categorylevel] = $row3['categories_image'];
                        }
                        foreach ($languages as $key => $lang) {
                            $sql2 = "SELECT categories_name\n\t\t\t\t\t\t\t\t     FROM " . TABLE_CATEGORIES_DESCRIPTION . "\n\t\t\t\t\t\t\t\t     WHERE    \n\t\t\t\t\t\t\t\t\t        categories_id = " . $thecategory_id . " AND\n\t\t\t\t\t\t\t\t\t        language_id = " . $lang['id'];
                            $result2 = vam_db_query($sql2);
                            if ($row2 = vam_db_fetch_array($result2)) {
                                $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] = $row2['categories_name'];
                            }
                        }
                        // now get the parent ID if there was one
                        $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_image_' . $categorylevel] = '';
                        foreach ($languages as $key => $lang) {
                            $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] = '';
                        }
                    }
                }
                // temprow has the old style low to high level categories.
                $newlevel = 1;
                // let's turn them into high to low level categories
                for ($categorylevel = EP_MAX_CATEGORIES + 1; $categorylevel > 0; $categorylevel--) {
                    $found = false;
                    if ($temprow['v_categories_image_' . $categorylevel] != '') {
                        $row['v_categories_image_' . $newlevel] = $temprow['v_categories_image_' . $categorylevel];
                        $found = true;
                    }
                    foreach ($languages as $key => $lang) {
                        if ($temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] != '') {
                            $row['v_categories_name_' . $newlevel . '_' . $lang['id']] = $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']];
                            $found = true;
                        }
                    }
                    if ($found == true) {
                        $newlevel++;
                    }
                }
                // default the manufacturer
                if ($row['v_manufacturers_id'] != '') {
                    $sql2 = "SELECT manufacturers_name\n                        FROM " . TABLE_MANUFACTURERS . "\n                        WHERE manufacturers_id = " . $row['v_manufacturers_id'];
                    $result2 = vam_db_query($sql2);
                    $row2 = vam_db_fetch_array($result2);
                    $row['v_manufacturers_name'] = $row2['manufacturers_name'];
                }
                if (EP_MVS_SUPPORT == true) {
                    $result2 = vam_db_query("select vendors_name from " . TABLE_VENDORS . " WHERE vendors_id = " . $row['v_vendor_id']);
                    $row2 = vam_db_fetch_array($result2);
                    $row['v_vendor'] = $row2['vendors_name'];
                }
                //elari -
                //We check the value of tax class and title instead of the id
                //Then we add the tax to price if EP_PRICE_WITH_TAX is set to true
                $row_tax_multiplier = vam_get_tax_class_rate($row['v_tax_class_id']);
                $row['v_tax_class_title'] = vam_get_tax_class_title($row['v_tax_class_id']);
                if (EP_PRICE_WITH_TAX == true) {
                    $row['v_products_price'] = $row['v_products_price'] + round($row['v_products_price'] * $row_tax_multiplier / 100, EP_PRECISION);
                }
                // 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 $tkey => $thisvar) {
                    ${$thisvar} = $row[$thisvar];
                }
                $row = vam_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) {
                if (!($key == 'v_date_added' && empty($items[$value]))) {
                    ${$key} = $items[$value];
                }
            }
            //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 = vam_get_tax_title_class_id($v_tax_class_title);
            }
            //we check the tax rate of this tax_class_id
            $row_tax_multiplier = vam_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 (EP_PRICE_WITH_TAX == true) {
                $v_products_price = round($v_products_price / (1 + $row_tax_multiplier * 0.01), EP_PRECISION);
            }
            // if they give us one category, they give us all categories. convert data structure to a multi-dim array
            unset($v_categories_name);
            // default to not set.
            unset($v_categories_image);
            // default to not set.
            foreach ($languages as $key => $lang) {
                $baselang_id = $lang['id'];
                break;
            }
            if (isset($filelayout['v_categories_name_1_' . $baselang_id])) {
                $v_categories_name = array();
                $v_categories_image = array();
                $newlevel = 1;
                for ($categorylevel = EP_MAX_CATEGORIES; $categorylevel > 0; $categorylevel--) {
                    $found = false;
                    if ($items[$filelayout['v_categories_image_' . $categorylevel]] != '') {
                        $v_categories_image[$newlevel] = $items[$filelayout['v_categories_image_' . $categorylevel]];
                        $found = true;
                    }
                    foreach ($languages as $key => $lang) {
                        if ($items[$filelayout['v_categories_name_' . $categorylevel . '_' . $lang['id']]] != '') {
                            $v_categories_name[$newlevel][$lang['id']] = $items[$filelayout['v_categories_name_' . $categorylevel . '_' . $lang['id']]];
                            $found = true;
                        }
                    }
                    if ($found == true) {
                        $newlevel++;
                    }
                }
                while ($newlevel < EP_MAX_CATEGORIES + 1) {
                    $v_categories_image[$newlevel] = '';
                    // default the remaining items to nothing
                    foreach ($languages as $key => $lang) {
                        $v_categories_name[$newlevel][$lang['id']] = '';
                        // default the remaining items to nothing
                    }
                    $newlevel++;
                }
            }
            if (ltrim(rtrim($v_products_quantity)) == '') {
                $v_products_quantity = 1;
            }
            if (empty($v_date_avail)) {
                $v_date_avail = 'NULL';
            } else {
                $v_date_avail = "'" . date("Y-m-d H:i:s", strtotime($v_date_avail)) . "'";
            }
            if (empty($v_date_added)) {
                $v_date_added = "'" . date("Y-m-d H:i:s") . "'";
            } else {
                $v_date_added = "'" . date("Y-m-d H:i:s", strtotime($v_date_added)) . "'";
            }
            // default the stock if they spec'd it or if it's blank
            if (isset($v_status_current)) {
                $v_db_status = strval($v_status_current);
                // default to current value
            } else {
                $v_db_status = '1';
                // default to active
            }
            if (trim($v_status) == EP_TEXT_INACTIVE) {
                // they told us to deactivate this item
                $v_db_status = '0';
            } elseif (trim($v_status) == EP_TEXT_ACTIVE) {
                $v_db_status = '1';
            }
            if (EP_INACTIVATE_ZERO_QUANTITIES == true && $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 = EP_DEFAULT_IMAGE_PRODUCT;
            } else {
                if (USE_EP_IMAGE_MANIPULATOR == 'true') {
                    prepare_image($v_products_image);
                } else {
                    $v_products_image;
                }
            }
            if (strlen($v_products_model) > EP_MODEL_NUMBER_SIZE) {
                echo EASY_ERROR_2 . EP_MODEL_NUMBER_SIZE . "<br />" . EASY_ERROR_2A;
                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                    FROM " . TABLE_MANUFACTURERS . " as man\n                    WHERE man.manufacturers_name = '" . vam_db_input($v_manufacturers_name) . "'";
                $result = vam_db_query($sql);
                $row = vam_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 = vam_db_query($sql);
                    $row = vam_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_image
                        ) VALUES (
                        $max_mfg_id,
                        '".EP_DEFAULT_IMAGE_MANUFACTURER."'
                        )";
                    */
                    // Comment this query out if you have an older 2.2 codebase
                    $sql = "INSERT INTO " . TABLE_MANUFACTURERS . "(\n                        manufacturers_id,\n                        manufacturers_name,\n                        manufacturers_image,\n                        date_added,\n                        last_modified\n                        ) VALUES (\n                        {$max_mfg_id},\n                        '" . vam_db_input($v_manufacturers_name) . "',\n                        '" . EP_DEFAULT_IMAGE_MANUFACTURER . "',\n                        '" . date("Y-m-d H:i:s") . "',\n                        '" . date("Y-m-d H:i:s") . "'\n                        )";
                    $result = vam_db_query($sql);
                    $v_manufacturer_id = $max_mfg_id;
                    $sql = "INSERT INTO " . TABLE_MANUFACTURERS_INFO . "(\n                        manufacturers_id,\n                        manufacturers_meta_title,\n                        manufacturers_meta_description,\n                        manufacturers_meta_keywords,\n                        manufacturers_url,\n                        manufacturers_description,\n                        languages_id\n                        ) VALUES (\n                        {$max_mfg_id},\n                        '',\n                        '',\n                        '',\n                        '',\n                        '',\n                        '" . EP_DEFAULT_LANGUAGE_ID . "'\n                        )";
                    $result = vam_db_query($sql);
                }
            }
            // if the categories names are set then try to update them
            foreach ($languages as $key => $lang) {
                $baselang_id = $lang['id'];
                break;
            }
            if (isset($filelayout['v_categories_name_1_' . $baselang_id])) {
                // start from the highest possible category and work our way down from the parent
                $v_categories_id = 0;
                $theparent_id = 0;
                for ($categorylevel = EP_MAX_CATEGORIES + 1; $categorylevel > 0; $categorylevel--) {
                    //foreach ($languages as $key => $lang){
                    $thiscategoryname = $v_categories_name[$categorylevel][$baselang_id];
                    if ($thiscategoryname != '') {
                        // we found a category name in this field, look for database entry
                        $sql = "SELECT cat.categories_id\n                            FROM " . TABLE_CATEGORIES . " as cat, \n                                 " . TABLE_CATEGORIES_DESCRIPTION . " as des\n                            WHERE\n                                cat.categories_id = des.categories_id AND\n                                des.language_id = " . $baselang_id . " AND\n                                cat.parent_id = " . $theparent_id . " AND\n                                des.categories_name like '" . vam_db_input($thiscategoryname) . "'";
                        $result = vam_db_query($sql);
                        $row = vam_db_fetch_array($result);
                        if ($row != '') {
                            // we have an existing category, update image and date
                            foreach ($row as $item) {
                                $thiscategoryid = $item;
                            }
                            $cat_image = '';
                            if (!empty($v_categories_image[$categorylevel])) {
                                $cat_image = "categories_image='" . vam_db_input($v_categories_image[$categorylevel]) . "', ";
                            } elseif (isset($filelayout['v_categories_image_' . $categorylevel])) {
                                $cat_image = "categories_image='', ";
                            }
                            $query = "UPDATE " . TABLE_CATEGORIES . "\n                                      SET \n                                        {$cat_image}\n                                        last_modified = '" . date("Y-m-d H:i:s") . "'\n                                      WHERE \n                                        categories_id = '" . $row['categories_id'] . "'\n                                      LIMIT 1";
                            vam_db_query($query);
                        } else {
                            // to add, we need to put stuff in categories and categories_description
                            $sql = "SELECT MAX( categories_id) max FROM " . TABLE_CATEGORIES;
                            $result = vam_db_query($sql);
                            $row = vam_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                                        categories_id,\n                                        parent_id,\n                                        categories_image,\n                                        sort_order,\n                                        date_added,\n                                        last_modified\n                                   ) VALUES (\n                                        {$max_category_id},\n                                        {$theparent_id},\n                                        '" . vam_db_input($v_categories_image[$categorylevel]) . "',\n                                        0,\n                                        '" . date("Y-m-d H:i:s") . "',\n                                        '" . date("Y-m-d H:i:s") . "'\n                                   )";
                            $result = vam_db_query($sql);
                            foreach ($languages as $key => $lang) {
                                $sql = "INSERT INTO " . TABLE_CATEGORIES_DESCRIPTION . " (\n                                                categories_id,\n                                                language_id,\n                                                categories_name\n                                       ) VALUES (\n                                                {$max_category_id},\n                                                '" . $lang['id'] . "',\n                                                '" . (!empty($v_categories_name[$categorylevel][$lang['id']]) ? vam_db_input($v_categories_name[$categorylevel][$lang['id']]) : '') . "'\n                                       )";
                                vam_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!
                foreach ($items as $tkey => $item) {
                    print_el($item);
                }
                // find the vendor id from the name imported
                if (EP_MVS_SUPPORT == true) {
                    $vend_result = vam_db_query("SELECT vendors_id FROM " . TABLE_VENDORS . " WHERE vendors_name = '" . $v_vendor . "'");
                    $vend_row = vam_db_fetch_array($vend_result);
                    $v_vendor_id = $vend_row['vendors_id'];
                }
                // process the PRODUCTS table
                $result = vam_db_query("SELECT products_id FROM " . TABLE_PRODUCTS . " WHERE (products_model = '" . $v_products_model . "')");
                // First we check to see if this is a product in the current db.
                if (vam_db_num_rows($result) == 0) {
                    //   insert into products
                    echo EASY_LABEL_NEW_PRODUCT;
                    // /////////////////////////////////////////////////////////////////////
                    //
                    // Start: Support for other contributions
                    //
                    // /////////////////////////////////////////////////////////////////////
                    $ep_additional_fields = '';
                    $ep_additional_data = '';
                    if (EP_ADDITIONAL_IMAGES == true) {
                        $ep_additional_fields .= 'products_image_description,';
                        $ep_additional_data .= "'" . vam_db_input($v_products_image_description) . "',";
                    }
                    foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) {
                        $ep_additional_fields .= $key . ',';
                    }
                    foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) {
                        $tmp_var = 'v_' . $key;
                        $ep_additional_data .= "'" . ${$tmp_var} . "',";
                    }
                    if (EP_MORE_PICS_6_SUPPORT == true) {
                        $ep_additional_fields .= 'products_subimage1,products_subimage2,products_subimage3,products_subimage4,products_subimage5,products_subimage6,';
                        $ep_additional_data .= "'{$v_products_subimage1}','{$v_products_subimage2}','{$v_products_subimage3}','{$v_products_subimage4}','{$v_products_subimage5}','{$v_products_subimage6}',";
                    }
                    if (EP_UNLIMITED_IMAGES == true) {
                        $ep_additional_fields .= 'products_image_array,';
                        $ep_additional_data .= "'" . serialize(explode("|", $v_products_image_array)) . "',";
                    }
                    if (EP_ULTRPICS_SUPPORT == true) {
                        $ep_additional_fields .= 'products_image_med,products_image_lrg,products_image_sm_1,products_image_xl_1,products_image_sm_2,products_image_xl_2,products_image_sm_3,products_image_xl_3,products_image_sm_4,products_image_xl_4,products_image_sm_5,products_image_xl_5,products_image_sm_6,products_image_xl_6,';
                        $ep_additional_data .= "'{$v_products_image_med}','{$v_products_image_lrg}','{$v_products_image_sm_1}','{$v_products_image_xl_1}','{$v_products_image_sm_2}','{$v_products_image_xl_2}','{$v_products_image_sm_3}','{$v_products_image_xl_3}','{$v_products_image_sm_4}','{$v_products_image_xl_4}','{$v_products_image_sm_5}','{$v_products_image_xl_5}','{$v_products_image_sm_6}','{$v_products_image_xl_6}',";
                    }
                    if (EP_PDF_UPLOAD_SUPPORT == true) {
                        $ep_additional_fields .= 'products_pdfupload,products_fileupload,';
                        $ep_additional_data .= "'{$v_products_pdfupload}','{$v_products_fileupload}',";
                    }
                    if (EP_MVS_SUPPORT == true) {
                        $ep_additional_fields .= 'vendors_id,';
                        $ep_additional_data .= "'{$v_vendor_id}',";
                    }
                    // /////////////////////////////////////////////////////////////////////
                    // End: Support for other contributions
                    // /////////////////////////////////////////////////////////////////////
                    $query = "INSERT INTO " . TABLE_PRODUCTS . " (\n                                products_image,\n                                {$ep_additional_fields}\n                                products_model,\n                                products_price,\n                                products_status,\n                                products_last_modified,\n                                products_date_added,\n                                products_date_available,\n                                products_tax_class_id,\n                                products_weight,\n                                products_quantity,\n                                manufacturers_id )\n                              VALUES (\n                                " . (!empty($v_products_image) ? "'" . $v_products_image . "'" : 'NULL') . ",\n                                {$ep_additional_data}\n                                '{$v_products_model}',\n                                '{$v_products_price}',\n                                '{$v_db_status}',\n                                '" . date("Y-m-d H:i:s") . "',\n                                " . $v_date_added . ",\n                                " . $v_date_avail . ",\n                                '{$v_tax_class_id}',\n                                '{$v_products_weight}',\n                                '{$v_products_quantity}',\n                                " . (!empty($v_manufacturer_id) ? $v_manufacturer_id : 'NULL') . ")\n                                ";
                    $result = vam_db_query($query);
                    $v_products_id = vam_db_insert_id();
                } else {
                    // existing product(s), get the id from the query
                    // and update the product data
                    while ($row = vam_db_fetch_array($result)) {
                        $v_products_id = $row['products_id'];
                        echo EASY_LABEL_UPDATED;
                        // /////////////////////////////////////////////////////////////////////
                        //
                        // Start: Support for other contributions
                        //
                        // /////////////////////////////////////////////////////////////////////
                        $ep_additional_updates = '';
                        foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) {
                            $tmp_var = 'v_' . $key;
                            $ep_additional_updates .= $key . "='" . ${$tmp_var} . "',";
                        }
                        if (EP_ADDITIONAL_IMAGES == true && isset($v_products_image_description)) {
                            $ep_additional_updates .= "products_image_description='" . vam_db_input($v_products_image_description) . "',";
                        }
                        if (EP_MORE_PICS_6_SUPPORT == true) {
                            $ep_additional_updates .= "products_subimage1='{$v_products_subimage1}',products_subimage2='{$v_products_subimage2}',products_subimage3='{$v_products_subimage3}',products_subimage4='{$v_products_subimage4}',products_subimage5='{$v_products_subimage5}',products_subimage6='{$v_products_subimage6}',";
                        }
                        if (EP_UNLIMITED_IMAGES == true) {
                            $ep_additional_updates .= "products_image_array='" . serialize(explode("|", $v_products_image_array)) . "',";
                        }
                        if (EP_ULTRPICS_SUPPORT == true) {
                            $ep_additional_updates .= "products_image_med='{$v_products_image_med}',products_image_lrg='{$v_products_image_lrg}',products_image_sm_1='{$v_products_image_sm_1}',products_image_xl_1='{$v_products_image_xl_1}',products_image_sm_2='{$v_products_image_sm_2}',products_image_xl_2='{$v_products_image_xl_2}',products_image_sm_3='{$v_products_image_sm_3}',products_image_xl_3='{$v_products_image_xl_3}',products_image_sm_4='{$v_products_image_sm_4}',products_image_xl_4='{$v_products_image_xl_4}',products_image_sm_5='{$v_products_image_sm_5}',products_image_xl_5='{$v_products_image_xl_5}',products_image_sm_6='{$v_products_image_sm_6}',products_image_xl_6='{$v_products_image_xl_6}',";
                        }
                        if (EP_PDF_UPLOAD_SUPPORT == true) {
                            $ep_additional_updates .= "products_pdfupload='{$v_products_pdfupload}',products_fileupload='{$v_products_fileupload}',";
                        }
                        if (EP_MVS_SUPPORT == true) {
                            $ep_additional_updates .= "vendors_id='{$v_vendor_id}',";
                        }
                        // /////////////////////////////////////////////////////////////////////
                        // End: Support for other contributions
                        // /////////////////////////////////////////////////////////////////////
                        // only include the products image if it has been included in the spreadsheet
                        $tmp_products_image_update = '';
                        if (isset($v_products_image)) {
                            $tmp_products_image_update = "products_image=" . (!empty($v_products_image) ? "'" . $v_products_image . "'" : 'NULL') . ", \n\t\t\t\t\t\t\t\t\t\t    ";
                            if (EP_ADDITIONAL_IMAGES == true && isset($filelayout['v_products_image'])) {
                                $tmp_products_image_update .= "products_image_med=NULL, \n                                                     products_image_pop=NULL, ";
                            }
                        }
                        $query = "UPDATE " . TABLE_PRODUCTS . "\n                              SET\n                                products_price='{$v_products_price}', \n                                {$tmp_products_image_update} \n                                {$ep_additional_updates}\n                                products_weight='{$v_products_weight}', \n                                products_tax_class_id='{$v_tax_class_id}', \n                                products_date_available=" . $v_date_avail . ", \n                                products_date_added=" . $v_date_added . ", \n                                products_last_modified='" . date("Y-m-d H:i:s") . "', \n                                products_quantity = {$v_products_quantity}, \n                                manufacturers_id = " . (!empty($v_manufacturer_id) ? $v_manufacturer_id : 'NULL') . ", \n                                products_status = {$v_db_status}\n                              WHERE\n                                (products_id = {$v_products_id})\n                              LIMIT 1";
                        vam_db_query($query);
                    }
                }
                if (isset($v_products_specials_price)) {
                    if (EP_SPPC_SUPPORT == true) {
                        $SPPC_extra_query = ' and customers_group_id = 0';
                    } else {
                        $SPPC_extra_query = '';
                    }
                    $result = vam_db_query('select * from ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . $SPPC_extra_query);
                    if ($v_products_specials_price == '') {
                        $result = vam_db_query('DELETE FROM ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . $SPPC_extra_query);
                        if (EP_SPPC_SUPPORT == true) {
                            $result = vam_db_query('DELETE FROM specials_retail_prices WHERE products_id = ' . $v_products_id);
                        }
                    } else {
                        if ($specials = vam_db_fetch_array($result)) {
                            $sql_data_array = array('products_id' => $v_products_id, 'specials_new_products_price' => $v_products_specials_price, 'specials_last_modified' => 'now()');
                            vam_db_perform(TABLE_SPECIALS, $sql_data_array, 'update', 'specials_id = ' . $specials['specials_id']);
                            if (EP_SPPC_SUPPORT == true) {
                                $sql_data_array = array('products_id' => $v_products_id, 'specials_new_products_price' => $v_products_specials_price);
                                vam_db_perform('specials_retail_prices', $sql_data_array, 'update', 'products_id = ' . $v_products_id);
                            }
                        } else {
                            $sql_data_array = array('products_id' => $v_products_id, 'specials_new_products_price' => $v_products_specials_price, 'specials_date_added' => 'now()', 'status' => '1');
                            if (EP_SPPC_SUPPORT == true) {
                                $sql_data_array = array_merge($sql_data_array, array('customers_group_id' => '0'));
                            }
                            vam_db_perform(TABLE_SPECIALS, $sql_data_array, 'insert');
                            if (EP_SPPC_SUPPORT == true) {
                                $sql_data_array = array('products_id' => $v_products_id, 'specials_new_products_price' => $v_products_specials_price, 'status' => '1', 'customers_group_id' => '0');
                                vam_db_perform('specials_retail_prices', $sql_data_array, 'insert');
                            }
                        }
                    }
                }
                if (EP_ADDITIONAL_IMAGES == true) {
                    if (isset($filelayout['v_products_image_2'])) {
                        vam_db_query("delete from " . TABLE_ADDITIONAL_IMAGES . " where products_id = '" . (int) $v_products_id . "'");
                        for ($i = 2; $i <= EP_ADDITIONAL_IMAGES_MAX + 1; $i++) {
                            $ai_description_var = 'v_products_image_description_' . $i;
                            $ai_image_var = 'v_products_image_' . $i;
                            if (!empty(${$ai_image_var}) || !empty(${$ai_description_var})) {
                                vam_db_query("insert into " . TABLE_ADDITIONAL_IMAGES . " (products_id, images_description, thumb_images) values ('" . (int) $v_products_id . "', '" . vam_db_input(${$ai_description_var}) . "', '" . vam_db_input(${$ai_image_var}) . "')");
                            }
                        }
                    }
                }
                // process the PRODUCTS_DESCRIPTION table
                foreach ($languages as $tkey => $lang) {
                    $doit = false;
                    foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) {
                        if (isset($filelayout['v_' . $key . '_' . $lang['id']])) {
                            $doit = true;
                        }
                    }
                    if (isset($filelayout['v_products_name_' . $lang['id']]) || isset($filelayout['v_products_description_' . $lang['id']]) || isset($filelayout['v_products_url_' . $lang['id']]) || isset($filelayout['v_products_meta_title_' . $lang['id']]) || $doit == true) {
                        $sql = "SELECT * FROM " . TABLE_PRODUCTS_DESCRIPTION . " WHERE\n                                products_id = {$v_products_id} AND\n                                language_id = " . $lang['id'];
                        $result = vam_db_query($sql);
                        $products_var = 'v_products_name_' . $lang['id'];
                        $description_var = 'v_products_description_' . $lang['id'];
                        $url_var = 'v_products_url_' . $lang['id'];
                        // /////////////////////////////////////////////////////////////////////
                        //
                        // Start: Support for other contributions
                        //
                        // /////////////////////////////////////////////////////////////////////
                        $ep_additional_updates = '';
                        $ep_additional_fields = '';
                        $ep_additional_data = '';
                        foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) {
                            $tmp_var = 'v_' . $key . '_' . $lang['id'];
                            $ep_additional_updates .= $key . " = '" . vam_db_input(${$tmp_var}) . "',";
                            $ep_additional_fields .= $key . ",";
                            $ep_additional_data .= "'" . vam_db_input(${$tmp_var}) . "',";
                        }
                        // header tags controller support
                        if (isset($filelayout['v_products_meta_title_' . $lang['id']])) {
                            $meta_title_var = 'v_products_meta_title_' . $lang['id'];
                            $meta_description_var = 'v_products_meta_description_' . $lang['id'];
                            $meta_keywords_var = 'v_products_meta_keywords_' . $lang['id'];
                            $ep_additional_updates .= "products_meta_title = '" . vam_db_input(${$meta_title_var}) . "', products_meta_description = '" . vam_db_input(${$meta_description_var}) . "', products_meta_keywords = '" . vam_db_input(${$meta_keywords_var}) . "',";
                            $ep_additional_fields .= "products_meta_title,products_meta_description,products_meta_keywords,";
                            $ep_additional_data .= "'" . vam_db_input(${$meta_title_var}) . "','" . vam_db_input(${$meta_description_var}) . "','" . vam_db_input(${$meta_keywords_var}) . "',";
                        }
                        // end: header tags controller support
                        // /////////////////////////////////////////////////////////////////////
                        // End: Support for other contributions
                        // /////////////////////////////////////////////////////////////////////
                        // existing product?
                        if (vam_db_num_rows($result) > 0) {
                            // already in the description, let's just update it
                            $sql = "UPDATE " . TABLE_PRODUCTS_DESCRIPTION . " \n                                 SET\n                                    products_name='" . vam_db_input(${$products_var}) . "',\n                                    products_description='" . vam_db_input(${$description_var}) . "',\n                                    {$ep_additional_updates}\n                                    products_url='" . ${$url_var} . "'\n                                 WHERE\n                                    products_id = '{$v_products_id}' AND\n                                    language_id = '" . $lang['id'] . "'\n                                 LIMIT 1";
                            $result = vam_db_query($sql);
                        } else {
                            // nope, this is a new product description
                            $result = vam_db_query($sql);
                            $sql = "INSERT INTO " . TABLE_PRODUCTS_DESCRIPTION . "\n                                    ( products_id,\n                                      language_id,\n                                      products_name,\n                                      products_description,\n                                      {$ep_additional_fields}\n                                      products_url\n                                    )\n                                 VALUES (\n                                        '" . $v_products_id . "',\n                                        " . $lang['id'] . ",\n                                        '" . vam_db_input(${$products_var}) . "',\n                                        '" . vam_db_input(${$description_var}) . "',\n                                        {$ep_additional_data}\n                                        '" . ${$url_var} . "'\n                                        )";
                            $result = vam_db_query($sql);
                        }
                    }
                }
                if (isset($v_categories_id)) {
                    //find out if this product is listed in the category given
                    $result_incategory = vam_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 (vam_db_num_rows($result_incategory) == 0) {
                        // nope, this is a new category for this product
                        $res1 = vam_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!
                    }
                }
                // this is for the cross sell contribution
                if (isset($v_cross_sell)) {
                    vam_db_query("delete from " . TABLE_PRODUCTS_XSELL . " where products_id = " . $v_products_id . " or xsell_id = " . $v_products_id . "");
                    if (!empty($v_cross_sell)) {
                        $xsells_array = explode(',', $v_cross_sell);
                        foreach ($xsells_array as $xs_key => $xs_model) {
                            $cross_sell_sql = "select products_id from " . TABLE_PRODUCTS . " where products_model = '" . trim($xs_model) . "' limit 1";
                            $cross_sell_result = vam_db_query($cross_sell_sql);
                            $cross_sell_row = vam_db_fetch_array($cross_sell_result);
                            vam_db_query("insert into " . TABLE_PRODUCTS_XSELL . " (products_id, xsell_id, sort_order) \n                                      values ( " . $v_products_id . ", " . $cross_sell_row['products_id'] . ", 1)");
                            vam_db_query("insert into " . TABLE_PRODUCTS_XSELL . " (products_id, xsell_id, sort_order) \n\t\t\t\t\t\t\t\t  values ( " . $cross_sell_row['products_id'] . ", " . $v_products_id . ", 1)");
                        }
                    }
                }
                // for the separate prices per customer (SPPC) 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 = vam_db_query('
                                DELETE
                                FROM
                                    ' . TABLE_PRODUCTS_GROUPS . '
                                WHERE
                                    products_id = ' . $v_products_id);
                    // and insert the new record
                    if ($v_customer_price_1 != '') {
                        $result = vam_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_1 . ',
                                        ' . $v_customer_price_1 . ',
                                        ' . $v_products_id . '
                                        )');
                    }
                    if ($v_customer_price_2 != '') {
                        $result = vam_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_2 . ',
                                        ' . $v_customer_price_2 . ',
                                        ' . $v_products_id . '
                                        )');
                    }
                    if ($v_customer_price_3 != '') {
                        $result = vam_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_3 . ',
                                        ' . $v_customer_price_3 . ',
                                        ' . $v_products_id . '
                                        )');
                    }
                    if ($v_customer_price_4 != '') {
                        $result = vam_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_4 . ',
                                        ' . $v_customer_price_4 . ',
                                        ' . $v_products_id . '
                                        )');
                    }
                    if (isset($v_customer_specials_price_1)) {
                        $result = vam_db_query('select * from ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . ' and customers_group_id = 1');
                        if ($v_customer_specials_price_1 == '') {
                            $result = vam_db_query('DELETE FROM ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . ' and customers_group_id = 1');
                        } else {
                            if ($specials = vam_db_fetch_array($result)) {
                                $sql_data_array = array('products_id' => $v_products_id, 'specials_new_products_price' => $v_customer_specials_price_1, 'specials_last_modified' => 'now()');
                                vam_db_perform(TABLE_SPECIALS, $sql_data_array, 'update', 'specials_id = ' . $specials['specials_id']);
                            } else {
                                $sql_data_array = array('products_id' => $v_products_id, 'specials_new_products_price' => $v_customer_specials_price_1, 'specials_date_added' => 'now()', 'status' => '1', 'customers_group_id' => '1');
                                vam_db_perform(TABLE_SPECIALS, $sql_data_array, 'insert');
                            }
                        }
                    }
                }
                // end: separate prices per customer (SPPC) module
                // VJ product attribs begin
                if (isset($v_attribute_options_id_1)) {
                    $attribute_rows = 1;
                    // master row count
                    // 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} . "'";
                        vam_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} . "'";
                        $attribute_options_values = vam_db_query($attribute_options_query);
                        // option table update begin
                        if ($attribute_rows == 1) {
                            // insert into options table if no option exists
                            if (vam_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 = vam_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 . "'";
                                        $attribute_options_update_lang_values = vam_db_query($attribute_options_update_lang_query);
                                        // if option name doesn't exist for particular language, insert value
                                        if (vam_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 = vam_db_query($attribute_options_lang_insert_query);
                                        } else {
                                            // if option name exists for particular language, update table
                                            $attribute_options_update_query = "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 . "'";
                                            $attribute_options_update = vam_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} . "'";
                            $attribute_values_values = vam_db_query($attribute_values_query);
                            // options_values table update begin
                            if ($attribute_rows == 1) {
                                // insert into options_values table if no option exists
                                if (vam_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 . "', '" . vam_db_input(${$v_attribute_values_name_var}) . "')";
                                            $attribute_values_insert = vam_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 = vam_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 . "'";
                                            $attribute_values_update_lang_values = vam_db_query($attribute_values_update_lang_query);
                                            // if options_values name doesn't exist for particular language, insert value
                                            if (vam_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 . "', '" . vam_db_input(${$v_attribute_values_name_var}) . "')";
                                                $attribute_values_lang_insert = vam_db_query($attribute_values_lang_insert_query);
                                            } else {
                                                // if options_values name exists for particular language, update table
                                                $attribute_values_update_query = "update " . TABLE_PRODUCTS_OPTIONS_VALUES . " set products_options_values_name = '" . vam_db_input(${$v_attribute_values_name_var}) . "' where products_options_values_id ='" . (int) ${$v_attribute_values_id_var} . "' and language_id = '" . (int) $lid . "'";
                                                $attribute_values_update = vam_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;
                            $v_attribute_values_model = 'v_attribute_values_model_' . $attribute_options_count . '_' . $attribute_values_count;
                            $v_attribute_values_stock = 'v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count;
                            $v_attribute_values_weight = 'v_attribute_values_weight_' . $attribute_options_count . '_' . $attribute_values_count;
                            $v_attribute_values_sort = 'v_attribute_values_sort_' . $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, attributes_model, attributes_stock, options_values_weight, weight_prefix, sortorder 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} . "'";
                                $attribute_prices_values = vam_db_query($attribute_prices_query);
                                $attribute_values_price_prefix = ${$v_attribute_values_price_var} < 0 ? '-' : '+';
                                $attribute_values_weight_prefix = ${$v_attribute_values_weight} < 0 ? '-' : '+';
                                // if negative, remove the negative sign for storing since the prefix is stored in another field.
                                if (${$v_attribute_values_price_var} < 0) {
                                    ${$v_attribute_values_price_var} = strval(-(double) ${$v_attribute_values_price_var});
                                }
                                // options_values_prices table update begin
                                // insert into options_values_prices table if no price exists
                                if (vam_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, attributes_model, attributes_stock, options_values_weight, weight_prefix, sortorder) values ('" . (int) $v_products_id . "', '" . (int) ${$v_attribute_options_id_var} . "', '" . (int) ${$v_attribute_values_id_var} . "', '" . (double) ${$v_attribute_values_price_var} . "', '" . $attribute_values_price_prefix . "', '" . ${$v_attribute_values_model} . "', '" . ${$v_attribute_values_stock} . "', '" . (double) ${$v_attribute_values_weight} . "', '" . ${$v_attribute_values_weight_prefix} . "', '" . ${$v_attribute_values_sort} . "')";
                                    $attribute_prices_insert = vam_db_query($attribute_prices_insert_query);
                                } else {
                                    // update options table, if options already exists
                                    $attribute_prices_update_query = "update " . TABLE_PRODUCTS_ATTRIBUTES . " set options_values_price = '" . ${$v_attribute_values_price_var} . "', price_prefix = '" . $attribute_values_price_prefix . "', set attributes_model = '" . ${$v_attribute_values_model} . "', set attributes_stock = '" . ${$v_attribute_values_stock} . "', set options_values_weight = '" . ${$v_attribute_values_weight} . "', set weight_prefix = '" . ${$v_attribute_values_weight_prefix} . "', set sortorder = '" . ${$v_attribute_values_sort} . "' 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} . "'";
                                    $attribute_prices_update = vam_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
                // BOF mo_image
                for ($i = 0; $i < MO_PICS; $i++) {
                    if (isset($filelayout['v_mo_image_' . ($i + 1)])) {
                        //				echo '<pre>';var_dump($items[$filelayout['v_mo_image_'.($i+1)]]);echo '</pre>';
                        if ($items[$filelayout['v_mo_image_' . ($i + 1)]] != "") {
                            $items[$filelayout['v_mo_image_' . ($i + 1)]];
                            if (USE_EP_IMAGE_MANIPULATOR == 'true') {
                                prepare_image($items[$filelayout['v_mo_image_' . ($i + 1)]]);
                            } else {
                                $items[$filelayout['v_mo_image_' . ($i + 1)]];
                            }
                        }
                        $check_query = vam_db_query("select image_id, image_name from " . TABLE_PRODUCTS_IMAGES . " where products_id='" . (int) $v_products_id . "' and image_nr='" . ($i + 1) . "'");
                        if (vam_db_num_rows($check_query) <= 0) {
                            if ($items[$filelayout['v_mo_image_' . ($i + 1)]] != "") {
                                vam_db_query("insert into " . TABLE_PRODUCTS_IMAGES . " (products_id, image_nr, image_name) values ('" . (int) $v_products_id . "', '" . ($i + 1) . "', '" . $items[$filelayout['v_mo_image_' . ($i + 1)]] . "')");
                            }
                        } else {
                            $check = vam_db_fetch_array($check_query);
                            if ($items[$filelayout['v_mo_image_' . ($i + 1)]] == "") {
                                vam_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where image_id='" . $check['image_id'] . "'");
                            } elseif ($items[$filelayout['v_mo_image_' . ($i + 1)]] != $check['image_name']) {
                                vam_db_query("update " . TABLE_PRODUCTS_IMAGES . " set image_name='" . $items[$filelayout['v_mo_image_' . ($i + 1)]] . "' where image_id='" . $check['image_id'] . "'");
                            }
                        }
                    }
                }
                // EOF mo_image
            } else {
                // this record was missing the product_model
                echo "<p class=smallText>" . EASY_LABEL_TEXT_NO_MODEL;
                foreach ($items as $tkey => $item) {
                    print_el($item);
                }
                echo "<br /><br /></p>";
            }
            // end of row insertion code
        }
        // EP for product extra fields Contrib by minhmaster DEVSOFTVN ==========
    }
    // end (EP for product extra fields Contrib by minhmt DEVSOFTVN) ============
}