$manufacturer_inputs_string = ''; $languages = oos_get_languages(); for ($i = 0, $n = count($languages); $i < $n; $i++) { $manufacturer_inputs_string .= '<br />' . oos_image(OOS_SHOP_IMAGES . 'flags/' . $languages[$i]['iso_639_2'] . '.gif', $languages[$i]['name']) . ' ' . oos_draw_input_field('manufacturers_url[' . $languages[$i]['id'] . ']'); } $contents[] = array('text' => '<br />' . TEXT_MANUFACTURERS_URL . $manufacturer_inputs_string); $contents[] = array('align' => 'center', 'text' => '<br />' . oos_image_swap_submits('save', 'save_off.gif', IMAGE_SAVE) . ' <a href="' . oos_href_link_admin($aFilename['manufacturers'], 'page=' . $_GET['page'] . '&mID=' . $_GET['mID']) . '">' . oos_image_swap_button('cancel', 'cancel_off.gif', IMAGE_CANCEL) . '</a>'); break; case 'edit': $heading[] = array('text' => '<b>' . TEXT_HEADING_EDIT_MANUFACTURER . '</b>'); $contents = array('form' => oos_draw_form('manufacturers', $aFilename['manufacturers'], 'page=' . $_GET['page'] . '&mID=' . $mInfo->manufacturers_id . '&action=save', 'post', 'enctype="multipart/form-data"')); $contents[] = array('text' => TEXT_EDIT_INTRO); $contents[] = array('text' => '<br />' . TEXT_MANUFACTURERS_NAME . '<br />' . oos_draw_input_field('manufacturers_name', $mInfo->manufacturers_name)); $contents[] = array('text' => '<br />' . TEXT_MANUFACTURERS_IMAGE . '<br />' . oos_draw_file_field('manufacturers_image') . '<br />' . $mInfo->manufacturers_image); $manufacturer_inputs_string = ''; $languages = oos_get_languages(); for ($i = 0, $n = count($languages); $i < $n; $i++) { $manufacturer_inputs_string .= '<br />' . oos_image(OOS_SHOP_IMAGES . 'flags/' . $languages[$i]['iso_639_2'] . '.gif', $languages[$i]['name']) . ' ' . oos_draw_input_field('manufacturers_url[' . $languages[$i]['id'] . ']', oos_get_manufacturer_url($mInfo->manufacturers_id, $languages[$i]['id'])); } $contents[] = array('text' => '<br />' . TEXT_MANUFACTURERS_URL . $manufacturer_inputs_string); $contents[] = array('align' => 'center', 'text' => '<br />' . oos_image_swap_submits('save', 'save_off.gif', IMAGE_SAVE) . ' <a href="' . oos_href_link_admin($aFilename['manufacturers'], 'page=' . $_GET['page'] . '&mID=' . $mInfo->manufacturers_id) . '">' . oos_image_swap_button('cancel', 'cancel_off.gif', IMAGE_CANCEL) . '</a>'); break; case 'delete': $heading[] = array('text' => '<b>' . TEXT_HEADING_DELETE_MANUFACTURER . '</b>'); $contents = array('form' => oos_draw_form('manufacturers', $aFilename['manufacturers'], 'page=' . $_GET['page'] . '&mID=' . $mInfo->manufacturers_id . '&action=deleteconfirm')); $contents[] = array('text' => TEXT_DELETE_INTRO); $contents[] = array('text' => '<br /><b>' . $mInfo->manufacturers_name . '</b>'); $contents[] = array('text' => '<br />' . oos_draw_checkbox_field('delete_image', '', true) . ' ' . TEXT_DELETE_IMAGE); if ($mInfo->products_count > 0) { $contents[] = array('text' => '<br />' . oos_draw_checkbox_field('delete_products') . ' ' . TEXT_DELETE_PRODUCTS); $contents[] = array('text' => '<br />' . sprintf(TEXT_DELETE_WARNING_PRODUCTS, $mInfo->products_count));
/** * */ function walk($item1) { global $filelayout, $filelayout_count, $modelsize; global $ps_outstock, $ps_instock, $ps_soon, $ps_notav, $langcode, $default_these, $deleteit, $zero_qty_inactive; global $price_with_tax, $replace_quotes; global $default_images, $default_image_manufacturer, $default_image_product, $default_image_category; global $separator, $max_categories; // first we clean up the row of data $dbconn =& oosDBGetConn(); $oostable =& oosDBGetTables(); // chop blanks from each end $item1 = ltrim(rtrim($item1)); // blow it into an array, splitting on the tabs $items = explode($separator, $item1); // make sure all non-set things are set to ''; // and strip the quotes from the start and end of the stings. // escape any special chars for the database. foreach ($filelayout as $key => $value) { $i = $filelayout[$key]; if (isset($items[$i]) == false) { $items[$i] = ''; } else { // Check to see if either of the magic_quotes are turned on or off; // And apply filtering accordingly. if (function_exists('ini_get')) { //echo "Getting ready to check magic quotes<br />"; if (ini_get('magic_quotes_runtime') == 1) { // The magic_quotes_runtime are on, so lets account for them // check if the last character is a quote; // if it is, chop off the quotes. if (substr($items[$i], -1) == '"') { $items[$i] = substr($items[$i], 2, strlen($items[$i]) - 4); } // now any remaining doubled double quotes should be converted to one doublequote $items[$i] = str_replace('\\"\\"', """, $items[$i]); if ($replace_quotes) { $items[$i] = str_replace('\\"', """, $items[$i]); $items[$i] = str_replace("\\'", "'", $items[$i]); } } else { // no magic_quotes are on // check if the last character is a quote; // if it is, chop off the 1st and last character of the string. if (substr($items[$i], -1) == '"') { $items[$i] = substr($items[$i], 1, strlen($items[$i]) - 2); } // now any remaining doubled double quotes should be converted to one doublequote $items[$i] = str_replace('""', """, $items[$i]); if ($replace_quotes) { $items[$i] = str_replace('"', """, $items[$i]); $items[$i] = str_replace("'", "'", $items[$i]); } } } } } /* if ( $items['v_status'] == $deleteit ){ // they want to delete this product. echo "Deleting product " . $items['v_products_model'] . " from the database<br />"; // Get the ID // kill in the products_to_categories // Kill in the products table return; // we're done deleteing! } */ // now do a query to get the record's current contents $sql = "SELECT\n p.products_id as v_products_id,\n p.products_model as v_products_model,\n p.products_image as v_products_image,\n p.products_price as v_products_price,\n p.products_weight as v_products_weight,\n p.products_date_added as v_date_avail,\n p.products_tax_class_id as v_tax_class_id,\n p.products_quantity as v_products_quantity,\n p.manufacturers_id as v_manufacturers_id,\n subc.categories_id as v_categories_id\n FROM\n " . $oostable['products'] . " as p,\n " . $oostable['categories'] . " as subc,\n " . $oostable['products_to_categories'] . " as ptoc\n WHERE\n p.products_id = ptoc.products_id AND\n p.products_model = '" . $items[$filelayout['v_products_model']] . "' AND\n ptoc.categories_id = subc.categories_id\n "; $result = $dbconn->Execute($sql); while ($row = $result->fields) { // OK, since we got a row, the item already exists. // Let's get all the data we need and fill in all the fields that need to be defaulted to the current values // for each language, get the description and set the vals foreach ($langcode as $key => $lang) { //echo "Inside defaulting loop"; //echo "key is $key<br />"; //echo "langid is " . $lang['id'] . "<br />"; // $sql2 = "SELECT products_name, products_description // FROM ".$oostable['products_description']." // WHERE // products_id = " . $row['v_products_id'] . " AND // language_id = '" . $lang['id'] . "' // "; $sql2 = "SELECT *\n FROM " . $oostable['products_description'] . "\n WHERE\n products_id = " . $row['v_products_id'] . " AND\n products_languages_id = '" . $lang['id'] . "'\n "; $result2 = $dbconn->Execute($sql2); $row2 = $result2->fields; // Need to report from ......_name_1 not ..._name_0 $row['v_products_name_' . $lang['id']] = $row2['products_name']; $row['v_products_description_' . $lang['id']] = $row2['products_description']; $row['v_products_url_' . $lang['id']] = $row2['products_url']; /* // support for Linda's Header Controller 2.0 here if(isset($filelayout['v_products_head_title_tag_' . $lang['id'] ])){ $row['v_products_head_title_tag_' . $lang['id']] = $row2['products_head_title_tag']; $row['v_products_head_desc_tag_' . $lang['id']] = $row2['products_head_desc_tag']; $row['v_products_head_keywords_tag_' . $lang['id']] = $row2['products_head_keywords_tag']; } // end support for Header Controller 2.0 */ } // start with v_categories_id // Get the category description // set the appropriate variable name // if parent_id is not null, then follow it up. $thecategory_id = $row['v_categories_id']; for ($categorylevel = 1; $categorylevel < $max_categories + 1; $categorylevel++) { if ($thecategory_id) { $sql2 = "SELECT categories_name\n FROM " . $oostable['categories_description'] . "\n WHERE\n categories_id = " . $thecategory_id . " AND\n categories_languages_id = '" . intval($_SESSION['language_id']) . "'"; $result2 = $dbconn->Execute($sql2); $row2 = $result2->fields; // only set it if we found something $temprow['v_categories_name_' . $categorylevel] = $row2['categories_name']; // now get the parent ID if there was one $sql3 = "SELECT parent_id\n FROM " . $oostable['categories'] . "\n WHERE\n categories_id = " . $thecategory_id; $result3 = $dbconn->Execute($sql3); $row3 = $result3->fields; $theparent_id = $row3['parent_id']; if ($theparent_id != '') { // there was a parent ID, lets set thecategoryid to get the next level $thecategory_id = $theparent_id; } else { // we have found the top level category for this item, $thecategory_id = false; } } else { $temprow['v_categories_name_' . $categorylevel] = ''; } } // temprow has the old style low to high level categories. $newlevel = 1; // let's turn them into high to low level categories for ($categorylevel = $max_categories + 1; $categorylevel > 0; $categorylevel--) { if ($temprow['v_categories_name_' . $categorylevel] != '') { $row['v_categories_name_' . $newlevel++] = $temprow['v_categories_name_' . $categorylevel]; } } if ($row['v_manufacturers_id'] != '') { $sql2 = "SELECT manufacturers_name\n FROM " . $oostable['manufacturers'] . "\n WHERE\n manufacturers_id = " . $row['v_manufacturers_id']; $result2 = $dbconn->Execute($sql2); $row2 = $result2->fields; $row['v_manufacturers_name'] = $row2['manufacturers_name']; } //elari - //We check the value of tax class and title instead of the id //Then we add the tax to price if $price_with_tax is set to true $row_tax_multiplier = oos_get_tax_class_rate($row['v_tax_class_id']); # ! ! ! $row['v_tax_class_title'] = oos_cfg_get_tax_class_title($row['v_tax_class_id']); if ($price_with_tax) { $row['v_products_price'] = round($row['v_products_price'] + $row['v_products_price'] * $row_tax_multiplier / 100, 2); } // now create the internal variables that will be used // the $$thisvar is on purpose: it creates a variable named what ever was in $thisvar and sets the value foreach ($default_these as $thisvar) { ${$thisvar} = $row[$thisvar]; } // Move that ADOdb pointer! $result->MoveNext(); } // this is an important loop. What it does is go thru all the fields in the incoming file and set the internal vars. // Internal vars not set here are either set in the loop above for existing records, or not set at all (null values) // the array values are handled separatly, although they will set variables in this loop, we won't use them. foreach ($filelayout as $key => $value) { ${$key} = $items[$value]; } // so how to handle these? we shouldn't built the array unless it's been giving to us. // The assumption is that if you give us names and descriptions, then you give us name and description for all applicable languages foreach ($langcode as $lang) { //echo "Langid is " . $lang['id'] . "<br />"; $l_id = $lang['id']; if (isset($filelayout['v_products_name_' . $l_id])) { //we set dynamically the language values $v_products_name[$l_id] = $items[$filelayout['v_products_name_' . $l_id]]; $v_products_description[$l_id] = $items[$filelayout['v_products_description_' . $l_id]]; $v_products_url[$l_id] = $items[$filelayout['v_products_url_' . $l_id]]; // support for Linda's Header Controller 2.0 here /* if(isset($filelayout['v_products_head_title_tag_' . $l_id])){ $v_products_head_title_tag[$l_id] = $items[$filelayout['v_products_head_title_tag_' . $l_id]]; $v_products_head_desc_tag[$l_id] = $items[$filelayout['v_products_head_desc_tag_' . $l_id]]; $v_products_head_keywords_tag[$l_id] = $items[$filelayout['v_products_head_keywords_tag_' . $l_id]]; } // end support for Header Controller 2.0 */ } } //elari... we get the tax_clas_id from the tax_title //on screen will still be displayed the tax_class_title instead of the id.... if (isset($v_tax_class_title)) { $v_tax_class_id = oos_get_tax_title_class_id($v_tax_class_title); # ! ! ! } //we check the tax rate of this tax_class_id $row_tax_multiplier = oos_get_tax_class_rate($v_tax_class_id); # ! ! ! //And we recalculate price without the included tax... //Since it seems display is made before, the displayed price will still include tax //This is same problem for the tax_clas_id that display tax_class_title if ($price_with_tax) { $v_products_price = round($v_products_price / (1 + $row_tax_multiplier * $price_with_tax / 100), 4); } // if they give us one category, they give us all 6 categories unset($v_categories_name); // default to not set. if (isset($filelayout['v_categories_name_1'])) { $newlevel = 1; for ($categorylevel = 6; $categorylevel > 0; $categorylevel--) { if ($items[$filelayout['v_categories_name_' . $categorylevel]] != '') { $v_categories_name[$newlevel++] = $items[$filelayout['v_categories_name_' . $categorylevel]]; } } while ($newlevel < $max_categories + 1) { $v_categories_name[$newlevel++] = ''; // default the remaining items to nothing } } if (ltrim(rtrim($v_products_quantity)) == '') { $v_products_quantity = 1; } if ($v_date_avail == '') { // $v_date_avail = "CURRENT_TIMESTAMP"; $v_date_avail = "NULL"; } else { // we put the quotes around it here because we can't put them into the query, because sometimes // we will use the "current_timestamp", which can't have quotes around it. $v_date_avail = '"' . $v_date_avail . '"'; } if ($v_date_added == '') { $v_date_added = "CURRENT_TIMESTAMP"; } else { // we put the quotes around it here because we can't put them into the query, because sometimes // we will use the "current_timestamp", which can't have quotes around it. $v_date_added = '"' . $v_date_added . '"'; } // default the stock if they spec'd it or if it's blank $v_db_status = '3'; // default to active if ($v_status == $ps_notav) { $v_db_status = '0'; } elseif ($v_status == $ps_outstock) { $v_db_status = '1'; } elseif ($v_status == $ps_soon) { $v_db_status = '2'; } if ($zero_qty_inactive && $v_products_quantity == 0) { // if they said that zero qty products should be deactivated, let's deactivate if the qty is zero $v_db_status = '0'; } if ($v_manufacturer_id == '') { $v_manufacturer_id = "NULL"; } if (trim($v_products_image) == '') { $v_products_image = $default_image_product; } if (strlen($v_products_model) > $modelsize) { echo "<font color='red'>" . strlen($v_products_model) . $v_products_model . "... ERROR! - Too many characters in the model number.<br />\n 12 is the maximum on a standard OSC install.<br />\n Your maximum product_model length is set to {$modelsize}<br />\n You can either shorten your model numbers or increase the size of the field in the database.</font>"; die; } // OK, we need to convert the manufacturer's name into id's for the database if (isset($v_manufacturers_name) && $v_manufacturers_name != '') { $sql = "SELECT man.manufacturers_id\n FROM " . $oostable['manufacturers'] . " as man\n WHERE\n man.manufacturers_name = '" . $v_manufacturers_name . "'"; $result = $dbconn->Execute($sql); $row = $result->fields; if ($row != '') { foreach ($row as $item) { # ! ! ! $v_manufacturer_id = $item; } } else { // to add, we need to put stuff in categories and categories_description $sql = "SELECT MAX( manufacturers_id) max FROM " . $oostable['manufacturers']; $result = $dbconn->Execute($sql); $row = $result->fields; $max_mfg_id = $row['max'] + 1; // default the id if there are no manufacturers yet if (!is_numeric($max_mfg_id)) { $max_mfg_id = 1; } // Uncomment this query if you have an older 2.2 codebase /* $sql = "INSERT INTO ".$oostable['manufacturers']."( manufacturers_id, manufacturers_name, manufacturers_image ) VALUES ( $max_mfg_id, '$v_manufacturers_name', '$default_image_manufacturer' )"; */ // Comment this query out if you have an older 2.2 codebase $sql = "INSERT INTO " . $oostable['manufacturers'] . "(\n manufacturers_id,\n manufacturers_name,\n manufacturers_image,\n date_added,\n last_modified\n ) VALUES (\n {$max_mfg_id},\n '{$v_manufacturers_name}',\n '{$default_image_manufacturer}',\n CURRENT_TIMESTAMP,\n CURRENT_TIMESTAMP\n )"; $result = $dbconn->Execute($sql); $v_manufacturer_id = $max_mfg_id; } } // if the categories names are set then try to update them if (isset($v_categories_name_1)) { // start from the highest possible category and work our way down from the parent $v_categories_id = 0; $theparent_id = 0; for ($categorylevel = $max_categories + 1; $categorylevel > 0; $categorylevel--) { $thiscategoryname = $v_categories_name[$categorylevel]; if ($thiscategoryname != '') { // we found a category name in this field // now the subcategory $sql = "SELECT cat.categories_id\n FROM " . $oostable['categories'] . " as cat, \n " . $oostable['categories_description'] . " as des\n WHERE\n cat.categories_id = des.categories_id AND\n des.categories_languages_id = '" . intval($_SESSION['language_id']) . "' AND\n cat.parent_id = " . $theparent_id . " AND\n des.categories_name = '" . $thiscategoryname . "'"; $result = $dbconn->Execute($sql); $row = $result->fields; if ($row != '') { foreach ($row as $item) { # ! ! ! $thiscategoryid = $item; } } else { // to add, we need to put stuff in categories and categories_description $sql = "SELECT MAX( categories_id) max FROM " . $oostable['categories']; $result = $dbconn->Execute($sql); $row = $result->fields; $max_category_id = $row['max'] + 1; if (!is_numeric($max_category_id)) { $max_category_id = 1; } $sql = "INSERT INTO " . $oostable['categories'] . "(\n categories_id,\n categories_image,\n parent_id,\n sort_order,\n date_added,\n last_modified,\n categories_status\n ) VALUES (\n {$max_category_id},\n '{$default_image_category}',\n {$theparent_id},\n 0,\n CURRENT_TIMESTAMP\n ,CURRENT_TIMESTAMP,\n 1\n )"; $result = $dbconn->Execute($sql); $sql = "INSERT INTO " . $oostable['categories_description'] . "(\n categories_id,\n categories_languages_id,\n categories_name\n ) VALUES (\n {$max_category_id},\n '" . $_SESSION['language_id'] . "',\n '{$thiscategoryname}'\n )"; $result = $dbconn->Execute($sql); $thiscategoryid = $max_category_id; } // the current catid is the next level's parent $theparent_id = $thiscategoryid; $v_categories_id = $thiscategoryid; // keep setting this, we need the lowest level category ID later } } } if ($v_products_model != "") { // products_model exists! array_walk($items, 'print_el'); // First we check to see if this is a product in the current db. $result = $dbconn->Execute("SELECT products_id FROM " . $oostable['products'] . " WHERE (products_model = '" . $v_products_model . "')"); if ($result->RecordCount() == 0) { // insert into products $sql = "SHOW TABLE STATUS LIKE '" . $oostable['products'] . "'"; $result = $dbconn->Execute($sql); $row = $result->fields; $max_product_id = $row['Auto_increment']; if (!is_numeric($max_product_id)) { $max_product_id = 1; } $v_products_id = $max_product_id; echo "<font color='green'> !New Product!</font><br />"; $query = "INSERT INTO " . $oostable['products'] . " (\n products_image,\n products_model,\n products_price,\n products_status,\n products_last_modified,\n products_date_added,\n products_date_available,\n products_tax_class_id,\n products_weight,\n products_quantity,\n manufacturers_id)\n VALUES (\n '{$v_products_image}',"; // unmcomment these lines if you are running the image mods /* $query .= . $v_products_mimage . '", "' . $v_products_bimage . '", "' . $v_products_subimage1 . '", "' . $v_products_bsubimage1 . '", "' . $v_products_subimage2 . '", "' . $v_products_bsubimage2 . '", "' . $v_products_subimage3 . '", "' . $v_products_bsubimage3 . '", "' */ $query .= " '{$v_products_model}',\n '{$v_products_price}',\n '{$v_db_status}',\n CURRENT_TIMESTAMP,\n {$v_date_added},\n {$v_date_avail},\n '{$v_tax_class_id}',\n '{$v_products_weight}',\n '{$v_products_quantity}',\n '{$v_manufacturer_id}')\n "; $result = $dbconn->Execute($query); } else { // existing product, get the id from the query // and update the product data $row = $result->fields; $v_products_id = $row['products_id']; echo "<font color='black'> Updated</font><br />"; $row = $result->fields; # ! ! ! $query = 'UPDATE ' . $oostable['products'] . ' SET products_price="' . $v_products_price . '" ,products_image="' . $v_products_image; // uncomment these lines if you are running the image mods /* $query .= '" ,products_mimage="'.$v_products_mimage. '" ,products_bimage="'.$v_products_bimage. '" ,products_subimage1="'.$v_products_subimage1. '" ,products_bsubimage1="'.$v_products_bsubimage1. '" ,products_subimage2="'.$v_products_subimage2. '" ,products_bsubimage2="'.$v_products_bsubimage2. '" ,products_subimage3="'.$v_products_subimage3. '" ,products_bsubimage3="'.$v_products_bsubimage3; */ $query .= '", products_weight="' . $v_products_weight . '", products_tax_class_id="' . $v_tax_class_id . '", products_date_available= ' . $v_date_avail . ', products_date_added= ' . $v_date_added . ', products_last_modified=CURRENT_TIMESTAMP , products_quantity="' . $v_products_quantity . '" ,manufacturers_id=' . $v_manufacturer_id . ' , products_status=' . $v_db_status . ' WHERE (products_id = "' . $v_products_id . '")'; $result = $dbconn->Execute($query); } // the following is common in both the updating an existing product and creating a new product if (isset($v_products_name)) { foreach ($v_products_name as $key => $name) { if ($name != '') { $sql = "SELECT * FROM " . $oostable['products_description'] . " WHERE\n products_id = {$v_products_id} AND\n products_languages_id = '" . $key . "'"; $result = $dbconn->Execute($sql); if ($result->RecordCount() == 0) { // nope, this is a new product description $result = $dbconn->Execute($sql); $sql = "INSERT INTO " . $oostable['products_description'] . "\n (products_id,\n products_languages_id,\n products_name,\n products_description,\n products_url)\n VALUES (\n '" . $v_products_id . "',\n '" . $key . "',\n '" . $name . "',\n '" . $v_products_description[$key] . "',\n '" . $v_products_url[$key] . "'\n )"; // support for Linda's Header Controller 2.0 if (isset($v_products_head_title_tag)) { // override the sql if we're using Linda's contrib $sql = "INSERT INTO " . $oostable['products_description'] . "\n (products_id,\n products_languages_id,\n products_name,\n products_description,\n products_url,\n products_head_title_tag,\n products_head_desc_tag,\n products_head_keywords_tag)\n VALUES (\n '" . $v_products_id . "',\n '" . $key . "',\n '" . $name . "',\n '" . $v_products_description[$key] . "',\n '" . $v_products_url[$key] . "',\n '" . $v_products_head_title_tag[$key] . "',\n '" . $v_products_head_desc_tag[$key] . "',\n '" . $v_products_head_keywords_tag[$key] . "')"; } // end support for Linda's Header Controller 2.0 $result = $dbconn->Execute($sql); } else { // already in the description, let's just update it $sql = "UPDATE " . $oostable['products_description'] . " SET\n products_name='{$name}',\n products_description='" . $v_products_description[$key] . "',\n products_url='" . $v_products_url[$key] . "'\n WHERE\n products_id = '{$v_products_id}' AND\n products_languages_id = '{$key}'"; // support for Lindas Header Controller 2.0 if (isset($v_products_head_title_tag)) { // override the sql if we're using Linda's contrib $sql = "UPDATE " . $oostable['products_description'] . " SET\n products_name = '{$name}',\n products_description = '" . $v_products_description[$key] . "',\n products_url = '" . $v_products_url[$key] . "',\n products_head_title_tag = '" . $v_products_head_title_tag[$key] . "',\n products_head_desc_tag = '" . $v_products_head_desc_tag[$key] . "',\n products_head_keywords_tag = '" . $v_products_head_keywords_tag[$key] . "'\n WHERE\n products_id = '{$v_products_id}' AND\n products_languages_id = '{$key}'"; } // end support for Linda's Header Controller 2.0 $result = $dbconn->Execute($sql); } } } } if (isset($v_categories_id)) { //find out if this product is listed in the category given $result_incategory = $dbconn->Execute('SELECT ' . $oostable['products_to_categories'] . '.products_id, ' . $oostable['products_to_categories'] . '.categories_id FROM ' . $oostable['products_to_categories'] . ' WHERE ' . $oostable['products_to_categories'] . '.products_id=' . $v_products_id . ' AND ' . $oostable['products_to_categories'] . '.categories_id=' . $v_categories_id); if ($result_incategory->RecordCount() == 0) { // nope, this is a new category for this product $res1 = $dbconn->Execute('INSERT INTO ' . $oostable['products_to_categories'] . ' (products_id, categories_id) VALUES ("' . $v_products_id . '", "' . $v_categories_id . '")'); } else { // already in this category, nothing to do! } } // for the separate prices per customer module $ll = 1; if (isset($v_customer_price_1)) { if ($v_customer_group_id_1 == '' and $v_customer_price_1 != '') { echo "<font color=red>ERROR - v_customer_group_id and v_customer_price must occur in pairs</font>"; die; } // they spec'd some prices, so clear all existing entries $result = $dbconn->Execute('DELETE FROM ' . $oostable['products_groups'] . ' WHERE products_id = ' . $v_products_id); // and insert the new record if ($v_customer_price_1 != '') { $result = $dbconn->Execute(' INSERT INTO ' . $oostable['products_groups'] . ' VALUES ( ' . $v_customer_group_id_1 . ', ' . $v_customer_price_1 . ', ' . $v_products_id . ', ' . $v_products_price . ' )'); } if ($v_customer_price_2 != '') { $result = $dbconn->Execute(' INSERT INTO ' . $oostable['products_groups'] . ' VALUES ( ' . $v_customer_group_id_2 . ', ' . $v_customer_price_2 . ', ' . $v_products_id . ', ' . $v_products_price . ' )'); } if ($v_customer_price_3 != '') { $result = $dbconn->Execute(' INSERT INTO ' . $oostable['products_groups'] . ' VALUES ( ' . $v_customer_group_id_3 . ', ' . $v_customer_price_3 . ', ' . $v_products_id . ', ' . $v_products_price . ' )'); } if ($v_customer_price_4 != '') { $result = $dbconn->Execute(' INSERT INTO ' . $oostable['products_groups'] . ' VALUES ( ' . $v_customer_group_id_4 . ', ' . $v_customer_price_4 . ', ' . $v_products_id . ', ' . $v_products_price . ' )'); } } // VJ product attribs begin if (isset($v_attribute_options_id_1)) { $attribute_rows = 1; // master row count $languages = oos_get_languages(); // product options count $attribute_options_count = 1; $v_attribute_options_id_var = 'v_attribute_options_id_' . $attribute_options_count; while (isset(${$v_attribute_options_id_var}) && !empty(${$v_attribute_options_id_var})) { // remove product attribute options linked to this product before proceeding further // this is useful for removing attributes linked to a product $attributes_clean_result = "delete FROM " . $oostable['products_attributes'] . " WHERE products_id = '" . (int) $v_products_id . "' and options_id = '" . (int) ${$v_attribute_options_id_var} . "'"; $dbconn->Execute($attributes_clean_result); $attribute_options_result = "SELECT products_options_name FROM " . $oostable['products_options'] . " WHERE products_options_id = '" . (int) ${$v_attribute_options_id_var} . "'"; $attribute_options_values = $dbconn->Execute($attribute_options_result); // option table update begin if ($attribute_rows == 1) { // insert into options table if no option exists if ($attribute_options_values->RecordCount() <= 0) { for ($i = 0, $n = count($languages); $i < $n; $i++) { $lid = $languages[$i]['id']; $v_attribute_options_name_var = 'v_attribute_options_name_' . $attribute_options_count . '_' . $lid; if (isset(${$v_attribute_options_name_var})) { $attribute_options_insert_result = "insert into " . $oostable['products_options'] . " (products_options_id, products_options_languages_id, products_options_name) values ('" . (int) ${$v_attribute_options_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_options_name_var} . "')"; $attribute_options_insert = $dbconn->Execute($attribute_options_insert_result); } } } else { // update options table, if options already exists for ($i = 0, $n = count($languages); $i < $n; $i++) { $lid = $languages[$i]['id']; $v_attribute_options_name_var = 'v_attribute_options_name_' . $attribute_options_count . '_' . $lid; if (isset(${$v_attribute_options_name_var})) { $attribute_options_update_lang_result = "SELECT products_options_name FROM " . $oostable['products_options'] . " WHERE products_options_id = '" . (int) ${$v_attribute_options_id_var} . "' and products_options_languages_id ='" . (int) $lid . "'"; $attribute_options_update_lang_values = $dbconn->Execute($attribute_options_update_lang_result); // if option name doesn't exist for particular language, insert value if ($attribute_options_update_lang_values->RecordCount() <= 0) { $attribute_options_lang_insert_result = "insert into " . $oostable['products_options'] . " (products_options_id, products_options_languages_id, products_options_name) values ('" . (int) ${$v_attribute_options_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_options_name_var} . "')"; $attribute_options_lang_insert = $dbconn->Execute($attribute_options_lang_insert_result); } else { // if option name exists for particular language, update table $attribute_options_update_result = "update " . $oostable['products_options'] . " set products_options_name = '" . ${$v_attribute_options_name_var} . "' WHERE products_options_id ='" . (int) ${$v_attribute_options_id_var} . "' and products_options_languages_id = '" . (int) $lid . "'"; $attribute_options_update = $dbconn->Execute($attribute_options_update_result); } } } } } // option table update end // product option values count $attribute_values_count = 1; $v_attribute_values_id_var = 'v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count; while (isset(${$v_attribute_values_id_var}) && !empty(${$v_attribute_values_id_var})) { $attribute_values_result = "SELECT products_options_values_name FROM " . $oostable['products_options_values'] . " WHERE products_options_values_id = '" . (int) ${$v_attribute_values_id_var} . "'"; $attribute_values_values = $dbconn->Execute($attribute_values_result); // options_values table update begin if ($attribute_rows == 1) { // insert into options_values table if no option exists if ($attribute_values_values->RecordCount() <= 0) { for ($i = 0, $n = count($languages); $i < $n; $i++) { $lid = $languages[$i]['id']; $v_attribute_values_name_var = 'v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid; if (isset(${$v_attribute_values_name_var})) { $attribute_values_insert_result = "insert into " . $oostable['products_options_values'] . " (products_options_values_id, products_options_values_languages_id, products_options_values_name) values ('" . (int) ${$v_attribute_values_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_values_name_var} . "')"; $attribute_values_insert = $dbconn->Execute($attribute_values_insert_result); } } // insert values to pov2po table $attribute_values_pov2po_result = "insert into " . $oostable['products_options_values_to_products_options'] . " (products_options_id, products_options_values_id) values ('" . (int) ${$v_attribute_options_id_var} . "', '" . (int) ${$v_attribute_values_id_var} . "')"; $attribute_values_pov2po = $dbconn->Execute($attribute_values_pov2po_result); } else { // update options table, if options already exists for ($i = 0, $n = count($languages); $i < $n; $i++) { $lid = $languages[$i]['id']; $v_attribute_values_name_var = 'v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid; if (isset(${$v_attribute_values_name_var})) { $attribute_values_update_lang_result = "SELECT products_options_values_name FROM " . $oostable['products_options_values'] . " WHERE products_options_values_id = '" . (int) ${$v_attribute_values_id_var} . "' and products_options_values_languages_id ='" . (int) $lid . "'"; $attribute_values_update_lang_values = $dbconn->Execute($attribute_values_update_lang_result); // if options_values name doesn't exist for particular language, insert value if ($attribute_values_update_lang_values->RecordCount() <= 0) { $attribute_values_lang_insert_result = "insert into " . $oostable['products_options_values'] . " (products_options_values_id, products_options_values_languages_id, products_options_values_name) values ('" . (int) ${$v_attribute_values_id_var} . "', '" . (int) $lid . "', '" . ${$v_attribute_values_name_var} . "')"; $attribute_values_lang_insert = $dbconn->Execute($attribute_values_lang_insert_result); } else { // if options_values name exists for particular language, update table $attribute_values_update_result = "update " . $oostable['products_options_values'] . " set products_options_values_name = '" . ${$v_attribute_values_name_var} . "' WHERE products_options_values_id ='" . (int) ${$v_attribute_values_id_var} . "' and products_options_values_languages_id = '" . (int) $lid . "'"; $attribute_values_update = $dbconn->Execute($attribute_values_update_result); } } } } } // options_values table update end // options_values price update begin $v_attribute_values_price_var = 'v_attribute_values_price_' . $attribute_options_count . '_' . $attribute_values_count; if (isset(${$v_attribute_values_price_var}) && ${$v_attribute_values_price_var} != '') { $attribute_prices_result = "SELECT options_values_price, price_prefix FROM " . $oostable['products_attributes'] . " WHERE products_id = '" . (int) $v_products_id . "' and options_id ='" . (int) ${$v_attribute_options_id_var} . "' and options_values_id = '" . (int) ${$v_attribute_values_id_var} . "'"; $attribute_prices_values = $dbconn->Execute($attribute_prices_result); $attribute_values_price_prefix = ${$v_attribute_values_price_var} < 0 ? '-' : '+'; // options_values_prices table update begin // insert into options_values_prices table if no price exists if ($attribute_prices_values->RecordCount() <= 0) { $attribute_prices_insert_result = "insert into " . $oostable['products_attributes'] . " (products_id, options_id, options_values_id, options_values_price, price_prefix) values ('" . (int) $v_products_id . "', '" . (int) ${$v_attribute_options_id_var} . "', '" . (int) ${$v_attribute_values_id_var} . "', '" . (double) ${$v_attribute_values_price_var} . "', '" . $attribute_values_price_prefix . "')"; $attribute_prices_insert = $dbconn->Execute($attribute_prices_insert_result); } else { // update options table, if options already exists $attribute_prices_update_result = "update " . $oostable['products_attributes'] . " set options_values_price = '" . ${$v_attribute_values_price_var} . "', price_prefix = '" . $attribute_values_price_prefix . "' WHERE products_id = '" . (int) $v_products_id . "' and options_id = '" . (int) ${$v_attribute_options_id_var} . "' and options_values_id ='" . (int) ${$v_attribute_values_id_var} . "'"; $attribute_prices_update = $dbconn->Execute($attribute_prices_update_result); } } // options_values price update end // attributes stock add start $v_attribute_values_stock_var = 'v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count; if (isset(${$v_attribute_values_stock_var}) && ${$v_attribute_values_stock_var} != '') { $stock_attributes = ${$v_attribute_options_id_var} . '-' . ${$v_attribute_values_id_var}; $attribute_stock_query = $dbconn->Execute("SELECT products_stock_quantity FROM " . $oostable['products_stock'] . " WHERE products_id = '" . (int) $v_products_id . "' AND products_stock_attributes ='" . $stock_attributes . "'"); // insert into products_stock_quantity table if no stock exists if ($attribute_stock_query->RecordCount() <= 0) { $attribute_stock_insert_query = $dbconn->Execute("INSERT INTO " . $oostable['products_stock'] . " (products_id, products_stock_attributes, products_stock_quantity) VALUES ('" . (int) $v_products_id . "', '" . $stock_attributes . "', '" . (int) ${$v_attribute_values_stock_var} . "')"); } else { // update options table, if options already exists $attribute_stock_insert_query = $dbconn->Execute("UPDATE " . $oostable['products_stock'] . " SET products_stock_quantity = '" . (int) ${$v_attribute_values_stock_var} . "' WHERE products_id = '" . (int) $v_products_id . "' AND products_stock_attributes = '" . $stock_attributes . "'"); // turn on stock tracking on products_options table $stock_tracking_query = $dbconn->Execute("UPDATE " . $oostable['products_options'] . " SET products_options_track_stock = '1' WHERE products_options_id = '" . (int) ${$v_attribute_options_id_var} . "'"); } } // attributes stock add end $attribute_values_count++; $v_attribute_values_id_var = 'v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count; } $attribute_options_count++; $v_attribute_options_id_var = 'v_attribute_options_id_' . $attribute_options_count; } $attribute_rows++; } // VJ product attribs end } else { // this record was missing the product_model array_walk($items, 'print_el'); echo "<p class=smallText>No products_model field in record. This line was not imported <br />"; echo "<br />"; } // end of row insertion code }