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("'", "&#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_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 = tep_db_query($sql);
    $row = tep_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'] . "<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 = tep_db_query($sql2);
            $row2 = tep_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'];
            // support for Linda's Header Controller 2.0 here
            if (isset($filelayout['v_products_head_title_tag_' . $lang['id']])) {
                $row['v_products_head_title_tag_' . $lang['id']] = $row2['products_head_title_tag'];
                $row['v_products_head_desc_tag_' . $lang['id']] = $row2['products_head_desc_tag'];
                $row['v_products_head_keywords_tag_' . $lang['id']] = $row2['products_head_keywords_tag'];
            }
            // 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 = tep_db_query($sql2);
                $row2 = tep_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 = tep_db_query($sql3);
                $row3 = tep_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 = tep_db_query($sql2);
            $row2 = tep_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 = tep_get_tax_class_rate($row['v_tax_class_id']);
        $row['v_tax_class_title'] = tep_get_tax_class_title($row['v_tax_class_id']);
        if ($price_with_tax) {
            $row['v_products_price'] = round($row['v_products_price'] + $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 = tep_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'] . "<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_url[$l_id] = $items[$filelayout['v_products_url_' . $l_id]];
            // support for Linda's Header Controller 2.0 here
            if (isset($filelayout['v_products_head_title_tag_' . $l_id])) {
                $v_products_head_title_tag[$l_id] = $items[$filelayout['v_products_head_title_tag_' . $l_id]];
                $v_products_head_desc_tag[$l_id] = $items[$filelayout['v_products_head_desc_tag_' . $l_id]];
                $v_products_head_keywords_tag[$l_id] = $items[$filelayout['v_products_head_keywords_tag_' . $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 = tep_get_tax_title_class_id($v_tax_class_title);
    }
    //we check the tax rate of this tax_class_id
    $row_tax_multiplier = tep_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 = round($v_products_price / (1 + $row_tax_multiplier * $price_with_tax / 100), 4);
    }
    // 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";
        $v_date_avail = "NULL";
    } else {
        // we put the quotes around it here because we can't put them into the query, because sometimes
        //   we will use the "current_timestamp", which can't have quotes around it.
        $v_date_avail = '"' . $v_date_avail . '"';
    }
    if ($v_date_added == '') {
        $v_date_added = "CURRENT_TIMESTAMP";
    } else {
        // we put the quotes around it here because we can't put them into the query, because sometimes
        //   we will use the "current_timestamp", which can't have quotes around 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 . "'";
        $result = tep_db_query($sql);
        $row = tep_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 = tep_db_query($sql);
            $row = tep_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 = tep_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 . "'";
                $result = tep_db_query($sql);
                $row = tep_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 = tep_db_query($sql);
                    $row = tep_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 = tep_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 = tep_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 = tep_db_query("SELECT products_id FROM " . TABLE_PRODUCTS . " WHERE (products_model = '" . $v_products_model . "')");
        if (tep_db_num_rows($result) == 0) {
            //   insert into products
            $sql = "SHOW TABLE STATUS LIKE '" . TABLE_PRODUCTS . "'";
            $result = tep_db_query($sql);
            $row = tep_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 = tep_db_query($query);
        } else {
            // existing product, get the id from the query
            // and update the product data
            $row = tep_db_fetch_array($result);
            $v_products_id = $row['products_id'];
            echo "<font color='black'> Updated</font><br>";
            $row = tep_db_fetch_array($result);
            $query = '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 = tep_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 = tep_db_query($sql);
                    if (tep_db_num_rows($result) == 0) {
                        // nope, this is a new product description
                        $result = tep_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\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\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_head_title_tag)) {
                            // 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\t\t\t\t\t\t\t\t\tproducts_description,\n\t\t\t\t\t\t\t\t\tproducts_url,\n\t\t\t\t\t\t\t\t\tproducts_head_title_tag,\n\t\t\t\t\t\t\t\t\tproducts_head_desc_tag,\n\t\t\t\t\t\t\t\t\tproducts_head_keywords_tag)\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\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_head_title_tag[$key] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_head_desc_tag[$key] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $v_products_head_keywords_tag[$key] . "')";
                        }
                        // end support for Linda's Header Controller 2.0
                        $result = tep_db_query($sql);
                    } else {
                        // already in the description, let's just update it
                        $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\t\t\t\t\t\t\t\tproducts_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_head_title_tag)) {
                            // override the sql if we're using Linda's contrib
                            $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\t\t\t\t\t\t\t\t\tproducts_url = '" . $v_products_url[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_head_title_tag = '" . $v_products_head_title_tag[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_head_desc_tag = '" . $v_products_head_desc_tag[$key] . "',\n\t\t\t\t\t\t\t\t\tproducts_head_keywords_tag = '" . $v_products_head_keywords_tag[$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 = tep_db_query($sql);
                    }
                }
            }
        }
        if (isset($v_categories_id)) {
            //find out if this product is listed in the category given
            $result_incategory = tep_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 (tep_db_num_rows($result_incategory) == 0) {
                // nope, this is a new category for this product
                $res1 = tep_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 = tep_db_query('
						DELETE
						FROM
							' . TABLE_PRODUCTS_GROUPS . '
						WHERE
							products_id = ' . $v_products_id);
            // and insert the new record
            if ($v_customer_price_1 != '') {
                $result = tep_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 = tep_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 = tep_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 = tep_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 = tep_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} . "'";
                tep_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 = tep_db_query($attribute_options_query);
                // option table update begin
                if ($attribute_rows == 1) {
                    // insert into options table if no option exists
                    if (tep_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 = tep_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 = tep_db_query($attribute_options_update_lang_query);
                                // if option name doesn't exist for particular language, insert value
                                if (tep_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 = tep_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 = tep_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 = tep_db_query($attribute_values_query);
                    // options_values table update begin
                    if ($attribute_rows == 1) {
                        // insert into options_values table if no option exists
                        if (tep_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 = tep_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 = tep_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 = tep_db_query($attribute_values_update_lang_query);
                                    // if options_values name doesn't exist for particular language, insert value
                                    if (tep_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 = tep_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 = '" . ${$v_attribute_values_name_var} . "' where products_options_values_id ='" . (int) ${$v_attribute_values_id_var} . "' and language_id = '" . (int) $lid . "'";
                                        $attribute_values_update = tep_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} . "'";
                        $attribute_prices_values = tep_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 (tep_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} . "', '" . (double) ${$v_attribute_values_price_var} . "', '" . $attribute_values_price_prefix . "')";
                            $attribute_prices_insert = tep_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 . "' 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 = tep_db_query($attribute_prices_update_query);
                        }
                    }
                    // options_values price update end
                    //////// attributes stock add start
                    $v_attribute_values_stock_var = 'v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count;
                    if (isset(${$v_attribute_values_stock_var}) && ${$v_attribute_values_stock_var} != '') {
                        $stock_attributes = ${$v_attribute_options_id_var} . '-' . ${$v_attribute_values_id_var};
                        $attribute_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int) $v_products_id . "' and products_stock_attributes ='" . $stock_attributes . "'");
                        // insert into products_stock_quantity table if no stock exists
                        if (tep_db_num_rows($attribute_stock_query) <= 0) {
                            $attribute_stock_insert_query = tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . (int) $v_products_id . "', '" . $stock_attributes . "', '" . (int) ${$v_attribute_values_stock_var} . "')");
                        } else {
                            // update options table, if options already exists
                            $attribute_stock_insert_query = tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . (int) ${$v_attribute_values_stock_var} . "' where products_id = '" . (int) $v_products_id . "' and products_stock_attributes = '" . $stock_attributes . "'");
                            // turn on stock tracking on products_options table
                            $stock_tracking_query = tep_db_query("update " . TABLE_PRODUCTS_OPTIONS . " set products_options_track_stock = '1' where products_options_id = '" . (int) ${$v_attribute_options_id_var} . "'");
                        }
                    }
                    //////// attributes stock add 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 "<br>";
    }
    // end of row insertion code
}
示例#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 = tep_db_query($sql);
        $row = tep_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 (tep_db_num_rows(tep_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>Product Extra Fields 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>Product Extra Fields Inserted</font></b><br />";
        }
        $result = tep_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 = tep_db_query($sql);
        $row = tep_db_fetch_array($result);
        if (tep_db_num_rows($result) == 1) {
            tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'");
            $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'");
            $product_categories = tep_db_fetch_array($product_categories_query);
            if ($product_categories['total'] == '0') {
                // gather product attribute data
                $result = tep_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 = tep_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 = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " where options_values_id = '" . (int) $ravalue['products_options_values_id'] . "'");
                    $product_attribs = tep_db_fetch_array($product_attribs_query);
                    // if no other products linked, remove attribute name
                    if ((int) $product_attribs['total'] == 1) {
                        tep_db_query("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int) $ravalue['products_options_values_id'] . "'");
                    }
                }
                // remove attribute records
                tep_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $row['v_products_id'] . "'");
                // remove product
                tep_remove_product($row['v_products_id']);
            }
            if (USE_CACHE == 'true') {
                tep_reset_cache_block('categories');
                tep_reset_cache_block('also_purchased');
            }
            echo "Deleted product " . $items[$filelayout['v_products_model']] . " from the database<br />";
        } else {
            echo "Did not delete " . $items['v_products_model'] . " since it is not unique<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_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 = tep_db_query($sql);
        $row = tep_db_fetch_array($result);
        // determine processing status based on dropdown choice on EP menu
        if (sizeof($row) > 1 && ($_POST['imput_mode'] == "normal" || $_POST['imput_mode'] == "update")) {
            $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 = tep_db_query($sql2);
                    $row2 = tep_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_head_title_tag_' . $lang['id']])) {
                        $row['v_products_head_title_tag_' . $lang['id']] = $row2['products_head_title_tag'];
                        $row['v_products_head_desc_tag_' . $lang['id']] = $row2['products_head_desc_tag'];
                        $row['v_products_head_keywords_tag_' . $lang['id']] = $row2['products_head_keywords_tag'];
                    }
                    // 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 = tep_db_query($sql3);
                        if ($row3 = tep_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 = tep_db_query($sql2);
                            if ($row2 = tep_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\n                        manufacturers_id = " . $row['v_manufacturers_id'];
                    $result2 = tep_db_query($sql2);
                    $row2 = tep_db_fetch_array($result2);
                    $row['v_manufacturers_name'] = $row2['manufacturers_name'];
                }
                if (EP_MVS_SUPPORT == true) {
                    $result2 = tep_db_query("select vendors_name from " . TABLE_VENDORS . " WHERE vendors_id = " . $row['v_vendor_id']);
                    $row2 = tep_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 = tep_get_tax_class_rate($row['v_tax_class_id']);
                $row['v_tax_class_title'] = tep_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 = tep_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 = tep_get_tax_title_class_id($v_tax_class_title);
            }
            //we check the tax rate of this tax_class_id
            $row_tax_multiplier = tep_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;
            }
            if (strlen($v_products_model) > EP_MODEL_NUMBER_SIZE) {
                echo "<font color='red'>" . strlen($v_products_model) . $v_products_model . "... ERROR! - Too many characters in the model number.<br />\n                    12 is the maximum on a standard OSC install.<br />\n                    Your maximum product_model length is set to " . EP_MODEL_NUMBER_SIZE . ".<br />\n                    You can either shorten your model numbers or increase the size of the<br />\n                    \"products_model\" field of the \"products\" table in the database.<br />\n                    Then change the setting at the top of the easypopulate.php file.</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                    FROM " . TABLE_MANUFACTURERS . " as man\n                    WHERE\n                        man.manufacturers_name = '" . tep_db_input($v_manufacturers_name) . "'";
                $result = tep_db_query($sql);
                $row = tep_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 = tep_db_query($sql);
                    $row = tep_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',
                        '".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                        '" . tep_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 = tep_db_query($sql);
                    $v_manufacturer_id = $max_mfg_id;
                    $sql = "INSERT INTO " . TABLE_MANUFACTURERS_INFO . "(\n                        manufacturers_id,\n                        manufacturers_url,\n                        languages_id\n                        ) VALUES (\n                        {$max_mfg_id},\n                        '',\n                        '" . EP_DEFAULT_LANGUAGE_ID . "'\n                        )";
                    $result = tep_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 '" . tep_db_input($thiscategoryname) . "'";
                        $result = tep_db_query($sql);
                        $row = tep_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='" . tep_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";
                            tep_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 = tep_db_query($sql);
                            $row = tep_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                                        '" . tep_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 = tep_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']]) ? tep_db_input($v_categories_name[$categorylevel][$lang['id']]) : '') . "'\n                                       )";
                                tep_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 = tep_db_query("SELECT vendors_id FROM " . TABLE_VENDORS . " WHERE vendors_name = '" . $v_vendor . "'");
                    $vend_row = tep_db_fetch_array($vend_result);
                    $v_vendor_id = $vend_row['vendors_id'];
                }
                // process the PRODUCTS table
                $result = tep_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 (tep_db_num_rows($result) == 0) {
                    //   insert into products
                    echo "<font color='green'> !New Product!</font><br />";
                    // /////////////////////////////////////////////////////////////////////
                    //
                    // 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 .= "'" . tep_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_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 = tep_db_query($query);
                    $v_products_id = tep_db_insert_id();
                } else {
                    // existing product(s), get the id from the query
                    // and update the product data
                    while ($row = tep_db_fetch_array($result)) {
                        $v_products_id = $row['products_id'];
                        echo "<font color='black'> Updated</font><br />";
                        // /////////////////////////////////////////////////////////////////////
                        //
                        // 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='" . tep_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_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";
                        tep_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 = tep_db_query('select * from ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . $SPPC_extra_query);
                    if ($v_products_specials_price == '') {
                        $result = tep_db_query('DELETE FROM ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . $SPPC_extra_query);
                        if (EP_SPPC_SUPPORT == true) {
                            $result = tep_db_query('DELETE FROM specials_retail_prices WHERE products_id = ' . $v_products_id);
                        }
                    } else {
                        if ($specials = tep_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()');
                            tep_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);
                                tep_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'));
                            }
                            tep_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');
                                tep_db_perform('specials_retail_prices', $sql_data_array, 'insert');
                            }
                        }
                    }
                }
                if (EP_ADDITIONAL_IMAGES == true) {
                    if (isset($filelayout['v_products_image_2'])) {
                        tep_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})) {
                                tep_db_query("insert into " . TABLE_ADDITIONAL_IMAGES . " (products_id, images_description, thumb_images) values ('" . (int) $v_products_id . "', '" . tep_db_input(${$ai_description_var}) . "', '" . tep_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_head_title_tag_' . $lang['id']]) || $doit == true) {
                        $sql = "SELECT * FROM " . TABLE_PRODUCTS_DESCRIPTION . " WHERE\n                                products_id = {$v_products_id} AND\n                                language_id = " . $lang['id'];
                        $result = tep_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 . " = '" . tep_db_input(${$tmp_var}) . "',";
                            $ep_additional_fields .= $key . ",";
                            $ep_additional_data .= "'" . tep_db_input(${$tmp_var}) . "',";
                        }
                        // header tags controller support
                        if (isset($filelayout['v_products_head_title_tag_' . $lang['id']])) {
                            $head_title_tag_var = 'v_products_head_title_tag_' . $lang['id'];
                            $head_desc_tag_var = 'v_products_head_desc_tag_' . $lang['id'];
                            $head_keywords_tag_var = 'v_products_head_keywords_tag_' . $lang['id'];
                            $ep_additional_updates .= "products_head_title_tag = '" . tep_db_input(${$head_title_tag_var}) . "', products_head_desc_tag = '" . tep_db_input(${$head_desc_tag_var}) . "', products_head_keywords_tag = '" . tep_db_input(${$head_keywords_tag_var}) . "',";
                            $ep_additional_fields .= "products_head_title_tag,products_head_desc_tag,products_head_keywords_tag,";
                            $ep_additional_data .= "'" . tep_db_input(${$head_title_tag_var}) . "','" . tep_db_input(${$head_desc_tag_var}) . "','" . tep_db_input(${$head_keywords_tag_var}) . "',";
                        }
                        // end: header tags controller support
                        // /////////////////////////////////////////////////////////////////////
                        // End: Support for other contributions
                        // /////////////////////////////////////////////////////////////////////
                        // existing product?
                        if (tep_db_num_rows($result) > 0) {
                            // already in the description, let's just update it
                            $sql = "UPDATE " . TABLE_PRODUCTS_DESCRIPTION . " \n                                 SET\n                                    products_name='" . tep_db_input(${$products_var}) . "',\n                                    products_description='" . tep_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 = tep_db_query($sql);
                        } else {
                            // nope, this is a new product description
                            $result = tep_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                                        '" . tep_db_input(${$products_var}) . "',\n                                        '" . tep_db_input(${$description_var}) . "',\n                                        {$ep_additional_data}\n                                        '" . ${$url_var} . "'\n                                        )";
                            $result = tep_db_query($sql);
                        }
                    }
                }
                if (isset($v_categories_id)) {
                    //find out if this product is listed in the category given
                    $result_incategory = tep_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 (tep_db_num_rows($result_incategory) == 0) {
                        // nope, this is a new category for this product
                        $res1 = tep_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)) {
                    tep_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 = tep_db_query($cross_sell_sql);
                            $cross_sell_row = tep_db_fetch_array($cross_sell_result);
                            tep_db_query("insert into " . TABLE_PRODUCTS_XSELL . " (products_id, xsell_id, sort_order) \n                                      values ( " . $v_products_id . ", " . $cross_sell_row['products_id'] . ", 1)");
                            tep_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 = tep_db_query('
                                DELETE
                                FROM
                                    ' . TABLE_PRODUCTS_GROUPS . '
                                WHERE
                                    products_id = ' . $v_products_id);
                    // and insert the new record
                    if ($v_customer_price_1 != '') {
                        $result = tep_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_1 . ',
                                        ' . $v_customer_price_1 . ',
                                        ' . $v_products_id . ',
					' . $v_products_price . ',
					' . $v_products_qty_blocks . ',
					' . $v_products_min_order_qty . '
                                        )');
                    }
                    if ($v_customer_price_2 != '') {
                        $result = tep_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_2 . ',
                                        ' . $v_customer_price_2 . ',
                                        ' . $v_products_id . ',
					' . $v_products_price . ',
					' . $v_products_qty_blocks . ',
					' . $v_products_min_order_qty . '
                                        )');
                    }
                    if ($v_customer_price_3 != '') {
                        $result = tep_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_3 . ',
                                        ' . $v_customer_price_3 . ',
                                        ' . $v_products_id . ',
					' . $v_products_price . ',
					' . $v_products_qty_blocks . ',
					' . $v_products_min_order_qty . '
                                        )');
                    }
                    if ($v_customer_price_4 != '') {
                        $result = tep_db_query('
                                    INSERT INTO
                                        ' . TABLE_PRODUCTS_GROUPS . '
                                    VALUES
                                    (
                                        ' . $v_customer_group_id_4 . ',
                                        ' . $v_customer_price_4 . ',
                                        ' . $v_products_id . ',
					' . $v_products_price . ',
					' . $v_products_qty_blocks . ',
					' . $v_products_min_order_qty . '
                                        )');
                    }
                    if (isset($v_customer_specials_price_1)) {
                        $result = tep_db_query('select * from ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . ' and customers_group_id = 1');
                        if ($v_customer_specials_price_1 == '') {
                            $result = tep_db_query('DELETE FROM ' . TABLE_SPECIALS . ' WHERE products_id = ' . $v_products_id . ' and customers_group_id = 1');
                        } else {
                            if ($specials = tep_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()');
                                tep_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');
                                tep_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} . "'";
                        tep_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 = tep_db_query($attribute_options_query);
                        // option table update begin
                        if ($attribute_rows == 1) {
                            // insert into options table if no option exists
                            if (tep_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 = tep_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 = tep_db_query($attribute_options_update_lang_query);
                                        // if option name doesn't exist for particular language, insert value
                                        if (tep_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 = tep_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 = tep_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 = tep_db_query($attribute_values_query);
                            // options_values table update begin
                            if ($attribute_rows == 1) {
                                // insert into options_values table if no option exists
                                if (tep_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 . "', '" . tep_db_input(${$v_attribute_values_name_var}) . "')";
                                            $attribute_values_insert = tep_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 = tep_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 = tep_db_query($attribute_values_update_lang_query);
                                            // if options_values name doesn't exist for particular language, insert value
                                            if (tep_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 . "', '" . tep_db_input(${$v_attribute_values_name_var}) . "')";
                                                $attribute_values_lang_insert = tep_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 = '" . tep_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 = tep_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} . "'";
                                $attribute_prices_values = tep_db_query($attribute_prices_query);
                                $attribute_values_price_prefix = ${$v_attribute_values_price_var} < 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 (tep_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} . "', '" . (double) ${$v_attribute_values_price_var} . "', '" . $attribute_values_price_prefix . "')";
                                    $attribute_prices_insert = tep_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 . "' 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 = tep_db_query($attribute_prices_update_query);
                                }
                            }
                            // options_values price update end
                            //////// attributes stock add start
                            $v_attribute_values_stock_var = 'v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count;
                            if (isset(${$v_attribute_values_stock_var}) && ${$v_attribute_values_stock_var} != '') {
                                $stock_attributes = ${$v_attribute_options_id_var} . '-' . ${$v_attribute_values_id_var};
                                $attribute_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int) $v_products_id . "' and products_stock_attributes ='" . $stock_attributes . "'");
                                // insert into products_stock_quantity table if no stock exists
                                if (tep_db_num_rows($attribute_stock_query) <= 0) {
                                    $attribute_stock_insert_query = tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . (int) $v_products_id . "', '" . $stock_attributes . "', '" . (int) ${$v_attribute_values_stock_var} . "')");
                                } else {
                                    // update options table, if options already exists
                                    $attribute_stock_insert_query = tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . (int) ${$v_attribute_values_stock_var} . "' where products_id = '" . (int) $v_products_id . "' and products_stock_attributes = '" . $stock_attributes . "'");
                                    // turn on stock tracking on products_options table
                                    $stock_tracking_query = tep_db_query("update " . TABLE_PRODUCTS_OPTIONS . " set products_options_track_stock = '1' where products_options_id = '" . (int) ${$v_attribute_options_id_var} . "'");
                                }
                            }
                            //////// attributes stock add 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
                echo "<p class=smallText>No products_model field in record. This line was not imported: ";
                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) ============
}