home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 90 / PIWD90.iso / pc / contents / ecommerce / tutorial_files / easy_populate_2.62-m.1 / easypopulate.php.bak < prev    next >
Encoding:
Text File  |  2003-01-01  |  68.7 KB  |  3,771 lines

  1. <?php
  2.  
  3.  
  4.  
  5. // Current EP Version
  6.  
  7. $curver = '2.62-MS2';
  8.  
  9.  
  10.  
  11. /*
  12.  
  13.   $Id: easypopulate.php,v 1.18 2002/12/05 14:34:18 elarifr Exp $
  14.  
  15.  
  16.  
  17.  
  18.  
  19. //*******************************
  20.  
  21. //*******************************
  22.  
  23. // E D I T   H I S T O R Y
  24.  
  25. //*******************************
  26.  
  27. //*******************************
  28.  
  29. Easy Populate
  30.  
  31.  
  32.  
  33. The point of easy populate is to let someone use an excel file exported to
  34.  
  35. a tab delimited file to set up their entire store:
  36.  
  37. categories, products, manufacturers, quantities, and prices.
  38.  
  39.  
  40.  
  41. -----------------------------------
  42.  
  43. Modified by Tim Wasson - Wasson65 (wasson65@nc.rr.com) to:
  44.  
  45.  accept category/subcategory names
  46.  
  47.  allow reordering of columns in csv file
  48.  
  49.  accept manufacturer name or id
  50.  
  51.  some minor code simplification
  52.  
  53.  accept and set status of the product if desired
  54.  
  55.  changed all # to // comment markers so KDE's Kate will syntax highlight correctly
  56.  
  57.  added support for default images for products, categories, and categories.
  58.  
  59.  added support for exporting a csv file that can be modified and sent back in.
  60.  
  61. -----------------------------------
  62.  
  63. 1.1 Changes
  64.  
  65.  Fixed a stupid bug, I didn't change the references to easypopulate.php from excel.php
  66.  
  67.  Added note in the docs that if the Excel import is already done, don't need to do the alter table
  68.  
  69.  Removed the extra semicolon on the end of the line in the csv download.  It prevented you from exporting and importing a file.
  70.  
  71. -----------------------------------
  72.  
  73. 1.2 Fixes
  74.  
  75. More bugs fixed
  76.  
  77. ___________________________________
  78.  
  79. 1.3 Fixes
  80.  
  81. Added another link to put csv file in temp file for access via tools->files, for some windows machines that refuse to dl right...
  82.  
  83. -----------------------------------
  84.  
  85. 1.4 Fixes
  86.  
  87. Switchted to tabs for delimiters
  88.  
  89. Strip cr's and tab's from strings before exporting
  90.  
  91. Added explicit end of row field
  92.  
  93. Added ability to split a big file into smaller files in the temp dir
  94.  
  95. Preserve double quotes, single quotes, and apostrophes and commas
  96.  
  97. Removed references to category_root, it's no longer required
  98.  
  99. ------------------------------------
  100.  
  101. 1.5 Fixes
  102.  
  103. Changed --EOR-- to EOREOR for better excel usability.
  104.  
  105. Made script accept "EOREOR" or EOREOR without the quotes.
  106.  
  107. If inserting a new product, delete any product_descriptions with that product_id to avoid an error if old data was still present.
  108.  
  109. ------------------------------------
  110.  
  111. 1.6 Fixes
  112.  
  113. Ooops, manufacturer_id variable misspellings meant that mfg wasn't getting set or updated
  114.  
  115. Whe I re-arranged the code, I left out the call to actually put the data into the products table.  Ooops again...
  116.  
  117. ------------------------------------
  118.  
  119. 1.61 Fixes
  120.  
  121. One more manufacturer id name fix.
  122.  
  123. ------------------------------------
  124.  
  125. Skipped to 2.0 because of the big jump in functionality
  126.  
  127. ------------------------------------
  128.  
  129. 2.0
  130.  
  131. Made EP handle magic-quotes
  132.  
  133. Thanks to Joshua Dechant aka dreamscape, for this fix
  134.  
  135. Rewrote the categories part to handle any number of categories
  136.  
  137. ------------------------------------
  138.  
  139. 2.1
  140.  
  141. Fix split files not splitting.
  142.  
  143. Change from "file" to "fgets" to read the file to be split to avoid out of memory problems... hopefully
  144.  
  145. ------------------------------------
  146.  
  147. 2.2
  148.  
  149. Added multi-language support. - thanks to elari, who wrote all the code around handling all active langs in OSC
  150.  
  151. Added category names assumed to be in default language - thanks to elari again!  who wrote all that code as well
  152.  
  153. Fixed bug where files wouldn't split because the check for EOREOR was too specific.
  154.  
  155. Added separate file for functions tep_get_uploaded_file and friends so that older snapshots will have it and work.
  156.  
  157. Finally updated the docs since they sucked
  158.  
  159. Moved product_model field to the start of each row because sometimes, if the image name was empty, the parsing would get confused
  160.  
  161. ------------------------------------
  162.  
  163. 2.3
  164.  
  165. Thanks to these sponsors - their financial support made this release possible!
  166.  
  167. Support for more than one output file format with variable numbers of columns
  168.  
  169.     Sponsored by Ted Joffs
  170.  
  171.  
  172.  
  173. Support for Separate Price per Customer mod
  174.  
  175.     Sponsored by Alan Pace
  176.  
  177.  
  178.  
  179. Support for Linda's Header Controller v2.0
  180.  
  181.     Sponsored by Stewart MacKenzie
  182.  
  183.  
  184.  
  185. Removed quotes around all the fields on export.
  186.  
  187. Added configuration variable so you can turn off the qoutes -> control codes replacement
  188.  
  189. Merged Elari's changes to not hardcode language id's
  190.  
  191. ------------------------------------
  192.  
  193. 2.31
  194.  
  195. Bugfix for single language non-english name/desc not being put into the output file.
  196.  
  197. The code was still checking for product_name_1 instead of product_name_$langid.
  198.  
  199. ------------------------------------
  200.  
  201. 2.32 - never released into the wild
  202.  
  203. Added config var $zero_qty_inactive, defaulted to true.
  204.  
  205. This will make zero qty items inactive by default.
  206.  
  207. ---- STILL NEED TO DEBUG THIS! ----
  208.  
  209. ------------------------------------
  210.  
  211. 2.4
  212.  
  213. Support for Froogle downloads to EP.
  214.  
  215.     Sponsored by Ted Joffs
  216.  
  217. Changed comments - it's not Multiple Price per Product, it's
  218.  
  219. Separate Price per Customer.
  220.  
  221. ------------------------------------
  222.  
  223. 2.41beta
  224.  
  225. Fixed bugs with Froogle:
  226.  
  227. 1. Category not getting built right
  228.  
  229. 2. Strip HTML from name/description
  230.  
  231. 3. Handle SearchEngineFriendly URL's
  232.  
  233.  
  234.  
  235. Adding "Delete" capability via EP. -- NOT COMPLETE
  236.  
  237. Fixed bug - the Model/Category would give SQL errors
  238.  
  239. Fixed bug - Items with no manufacturer were getting a man of '' (empty string)
  240.  
  241. Fixed bug - When trying to import, all items gave a "Deleting product" message but no db changes
  242.  
  243.     This was because I'd tried inserting the delete functionality and didn't finish it.
  244.  
  245.     Commented it out for now.
  246.  
  247. Added Date_added, fixed Date_available
  248.  
  249. Fixed active/inactive status settings
  250.  
  251. Fixed bug with misnamed item for Linda's Header Controller support
  252.  
  253. Fixed bug with SQL syntax error with new products
  254.  
  255. These following 3 fixes thanks to Yassen Yotov
  256.  
  257.     Fixed bug where the default image name vars weren't declared global in function walk()
  258.  
  259.     Added set_time_limit call, it won't cover all cases, but hopefully many. commented out to avoid
  260.  
  261.         complaints with safe mode servers
  262.  
  263.     Fixed hardcoded catalog/temp/ in output string for splitting files
  264.  
  265. ------------------------------------
  266.  
  267. 2.5
  268.  
  269. DJZeon found a bug where product URL was getting lost because I always deleted and inserted the product description info - fixed
  270.  
  271. Same bug also was causing times viewed to be reset to zero because I always deleted and inserted the product descriiption.
  272.  
  273. Added the multi-image lines from Debbie and Nickie - Thanks!
  274.  
  275. Changed the output file name to make more sense, now it looks like EP2003Mar20-09:45.txt
  276.  
  277. ------------------------------------
  278.  
  279. 2.51
  280.  
  281. No code changes, bump version because I forgot to update the docs about the high-to-low category order
  282.  
  283. ------------------------------------
  284.  
  285. 2.53
  286.  
  287. Bug fixes?
  288.  
  289. ------------------------------------
  290.  
  291. 2.60
  292.  
  293. Fix froogle categories in reverse order bug
  294.  
  295. Comment out mimage lines that were causing problems for people in 2.53
  296.  
  297. Added separator configuration variable so you can pick the separator character to use.
  298.  
  299. Made Froogle download look for an applicable specials price
  300.  
  301. Froogle downloads have "froogle" at the start of the file name
  302.  
  303. You can now specify a file in the temp directory and it will upload that instead of uploading via the browser
  304.  
  305. ------------------------------------
  306.  
  307. 2.61-MS2
  308.  
  309. Bug fixes thanks to frozenlightning.com
  310.  
  311. Replaced tep_array_merge with array_merge to bring up to MS2 Standards.
  312.  
  313. Modified by Deborah Carney, inspired by the Think Tank to be included in the CRE Loaded 6
  314.  
  315. New support will be found at http://phesis.co.uk in the forums, as well as at forums.oscommerce.com in the Contributions section.  This script was/is written by volunteers, please don't email or PM them, more answers are available in the forums if you search.  If you want EP to do something, someone else probably already asked....
  316.  
  317. Known issue:  html in the product description gets messed up, not sure how to fix it.  
  318.  
  319.  
  320.  
  321. 2.62-MS2
  322.  
  323. Modified by Karlheinz Meier on 08.August.2003
  324.  
  325. As some people happen to have something like DIFFERENT_Prefix_TABLES in their databases,
  326.  
  327. normally there is a file called /admin/includes/database_tables.php
  328.  
  329. which defines nice varibales for them; you can for example make prefixed_databases, or live backups or so.
  330.  
  331. As some programmers did use DIRECT table names, this was changed.
  332.  
  333. And now if you use the "separte price..."-module and have an article where there is NO special price,
  334.  
  335. the import process won't die
  336.  
  337.  
  338.  
  339. Derived from the Excel Import 1.51 by:
  340.  
  341.  
  342.  
  343. ukrainianshop.net
  344.  
  345.  
  346.  
  347.   Copyright (c) 2002-2003 Tim Wasson
  348.  
  349.   Released under the GNU General Public License
  350.  
  351. */
  352.  
  353. //*******************************
  354.  
  355. //*******************************
  356.  
  357. // E N D
  358.  
  359. // E D I T   H I S T O R Y
  360.  
  361. //*******************************
  362.  
  363. //*******************************
  364.  
  365.  
  366.  
  367. //
  368.  
  369. //*******************************
  370.  
  371. //*******************************
  372.  
  373. // C O N F I G U R A T I O N
  374.  
  375. // V A R I A B L E S
  376.  
  377. //*******************************
  378.  
  379. //*******************************
  380.  
  381.  
  382.  
  383. // **** Temp directory ****
  384.  
  385. // if you changed your directory structure from stock and do not have /catalog/temp/, then you'll need to change this accordingly.
  386.  
  387. //
  388.  
  389. $tempdir = "temp/";
  390.  
  391. $tempdir2 = "temp/";
  392.  
  393.  
  394.  
  395. //**** File Splitting Configuration ****
  396.  
  397. // we attempt to set the timeout limit longer for this script to avoid having to split the files
  398.  
  399. // NOTE:  If your server is running in safe mode, this setting cannot override the timeout set in php.ini
  400.  
  401. // uncomment this if you are not on a safe mode server and you are getting timeouts
  402.  
  403. //set_time_limit(330);
  404.  
  405.  
  406.  
  407. // if you are splitting files, this will set the maximum number of records to put in each file.
  408.  
  409. // if you set your php.ini to a long time, you can make this number bigger
  410.  
  411. global $maxrecs;
  412.  
  413. $maxrecs = 300; // default, seems to work for most people.  Reduce if you hit timeouts
  414.  
  415. //$maxrecs = 4; // for testing
  416.  
  417.  
  418.  
  419. //**** Image Defaulting ****
  420.  
  421. global $default_images, $default_image_manufacturer, $default_image_product, $default_image_category;
  422.  
  423.  
  424.  
  425. // set them to your own default "We don't have any picture" gif
  426.  
  427. //$default_image_manufacturer = 'no_image_manufacturer.gif';
  428.  
  429. //$default_image_product = 'no_image_product.gif';
  430.  
  431. //$default_image_category = 'no_image_category.gif';
  432.  
  433.  
  434.  
  435. // or let them get set to nothing
  436.  
  437. $default_image_manufacturer = '';
  438.  
  439. $default_image_product = '';
  440.  
  441. $default_image_category = '';
  442.  
  443.  
  444.  
  445. //**** Status Field Setting ****
  446.  
  447. // Set the v_status field to "Inactive" if you want the status=0 in the system
  448.  
  449. // Set the v_status field to "Delete" if you want to remove the item from the system <- THIS IS NOT WORKING YET!
  450.  
  451. // If zero_qty_inactive is true, then items with zero qty will automatically be inactive in the store.
  452.  
  453. global $active, $inactive, $zero_qty_inactive, $deleteit;
  454.  
  455. $active = 'Active';
  456.  
  457. $inactive = 'Inactive';
  458.  
  459. //$deleteit = 'Delete'; // not functional yet
  460.  
  461. $zero_qty_inactive = true;
  462.  
  463.  
  464.  
  465. //**** Size of products_model in products table ****
  466.  
  467. // set this to the size of your model number field in the db.  We check to make sure all models are no longer than this value.
  468.  
  469. // this prevents the database from getting fubared.  Just making this number bigger won't help your database!  They must match!
  470.  
  471. global $modelsize;
  472.  
  473. $modelsize = 15;
  474.  
  475.  
  476.  
  477. //**** Price includes tax? ****
  478.  
  479. // Set the v_price_with_tax to
  480.  
  481. // 0 if you want the price without the tax included
  482.  
  483. // 1 if you want the price to be defined for import & export including tax.
  484.  
  485. global $price_with_tax;
  486.  
  487. $price_with_tax = true;
  488.  
  489.  
  490.  
  491. // **** Quote -> Escape character conversion ****
  492.  
  493. // If you have extensive html in your descriptions and it's getting mangled on upload, turn this off
  494.  
  495. // set to 1 = replace quotes with escape characters
  496.  
  497. // set to 0 = no quote replacement
  498.  
  499. global $replace_quotes;
  500.  
  501. $replace_quotes = true;
  502.  
  503.  
  504.  
  505. // **** Field Separator ****
  506.  
  507. // change this if you can't use the default of tabs
  508.  
  509. // Tab is the default, comma and semicolon are commonly supported by various progs
  510.  
  511. // Remember, if your descriptions contain this character, you will confuse EP!
  512.  
  513. global $separator;
  514.  
  515. $separator = "\t"; // tab is default
  516.  
  517. //$separator = ","; // comma
  518.  
  519. //$separator = ";"; // semi-colon
  520.  
  521. //$separator = "~"; // tilde
  522.  
  523. //$separator = "-"; // dash
  524.  
  525. //$separator = "*"; // splat
  526.  
  527.  
  528.  
  529. // **** Max Category Levels ****
  530.  
  531. // change this if you need more or fewer categories
  532.  
  533. global $max_categories;
  534.  
  535. $max_categories = 3; // 7 is default
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545. // ****************************************
  546.  
  547. // Froogle configuration variables
  548.  
  549. // -- YOU MUST CONFIGURE THIS!  IT WON'T WORK OUT OF THE BOX!
  550.  
  551. // ****************************************
  552.  
  553.  
  554.  
  555. // **** Froogle product info page path ****
  556.  
  557. // We can't use the tep functions to create the link, because the links will point to the admin, since that's where we're at.
  558.  
  559. // So put the entire path to your product_info.php page here
  560.  
  561. global $froogle_product_info_path;
  562.  
  563. $froogle_product_info_path = "http://www.your-domain/catalog/product_info.php";
  564.  
  565.  
  566.  
  567. // **** Froogle product image path ****
  568.  
  569. // Set this to the path to your images directory
  570.  
  571. global $froogle_image_path;
  572.  
  573. $froogle_image_path = "http://www.your-domain/catalog/images/";
  574.  
  575.  
  576.  
  577. // **** Froogle - search engine friendly setting
  578.  
  579. // if your store has SEARCH ENGINE FRIENDLY URLS set, then turn this to true
  580.  
  581. // I did it this way because I'm having trouble with the code seeing the constants
  582.  
  583. // that are defined in other places.
  584.  
  585. global $froogle_SEF_urls;
  586.  
  587. $froogle_SEF_urls = true;
  588.  
  589.  
  590.  
  591.  
  592.  
  593. // ****************************************
  594.  
  595. // End Froogle configuration variables
  596.  
  597. // ****************************************
  598.  
  599.  
  600.  
  601. //*******************************
  602.  
  603. //*******************************
  604.  
  605. // E N D
  606.  
  607. // C O N F I G U R A T I O N
  608.  
  609. // V A R I A B L E S
  610.  
  611. //*******************************
  612.  
  613. //*******************************
  614.  
  615.  
  616.  
  617.  
  618.  
  619. //*******************************
  620.  
  621. //*******************************
  622.  
  623. // S T A R T
  624.  
  625. // INITIALIZATION
  626.  
  627. //*******************************
  628.  
  629. //*******************************
  630.  
  631.  
  632.  
  633.  
  634.  
  635. require('includes/application_top.php');
  636.  
  637. require('includes/database_tables.php');
  638.  
  639.  
  640.  
  641. //*******************************
  642.  
  643. // If you are running a pre-Nov1-2002 snapshot of OSC, then we need this include line to avoid
  644.  
  645. // errors like:
  646.  
  647. //   undefined function tep_get_uploaded_file
  648.  
  649.  if (!function_exists(tep_get_uploaded_file)){
  650.  
  651.     include ('easypopulate_functions.php');
  652.  
  653.  }
  654.  
  655. //*******************************
  656.  
  657.  
  658.  
  659. global $filelayout, $filelayout_count, $filelayout_sql, $langcode, $fileheaders;
  660.  
  661.  
  662.  
  663. // these are the fields that will be defaulted to the current values in the database if they are not found in the incoming file
  664.  
  665. global $default_these;
  666.  
  667. $default_these = array(
  668.  
  669.     'v_products_image',
  670.  
  671.     #'v_products_mimage',
  672.  
  673.     #'v_products_bimage',
  674.  
  675.     #'v_products_subimage1',
  676.  
  677.     #'v_products_bsubimage1',
  678.  
  679.     #'v_products_subimage2',
  680.  
  681.     #'v_products_bsubimage2',
  682.  
  683.     #'v_products_subimage3',
  684.  
  685.     #'v_products_bsubimage3',
  686.  
  687.     'v_categories_id',
  688.  
  689.     'v_products_price',
  690.  
  691.     'v_products_quantity',
  692.  
  693.     'v_products_weight',
  694.  
  695.     'v_date_avail',
  696.  
  697.     'v_instock',
  698.  
  699.     'v_tax_class_title',
  700.  
  701.     'v_manufacturers_name',
  702.  
  703.     'v_manufacturers_id',
  704.  
  705.     'v_products_dim_type',
  706.  
  707.     'v_products_length',
  708.  
  709.     'v_products_width',
  710.  
  711.     'v_products_height'
  712.  
  713.     );
  714.  
  715.  
  716.  
  717. //elari check default language_id from configuration table DEFAULT_LANGUAGE
  718.  
  719. $epdlanguage_query = tep_db_query("select languages_id, name from " . TABLE_LANGUAGES . " where code = '" . DEFAULT_LANGUAGE . "'");
  720.  
  721. if (tep_db_num_rows($epdlanguage_query)) {
  722.  
  723.     $epdlanguage = tep_db_fetch_array($epdlanguage_query);
  724.  
  725.     $epdlanguage_id   = $epdlanguage['languages_id'];
  726.  
  727.     $epdlanguage_name = $epdlanguage['name'];
  728.  
  729. } else {
  730.  
  731.     Echo 'Strange but there is no default language to work... That may not happen, just in case... ';
  732.  
  733. }
  734.  
  735.  
  736.  
  737. $langcode = ep_get_languages();
  738.  
  739.  
  740.  
  741. if ( $dltype != '' ){
  742.  
  743.     // if dltype is set, then create the filelayout.  Otherwise it gets read from the uploaded file
  744.  
  745.     ep_create_filelayout($dltype); // get the right filelayout for this download
  746.  
  747. }
  748.  
  749. //*******************************
  750.  
  751. //*******************************
  752.  
  753. // E N D
  754.  
  755. // INITIALIZATION
  756.  
  757. //*******************************
  758.  
  759. //*******************************
  760.  
  761.  
  762.  
  763.  
  764.  
  765. if ( $download == 'stream' or  $download == 'tempfile' ){
  766.  
  767.     //*******************************
  768.  
  769.     //*******************************
  770.  
  771.     // DOWNLOAD FILE
  772.  
  773.     //*******************************
  774.  
  775.     //*******************************
  776.  
  777.     $filestring = ""; // this holds the csv file we want to download
  778.  
  779.  
  780.  
  781.     if ( $dltype=='froogle' ){
  782.  
  783.         // set the things froogle wants at the top of the file
  784.  
  785.         $filestring .= "# html_escaped=YES\n";
  786.  
  787.         $filestring .= "# updates_only=NO\n";
  788.  
  789.         $filestring .= "# product_type=OTHER\n";
  790.  
  791.         $filestring .= "# quoted=YES\n";
  792.  
  793.     }
  794.  
  795.  
  796.  
  797.     $result = tep_db_query($filelayout_sql);
  798.  
  799.     $row =  tep_db_fetch_array($result);
  800.  
  801.  
  802.  
  803.     // Here we need to allow for the mapping of internal field names to external field names
  804.  
  805.     // default to all headers named like the internal ones
  806.  
  807.     // the field mapping array only needs to cover those fields that need to have their name changed
  808.  
  809.     if ( count($fileheaders) != 0 ){
  810.  
  811.         $filelayout_header = $fileheaders; // if they gave us fileheaders for the dl, then use them
  812.  
  813.     } else {
  814.  
  815.         $filelayout_header = $filelayout; // if no mapping was spec'd use the internal field names for header names
  816.  
  817.     }
  818.  
  819.     //We prepare the table heading with layout values
  820.  
  821.     foreach( $filelayout_header as $key => $value ){
  822.  
  823.         $filestring .= $key . $separator;
  824.  
  825.     }
  826.  
  827.     // now lop off the trailing tab
  828.  
  829.     $filestring = substr($filestring, 0, strlen($filestring)-1);
  830.  
  831.  
  832.  
  833.     // set the type
  834.  
  835.     if ( $dltype == 'froogle' ){
  836.  
  837.         $endofrow = "\n";
  838.  
  839.     } else {
  840.  
  841.         // default to normal end of row
  842.  
  843.         $endofrow = $separator . 'EOREOR' . "\n";
  844.  
  845.     }
  846.  
  847.     $filestring .= $endofrow;
  848.  
  849.  
  850.  
  851.     $num_of_langs = count($langcode);
  852.  
  853.     while ($row){
  854.  
  855.  
  856.  
  857.  
  858.  
  859.         // if the filelayout says we need a products_name, get it
  860.  
  861.         // build the long full froogle image path
  862.  
  863.         $row['v_products_fullpath_image'] = $froogle_image_path . $row['v_products_image'];
  864.  
  865.         // Other froogle defaults go here for now
  866.  
  867.         $row['v_froogle_instock']         = 'Y';
  868.  
  869.         $row['v_froogle_shipping']         = '';
  870.  
  871.         $row['v_froogle_upc']             = '';
  872.  
  873.         $row['v_froogle_color']            = '';
  874.  
  875.         $row['v_froogle_size']            = '';
  876.  
  877.         $row['v_froogle_quantitylevel']        = '';
  878.  
  879.         $row['v_froogle_manufacturer_id']    = '';
  880.  
  881.         $row['v_froogle_exp_date']        = '';
  882.  
  883.         $row['v_froogle_product_type']        = 'OTHER';
  884.  
  885.         $row['v_froogle_delete']        = '';
  886.  
  887.         $row['v_froogle_currency']        = 'USD';
  888.  
  889.         $row['v_froogle_offer_id']        = $row['v_products_model'];
  890.  
  891.         $row['v_froogle_product_id']        = $row['v_products_model'];
  892.  
  893.  
  894.  
  895.         // names and descriptions require that we loop thru all languages that are turned on in the store
  896.  
  897.         foreach ($langcode as $key => $lang){
  898.  
  899.             $lid = $lang['id'];
  900.  
  901.  
  902.  
  903.             // for each language, get the description and set the vals
  904.  
  905.             $sql2 = "SELECT *
  906.  
  907.                 FROM ".TABLE_PRODUCTS_DESCRIPTION."
  908.  
  909.                 WHERE
  910.  
  911.                     products_id = " . $row['v_products_id'] . " AND
  912.  
  913.                     language_id = '" . $lid . "'
  914.  
  915.                 ";
  916.  
  917.             $result2 = tep_db_query($sql2);
  918.  
  919.             $row2 =  tep_db_fetch_array($result2);
  920.  
  921.  
  922.  
  923.             // I'm only doing this for the first language, since right now froogle is US only.. Fix later!
  924.  
  925.             // adding url for froogle, but it should be available no matter what
  926.  
  927.             if ($froogle_SEF_urls){
  928.  
  929.                 // if only one language
  930.  
  931.                 if ($num_of_langs == 1){
  932.  
  933.                     $row['v_froogle_products_url_' . $lid] = $froogle_product_info_path . '/products_id/' . $row['v_products_id'];
  934.  
  935.                 } else {
  936.  
  937.                     $row['v_froogle_products_url_' . $lid] = $froogle_product_info_path . '/products_id/' . $row['v_products_id'] . '/language/' . $lid;
  938.  
  939.                 }
  940.  
  941.             } else {
  942.  
  943.                 if ($num_of_langs == 1){
  944.  
  945.                     $row['v_froogle_products_url_' . $lid] = $froogle_product_info_path . '?products_id=' . $row['v_products_id'];
  946.  
  947.                 } else {
  948.  
  949.                     $row['v_froogle_products_url_' . $lid] = $froogle_product_info_path . '?products_id=' . $row['v_products_id'] . '&language=' . $lid;
  950.  
  951.                 }
  952.  
  953.             }
  954.  
  955.  
  956.  
  957.             $row['v_products_name_' . $lid]     = $row2['products_name'];
  958.  
  959.             $row['v_products_description_' . $lid]     = $row2['products_description'];
  960.  
  961.             $row['v_products_url_' . $lid]         = $row2['products_url'];
  962.  
  963.  
  964.  
  965.             // froogle advanced format needs the quotes around the name and desc
  966.  
  967.             $row['v_froogle_products_name_' . $lid] = '"' . strip_tags(str_replace('"','""',$row2['products_name'])) . '"';
  968.  
  969.             $row['v_froogle_products_description_' . $lid] = '"' . strip_tags(str_replace('"','""',$row2['products_description'])) . '"';
  970.  
  971.  
  972.  
  973.             // support for Linda's Header Controller 2.0 here
  974.  
  975.             if(isset($filelayout['v_products_head_title_tag_' . $lid])){
  976.  
  977.                 $row['v_products_head_title_tag_' . $lid]     = $row2['products_head_title_tag'];
  978.  
  979.                 $row['v_products_head_desc_tag_' . $lid]     = $row2['products_head_desc_tag'];
  980.  
  981.                 $row['v_products_head_keywords_tag_' . $lid]     = $row2['products_head_keywords_tag'];
  982.  
  983.             }
  984.  
  985.             // end support for Header Controller 2.0
  986.  
  987.         }
  988.  
  989.  
  990.  
  991.         // for the categories, we need to keep looping until we find the root category
  992.  
  993.  
  994.  
  995.         // start with v_categories_id
  996.  
  997.         // Get the category description
  998.  
  999.         // set the appropriate variable name
  1000.  
  1001.         // if parent_id is not null, then follow it up.
  1002.  
  1003.         // we'll populate an aray first, then decide where it goes in the
  1004.  
  1005.         $thecategory_id = $row['v_categories_id'];
  1006.  
  1007.         $fullcategory = ''; // this will have the entire category stack for froogle
  1008.  
  1009.         for( $categorylevel=1; $categorylevel<$max_categories+1; $categorylevel++){
  1010.  
  1011.             if ($thecategory_id){
  1012.  
  1013.                 $sql2 = "SELECT categories_name
  1014.  
  1015.                     FROM ".TABLE_CATEGORIES_DESCRIPTION."
  1016.  
  1017.                     WHERE
  1018.  
  1019.                         categories_id = " . $thecategory_id . " AND
  1020.  
  1021.                         language_id = " . $epdlanguage_id ;
  1022.  
  1023.  
  1024.  
  1025.                 $result2 = tep_db_query($sql2);
  1026.  
  1027.                 $row2 =  tep_db_fetch_array($result2);
  1028.  
  1029.                 // only set it if we found something
  1030.  
  1031.                 $temprow['v_categories_name_' . $categorylevel] = $row2['categories_name'];
  1032.  
  1033.                 // now get the parent ID if there was one
  1034.  
  1035.                 $sql3 = "SELECT parent_id
  1036.  
  1037.                     FROM ".TABLE_CATEGORIES."
  1038.  
  1039.                     WHERE
  1040.  
  1041.                         categories_id = " . $thecategory_id;
  1042.  
  1043.                 $result3 = tep_db_query($sql3);
  1044.  
  1045.                 $row3 =  tep_db_fetch_array($result3);
  1046.  
  1047.                 $theparent_id = $row3['parent_id'];
  1048.  
  1049.                 if ($theparent_id != ''){
  1050.  
  1051.                     // there was a parent ID, lets set thecategoryid to get the next level
  1052.  
  1053.                     $thecategory_id = $theparent_id;
  1054.  
  1055.                 } else {
  1056.  
  1057.                     // we have found the top level category for this item,
  1058.  
  1059.                     $thecategory_id = false;
  1060.  
  1061.                 }
  1062.  
  1063.                 //$fullcategory .= " > " . $row2['categories_name'];
  1064.  
  1065.                 $fullcategory = $row2['categories_name'] . " > " . $fullcategory;
  1066.  
  1067.             } else {
  1068.  
  1069.                 $temprow['v_categories_name_' . $categorylevel] = '';
  1070.  
  1071.             }
  1072.  
  1073.         }
  1074.  
  1075.         // now trim off the last ">" from the category stack
  1076.  
  1077.         $row['v_category_fullpath'] = substr($fullcategory,0,strlen($fullcategory)-3);
  1078.  
  1079.  
  1080.  
  1081.         // temprow has the old style low to high level categories.
  1082.  
  1083.         $newlevel = 1;
  1084.  
  1085.         // let's turn them into high to low level categories
  1086.  
  1087.         for( $categorylevel=6; $categorylevel>0; $categorylevel--){
  1088.  
  1089.             if ($temprow['v_categories_name_' . $categorylevel] != ''){
  1090.  
  1091.                 $row['v_categories_name_' . $newlevel++] = $temprow['v_categories_name_' . $categorylevel];
  1092.  
  1093.             }
  1094.  
  1095.         }
  1096.  
  1097.         // if the filelayout says we need a manufacturers name, get it
  1098.  
  1099.         if (isset($filelayout['v_manufacturers_name'])){
  1100.  
  1101.             if ($row['v_manufacturers_id'] != ''){
  1102.  
  1103.                 $sql2 = "SELECT manufacturers_name
  1104.  
  1105.                     FROM ".TABLE_MANUFACTURERS."
  1106.  
  1107.                     WHERE
  1108.  
  1109.                     manufacturers_id = " . $row['v_manufacturers_id']
  1110.  
  1111.                     ;
  1112.  
  1113.                 $result2 = tep_db_query($sql2);
  1114.  
  1115.                 $row2 =  tep_db_fetch_array($result2);
  1116.  
  1117.                 $row['v_manufacturers_name'] = $row2['manufacturers_name'];
  1118.  
  1119.             }
  1120.  
  1121.         }
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.         // If you have other modules that need to be available, put them here
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.         // this is for the separate price per customer module
  1134.  
  1135.         if (isset($filelayout['v_customer_price_1'])){
  1136.  
  1137.             $sql2 = "SELECT
  1138.  
  1139.                     customers_group_price,
  1140.  
  1141.                     customers_group_id
  1142.  
  1143.                 FROM
  1144.  
  1145.                     ".TABLE_PRODUCTS_GROUPS."
  1146.  
  1147.                 WHERE
  1148.  
  1149.                 products_id = " . $row['v_products_id'] . "
  1150.  
  1151.                 ORDER BY
  1152.  
  1153.                 customers_group_id"
  1154.  
  1155.                 ;
  1156.  
  1157.             $result2 = tep_db_query($sql2);
  1158.  
  1159.             $ll = 1;
  1160.  
  1161.             $row2 =  tep_db_fetch_array($result2);
  1162.  
  1163.             while( $row2 ){
  1164.  
  1165.                 $row['v_customer_group_id_' . $ll]     = $row2['customers_group_id'];
  1166.  
  1167.                 $row['v_customer_price_' . $ll]     = $row2['customers_group_price'];
  1168.  
  1169.                 $row2 = tep_db_fetch_array($result2);
  1170.  
  1171.                 $ll++;
  1172.  
  1173.             }
  1174.  
  1175.         }
  1176.  
  1177.         if ($dltype == 'froogle'){
  1178.  
  1179.             // For froogle, we check the specials prices for any applicable specials, and use that price
  1180.  
  1181.             // by grabbing the specials id descending, we always get the most recently added special price
  1182.  
  1183.             // I'm checking status because I think you can turn off specials
  1184.  
  1185.             $sql2 = "SELECT
  1186.  
  1187.                     specials_new_products_price
  1188.  
  1189.                 FROM
  1190.  
  1191.                     ".TABLE_SPECIALS."
  1192.  
  1193.                 WHERE
  1194.  
  1195.                 products_id = " . $row['v_products_id'] . " and
  1196.  
  1197.                 status = 1 and
  1198.  
  1199.                 expires_date < CURRENT_TIMESTAMP
  1200.  
  1201.                 ORDER BY
  1202.  
  1203.                     specials_id DESC"
  1204.  
  1205.                 ;
  1206.  
  1207.             $result2 = tep_db_query($sql2);
  1208.  
  1209.             $ll = 1;
  1210.  
  1211.             $row2 =  tep_db_fetch_array($result2);
  1212.  
  1213.             if( $row2 ){
  1214.  
  1215.                 // reset the products price to our special price if there is one for this product
  1216.  
  1217.                 $row['v_products_price']     = $row2['specials_new_products_price'];
  1218.  
  1219.             }
  1220.  
  1221.         }
  1222.  
  1223.  
  1224.  
  1225.         //elari -
  1226.  
  1227.         //We check the value of tax class and title instead of the id
  1228.  
  1229.         //Then we add the tax to price if $price_with_tax is set to 1
  1230.  
  1231.         $row_tax_multiplier         = tep_get_tax_class_rate($row['v_tax_class_id']);
  1232.  
  1233.         $row['v_tax_class_title']     = tep_get_tax_class_title($row['v_tax_class_id']);
  1234.  
  1235.         $row['v_products_price']     = $row['v_products_price'] +
  1236.  
  1237.                             ($price_with_tax * round($row['v_products_price'] * $row_tax_multiplier / 100,2));
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.         // Now set the status to a word the user specd in the config vars
  1244.  
  1245.         if ( $row['v_status'] == '1' ){
  1246.  
  1247.             $row['v_status'] = $active;
  1248.  
  1249.         } else {
  1250.  
  1251.             $row['v_status'] = $inactive;
  1252.  
  1253.         }
  1254.  
  1255.  
  1256.  
  1257.         // remove any bad things in the texts that could confuse EasyPopulate
  1258.  
  1259.         $therow = '';
  1260.  
  1261.         foreach( $filelayout as $key => $value ){
  1262.  
  1263.             //echo "The field was $key<br>";
  1264.  
  1265.  
  1266.  
  1267.             $thetext = $row[$key];
  1268.  
  1269.             // kill the carriage returns and tabs in the descriptions, they're killing me!
  1270.  
  1271.             $thetext = str_replace("\r",' ',$thetext);
  1272.  
  1273.             $thetext = str_replace("\n",' ',$thetext);
  1274.  
  1275.             $thetext = str_replace("\t",' ',$thetext);
  1276.  
  1277.             // and put the text into the output separated by tabs
  1278.  
  1279.             $therow .= $thetext . $separator;
  1280.  
  1281.         }
  1282.  
  1283.  
  1284.  
  1285.         // lop off the trailing tab, then append the end of row indicator
  1286.  
  1287.         $therow = substr($therow,0,strlen($therow)-1) . $endofrow;
  1288.  
  1289.  
  1290.  
  1291.         $filestring .= $therow;
  1292.  
  1293.         // grab the next row from the db
  1294.  
  1295.         $row =  tep_db_fetch_array($result);
  1296.  
  1297.     }
  1298.  
  1299.  
  1300.  
  1301.     #$EXPORT_TIME=time();
  1302.  
  1303.     $EXPORT_TIME = strftime('%Y%b%d-%H%I');
  1304.  
  1305.     if ($dltype=="froogle"){
  1306.  
  1307.         $EXPORT_TIME = "FroogleEP" . $EXPORT_TIME;
  1308.  
  1309.     } else {
  1310.  
  1311.         $EXPORT_TIME = "EP" . $EXPORT_TIME;
  1312.  
  1313.     }
  1314.  
  1315.  
  1316.  
  1317.     // now either stream it to them or put it in the temp directory
  1318.  
  1319.     if ($download == 'stream'){
  1320.  
  1321.         //*******************************
  1322.  
  1323.         // STREAM FILE
  1324.  
  1325.         //*******************************
  1326.  
  1327.         header("Content-type: application/vnd.ms-excel");
  1328.  
  1329.         header("Content-disposition: attachment; filename=$EXPORT_TIME.txt");
  1330.  
  1331.         header("Pragma: no-cache");
  1332.  
  1333.         header("Expires: 0");
  1334.  
  1335.         echo $filestring;
  1336.  
  1337.         die();
  1338.  
  1339.     } else {
  1340.  
  1341.         //*******************************
  1342.  
  1343.         // PUT FILE IN TEMP DIR
  1344.  
  1345.         //*******************************
  1346.  
  1347.         $tmpfname = DIR_FS_DOCUMENT_ROOT . $tempdir . "$EXPORT_TIME.txt";
  1348.  
  1349.         //unlink($tmpfname);
  1350.  
  1351.         $fp = fopen( $tmpfname, "w+");
  1352.  
  1353.         fwrite($fp, $filestring);
  1354.  
  1355.         fclose($fp);
  1356.  
  1357.         echo "You can get your file in the Tools/Files under " . $tempdir . "EP" . $EXPORT_TIME . ".txt";
  1358.  
  1359.         die();
  1360.  
  1361.     }
  1362.  
  1363. }   // *** END *** download section
  1364.  
  1365. ?>
  1366.  
  1367.  
  1368.  
  1369. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  1370.  
  1371. <html <?php echo HTML_PARAMS; ?>>
  1372.  
  1373. <head>
  1374.  
  1375. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  1376.  
  1377. <title><?php echo TITLE; ?></title>
  1378.  
  1379. <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  1380.  
  1381. </head>
  1382.  
  1383. <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
  1384.  
  1385. <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
  1386.  
  1387.  
  1388.  
  1389. <table border="0" width="100%" cellspacing="2" cellpadding="2">
  1390.  
  1391. <tr>
  1392.  
  1393. <td width="<?php echo BOX_WIDTH; ?>" valign="top" height="27">
  1394.  
  1395. <table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
  1396.  
  1397. <?php require(DIR_WS_INCLUDES . 'column_left.php');?>
  1398.  
  1399. </table></td>
  1400.  
  1401. <td class="pageHeading" valign="top"><?php
  1402.  
  1403. echo "Easy Populate $curver - Default Language : " . $epdlanguage_name . '(' . $epdlanguage_id .')' ;
  1404.  
  1405. ?>
  1406.  
  1407.  
  1408.  
  1409. <p class="smallText">
  1410.  
  1411.  
  1412.  
  1413. <?php
  1414.  
  1415.  
  1416.  
  1417. if ($localfile or (is_uploaded_file($usrfl) && $split==0)) {
  1418.  
  1419.     //*******************************
  1420.  
  1421.     //*******************************
  1422.  
  1423.     // UPLOAD AND INSERT FILE
  1424.  
  1425.     //*******************************
  1426.  
  1427.     //*******************************
  1428.  
  1429.  
  1430.  
  1431.     if ($usrfl){
  1432.  
  1433.         // move the file to where we can work with it
  1434.  
  1435.         $file = tep_get_uploaded_file('usrfl');
  1436.  
  1437.         if (is_uploaded_file($file['tmp_name'])) {
  1438.  
  1439.             tep_copy_uploaded_file($file, DIR_FS_DOCUMENT_ROOT . $tempdir);
  1440.  
  1441.         }
  1442.  
  1443.  
  1444.  
  1445.         echo "<p class=smallText>";
  1446.  
  1447.         echo "File uploaded. <br>";
  1448.  
  1449.         echo "Temporary filename: " . $usrfl . "<br>";
  1450.  
  1451.         echo "User filename: " . $usrfl_name . "<br>";
  1452.  
  1453.         echo "Size: " . $usrfl_size . "<br>";
  1454.  
  1455.  
  1456.  
  1457.         // get the entire file into an array
  1458.  
  1459.         $readed = file(DIR_FS_DOCUMENT_ROOT . $tempdir . $usrfl_name);
  1460.  
  1461.     }
  1462.  
  1463.     if ($localfile){
  1464.  
  1465.         // move the file to where we can work with it
  1466.  
  1467.         $file = tep_get_uploaded_file('usrfl');
  1468.  
  1469.         if (is_uploaded_file($file['tmp_name'])) {
  1470.  
  1471.             tep_copy_uploaded_file($file, DIR_FS_DOCUMENT_ROOT . $tempdir);
  1472.  
  1473.         }
  1474.  
  1475.  
  1476.  
  1477.         echo "<p class=smallText>";
  1478.  
  1479.         echo "Filename: " . $localfile . "<br>";
  1480.  
  1481.  
  1482.  
  1483.         // get the entire file into an array
  1484.  
  1485.         $readed = file(DIR_FS_DOCUMENT_ROOT . $tempdir . $localfile);
  1486.  
  1487.     }
  1488.  
  1489.  
  1490.  
  1491.     // now we string the entire thing together in case there were carriage returns in the data
  1492.  
  1493.     $newreaded = "";
  1494.  
  1495.     foreach ($readed as $read){
  1496.  
  1497.         $newreaded .= $read;
  1498.  
  1499.     }
  1500.  
  1501.  
  1502.  
  1503.     // now newreaded has the entire file together without the carriage returns.
  1504.  
  1505.     // if for some reason excel put qoutes around our EOREOR, remove them then split into rows
  1506.  
  1507.     $newreaded = str_replace('"EOREOR"', 'EOREOR', $newreaded);
  1508.  
  1509.     $readed = explode( $separator . 'EOREOR',$newreaded);
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.     // Now we'll populate the filelayout based on the header row.
  1516.  
  1517.     $theheaders_array = explode( $separator, $readed[0] ); // explode the first row, it will be our filelayout
  1518.  
  1519.     $lll = 0;
  1520.  
  1521.     $filelayout = array();
  1522.  
  1523.     foreach( $theheaders_array as $header ){
  1524.  
  1525.         $cleanheader = str_replace( '"', '', $header);
  1526.  
  1527.     //    echo "Fileheader was $header<br><br><br>";
  1528.  
  1529.         $filelayout[ $cleanheader ] = $lll++; //
  1530.  
  1531.     }
  1532.  
  1533.     unset($readed[0]); //  we don't want to process the headers with the data
  1534.  
  1535.  
  1536.  
  1537.     // now we've got the array broken into parts by the expicit end-of-row marker.
  1538.  
  1539.     array_walk($readed, 'walk');
  1540.  
  1541.  
  1542.  
  1543. }
  1544.  
  1545.  
  1546.  
  1547. if (is_uploaded_file($usrfl) && $split==1) {
  1548.  
  1549.     //*******************************
  1550.  
  1551.     //*******************************
  1552.  
  1553.     // UPLOAD AND SPLIT FILE
  1554.  
  1555.     //*******************************
  1556.  
  1557.     //*******************************
  1558.  
  1559.     // move the file to where we can work with it
  1560.  
  1561.     $file = tep_get_uploaded_file('usrfl');
  1562.  
  1563.     //echo "Trying to move file...";
  1564.  
  1565.     if (is_uploaded_file($file['tmp_name'])) {
  1566.  
  1567.         tep_copy_uploaded_file($file, DIR_FS_DOCUMENT_ROOT . $tempdir);
  1568.  
  1569.     }
  1570.  
  1571.  
  1572.  
  1573.     $infp = fopen(DIR_FS_DOCUMENT_ROOT . $tempdir . $usrfl_name, "r");
  1574.  
  1575.  
  1576.  
  1577.     //toprow has the field headers
  1578.  
  1579.     $toprow = fgets($infp,32768);
  1580.  
  1581.  
  1582.  
  1583.     $filecount = 1;
  1584.  
  1585.  
  1586.  
  1587.     echo "Creating file EP_Split" . $filecount . ".txt ...  ";
  1588.  
  1589.     $tmpfname = DIR_FS_DOCUMENT_ROOT . $tempdir . "EP_Split" . $filecount . ".txt";
  1590.  
  1591.     $fp = fopen( $tmpfname, "w+");
  1592.  
  1593.     fwrite($fp, $toprow);
  1594.  
  1595.  
  1596.  
  1597.     $linecount = 0;
  1598.  
  1599.     $line = fgets($infp,32768);
  1600.  
  1601.     while ($line){
  1602.  
  1603.         // walking the entire file one row at a time
  1604.  
  1605.         // but a line is not necessarily a complete row, we need to split on rows that have "EOREOR" at the end
  1606.  
  1607.         $line = str_replace('"EOREOR"', 'EOREOR', $line);
  1608.  
  1609.         fwrite($fp, $line);
  1610.  
  1611.         if (strpos($line, 'EOREOR')){
  1612.  
  1613.             // we found the end of a line of data, store it
  1614.  
  1615.             $linecount++; // increment our line counter
  1616.  
  1617.             if ($linecount >= $maxrecs){
  1618.  
  1619.                 echo "Added $linecount records and closing file... <Br>";
  1620.  
  1621.                 $linecount = 0; // reset our line counter
  1622.  
  1623.                 // close the existing file and open another;
  1624.  
  1625.                 fclose($fp);
  1626.  
  1627.                 // increment filecount
  1628.  
  1629.                 $filecount++;
  1630.  
  1631.                 echo "Creating file EP_Split" . $filecount . ".txt ...  ";
  1632.  
  1633.                 $tmpfname = DIR_FS_DOCUMENT_ROOT . $tempdir . "EP_Split" . $filecount . ".txt";
  1634.  
  1635.                 //Open next file name
  1636.  
  1637.                 $fp = fopen( $tmpfname, "w+");
  1638.  
  1639.                 fwrite($fp, $toprow);
  1640.  
  1641.             }
  1642.  
  1643.         }
  1644.  
  1645.         $line=fgets($infp,32768);
  1646.  
  1647.     }
  1648.  
  1649.     echo "Added $linecount records and closing file...<br><br> ";
  1650.  
  1651.     fclose($fp);
  1652.  
  1653.     fclose($infp);
  1654.  
  1655.  
  1656.  
  1657.     echo "You can download your split files in the Tools/Files under /catalog/temp/";
  1658.  
  1659.  
  1660.  
  1661. }
  1662.  
  1663.  
  1664.  
  1665. ?>
  1666.  
  1667.       </p>
  1668.  
  1669.  
  1670.  
  1671.       <table width="75%" border="2">
  1672.  
  1673.         <tr>
  1674.  
  1675.           <td width="75%">
  1676.  
  1677.            <FORM ENCTYPE="multipart/form-data" ACTION="easypopulate.php?split=0" METHOD=POST>
  1678.  
  1679.               <p>
  1680.  
  1681.                 <div align = "left">
  1682.  
  1683.                 <p><b>Upload EP File</b></p>
  1684.  
  1685.                 <p>
  1686.  
  1687.                   <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000000">
  1688.  
  1689.                   <p></p>
  1690.  
  1691.                   <input name="usrfl" type="file" size="50">
  1692.  
  1693.                   <input type="submit" name="buttoninsert" value="Insert into db"><br>
  1694.  
  1695.                 </p>
  1696.  
  1697.               </div>
  1698.  
  1699.  
  1700.  
  1701.               </form>
  1702.  
  1703.  
  1704.  
  1705.            <FORM ENCTYPE="multipart/form-data" ACTION="easypopulate.php?split=1" METHOD=POST>
  1706.  
  1707.               <p>
  1708.  
  1709.                 <div align = "left">
  1710.  
  1711.                 <p><b>Split EP File</b></p>
  1712.  
  1713.                 <p>
  1714.  
  1715.                   <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000000">
  1716.  
  1717.                   <p></p>
  1718.  
  1719.                   <input name="usrfl" type="file" size="50">
  1720.  
  1721.                   <input type="submit" name="buttonsplit" value="Split file"><br>
  1722.  
  1723.                 </p>
  1724.  
  1725.               </div>
  1726.  
  1727.  
  1728.  
  1729.              </form>
  1730.  
  1731.  
  1732.  
  1733.            <FORM ENCTYPE="multipart/form-data" ACTION="easypopulate.php" METHOD=POST>
  1734.  
  1735.               <p>
  1736.  
  1737.                 <div align = "left">
  1738.  
  1739.                 <p><b>Import from Temp Dir (<? echo $tempdir; ?>)</b></p>
  1740.  
  1741.         <p class="smallText">
  1742.  
  1743.         <INPUT TYPE="text" name="localfile" size="50">
  1744.  
  1745.                   <input type="submit" name="buttoninsert" value="Insert into db"><br>
  1746.  
  1747.                 </p>
  1748.  
  1749.               </div>
  1750.  
  1751.  
  1752.  
  1753.              </form>
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.         <p><b>Download EP and Froogle Files</b></p>
  1764.  
  1765.  
  1766.  
  1767.           <!-- Download file links -  Add your custom fields here -->
  1768.  
  1769.       <a href="easypopulate.php?download=stream&dltype=full">Download <b>Complete</b> tab-delimited .txt file to edit</a><br>
  1770.  
  1771.       <a href="easypopulate.php?download=stream&dltype=priceqty">Download <b>Model/Price/Qty</b> tab-delimited .txt file to edit</a><br>
  1772.  
  1773.       <a href="easypopulate.php?download=stream&dltype=category">Download <b>Model/Category</b> tab-delimited .txt file to edit</a><br>
  1774.  
  1775.       <a href="easypopulate.php?download=stream&dltype=froogle">Download <b>Froogle</b> tab-delimited .txt file</a><br>
  1776.  
  1777.  
  1778.  
  1779.         <p><b>Create EP and Froogle Files in Temp Dir (<? echo $tempdir; ?>)</b></p>
  1780.  
  1781.       <a href="easypopulate.php?download=tempfile&dltype=full">Create Complete tab-delimited .txt file in temp dir</a><br>
  1782.  
  1783.           <a href="easypopulate.php?download=tempfile&dltype=priceqty"">Create Model/Price/Qty tab-delimited .txt file in temp dir</a><br>
  1784.  
  1785.           <a href="easypopulate.php?download=tempfile&dltype=category">Create Model/Category tab-delimited .txt file in temp dir</a><br>
  1786.  
  1787.       <a href="easypopulate.php?download=tempfile&dltype=froogle">Create Froogle tab-delimited .txt file in temp dir</a><br>
  1788.  
  1789.       </td>
  1790.  
  1791.     </tr>
  1792.  
  1793.       </table>
  1794.  
  1795.     </td>
  1796.  
  1797.  </tr>
  1798.  
  1799. </table>
  1800.  
  1801.  
  1802.  
  1803. <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  1804.  
  1805.  
  1806.  
  1807. <p>†</p>
  1808.  
  1809. <p>†</p><p><br>
  1810.  
  1811. </p></body>
  1812.  
  1813. </html>
  1814.  
  1815.  
  1816.  
  1817. <?php
  1818.  
  1819.  
  1820.  
  1821. function ep_get_languages() {
  1822.  
  1823.     $languages_query = tep_db_query("select languages_id, code from " . TABLE_LANGUAGES . " order by sort_order");
  1824.  
  1825.     // start array at one, the rest of the code expects it that way
  1826.  
  1827.     $ll =1;
  1828.  
  1829.     while ($ep_languages = tep_db_fetch_array($languages_query)) {
  1830.  
  1831.         //will be used to return language_id en language code to report in product_name_code instead of product_name_id
  1832.  
  1833.         $ep_languages_array[$ll++] = array(
  1834.  
  1835.                     'id' => $ep_languages['languages_id'],
  1836.  
  1837.                     'code' => $ep_languages['code']
  1838.  
  1839.                     );
  1840.  
  1841.     }
  1842.  
  1843.     return $ep_languages_array;
  1844.  
  1845. };
  1846.  
  1847.  
  1848.  
  1849. function tep_get_tax_class_rate($tax_class_id) {
  1850.  
  1851.     $tax_multiplier = 0;
  1852.  
  1853.     $tax_query = tep_db_query("select SUM(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " WHERE  tax_class_id = '" . $tax_class_id . "' GROUP BY tax_priority");
  1854.  
  1855.     if (tep_db_num_rows($tax_query)) {
  1856.  
  1857.         while ($tax = tep_db_fetch_array($tax_query)) {
  1858.  
  1859.             $tax_multiplier += $tax['tax_rate'];
  1860.  
  1861.         }
  1862.  
  1863.     }
  1864.  
  1865.     return $tax_multiplier;
  1866.  
  1867. };
  1868.  
  1869.  
  1870.  
  1871. function tep_get_tax_title_class_id($tax_class_title) {
  1872.  
  1873.     $classes_query = tep_db_query("select tax_class_id from " . TABLE_TAX_CLASS . " WHERE tax_class_title = '" . $tax_class_title . "'" );
  1874.  
  1875.     $tax_class_array = tep_db_fetch_array($classes_query);
  1876.  
  1877.     $tax_class_id = $tax_class_array['tax_class_id'];
  1878.  
  1879.     return $tax_class_id ;
  1880.  
  1881. }
  1882.  
  1883.  
  1884.  
  1885. function print_el( $item2 ) {
  1886.  
  1887.     echo " | " . substr(strip_tags($item2), 0, 10);
  1888.  
  1889. };
  1890.  
  1891.  
  1892.  
  1893. function print_el1( $item2 ) {
  1894.  
  1895.     echo sprintf("| %'.4s ", substr(strip_tags($item2), 0, 80));
  1896.  
  1897. };
  1898.  
  1899. function ep_create_filelayout($dltype){
  1900.  
  1901.     global $filelayout, $filelayout_count, $filelayout_sql, $langcode, $fileheaders, $max_categories;
  1902.  
  1903.     // depending on the type of the download the user wanted, create a file layout for it.
  1904.  
  1905.     $fieldmap = array(); // default to no mapping to change internal field names to external.
  1906.  
  1907.     switch( $dltype ){
  1908.  
  1909.     case 'full':
  1910.  
  1911.         // The file layout is dynamically made depending on the number of languages
  1912.  
  1913.         $iii = 0;
  1914.  
  1915.         $filelayout = array(
  1916.  
  1917.             'v_products_model'        => $iii++,
  1918.  
  1919.             'v_products_image'        => $iii++,
  1920.  
  1921.             );
  1922.  
  1923.  
  1924.  
  1925.         foreach ($langcode as $key => $lang){
  1926.  
  1927.             $l_id = $lang['id'];
  1928.  
  1929.             // uncomment the head_title, head_desc, and head_keywords to use
  1930.  
  1931.             // Linda's Header Tag Controller 2.0
  1932.  
  1933.             //echo $langcode['id'] . $langcode['code'];
  1934.  
  1935.             $filelayout  = array_merge($filelayout , array(
  1936.  
  1937.                     'v_products_name_' . $l_id        => $iii++,
  1938.  
  1939.                     'v_products_description_' . $l_id    => $iii++,
  1940.  
  1941.                     'v_products_url_' . $l_id    => $iii++,
  1942.  
  1943.             //        'v_products_head_title_tag_'.$l_id    => $iii++,
  1944.  
  1945.             //        'v_products_head_desc_tag_'.$l_id    => $iii++,
  1946.  
  1947.             //        'v_products_head_keywords_tag_'.$l_id    => $iii++,
  1948.  
  1949.                     ));
  1950.  
  1951.         }
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.         // uncomment the customer_price and customer_group to support multi-price per product contrib
  1958.  
  1959.  
  1960.  
  1961.         $filelayout  = array_merge($filelayout , array(
  1962.  
  1963.             'v_products_price'        => $iii++,
  1964.  
  1965.             'v_products_weight'        => $iii++,
  1966.  
  1967.             'v_date_avail'            => $iii++,
  1968.  
  1969.             'v_date_added'            => $iii++,
  1970.  
  1971.             'v_products_quantity'        => $iii++,
  1972.  
  1973.             'v_customer_price_1'        => $iii++,
  1974.  
  1975.             'v_customer_group_id_1'        => $iii++,
  1976.  
  1977.             'v_customer_price_2'        => $iii++,
  1978.  
  1979.             'v_customer_group_id_2'        => $iii++,
  1980.  
  1981.             #'v_customer_price_3'        => $iii++,
  1982.  
  1983.             #'v_customer_group_id_3'        => $iii++,
  1984.  
  1985.             #'v_customer_price_4'        => $iii++,
  1986.  
  1987.             #'v_customer_group_id_4'        => $iii++,
  1988.  
  1989.             'v_manufacturers_name'        => $iii++,
  1990.  
  1991.             ));
  1992.  
  1993.  
  1994.  
  1995.         // build the categories name section of the array based on the number of categores the user wants to have
  1996.  
  1997.         for($i=1;$i<$max_categories+1;$i++){
  1998.  
  1999.             $filelayout = array_merge($filelayout, array('v_categories_name_' . $i => $iii++));
  2000.  
  2001.         }
  2002.  
  2003.  
  2004.  
  2005.         $filelayout = array_merge($filelayout, array(
  2006.  
  2007.             'v_tax_class_title'        => $iii++,
  2008.  
  2009.             'v_status'            => $iii++,
  2010.  
  2011.             ));
  2012.  
  2013.  
  2014.  
  2015.         $filelayout_sql = "SELECT
  2016.  
  2017.             p.products_id as v_products_id,
  2018.  
  2019.             p.products_model as v_products_model,
  2020.  
  2021.             p.products_image as v_products_image,
  2022.  
  2023.             p.products_price as v_products_price,
  2024.  
  2025.             p.products_weight as v_products_weight,
  2026.  
  2027.             p.products_date_available as v_date_avail,
  2028.  
  2029.             p.products_date_added as v_date_added,
  2030.  
  2031.             p.products_tax_class_id as v_tax_class_id,
  2032.  
  2033.             p.products_quantity as v_products_quantity,
  2034.  
  2035.             p.manufacturers_id as v_manufacturers_id,
  2036.  
  2037.             subc.categories_id as v_categories_id,
  2038.  
  2039.             p.products_status as v_status
  2040.  
  2041.             FROM
  2042.  
  2043.             ".TABLE_PRODUCTS." as p,
  2044.  
  2045.             ".TABLE_CATEGORIES." as subc,
  2046.  
  2047.             ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
  2048.  
  2049.             WHERE
  2050.  
  2051.             p.products_id = ptoc.products_id AND
  2052.  
  2053.             ptoc.categories_id = subc.categories_id
  2054.  
  2055.             ";
  2056.  
  2057.  
  2058.  
  2059.         break;
  2060.  
  2061.     case 'priceqty':
  2062.  
  2063.         $iii = 0;
  2064.  
  2065.         // uncomment the customer_price and customer_group to support multi-price per product contrib
  2066.  
  2067.         $filelayout = array(
  2068.  
  2069.             'v_products_model'        => $iii++,
  2070.  
  2071.             'v_products_price'        => $iii++,
  2072.  
  2073.             'v_products_quantity'        => $iii++,
  2074.  
  2075.             'v_customer_price_1'        => $iii++,
  2076.  
  2077.             'v_customer_group_id_1'        => $iii++,
  2078.  
  2079.             'v_customer_price_2'        => $iii++,
  2080.  
  2081.             'v_customer_group_id_2'        => $iii++,
  2082.  
  2083.             #'v_customer_price_3'        => $iii++,
  2084.  
  2085.             #'v_customer_group_id_3'        => $iii++,
  2086.  
  2087.             #'v_customer_price_4'        => $iii++,
  2088.  
  2089.             #'v_customer_group_id_4'        => $iii++,
  2090.  
  2091.                 );
  2092.  
  2093.         $filelayout_sql = "SELECT
  2094.  
  2095.             p.products_id as v_products_id,
  2096.  
  2097.             p.products_model as v_products_model,
  2098.  
  2099.             p.products_price as v_products_price,
  2100.  
  2101.             p.products_quantity as v_products_quantity
  2102.  
  2103.             FROM
  2104.  
  2105.             ".TABLE_PRODUCTS." as p
  2106.  
  2107.             ";
  2108.  
  2109.  
  2110.  
  2111.         break;
  2112.  
  2113.  
  2114.  
  2115.     case 'category':
  2116.  
  2117.         // The file layout is dynamically made depending on the number of languages
  2118.  
  2119.         $iii = 0;
  2120.  
  2121.         $filelayout = array(
  2122.  
  2123.             'v_products_model'        => $iii++,
  2124.  
  2125.         );
  2126.  
  2127.  
  2128.  
  2129.         // build the categories name section of the array based on the number of categores the user wants to have
  2130.  
  2131.         for($i=1;$i<$max_categories+1;$i++){
  2132.  
  2133.             $filelayout = array_merge($filelayout, array('v_categories_name_' . $i => $iii++));
  2134.  
  2135.         }
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.         $filelayout_sql = "SELECT
  2142.  
  2143.             p.products_id as v_products_id,
  2144.  
  2145.             p.products_model as v_products_model,
  2146.  
  2147.             subc.categories_id as v_categories_id
  2148.  
  2149.             FROM
  2150.  
  2151.             ".TABLE_PRODUCTS." as p,
  2152.  
  2153.             ".TABLE_CATEGORIES." as subc,
  2154.  
  2155.             ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc            
  2156.  
  2157.             WHERE
  2158.  
  2159.             p.products_id = ptoc.products_id AND
  2160.  
  2161.             ptoc.categories_id = subc.categories_id
  2162.  
  2163.             ";
  2164.  
  2165.         break;
  2166.  
  2167.  
  2168.  
  2169.     case 'froogle':
  2170.  
  2171.         // this is going to be a little interesting because we need
  2172.  
  2173.         // a way to map from internal names to external names
  2174.  
  2175.         //
  2176.  
  2177.         // Before it didn't matter, but with froogle needing particular headers,
  2178.  
  2179.         // The file layout is dynamically made depending on the number of languages
  2180.  
  2181.         $iii = 0;
  2182.  
  2183.         $filelayout = array(
  2184.  
  2185.             'v_froogle_products_url_1'            => $iii++,
  2186.  
  2187.             );
  2188.  
  2189.         //
  2190.  
  2191.         // here we need to get the default language and put
  2192.  
  2193.         $l_id = 1; // dummy it in for now.
  2194.  
  2195. //        foreach ($langcode as $key => $lang){
  2196.  
  2197. //            $l_id = $lang['id'];
  2198.  
  2199.             $filelayout  = array_merge($filelayout , array(
  2200.  
  2201.                     'v_froogle_products_name_' . $l_id        => $iii++,
  2202.  
  2203.                     'v_froogle_products_description_' . $l_id    => $iii++,
  2204.  
  2205.                     ));
  2206.  
  2207. //        }
  2208.  
  2209.         $filelayout  = array_merge($filelayout , array(
  2210.  
  2211.             'v_products_price'        => $iii++,
  2212.  
  2213.             'v_products_fullpath_image'    => $iii++,
  2214.  
  2215.             'v_category_fullpath'        => $iii++,
  2216.  
  2217.             'v_froogle_offer_id'        => $iii++,
  2218.  
  2219.             'v_froogle_instock'        => $iii++,
  2220.  
  2221.             'v_froogle_ shipping'        => $iii++,
  2222.  
  2223.             'v_manufacturers_name'        => $iii++,
  2224.  
  2225.             'v_froogle_ upc'        => $iii++,
  2226.  
  2227.             'v_froogle_color'        => $iii++,
  2228.  
  2229.             'v_froogle_size'        => $iii++,
  2230.  
  2231.             'v_froogle_quantitylevel'    => $iii++,
  2232.  
  2233.             'v_froogle_product_id'        => $iii++,
  2234.  
  2235.             'v_froogle_manufacturer_id'    => $iii++,
  2236.  
  2237.             'v_froogle_exp_date'        => $iii++,
  2238.  
  2239.             'v_froogle_product_type'    => $iii++,
  2240.  
  2241.             'v_froogle_delete'        => $iii++,
  2242.  
  2243.             'v_froogle_currency'        => $iii++,
  2244.  
  2245.                 ));
  2246.  
  2247.         $iii=0;
  2248.  
  2249.         $fileheaders = array(
  2250.  
  2251.             'product_url'        => $iii++,
  2252.  
  2253.             'name'            => $iii++,
  2254.  
  2255.             'description'        => $iii++,
  2256.  
  2257.             'price'            => $iii++,
  2258.  
  2259.             'image_url'        => $iii++,
  2260.  
  2261.             'category'        => $iii++,
  2262.  
  2263.             'offer_id'        => $iii++,
  2264.  
  2265.             'instock'        => $iii++,
  2266.  
  2267.             'shipping'        => $iii++,
  2268.  
  2269.             'brand'            => $iii++,
  2270.  
  2271.             'upc'            => $iii++,
  2272.  
  2273.             'color'            => $iii++,
  2274.  
  2275.             'size'            => $iii++,
  2276.  
  2277.             'quantity'        => $iii++,
  2278.  
  2279.             'product_id'        => $iii++,
  2280.  
  2281.             'manufacturer_id'    => $iii++,
  2282.  
  2283.             'exp_date'        => $iii++,
  2284.  
  2285.             'product_type'        => $iii++,
  2286.  
  2287.             'delete'        => $iii++,
  2288.  
  2289.             'currency'        => $iii++,
  2290.  
  2291.             );
  2292.  
  2293.         $filelayout_sql = "SELECT
  2294.  
  2295.             p.products_id as v_products_id,
  2296.  
  2297.             p.products_model as v_products_model,
  2298.  
  2299.             p.products_image as v_products_image,
  2300.  
  2301.             p.products_price as v_products_price,
  2302.  
  2303.             p.products_weight as v_products_weight,
  2304.  
  2305.             p.products_date_added as v_date_avail,
  2306.  
  2307.             p.products_tax_class_id as v_tax_class_id,
  2308.  
  2309.             p.products_quantity as v_products_quantity,
  2310.  
  2311.             p.manufacturers_id as v_manufacturers_id,
  2312.  
  2313.             subc.categories_id as v_categories_id
  2314.  
  2315.             FROM
  2316.  
  2317.             ".TABLE_PRODUCTS." as p,
  2318.  
  2319.             ".TABLE_CATEGORIES." as subc,
  2320.  
  2321.             ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
  2322.  
  2323.             WHERE
  2324.  
  2325.             p.products_id = ptoc.products_id AND
  2326.  
  2327.             ptoc.categories_id = subc.categories_id
  2328.  
  2329.             ";
  2330.  
  2331.         break;
  2332.  
  2333.  
  2334.  
  2335.     }
  2336.  
  2337.     $filelayout_count = count($filelayout);
  2338.  
  2339.  
  2340.  
  2341. }
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347. function walk( $item1 ) {
  2348.  
  2349.     global $filelayout, $filelayout_count, $modelsize;
  2350.  
  2351.     global $active, $inactive, $langcode, $default_these, $deleteit, $zero_qty_inactive;
  2352.  
  2353.         global $epdlanguage_id, $price_with_tax, $replace_quotes;
  2354.  
  2355.     global $default_images, $default_image_manufacturer, $default_image_product, $default_image_category;
  2356.  
  2357.     global $separator, $max_categories;
  2358.  
  2359.     // first we clean up the row of data
  2360.  
  2361.  
  2362.  
  2363.     // chop blanks from each end
  2364.  
  2365.     $item1 = ltrim(rtrim($item1));
  2366.  
  2367.  
  2368.  
  2369.     // blow it into an array, splitting on the tabs
  2370.  
  2371.     $items = explode($separator, $item1);
  2372.  
  2373.  
  2374.  
  2375.     // make sure all non-set things are set to '';
  2376.  
  2377.     // and strip the quotes from the start and end of the stings.
  2378.  
  2379.     // escape any special chars for the database.
  2380.  
  2381.     foreach( $filelayout as $key=> $value){
  2382.  
  2383.         $i = $filelayout[$key];
  2384.  
  2385.         if (isset($items[$i]) == false) {
  2386.  
  2387.             $items[$i]='';
  2388.  
  2389.         } else {
  2390.  
  2391.             // Check to see if either of the magic_quotes are turned on or off;
  2392.  
  2393.             // And apply filtering accordingly.
  2394.  
  2395.             if (function_exists('ini_get')) {
  2396.  
  2397.                 //echo "Getting ready to check magic quotes<br>";
  2398.  
  2399.                 if (ini_get('magic_quotes_runtime') == 1){
  2400.  
  2401.                     // The magic_quotes_runtime are on, so lets account for them
  2402.  
  2403.                     // check if the last character is a quote;
  2404.  
  2405.                     // if it is, chop off the quotes.
  2406.  
  2407.                     if (substr($items[$i],-1) == '"'){
  2408.  
  2409.                         $items[$i] = substr($items[$i],2,strlen($items[$i])-4);
  2410.  
  2411.                     }
  2412.  
  2413.                     // now any remaining doubled double quotes should be converted to one doublequote
  2414.  
  2415.                     $items[$i] = str_replace('\"\"',""",$items[$i]);
  2416.  
  2417.                     if ($replace_quotes){
  2418.  
  2419.                         $items[$i] = str_replace('\"',""",$items[$i]);
  2420.  
  2421.                         $items[$i] = str_replace("\'","'",$items[$i]);
  2422.  
  2423.                     }
  2424.  
  2425.                 } else { // no magic_quotes are on
  2426.  
  2427.                     // check if the last character is a quote;
  2428.  
  2429.                     // if it is, chop off the 1st and last character of the string.
  2430.  
  2431.                     if (substr($items[$i],-1) == '"'){
  2432.  
  2433.                         $items[$i] = substr($items[$i],1,strlen($items[$i])-2);
  2434.  
  2435.                     }
  2436.  
  2437.                     // now any remaining doubled double quotes should be converted to one doublequote
  2438.  
  2439.                     $items[$i] = str_replace('""',""",$items[$i]);
  2440.  
  2441.                     if ($replace_quotes){
  2442.  
  2443.                         $items[$i] = str_replace('"',""",$items[$i]);
  2444.  
  2445.                         $items[$i] = str_replace("'","'",$items[$i]);
  2446.  
  2447.                     }
  2448.  
  2449.                 }
  2450.  
  2451.             }
  2452.  
  2453.         }
  2454.  
  2455.     }
  2456.  
  2457. /*
  2458.  
  2459.     if ( $items['v_status'] == $deleteit ){
  2460.  
  2461.         // they want to delete this product.
  2462.  
  2463.         echo "Deleting product " . $items['v_products_model'] . " from the database<br>";
  2464.  
  2465.         // Get the ID
  2466.  
  2467.  
  2468.  
  2469.         // kill in the products_to_categories
  2470.  
  2471.  
  2472.  
  2473.         // Kill in the products table
  2474.  
  2475.  
  2476.  
  2477.         return; // we're done deleteing!
  2478.  
  2479.     }
  2480.  
  2481. */
  2482.  
  2483.     // now do a query to get the record's current contents
  2484.  
  2485.     $sql = "SELECT
  2486.  
  2487.         p.products_id as v_products_id,
  2488.  
  2489.         p.products_model as v_products_model,
  2490.  
  2491.         p.products_image as v_products_image,
  2492.  
  2493.         p.products_price as v_products_price,
  2494.  
  2495.         p.products_weight as v_products_weight,
  2496.  
  2497.         p.products_date_added as v_date_avail,
  2498.  
  2499.         p.products_tax_class_id as v_tax_class_id,
  2500.  
  2501.         p.products_quantity as v_products_quantity,
  2502.  
  2503.         p.manufacturers_id as v_manufacturers_id,
  2504.  
  2505.         subc.categories_id as v_categories_id
  2506.  
  2507.         FROM
  2508.  
  2509.         ".TABLE_PRODUCTS." as p,
  2510.  
  2511.         ".TABLE_CATEGORIES." as subc,
  2512.  
  2513.         ".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
  2514.  
  2515.         WHERE
  2516.  
  2517.         p.products_id = ptoc.products_id AND
  2518.  
  2519.         p.products_model = '" . $items[$filelayout['v_products_model']] . "' AND
  2520.  
  2521.         ptoc.categories_id = subc.categories_id
  2522.  
  2523.         ";
  2524.  
  2525.  
  2526.  
  2527.     $result = tep_db_query($sql);
  2528.  
  2529.     $row =  tep_db_fetch_array($result);
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.     while ($row){
  2536.  
  2537.         // OK, since we got a row, the item already exists.
  2538.  
  2539.         // Let's get all the data we need and fill in all the fields that need to be defaulted to the current values
  2540.  
  2541.         // for each language, get the description and set the vals
  2542.  
  2543.         foreach ($langcode as $key => $lang){
  2544.  
  2545.             //echo "Inside defaulting loop";
  2546.  
  2547.             //echo "key is $key<br>";
  2548.  
  2549.             //echo "langid is " . $lang['id'] . "<br>";
  2550.  
  2551. //            $sql2 = "SELECT products_name, products_description
  2552.  
  2553. //                FROM ".TABLE_PRODUCTS_DESCRIPTION."
  2554.  
  2555. //                WHERE
  2556.  
  2557. //                    products_id = " . $row['v_products_id'] . " AND
  2558.  
  2559. //                    language_id = '" . $lang['id'] . "'
  2560.  
  2561. //                ";
  2562.  
  2563.             $sql2 = "SELECT *
  2564.  
  2565.                 FROM ".TABLE_PRODUCTS_DESCRIPTION."
  2566.  
  2567.                 WHERE
  2568.  
  2569.                     products_id = " . $row['v_products_id'] . " AND
  2570.  
  2571.                     language_id = '" . $lang['id'] . "'
  2572.  
  2573.                 ";
  2574.  
  2575.             $result2 = tep_db_query($sql2);
  2576.  
  2577.             $row2 =  tep_db_fetch_array($result2);
  2578.  
  2579.                         // Need to report from ......_name_1 not ..._name_0
  2580.  
  2581.             $row['v_products_name_' . $lang['id']]         = $row2['products_name'];
  2582.  
  2583.             $row['v_products_description_' . $lang['id']]     = $row2['products_description'];
  2584.  
  2585.             $row['v_products_url_' . $lang['id']]         = $row2['products_url'];
  2586.  
  2587.  
  2588.  
  2589.             // support for Linda's Header Controller 2.0 here
  2590.  
  2591.             if(isset($filelayout['v_products_head_title_tag_' . $lang['id'] ])){
  2592.  
  2593.                 $row['v_products_head_title_tag_' . $lang['id']]     = $row2['products_head_title_tag'];
  2594.  
  2595.                 $row['v_products_head_desc_tag_' . $lang['id']]     = $row2['products_head_desc_tag'];
  2596.  
  2597.                 $row['v_products_head_keywords_tag_' . $lang['id']]     = $row2['products_head_keywords_tag'];
  2598.  
  2599.             }
  2600.  
  2601.             // end support for Header Controller 2.0
  2602.  
  2603.         }
  2604.  
  2605.  
  2606.  
  2607.         // start with v_categories_id
  2608.  
  2609.         // Get the category description
  2610.  
  2611.         // set the appropriate variable name
  2612.  
  2613.         // if parent_id is not null, then follow it up.
  2614.  
  2615.         $thecategory_id = $row['v_categories_id'];
  2616.  
  2617.  
  2618.  
  2619.         for( $categorylevel=1; $categorylevel<$max_categories+1; $categorylevel++){
  2620.  
  2621.             if ($thecategory_id){
  2622.  
  2623.                 $sql2 = "SELECT categories_name
  2624.  
  2625.                     FROM ".TABLE_CATEGORIES_DESCRIPTION."
  2626.  
  2627.                     WHERE
  2628.  
  2629.                         categories_id = " . $thecategory_id . " AND
  2630.  
  2631.                         language_id = " . $epdlanguage_id ;
  2632.  
  2633.  
  2634.  
  2635.                 $result2 = tep_db_query($sql2);
  2636.  
  2637.                 $row2 =  tep_db_fetch_array($result2);
  2638.  
  2639.                 // only set it if we found something
  2640.  
  2641.                 $temprow['v_categories_name_' . $categorylevel] = $row2['categories_name'];
  2642.  
  2643.                 // now get the parent ID if there was one
  2644.  
  2645.                 $sql3 = "SELECT parent_id
  2646.  
  2647.                     FROM ".TABLE_CATEGORIES."
  2648.  
  2649.                     WHERE
  2650.  
  2651.                         categories_id = " . $thecategory_id;
  2652.  
  2653.                 $result3 = tep_db_query($sql3);
  2654.  
  2655.                 $row3 =  tep_db_fetch_array($result3);
  2656.  
  2657.                 $theparent_id = $row3['parent_id'];
  2658.  
  2659.                 if ($theparent_id != ''){
  2660.  
  2661.                     // there was a parent ID, lets set thecategoryid to get the next level
  2662.  
  2663.                     $thecategory_id = $theparent_id;
  2664.  
  2665.                 } else {
  2666.  
  2667.                     // we have found the top level category for this item,
  2668.  
  2669.                     $thecategory_id = false;
  2670.  
  2671.                 }
  2672.  
  2673.             } else {
  2674.  
  2675.                     $temprow['v_categories_name_' . $categorylevel] = '';
  2676.  
  2677.             }
  2678.  
  2679.         }
  2680.  
  2681.         // temprow has the old style low to high level categories.
  2682.  
  2683.         $newlevel = 1;
  2684.  
  2685.         // let's turn them into high to low level categories
  2686.  
  2687.         for( $categorylevel=$max_categories+1; $categorylevel>0; $categorylevel--){
  2688.  
  2689.             if ($temprow['v_categories_name_' . $categorylevel] != ''){
  2690.  
  2691.                 $row['v_categories_name_' . $newlevel++] = $temprow['v_categories_name_' . $categorylevel];
  2692.  
  2693.             }
  2694.  
  2695.         }
  2696.  
  2697.  
  2698.  
  2699.         if ($row['v_manufacturers_id'] != ''){
  2700.  
  2701.             $sql2 = "SELECT manufacturers_name
  2702.  
  2703.                 FROM ".TABLE_MANUFACTURERS."
  2704.  
  2705.                 WHERE
  2706.  
  2707.                 manufacturers_id = " . $row['v_manufacturers_id']
  2708.  
  2709.                 ;
  2710.  
  2711.             $result2 = tep_db_query($sql2);
  2712.  
  2713.             $row2 =  tep_db_fetch_array($result2);
  2714.  
  2715.             $row['v_manufacturers_name'] = $row2['manufacturers_name'];
  2716.  
  2717.         }
  2718.  
  2719.  
  2720.  
  2721.         //elari -
  2722.  
  2723.         //We check the value of tax class and title instead of the id
  2724.  
  2725.         //Then we add the tax to price if $price_with_tax is set to true
  2726.  
  2727.         $row_tax_multiplier = tep_get_tax_class_rate($row['v_tax_class_id']);
  2728.  
  2729.         $row['v_tax_class_title'] = tep_get_tax_class_title($row['v_tax_class_id']);
  2730.  
  2731.         if ($price_with_tax){
  2732.  
  2733.             $row['v_products_price'] = $row['v_products_price'] + round($row['v_products_price']* $row_tax_multiplier / 100,2);
  2734.  
  2735.         }
  2736.  
  2737.  
  2738.  
  2739.         // now create the internal variables that will be used
  2740.  
  2741.         // the $$thisvar is on purpose: it creates a variable named what ever was in $thisvar and sets the value
  2742.  
  2743.         foreach ($default_these as $thisvar){
  2744.  
  2745.             $$thisvar    = $row[$thisvar];
  2746.  
  2747.         }
  2748.  
  2749.  
  2750.  
  2751.         $row =  tep_db_fetch_array($result);
  2752.  
  2753.     }
  2754.  
  2755.  
  2756.  
  2757.     // this is an important loop.  What it does is go thru all the fields in the incoming file and set the internal vars.
  2758.  
  2759.     // Internal vars not set here are either set in the loop above for existing records, or not set at all (null values)
  2760.  
  2761.     // the array values are handled separatly, although they will set variables in this loop, we won't use them.
  2762.  
  2763.     foreach( $filelayout as $key => $value ){
  2764.  
  2765.         $$key = $items[ $value ];
  2766.  
  2767.     }
  2768.  
  2769.  
  2770.  
  2771.         // so how to handle these?  we shouldn't built the array unless it's been giving to us.
  2772.  
  2773.     // The assumption is that if you give us names and descriptions, then you give us name and description for all applicable languages
  2774.  
  2775.     foreach ($langcode as $lang){
  2776.  
  2777.         //echo "Langid is " . $lang['id'] . "<br>";
  2778.  
  2779.         $l_id = $lang['id'];
  2780.  
  2781.         if (isset($filelayout['v_products_name_' . $l_id ])){
  2782.  
  2783.             //we set dynamically the language values
  2784.  
  2785.             $v_products_name[$l_id]     = $items[$filelayout['v_products_name_' . $l_id]];
  2786.  
  2787.             $v_products_description[$l_id]     = $items[$filelayout['v_products_description_' . $l_id ]];
  2788.  
  2789.             $v_products_url[$l_id]         = $items[$filelayout['v_products_url_' . $l_id ]];
  2790.  
  2791.             // support for Linda's Header Controller 2.0 here
  2792.  
  2793.             if(isset($filelayout['v_products_head_title_tag_' . $l_id])){
  2794.  
  2795.                 $v_products_head_title_tag[$l_id]     = $items[$filelayout['v_products_head_title_tag_' . $l_id]];
  2796.  
  2797.                 $v_products_head_desc_tag[$l_id]     = $items[$filelayout['v_products_head_desc_tag_' . $l_id]];
  2798.  
  2799.                 $v_products_head_keywords_tag[$l_id]     = $items[$filelayout['v_products_head_keywords_tag_' . $l_id]];
  2800.  
  2801.             }
  2802.  
  2803.             // end support for Header Controller 2.0
  2804.  
  2805.         }
  2806.  
  2807.     }
  2808.  
  2809.     //elari... we get the tax_clas_id from the tax_title
  2810.  
  2811.     //on screen will still be displayed the tax_class_title instead of the id....
  2812.  
  2813.     if ( isset( $v_tax_class_title) ){
  2814.  
  2815.         $v_tax_class_id          = tep_get_tax_title_class_id($v_tax_class_title);
  2816.  
  2817.     }
  2818.  
  2819.     //we check the tax rate of this tax_class_id
  2820.  
  2821.         $row_tax_multiplier = tep_get_tax_class_rate($v_tax_class_id);
  2822.  
  2823.  
  2824.  
  2825.     //And we recalculate price without the included tax...
  2826.  
  2827.     //Since it seems display is made before, the displayed price will still include tax
  2828.  
  2829.     //This is same problem for the tax_clas_id that display tax_class_title
  2830.  
  2831.     if ($price_with_tax){
  2832.  
  2833.         $v_products_price        = round( $v_products_price / (1 + ( $row_tax_multiplier * $price_with_tax/100) ), 2);
  2834.  
  2835.     }
  2836.  
  2837.  
  2838.  
  2839.     // if they give us one category, they give us all 6 categories
  2840.  
  2841.     unset ($v_categories_name); // default to not set.
  2842.  
  2843.     if ( isset( $filelayout['v_categories_name_1'] ) ){
  2844.  
  2845.         $newlevel = 1;
  2846.  
  2847.         for( $categorylevel=6; $categorylevel>0; $categorylevel--){
  2848.  
  2849.             if ( $items[$filelayout['v_categories_name_' . $categorylevel]] != ''){
  2850.  
  2851.                 $v_categories_name[$newlevel++] = $items[$filelayout['v_categories_name_' . $categorylevel]];
  2852.  
  2853.             }
  2854.  
  2855.         }
  2856.  
  2857.         while( $newlevel < $max_categories+1){
  2858.  
  2859.             $v_categories_name[$newlevel++] = ''; // default the remaining items to nothing
  2860.  
  2861.         }
  2862.  
  2863.     }
  2864.  
  2865.  
  2866.  
  2867.     if (ltrim(rtrim($v_products_quantity)) == '') {
  2868.  
  2869.         $v_products_quantity = 1;
  2870.  
  2871.     }
  2872.  
  2873.     if ($v_date_avail == '') {
  2874.  
  2875.         $v_date_avail = "CURRENT_TIMESTAMP";
  2876.  
  2877.     } else {
  2878.  
  2879.         // we put the quotes around it here because we can't put them into the query, because sometimes
  2880.  
  2881.         //   we will use the "current_timestamp", which can't have quotes around it.
  2882.  
  2883.         $v_date_avail = '"' . $v_date_avail . '"';
  2884.  
  2885.     }
  2886.  
  2887.  
  2888.  
  2889.     if ($v_date_added == '') {
  2890.  
  2891.         $v_date_added = "CURRENT_TIMESTAMP";
  2892.  
  2893.     } else {
  2894.  
  2895.         // we put the quotes around it here because we can't put them into the query, because sometimes
  2896.  
  2897.         //   we will use the "current_timestamp", which can't have quotes around it.
  2898.  
  2899.         $v_date_added = '"' . $v_date_added . '"';
  2900.  
  2901.     }
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.     // default the stock if they spec'd it or if it's blank
  2908.  
  2909.     $v_db_status = '1'; // default to active
  2910.  
  2911.     if ($v_status == $inactive){
  2912.  
  2913.         // they told us to deactivate this item
  2914.  
  2915.         $v_db_status = '0';
  2916.  
  2917.     }
  2918.  
  2919.     if ($zero_qty_inactive && $v_products_quantity == 0) {
  2920.  
  2921.         // if they said that zero qty products should be deactivated, let's deactivate if the qty is zero
  2922.  
  2923.         $v_db_status = '0';
  2924.  
  2925.     }
  2926.  
  2927.  
  2928.  
  2929.     if ($v_manufacturer_id==''){
  2930.  
  2931.         $v_manufacturer_id="NULL";
  2932.  
  2933.     }
  2934.  
  2935.  
  2936.  
  2937.     if (trim($v_products_image)==''){
  2938.  
  2939.         $v_products_image = $default_image_product;
  2940.  
  2941.     }
  2942.  
  2943.  
  2944.  
  2945.     if (strlen($v_products_model) > $modelsize ){
  2946.  
  2947.         echo "<font color='red'>" . strlen($v_products_model) . $v_products_model . "... ERROR! - Too many characters in the model number.<br>
  2948.  
  2949.             12 is the maximum on a standard OSC install.<br>
  2950.  
  2951.             Your maximum product_model length is set to $modelsize<br>
  2952.  
  2953.             You can either shorten your model numbers or increase the size of the field in the database.</font>";
  2954.  
  2955.         die();
  2956.  
  2957.     }
  2958.  
  2959.  
  2960.  
  2961.     // OK, we need to convert the manufacturer's name into id's for the database
  2962.  
  2963.     if ( isset($v_manufacturers_name) && $v_manufacturers_name != '' ){
  2964.  
  2965.         $sql = "SELECT man.manufacturers_id
  2966.  
  2967.             FROM ".TABLE_MANUFACTURERS." as man
  2968.  
  2969.             WHERE
  2970.  
  2971.                 man.manufacturers_name = '" . $v_manufacturers_name . "'";
  2972.  
  2973.         $result = tep_db_query($sql);
  2974.  
  2975.         $row =  tep_db_fetch_array($result);
  2976.  
  2977.         if ( $row != '' ){
  2978.  
  2979.             foreach( $row as $item ){
  2980.  
  2981.                 $v_manufacturer_id = $item;
  2982.  
  2983.             }
  2984.  
  2985.         } else {
  2986.  
  2987.             // to add, we need to put stuff in categories and categories_description
  2988.  
  2989.             $sql = "SELECT MAX( manufacturers_id) max FROM ".TABLE_MANUFACTURERS;
  2990.  
  2991.             $result = tep_db_query($sql);
  2992.  
  2993.             $row =  tep_db_fetch_array($result);
  2994.  
  2995.             $max_mfg_id = $row['max']+1;
  2996.  
  2997.             // default the id if there are no manufacturers yet
  2998.  
  2999.             if (!is_numeric($max_mfg_id) ){
  3000.  
  3001.                 $max_mfg_id=1;
  3002.  
  3003.             }
  3004.  
  3005.  
  3006.  
  3007.             // Uncomment this query if you have an older 2.2 codebase
  3008.  
  3009.             /*
  3010.  
  3011.             $sql = "INSERT INTO ".TABLE_MANUFACTURERS."(
  3012.  
  3013.                 manufacturers_id,
  3014.  
  3015.                 manufacturers_name,
  3016.  
  3017.                 manufacturers_image
  3018.  
  3019.                 ) VALUES (
  3020.  
  3021.                 $max_mfg_id,
  3022.  
  3023.                 '$v_manufacturers_name',
  3024.  
  3025.                 '$default_image_manufacturer'
  3026.  
  3027.                 )";
  3028.  
  3029.             */
  3030.  
  3031.  
  3032.  
  3033.             // Comment this query out if you have an older 2.2 codebase
  3034.  
  3035.             $sql = "INSERT INTO ".TABLE_MANUFACTURERS."(
  3036.  
  3037.                 manufacturers_id,
  3038.  
  3039.                 manufacturers_name,
  3040.  
  3041.                 manufacturers_image,
  3042.  
  3043.                 date_added,
  3044.  
  3045.                 last_modified
  3046.  
  3047.                 ) VALUES (
  3048.  
  3049.                 $max_mfg_id,
  3050.  
  3051.                 '$v_manufacturers_name',
  3052.  
  3053.                 '$default_image_manufacturer',
  3054.  
  3055.                 CURRENT_TIMESTAMP,
  3056.  
  3057.                 CURRENT_TIMESTAMP
  3058.  
  3059.                 )";
  3060.  
  3061.             $result = tep_db_query($sql);
  3062.  
  3063.             $v_manufacturer_id = $max_mfg_id;
  3064.  
  3065.         }
  3066.  
  3067.     }
  3068.  
  3069.     // if the categories names are set then try to update them
  3070.  
  3071.     if ( isset($v_categories_name_1)){
  3072.  
  3073.         // start from the highest possible category and work our way down from the parent
  3074.  
  3075.         $v_categories_id = 0;
  3076.  
  3077.         $theparent_id = 0;
  3078.  
  3079.         for ( $categorylevel=$max_categories+1; $categorylevel>0; $categorylevel-- ){
  3080.  
  3081.             $thiscategoryname = $v_categories_name[$categorylevel];
  3082.  
  3083.             if ( $thiscategoryname != ''){
  3084.  
  3085.                 // we found a category name in this field
  3086.  
  3087.  
  3088.  
  3089.                 // now the subcategory
  3090.  
  3091.                 $sql = "SELECT cat.categories_id
  3092.  
  3093.                     FROM ".TABLE_CATEGORIES." as cat, 
  3094.  
  3095.                          ".TABLE_CATEGORIES_DESCRIPTION." as des
  3096.  
  3097.                     WHERE
  3098.  
  3099.                         cat.categories_id = des.categories_id AND
  3100.  
  3101.                         des.language_id = $epdlanguage_id AND
  3102.  
  3103.                         cat.parent_id = " . $theparent_id . " AND
  3104.  
  3105.                         des.categories_name = '" . $thiscategoryname . "'";
  3106.  
  3107.                 $result = tep_db_query($sql);
  3108.  
  3109.                 $row =  tep_db_fetch_array($result);
  3110.  
  3111.                 if ( $row != '' ){
  3112.  
  3113.                     foreach( $row as $item ){
  3114.  
  3115.                         $thiscategoryid = $item;
  3116.  
  3117.                     }
  3118.  
  3119.                 } else {
  3120.  
  3121.                     // to add, we need to put stuff in categories and categories_description
  3122.  
  3123.                     $sql = "SELECT MAX( categories_id) max FROM ".TABLE_CATEGORIES;
  3124.  
  3125.                     $result = tep_db_query($sql);
  3126.  
  3127.                     $row =  tep_db_fetch_array($result);
  3128.  
  3129.                     $max_category_id = $row['max']+1;
  3130.  
  3131.                     if (!is_numeric($max_category_id) ){
  3132.  
  3133.                         $max_category_id=1;
  3134.  
  3135.                     }
  3136.  
  3137.                     $sql = "INSERT INTO ".TABLE_CATEGORIES."(
  3138.  
  3139.                         categories_id,
  3140.  
  3141.                         categories_image,
  3142.  
  3143.                         parent_id,
  3144.  
  3145.                         sort_order,
  3146.  
  3147.                         date_added,
  3148.  
  3149.                         last_modified
  3150.  
  3151.                         ) VALUES (
  3152.  
  3153.                         $max_category_id,
  3154.  
  3155.                         '$default_image_category',
  3156.  
  3157.                         $theparent_id,
  3158.  
  3159.                         0,
  3160.  
  3161.                         CURRENT_TIMESTAMP
  3162.  
  3163.                         ,CURRENT_TIMESTAMP
  3164.  
  3165.                         )";
  3166.  
  3167.                     $result = tep_db_query($sql);
  3168.  
  3169.                     $sql = "INSERT INTO ".TABLE_CATEGORIES_DESCRIPTION."(
  3170.  
  3171.                             categories_id,
  3172.  
  3173.                             language_id,
  3174.  
  3175.                             categories_name
  3176.  
  3177.                         ) VALUES (
  3178.  
  3179.                             $max_category_id,
  3180.  
  3181.                             '$epdlanguage_id',
  3182.  
  3183.                             '$thiscategoryname'
  3184.  
  3185.                         )";
  3186.  
  3187.                     $result = tep_db_query($sql);
  3188.  
  3189.                     $thiscategoryid = $max_category_id;
  3190.  
  3191.                 }
  3192.  
  3193.                 // the current catid is the next level's parent
  3194.  
  3195.                 $theparent_id = $thiscategoryid;
  3196.  
  3197.                 $v_categories_id = $thiscategoryid; // keep setting this, we need the lowest level category ID later
  3198.  
  3199.             }
  3200.  
  3201.         }
  3202.  
  3203.     }
  3204.  
  3205.  
  3206.  
  3207.     if ($v_products_model != "") {
  3208.  
  3209.         //   products_model exists!
  3210.  
  3211.         array_walk($items, 'print_el');
  3212.  
  3213.  
  3214.  
  3215.         // First we check to see if this is a product in the current db.
  3216.  
  3217.         $result = tep_db_query("SELECT products_id FROM ".TABLE_PRODUCTS." WHERE (products_model = '". $v_products_model . "')");
  3218.  
  3219.  
  3220.  
  3221.         if (tep_db_num_rows($result) == 0)  {
  3222.  
  3223.             //   insert into products
  3224.  
  3225.  
  3226.  
  3227.             $sql = "SELECT MAX( products_id) max FROM ".TABLE_PRODUCTS;
  3228.  
  3229.             $result = tep_db_query($sql);
  3230.  
  3231.             $row =  tep_db_fetch_array($result);
  3232.  
  3233.             $max_product_id = $row['max']+1;
  3234.  
  3235.             if (!is_numeric($max_product_id) ){
  3236.  
  3237.                 $max_product_id=1;
  3238.  
  3239.             }
  3240.  
  3241.             $v_products_id = $max_product_id;
  3242.  
  3243.             echo "<font color='green'> !New Product!</font><br>";
  3244.  
  3245.  
  3246.  
  3247.             $query = "INSERT INTO ".TABLE_PRODUCTS." (
  3248.  
  3249.                     products_image,
  3250.  
  3251.                     products_model,
  3252.  
  3253.                     products_price,
  3254.  
  3255.                     products_status,
  3256.  
  3257.                     products_last_modified,
  3258.  
  3259.                     products_date_added,
  3260.  
  3261.                     products_date_available,
  3262.  
  3263.                     products_tax_class_id,
  3264.  
  3265.                     products_weight,
  3266.  
  3267.                     products_quantity,
  3268.  
  3269.                     manufacturers_id)
  3270.  
  3271.                         VALUES (
  3272.  
  3273.                             '$v_products_image',";
  3274.  
  3275.  
  3276.  
  3277.             // unmcomment these lines if you are running the image mods
  3278.  
  3279.             /*
  3280.  
  3281.                 $query .=        . $v_products_mimage . '", "'
  3282.  
  3283.                             . $v_products_bimage . '", "'
  3284.  
  3285.                             . $v_products_subimage1 . '", "'
  3286.  
  3287.                             . $v_products_bsubimage1 . '", "'
  3288.  
  3289.                             . $v_products_subimage2 . '", "'
  3290.  
  3291.                             . $v_products_bsubimage2 . '", "'
  3292.  
  3293.                             . $v_products_subimage3 . '", "'
  3294.  
  3295.                             . $v_products_bsubimage3 . '", "'
  3296.  
  3297.             */
  3298.  
  3299.  
  3300.  
  3301.             $query .="                '$v_products_model',
  3302.  
  3303.                                 '$v_products_price',
  3304.  
  3305.                                 '$v_db_status',
  3306.  
  3307.                                 CURRENT_TIMESTAMP,
  3308.  
  3309.                                 $v_date_added,
  3310.  
  3311.                                 $v_date_avail,
  3312.  
  3313.                                 '$v_tax_class_id',
  3314.  
  3315.                                 '$v_products_weight',
  3316.  
  3317.                                 '$v_products_quantity',
  3318.  
  3319.                                 '$v_manufacturer_id')
  3320.  
  3321.                             ";
  3322.  
  3323.                 $result = tep_db_query($query);
  3324.  
  3325.         } else {
  3326.  
  3327.             // existing product, get the id from the query
  3328.  
  3329.             // and update the product data
  3330.  
  3331.             $row =  tep_db_fetch_array($result);
  3332.  
  3333.             $v_products_id = $row['products_id'];
  3334.  
  3335.             echo "<font color='black'> Updated</font><br>";
  3336.  
  3337.             $row =  tep_db_fetch_array($result);
  3338.  
  3339.             $query = 'UPDATE '.TABLE_PRODUCTS.'
  3340.  
  3341.                     SET
  3342.  
  3343.                     products_price="'.$v_products_price.
  3344.  
  3345.                     '" ,products_image="'.$v_products_image;
  3346.  
  3347.  
  3348.  
  3349.             // uncomment these lines if you are running the image mods
  3350.  
  3351. /*
  3352.  
  3353.                 $query .=
  3354.  
  3355.                     '" ,products_mimage="'.$v_products_mimage.
  3356.  
  3357.                     '" ,products_bimage="'.$v_products_bimage.
  3358.  
  3359.                     '" ,products_subimage1="'.$v_products_subimage1.
  3360.  
  3361.                     '" ,products_bsubimage1="'.$v_products_bsubimage1.
  3362.  
  3363.                     '" ,products_subimage2="'.$v_products_subimage2.
  3364.  
  3365.                     '" ,products_bsubimage2="'.$v_products_bsubimage2.
  3366.  
  3367.                     '" ,products_subimage3="'.$v_products_subimage3.
  3368.  
  3369.                     '" ,products_bsubimage3="'.$v_products_bsubimage3;
  3370.  
  3371. */
  3372.  
  3373.  
  3374.  
  3375.             $query .= '", products_weight="'.$v_products_weight .
  3376.  
  3377.                     '", products_tax_class_id="'.$v_tax_class_id . 
  3378.  
  3379.                     '", products_date_available= ' . $v_date_avail .
  3380.  
  3381.                     ', products_date_added= ' . $v_date_added .
  3382.  
  3383.                     ', products_last_modified=CURRENT_TIMESTAMP
  3384.  
  3385.                     , products_quantity="' . $v_products_quantity .  
  3386.  
  3387.                     '" ,manufacturers_id=' . $v_manufacturer_id . 
  3388.  
  3389.                     ' , products_status=' . $v_db_status . '
  3390.  
  3391.                     WHERE
  3392.  
  3393.                         (products_id = "'. $v_products_id . '")';
  3394.  
  3395.  
  3396.  
  3397.             $result = tep_db_query($query);
  3398.  
  3399.         }
  3400.  
  3401.  
  3402.  
  3403.         // the following is common in both the updating an existing product and creating a new product
  3404.  
  3405.                 if ( isset($v_products_name)){
  3406.  
  3407.             foreach( $v_products_name as $key => $name){
  3408.  
  3409.                             if ($name!=''){
  3410.  
  3411.                     $sql = "SELECT * FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE
  3412.  
  3413.                             products_id = $v_products_id AND
  3414.  
  3415.                             language_id = " . $key;
  3416.  
  3417.                     $result = tep_db_query($sql);
  3418.  
  3419.                     if (tep_db_num_rows($result) == 0) {
  3420.  
  3421.                         // nope, this is a new product description
  3422.  
  3423.                         $result = tep_db_query($sql);
  3424.  
  3425.                         $sql =
  3426.  
  3427.                             "INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION."
  3428.  
  3429.                                 (products_id,
  3430.  
  3431.                                 language_id,
  3432.  
  3433.                                 products_name,
  3434.  
  3435.                                 products_description,
  3436.  
  3437.                                 products_url)
  3438.  
  3439.                                 VALUES (
  3440.  
  3441.                                     '" . $v_products_id . "',
  3442.  
  3443.                                     " . $key . ",
  3444.  
  3445.                                     '" . $name . "',
  3446.  
  3447.                                     '". $v_products_description[$key] . "',
  3448.  
  3449.                                     '". $v_products_url[$key] . "'
  3450.  
  3451.                                     )";
  3452.  
  3453.                         // support for Linda's Header Controller 2.0
  3454.  
  3455.                         if (isset($v_products_head_title_tag)){
  3456.  
  3457.                             // override the sql if we're using Linda's contrib
  3458.  
  3459.                             $sql =
  3460.  
  3461.                                 "INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION."
  3462.  
  3463.                                     (products_id,
  3464.  
  3465.                                     language_id,
  3466.  
  3467.                                     products_name,
  3468.  
  3469.                                     products_description,
  3470.  
  3471.                                     products_url,
  3472.  
  3473.                                     products_head_title_tag,
  3474.  
  3475.                                     products_head_desc_tag,
  3476.  
  3477.                                     products_head_keywords_tag)
  3478.  
  3479.                                     VALUES (
  3480.  
  3481.                                         '" . $v_products_id . "',
  3482.  
  3483.                                         " . $key . ",
  3484.  
  3485.                                         '" . $name . "',
  3486.  
  3487.                                         '". $v_products_description[$key] . "',
  3488.  
  3489.                                         '". $v_products_url[$key] . "',
  3490.  
  3491.                                         '". $v_products_head_title_tag[$key] . "',
  3492.  
  3493.                                         '". $v_products_head_desc_tag[$key] . "',
  3494.  
  3495.                                         '". $v_products_head_keywords_tag[$key] . "')";
  3496.  
  3497.                         }
  3498.  
  3499.                         // end support for Linda's Header Controller 2.0
  3500.  
  3501.                         $result = tep_db_query($sql);
  3502.  
  3503.                     } else {
  3504.  
  3505.                         // already in the description, let's just update it
  3506.  
  3507.                         $sql =
  3508.  
  3509.                             "UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
  3510.  
  3511.                                 products_name='$name',
  3512.  
  3513.                                 products_description='".$v_products_description[$key] . "',
  3514.  
  3515.                                 products_url='" . $v_products_url[$key] . "'
  3516.  
  3517.                             WHERE
  3518.  
  3519.                                 products_id = '$v_products_id' AND
  3520.  
  3521.                                 language_id = '$key'";
  3522.  
  3523.                         // support for Lindas Header Controller 2.0
  3524.  
  3525.                         if (isset($v_products_head_title_tag)){
  3526.  
  3527.                             // override the sql if we're using Linda's contrib
  3528.  
  3529.                             $sql =
  3530.  
  3531.                                 "UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
  3532.  
  3533.                                     products_name = '$name',
  3534.  
  3535.                                     products_description = '".$v_products_description[$key] . "',
  3536.  
  3537.                                     products_url = '" . $v_products_url[$key] ."',
  3538.  
  3539.                                     products_head_title_tag = '" . $v_products_head_title_tag[$key] ."',
  3540.  
  3541.                                     products_head_desc_tag = '" . $v_products_head_desc_tag[$key] ."',
  3542.  
  3543.                                     products_head_keywords_tag = '" . $v_products_head_keywords_tag[$key] ."'
  3544.  
  3545.                                 WHERE
  3546.  
  3547.                                     products_id = '$v_products_id' AND
  3548.  
  3549.                                     language_id = '$key'";
  3550.  
  3551.                         }
  3552.  
  3553.                         // end support for Linda's Header Controller 2.0
  3554.  
  3555.                         $result = tep_db_query($sql);
  3556.  
  3557.                     }
  3558.  
  3559.                 }
  3560.  
  3561.             }
  3562.  
  3563.         }
  3564.  
  3565.         if (isset($v_categories_id)){
  3566.  
  3567.             //find out if this product is listed in the category given
  3568.  
  3569.             $result_incategory = tep_db_query('SELECT
  3570.  
  3571.                         '.TABLE_PRODUCTS_TO_CATEGORIES.'.products_id,
  3572.  
  3573.                         '.TABLE_PRODUCTS_TO_CATEGORIES.'.categories_id
  3574.  
  3575.                         FROM
  3576.  
  3577.                             '.TABLE_PRODUCTS_TO_CATEGORIES.'
  3578.  
  3579.                         WHERE
  3580.  
  3581.                         '.TABLE_PRODUCTS_TO_CATEGORIES.'.products_id='.$v_products_id.' AND
  3582.  
  3583.                         '.TABLE_PRODUCTS_TO_CATEGORIES.'.categories_id='.$v_categories_id);
  3584.  
  3585.  
  3586.  
  3587.             if (tep_db_num_rows($result_incategory) == 0) {
  3588.  
  3589.                 // nope, this is a new category for this product
  3590.  
  3591.                 $res1 = tep_db_query('INSERT INTO '.TABLE_PRODUCTS_TO_CATEGORIES.' (products_id, categories_id)
  3592.  
  3593.                             VALUES ("' . $v_products_id . '", "' . $v_categories_id . '")');
  3594.  
  3595.             } else {
  3596.  
  3597.                 // already in this category, nothing to do!
  3598.  
  3599.             }
  3600.  
  3601.         }
  3602.  
  3603.         // for the separate prices per customer module
  3604.  
  3605.         $ll=1;
  3606.  
  3607.  
  3608.  
  3609.         if (isset($v_customer_price_1)){
  3610.  
  3611.             
  3612.  
  3613.             if (($v_customer_group_id_1 == '') AND ($v_customer_price_1 != ''))  {
  3614.  
  3615.                 echo "<font color=red>ERROR - v_customer_group_id and v_customer_price must occur in pairs</font>";
  3616.  
  3617.                 die();
  3618.  
  3619.             }
  3620.  
  3621.             // they spec'd some prices, so clear all existing entries
  3622.  
  3623.             $result = tep_db_query('
  3624.  
  3625.                         DELETE
  3626.  
  3627.                         FROM
  3628.  
  3629.                             '.TABLE_PRODUCTS_GROUPS.'
  3630.  
  3631.                         WHERE
  3632.  
  3633.                             products_id = ' . $v_products_id
  3634.  
  3635.                         );
  3636.  
  3637.             // and insert the new record
  3638.  
  3639.             if ($v_customer_price_1 != ''){
  3640.  
  3641.                 $result = tep_db_query('
  3642.  
  3643.                             INSERT INTO
  3644.  
  3645.                                 '.TABLE_PRODUCTS_GROUPS.'
  3646.  
  3647.                             VALUES
  3648.  
  3649.                             (
  3650.  
  3651.                                 ' . $v_customer_group_id_1 . ',
  3652.  
  3653.                                 ' . $v_customer_price_1 . ',
  3654.  
  3655.                                 ' . $v_products_id . ',
  3656.  
  3657.                                 ' . $v_products_price .'
  3658.  
  3659.                                 )'
  3660.  
  3661.                             );
  3662.  
  3663.             }
  3664.  
  3665.             if ($v_customer_price_2 != ''){
  3666.  
  3667.                 $result = tep_db_query('
  3668.  
  3669.                             INSERT INTO
  3670.  
  3671.                                 '.TABLE_PRODUCTS_GROUPS.'
  3672.  
  3673.                             VALUES
  3674.  
  3675.                             (
  3676.  
  3677.                                 ' . $v_customer_group_id_2 . ',
  3678.  
  3679.                                 ' . $v_customer_price_2 . ',
  3680.  
  3681.                                 ' . $v_products_id . ',
  3682.  
  3683.                                 ' . $v_products_price . '
  3684.  
  3685.                                 )'
  3686.  
  3687.                             );
  3688.  
  3689.             }
  3690.  
  3691.             if ($v_customer_price_3 != ''){
  3692.  
  3693.                 $result = tep_db_query('
  3694.  
  3695.                             INSERT INTO
  3696.  
  3697.                                 '.TABLE_PRODUCTS_GROUPS.'
  3698.  
  3699.                             VALUES
  3700.  
  3701.                             (
  3702.  
  3703.                                 ' . $v_customer_group_id_3 . ',
  3704.  
  3705.                                 ' . $v_customer_price_3 . ',
  3706.  
  3707.                                 ' . $v_products_id . ',
  3708.  
  3709.                                 ' . $v_products_price . '
  3710.  
  3711.                                 )'
  3712.  
  3713.                             );
  3714.  
  3715.             }
  3716.  
  3717.             if ($v_customer_price_4 != ''){
  3718.  
  3719.                 $result = tep_db_query('
  3720.  
  3721.                             INSERT INTO
  3722.  
  3723.                                 '.TABLE_PRODUCTS_GROUPS.'
  3724.  
  3725.                             VALUES
  3726.  
  3727.                             (
  3728.  
  3729.                                 ' . $v_customer_group_id_4 . ',
  3730.  
  3731.                                 ' . $v_customer_price_4 . ',
  3732.  
  3733.                                 ' . $v_products_id . ',
  3734.  
  3735.                                 ' . $v_products_price . '
  3736.  
  3737.                                 )'
  3738.  
  3739.                             );
  3740.  
  3741.             }
  3742.  
  3743.  
  3744.  
  3745.         }
  3746.  
  3747.  
  3748.  
  3749.     } else {
  3750.  
  3751.         // this record was missing the product_model
  3752.  
  3753.         array_walk($items, 'print_el');
  3754.  
  3755.         echo "<p class=smallText>No products_model field in record. This line was not imported <br>";
  3756.  
  3757.         echo "<br>";
  3758.  
  3759.     }
  3760.  
  3761. // end of row insertion code
  3762.  
  3763. }
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769. require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
  3770.  
  3771.