Ejemplo n.º 1
0
function tep_remove_product($product_id)
{
    $product_image_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int) $product_id . "'");
    $product_image = tep_db_fetch_array($product_image_query);
    $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_image = '" . tep_db_input($product_image['products_image']) . "'");
    $duplicate_image = tep_db_fetch_array($duplicate_image_query);
    if ($duplicate_image['total'] < 2) {
        if (file_exists(DIR_FS_CATALOG_IMAGES . $product_image['products_image'])) {
            @unlink(DIR_FS_CATALOG_IMAGES . $product_image['products_image']);
        }
    }
    $product_images_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int) $product_id . "'");
    if (tep_db_num_rows($product_images_query)) {
        while ($product_images = tep_db_fetch_array($product_images_query)) {
            $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_IMAGES . " where image = '" . tep_db_input($product_images['image']) . "'");
            $duplicate_image = tep_db_fetch_array($duplicate_image_query);
            if ($duplicate_image['total'] < 2) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $product_images['image'])) {
                    @unlink(DIR_FS_CATALOG_IMAGES . $product_images['image']);
                }
            }
        }
        tep_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int) $product_id . "'");
    }
    tep_db_query("delete from " . TABLE_SPECIALS . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where products_id = '" . (int) $product_id . "' or products_id like '" . (int) $product_id . "{%'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where products_id = '" . (int) $product_id . "' or products_id like '" . (int) $product_id . "{%'");
    $product_reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where products_id = '" . (int) $product_id . "'");
    while ($product_reviews = tep_db_fetch_array($product_reviews_query)) {
        tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int) $product_reviews['reviews_id'] . "'");
    }
    tep_db_query("delete from " . TABLE_REVIEWS . " where products_id = '" . (int) $product_id . "'");
    if (USE_CACHE == 'true') {
        tep_reset_cache_block('categories');
        tep_reset_cache_block('also_purchased');
    }
}
Ejemplo n.º 2
0
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/
require 'includes/application_top.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';
if (tep_not_null($action)) {
    if ($action == 'reset') {
        tep_reset_cache_block($_GET['block']);
    }
    tep_redirect(tep_href_link(FILENAME_CACHE));
}
// check if the cache directory exists
if (is_dir(DIR_FS_CACHE)) {
    if (!tep_is_writable(DIR_FS_CACHE)) {
        $messageStack->add(ERROR_CACHE_DIRECTORY_NOT_WRITEABLE, 'error');
    }
} else {
    $messageStack->add(ERROR_CACHE_DIRECTORY_DOES_NOT_EXIST, 'error');
}
require DIR_WS_INCLUDES . 'template_top.php';
?>

    <table border="0" width="100%" cellspacing="0" cellpadding="2">
Ejemplo n.º 3
0
                if (file_exists($image_location)) {
                    @unlink($image_location);
                }
            }
            tep_db_query("delete from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int) $manufacturers_id . "'");
            tep_db_query("delete from " . TABLE_MANUFACTURERS_INFO . " where manufacturers_id = '" . (int) $manufacturers_id . "'");
            if (isset($HTTP_POST_VARS['delete_products']) && $HTTP_POST_VARS['delete_products'] == 'on') {
                $products_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " where manufacturers_id = '" . (int) $manufacturers_id . "'");
                while ($products = tep_db_fetch_array($products_query)) {
                    tep_remove_product($products['products_id']);
                }
            } else {
                tep_db_query("update " . TABLE_PRODUCTS . " set manufacturers_id = '' where manufacturers_id = '" . (int) $manufacturers_id . "'");
            }
            if (USE_CACHE == 'true') {
                tep_reset_cache_block('manufacturers');
            }
            tep_redirect(tep_href_link(FILENAME_MANUFACTURERS, 'page=' . $HTTP_GET_VARS['page']));
            break;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html <?php 
echo HTML_PARAMS;
?>
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php 
echo CHARSET;
?>
Ejemplo n.º 4
0
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/
require 'includes/application_top.php';
$action = isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '';
if (tep_not_null($action)) {
    if ($action == 'reset') {
        tep_reset_cache_block($HTTP_GET_VARS['block']);
    }
    tep_redirect(tep_href_link('cache.php'));
}
// check if the cache directory exists
if (is_dir(DIR_FS_CACHE)) {
    if (!tep_is_writable(DIR_FS_CACHE)) {
        $messageStack->add(ERROR_CACHE_DIRECTORY_NOT_WRITEABLE, 'error');
    }
} else {
    $messageStack->add(ERROR_CACHE_DIRECTORY_DOES_NOT_EXIST, 'error');
}
require 'includes/template_top.php';
?>

    <table border="0" width="100%" cellspacing="0" cellpadding="2">
Ejemplo n.º 5
0
                 }
             } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
                 $product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id from " . TABLE_PRODUCTS . " where products_id = '" . (int) $products_id . "'");
                 $product = tep_db_fetch_array($product_query);
                 tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int) $product['products_tax_class_id'] . "', '" . (int) $product['manufacturers_id'] . "')");
                 $dup_products_id = tep_db_insert_id();
                 $description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int) $products_id . "'");
                 while ($description = tep_db_fetch_array($description_query)) {
                     tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int) $dup_products_id . "', '" . (int) $description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')");
                 }
                 tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int) $dup_products_id . "', '" . (int) $categories_id . "')");
                 $products_id = $dup_products_id;
             }
             if (USE_CACHE == 'true') {
                 tep_reset_cache_block('categories');
                 tep_reset_cache_block('also_purchased');
             }
         }
         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id));
         break;
     case 'new_product_preview':
         // copy image only if modified
         $products_image = new upload('products_image');
         $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
         if ($products_image->parse() && $products_image->save()) {
             $products_image_name = $products_image->filename;
         } else {
             $products_image_name = isset($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : '';
         }
         break;
 }
Ejemplo n.º 6
0
function tep_remove_product($product_id)
{
    $product_image_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int) $product_id . "'");
    $product_image = tep_db_fetch_array($product_image_query);
    $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_image = '" . tep_db_input($product_image['products_image']) . "'");
    $duplicate_image = tep_db_fetch_array($duplicate_image_query);
    if ($duplicate_image['total'] < 2) {
        if (file_exists(DIR_FS_CATALOG_IMAGES . $product_image['products_image'])) {
            @unlink(DIR_FS_CATALOG_IMAGES . $product_image['products_image']);
        }
    }
    tep_db_query("delete from " . TABLE_SPECIALS . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS . " where master_products_id = '" . (int) $product_id . "'");
    // BOF Separate Pricing per Customer
    tep_db_query("delete from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int) $product_id . "'");
    // EOF Separate Pricing per Customer
    tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where products_id = '" . (int) $product_id . "'");
    //Wishlist addition to delete products from the wishlist when deleted
    tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . (int) $product_id . "'");
    $product_reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where products_id = '" . (int) $product_id . "'");
    while ($product_reviews = tep_db_fetch_array($product_reviews_query)) {
        tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int) $product_reviews['reviews_id'] . "'");
    }
    tep_db_query("delete from " . TABLE_REVIEWS . " where products_id = '" . (int) $product_id . "'");
    if (USE_CACHE == 'true') {
        tep_reset_cache_block('categories');
        tep_reset_cache_block('also_purchased');
    }
}
Ejemplo n.º 7
0
function tep_remove_product($product_id)
{
    $product_image_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int) $product_id . "'");
    $product_image = tep_db_fetch_array($product_image_query);
    $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_image = '" . tep_db_input($product_image['products_image']) . "'");
    $duplicate_image = tep_db_fetch_array($duplicate_image_query);
    if ($duplicate_image['total'] < 2) {
        if (file_exists(DIR_FS_CATALOG_IMAGES . CATEGORY_IMAGES_DIR . $category_image['categories_image'])) {
            @unlink(DIR_FS_CATALOG_IMAGES . CATEGORY_IMAGES_DIR . $category_image['categories_image']);
        }
    }
    tep_db_query("delete from " . TABLE_SPECIALS . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS . " where products_id = '" . (int) $product_id . "'");
    // LINE ADDED: MOD - Separate Price per Customer
    tep_db_query("delete from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int) $product_id . "'");
    // BOF QPBPP for SPPC
    tep_db_query("delete from " . TABLE_PRODUCTS_PRICE_BREAK . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . " where products_id = '" . (int) $product_id . "'");
    // EOF QPBPP for SPPC
    tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where products_id = '" . (int) $product_id . "' or products_id like '" . (int) $product_id . "{%'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where products_id = '" . (int) $product_id . "' or products_id like '" . (int) $product_id . "{%'");
    // BOF: MOD - Wishlist addition to delete products from the wishlist when deleted
    tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . (int) $product_id . "'");
    tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . (int) $product_id . "'");
    // EOF: MOD - Wishlist addition to delete products from the wishlist when deleted
    $product_reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where products_id = '" . (int) $product_id . "'");
    while ($product_reviews = tep_db_fetch_array($product_reviews_query)) {
        tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int) $product_reviews['reviews_id'] . "'");
    }
    tep_db_query("delete from " . TABLE_REVIEWS . " where products_id = '" . (int) $product_id . "'");
    if (USE_CACHE == 'true') {
        tep_reset_cache_block('categories');
        tep_reset_cache_block('also_purchased');
    }
    //++++ QT Pro: Begin Changed code
    qtpro_doctor_amputate_all_from_product($product_id);
    //++++ QT Pro: End Changed code
}
Ejemplo n.º 8
0
function tep_remove_article($article_id)
{
    tep_db_query("delete from " . TABLE_ARTICLES . " where articles_id = '" . (int) $article_id . "'");
    tep_db_query("delete from " . TABLE_ARTICLES_TO_TOPICS . " where articles_id = '" . (int) $article_id . "'");
    tep_db_query("delete from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int) $article_id . "'");
    $article_reviews_query = tep_db_query("select reviews_id from " . TABLE_ARTICLE_REVIEWS . " where articles_id = '" . (int) $article_id . "'");
    while ($article_reviews = tep_db_fetch_array($article_reviews_query)) {
        tep_db_query("delete from " . TABLE_ARTICLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int) $article_reviews['reviews_id'] . "'");
    }
    tep_db_query("delete from " . TABLE_ARTICLE_REVIEWS . " where articles_id = '" . (int) $article_id . "'");
    if (USE_CACHE == 'true') {
        tep_reset_cache_block('topics');
        tep_reset_cache_block('also_purchased');
    }
}
Ejemplo n.º 9
0
         $news_id = tep_db_prepare_input($HTTP_GET_VARS['nID']);
     }
     $sql_data_array = array('news_title' => tep_db_prepare_input($HTTP_POST_VARS['news_title']), 'news_content' => tep_db_prepare_input($HTTP_POST_VARS['news_content']), 'news_status' => tep_db_prepare_input($HTTP_POST_VARS['news_status']), 'source' => tep_db_prepare_input($HTTP_POST_VARS['source']), 'sort_order' => tep_db_prepare_input($HTTP_POST_VARS['sort_order']), 'news_categories_id' => (int) $current_news_categories_id, 'news_categories_path' => tep_get_news_categories_path_toinsert($current_news_categories_id));
     if (isset($HTTP_POST_VARS['icon']) && tep_not_null($HTTP_POST_VARS['icon']) && $HTTP_POST_VARS['icon'] != 'none') {
         $sql_data_array['icon'] = tep_db_prepare_input($HTTP_POST_VARS['icon']);
     }
     if ($action == 'insert_news') {
         $insert_sql_data = array('date_added' => 'now()');
         $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
         tep_db_perform(TABLE_NEWS, $sql_data_array);
         $news_id = tep_db_insert_id();
     } elseif ($action == 'update_news') {
         tep_db_perform(TABLE_NEWS, $sql_data_array, 'update', "news_id = '" . (int) $news_id . "'");
     }
     if (USE_CACHE == 'true') {
         tep_reset_cache_block('news');
     }
     tep_redirect(tep_href_link(FILENAME_NEWS, 'cPath=' . $cPath . '&nID=' . $news_id));
 }
 break;
 //      case 'copy_to_confirm':
 //        if (isset($HTTP_POST_VARS['news_id']) && isset($HTTP_POST_VARS['news_id'])) {
 //          $news_id = tep_db_prepare_input($HTTP_POST_VARS['news_id']);
 //          $news_id = tep_db_prepare_input($HTTP_POST_VARS['news_id']);
 //
 //          if ($HTTP_POST_VARS['copy_as'] == 'link') {
 //            if ($news_id != $current_news_id) {
 //              $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_news . " where news_id = '" . (int)$news_id . "' and news_id = '" . (int)$news_id . "'");
 //              $check = tep_db_fetch_array($check_query);
 //              if ($check['total'] < '1') {
 //                tep_db_query("insert into " . TABLE_PRODUCTS_TO_news . " (news_id, news_id) values ('" . (int)$news_id . "', '" . (int)$news_id . "')");
Ejemplo n.º 10
0
                if (USE_CACHE == 'true') {
                    tep_reset_cache_block('pages');
                }
                tep_redirect(tep_href_link(FILENAME_PAGES, 'pID=' . $pages_id));
            }
            break;
        case 'delete_page_confirm':
            if (isset($_POST['pages_id'])) {
                $pages_id = tep_db_prepare_input($_POST['pages_id']);
                if ($pages_id != 1 && $pages_id != 2) {
                    tep_db_query("delete from " . TABLE_PAGES . " where pages_id = '" . (int) $pages_id . "'");
                    tep_db_query("delete from " . TABLE_PAGES_DESCRIPTION . " where pages_id = '" . (int) $pages_id . "'");
                }
            }
            if (USE_CACHE == 'true') {
                tep_reset_cache_block('pages');
            }
            tep_redirect(tep_href_link(FILENAME_PAGES));
            break;
        case 'new_page_preview':
            $pages_image = new upload('pages_image');
            $pages_image->set_destination(DIR_FS_CATALOG_IMAGES);
            if ($pages_image->parse() && $pages_image->save()) {
                $pages_image_name = $pages_image->filename;
            } else {
                $pages_image_name = isset($_POST['pages_previous_image']) ? $_POST['pages_previous_image'] : '';
            }
            break;
    }
}
// check if the catalog image directory exists
Ejemplo n.º 11
0
            $properties = tep_get_properties($selectors_id);
            for ($i = 0, $n = sizeof($properties); $i < $n; $i++) {
                $property_element_array = $HTTP_POST_VARS['property_element'];
                $property_value_array = $HTTP_POST_VARS['property_value'];
                $property_id = $properties[$i]['properties_id'];
                $sql_data_array = array('property_element' => tep_db_prepare_input($property_element_array[$property_id]), 'property_value' => tep_db_prepare_input($property_value_array[$property_id]));
                tep_db_perform(TABLE_BTS_CSS_PROPERTIES, $sql_data_array, 'update', "properties_id = '" . (int) $property_id . "' and selectors_id = '" . (int) $selectors_id . "'");
            }
            tep_redirect(tep_href_link(FILENAME_BTS_CSS, (isset($HTTP_GET_VARS['page']) ? 'page=' . $HTTP_GET_VARS['page'] . '&' : '') . 'selID=' . $selectors_id));
            break;
        case 'deleteconfirm':
            $selectors_id = tep_db_prepare_input($HTTP_GET_VARS['selID']);
            tep_db_query("delete from " . TABLE_BTS_CSS_SELECTORS . " where selectors_id = '" . (int) $selectors_id . "'");
            tep_db_query("delete from " . TABLE_BTS_CSS_PROPERTIES . " where selectors_id = '" . (int) $selectors_id . "'");
            if (USE_CACHE == 'true') {
                tep_reset_cache_block('css');
            }
            tep_redirect(tep_href_link(FILENAME_BTS_CSS, 'page=' . $HTTP_GET_VARS['page']));
            break;
    }
}
require DIR_WS_INCLUDES . 'bootstrap_top.php';
?>

    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php 
echo HEADING_TITLE;
?>
Ejemplo n.º 12
0
            tep_redirect(tep_href_link(FILENAME_AUTHORS, (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . 'auID=' . $authors_id));
            break;
        case 'deleteconfirm':
            $authors_id = tep_db_prepare_input($_GET['auID']);
            tep_db_query("delete from " . TABLE_AUTHORS . " where authors_id = '" . (int) $authors_id . "'");
            tep_db_query("delete from " . TABLE_AUTHORS_INFO . " where authors_id = '" . (int) $authors_id . "'");
            if (isset($_POST['delete_articles']) && $_POST['delete_articles'] == 'on') {
                $articles_query = tep_db_query("select articles_id from " . TABLE_ARTICLES . " where authors_id = '" . (int) $authors_id . "'");
                while ($articles = tep_db_fetch_array($articles_query)) {
                    tep_remove_article($articles['articles_id']);
                }
            } else {
                tep_db_query("update " . TABLE_ARTICLES . " set authors_id = '' where authors_id = '" . (int) $authors_id . "'");
            }
            if (USE_CACHE == 'true') {
                tep_reset_cache_block('authors');
            }
            tep_redirect(tep_href_link(FILENAME_AUTHORS, 'page=' . $_GET['page']));
            break;
    }
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php 
echo HTML_PARAMS;
?>
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php 
echo CHARSET;
?>
    echo ($form_action == 'insert' ? tep_image_submit('button_save.gif', IMAGE_SAVE) : tep_image_submit('button_update.gif', IMAGE_UPDATE)) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_MM_RESPONSEMAIL, (isset($HTTP_GET_VARS['page']) ? 'page=' . $HTTP_GET_VARS['page'] . '&' : '') . (isset($HTTP_GET_VARS['nID']) ? 'nID=' . $HTTP_GET_VARS['nID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
    ?>
            		</td>
          		</tr>
        	</table>
        </td>
      	</form>
      </tr>
<?php 
} elseif ($action == 'setflag') {
    if ($HTTP_GET_VARS['flag'] == '0' || $HTTP_GET_VARS['flag'] == '1') {
        if (isset($HTTP_GET_VARS['nID'])) {
            tep_mm_set_mailstatus($HTTP_GET_VARS['nID'], $HTTP_GET_VARS['flag']);
        }
        if (USE_CACHE == 'true') {
            tep_reset_cache_block('topics');
        }
    }
    if ($HTTP_GET_VARS['flag'] == '1') {
        $newstatus = 'Active';
    } else {
        $newstatus = 'Inactive';
    }
    echo '<tr><td class="main">Status changed to: <strong>' . $newstatus . '</strong><a href="' . tep_href_link(FILENAME_MM_RESPONSEMAIL, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID']) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a></td></tr>';
} elseif ($action == 'preview') {
    $nID = tep_db_prepare_input($HTTP_GET_VARS['nID']);
    $mail_query = tep_db_query("select title, htmlcontent, txtcontent, template from " . TABLE_MM_RESPONSEMAIL . " where mail_id = '" . (int) $nID . "'");
    $mail = tep_db_fetch_array($mail_query);
    $template_name = $mail['template'];
    $template_query = tep_db_query("select title, htmlheader, htmlfooter, txtheader, txtfooter from " . TABLE_MM_TEMPLATES . " where title = '" . $template_name . "'");
    $template = tep_db_fetch_array($template_query);
Ejemplo n.º 14
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) ============
}