[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> easypopulate.php (source)

   1  <?php
   2  /*
   3    $Id: easypopulate.php,v 2.76g 2007/01/20 22:50:52 surfalot Exp $
   4  
   5    Designed for osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2007 Todd Holforty mtholforty(at)surfalot(dot)com 
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13  // Current EP Version
  14  define ('EP_CURRENT_VERSION', '2.76g-MS2');
  15  
  16  require ('includes/application_top.php');
  17  require_once ('includes/database_tables.php');
  18  require ('easypopulate_functions.php');
  19  
  20  $system = tep_get_system_information();
  21  
  22  //
  23  //*******************************
  24  //*******************************
  25  // C O N F I G U R A T I O N
  26  // V A R I A B L E S
  27  //*******************************
  28  //*******************************
  29  
  30  
  31  //////////////////////////////////////////////////////
  32  // *** Show all these settings on EP main page ***
  33  // use this to debug your settings. Copy the settings 
  34  // to your post on the forum if you need help.
  35  //////////////////////////////////////////////////////
  36  define ('EP_SHOW_EP_SETTINGS', true); // default is: false
  37  
  38  
  39  // **** Temp directory **** 
  40  /* ////////////////////////////////////////////////////////////////////////
  41  //
  42  // *IF* you changed your directory structure from stock and do not 
  43  // have /catalog/temp/, then you'll need to change this accordingly.
  44  //
  45  // *IF* your shop is in the default /catalog/ installation directory
  46  // on your website, skip this Temp Directory settings info.
  47  //
  48  ///////////////////////////////////////////////////////////////////////////
  49  
  50     CREATING THE TEMP DIRECTORY
  51  
  52     If your shop is in the root of your public site ( /home/myaccount/public_html/index.php ), 
  53     you should create a folder called temp from the root of your web space so that the
  54     full path looks like this: /home/myaccount/public_html/temp/
  55     
  56     Then you must set the permissions to 777. If you don't know how, ask your host.
  57  
  58  
  59     THE DIR_FS_DOCUMENT_ROOT SETTING
  60  
  61     DIR_FS_DOCUMENT_ROOT is set in your /catalog/admin/includes/configure.php
  62     You should look at the setting DIR_FS_DOCUMENT_ROOT setting.
  63     if it looks like this (recommended, but doesn't always work): 
  64  
  65         define ('DIR_FS_DOCUMENT_ROOT', $DOCUMENT_ROOT);
  66  
  67     then leave it alone. If it looks like this: 
  68  
  69         define ('DIR_FS_DOCUMENT_ROOT', '/home/myaccount/public_html'); 
  70  
  71     ask your host if the "/home/myaccount/public_html" portion points to your public
  72     web space and is correct. Whether you add the trailing slash on the
  73     path or not doesn't matter to this contrib, as long as you make the 
  74     right choice on the following setting. The best thing is to leave it
  75     alone as long as your host can confirm it is correct and everything else
  76     is working fine. Having said that, NO trailing slash is technically correct.
  77  
  78  
  79  
  80     THE DIR_WS_CATALOG & DIR_FS_CATALOG SETTINGS
  81     
  82     DIR_WS_CATALOG & DIR_FS_CATALOG are set in your /catalog/admin/includes/configure.php
  83     They may look like this if your shop is in the root of your web space. 
  84     If you have something different, don't just change it to this. 
  85     There is probably a good reason. I'm providing this as a reference 
  86     to you-all. The DIR_FS_DOCUMENT_ROOT, the DIR_WS_CATALOG, and the 
  87     DIR_FS_CATALOG settings all combine to create the temp location below.
  88     
  89         define('DIR_WS_CATALOG', '/');
  90         define('DIR_FS_CATALOG', DIR_FS_DOCUMENT_ROOT . DIR_WS_CATALOG);
  91  
  92  
  93  
  94     THIS EP_TEMP_DIRECTORY SETTING
  95  
  96     Next, the following setting should set so that the DIR_FS_CATALOG setting
  97     plus this following setting makes a correct full path to your temporary 
  98     location, like this: /home/myaccount/public_html/temp/
  99  
 100     if /home/myaccount/public_html/temp/ is the correct full path to your temp
 101     location, then: 
 102  
 103         define ('EP_TEMP_DIRECTORY', DIR_FS_CATALOG . 'temp/');
 104  
 105     is the correct setting here.  Wow, I really hope this stops the forum traffic about this !!
 106  
 107  ////////////////////////////////////////////////////////////////////////// */
 108  // **** Temp directory **** 
 109  define ('EP_TEMP_DIRECTORY', DIR_FS_CATALOG . 'temp/'); 
 110  
 111  
 112  //**** File Splitting Configuration ****
 113  // we attempt to set the timeout limit longer for this script to avoid having to split the files
 114  // NOTE:  If your server is running in safe mode, this setting cannot override the timeout set in php.ini
 115  // uncomment this if you are not on a safe mode server and you are getting timeouts
 116  // set_time_limit(330);
 117  
 118  // if you are splitting files, this will set the maximum number of records to put in each file.
 119  // if you set your php.ini to a long time, you can make this number bigger
 120  define ('EP_SPLIT_MAX_RECORDS', 300);  // default, seems to work for most people.  Reduce if you hit timeouts
 121  //define ('EP_SPLIT_MAX_RECORDS', 4); // for testing
 122  
 123  
 124  //**** Image Defaulting ****
 125  // set them to your own default "We don't have any picture" gif
 126  //define ('EP_DEFAULT_IMAGE_MANUFACTURER', 'no_image_manufacturer.gif'); 
 127  //define ('EP_DEFAULT_IMAGE_PRODUCT', 'no_image_product.gif'); 
 128  //define ('EP_DEFAULT_IMAGE_CATEGORY', 'no_image_category.gif'); 
 129  
 130  // or let them get set to nothing
 131  define ('EP_DEFAULT_IMAGE_MANUFACTURER', ''); 
 132  define ('EP_DEFAULT_IMAGE_PRODUCT', ''); 
 133  define ('EP_DEFAULT_IMAGE_CATEGORY', ''); 
 134  
 135  
 136  //**** Status Field Setting ****
 137  // Set the v_status field to "Inactive" if you want the status=0 in the system
 138  define ('EP_TEXT_ACTIVE', 'Active'); 
 139  define ('EP_TEXT_INACTIVE', 'Inactive'); 
 140  
 141  // Set the v_status field to "Delete" if you want to remove the item from the system
 142  define ('EP_DELETE_IT', 'Delete');
 143  
 144  
 145  // If zero_qty_inactive is true, then items with zero qty will automatically be inactive in the store.
 146  define ('EP_INACTIVATE_ZERO_QUANTITIES', false);  // default is false
 147  
 148  
 149  //**** Size of products_model in products table ****
 150  // set this to the size of your model number field in the db.  We check to make 
 151  // sure all models are no longer than this value. this prevents the database from 
 152  // getting fubared.  Just making this number bigger won't help your database!  They must match!
 153  // If you increase the Model Number size, you must increase the size of the field
 154  // in the database. Use a SQL tool like phpMyAdmin (see your host) and change the
 155  // "products_model" field of the "products" table in your osCommerce Database.
 156  define ('EP_MODEL_NUMBER_SIZE', 12); // default is 12
 157  
 158  
 159  //**** Price includes tax? ****
 160  // Set the EP_PRICE_WITH_TAX to
 161  // false if you want the price that is exported to be the same value as stored in the database (no tax added).
 162  // true if you want the tax to be added to the export price and subtracted from the import price.
 163  define ('EP_PRICE_WITH_TAX', false);  // default is false
 164  
 165  
 166  //**** Price calculation precision ****
 167  // NOTE: when entering into the database all prices will be converted to 4 decimal places.
 168  define ('EP_PRECISION', 2);  // default is 2
 169  
 170  
 171  // **** Quote -> Escape character conversion ****
 172  // If you have extensive html in your descriptions and it's getting mangled on upload, turn this off
 173  // set to true = replace quotes with escape characters
 174  // set to false = no quote replacement
 175  define ('EP_REPLACE_QUOTES', false);  // default is false
 176  
 177  
 178  // **** Field Separator ****
 179  // change this if you can't use the default of tabs
 180  // Tab is the default, comma and semicolon are commonly supported by various progs
 181  // Remember, if your descriptions contain this character, you will confuse EP!
 182  // if EP_EXCEL_SAFE_OUTPUT if false (below) you must make EP_PRESERVE_TABS_CR_LF false also.
 183  $ep_separator = "\t"; // tab is default
 184  //$ep_separator = ',';  // comma
 185  //$ep_separator = ';';  // semi-colon
 186  //$ep_separator = '~';  // tilde
 187  //$ep_separator = '*';  // splat
 188  
 189  
 190  // *** Excel safe output ***
 191  // this setting will supersede the previous $ep_separator setting and create a file
 192  // that excel will import without spanning cells from embedded commas or tabs in your products.
 193  // if EP_EXCEL_SAFE_OUTPUT if false (below) you must make EP_PRESERVE_TABS_CR_LF false also.
 194  define ('EP_EXCEL_SAFE_OUTPUT', true); // default is: true
 195  
 196  if (EP_EXCEL_SAFE_OUTPUT == true) { 
 197    if ($language == 'english') { 
 198      $ep_separator = ',';  // comma
 199    } elseif ($language == 'german') {
 200      $ep_separator = ';';  // semi-colon
 201    } else {
 202      $ep_separator = ',';  // comma  // default for all others.
 203    }
 204  }
 205  
 206  // if EP_EXCEL_SAFE_OUTPUT if true (above) there is an alternative line parsing routine
 207  //  provided by Maynard that will use a manual php approach.  There is a bug in some
 208  // PHP versions that may require you to use this routine.  This should also provide proper
 209  // parsing when quotes are used within a string. I suspect this should also resolve an issue
 210  // recently reported in which characters with a german "Umlaute" like  at the Beginning 
 211  // of some text, they will disappear when importing some csv-file, reported by TurboTB.
 212  define ('EP_EXCEL_SAFE_OUTPUT_ALT_PARCE', false); // default is: false
 213  
 214  
 215  // *** Preserve Tabs, Carriage returns and Line feeds ***
 216  // this setting will preserve the special chars that can cause problems in 
 217  // a text based output. When used with EP_EXCEL_SAFE_OUTPUT, it will safely
 218  // preserve these elements in the export and import.
 219  define ('EP_PRESERVE_TABS_CR_LF', false); // default is: false
 220  
 221  
 222  // **** Max Category Levels ****
 223  // change this if you need more or fewer categories.
 224  // set this to the maximum depth of your categories.
 225  define ('EP_MAX_CATEGORIES', 7); // default is 7
 226  
 227  
 228  // VJ product attributes begin
 229  // **** Product Attributes ****
 230  // change this to false, if do not want to download product attributes
 231  define ('EP_PRODUCTS_WITH_ATTRIBUTES', true);  // default is true
 232  
 233  // change this to true, if you use QTYpro and want to set attributes stock with EP.
 234  define ('EP_PRODUCTS_ATTRIBUTES_STOCK', false); // default is false
 235  
 236  // change this if you want to download only selected product options (attributes).
 237  // If you have a lot of product options, and your output file exceeds 256 columns, 
 238  // which is the max. limit MS Excel is able to handle, then load-up this array with
 239  // attributes to skip when generating the export.
 240  $attribute_options_select = '';
 241  // $attribute_options_select = array('Size', 'Model'); // uncomment and fill with product options name you wish to download // comment this line, if you wish to download all product options
 242  // VJ product attributes end
 243  
 244  
 245  // ******************************************************************
 246  // BEGIN Define Custom Fields for your products database
 247  // ******************************************************************
 248  // the following line is always left as is.
 249  $custom_fields = array();
 250  //
 251  // The following setup will allow you to define any additional 
 252  // field into the "products" and "products_description" tables
 253  // in your shop. If you have  installed a custom contribution
 254  // that adds fields to these tables you may simply and easily add
 255  // them to the EasyPopulate system.
 256  //
 257  // ********************
 258  // ** products table **
 259  // Lets say you have added a field to your "products" table called
 260  // "products_upc". The header name in your import file will be
 261  // called "v_products_upc".  Then below you will change the line
 262  // that looks like this (without the comment double-slash at the beginning):
 263  // $custom_fields[TABLE_PRODUCTS] = array(); // this line is used if you have no custom fields to import/export
 264  //
 265  // TO:
 266  // $custom_fields[TABLE_PRODUCTS] = array( 'products_upc' => 'UPC' );
 267  //
 268  // If you have multiple fields this is what it would look like:
 269  // $custom_fields[TABLE_PRODUCTS] = array( 'products_upc' => 'UPC', 'products_restock_quantity' => 'Restock' );
 270  //
 271  // ********************************
 272  // ** products_description table **
 273  // Lets say you have added a field to your "products_description" table called
 274  // "products_short_description". The header name in your import file will be
 275  // called "v_products_short_description_1" for English, "v_products_short_description_2" for German,
 276  // "v_products_short_description_3" for Spanish. Other languages will vary. Be sure to use the 
 277  // langugage ID of the custom language you installed if it is other then the original
 278  // 3 installed languages of osCommerce. If you are unsure what language ID you need to
 279  // use, do a complete export and examine the file headers EasyPopulate produces.
 280  //
 281  // Then below you will change the line that looks like this (without the comment double-slash at the beginning):
 282  // $custom_fields[TABLE_PRODUCTS_DESCRIPTION] = array(); // this line is used if you have no custom fields to import/export
 283  //
 284  // TO:
 285  // $custom_fields[TABLE_PRODUCTS_DESCRIPTION] = array( 'products_short_description' => 'short' );
 286  //
 287  // If you have multiple fields this is what it would look like:
 288  // $custom_fields[TABLE_PRODUCTS_DESCRIPTION] = array( 'products_short_description' => 'short', 'products_viewed' => 'Viewed' );
 289  //
 290  // the array format is: array( 'table_field_name' => 'Familiar Name' )
 291  // the array key ('table_field_name') is always the exact name of the 
 292  // field in the table. The array value ('Familiar Name') is any text
 293  // name that will be used in the custom EP export download checkbox.
 294  //
 295  // I believe this will only work for text/varchar and numeric field
 296  // types.  If your custom field is a date/time or any other type, you
 297  // may need to incorporate custom code to correctly import your data.
 298  //
 299  
 300  $custom_fields[TABLE_PRODUCTS] = array(); // this line is used if you have no custom fields to import/export
 301  $custom_fields[TABLE_PRODUCTS_DESCRIPTION] = array(); // this line is used if you have no custom fields to import/export
 302  
 303  //
 304  // FINAL NOTE: this currently only works with the "products" & "products_description" table.
 305  // If it works well and I don't get a plethora of problems reported,
 306  // I may expand it to more tables. Feel free to make requests, but
 307  // as always, only as me free time allows.
 308  //
 309  // ******************************************************************
 310  // END Define Custom Fields for your products database
 311  // ******************************************************************
 312  
 313  
 314  
 315  // ****************************************
 316  // Froogle configuration variables
 317  // Here are some links regarding Bulk uploads
 318  // http://www.google.com/base/attributes.html
 319  // http://www.google.com/base/help/custom-attributes.html
 320  // ****************************************
 321  
 322  // **** Froogle product info page path ****
 323  // We can't use the tep functions to create the link, because the links will point to the 
 324  // admin, since that's where we're at. So put the entire path to your product_info.php page here
 325  define ('EP_FROOGLE_PRODUCT_INFO_PATH', HTTP_CATALOG_SERVER . DIR_WS_CATALOG . "product_info.php");
 326  
 327  // **** Froogle product image path ****
 328  // Set this to the path to your images directory
 329  define ('EP_FROOGLE_IMAGE_PATH', HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES);
 330  
 331  // **** Froogle - search engine friendly setting
 332  // if your store has SEARCH ENGINE FRIENDLY URLS set, then turn this to true
 333  // I did it this way because I'm having trouble with the code seeing the constants
 334  // that are defined in other places.
 335  define ('EP_FROOGLE_SEF_URLS', false);  // default is false
 336  
 337  // **** Froogle Currency Setting
 338  define ('EP_FROOGLE_CURRENCY', 'USD');  // default is 'USD'
 339  
 340  // ****************************************
 341  // End: Froogle configuration variables
 342  // 
 343  
 344  
 345  // ***********************************
 346  // *** Other Contributions Support ***
 347  // ***********************************
 348  
 349  // More Pics 6 v1.3
 350  define ('EP_MORE_PICS_6_SUPPORT', false);  // default is false
 351  //
 352  // Header Tags Controller Support v2.0
 353  define ('EP_HTC_SUPPORT', false);  // default is false
 354  //
 355  // Separate Pricing Per Customer (SPPC)
 356  define ('EP_SPPC_SUPPORT', false);  // default is false
 357  
 358  // ///////////////////////////////////////////////////////////////////////////////
 359  // The following items are not complete and untested. Experiment at your own risk.
 360  // ///////////////////////////////////////////////////////////////////////////////
 361  
 362  //
 363  // Extra Fields Contribution (***UNTESTED AND MAY NOT BE FUNCTIONAL***)
 364  define ('EP_EXTRA_FIELDS_SUPPORT', false);  // default is false
 365  //
 366  // Unknown Image Contrib (***UNTESTED AND MAY NOT BE FUNCTIONAL***)
 367  define ('EP_UNKNOWN_ADD_IMAGES_SUPPORT', false);  // default is false
 368  
 369  
 370  //*******************************
 371  //*******************************
 372  // E N D
 373  // C O N F I G U R A T I O N
 374  // V A R I A B L E S
 375  //*******************************
 376  //*******************************
 377  
 378  
 379  
 380  
 381  
 382  //*******************************
 383  //*******************************
 384  // S T A R T
 385  // INITIALIZATION
 386  //*******************************
 387  //*******************************
 388  
 389  // modify tableBlock for use here.
 390    class epbox extends tableBlock {
 391      // constructor
 392      function epbox($contents, $direct_ouput = true) {
 393        $this->table_width = '';
 394        if (!empty($contents) && $direct_ouput == true) {
 395          echo $this->tableBlock($contents);
 396        }
 397      }
 398      // only member function
 399      function output($contents) {
 400        return $this->tableBlock($contents);
 401      }
 402    }
 403  
 404  if (!empty($languages_id) && !empty($language)) {
 405    define ('EP_DEFAULT_LANGUAGE_ID', $languages_id);
 406    define ('EP_DEFAULT_LANGUAGE_NAME', $language);
 407  } else {
 408    //elari check default language_id from configuration table DEFAULT_LANGUAGE
 409    $epdlanguage_query = tep_db_query("select languages_id, name from " . TABLE_LANGUAGES . " where code = '" . DEFAULT_LANGUAGE . "'");
 410    if (tep_db_num_rows($epdlanguage_query) > 0) {
 411      $epdlanguage = tep_db_fetch_array($epdlanguage_query);
 412      define ('EP_DEFAULT_LANGUAGE_ID', $epdlanguage['languages_id']);
 413      define ('EP_DEFAULT_LANGUAGE_NAME', $epdlanguage['name']);
 414    } else {
 415      echo 'Strange but there is no default language to work... That may not happen, just in case... ';
 416    }
 417  }
 418  
 419  $languages = tep_get_languages();
 420  
 421  // VJ product attributes begin
 422  $attribute_options_array = array();
 423  
 424  if (EP_PRODUCTS_WITH_ATTRIBUTES == true) {
 425      if (is_array($attribute_options_select) && (count($attribute_options_select) > 0)) {
 426          foreach ($attribute_options_select as $value) {
 427              $attribute_options_query = "select distinct products_options_id from " . TABLE_PRODUCTS_OPTIONS . " where products_options_name = '" . $value . "'";
 428  
 429              $attribute_options_values = tep_db_query($attribute_options_query);
 430  
 431              if ($attribute_options = tep_db_fetch_array($attribute_options_values)){
 432                  $attribute_options_array[] = array('products_options_id' => $attribute_options['products_options_id']);
 433              }
 434          }
 435      } else {
 436          $attribute_options_query = "select distinct products_options_id from " . TABLE_PRODUCTS_OPTIONS . " order by products_options_id";
 437  
 438          $attribute_options_values = tep_db_query($attribute_options_query);
 439  
 440          while ($attribute_options = tep_db_fetch_array($attribute_options_values)){
 441              $attribute_options_array[] = array('products_options_id' => $attribute_options['products_options_id']);
 442          }
 443      }
 444  }
 445  // VJ product attributes end
 446  
 447  
 448  // these are the fields that will be defaulted to the current values in 
 449  // the database if they are not found in the incoming file
 450  $default_these = array();
 451  foreach ($languages as $key => $lang){
 452    $default_these[] = 'v_products_name_' . $lang['id'];
 453    $default_these[] = 'v_products_description_' . $lang['id'];
 454    $default_these[] = 'v_products_url_' . $lang['id'];
 455    foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
 456      $default_these[] = 'v_' . $key . '_' . $lang['id'];
 457    }
 458    if (EP_HTC_SUPPORT == true) {
 459      $default_these[] = 'v_products_head_title_tag_' . $lang['id'];
 460      $default_these[] = 'v_products_head_desc_tag_' . $lang['id'];
 461      $default_these[] = 'v_products_head_keywords_tag_' . $lang['id'];
 462    }
 463  }
 464  $default_these[] = 'v_products_image';
 465  foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
 466    $default_these[] = 'v_' . $key;
 467  }
 468  if (EP_MORE_PICS_6_SUPPORT == true) { 
 469    $default_these[] = 'v_products_subimage1';
 470    $default_these[] = 'v_products_subimage2';
 471    $default_these[] = 'v_products_subimage3';
 472    $default_these[] = 'v_products_subimage4';
 473    $default_these[] = 'v_products_subimage5';
 474    $default_these[] = 'v_products_subimage6';
 475  }
 476  if (EP_UNKNOWN_ADD_IMAGES_SUPPORT == true) { 
 477    $default_these[] = 'v_products_mimage';
 478    $default_these[] = 'v_products_bimage';
 479    $default_these[] = 'v_products_subimage1';
 480    $default_these[] = 'v_products_bsubimage1';
 481    $default_these[] = 'v_products_subimage2';
 482    $default_these[] = 'v_products_bsubimage2';
 483    $default_these[] = 'v_products_subimage3';
 484    $default_these[] = 'v_products_bsubimage3';
 485  }
 486  $default_these[] = 'v_categories_id';
 487  $default_these[] = 'v_products_price';
 488  $default_these[] = 'v_products_quantity';
 489  $default_these[] = 'v_products_weight';
 490  $default_these[] = 'v_status_current';
 491  $default_these[] = 'v_date_avail';
 492  $default_these[] = 'v_date_added';
 493  $default_these[] = 'v_tax_class_title';
 494  $default_these[] = 'v_manufacturers_name';
 495  $default_these[] = 'v_manufacturers_id';
 496  
 497  $filelayout = '';
 498  $filelayout_count = '';
 499  $filelayout_sql = '';
 500  $fileheaders = '';
 501  
 502  
 503  
 504  if ( !empty($_GET['dltype']) ) {
 505      // if dltype is set, then create the filelayout.  Otherwise it gets read from the uploaded file
 506      list($filelayout, $filelayout_count, $filelayout_sql, $fileheaders) = ep_create_filelayout($_GET['dltype'], $attribute_options_array, $languages, $custom_fields); // get the right filelayout for this download
 507  }
 508  
 509  //*******************************
 510  //*******************************
 511  // E N D
 512  // INITIALIZATION
 513  //*******************************
 514  //*******************************
 515  
 516  
 517  
 518  
 519  //*******************************
 520  //*******************************
 521  // DOWNLOAD FILE (EXPORT)
 522  //*******************************
 523  //*******************************
 524  if ( !empty($_GET['download']) && ($_GET['download'] == 'stream' or $_GET['download'] == 'activestream' or $_GET['download'] == 'tempfile') ){
 525      $filestring = ""; // this holds the csv file we want to download
 526      $result = tep_db_query($filelayout_sql);
 527      $row =  tep_db_fetch_array($result);
 528  
 529  
 530      // $EXPORT_TIME=time();  // start export time when export is started.
 531      $EXPORT_TIME = strftime('%Y%b%d-%H%I');
 532      if ($dltype=="froogle"){
 533          $EXPORT_TIME = "FroogleEP" . $EXPORT_TIME;
 534      } else {
 535          $EXPORT_TIME = "EP" . $EXPORT_TIME;
 536      }
 537  
 538      // Here we need to allow for the mapping of internal field names to external field names
 539      // default to all headers named like the internal ones
 540      // the field mapping array only needs to cover those fields that need to have their name changed
 541      if ( count($fileheaders) != 0 ){
 542          $filelayout_header = $fileheaders; // if they gave us fileheaders for the dl, then use them
 543      } else {
 544          $filelayout_header = $filelayout; // if no mapping was spec'd use the internal field names for header names
 545      }
 546      //We prepare the table heading with layout values
 547      foreach( $filelayout_header as $key => $value ){
 548          $filestring .= $key . $ep_separator;
 549      }
 550      // now lop off the trailing tab
 551      $filestring = substr($filestring, 0, strlen($filestring)-1);
 552  
 553      // set the type
 554      if ( $dltype == 'froogle' ){
 555          $endofrow = "\n";
 556      } else {
 557          // default to normal end of row
 558          $endofrow = $ep_separator . 'EOREOR' . "\n";
 559      }
 560      $filestring .= $endofrow;
 561  
 562      if ($_GET['download'] == 'activestream'){
 563        header("Content-type: application/vnd.ms-excel");
 564        header("Content-disposition: attachment; filename=$EXPORT_TIME" . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"));
 565        // Changed if using SSL, helps prevent program delay/timeout (add to backup.php also)
 566        //    header("Pragma: no-cache");
 567        if ($request_type== 'NONSSL'){
 568          header("Pragma: no-cache");
 569        } else {
 570          header("Pragma: ");
 571        }
 572        header("Expires: 0");
 573        echo $filestring;
 574      }
 575  
 576      $num_of_langs = count($languages);
 577      while ($row){
 578  
 579  
 580          // if the filelayout says we need a products_name, get it
 581          // build the long full froogle image path
 582          $row['v_products_fullpath_image'] = EP_FROOGLE_IMAGE_PATH . $row['v_products_image'];
 583          // Other froogle defaults go here for now
 584          $row['v_froogle_quantitylevel']     = $row['v_products_quantity'];
 585          $row['v_froogle_manufacturer_id']   = '';
 586          $row['v_froogle_exp_date']          = date('Y-m-d', strtotime('+30 days'));
 587          $row['v_froogle_product_type']      = $row['v_categories_id'];
 588          $row['v_froogle_product_id']        = $row['v_products_model'];
 589          $row['v_froogle_currency']          = EP_FROOGLE_CURRENCY;
 590          
 591          // names and descriptions require that we loop thru all languages that are turned on in the store
 592          foreach ($languages as $key => $lang){
 593              $lid = $lang['id'];
 594  
 595              // for each language, get the description and set the vals
 596              $sql2 = "SELECT *
 597                  FROM ".TABLE_PRODUCTS_DESCRIPTION."
 598                  WHERE
 599                      products_id = " . $row['v_products_id'] . " AND
 600                      language_id = '" . $lid . "'
 601                  ";
 602              $result2 = tep_db_query($sql2);
 603              $row2 =  tep_db_fetch_array($result2);
 604  
 605              // I'm only doing this for the first language, since right now froogle is US only.. Fix later!
 606              // adding url for froogle, but it should be available no matter what
 607              if (EP_FROOGLE_SEF_URLS == true){
 608                  // if only one language
 609                  if ($num_of_langs == 1){
 610                      $row['v_froogle_products_url_' . $lid] = EP_FROOGLE_PRODUCT_INFO_PATH . '/products_id/' . $row['v_products_id'];
 611                  } else {
 612                      $row['v_froogle_products_url_' . $lid] = EP_FROOGLE_PRODUCT_INFO_PATH . '/products_id/' . $row['v_products_id'] . '/language/' . $lid;
 613                  }
 614              } else {
 615                  if ($num_of_langs == 1){
 616                      $row['v_froogle_products_url_' . $lid] = EP_FROOGLE_PRODUCT_INFO_PATH . '?products_id=' . $row['v_products_id'];
 617                  } else {
 618                      $row['v_froogle_products_url_' . $lid] = EP_FROOGLE_PRODUCT_INFO_PATH . '?products_id=' . $row['v_products_id'] . '&language=' . $lid;
 619                  }
 620              }
 621  
 622              $row['v_products_name_' . $lid]          = $row2['products_name'];
 623              $row['v_products_description_' . $lid]   = $row2['products_description'];
 624              $row['v_products_url_' . $lid]           = $row2['products_url'];
 625              foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
 626                $row['v_' . $key . '_' . $lid]           = $row2[$key];
 627              }
 628              // froogle advanced format needs the quotes around the name and desc
 629              $row['v_froogle_products_name_' . $lid] = '"' . strip_tags(str_replace('"','""',$row2['products_name'])) . '"';
 630              $row['v_froogle_products_description_' . $lid] = '"' . strip_tags(str_replace('"','""',$row2['products_description'])) . '"';
 631  
 632              // support for Linda's Header Controller 2.0 here
 633              if(isset($filelayout['v_products_head_title_tag_' . $lid])){
 634                  $row['v_products_head_title_tag_' . $lid]     = $row2['products_head_title_tag'];
 635                  $row['v_products_head_desc_tag_' . $lid]      = $row2['products_head_desc_tag'];
 636                  $row['v_products_head_keywords_tag_' . $lid]  = $row2['products_head_keywords_tag'];
 637              }
 638              // end support for Header Controller 2.0
 639          
 640          }
 641  
 642          // for the categories, we need to keep looping until we find the root category
 643          // start with v_categories_id
 644          // Get the category description
 645          // set the appropriate variable name
 646          // if parent_id is not null, then follow it up.
 647          // we'll populate an aray first, then decide where it goes in the
 648          $thecategory_id = $row['v_categories_id'];
 649          $fullcategory = ''; // this will have the entire category stack for froogle
 650          for( $categorylevel=1; $categorylevel<=EP_MAX_CATEGORIES; $categorylevel++){
 651              if ($thecategory_id){
 652  
 653                  $sql3 = "SELECT parent_id, 
 654                                  categories_image
 655                           FROM ".TABLE_CATEGORIES."
 656                           WHERE    
 657                                  categories_id = " . $thecategory_id . '';
 658                  $result3 = tep_db_query($sql3);
 659                  if ($row3 = tep_db_fetch_array($result3)) {
 660                      $temprow['v_categories_image_' . $categorylevel] = $row3['categories_image'];
 661                  }
 662  
 663                  foreach ($languages as $key => $lang){
 664                      $sql2 = "SELECT categories_name
 665                               FROM ".TABLE_CATEGORIES_DESCRIPTION."
 666                               WHERE    
 667                                      categories_id = " . $thecategory_id . " AND
 668                                      language_id = " . $lang['id'];
 669                      $result2 = tep_db_query($sql2);
 670                      if ($row2 =  tep_db_fetch_array($result2)) {
 671                          $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] = $row2['categories_name'];
 672                      }
 673                      if ($lang['id'] == '1') {
 674                          //$fullcategory .= " > " . $row2['categories_name'];
 675                          $fullcategory = $row2['categories_name'] . " > " . $fullcategory;
 676                      }
 677  
 678                  }
 679  
 680                  // now get the parent ID if there was one
 681                  $theparent_id = $row3['parent_id'];
 682                  if ($theparent_id != ''){
 683                      // there was a parent ID, lets set thecategoryid to get the next level
 684                      $thecategory_id = $theparent_id;
 685                  } else {
 686                      // we have found the top level category for this item,
 687                      $thecategory_id = false;
 688                  }
 689   
 690              } else {
 691                  $temprow['v_categories_image_' . $categorylevel] = '';
 692                  foreach ($languages as $key => $lang){
 693                      $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] = '';
 694                  }
 695              }
 696          }
 697  
 698          // now trim off the last ">" from the category stack
 699          $row['v_category_fullpath'] = substr($fullcategory,0,strlen($fullcategory)-3);
 700  
 701          // temprow has the old style low to high level categories.
 702          $newlevel = 1;
 703          // let's turn them into high to low level categories
 704          for( $categorylevel=EP_MAX_CATEGORIES; $categorylevel>0; $categorylevel--){
 705              $found = false;
 706              if ($temprow['v_categories_image_' . $categorylevel] != ''){
 707                  $row['v_categories_image_' . $newlevel] = $temprow['v_categories_image_' . $categorylevel];
 708                  $found = true;
 709              }
 710              foreach ($languages as $key => $lang){
 711                  if ($temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] != ''){
 712                      $row['v_categories_name_' . $newlevel . '_' . $lang['id']] = $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']];
 713                      $found = true;
 714                  }
 715              }
 716              if ($found == true) {
 717                  $newlevel++;
 718              }
 719          }
 720  
 721  
 722          // if the filelayout says we need a manufacturers name, get it
 723          if (isset($filelayout['v_manufacturers_name'])){
 724              if ($row['v_manufacturers_id'] != ''){
 725                  $sql2 = "SELECT manufacturers_name
 726                      FROM ".TABLE_MANUFACTURERS."
 727                      WHERE
 728                      manufacturers_id = " . $row['v_manufacturers_id']
 729                      ;
 730                  $result2 = tep_db_query($sql2);
 731                  $row2 =  tep_db_fetch_array($result2);
 732                  $row['v_manufacturers_name'] = $row2['manufacturers_name'];
 733              }
 734          }
 735  
 736  
 737          // If you have other modules that need to be available, put them here
 738  
 739          // VJ product attribs begin
 740          if (isset($filelayout['v_attribute_options_id_1'])){
 741  
 742              $attribute_options_count = 1;
 743        foreach ($attribute_options_array as $attribute_options) {
 744                  $row['v_attribute_options_id_' . $attribute_options_count]     = $attribute_options['products_options_id'];
 745  
 746                  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 747                      $lid = $languages[$i]['id'];
 748  
 749                      $attribute_options_languages_query = "select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options['products_options_id'] . "' and language_id = '" . (int)$lid . "'";
 750  
 751                      $attribute_options_languages_values = tep_db_query($attribute_options_languages_query);
 752  
 753                      $attribute_options_languages = tep_db_fetch_array($attribute_options_languages_values);
 754  
 755                      $row['v_attribute_options_name_' . $attribute_options_count . '_' . $lid] = $attribute_options_languages['products_options_name'];
 756                  }
 757  
 758                  $attribute_values_query = "select products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options['products_options_id'] . "' order by products_options_values_id";
 759  
 760                  $attribute_values_values = tep_db_query($attribute_values_query);
 761  
 762                  $attribute_values_count = 1;
 763                  while ($attribute_values = tep_db_fetch_array($attribute_values_values)) {
 764                      $row['v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count]     = $attribute_values['products_options_values_id'];
 765  
 766                      $attribute_values_price_query = "select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$row['v_products_id'] . "' and options_id = '" . (int)$attribute_options['products_options_id'] . "' and options_values_id = '" . (int)$attribute_values['products_options_values_id'] . "'";
 767  
 768                      $attribute_values_price_values = tep_db_query($attribute_values_price_query);
 769  
 770                      $attribute_values_price = tep_db_fetch_array($attribute_values_price_values);
 771  
 772                      $row['v_attribute_values_price_' . $attribute_options_count . '_' . $attribute_values_count]     = $attribute_values_price['price_prefix'] . $attribute_values_price['options_values_price'];
 773  
 774      //// attributes stock add start        
 775      if ( EP_PRODUCTS_ATTRIBUTES_STOCK    == true ) {   
 776             $stock_attributes = $attribute_options['products_options_id'].'-'.$attribute_values['products_options_values_id'];
 777             
 778             $stock_quantity_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int)$row['v_products_id'] . "' and products_stock_attributes = '" . $stock_attributes . "'");
 779             $stock_quantity = tep_db_fetch_array($stock_quantity_query);
 780             
 781             $row['v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count] = $stock_quantity['products_stock_quantity'];
 782       }
 783      //// attributes stock add end  
 784                      
 785                      
 786                      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 787                          $lid = $languages[$i]['id'];
 788  
 789                          $attribute_values_languages_query = "select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int)$attribute_values['products_options_values_id'] . "' and language_id = '" . (int)$lid . "'";
 790  
 791                          $attribute_values_languages_values = tep_db_query($attribute_values_languages_query);
 792  
 793                          $attribute_values_languages = tep_db_fetch_array($attribute_values_languages_values);
 794  
 795                          $row['v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid] = $attribute_values_languages['products_options_values_name'];
 796                      }
 797  
 798                      $attribute_values_count++;
 799                  }
 800  
 801                  $attribute_options_count++;
 802              }
 803          }
 804          // VJ product attribs end
 805  
 806          // this is for the separate price per customer module
 807          if (isset($filelayout['v_customer_price_1'])){
 808              $sql2 = "SELECT
 809                      customers_group_price,
 810                      customers_group_id
 811                  FROM
 812                      ".TABLE_PRODUCTS_GROUPS."
 813                  WHERE
 814                  products_id = " . $row['v_products_id'] . "
 815                  ORDER BY
 816                  customers_group_id"
 817                  ;
 818              $result2 = tep_db_query($sql2);
 819              $ll = 1;
 820              $row2 =  tep_db_fetch_array($result2);
 821              while( $row2 ){
 822                  $row['v_customer_group_id_' . $ll]     = $row2['customers_group_id'];
 823                  $row['v_customer_price_' . $ll]     = $row2['customers_group_price'];
 824                  $row2 = tep_db_fetch_array($result2);
 825                  $ll++;
 826              }
 827          }
 828  
 829          if ($dltype == 'froogle'){
 830              // For froogle, we check the specials prices for any applicable specials, and use that price
 831              // by grabbing the specials id descending, we always get the most recently added special price
 832              // I'm checking status because I think you can turn off specials
 833              $sql2 = "SELECT
 834                      specials_new_products_price
 835                  FROM
 836                      ".TABLE_SPECIALS."
 837                  WHERE
 838                  products_id = " . $row['v_products_id'] . " and
 839                  status = 1 and
 840                  expires_date < CURRENT_TIMESTAMP
 841                  ORDER BY
 842                      specials_id DESC"
 843                  ;
 844              $result2 = tep_db_query($sql2);
 845              $ll = 1;
 846              $row2 =  tep_db_fetch_array($result2);
 847              if( $row2 ){
 848                  // reset the products price to our special price if there is one for this product
 849                  $row['v_products_price']     = $row2['specials_new_products_price'];
 850              }
 851          }
 852  
 853          //elari -
 854          //We check the value of tax class and title instead of the id
 855          //Then we add the tax to price if EP_PRICE_WITH_TAX is set to true
 856          $row_tax_multiplier         = tep_get_tax_class_rate($row['v_tax_class_id']);
 857          $row['v_tax_class_title']   = tep_get_tax_class_title($row['v_tax_class_id']);
 858          $row['v_products_price']    = $row['v_products_price'] +
 859                  (EP_PRICE_WITH_TAX == true ? round( ($row['v_products_price'] * $row_tax_multiplier / 100), EP_PRECISION) : 0);
 860  
 861  
 862          // Now set the status to a word the user specd in the config vars
 863          if ( $row['v_status'] == '1' ){
 864              $row['v_status'] = EP_TEXT_ACTIVE;
 865          } else {
 866              $row['v_status'] = EP_TEXT_INACTIVE;
 867          }
 868  
 869          // remove any bad things in the texts that could confuse EasyPopulate
 870          $therow = '';
 871          foreach( $filelayout as $key => $value ){
 872              //echo "The field was $key<br />";
 873  
 874              $thetext = $row[$key];
 875              // kill the carriage returns and tabs in the descriptions, they're killing me!
 876              if (EP_PRESERVE_TABS_CR_LF == false || $dltype == 'froogle') {
 877                $thetext = str_replace("\r",' ',$thetext);
 878                $thetext = str_replace("\n",' ',$thetext);
 879                $thetext = str_replace("\t",' ',$thetext);
 880              }
 881              if (EP_EXCEL_SAFE_OUTPUT == true && $dltype != 'froogle') {
 882                // use quoted values and escape the embedded quotes for excel safe output.
 883                $therow .= '"'.str_replace('"','""',$thetext).'"' . $ep_separator;
 884              } else {
 885                // and put the text into the output separated by $ep_separator defined above
 886                $therow .= $thetext . $ep_separator;
 887              }
 888          }
 889  
 890          // lop off the trailing separator, then append the end of row indicator
 891          $therow = substr($therow,0,strlen($therow)-1) . $endofrow;
 892  
 893          if ($_GET['download'] == 'activestream'){
 894            echo $therow;
 895          } else {
 896            $filestring .= $therow;
 897          }
 898          // grab the next row from the db
 899          $row =  tep_db_fetch_array($result);
 900      }
 901  
 902      // now either stream it to them or put it in the temp directory
 903      if ($_GET['download'] == 'activestream'){
 904          die();
 905      } elseif ($_GET['download'] == 'stream'){
 906          //*******************************
 907          // STREAM FILE
 908          //*******************************
 909          header("Content-type: application/vnd.ms-excel");
 910          header("Content-disposition: attachment; filename=$EXPORT_TIME" . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"));
 911          // Changed if using SSL, helps prevent program delay/timeout (add to backup.php also)
 912          //    header("Pragma: no-cache");
 913          if ($request_type== 'NONSSL'){
 914            header("Pragma: no-cache");
 915          } else {
 916            header("Pragma: ");
 917          }
 918          header("Expires: 0");
 919          echo $filestring;
 920          die();
 921      } elseif ($_GET['download'] == 'tempfile') {
 922          //*******************************
 923          // PUT FILE IN TEMP DIR
 924          //*******************************
 925          $tmpfname = EP_TEMP_DIRECTORY . "$EXPORT_TIME" . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt");
 926          //unlink($tmpfname);
 927          $fp = fopen( $tmpfname, "w+");
 928          fwrite($fp, $filestring);
 929          fclose($fp);
 930          echo "You can get your file in the Tools/File Manager here: " . EP_TEMP_DIRECTORY . "EP" . $EXPORT_TIME . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt");
 931          die();
 932      }
 933  } 
 934  
 935  
 936  
 937  //*******************************
 938  //*******************************
 939  // S T A R T
 940  // PAGE DELIVERY
 941  //*******************************
 942  //*******************************
 943  ?>
 944  
 945  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 946  <html <?php echo HTML_PARAMS; ?>>
 947  <head>
 948  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 949  <title><?php echo TITLE; ?></title>
 950  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 951  <script type="text/javascript"><!--
 952    function switchForm( field ) {
 953      var d = document;
 954      var frm = field.form;
 955      var tbl = d.getElementById('customtable');
 956          
 957      if(d.getElementById)
 958      {
 959        if(field.options[field.selectedIndex].text == 'Complete' || field.options[field.selectedIndex].text == 'Froogle') 
 960        {
 961          tbl.style.backgroundColor='lightgrey';
 962          for ( var index = 0; index < frm.elements.length; index++ )
 963          {
 964              var oElement = frm.elements[ index ];
 965              if ( oElement.type == "checkbox" )
 966              {
 967                  if ( oElement.checked )
 968                  {
 969                    oElement.checked = false;
 970                  }
 971                  oElement.disabled = true;
 972              }
 973          }
 974        } 
 975        else if(field.options[field.selectedIndex].text == 'Price/Qty' || field.options[field.selectedIndex].text == 'Categories' || field.options[field.selectedIndex].text == 'Attributes' ) 
 976        {
 977          tbl.style.backgroundColor='lightgrey';
 978          for ( var index = 0; index < frm.elements.length; index++ )
 979          {
 980              var oElement = frm.elements[ index ];
 981              if ( oElement.type == "checkbox" )
 982              {
 983                  if ( oElement.checked )
 984                  {
 985                    oElement.checked = false;
 986                  }
 987                  if ( (oElement.name == 'epcust_price' || oElement.name == 'epcust_quantity') && field.options[field.selectedIndex].text == 'Price/Qty' )
 988                  {
 989                    oElement.disabled = false;
 990                    oElement.checked = true;
 991                  } 
 992                  else if ( oElement.name == 'epcust_category' && field.options[field.selectedIndex].text == 'Categories' )
 993                  {
 994                    oElement.disabled = false;
 995                    oElement.checked = true;
 996                  } 
 997                  else if ( oElement.name == 'epcust_attributes' && field.options[field.selectedIndex].text == 'Attributes' )
 998                  {
 999                    oElement.disabled = false;
1000                    oElement.checked = true;
1001                  } 
1002                  else 
1003                  {
1004                    oElement.disabled = true;
1005                  }
1006              }
1007          }
1008        } 
1009        else 
1010        { 
1011          tbl.style.backgroundColor='white';
1012          for ( var index = 0; index < frm.elements.length; index++ )
1013          {
1014              var oElement = frm.elements[ index ];
1015              if ( oElement.type == "checkbox" )
1016              {
1017                  oElement.disabled = false;
1018              }
1019          }
1020        }
1021      }
1022    }
1023  //--></script> 
1024  </head>
1025  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
1026  <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
1027  
1028  <table border="0" width="100%" cellspacing="2" cellpadding="2">
1029  <tr>
1030  <td width="<?php echo BOX_WIDTH; ?>" valign="top" height="27">
1031  <table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
1032  <?php require(DIR_WS_INCLUDES . 'column_left.php');?>
1033  </table></td>
1034  <td class="pageHeading" valign="top"><?php
1035  echo "Easy Populate ".EP_CURRENT_VERSION." - Default Language : " . EP_DEFAULT_LANGUAGE_NAME . '(' . EP_DEFAULT_LANGUAGE_ID .')' ;
1036  ?>
1037  
1038  <p class="smallText"><?php
1039  
1040  
1041  //*******************************
1042  //*******************************
1043  // UPLOAD AND INSERT FILE
1044  //*******************************
1045  //*******************************
1046  if (!empty($_POST['localfile']) or (isset($_FILES['usrfl']) && isset($_GET['split']) && $_GET['split']==0)) {
1047  
1048      if (isset($_FILES['usrfl'])){
1049          // move the file to where we can work with it
1050          $file = tep_get_uploaded_file('usrfl');
1051          if (is_uploaded_file($file['tmp_name'])) {
1052              tep_copy_uploaded_file($file, EP_TEMP_DIRECTORY);
1053          }
1054  
1055          echo "<p class=smallText>";
1056          echo "File uploaded. <br />";
1057          echo "Temporary filename: " . $file['tmp_name'] . "<br />";
1058          echo "User filename: " . $file['name'] . "<br />";
1059          echo "Size: " . $file['size'] . "<br />";
1060  
1061          // get the entire file into an array
1062          $readed = file(EP_TEMP_DIRECTORY . $file['name']);
1063      }
1064      if (!empty($_POST['localfile'])){
1065          // move the file to where we can work with it
1066          //$file = tep_get_uploaded_file('usrfl');
1067  
1068          //$attribute_options_query = "select distinct products_options_id from " . TABLE_PRODUCTS_OPTIONS . " order by products_options_id";
1069          //$attribute_options_values = tep_db_query($attribute_options_query);
1070          //$attribute_options_count = 1;
1071          //while ($attribute_options = tep_db_fetch_array($attribute_options_values)){
1072  
1073          //if (is_uploaded_file($file['tmp_name'])) {
1074          //    tep_copy_uploaded_file($file, EP_TEMP_DIRECTORY);
1075          //}
1076  
1077          echo "<p class=smallText>";
1078          echo "Filename: " . $_POST['localfile'] . "<br />";
1079  
1080          // get the entire file into an array
1081          $readed = file(EP_TEMP_DIRECTORY . $_POST['localfile']);
1082      }
1083      
1084      if (EP_EXCEL_SAFE_OUTPUT == true) {
1085      
1086          // do excel safe input
1087          $fp = fopen(EP_TEMP_DIRECTORY . (isset($_FILES['usrfl'])?$file['name']:$_POST['localfile']),'r') or die('##Can not open file for reading. Script will terminate.<br />');  // open file
1088          // determine the separator character.
1089          $header_line = fgets($fp);
1090          if (strpos($header_line,',') !== false) { $ep_separator = ','; }
1091          if (strpos($header_line,';') !== false) { $ep_separator = ';'; }
1092          if (strpos($header_line,"\t") !== false) { $ep_separator = "\t"; }
1093          if (strpos($header_line,'~') !== false) { $ep_separator = '~'; }
1094          if (strpos($header_line,'-') !== false) { $ep_separator = '-'; }
1095          if (strpos($header_line,'*') !== false) { $ep_separator = '*'; }
1096          fclose($fp); 
1097  
1098          if (EP_EXCEL_SAFE_OUTPUT_ALT_PARCE == false) {
1099              
1100              unset($readed);                    // kill array setup with above code
1101              $readed = array();                 // start a new one for excel_safe_output
1102              $fp = fopen(EP_TEMP_DIRECTORY . (isset($_FILES['usrfl'])?$file['name']:$_POST['localfile']),'r') or die('##Can not open file for reading. Script will terminate.<br />');  // open file
1103              while($line = fgetcsv($fp,32768,$ep_separator))   // read new line (max 32K bytes)
1104              {
1105                  unset($line[(sizeof($line)-1)]);  // remove EOREOR at the end of the array
1106                  $readed[] = $line;                // add to array we will process later
1107              }
1108              $theheaders_array = $readed[0];     // pull out header line
1109              fclose($fp);                        // close file
1110  
1111          } else {
1112          
1113              // Maynard's CSV Fix ###################################################
1114              // some versions of fgetcsv don't like a field beginning with "", so we'll parse it ourselves
1115              // use readed, but parse it ourselves according to $ep_separator, and " as field encloser
1116              
1117              // I copied this from below:
1118              // now we string the entire thing together in case there were carriage returns in the data
1119                $newreaded = "";
1120                foreach ($readed as $read){
1121                  $newreaded .= $read;
1122                }
1123                // now newreaded has the entire file together without the carriage returns.
1124                // if for some reason excel put qoutes around our EOREOR, remove them then split into rows
1125                $newreaded = str_replace('"EOREOR"', 'EOREOR', $newreaded);
1126                $readed = explode( $ep_separator . 'EOREOR',$newreaded);
1127              // dump the last entry - it's blank
1128              unset($readed[sizeof($readed)-1]);    
1129              // parse it all!
1130              foreach ($readed as $key => $line) {
1131                  $ppp = 0; // pointer
1132                  $line1 = array();
1133                  $remains = trim($line);
1134                  while ($remains != '') {
1135                      if (substr($remains,0,1) == '"') {
1136                          // this is an enclosed portion
1137                          $ppp1 = -1; // so that our first loop points to the right place in $remains
1138                          $ppp2 = -1;
1139                          // we've got to find the next " that isn't ""    
1140                          while($ppp1 < strlen($remains) && $ppp1 == $ppp2 && $ppp1 !== FALSE) {
1141                              $ppp1 = strpos($remains, '"', $ppp2+2);
1142                              $ppp2 = strpos($remains, '""', $ppp2+2); // use ppp2 because then """ will get properly understood                
1143                          }
1144                          // now $ppp1 points to the closing "
1145                          // we are pulling out the determined chunk and 
1146                          // replacing any double quotes with single quotes 
1147                          // since that is how CSV handles quotes
1148                          $line1[] = str_replace('""','"',substr($remains,1,$ppp1-1));
1149                          // find the next separator - for a well formed CSV file, it MUST be a separator (and not in quoted text)
1150                          $ppp1 = strpos($remains, $ep_separator, $ppp1);
1151                          $remains = ($ppp1 !== false) ? substr($remains,$ppp1+1) : '';             
1152                      } else {
1153                          // this is an un-enclosed portion - find the next separator
1154                          $ppp1 = strpos($remains, $ep_separator, 0);
1155                          $line1[] = ($ppp1 !== false) ? substr($remains,0,$ppp1) : $remains;
1156                          $remains = ($ppp1 !== false) ? substr($remains,$ppp1+1) : '';                        
1157                      }
1158                  }
1159                  // replace that line with our new array
1160                  $readed[$key] = $line1;
1161              }
1162              $theheaders_array = $readed[0];     // pull out header line    
1163              // EOF Maynard's CSV Fix ###################################################      
1164          }
1165  
1166      } else {
1167        // do normal EP input
1168        // now we string the entire thing together in case there were carriage returns in the data
1169        $newreaded = "";
1170        foreach ($readed as $read){
1171          $newreaded .= $read;
1172        }
1173  
1174        // now newreaded has the entire file together without the carriage returns.
1175        // if for some reason excel put qoutes around our EOREOR, remove them then split into rows
1176        $newreaded = str_replace('"EOREOR"', 'EOREOR', $newreaded);
1177        $readed = explode( $ep_separator . 'EOREOR',$newreaded);
1178  
1179        // Now we'll populate the filelayout based on the header row.
1180        $theheaders_array = explode( $ep_separator, $readed[0] ); // explode the first row, it will be our filelayout
1181      }
1182      
1183      $lll = 0;
1184      $filelayout = array();
1185      foreach( $theheaders_array as $header ){
1186          $cleanheader = str_replace( '"', '', $header);
1187          // echo "Fileheader was $header<br /><br /><br />";
1188          $filelayout[ $cleanheader ] = $lll++; //
1189      }
1190      unset($readed[0]); //  we don't want to process the headers with the data
1191  
1192      // now we've got the array broken into parts by the expicit end-of-row marker.
1193      foreach ($readed as $tkey => $readed_row) {
1194        process_row($readed_row, $filelayout, $filelayout_count, $default_these, $ep_separator, $languages, $custom_fields);
1195      }
1196      // isn't working in PHP 5
1197      // array_walk($readed, $filelayout, $filelayout_count, $default_these, 'process_row');
1198  
1199  
1200  
1201  //*******************************
1202  //*******************************
1203  // UPLOAD AND SPLIT FILE
1204  //*******************************
1205  //*******************************
1206  } elseif (isset($_FILES['usrfl']) && isset($_GET['split']) && $_GET['split']==1) {
1207      // move the file to where we can work with it
1208      $file = tep_get_uploaded_file('usrfl');
1209      //echo "Trying to move file...";
1210      if (is_uploaded_file($file['tmp_name'])) {
1211          tep_copy_uploaded_file($file, EP_TEMP_DIRECTORY);
1212      }
1213  
1214      $infp = fopen(EP_TEMP_DIRECTORY . $file['name'], "r");
1215  
1216      //toprow has the field headers
1217      $toprow = fgets($infp,32768);
1218  
1219      $filecount = 1;
1220  
1221      echo "Creating file EP_Split" . $filecount . '.'.((EP_EXCEL_SAFE_OUTPUT==true)?'csv':'txt').' ...  ';
1222      $tmpfname = EP_TEMP_DIRECTORY . "EP_Split" . $filecount.'.'.((EP_EXCEL_SAFE_OUTPUT==true)?'csv':'txt');
1223      $fp = fopen( $tmpfname, "w+");
1224      fwrite($fp, $toprow);
1225  
1226      $linecount = 0;
1227      $line = fgets($infp,32768);
1228      while ($line){
1229          // walking the entire file one row at a time
1230          // but a line is not necessarily a complete row, we need to split on rows that have "EOREOR" at the end
1231          $line = str_replace('"EOREOR"', 'EOREOR', $line);
1232          fwrite($fp, $line);
1233          if (strpos($line, 'EOREOR')){
1234              // we found the end of a line of data, store it
1235              $linecount++; // increment our line counter
1236              if ($linecount >= EP_SPLIT_MAX_RECORDS){
1237                  echo "Added $linecount records and closing file... <br />";
1238                  $linecount = 0; // reset our line counter
1239                  // close the existing file and open another;
1240                  fclose($fp);
1241                  // increment filecount
1242                  $filecount++;
1243                  echo "Creating file EP_Split" . $filecount . '.'.((EP_EXCEL_SAFE_OUTPUT==true)?'csv':'txt').' ...  ';
1244                  $tmpfname = EP_TEMP_DIRECTORY . "EP_Split" . $filecount.'.'.((EP_EXCEL_SAFE_OUTPUT==true)?'csv':'txt');
1245                  //Open next file name
1246                  $fp = fopen( $tmpfname, "w+");
1247                  fwrite($fp, $toprow);
1248              }
1249          }
1250          $line=fgets($infp,32768);
1251      }
1252      echo "Added $linecount records and closing file...<br /><br /> ";
1253      fclose($fp);
1254      fclose($infp);
1255  
1256      echo "You can download your split files in the Tools/Files under " . EP_TEMP_DIRECTORY;
1257  
1258  }
1259  
1260  
1261  //*******************************
1262  //*******************************
1263  // MAIN MENU
1264  //*******************************
1265  //*******************************
1266  ?>
1267        </p>
1268  
1269        <table width="<?php if (EP_SHOW_EP_SETTINGS == true) { echo '95'; } else { echo '75'; } ?>%" cellpadding="5" cellspacing="0" style="border-collapse:collapse;">
1270          <tr>
1271            <td width="75%" style="border-style:solid; border-width:thin; border-color:#CCCCCC;"><span style="font-size:10px;background-color:#FFFFCC; width:100%;">&nbsp; &nbsp;Please <a href="backup.php<?php if (defined('SID') && tep_not_null(SID)) { echo '?'.tep_session_name().'='.tep_session_id(); } ?>" style="font-size:10px;background-color:#FFFFCC;text-decoration:underline;">backup your database</a> before performing any Easy Populate operations!&nbsp; &nbsp;</span><br />
1272             <form enctype="multipart/form-data" action="easypopulate.php?split=0<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>" method="post"><?php if (defined('SID') && tep_not_null(SID)) { echo tep_draw_hidden_field(tep_session_name(), tep_session_id()); } ?>
1273                  <p style="margin-top: 18px; margin-bottom: 8px;"><b>Upload and Import EP File</b></p>
1274                  <p style="margin-top: 0px;">
1275                    <input type="hidden" name="MAX_FILE_SIZE" value="100000000">
1276                    <input name="usrfl" type="file" size="50">
1277                    <select name="imput_mode">
1278                        <option value="normal">Normal</option>
1279                        <option value="addnew">Add New Only</option>
1280                        <option value="update">Update Only</option>
1281                    </select>
1282                    <input type="submit" name="buttoninsert" value="Insert into db">
1283                  <br />
1284                  </p>
1285                </form>
1286  
1287             <form enctype="multipart/form-data" action="easypopulate.php?split=1<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>" method="post"><?php if (defined('SID') && tep_not_null(SID)) { echo tep_draw_hidden_field(tep_session_name(), tep_session_id()); } ?>
1288                  <p style="margin-top: 18px; margin-bottom: 8px;"><b>Upload and Split EP File</b></p>
1289                  <p style="margin-top: 0px;">
1290                    <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
1291                    <input name="usrfl" type="file" size="50">
1292                    <input type="submit" name="buttonsplit" value="Split file">
1293                  <br />
1294                  </p>
1295               </form>
1296  
1297             <form enctype="multipart/form-data" action="easypopulate.php<?php if (defined('SID') && tep_not_null(SID)) { echo '?'.tep_session_name().'='.tep_session_id(); } ?>" method="post"><?php if (defined('SID') && tep_not_null(SID)) { echo tep_draw_hidden_field(tep_session_name(), tep_session_id()); } ?>
1298                  <p style="margin-top: 18px; margin-bottom: 8px;"><b>Import EP file from Temp Dir</b></p>
1299                  <p style="margin-top: 0px;">
1300                    <?PHP
1301                      //<input type="text" name="localfile" size="50">
1302                      $the_array = Array();
1303                      if (is_readable(EP_TEMP_DIRECTORY)) {
1304                          $handle = opendir(EP_TEMP_DIRECTORY);
1305                          while (false!== ($file = readdir($handle))) {
1306                            if ($file!= "." && $file!= ".." &&!is_dir($file)) {
1307                             $namearr = split('\.',$file);
1308                             if ($namearr[count($namearr)-1] == ((EP_EXCEL_SAFE_OUTPUT==true)?'csv':'txt')) $the_array[] = $file;
1309                            }
1310                          }
1311                          closedir($handle);
1312                      }
1313                          
1314                      $array_size = count($the_array);
1315                      if($array_size == 0){
1316                        echo ('            <input type="text" name="localfile" size="50">' . "\n");
1317                      } else {
1318                        echo ('            <select name="localfile" size="1">' . "\n");
1319                        foreach ($the_array as $list){
1320                         echo ('                <option value="' . $list . '">' . $list . '</option>' . "\n");
1321                        }
1322                        echo ('            </select>' . "\n");
1323                      }
1324                      ?>
1325                    <select name="imput_mode">
1326                        <option value="normal">Normal</option>
1327                        <option value="addnew">Add New Only</option>
1328                        <option value="update">Update Only</option>
1329                    </select>
1330                    <input type="submit" name="buttoninsert" value="Insert into db">
1331                    <br />
1332                  </p>
1333               </form>
1334  
1335          <p style="margin-top: 24px; margin-bottom: 8px;"><b>Export EP or Froogle Products File</b></p>
1336          <p style="margin-top: 0px;"><!-- Download file links -  Add your custom fields here -->
1337            <table border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #666666; padding: 3px;">
1338            <?php echo tep_draw_form('custom', 'easypopulate.php', 'id="custom"' . ((defined('SID') && tep_not_null(SID)) ? '&'.tep_session_name().'='.tep_session_id() : ''), 'get'); ?><?php if (defined('SID') && tep_not_null(SID)) { echo tep_draw_hidden_field(tep_session_name(), tep_session_id()); } ?>
1339            <tr><td class="smallText"><?php 
1340            
1341            echo tep_draw_pull_down_menu('download',array( 0 => array( "id" => 'activestream', 'text' => 'Download on-the-fly' ), 1 => array( "id" => 'stream', 'text' => 'Create then Download' ), 2 => array( "id" => 'tempfile', 'text' => 'Create in Temp Dir' )));
1342            echo '&nbsp;a&nbsp;' . tep_draw_pull_down_menu('dltype',array( 0 => array( "id" => 'full', 'text' => 'Complete' ), 1 => array( "id" => 'custom', 'text' => 'Custom' ), 2 => array( "id" => 'priceqty', 'text' => 'Price/Qty' ), 3 => array( "id" => 'category', 'text' => 'Categories' ), 4 => array( "id" => 'attrib', 'text' => 'Attributes' ), 5 => array( "id" => 'froogle', 'text' => 'Froogle' )),'custom','onChange="return switchForm(this);"');
1343            echo '&nbsp;' . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt") . ' file (model number is always included).'; 
1344  
1345            $cells = array();
1346            $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_name', 'show', (!empty($_GET['epcust_name'])?true:false)) . '</td><td class="smallText"> name' . '</td></tr></table>');
1347            $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_description', 'show', (!empty($_GET['epcust_description'])?true:false)) . '</td><td class="smallText"> description' . '</td></tr></table>');
1348            $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_url', 'show', (!empty($_GET['epcust_url'])?true:false)) . '</td><td class="smallText"> url' . '</td></tr></table>');
1349            $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_image', 'show', (!empty($_GET['epcust_image'])?true:false)) . '</td><td class="smallText"> image' . '</td></tr></table>');
1350            if (EP_PRODUCTS_WITH_ATTRIBUTES == true) {
1351              $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_attributes', 'show', (!empty($_GET['epcust_attributes'])?true:false)) . '</td><td class="smallText"> attributes' . '</td></tr></table>');
1352            }
1353            $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_category', 'show', (!empty($_GET['epcust_category'])?true:false)) . '</td><td class="smallText"> categories' . '</td></tr></table>');
1354            $cells[0][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_manufacturer', 'show', (!empty($_GET['epcust_manufacturer'])?true:false)) . '</td><td class="smallText"> manufacturer' . '</td></tr></table>');
1355  
1356            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_price', 'show', (!empty($_GET['epcust_price'])?true:false)) . '</td><td class="smallText"> price' . '</td></tr></table>');
1357            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_quantity', 'show', (!empty($_GET['epcust_quantity'])?true:false)) . '</td><td class="smallText"> quantity' . '</td></tr></table>');
1358            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_weight', 'show', (!empty($_GET['epcust_weight'])?true:false)) . '</td><td class="smallText"> weight' . '</td></tr></table>');
1359            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_tax_class', 'show', (!empty($_GET['epcust_tax_class'])?true:false)) . '</td><td class="smallText"> tax class' . '</td></tr></table>');
1360            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_avail', 'show', (!empty($_GET['epcust_avail'])?true:false)) . '</td><td class="smallText"> available' . '</td></tr></table>');
1361            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_date_added', 'show', (!empty($_GET['epcust_date_added'])?true:false)) . '</td><td class="smallText"> date added' . '</td></tr></table>');
1362            $cells[1][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_status', 'show', (!empty($_GET['epcust_status'])?true:false)) . '</td><td class="smallText"> status' . '</td></tr></table>');
1363  
1364            $tmp_row_count = 2;
1365            $tmp_col_count = 0;
1366            foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
1367              $cells[$tmp_row_count][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_' . $key, 'show', (!empty($_GET['epcust_' . $key])?true:false)) . '</td><td class="smallText"> ' . $name . '</td></tr></table>');
1368              $tmp_col_count += 1;
1369              if ($tmp_col_count >= 7) { 
1370                $tmp_row_count += 1; 
1371                $tmp_col_count = 0; 
1372              }
1373            }
1374  
1375            foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
1376              $cells[$tmp_row_count][] = array('text' => '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">' . tep_draw_checkbox_field('epcust_' . $key, 'show', (!empty($_GET['epcust_' . $key])?true:false)) . '</td><td class="smallText"> ' . $name . '</td></tr></table>');
1377              $tmp_col_count += 1;
1378              if ($tmp_col_count >= 7) { 
1379                $tmp_row_count += 1; 
1380                $tmp_col_count = 0; 
1381              }
1382            }
1383  
1384            $bigbox = new epbox('',false);
1385            $bigbox->table_parameters = 'id="customtable" style="border: 1px solid #CCCCCC; padding: 2px; margin: 3px;"';
1386            echo $bigbox->output($cells);
1387  
1388            $manufacturers_array = array();
1389            $manufacturers_array[] = array( "id" => '', 'text' => '- manufacturer -' );
1390            $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
1391            while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
1392              $manufacturers_array[] = array( "id" => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name'] );
1393            }
1394  
1395            $status_array = array(array( "id" => '', 'text' => '- status -' ),array( "id" => '1', 'text' => 'active' ),array( "id" => '0', 'text' => 'disabled' ));
1396  
1397            echo 'filter by: ' . tep_draw_pull_down_menu('epcust_category_filter', array_merge(array( 0 => array( "id" => '', 'text' => '- category -' )), tep_get_category_tree()));
1398            echo ' ' . tep_draw_pull_down_menu('epcust_manufacturer_filter', $manufacturers_array) . ' ';
1399            echo ' ' . tep_draw_pull_down_menu('epcust_status_filter', $status_array) . ' ';
1400            
1401            echo tep_draw_input_field('submit', 'Build File', ' style="padding: 0px"', false, 'submit');
1402            ?></td></tr>
1403            </form>
1404            </table>
1405          </p><br /><br />
1406  
1407          <font size="-2">Quick Links</font>
1408          <table width="100%" border="0" cellpadding="3" cellspacing="3"><tr><td width="50%" valign="top" bgcolor="#EEEEEE">
1409          <p style="margin-top: 8px;"><b>Create then Download Files</b><br />
1410          <font size="-2">Create entire file in server memory then stream download after completed.</font></p>
1411          <p><!-- Download file links -  Add your custom fields here -->
1412            <a href="easypopulate.php?download=stream&dltype=full<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Download <b>Complete<?php if (EP_SPPC_SUPPORT == true) { echo ' w/SPPC'; } ?></b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file to edit</a><br />
1413  <?php if (EP_EXTRA_FIELDS_SUPPORT == true) { ?>
1414            <a href="easypopulate.php?download=stream&dltype=extra_fields<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Download <b>Extra Fields</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file to edit</a><br />
1415  <?php } ?>
1416            <a href="easypopulate.php?download=stream&dltype=priceqty<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Download <b>Model/Price/Qty<?php if (EP_SPPC_SUPPORT == true) { echo ' w/SPPC'; } ?></b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file to edit</a><br />
1417            <a href="easypopulate.php?download=stream&dltype=category<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Download <b>Model/Category</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file to edit</a><br />
1418            <a href="easypopulate.php?download=stream&dltype=froogle<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Download <b>Froogle</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file</a><br />
1419            <!-- VJ product attributes begin //-->
1420            <?php if (EP_PRODUCTS_WITH_ATTRIBUTES == true) { ?>
1421            <a href="easypopulate.php?download=stream&dltype=attrib<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Download <b>Model/Attributes</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file</a><br />
1422            <?php } ?>
1423            <!-- VJ product attributes end //-->
1424          </p><br />
1425          </td><td width="50%" valign="top" bgcolor="#EEEEEE">
1426          <p style="margin-top: 8px;"><b>Create Files in Temp Dir</b><br />
1427          <font size="-2">Create entire file in server memory then save to Temp Dir after completed.</font></p>
1428          <p>
1429            <a href="easypopulate.php?download=tempfile&dltype=full<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Create <b>Complete</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file in temp dir</a><br />
1430            <a href="easypopulate.php?download=tempfile&dltype=priceqty<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Create <b>Model/Price/Qty</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file in temp dir</a><br />
1431            <a href="easypopulate.php?download=tempfile&dltype=category<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Create <b>Model/Category</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file in temp dir</a><br />
1432            <a href="easypopulate.php?download=tempfile&dltype=froogle<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Create <b>Froogle</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file in temp dir</a><br />
1433            <!-- VJ product attributes begin //-->
1434            <?php if (EP_PRODUCTS_WITH_ATTRIBUTES == true) { ?>
1435            <a href="easypopulate.php?download=tempfile&dltype=attrib<?php if (defined('SID') && tep_not_null(SID)) { echo '&'.tep_session_name().'='.tep_session_id(); } ?>">Create <b>Model/Attributes</b> <?php echo ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"); ?> file in temp dir</a><br />
1436            <?php } ?>
1437            <!-- VJ product attributes end //-->
1438          </p><br />
1439          </td></tr></table>
1440  
1441            </td>
1442            
1443            <?php if (EP_SHOW_EP_SETTINGS == true) { ?>
1444            <td width="25%" valign="top" style="border-style:solid; border-width:thin; border-color:#CCCCCC;"><p style="margin-top: 8px;"><b>Settings & Info</b></p>
1445            <table border="0" cellpadding="0" cellspacing="0"><tr><td class="smallText">
1446            
1447               <p>EP vers: <?php echo EP_CURRENT_VERSION; ?><br />
1448               <?php if (defined('PROJECT_VERSION')) { echo PROJECT_VERSION . '<br>'; } ?>
1449               <?php echo 'OS: ' . $system['system'] . ' ' . $system['kernel'] . '<br>'; ?>
1450               <?php echo 'HTTP: ' . $system['http_server'] . '<br>'; ?>
1451               <?php echo 'DB: ' . $system['db_version'] . '<br>'; ?>
1452               <?php echo 'PHP: ' . $system['php'] . ' (Zend: ' . $system['zend'] . ')' . '<br>'; ?>
1453               <br />Temp Directory:<br />
1454               <?php echo EP_TEMP_DIRECTORY; ?><br />
1455               <?php if (is_writable(EP_TEMP_DIRECTORY)) { ?><font color="#009900">Temp Dir is Writable</font><?php } else { ?><font color="#FF0000">Temp Dir is NOT Writable</font><?php } ?><br />
1456               Magic Quotes is: <?php if (ini_get('magic_quotes_runtime') == 1){ echo 'on'; } else { echo 'off'; } ?><br />
1457               register_globals is: <?php if (ini_get(register_globals)) { echo 'on'; } else { echo 'off'; } ?><br />
1458               Split files on: <?php echo EP_SPLIT_MAX_RECORDS; ?> records<br />
1459               Model Num Size: <?php echo EP_MODEL_NUMBER_SIZE; ?><br />
1460               Price with tax: <?php echo (EP_PRICE_WITH_TAX?'true':'false'); ?><br />
1461               Calc Precision: <?php echo EP_PRECISION; ?><br />
1462               Replace quotes: <?php echo (EP_REPLACE_QUOTES?'true':'false'); ?><br />
1463               Field seperator:
1464               <?php switch ($ep_separator) {
1465                 case "\t";
1466                   echo 'tab';
1467                   break;
1468                 case ",";
1469                   echo 'comma';
1470                   break;
1471                 case ";";
1472                   echo 'semi-colon';
1473                   break;
1474                 case "~";
1475                   echo 'tilde';
1476                   break;
1477                 case "-";
1478                   echo 'dash';
1479                   break;
1480                 case "*";
1481                   echo 'splat';
1482                   break;
1483               }
1484               ?><br />
1485               Excel safe output: <?php echo (EP_EXCEL_SAFE_OUTPUT?'true':'false'); ?><br />
1486               Preserve tab/cr/lf: <?php echo (EP_PRESERVE_TABS_CR_LF?'true':'false'); ?><br />
1487               Category depth: <?php echo EP_MAX_CATEGORIES; ?><br />
1488               Enable attributes: <?php echo (EP_PRODUCTS_WITH_ATTRIBUTES?'true':'false'); ?><br />
1489               SEF Froogle URLS: <?php echo (EP_FROOGLE_SEF_URLS?'true':'false'); ?><br />
1490  
1491               More Pics: <?php echo (EP_MORE_PICS_6_SUPPORT?'true':'false'); ?><br />
1492               Unknown Pics: <?php echo (EP_UNKNOWN_ADD_IMAGES_SUPPORT?'true':'false'); ?><br />
1493               HTC: <?php echo (EP_HTC_SUPPORT?'true':'false'); ?><br />
1494               SPPC: <?php echo (EP_SPPC_SUPPORT?'true':'false'); ?><br />
1495               Extra Fields: <?php echo (EP_EXTRA_FIELDS_SUPPORT?'true':'false'); ?><br />
1496               <br />
1497               <div style="padding: 10px; background-color: #ffffCC">Please see the manual in this contribution's package for help in changing these settings.</div>
1498               </td></tr></table>
1499  
1500  
1501            </td>
1502            <?php } ?>
1503          </tr>
1504        </table>
1505      </td>
1506   </tr>
1507  </table>
1508  
1509  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
1510  
1511  <p></p>
1512  <p></p><p><br />
1513  </p></body>
1514  </html>
1515  
1516  <?php
1517  //*******************************
1518  //*******************************
1519  // end: MAIN MENU
1520  //*******************************
1521  //*******************************
1522  
1523  
1524  
1525  
1526  
1527  
1528  ///////////////////////////////////////////////////////////////////////////////////
1529  ///////////////////////////////////////////////////////////////////////////////////
1530  // 
1531  // ep_create_filelayout()
1532  // 
1533  ///////////////////////////////////////////////////////////////////////////////////
1534  ///////////////////////////////////////////////////////////////////////////////////
1535  ///////////////////////////////////////////////////////////////////////////////////
1536  function ep_create_filelayout($dltype, $attribute_options_array, $languages, $custom_fields){
1537  
1538      // depending on the type of the download the user wanted, create a file layout for it.
1539      $fieldmap = array(); // default to no mapping to change internal field names to external.
1540  
1541      // build filters
1542      $sql_filter = '';
1543      if (!empty($_GET['epcust_category_filter'])) {
1544        $sub_categories = array();
1545        $categories_query_addition = 'ptoc.categories_id = ' . (int)$_GET['epcust_category_filter'] . '';
1546        tep_get_sub_categories($sub_categories, $_GET['epcust_category_filter']);
1547        foreach ($sub_categories AS $ckey => $category ) {
1548          $categories_query_addition .= ' or ptoc.categories_id = ' . (int)$category . '';
1549        }
1550        $sql_filter .= ' and (' . $categories_query_addition . ')';
1551      }
1552      if ($_GET['epcust_manufacturer_filter']!='') {
1553        $sql_filter .= ' and p.manufacturers_id = ' . (int)$_GET['epcust_manufacturer_filter'];
1554      }
1555      if ($_GET['epcust_status_filter']!='') {
1556        $sql_filter .= ' and p.products_status = ' . (int)$_GET['epcust_status_filter'];
1557      }
1558  
1559      // /////////////////////////////////////////////////////////////////////
1560      //
1561      // Start: Support for other contributions
1562      //
1563      // /////////////////////////////////////////////////////////////////////
1564      
1565      $ep_additional_layout_product = '';
1566      $ep_additional_layout_product_select = '';
1567      $ep_additional_layout_product_description = '';
1568      $ep_additional_layout_pricing = '';
1569      
1570      if ( $dltype == 'full'){
1571          foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
1572            $ep_additional_layout_product .= '$filelayout[\'v_' . $key . '\'] = $iii++;
1573                                              ';
1574            $ep_additional_layout_product_select .= 'p.' . $key . ' as v_' . $key . ',';
1575          }
1576      }
1577  
1578      if (EP_MORE_PICS_6_SUPPORT == true) { 
1579        $ep_additional_layout_product .= '$filelayout[\'v_products_subimage1\'] = $iii++;
1580                                          $filelayout[\'v_products_subimage2\'] = $iii++;
1581                                          $filelayout[\'v_products_subimage3\'] = $iii++;
1582                                          $filelayout[\'v_products_subimage4\'] = $iii++;
1583                                          $filelayout[\'v_products_subimage5\'] = $iii++;
1584                                          $filelayout[\'v_products_subimage6\'] = $iii++;
1585                                          ';
1586      }    
1587      if (EP_MORE_PICS_6_SUPPORT == true) { 
1588        $ep_additional_layout_product_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,';
1589      }    
1590  
1591      if (EP_UNKNOWN_ADD_IMAGES_SUPPORT == true) { 
1592        $ep_additional_layout_product .= '$filelayout[\'v_products_mimage\'] = $iii++;
1593                                          $filelayout[\'v_products_bimage\'] = $iii++;
1594                                          $filelayout[\'v_products_subimage1\'] = $iii++;
1595                                          $filelayout[\'v_products_bsubimage1\'] = $iii++;
1596                                          $filelayout[\'v_products_subimage2\'] = $iii++;
1597                                          $filelayout[\'v_products_bsubimage2\'] = $iii++;
1598                                          $filelayout[\'v_products_subimage3\'] = $iii++;
1599                                          $filelayout[\'v_products_bsubimage3\'] = $iii++;
1600                                          ';
1601      }
1602      if (EP_UNKNOWN_ADD_IMAGES_SUPPORT == true) { 
1603        $ep_additional_layout_product_select .= 'p.products_mimage as v_products_mimage, p.products_bimage as v_products_bimage, p.products_subimage1 as v_products_subimage1, p.products_bsubimage1 as v_products_bsubimage1, p.products_subimage2 as v_products_subimage2, p.products_bsubimage2 as v_products_bsubimage2, p.products_subimage3 as v_products_subimage3, p.products_bsubimage3 as v_products_bsubimage3,';
1604      }
1605      
1606      if (EP_SPPC_SUPPORT == true) { 
1607        $ep_additional_layout_pricing .= '$filelayout[\'v_customer_price_1\'] = $iii++;
1608                                          $filelayout[\'v_customer_group_id_1\'] = $iii++;
1609                                          $filelayout[\'v_customer_price_2\'] = $iii++;
1610                                          $filelayout[\'v_customer_group_id_2\'] = $iii++;
1611                                          $filelayout[\'v_customer_price_3\'] = $iii++;
1612                                          $filelayout[\'v_customer_group_id_3\'] = $iii++;
1613                                          $filelayout[\'v_customer_price_4\'] = $iii++;
1614                                          $filelayout[\'v_customer_group_id_4\'] = $iii++;
1615                                          ';
1616      }
1617      
1618      if (EP_HTC_SUPPORT == true) {
1619        $ep_additional_layout_product_description .= '$filelayout[\'v_products_head_title_tag_\'.$lang[\'id\']]    = $iii++;
1620                                                      $filelayout[\'v_products_head_desc_tag_\'.$lang[\'id\']]     = $iii++;
1621                                                      $filelayout[\'v_products_head_keywords_tag_\'.$lang[\'id\']] = $iii++;
1622                                                      ';
1623      }
1624  
1625      // /////////////////////////////////////////////////////////////////////
1626      // End: Support for other contributions
1627      // /////////////////////////////////////////////////////////////////////
1628  
1629  
1630  
1631      switch( $dltype ){
1632  
1633      case 'full':
1634          // The file layout is dynamically made depending on the number of languages
1635          $iii = 0;
1636          $filelayout = array();
1637  
1638          $filelayout['v_products_model'] = $iii++;
1639  
1640          foreach ($languages as $key => $lang){
1641              $filelayout['v_products_name_'.$lang['id']]        = $iii++;
1642              $filelayout['v_products_description_'.$lang['id']] = $iii++;
1643              $filelayout['v_products_url_'.$lang['id']]         = $iii++;
1644              foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
1645                $filelayout['v_' . $key . '_'.$lang['id']]         = $iii++;
1646              }
1647              if (!empty($ep_additional_layout_product_description)) {
1648                eval($ep_additional_layout_product_description);
1649              }
1650              
1651          }
1652  
1653          $filelayout['v_products_image'] = $iii++;
1654  
1655          if (!empty($ep_additional_layout_product)) {
1656            eval($ep_additional_layout_product);
1657          }
1658  
1659          $filelayout['v_products_price']    = $iii++;
1660  
1661          if (!empty($ep_additional_layout_pricing)) {
1662            eval($ep_additional_layout_pricing);
1663          }
1664  
1665          $filelayout['v_products_quantity'] = $iii++;
1666          $filelayout['v_products_weight']   = $iii++;
1667          $filelayout['v_date_avail']        = $iii++;
1668          $filelayout['v_date_added']        = $iii++;
1669  
1670          // build the categories name section of the array based on the number of categores the user wants to have
1671          for($i=1; $i<EP_MAX_CATEGORIES+1; $i++){
1672              $filelayout['v_categories_image_' . $i] = $iii++;
1673              foreach ($languages as $key => $lang){
1674                  $filelayout['v_categories_name_' . $i . '_' . $lang['id']] = $iii++;
1675              }
1676          }
1677  
1678          $filelayout['v_manufacturers_name'] = $iii++;
1679  
1680          // VJ product attribs begin
1681          $attribute_options_count = 1;
1682          foreach ($attribute_options_array as $tkey => $attribute_options_values) {
1683              $filelayout['v_attribute_options_id_'.$attribute_options_count] = $iii++;
1684              foreach ($languages as $tkey => $lang ) {
1685                  $filelayout['v_attribute_options_name_'.$attribute_options_count.'_'.$lang['id']] = $iii++;
1686              }
1687  
1688              $attribute_values_query = "select products_options_values_id  from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options_values['products_options_id'] . "' order by products_options_values_id";
1689              $attribute_values_values = tep_db_query($attribute_values_query);
1690  
1691              $attribute_values_count = 1;
1692              while ($attribute_values = tep_db_fetch_array($attribute_values_values)) {
1693                  $filelayout['v_attribute_values_id_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
1694                  foreach ($languages as $tkey => $lang ) {
1695                      $filelayout['v_attribute_values_name_'.$attribute_options_count.'_'.$attribute_values_count.'_'.$lang['id']] = $iii++;
1696                  }
1697                  $filelayout['v_attribute_values_price_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
1698                  //// attributes stock add start        
1699                  if ( EP_PRODUCTS_ATTRIBUTES_STOCK == true ) { 
1700                      $filelayout['v_attribute_values_stock_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
1701                  }                
1702                  //// attributes stock add end         
1703                  $attribute_values_count++;
1704               }
1705              $attribute_options_count++;
1706          }
1707          // VJ product attribs end
1708  
1709          $filelayout['v_tax_class_title']  = $iii++;
1710          $filelayout['v_status']           = $iii++;
1711  
1712          $filelayout_sql = "SELECT
1713              p.products_id as v_products_id,
1714              p.products_model as v_products_model,
1715              p.products_image as v_products_image,
1716              $ep_additional_layout_product_select
1717              p.products_price as v_products_price,
1718              p.products_weight as v_products_weight,
1719              p.products_date_available as v_date_avail,
1720              p.products_date_added as v_date_added,
1721              p.products_tax_class_id as v_tax_class_id,
1722              p.products_quantity as v_products_quantity,
1723              p.manufacturers_id as v_manufacturers_id,
1724              subc.categories_id as v_categories_id,
1725              p.products_status as v_status
1726              FROM
1727              ".TABLE_PRODUCTS." as p,
1728              ".TABLE_CATEGORIES." as subc,
1729              ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
1730              WHERE
1731              p.products_id = ptoc.products_id AND
1732              ptoc.categories_id = subc.categories_id
1733              " . $sql_filter;
1734  
1735          break;
1736  
1737      case 'priceqty':
1738          $iii = 0;
1739          $filelayout = array();
1740  
1741          $filelayout['v_products_model']    = $iii++;
1742          $filelayout['v_products_price']    = $iii++;
1743          $filelayout['v_products_quantity'] = $iii++;
1744          
1745          if (!empty($ep_additional_layout_pricing)) {
1746            eval($ep_additional_layout_pricing);
1747          }
1748  
1749          $filelayout_sql = "SELECT
1750              p.products_id as v_products_id,
1751              p.products_model as v_products_model,
1752              p.products_price as v_products_price,
1753              p.products_tax_class_id as v_tax_class_id,
1754              p.products_quantity as v_products_quantity
1755              FROM
1756              ".TABLE_PRODUCTS." as p
1757              ";
1758          break;
1759  
1760      case 'custom':
1761          $iii = 0;
1762          $filelayout = array();
1763  
1764          $filelayout['v_products_model'] = $iii++;
1765  
1766          if (!empty($_GET['epcust_status'])) { $filelayout['v_status'] = $iii++; }
1767  
1768          foreach ($languages as $key => $lang){
1769              if (!empty($_GET['epcust_name'])) { $filelayout['v_products_name_'.$lang['id']] = $iii++; }
1770              if (!empty($_GET['epcust_description'])) { $filelayout['v_products_description_'.$lang['id']] = $iii++; }
1771              if (!empty($_GET['epcust_url'])) { $filelayout['v_products_url_'.$lang['id']] = $iii++; }
1772              foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
1773                if (!empty($_GET['epcust_' . $key])) { $filelayout['v_' . $key . '_'.$lang['id']] = $iii++; }
1774              }
1775          }
1776  
1777          if (!empty($_GET['epcust_image'])) {
1778            $filelayout['v_products_image'] = $iii++;
1779            
1780            if (!empty($ep_additional_layout_product)) {
1781              eval($ep_additional_layout_product);
1782            }
1783          }
1784   
1785          foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
1786              if (!empty($_GET['epcust_' . $key])) {
1787                  $filelayout['v_' . $key] = $iii++;
1788                  $ep_additional_layout_product_select .= 'p.' . $key . ' as v_' . $key . ',';
1789              }
1790          }
1791  
1792          if (!empty($_GET['epcust_price'])) { $filelayout['v_products_price'] = $iii++; }
1793          if (!empty($_GET['epcust_quantity'])) { $filelayout['v_products_quantity'] = $iii++; }
1794          if (!empty($_GET['epcust_weight'])) { $filelayout['v_products_weight'] = $iii++; }
1795          if (!empty($_GET['epcust_avail'])) { $filelayout['v_date_avail'] = $iii++; }
1796          if (!empty($_GET['epcust_date_added'])) { $filelayout['v_date_added'] = $iii++; }
1797          
1798          if (!empty($_GET['epcust_category'])) {
1799            // build the categories name section of the array based on the number 
1800            // of categores the user wants to have
1801            for($i=1; $i<=EP_MAX_CATEGORIES; $i++){
1802              $filelayout['v_categories_image_'.$i] = $iii++;
1803              foreach ($languages as $key => $lang){
1804                $filelayout['v_categories_name_'.$i.'_'.$lang['id']] = $iii++;
1805              }
1806            }
1807          }
1808  
1809          if (!empty($_GET['epcust_manufacturer'])) { $filelayout['v_manufacturers_name'] = $iii++; }
1810  
1811          if (!empty($_GET['epcust_attributes'])) {
1812            // VJ product attribs begin
1813            $attribute_options_count = 1;
1814            foreach ($attribute_options_array as $tkey => $attribute_options_values) {
1815              $filelayout['v_attribute_options_id_'.$attribute_options_count] = $iii++;
1816              foreach ($languages as $tkey => $lang ) {
1817                  $filelayout['v_attribute_options_name_'.$attribute_options_count.'_'.$lang['id']] = $iii++;
1818              }
1819  
1820              $attribute_values_query = "select products_options_values_id  from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options_values['products_options_id'] . "' order by products_options_values_id";
1821              $attribute_values_values = tep_db_query($attribute_values_query);
1822  
1823              $attribute_values_count = 1;
1824              while ($attribute_values = tep_db_fetch_array($attribute_values_values)) {
1825                  $filelayout['v_attribute_values_id_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
1826                  foreach ($languages as $tkey => $lang ) {
1827                      $filelayout['v_attribute_values_name_'.$attribute_options_count.'_'.$attribute_values_count.'_'.$lang['id']] = $iii++;
1828                  }
1829                  $filelayout['v_attribute_values_price_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
1830                  //// attributes stock add start        
1831                  if ( EP_PRODUCTS_ATTRIBUTES_STOCK == true ) { 
1832                      $filelayout['v_attribute_values_stock_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
1833                  }                
1834                  //// attributes stock add end         
1835                  $attribute_values_count++;
1836               }
1837              $attribute_options_count++;
1838            }
1839            // VJ product attribs end
1840          }
1841          if (!empty($_GET['epcust_tax_class'])) { $filelayout['v_tax_class_title'] = $iii++; }
1842          if (!empty($_GET['epcust_comment'])) { $filelayout['v_products_comment'] = $iii++; }
1843  
1844          $filelayout_sql = "SELECT
1845              p.products_id as v_products_id,
1846              p.products_model as v_products_model,
1847              p.products_status as v_status,
1848              p.products_price as v_products_price,
1849              p.products_quantity as v_products_quantity,
1850              p.products_weight as v_products_weight,
1851              p.products_image as v_products_image,
1852              $ep_additional_layout_product_select
1853              p.manufacturers_id as v_manufacturers_id,
1854              p.products_date_available as v_date_avail,
1855              p.products_date_added as v_date_added,
1856              p.products_tax_class_id as v_tax_class_id,
1857              subc.categories_id as v_categories_id
1858              FROM
1859              ".TABLE_PRODUCTS." as p,
1860              ".TABLE_CATEGORIES." as subc,
1861              ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
1862              WHERE
1863              p.products_id = ptoc.products_id AND
1864              ptoc.categories_id = subc.categories_id
1865              " . $sql_filter;
1866          break;
1867  
1868      case 'category':
1869          $iii = 0;
1870          $filelayout = array();
1871          
1872          $filelayout['v_products_model'] = $iii++;
1873  
1874          for($i=1; $i<EP_MAX_CATEGORIES+1; $i++){
1875              $filelayout['v_categories_image_'.$i] = $iii++;
1876              foreach ($languages as $key => $lang){
1877                      $filelayout['v_categories_name_'.$i.'_'.$lang['id']] = $iii++;
1878              }
1879          }
1880  
1881          $filelayout_sql = "SELECT
1882              p.products_id as v_products_id,
1883              p.products_model as v_products_model,
1884              subc.categories_id as v_categories_id
1885              FROM
1886              ".TABLE_PRODUCTS." as p,
1887              ".TABLE_CATEGORIES." as subc,
1888              ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc            
1889              WHERE
1890              p.products_id = ptoc.products_id AND
1891              ptoc.categories_id = subc.categories_id
1892              ";
1893          break;
1894  
1895      case 'extra_fields':
1896      // start EP for product extra field ============================= DEVSOFTVN - 10/20/2005     
1897          $iii = 0;
1898          $filelayout = array(
1899              'v_products_model'        => $iii++,
1900              'v_products_extra_fields_name'        => $iii++, 
1901              'v_products_extra_fields_id'        => $iii++,
1902  //            'v_products_id'        => $iii++,
1903              'v_products_extra_fields_value'        => $iii++,
1904                          );
1905      
1906          $filelayout_sql = "SELECT
1907                          p.products_id as v_products_id,
1908                          p.products_model as v_products_model,
1909                          subc.products_extra_fields_id as v_products_extra_fields_id,
1910                          subc.products_extra_fields_value as v_products_extra_fields_value,
1911                          ptoc.products_extra_fields_name as v_products_extra_fields_name
1912                          FROM
1913                          ".TABLE_PRODUCTS." as p,
1914                          ".TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS." as subc,
1915                          ".TABLE_PRODUCTS_EXTRA_FIELDS." as ptoc
1916                          WHERE
1917                          p.products_id = subc.products_id AND
1918                          ptoc.products_extra_fields_id = subc.products_extra_fields_id
1919                          ";    
1920      // end of EP for extra field code ======= DEVSOFTVN================       
1921          break;
1922  
1923  
1924      case 'froogle':
1925          // this is going to be a little interesting because we need
1926          // a way to map from internal names to external names
1927          //
1928          // Before it didn't matter, but with froogle needing particular headers,
1929          // The file layout is dynamically made depending on the number of languages
1930          $iii = 0;
1931          $filelayout = array();
1932  
1933          $filelayout['v_froogle_products_url_1'] = $iii++;
1934          $filelayout['v_froogle_products_name_'.EP_DEFAULT_LANGUAGE_ID] = $iii++;
1935          $filelayout['v_froogle_products_description_'.EP_DEFAULT_LANGUAGE_ID] = $iii++;
1936          $filelayout['v_products_price'] = $iii++;
1937          $filelayout['v_products_fullpath_image'] = $iii++;
1938          $filelayout['v_froogle_product_id'] = $iii++;
1939          $filelayout['v_froogle_quantitylevel'] = $iii++;
1940          $filelayout['v_category_fullpath'] = $iii++;
1941          $filelayout['v_froogle_exp_date'] = $iii++;
1942          $filelayout['v_froogle_currency'] = $iii++;
1943  
1944          $iii=0;
1945          $fileheaders = array();
1946  
1947          // EP Support mapping new names to the export headers.
1948          // use the $fileheaders[''] vars to do that.
1949          $fileheaders['link'] = $iii++;
1950          $fileheaders['title'] = $iii++;
1951          $fileheaders['description'] = $iii++;
1952          $fileheaders['price'] = $iii++;
1953          $fileheaders['image_link'] = $iii++;
1954          $fileheaders['id'] = $iii++;
1955          $fileheaders['quantity'] = $iii++;
1956          $fileheaders['product_type'] = $iii++;
1957          $fileheaders['expiration_date'] = $iii++;
1958          $fileheaders['currency'] = $iii++;
1959  
1960          $filelayout_sql = "SELECT
1961              p.products_id as v_products_id,
1962              p.products_model as v_products_model,
1963              p.products_image as v_products_image,
1964              p.products_price as v_products_price,
1965              p.products_weight as v_products_weight,
1966              p.products_date_added as v_date_added,
1967              p.products_date_available as v_date_avail,
1968              p.products_tax_class_id as v_tax_class_id,
1969              p.products_quantity as v_products_quantity,
1970              p.manufacturers_id as v_manufacturers_id,
1971              subc.categories_id as v_categories_id
1972              FROM
1973              ".TABLE_PRODUCTS." as p,
1974              ".TABLE_CATEGORIES." as subc,
1975              ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
1976              WHERE
1977              p.products_id = ptoc.products_id AND
1978              ptoc.categories_id = subc.categories_id
1979              " . $sql_filter;
1980          break;
1981  
1982      // VJ product attributes begin
1983      case 'attrib':
1984          $iii = 0;
1985          $filelayout = array();
1986  
1987          $filelayout['v_products_model'] = $iii++;
1988  
1989          $attribute_options_count = 1;
1990          foreach ($attribute_options_array as $tkey1 => $attribute_options_values) {
1991              $filelayout['v_attribute_options_id_'.$attribute_options_count] = $iii++;
1992              foreach ($languages as $tkey => $lang ) {
1993                  $filelayout['v_attribute_options_name_'.$attribute_options_count.'_'.$lang['id']] = $iii++;
1994              }
1995  
1996              $attribute_values_query = "select products_options_values_id  from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options_values['products_options_id'] . "' order by products_options_values_id";
1997              $attribute_values_values = tep_db_query($attribute_values_query);
1998  
1999              $attribute_values_count = 1;
2000              while ($attribute_values = tep_db_fetch_array($attribute_values_values)) {
2001                  $filelayout['v_attribute_values_id_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
2002                  foreach ($languages as $tkey2 => $lang ) {
2003                      $filelayout['v_attribute_values_name_'.$attribute_options_count.'_'.$attribute_values_count.'_'.$lang['id']] = $iii++;
2004                  }
2005                  $filelayout['v_attribute_values_price_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
2006                  //// attributes stock add start        
2007                  if ( EP_PRODUCTS_ATTRIBUTES_STOCK    == true ) { 
2008                      $header_array['v_attribute_values_stock_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
2009                  }                
2010                  //// attributes stock add end         
2011                  $attribute_values_count++;
2012              }
2013              $attribute_options_count++;
2014          }
2015  
2016          $filelayout_sql = "SELECT
2017                              p.products_id as v_products_id,
2018                              p.products_model as v_products_model
2019                              FROM
2020                              ".TABLE_PRODUCTS." as p
2021                              ";
2022  
2023          break;
2024          // VJ product attributes end
2025      }
2026  
2027  
2028      $filelayout_count = count($filelayout);
2029  
2030    return array($filelayout, $filelayout_count, $filelayout_sql, $fileheaders);
2031  
2032  }
2033  
2034  
2035  
2036  
2037  
2038  
2039  ///////////////////////////////////////////////////////////////////////////////////
2040  ///////////////////////////////////////////////////////////////////////////////////
2041  // 
2042  // process_row()
2043  //
2044  //   Processes one row of the import file
2045  // 
2046  ///////////////////////////////////////////////////////////////////////////////////
2047  ///////////////////////////////////////////////////////////////////////////////////
2048  ///////////////////////////////////////////////////////////////////////////////////
2049  function process_row( $item1, $filelayout, $filelayout_count, $default_these, $ep_separator, $languages, $custom_fields ) {
2050  
2051      // first we clean up the row of data
2052      if (EP_EXCEL_SAFE_OUTPUT == true) {
2053        $items = $item1;
2054      } else {
2055        // chop blanks from each end
2056        $item1 = ltrim(rtrim($item1));
2057      
2058        // blow it into an array, splitting on the tabs
2059        $items = explode($ep_separator, $item1);
2060      }
2061  
2062      // make sure all non-set things are set to '';
2063      // and strip the quotes from the start and end of the stings.
2064      // escape any special chars for the database.
2065      foreach( $filelayout as $key => $value){
2066          $i = $filelayout[$key];
2067          if (isset($items[$i]) == false) {
2068              $items[$i]='';
2069          } else {
2070              // Check to see if either of the magic_quotes are turned on or off;
2071              // And apply filtering accordingly.
2072              if (function_exists('ini_get')) {
2073                  //echo "Getting ready to check magic quotes<br />";
2074                  if (ini_get('magic_quotes_runtime') == 1){
2075                      // The magic_quotes_runtime are on, so lets account for them
2076                      // check if the first & last character are quotes;
2077                      // if it is, chop off the quotes.
2078                      if (substr($items[$i],-1) == '"' && substr($items[$i],0,1) == '"'){
2079                          $items[$i] = substr($items[$i],2,strlen($items[$i])-4);
2080                      }
2081                      // now any remaining doubled double quotes should be converted to one doublequote
2082                      if (EP_REPLACE_QUOTES == true){
2083                          if (EP_EXCEL_SAFE_OUTPUT == true) {
2084                            $items[$i] = str_replace('\"\"',"&#34;",$items[$i]);
2085                          }
2086                          $items[$i] = str_replace('\"',"&#34;",$items[$i]);
2087                          $items[$i] = str_replace("\'","&#39;",$items[$i]);
2088                      }
2089                  } else { // no magic_quotes are on
2090                      // check if the last character is a quote;
2091                      // if it is, chop off the 1st and last character of the string.
2092                      if (substr($items[$i],-1) == '"' && substr($items[$i],0,1) == '"'){
2093                          $items[$i] = substr($items[$i],1,strlen($items[$i])-2);
2094                      }
2095                      // now any remaining doubled double quotes should be converted to one doublequote
2096                      if (EP_REPLACE_QUOTES == true){
2097                          if (EP_EXCEL_SAFE_OUTPUT == true) {
2098                            $items[$i] = str_replace('""',"&#34;",$items[$i]);
2099                          }
2100                          $items[$i] = str_replace('"',"&#34;",$items[$i]);
2101                          $items[$i] = str_replace("'","&#39;",$items[$i]);
2102                      }
2103                  }
2104              }
2105          }
2106      }
2107  
2108  
2109      // /////////////////////////////////////////////////////////////
2110      // Do specific functions without processing entire range of vars
2111      // /////////////////////////////
2112      // first do product extra fields
2113      if (isset($items[$filelayout['v_products_extra_fields_id']]) ){    
2114      
2115          // EP for product extra fields Contrib by minhmaster DEVSOFTVN ==========
2116          $v_products_extra_fields_id = $items[$filelayout['v_products_extra_fields_id']];
2117  //        $v_products_id    =    $items[$filelayout['v_products_id']];
2118          $v_products_extra_fields_value    =    $items[$filelayout['v_products_extra_fields_value']];
2119          
2120          $sql = "SELECT p.products_id as v_products_id FROM ".TABLE_PRODUCTS." as p WHERE p.products_model = '" . $v_products_model . "'";
2121          $result = tep_db_query($sql);
2122          $row =  tep_db_fetch_array($result);
2123  
2124          $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 ."')";
2125  
2126          if (tep_db_num_rows(tep_db_query($sql_exist)) > 0) {
2127              $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 ."')";
2128              $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 />";
2129          } else {
2130              $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."')";
2131              $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 />";
2132          }
2133  
2134          $result = tep_db_query($sql_extra_field);
2135          
2136          echo $str_err_report;
2137          // end (EP for product extra fields Contrib by minhmt DEVSOFTVN) ============
2138          
2139      // /////////////////////
2140      // or do product deletes
2141      } elseif ( $items[$filelayout['v_status']] == EP_DELETE_IT ) {
2142        // Get the ID
2143        $sql = "SELECT p.products_id as v_products_id    FROM ".TABLE_PRODUCTS." as p WHERE p.products_model = '" . $items[$filelayout['v_products_model']] . "'";
2144        $result = tep_db_query($sql);
2145        $row =  tep_db_fetch_array($result);
2146        if (tep_db_num_rows($result) == 1 ) {
2147          tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'");
2148  
2149          $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'");
2150          $product_categories = tep_db_fetch_array($product_categories_query);
2151  
2152          if ($product_categories['total'] == '0') {
2153             tep_remove_product($row['v_products_id']);
2154          }
2155  
2156          if (USE_CACHE == 'true') {
2157            tep_reset_cache_block('categories');
2158            tep_reset_cache_block('also_purchased');
2159          }
2160          echo "Deleted product " . $items[$filelayout['v_products_model']] . " from the database<br />";
2161          
2162        } else {
2163            echo "Did not delete " . $items['v_products_model'] . " since it is not unique ";
2164        }
2165    
2166      // //////////////////////////////////
2167      // or do regular product processing
2168      // //////////////////////////////////
2169      } else {
2170  
2171          // /////////////////////////////////////////////////////////////////////
2172          //
2173          // Start: Support for other contributions in products table
2174          //
2175          // /////////////////////////////////////////////////////////////////////
2176          $ep_additional_select = '';
2177  
2178          if (EP_MORE_PICS_6_SUPPORT == true) { 
2179            $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,';
2180          }    
2181  
2182          if (EP_UNKNOWN_ADD_IMAGES_SUPPORT == true) { 
2183            $ep_additional_select .= 'p.products_mimage as v_products_mimage,p.products_bimage as v_products_bimage,p.products_subimage1 as v_products_subimage1,p.products_bsubimage1 as v_products_bsubimage1,p.products_subimage2 as v_products_subimage2,p.products_bsubimage2 as v_products_bsubimage2,p.products_subimage3 as v_products_subimage3,p.products_bsubimage3 as v_products_bsubimage3,';
2184          }
2185  
2186          foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
2187            $ep_additional_select .= 'p.' . $key . ' as v_' . $key . ',';
2188          }
2189  
2190  
2191          // /////////////////////////////////////////////////////////////////////
2192          // End: Support for other contributions in products table
2193          // /////////////////////////////////////////////////////////////////////
2194      
2195      
2196          // now do a query to get the record's current contents
2197          $sql = "SELECT
2198                      p.products_id as v_products_id,
2199                      p.products_model as v_products_model,
2200                      p.products_image as v_products_image,
2201                      $ep_additional_select
2202                      p.products_price as v_products_price,
2203                      p.products_weight as v_products_weight,
2204                      p.products_date_available as v_date_avail,
2205                      p.products_date_added as v_date_added,
2206                      p.products_tax_class_id as v_tax_class_id,
2207                      p.products_quantity as v_products_quantity,
2208                      p.manufacturers_id as v_manufacturers_id,
2209                      subc.categories_id as v_categories_id,
2210                      p.products_status as v_status_current
2211                  FROM
2212                      ".TABLE_PRODUCTS." as p,
2213                      ".TABLE_CATEGORIES." as subc,
2214                      ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
2215                  WHERE
2216                      p.products_model = '" . $items[$filelayout['v_products_model']] . "' AND
2217                      p.products_id = ptoc.products_id AND
2218                      ptoc.categories_id = subc.categories_id
2219                  LIMIT 1
2220              ";
2221  
2222          $result = tep_db_query($sql);
2223          $row =  tep_db_fetch_array($result);
2224  
2225          // determine processing status based on dropdown choice on EP menu
2226          if ((sizeof($row) > 1) && ($_POST['imput_mode'] == "normal" || $_POST['imput_mode'] == "update")) {
2227              $process_product = true;
2228          } elseif ((sizeof($row) == 1) && ($_POST['imput_mode'] == "normal" || $_POST['imput_mode'] == "addnew")) {
2229              $process_product = true;
2230          } else {
2231              $process_product = false;
2232          }
2233  
2234          if ($process_product == true) {
2235  
2236              while ($row){
2237                  // OK, since we got a row, the item already exists.
2238                  // Let's get all the data we need and fill in all the fields that need to be defaulted 
2239                  // to the current values for each language, get the description and set the vals
2240                  foreach ($languages as $key => $lang){
2241                      // products_name, products_description, products_url
2242                      $sql2 = "SELECT * 
2243                              FROM ".TABLE_PRODUCTS_DESCRIPTION."
2244                              WHERE
2245                                  products_id = " . $row['v_products_id'] . " AND
2246                                  language_id = '" . $lang['id'] . "'
2247                              LIMIT 1
2248                              ";
2249                      $result2 = tep_db_query($sql2);
2250                      $row2 =  tep_db_fetch_array($result2);
2251                      // Need to report from ......_name_1 not ..._name_0
2252                      $row['v_products_name_' . $lang['id']]         = $row2['products_name'];
2253                      $row['v_products_description_' . $lang['id']]     = $row2['products_description'];
2254                      $row['v_products_url_' . $lang['id']]         = $row2['products_url'];
2255                      foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
2256                        $row['v_' . $key . '_' . $lang['id']]         = $row2[$key];
2257                      }
2258                      // header tags controller support
2259                      if(isset($filelayout['v_products_head_title_tag_' . $lang['id'] ])){
2260                          $row['v_products_head_title_tag_' . $lang['id']]     = $row2['products_head_title_tag'];
2261                          $row['v_products_head_desc_tag_' . $lang['id']]     = $row2['products_head_desc_tag'];
2262                          $row['v_products_head_keywords_tag_' . $lang['id']]     = $row2['products_head_keywords_tag'];
2263                      }
2264                      // end: header tags controller support
2265                  }
2266          
2267                  // start with v_categories_id
2268                  // Get the category description
2269                  // set the appropriate variable name
2270                  // if parent_id is not null, then follow it up.
2271                  $thecategory_id = $row['v_categories_id'];
2272                  for( $categorylevel=1; $categorylevel<=(EP_MAX_CATEGORIES+1); $categorylevel++){
2273                      if ($thecategory_id){
2274          
2275                          $sql3 = "SELECT parent_id, 
2276                                          categories_image
2277                                   FROM ".TABLE_CATEGORIES."
2278                                   WHERE    
2279                                          categories_id = " . $thecategory_id . '';
2280                          $result3 = tep_db_query($sql3);
2281                          if ($row3 = tep_db_fetch_array($result3)) {
2282                              $temprow['v_categories_image_' . $categorylevel] = $row3['categories_image'];
2283                          }
2284          
2285                          foreach ($languages as $key => $lang){
2286                              $sql2 = "SELECT categories_name
2287                                       FROM ".TABLE_CATEGORIES_DESCRIPTION."
2288                                       WHERE    
2289                                              categories_id = " . $thecategory_id . " AND
2290                                              language_id = " . $lang['id'];
2291                              $result2 = tep_db_query($sql2);
2292                              if ($row2 =  tep_db_fetch_array($result2)) {
2293                                  $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] = $row2['categories_name'];
2294                              }
2295                          }
2296          
2297                          // now get the parent ID if there was one
2298                          $theparent_id = $row3['parent_id'];
2299                          if ($theparent_id != ''){
2300                              // there was a parent ID, lets set thecategoryid to get the next level
2301                              $thecategory_id = $theparent_id;
2302                          } else {
2303                              // we have found the top level category for this item,
2304                              $thecategory_id = false;
2305                          }
2306           
2307                      } else {
2308                          $temprow['v_categories_image_' . $categorylevel] = '';
2309                          foreach ($languages as $key => $lang){
2310                              $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] = '';
2311                          }
2312                      }
2313                  }
2314                  // temprow has the old style low to high level categories.
2315                  $newlevel = 1;
2316                  // let's turn them into high to low level categories
2317                  for( $categorylevel=EP_MAX_CATEGORIES+1; $categorylevel>0; $categorylevel--){
2318                      $found = false;
2319                      if ($temprow['v_categories_image_' . $categorylevel] != ''){
2320                          $row['v_categories_image_' . $newlevel] = $temprow['v_categories_image_' . $categorylevel];
2321                          $found = true;
2322                      }
2323                      foreach ($languages as $key => $lang){
2324                          if ($temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']] != ''){
2325                              $row['v_categories_name_' . $newlevel . '_' . $lang['id']] = $temprow['v_categories_name_' . $categorylevel . '_' . $lang['id']];
2326                              $found = true;
2327                          }
2328                      }
2329                      if ($found == true) {
2330                          $newlevel++;
2331                      }
2332                  }
2333  
2334  
2335                  // default the manufacturer        
2336                  if ($row['v_manufacturers_id'] != ''){
2337                      $sql2 = "SELECT manufacturers_name
2338                          FROM ".TABLE_MANUFACTURERS."
2339                          WHERE
2340                          manufacturers_id = " . $row['v_manufacturers_id']
2341                          ;
2342                      $result2 = tep_db_query($sql2);
2343                      $row2 =  tep_db_fetch_array($result2);
2344                      $row['v_manufacturers_name'] = $row2['manufacturers_name'];
2345                  }
2346  
2347  
2348                  //elari -
2349                  //We check the value of tax class and title instead of the id
2350                  //Then we add the tax to price if EP_PRICE_WITH_TAX is set to true
2351                  $row_tax_multiplier = tep_get_tax_class_rate($row['v_tax_class_id']);
2352                  $row['v_tax_class_title'] = tep_get_tax_class_title($row['v_tax_class_id']);
2353                  if (EP_PRICE_WITH_TAX == true){
2354                      $row['v_products_price'] = $row['v_products_price'] + round(($row['v_products_price'] * $row_tax_multiplier / 100), EP_PRECISION);
2355                  }
2356                  // now create the internal variables that will be used
2357                  // the $$thisvar is on purpose: it creates a variable named what ever was in $thisvar and sets the value
2358                  foreach ($default_these as $tkey => $thisvar){
2359                      $$thisvar = $row[$thisvar];
2360                  }
2361          
2362                  $row =  tep_db_fetch_array($result);
2363              }
2364          
2365              // this is an important loop.  What it does is go thru all the fields in the incoming 
2366              // file and set the internal vars. Internal vars not set here are either set in the 
2367              // loop above for existing records, or not set at all (null values) the array values 
2368              // are handled separatly, although they will set variables in this loop, we won't use them.
2369              foreach( $filelayout as $key => $value ){
2370                  $$key = $items[ $value ];
2371              }
2372          
2373              //elari... we get the tax_clas_id from the tax_title
2374              //on screen will still be displayed the tax_class_title instead of the id....
2375              if ( isset( $v_tax_class_title) ){
2376                  $v_tax_class_id          = tep_get_tax_title_class_id($v_tax_class_title);
2377              }
2378              //we check the tax rate of this tax_class_id
2379                  $row_tax_multiplier = tep_get_tax_class_rate($v_tax_class_id);
2380          
2381              //And we recalculate price without the included tax...
2382              //Since it seems display is made before, the displayed price will still include tax
2383              //This is same problem for the tax_clas_id that display tax_class_title
2384              if (EP_PRICE_WITH_TAX == true){
2385                  $v_products_price = round( $v_products_price / (1 + ($row_tax_multiplier * .01)), EP_PRECISION);
2386              }
2387          
2388              // if they give us one category, they give us all categories. convert data structure to a multi-dim array
2389              unset ($v_categories_name); // default to not set.
2390              unset ($v_categories_image); // default to not set.
2391              foreach ($languages as $key => $lang){
2392                $baselang_id = $lang['id'];
2393                break;
2394              }
2395              if ( isset( $filelayout['v_categories_name_1_' . $baselang_id] ) ){
2396                  $v_categories_name = array();
2397                  $v_categories_image = array();
2398                  $newlevel = 1;
2399                  for( $categorylevel=EP_MAX_CATEGORIES; $categorylevel>0; $categorylevel--){
2400                      $found = false;
2401                      if ($items[$filelayout['v_categories_image_' . $categorylevel]] != '') {
2402                        $v_categories_image[$newlevel] = $items[$filelayout['v_categories_image_' . $categorylevel]];
2403                        $found = true;
2404                      }
2405                      foreach ($languages as $key => $lang){
2406                          if ( $items[$filelayout['v_categories_name_' . $categorylevel . '_' . $lang['id']]] != ''){
2407                              $v_categories_name[$newlevel][$lang['id']] = $items[$filelayout['v_categories_name_' . $categorylevel . '_' . $lang['id']]];
2408                              $found = true;
2409                          }
2410                      }
2411                      if ($found == true) {
2412                        $newlevel++;
2413                      }
2414                  }
2415                  while( $newlevel < EP_MAX_CATEGORIES+1){
2416                      $v_categories_image[$newlevel] = ''; // default the remaining items to nothing
2417                      foreach ($languages as $key => $lang){
2418                        $v_categories_name[$newlevel][$lang['id']] = ''; // default the remaining items to nothing
2419                      }
2420                      $newlevel++;
2421                  }
2422              }
2423          
2424              if (ltrim(rtrim($v_products_quantity)) == '') {
2425                  $v_products_quantity = 1;
2426              }
2427          
2428              if (empty($v_date_avail)) {
2429                  $v_date_avail = "'" . '0000-00-00 00:00:00' . "'";
2430              } else {
2431                  $v_date_avail = "'" . date("Y-m-d H:i:s",strtotime($v_date_avail)) . "'";
2432              }
2433          
2434              if (empty($v_date_added)) {
2435                  $v_date_added = "'" . date("Y-m-d H:i:s") . "'";
2436              } else {
2437                  $v_date_added = "'" . date("Y-m-d H:i:s",strtotime($v_date_added)) . "'";
2438              }
2439          
2440              // default the stock if they spec'd it or if it's blank
2441              if (isset($v_status_current)){
2442                $v_db_status = strval($v_status_current); // default to current value
2443              } else {
2444                $v_db_status = '1'; // default to active
2445              }
2446              if (trim($v_status) == EP_TEXT_INACTIVE){
2447                  // they told us to deactivate this item
2448                  $v_db_status = '0';
2449              } elseif (trim($v_status) == EP_TEXT_ACTIVE) {
2450                  $v_db_status = '1';
2451              }    
2452          
2453              if (EP_INACTIVATE_ZERO_QUANTITIES == true && $v_products_quantity == 0) {
2454                  // if they said that zero qty products should be deactivated, let's deactivate if the qty is zero
2455                  $v_db_status = '0';
2456              }
2457          
2458              if ($v_manufacturer_id==''){
2459                  $v_manufacturer_id="NULL";
2460              }
2461          
2462              if (trim($v_products_image)==''){
2463                  $v_products_image = EP_DEFAULT_IMAGE_PRODUCT;
2464              }
2465          
2466              if (strlen($v_products_model) > EP_MODEL_NUMBER_SIZE ){
2467                  echo "<font color='red'>" . strlen($v_products_model) . $v_products_model . "... ERROR! - Too many characters in the model number.<br />
2468                      12 is the maximum on a standard OSC install.<br />
2469                      Your maximum product_model length is set to ".EP_MODEL_NUMBER_SIZE.".<br />
2470                      You can either shorten your model numbers or increase the size of the<br />
2471                      \"products_model\" field of the \"products\" table in the database.<br />
2472                      Then change the setting at the top of the easypopulate.php file.</font>";
2473                  die();
2474              }
2475          
2476          
2477              // OK, we need to convert the manufacturer's name into id's for the database
2478              if ( isset($v_manufacturers_name) && $v_manufacturers_name != '' ){
2479                  $sql = "SELECT man.manufacturers_id
2480                      FROM ".TABLE_MANUFACTURERS." as man
2481                      WHERE
2482                          man.manufacturers_name = '" . tep_db_input($v_manufacturers_name) . "'";
2483                  $result = tep_db_query($sql);
2484                  $row =  tep_db_fetch_array($result);
2485                  if ( $row != '' ){
2486                      foreach( $row as $item ){
2487                          $v_manufacturer_id = $item;
2488                      }
2489                  } else {
2490                      // to add, we need to put stuff in categories and categories_description
2491                      $sql = "SELECT MAX( manufacturers_id) max FROM ".TABLE_MANUFACTURERS;
2492                      $result = tep_db_query($sql);
2493                      $row =  tep_db_fetch_array($result);
2494                      $max_mfg_id = $row['max']+1;
2495                      // default the id if there are no manufacturers yet
2496                      if (!is_numeric($max_mfg_id) ){
2497                          $max_mfg_id=1;
2498                      }
2499          
2500                      // Uncomment this query if you have an older 2.2 codebase
2501                      /*
2502                      $sql = "INSERT INTO ".TABLE_MANUFACTURERS."(
2503                          manufacturers_id,
2504                          manufacturers_name,
2505                          manufacturers_image
2506                          ) VALUES (
2507                          $max_mfg_id,
2508                          '$v_manufacturers_name',
2509                          '".EP_DEFAULT_IMAGE_MANUFACTURER."'
2510                          )";
2511                      */
2512          
2513                      // Comment this query out if you have an older 2.2 codebase
2514                      $sql = "INSERT INTO ".TABLE_MANUFACTURERS."(
2515                          manufacturers_id,
2516                          manufacturers_name,
2517                          manufacturers_image,
2518                          date_added,
2519                          last_modified
2520                          ) VALUES (
2521                          $max_mfg_id,
2522                          '".tep_db_input($v_manufacturers_name)."',
2523                          '".EP_DEFAULT_IMAGE_MANUFACTURER."',
2524                          '".date("Y-m-d H:i:s")."',
2525                          '".date("Y-m-d H:i:s")."'
2526                          )";
2527                      $result = tep_db_query($sql);
2528                      $v_manufacturer_id = $max_mfg_id;
2529          
2530                      $sql = "INSERT INTO ".TABLE_MANUFACTURERS_INFO."(
2531                          manufacturers_id,
2532                          manufacturers_url,
2533                          languages_id
2534                          ) VALUES (
2535                          $max_mfg_id,
2536                          '',
2537                          '".EP_DEFAULT_LANGUAGE_ID."'
2538                          )";
2539                      $result = tep_db_query($sql);
2540                  }
2541              }
2542              
2543              // if the categories names are set then try to update them
2544              foreach ($languages as $key => $lang){
2545                $baselang_id = $lang['id'];
2546                break;
2547              }
2548              if ( isset( $filelayout['v_categories_name_1_' . $baselang_id] ) ){
2549                  // start from the highest possible category and work our way down from the parent
2550                  $v_categories_id = 0;
2551                  $theparent_id = 0;
2552                  for ( $categorylevel=EP_MAX_CATEGORIES+1; $categorylevel>0; $categorylevel-- ){
2553                    //foreach ($languages as $key => $lang){
2554                      $thiscategoryname = $v_categories_name[$categorylevel][$baselang_id];
2555                      if ( $thiscategoryname != ''){
2556                          // we found a category name in this field, look for database entry
2557                          $sql = "SELECT cat.categories_id
2558                              FROM ".TABLE_CATEGORIES." as cat, 
2559                                   ".TABLE_CATEGORIES_DESCRIPTION." as des
2560                              WHERE
2561                                  cat.categories_id = des.categories_id AND
2562                                  des.language_id = " . $lang['id'] . " AND
2563                                  cat.parent_id = " . $theparent_id . " AND
2564                                  des.categories_name like '" . tep_db_input($thiscategoryname) . "'";
2565                          $result = tep_db_query($sql);
2566                          $row =  tep_db_fetch_array($result);
2567  
2568                          if ( $row != '' ){
2569                              // we have an existing category, update image and date
2570                              foreach( $row as $item ){
2571                                  $thiscategoryid = $item;
2572                              }
2573                              $query = "UPDATE ".TABLE_CATEGORIES."
2574                                        SET 
2575                                          categories_image='".tep_db_input($v_categories_image[$categorylevel])."', 
2576                                          last_modified = '".date("Y-m-d H:i:s")."'
2577                                        WHERE 
2578                                          categories_id = '".$row['categories_id']."'
2579                                        LIMIT 1";
2580                  
2581                              tep_db_query($query);
2582                          } else {
2583                              // to add, we need to put stuff in categories and categories_description
2584                              $sql = "SELECT MAX( categories_id) max FROM ".TABLE_CATEGORIES;
2585                              $result = tep_db_query($sql);
2586                              $row =  tep_db_fetch_array($result);
2587                              $max_category_id = $row['max']+1;
2588                              if (!is_numeric($max_category_id) ){
2589                                  $max_category_id=1;
2590                              }
2591                              $sql = "INSERT INTO ".TABLE_CATEGORIES." (
2592                                          categories_id,
2593                                          parent_id,
2594                                          categories_image,
2595                                          sort_order,
2596                                          date_added,
2597                                          last_modified
2598                                     ) VALUES (
2599                                          $max_category_id,
2600                                          $theparent_id,
2601                                          '".tep_db_input($v_categories_image[$categorylevel])."',
2602                                          0,
2603                                          '".date("Y-m-d H:i:s")."',
2604                                          '".date("Y-m-d H:i:s")."'
2605                                     )";
2606                              $result = tep_db_query($sql);
2607                              
2608                              foreach ($languages as $key => $lang){
2609                                  $sql = "INSERT INTO ".TABLE_CATEGORIES_DESCRIPTION." (
2610                                                  categories_id,
2611                                                  language_id,
2612                                                  categories_name
2613                                         ) VALUES (
2614                                                  $max_category_id,
2615                                                  '".$lang['id']."',
2616                                                  '".(!empty($v_categories_name[$categorylevel][$lang['id']])?tep_db_input($v_categories_name[$categorylevel][$lang['id']]):'')."'
2617                                         )";
2618                                  tep_db_query($sql);
2619                              }
2620                              
2621                              $thiscategoryid = $max_category_id;
2622                          }
2623                          // the current catid is the next level's parent
2624                          $theparent_id = $thiscategoryid;
2625                          $v_categories_id = $thiscategoryid; // keep setting this, we need the lowest level category ID later
2626                      }
2627                   // }
2628                  }
2629              }
2630  
2631                
2632              if ($v_products_model != "") {
2633                  //   products_model exists!
2634                  foreach ($items as $tkey => $item) {
2635                    print_el($item);
2636                  }
2637          
2638                  // process the PRODUCTS table
2639                  $result = tep_db_query("SELECT products_id FROM ".TABLE_PRODUCTS." WHERE (products_model = '". $v_products_model . "')");
2640          
2641                  // First we check to see if this is a product in the current db.
2642                  if (tep_db_num_rows($result) == 0)  {
2643                  
2644                      //   insert into products
2645                      echo "<font color='green'> !New Product!</font><br />";
2646          
2647                      // /////////////////////////////////////////////////////////////////////
2648                      //
2649                      // Start: Support for other contributions
2650                      //
2651                      // /////////////////////////////////////////////////////////////////////
2652                      $ep_additional_fields = '';
2653                      $ep_additional_data = '';
2654  
2655                      foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
2656                        $ep_additional_fields .= $key . ',';
2657                      }
2658  
2659                      foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
2660                        $tmp_var = 'v_' . $key;
2661                        $ep_additional_data .= "'" . $$tmp_var . "',";
2662                      }
2663  
2664                      if (EP_MORE_PICS_6_SUPPORT == true) { 
2665                        $ep_additional_fields .= 'products_subimage1,products_subimage2,products_subimage3,products_subimage4,products_subimage5,products_subimage6,';
2666                        $ep_additional_data .= "'$v_products_subimage1','$v_products_subimage2','$v_products_subimage3','$v_products_subimage4','$v_products_subimage5','$v_products_subimage6',";
2667                      }    
2668          
2669                      if (EP_UNKNOWN_ADD_IMAGES_SUPPORT == true) { 
2670                        $ep_additional_fields .= 'products_mimage,products_bimage,products_subimage1,products_bsubimage1,products_subimage2,products_bsubimage2,products_subimage3,products_bsubimage3,';
2671                        $ep_additional_data .= "'$v_products_mimage','$v_products_bimage','$v_products_subimage1','$v_products_bsubimage1','$v_products_subimage2','$v_products_bsubimage2','$v_products_subimage3','$v_products_bsubimage3',";
2672                      }
2673                      // /////////////////////////////////////////////////////////////////////
2674                      // End: Support for other contributions
2675                      // /////////////////////////////////////////////////////////////////////
2676                      
2677                      $query = "INSERT INTO ".TABLE_PRODUCTS." (
2678                                  products_image,
2679                                  $ep_additional_fields
2680                                  products_model,
2681                                  products_price,
2682                                  products_status,
2683                                  products_last_modified,
2684                                  products_date_added,
2685                                  products_date_available,
2686                                  products_tax_class_id,
2687                                  products_weight,
2688                                  products_quantity,
2689                                  manufacturers_id )
2690                                VALUES (
2691                                  ".(!empty($v_products_image)?"'".$v_products_image."'":'NULL').",
2692                                  $ep_additional_data
2693                                  '$v_products_model',
2694                                  '$v_products_price',
2695                                  '$v_db_status',
2696                                  '".date("Y-m-d H:i:s")."',
2697                                  ".$v_date_added.",
2698                                  ".$v_date_avail.",
2699                                  '$v_tax_class_id',
2700                                  '$v_products_weight',
2701                                  '$v_products_quantity',
2702                                  ".(!empty($v_manufacturer_id)?$v_manufacturer_id:'NULL').")
2703                                  ";
2704                      $result = tep_db_query($query);
2705                      
2706                      $v_products_id = tep_db_insert_id();
2707          
2708                  } else {
2709          
2710                    // existing product(s), get the id from the query
2711                    // and update the product data
2712                    while ($row = tep_db_fetch_array($result)) {
2713          
2714                      $v_products_id = $row['products_id'];
2715                      echo "<font color='black'> Updated</font><br />";
2716                      
2717                      // /////////////////////////////////////////////////////////////////////
2718                      //
2719                      // Start: Support for other contributions
2720                      //
2721                      // /////////////////////////////////////////////////////////////////////
2722                      $ep_additional_updates = '';
2723  
2724                      foreach ($custom_fields[TABLE_PRODUCTS] as $key => $name) { 
2725                        $tmp_var = 'v_' . $key;
2726                        $ep_additional_updates .= $key . "='" . $$tmp_var . "',";
2727                      }
2728  
2729                      if (EP_MORE_PICS_6_SUPPORT == true) { 
2730                        $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',";
2731                      }    
2732  
2733                      if (EP_UNKNOWN_ADD_IMAGES_SUPPORT == true) { 
2734                        $ep_additional_updates .= "products_mimage='$v_products_mimage',products_bimage='$v_products_bimage',products_subimage1='$v_products_subimage1',products_bsubimage1='$v_products_bsubimage1',products_subimage2='$v_products_subimage2',products_bsubimage2='$v_products_bsubimage2',products_subimage3='$v_products_subimage3',products_bsubimage3='$v_products_bsubimage3',";
2735                      }
2736                      // /////////////////////////////////////////////////////////////////////
2737                      // End: Support for other contributions
2738                      // /////////////////////////////////////////////////////////////////////
2739  
2740  
2741                      $query = "UPDATE ".TABLE_PRODUCTS."
2742                                SET
2743                                  products_price='$v_products_price', 
2744                                  products_image=".(!empty($v_products_image)?"'".$v_products_image."'":'NULL').", 
2745                                  $ep_additional_updates
2746                                  products_weight='$v_products_weight', 
2747                                  products_tax_class_id='$v_tax_class_id', 
2748                                  products_date_available=".$v_date_avail.", 
2749                                  products_date_added=".$v_date_added.", 
2750                                  products_last_modified='".date("Y-m-d H:i:s")."', 
2751                                  products_quantity = $v_products_quantity, 
2752                                  manufacturers_id = ".(!empty($v_manufacturer_id)?$v_manufacturer_id:'NULL').", 
2753                                  products_status = $v_db_status
2754                                WHERE
2755                                  (products_id = $v_products_id)
2756                                LIMIT 1";
2757          
2758                      tep_db_query($query);
2759                    }
2760                  }
2761          
2762          
2763                  // process the PRODUCTS_DESCRIPTION table
2764                  foreach ($languages as $tkey => $lang){
2765  
2766                      $doit = false;
2767                      foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
2768                        if (isset($filelayout['v_' . $key . '_'.$lang['id']])) { $doit = true; }
2769                      }
2770  
2771                      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 ) {
2772          
2773                          $sql = "SELECT * FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE
2774                                  products_id = $v_products_id AND
2775                                  language_id = " . $lang['id'];
2776                          $result = tep_db_query($sql);
2777          
2778                          $products_var = 'v_products_name_'.$lang['id'];
2779                          $description_var = 'v_products_description_'.$lang['id'];
2780                          $url_var = 'v_products_url_'.$lang['id'];
2781  
2782                          // /////////////////////////////////////////////////////////////////////
2783                          //
2784                          // Start: Support for other contributions
2785                          //
2786                          // /////////////////////////////////////////////////////////////////////
2787                          $ep_additional_updates = '';
2788                          $ep_additional_fields = '';
2789                          $ep_additional_data = '';
2790  
2791                          foreach ($custom_fields[TABLE_PRODUCTS_DESCRIPTION] as $key => $name) { 
2792                            $tmp_var = 'v_' . $key . '_' . $lang['id'];
2793                            $ep_additional_updates .= $key . " = '" . tep_db_input($$tmp_var) ."',";
2794                            $ep_additional_fields .= $key . ",";
2795                            $ep_additional_data .= "'". tep_db_input($$tmp_var) . "',";
2796                          }
2797  
2798                          // header tags controller support
2799                          if (isset($filelayout['v_products_head_title_tag_'.$lang['id']])){
2800                            $head_title_tag_var = 'v_products_head_title_tag_'.$lang['id'];
2801                            $head_desc_tag_var = 'v_products_head_desc_tag_'.$lang['id'];
2802                            $head_keywords_tag_var = 'v_products_head_keywords_tag_'.$lang['id'];
2803          
2804                            $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) ."',";
2805                            $ep_additional_fields .= "products_head_title_tag,products_head_desc_tag,products_head_keywords_tag,";
2806                            $ep_additional_data .= "'". tep_db_input($$head_title_tag_var) . "','". tep_db_input($$head_desc_tag_var) . "','". tep_db_input($$head_keywords_tag_var) . "',";
2807                          }
2808                          // end: header tags controller support
2809                          
2810                          // /////////////////////////////////////////////////////////////////////
2811                          // End: Support for other contributions
2812                          // /////////////////////////////////////////////////////////////////////
2813          
2814                          
2815                          // existing product?
2816                          if (tep_db_num_rows($result) > 0) {
2817                              // already in the description, let's just update it
2818                              $sql =
2819                                  "UPDATE ".TABLE_PRODUCTS_DESCRIPTION." 
2820                                   SET
2821                                      products_name='" . tep_db_input($$products_var) . "',
2822                                      products_description='" . tep_db_input($$description_var) . "',
2823                                      $ep_additional_updates
2824                                      products_url='" . $$url_var . "'
2825                                   WHERE
2826                                      products_id = '$v_products_id' AND
2827                                      language_id = '".$lang['id']."'
2828                                   LIMIT 1";
2829                              $result = tep_db_query($sql);
2830          
2831                          } else {
2832          
2833                              // nope, this is a new product description
2834                              $result = tep_db_query($sql);
2835                              $sql =
2836                                  "INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION."
2837                                      ( products_id,
2838                                        language_id,
2839                                        products_name,
2840                                        products_description,
2841                                        $ep_additional_fields
2842                                        products_url
2843                                      )
2844                                   VALUES (
2845                                          '" . $v_products_id . "',
2846                                          " . $lang['id'] . ",
2847                                          '". tep_db_input($$products_var) . "',
2848                                          '". tep_db_input($$description_var) . "',
2849                                          $ep_additional_data
2850                                          '". $$url_var . "'
2851                                          )";
2852                              $result = tep_db_query($sql);
2853                          }
2854                      }
2855                  }
2856          
2857          
2858          
2859                  if (isset($v_categories_id)){
2860                      //find out if this product is listed in the category given
2861                      $result_incategory = tep_db_query('SELECT
2862                                  '.TABLE_PRODUCTS_TO_CATEGORIES.'.products_id,
2863                                  '.TABLE_PRODUCTS_TO_CATEGORIES.'.categories_id
2864                                  FROM
2865                                      '.TABLE_PRODUCTS_TO_CATEGORIES.'
2866                                  WHERE
2867                                  '.TABLE_PRODUCTS_TO_CATEGORIES.'.products_id='.$v_products_id.' AND
2868                                  '.TABLE_PRODUCTS_TO_CATEGORIES.'.categories_id='.$v_categories_id);
2869          
2870                      if (tep_db_num_rows($result_incategory) == 0) {
2871                          // nope, this is a new category for this product
2872                          $res1 = tep_db_query('INSERT INTO '.TABLE_PRODUCTS_TO_CATEGORIES.' (products_id, categories_id)
2873                                                VALUES ("' . $v_products_id . '", "' . $v_categories_id . '")');
2874                      } else {
2875                          // already in this category, nothing to do!
2876                      }
2877                  }
2878              
2879          
2880                  // for the separate prices per customer (SPPC) module
2881                  $ll=1;
2882                  if (isset($v_customer_price_1)){
2883                      
2884                      if (($v_customer_group_id_1 == '') AND ($v_customer_price_1 != ''))  {
2885                          echo "<font color=red>ERROR - v_customer_group_id and v_customer_price must occur in pairs</font>";
2886                          die();
2887                      }
2888                      // they spec'd some prices, so clear all existing entries
2889                      $result = tep_db_query('
2890                                  DELETE
2891                                  FROM
2892                                      '.TABLE_PRODUCTS_GROUPS.'
2893                                  WHERE
2894                                      products_id = ' . $v_products_id
2895                                  );
2896                      // and insert the new record
2897                      if ($v_customer_price_1 != ''){
2898                          $result = tep_db_query('
2899                                      INSERT INTO
2900                                          '.TABLE_PRODUCTS_GROUPS.'
2901                                      VALUES
2902                                      (
2903                                          ' . $v_customer_group_id_1 . ',
2904                                          ' . $v_customer_price_1 . ',
2905                                          ' . $v_products_id . '
2906                                          )'
2907                                      );
2908                      }
2909                      if ($v_customer_price_2 != ''){
2910                          $result = tep_db_query('
2911                                      INSERT INTO
2912                                          '.TABLE_PRODUCTS_GROUPS.'
2913                                      VALUES
2914                                      (
2915                                          ' . $v_customer_group_id_2 . ',
2916                                          ' . $v_customer_price_2 . ',
2917                                          ' . $v_products_id . '
2918                                          )'
2919                                      );
2920                      }
2921                      if ($v_customer_price_3 != ''){
2922                          $result = tep_db_query('
2923                                      INSERT INTO
2924                                          '.TABLE_PRODUCTS_GROUPS.'
2925                                      VALUES
2926                                      (
2927                                          ' . $v_customer_group_id_3 . ',
2928                                          ' . $v_customer_price_3 . ',
2929                                          ' . $v_products_id . '
2930                                          )'
2931                                      );
2932                      }
2933                      if ($v_customer_price_4 != ''){
2934                          $result = tep_db_query('
2935                                      INSERT INTO
2936                                          '.TABLE_PRODUCTS_GROUPS.'
2937                                      VALUES
2938                                      (
2939                                          ' . $v_customer_group_id_4 . ',
2940                                          ' . $v_customer_price_4 . ',
2941                                          ' . $v_products_id . '
2942                                          )'
2943                                      );
2944                      }
2945          
2946                  }
2947                  // end: separate prices per customer (SPPC) module
2948          
2949          
2950                  // VJ product attribs begin
2951                  if (isset($v_attribute_options_id_1)){
2952                      $attribute_rows = 1; // master row count
2953          
2954                      // product options count
2955                      $attribute_options_count = 1;
2956                      $v_attribute_options_id_var = 'v_attribute_options_id_' . $attribute_options_count;
2957          
2958                      while (isset($$v_attribute_options_id_var) && !empty($$v_attribute_options_id_var)) {
2959                          // remove product attribute options linked to this product before proceeding further
2960                          // this is useful for removing attributes linked to a product
2961                          $attributes_clean_query = "delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$v_products_id . "' and options_id = '" . (int)$$v_attribute_options_id_var . "'";
2962          
2963                          tep_db_query($attributes_clean_query);
2964          
2965                          $attribute_options_query = "select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$$v_attribute_options_id_var . "'";
2966          
2967                          $attribute_options_values = tep_db_query($attribute_options_query);
2968          
2969                          // option table update begin
2970                          if ($attribute_rows == 1) {
2971                              // insert into options table if no option exists
2972                              if (tep_db_num_rows($attribute_options_values) <= 0) {
2973                                  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
2974                                      $lid = $languages[$i]['id'];
2975          
2976                                    $v_attribute_options_name_var = 'v_attribute_options_name_' . $attribute_options_count . '_' . $lid;
2977          
2978                                      if (isset($$v_attribute_options_name_var)) {
2979                                          $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 . "')";
2980          
2981                                          $attribute_options_insert = tep_db_query($attribute_options_insert_query);
2982                                      }
2983                                  }
2984                              } else { // update options table, if options already exists
2985                                  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
2986                                      $lid = $languages[$i]['id'];
2987          
2988                                      $v_attribute_options_name_var = 'v_attribute_options_name_' . $attribute_options_count . '_' . $lid;
2989          
2990                                      if (isset($$v_attribute_options_name_var)) {
2991                                          $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 . "'";
2992          
2993                                          $attribute_options_update_lang_values = tep_db_query($attribute_options_update_lang_query);
2994          
2995                                          // if option name doesn't exist for particular language, insert value
2996                                          if (tep_db_num_rows($attribute_options_update_lang_values) <= 0) {
2997                                              $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 . "')";
2998          
2999                                              $attribute_options_lang_insert = tep_db_query($attribute_options_lang_insert_query);
3000                                          } else { // if option name exists for particular language, update table
3001                                              $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 . "'";
3002          
3003                                              $attribute_options_update = tep_db_query($attribute_options_update_query);
3004                                          }
3005                                      }
3006                                  }
3007                              }
3008                          }
3009                          // option table update end
3010          
3011                          // product option values count
3012                          $attribute_values_count = 1;
3013                          $v_attribute_values_id_var = 'v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count;
3014          
3015                          while (isset($$v_attribute_values_id_var) && !empty($$v_attribute_values_id_var)) {
3016                              $attribute_values_query = "select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int)$$v_attribute_values_id_var . "'";
3017          
3018                              $attribute_values_values = tep_db_query($attribute_values_query);
3019          
3020                              // options_values table update begin
3021                              if ($attribute_rows == 1) {
3022                                  // insert into options_values table if no option exists
3023                                  if (tep_db_num_rows($attribute_values_values) <= 0) {
3024                                      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
3025                                          $lid = $languages[$i]['id'];
3026          
3027                                          $v_attribute_values_name_var = 'v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid;
3028          
3029                                          if (isset($$v_attribute_values_name_var)) {
3030                                              $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) . "')";
3031          
3032                                              $attribute_values_insert = tep_db_query($attribute_values_insert_query);
3033                                          }
3034                                      }
3035          
3036          
3037                                      // insert values to pov2po table
3038                                      $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 . "')";
3039          
3040                                      $attribute_values_pov2po = tep_db_query($attribute_values_pov2po_query);
3041                                  } else { // update options table, if options already exists
3042                                      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
3043                                          $lid = $languages[$i]['id'];
3044          
3045                                          $v_attribute_values_name_var = 'v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid;
3046          
3047                                          if (isset($$v_attribute_values_name_var)) {
3048                                              $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 . "'";
3049          
3050                                              $attribute_values_update_lang_values = tep_db_query($attribute_values_update_lang_query);
3051          
3052                                              // if options_values name doesn't exist for particular language, insert value
3053                                              if (tep_db_num_rows($attribute_values_update_lang_values) <= 0) {
3054                                                  $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) . "')";
3055          
3056                                                  $attribute_values_lang_insert = tep_db_query($attribute_values_lang_insert_query);
3057                                              } else { // if options_values name exists for particular language, update table
3058                                                  $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 . "'";
3059          
3060                                                  $attribute_values_update = tep_db_query($attribute_values_update_query);
3061                                              }
3062                                          }
3063                                      }
3064                                  }
3065                              }
3066                              // options_values table update end
3067          
3068                              // options_values price update begin
3069                            $v_attribute_values_price_var = 'v_attribute_values_price_' . $attribute_options_count . '_' . $attribute_values_count;
3070          
3071                              if (isset($$v_attribute_values_price_var) && ($$v_attribute_values_price_var != '')) {
3072                                  $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 . "'";
3073          
3074                                  $attribute_prices_values = tep_db_query($attribute_prices_query);
3075          
3076                                  $attribute_values_price_prefix = ($$v_attribute_values_price_var < 0) ? '-' : '+';
3077                                  // if negative, remove the negative sign for storing since the prefix is stored in another field.
3078                                  if ( $$v_attribute_values_price_var < 0 ) $$v_attribute_values_price_var = strval(-((int)$$v_attribute_values_price_var));
3079          
3080                                  // options_values_prices table update begin
3081                                  // insert into options_values_prices table if no price exists
3082                                  if (tep_db_num_rows($attribute_prices_values) <= 0) {
3083                                      $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 . "', '" . (float)$$v_attribute_values_price_var . "', '" . $attribute_values_price_prefix . "')";
3084          
3085                                      $attribute_prices_insert = tep_db_query($attribute_prices_insert_query);
3086                                  } else { // update options table, if options already exists
3087                                      $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 . "'";
3088          
3089                                      $attribute_prices_update = tep_db_query($attribute_prices_update_query);
3090                                  }
3091                              }
3092                              // options_values price update end
3093          
3094                              //////// attributes stock add start
3095                              $v_attribute_values_stock_var = 'v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count;
3096                          
3097                              if (isset($$v_attribute_values_stock_var) && ($$v_attribute_values_stock_var != '')) {
3098                                  
3099                                  $stock_attributes = $$v_attribute_options_id_var.'-'.$$v_attribute_values_id_var;
3100                                  $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 . "'");        
3101                                  
3102                                  // insert into products_stock_quantity table if no stock exists
3103                                  if (tep_db_num_rows($attribute_stock_query) <= 0) {
3104                                      $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 . "')");
3105                                          
3106                                  } else { // update options table, if options already exists
3107                                      $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 . "'");
3108                                                  
3109                                      // turn on stock tracking on products_options table
3110                                      $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 . "'");
3111                                  
3112                                  }
3113                              }
3114                              //////// attributes stock add end                    
3115                              
3116                              $attribute_values_count++;
3117                              $v_attribute_values_id_var = 'v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count;
3118                          }
3119          
3120                          $attribute_options_count++;
3121                          $v_attribute_options_id_var = 'v_attribute_options_id_' . $attribute_options_count;
3122                      }
3123          
3124                      $attribute_rows++;
3125                  }
3126                  // VJ product attribs end
3127          
3128              } else {
3129                  // this record was missing the product_model
3130                  echo "<p class=smallText>No products_model field in record. This line was not imported: ";
3131                  foreach ($items as $tkey => $item) {
3132                    print_el($item);
3133                  }
3134                  echo "<br /><br /></p>";
3135              }
3136              // end of row insertion code
3137              
3138          }
3139  
3140      // EP for product extra fields Contrib by minhmaster DEVSOFTVN ==========
3141      }
3142      // end (EP for product extra fields Contrib by minhmt DEVSOFTVN) ============
3143  
3144  }
3145  
3146  require (DIR_WS_INCLUDES . 'application_bottom.php'); 
3147  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7