Execute("select count(*) as count from " . TABLE_PRODUCTS_OPTIONS . " where language_id='" . $_SESSION['languages_id'] . "' limit 1");
if ($chk_option_names->fields['count'] < 1) {
$messageStack->add_session(ERROR_DEFINE_OPTION_NAMES, 'caution');
zen_redirect(zen_href_link(FILENAME_OPTIONS_NAME_MANAGER));
}
$languages = zen_get_languages();
$action = (isset($_GET['action']) ? $_GET['action'] : '');
// display or hide copier features
if (!isset($_SESSION['option_names_values_copier'])) {
$_SESSION['option_names_values_copier'] = OPTION_NAMES_VALUES_GLOBAL_STATUS;
}
if (!isset($_GET['reset_option_names_values_copier'])) {
$reset_option_names_values_copier = $_SESSION['option_names_values_copier'];
}
if (zen_not_null($action)) {
$_SESSION['page_info'] = '';
if (isset($_GET['option_page'])) $_SESSION['page_info'] .= 'option_page=' . $_GET['option_page'] . '&';
if (isset($_GET['value_page'])) $_SESSION['page_info'] .= 'value_page=' . $_GET['value_page'] . '&';
if (isset($_GET['attribute_page'])) $_SESSION['page_info'] .= 'attribute_page=' . $_GET['attribute_page'] . '&';
if (zen_not_null($_SESSION['page_info'])) {
$_SESSION['page_info'] = substr($_SESSION['page_info'], 0, -1);
}
switch ($action) {
case 'set_option_names_values_copier':
$_SESSION['option_names_values_copier'] = $_GET['reset_option_names_values_copier'];
$action='';
zen_redirect(zen_href_link(FILENAME_OPTIONS_VALUES_MANAGER));
break;
case 'add_product_option_values':
$value_name_array = $_POST['value_name'];
$value_id = zen_db_prepare_input($_POST['value_id']);
$option_id = zen_db_prepare_input($_POST['option_id']);
$products_options_values_sort_order = zen_db_prepare_input($_POST['products_options_values_sort_order']);
for ($i=0, $n=sizeof($languages); $i<$n; $i ++) {
$value_name = zen_db_prepare_input($value_name_array[$languages[$i]['id']]);
$db->Execute("insert into " . TABLE_PRODUCTS_OPTIONS_VALUES . "
(products_options_values_id, language_id, products_options_values_name, products_options_values_sort_order)
values ('" . (int)$value_id . "',
'" . (int)$languages[$i]['id'] . "',
'" . zen_db_input($value_name) . "',
'" . (int)$products_options_values_sort_order . "')");
}
$db->Execute("insert into " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . "
(products_options_id, products_options_values_id)
values ('" . (int)$option_id . "', '" . (int)$value_id . "')");
// alert if possible duplicate
$duplicate_option_values= '';
for ($i=0, $n=sizeof($languages); $i<$n; $i ++) {
$value_name = zen_db_prepare_input($value_name_array[$languages[$i]['id']]);
if (!empty($value_name)) {
$check= $db->Execute("select pov.products_options_values_id, pov.products_options_values_name, pov.language_id
from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
left join " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " pov2po on pov.products_options_values_id = pov2po.products_options_values_id
where pov.language_id= '" . $languages[$i]['id'] . "'
and pov.products_options_values_name='" . zen_db_input($value_name) . "'
and pov2po.products_options_id ='" . (int)$option_id .
"'");
if ($check->RecordCount() > 1) {
while (!$check->EOF) {
$check_dups .= ' - ' . $check->fields['products_options_values_id'];
$check->MoveNext();
}
$duplicate_option_values .= ' ' . strtoupper(zen_get_language_name($languages[$i]['id'])) . ' : ' . $check_dups;
}
}
}
if (!empty($duplicate_option_values)) {
$messageStack->add_session(ATTRIBUTE_POSSIBLE_OPTIONS_VALUE_WARNING_DUPLICATE . ' ' . $duplicate_option_values, 'caution');
}
zen_redirect(zen_href_link(FILENAME_OPTIONS_VALUES_MANAGER, $_SESSION['page_info']));
break;
case 'update_value':
$value_name_array = $_POST['value_name'];
$value_id = zen_db_prepare_input($_POST['value_id']);
$option_id = zen_db_prepare_input($_POST['option_id']);
$products_options_values_sort_order = zen_db_prepare_input($_POST['products_options_values_sort_order']);
for ($i=0, $n=sizeof($languages); $i<$n; $i ++) {
$value_name = zen_db_prepare_input($value_name_array[$languages[$i]['id']]);
$db->Execute("update " . TABLE_PRODUCTS_OPTIONS_VALUES . "
set products_options_values_name = '" . zen_db_input($value_name) . "', products_options_values_sort_order = '" . (int)$products_options_values_sort_order . "'
where products_options_values_id = '" . zen_db_input($value_id) . "'
and language_id = '" . (int)$languages[$i]['id'] . "'");
}
$db->Execute("update " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . "
set products_options_id = '" . (int)$option_id . "'
where products_options_values_id = '" . (int)$value_id . "'");
// alert if possible duplicate
$duplicate_option_values= '';
for ($i=0, $n=sizeof($languages); $i<$n; $i ++) {
$value_name = zen_db_prepare_input($value_name_array[$languages[$i]['id']]);
if (!empty($value_name)) {
$check= $db->Execute("select pov.products_options_values_id, pov.products_options_values_name, pov.language_id
from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
left join " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " pov2po on pov.products_options_values_id = pov2po.products_options_values_id
where pov.language_id= '" . $languages[$i]['id'] . "'
and pov.products_options_values_name='" . zen_db_input($value_name) . "'
and pov2po.products_options_id ='" . (int)$option_id .
"'");
if ($check->RecordCount() > 1) {
while (!$check->EOF) {
$check_dups .= ' - ' . $check->fields['products_options_values_id'];
$check->MoveNext();
}
$duplicate_option_values .= ' ' . strtoupper(zen_get_language_name($languages[$i]['id'])) . ' : ' . $check_dups;
}
}
}
if (!empty($duplicate_option_values)) {
$messageStack->add_session(ATTRIBUTE_POSSIBLE_OPTIONS_VALUE_WARNING_DUPLICATE . ' ' . $duplicate_option_values, 'caution');
}
zen_redirect(zen_href_link(FILENAME_OPTIONS_VALUES_MANAGER, $_SESSION['page_info']));
break;
case 'delete_value':
// demo active test
if (zen_admin_demo()) {
$_GET['action']= '';
$messageStack->add_session(ERROR_ADMIN_DEMO, 'caution');
zen_redirect(zen_href_link(FILENAME_OPTIONS_VALUES_MANAGER, $_SESSION['page_info']));
}
$value_id = zen_db_prepare_input($_GET['value_id']);
// remove all attributes from products with value
$remove_attributes_query = $db->Execute("select products_attributes_id, options_id, options_values_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where options_values_id ='" . (int)$value_id . "'");
if ($remove_attributes_query->RecordCount() > 0) {
// clean all tables of option value
while (!$remove_attributes_query->EOF) {
$db->Execute("delete from " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . "
where products_attributes_id='" . $remove_attributes_query->fields['products_attributes_id'] . "'");
$remove_attributes_query->MoveNext();
}
$db->Execute("delete from " . TABLE_PRODUCTS_ATTRIBUTES . "
where options_values_id='" . (int)$value_id . "'");
}
$db->Execute("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES . "
where products_options_values_id = '" . (int)$value_id . "'");
$db->Execute("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . "
where products_options_values_id = '" . (int)$value_id . "'");
zen_redirect(zen_href_link(FILENAME_OPTIONS_VALUES_MANAGER, $_SESSION['page_info']));
break;
////////////////////////////////////////////////////
// copy option values based on existance of another option value
case 'copy_options_values_one_to_another':
$options_id_from = $_POST['options_id_from'];
$options_values_values_id_from = $_POST['options_values_values_id_from'];
$options_id_to = $_POST['options_id_to'];
$options_values_values_id_to = $_POST['options_values_values_id_to'];
// one category of products or all products
if ($_POST['copy_to_categories_id'] != '') {
$products_only = $db->Execute("select ptc.products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa on pa.products_id=ptc.products_id where ptc.categories_id='" . $_POST['copy_to_categories_id'] . "' and (pa.options_id='" . $options_id_from . "' and pa.options_values_id='" . $options_values_values_id_from . "')");
} else {
$products_only = $db->Execute("select pa.products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.options_id='" . $options_id_from . "' and pa.options_values_id='" . $options_values_values_id_from . "'");
}
/*
// debug code
while(!$products_only->EOF) {
echo 'Product ' . $products_only->fields['products_id'] . ' ';
$products_only->MoveNext();
}
die('I SEE match from: ' . $options_id_from . '-' . $options_values_values_id_from . ' add to: ' . $options_id_to . ' -' . $options_values_values_id_to . ' | only for cat ' . $_POST['copy_to_categories_id'] . ' | found matches ' . $products_only->RecordCount());
*/
if ($_POST['copy_to_categories_id'] == '') {
$zc_categories = ' All Products ';
} else {
$zc_categories = ' Category: ' . $_POST['copy_to_categories_id'];
}
$new_attribute=0;
if ($options_values_values_id_from == $options_values_values_id_to) {
// cannot copy to self
$messageStack->add(ERROR_OPTION_VALUES_COPIED . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' ' . zen_values_name($options_values_values_id_to), 'warning');
} else {
if (!zen_validate_options_to_options_value($options_id_from, $options_values_values_id_from) or !zen_validate_options_to_options_value($options_id_to, $options_values_values_id_to)) {
$messageStack->add(ERROR_OPTION_VALUES_COPIED_MISMATCH . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' ' . zen_values_name($options_values_values_id_to), 'warning');
} else {
// check for existing combination
if ($products_only->RecordCount() > 0) {
// check existing matching products and add new attributes
while(!$products_only->EOF) {
$current_products_id = $products_only->fields['products_id'];
$sql = "insert into " . TABLE_PRODUCTS_ATTRIBUTES . " (products_id, options_id, options_values_id) values('" . $current_products_id . "', '" . $options_id_to . "', '" . $options_values_values_id_to . "')";
$check_previous = $db->Execute("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $current_products_id . "' and options_id='" . $options_id_to . "' and options_values_id='" . $options_values_values_id_to . "' limit 1");
// do not add duplicate attributes
if ($check_previous->fields['count'] < 1) {
$db->Execute($sql);
$new_attribute++;
}
$products_only->MoveNext();
}
// display how many products were updated
if ($new_attribute < 1) {
// nothing was added due to duplicates
$messageStack->add(SUCCESS_OPTION_VALUES_COPIED . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' ' . zen_values_name($options_values_values_id_to) . ' for: ' . $zc_categories . ' ' . $new_attribute . ' products', 'caution');
} else {
// successful addition of new attributes that were not duplicates
$messageStack->add(SUCCESS_OPTION_VALUES_COPIED . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' ' . zen_values_name($options_values_values_id_to) . ' for: ' . $zc_categories . ' ' . $new_attribute . ' products', 'success');
}
} else {
// warning nothing to copy
$messageStack->add(ERROR_OPTION_VALUES_NONE . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' ' . zen_values_name($options_values_values_id_to) . $zc_categories, 'warning');
}
} // mismatch
} // same option value
break;
////////////////////////////////////
// fix here copy_options_values_one_to_another_options_id
////////////////////////////////////////////////////
// copy option values based on existance of another option value
case 'copy_options_values_one_to_another_options_id':
$options_id_from = $_POST['options_id_from'];
$options_values_values_id_from = $_POST['options_values_values_id_from'];
$copy_from_products_id = $_POST['copy_from_products_id'];
$options_id_to = $_POST['options_id_to'];
$options_values_values_id_to = $_POST['options_values_values_id_to'];
// one category of products or all products
if ($_POST['copy_to_categories_id'] != '') {
$products_only = $db->Execute("select distinct ptc.products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa on pa.products_id=ptc.products_id where ptc.categories_id='" . $_POST['copy_to_categories_id'] . "' and (pa.options_id='" . $options_id_to . "')");
} else {
$products_only = $db->Execute("select distinct pa.products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.options_id='" . $options_id_to . "'");
}
$products_attributes_defaults = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $copy_from_products_id . "' and options_id='" . $options_id_from . "' and pa.options_values_id='" . $options_values_values_id_from . "'");
$options_id = zen_db_prepare_input($options_id_from);
$values_id = zen_db_prepare_input($options_values_values_id_from);
if (!$products_attributes_defaults->EOF) {
$options_values_price = zen_db_prepare_input($products_attributes_defaults->fields['options_values_price']);
$price_prefix = zen_db_prepare_input($products_attributes_defaults->fields['price_prefix']);
$products_options_sort_order = zen_db_prepare_input($products_attributes_defaults->fields['products_options_sort_order']);
$product_attribute_is_free = zen_db_prepare_input($products_attributes_defaults->fields['product_attribute_is_free']);
$products_attributes_weight = zen_db_prepare_input($products_attributes_defaults->fields['products_attributes_weight']);
$products_attributes_weight_prefix = zen_db_prepare_input($products_attributes_defaults->fields['products_attributes_weight_prefix']);
$attributes_display_only = zen_db_prepare_input($products_attributes_defaults->fields['attributes_display_only']);
$attributes_default = zen_db_prepare_input($products_attributes_defaults->fields['attributes_default']);
$attributes_discounted = zen_db_prepare_input($products_attributes_defaults->fields['attributes_discounted']);
$attributes_price_base_included = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_base_included']);
$attributes_price_onetime = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_onetime']);
$attributes_price_factor = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_factor']);
$attributes_price_factor_offset = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_factor_offset']);
$attributes_price_factor_onetime = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_factor_onetime']);
$attributes_price_factor_onetime_offset = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_factor_onetime_offset']);
$attributes_qty_prices = zen_db_prepare_input($products_attributes_defaults->fields['attributes_qty_prices']);
$attributes_qty_prices_onetime = zen_db_prepare_input($products_attributes_defaults->fields['attributes_qty_prices_onetime']);
$attributes_price_words = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_words']);
$attributes_price_words_free = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_words_free']);
$attributes_price_letters = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_letters']);
$attributes_price_letters_free = zen_db_prepare_input($products_attributes_defaults->fields['attributes_price_letters_free']);
$attributes_required = zen_db_prepare_input($products_attributes_defaults->fields['attributes_required']);
}
/*
/////
// debug code
while(!$products_only->EOF) {
echo 'Product ' . $products_only->fields['products_id'] . ' ';
$products_only->MoveNext();
}
die('I SEE match from products_id:' . $copy_from_products_id . ' options_id_from: ' . $options_id_from . '-' . $options_values_values_id_from . ' add to: ' . $options_id_to . ' | only for cat ' . $_POST['copy_to_categories_id'] . ' | found matches ' . $products_only->RecordCount() . ' ' .
'from products_id: ' . $products_attributes_defaults->fields['products_id'] . ' option_id: ' . $products_attributes_defaults->fields['options_id'] . ' options_values_id: ' . $products_attributes_defaults->fields['options_values_id']
);
/////
*/
if ($_POST['copy_to_categories_id'] == '') {
$zc_categories = ' All Products ';
} else {
$zc_categories = ' Category: ' . $_POST['copy_to_categories_id'];
}
$new_attribute=0;
if (!zen_validate_options_to_options_value($options_id_from, $options_values_values_id_from) or ($products_attributes_defaults->EOF and $copy_from_products_id != '')) {
if ($products_attributes_defaults->EOF and $copy_from_products_id != '') {
// bad product_id with no match
$messageStack->add(ERROR_OPTION_VALUES_COPIED_MISMATCH_PRODUCTS_ID . $copy_from_products_id . ': ' . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from), 'warning');
} else {
// mismatched Option Name/Value
$messageStack->add(ERROR_OPTION_VALUES_COPIED_MISMATCH . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from), 'warning');
}
} else {
// check for existing combination
if ($products_only->RecordCount() > 0) {
// check existing matching products and add new attributes
while(!$products_only->EOF) {
$current_products_id = $products_only->fields['products_id'];
// $sql = "insert into " . TABLE_PRODUCTS_ATTRIBUTES . "(products_id, options_id, options_values_id) values('" . $current_products_id . "', '" . $options_id_from . "', '" . $options_values_values_id_from . "')";
$sql = "insert into " . TABLE_PRODUCTS_ATTRIBUTES . " (products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order, product_attribute_is_free, products_attributes_weight, products_attributes_weight_prefix, attributes_display_only, attributes_default, attributes_discounted, attributes_image, attributes_price_base_included, attributes_price_onetime, attributes_price_factor, attributes_price_factor_offset, attributes_price_factor_onetime, attributes_price_factor_onetime_offset, attributes_qty_prices, attributes_qty_prices_onetime, attributes_price_words, attributes_price_words_free, attributes_price_letters, attributes_price_letters_free, attributes_required)
values (0,
'" . (int)$current_products_id . "',
'" . (int)$options_id . "',
'" . (int)$values_id . "',
'" . zen_db_input($options_values_price) . "',
'" . zen_db_input($price_prefix) . "',
'" . (int)zen_db_input($products_options_sort_order) . "',
'" . (int)zen_db_input($product_attribute_is_free) . "',
'" . (float)zen_db_input($products_attributes_weight) . "',
'" . zen_db_input($products_attributes_weight_prefix) . "',
'" . (int)zen_db_input($attributes_display_only) . "',
'" . (int)zen_db_input($attributes_default) . "',
'" . (int)zen_db_input($attributes_discounted) . "',
'" . zen_db_input($attributes_image_name) . "',
'" . (int)zen_db_input($attributes_price_base_included) . "',
'" . (float)zen_db_input($attributes_price_onetime) . "',
'" . (float)zen_db_input($attributes_price_factor) . "',
'" . (float)zen_db_input($attributes_price_factor_offset) . "',
'" . (float)zen_db_input($attributes_price_factor_onetime) . "',
'" . (float)zen_db_input($attributes_price_factor_onetime_offset) . "',
'" . zen_db_input($attributes_qty_prices) . "',
'" . zen_db_input($attributes_qty_prices_onetime) . "',
'" . (float)zen_db_input($attributes_price_words) . "',
'" . (int)zen_db_input($attributes_price_words_free) . "',
'" . (float)zen_db_input($attributes_price_letters) . "',
'" . (int)zen_db_input($attributes_price_letters_free) . "',
'" . (int)zen_db_input($attributes_required) . "')";
$check_previous = $db->Execute("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $current_products_id . "' and options_id='" . $options_id_from . "' and options_values_id='" . $options_values_values_id_from . "' limit 1");
// do not add duplicate attributes
if ($check_previous->fields['count'] < 1) {
// add new attribute
$db->Execute($sql);
//echo $sql . ' ';
$new_attribute++;
} else {
// ignore
if ($_POST['copy_attributes'] == 'copy_attributes_ignore') {
//echo 'skipped already exists: ' . $current_products_id . ' ';
} else {
// delete old and add new
//echo 'delete old and add new: ' . $current_products_id . ' ';
$db->Execute("DELETE from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $current_products_id . "' and options_id='" . $options_id_from . "' and options_values_id='" . $options_values_values_id_from . "'");
$db->Execute($sql);
$new_attribute++;
}
}
$products_only->MoveNext();
}
// display how many products were updated
if ($new_attribute < 1) {
// nothing was added
$messageStack->add(ERROR_OPTION_VALUES_NONE . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' for: ' . $zc_categories . ' ' . $new_attribute . ' products', 'warning');
} else {
// successful addition of new attributes that were not duplicates
$messageStack->add(SUCCESS_OPTION_VALUES_COPIED . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' for: ' . $zc_categories . ' ' . $new_attribute . ' products', 'success');
}
} else {
// warning nothing to copy
$messageStack->add(ERROR_OPTION_VALUES_NONE . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' for: ' . $zc_categories, 'warning');
}
} // mismatch
break;
////////////////////////////////////
case ('delete_options_values_of_option_name'):
$options_id_from = $_POST['options_id_from'];
$options_values_values_id_from = $_POST['options_values_values_id_from'];
// one category of products or all products
if ($_POST['copy_to_categories_id'] != '') {
$products_only = $db->Execute("select ptc.products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa on pa.products_id=ptc.products_id where ptc.categories_id='" . $_POST['copy_to_categories_id'] . "' and (pa.options_id='" . $options_id_from . "' and pa.options_values_id='" . $options_values_values_id_from . "')");
} else {
$products_only = $db->Execute("select pa.products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.options_id='" . $options_id_from . "' and pa.options_values_id='" . $options_values_values_id_from . "'");
}
if ($_POST['copy_to_categories_id'] == '') {
$zc_categories = ' All Products ';
} else {
$zc_categories = ' Category: ' . $_POST['copy_to_categories_id'];
}
$new_attribute=0;
if (!zen_validate_options_to_options_value($options_id_from, $options_values_values_id_from)) {
$messageStack->add(ERROR_OPTION_VALUES_DELETE_MISMATCH . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from), 'warning');
} else {
// check for existing combination
if ($products_only->RecordCount() > 0) {
// check existing matching products and add new attributes
while(!$products_only->EOF) {
$current_products_id = $products_only->fields['products_id'];
// check for associated downloads
$downloads_remove_query = "select products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $current_products_id . "' and options_id='" . $options_id_from . "' and options_values_id='" . $options_values_values_id_from . "'";
$downloads_remove = $db->Execute($downloads_remove_query);
$sql = "delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $current_products_id . "' and options_id='" . $options_id_from . "' and options_values_id='" . $options_values_values_id_from . "'";
$delete_selected = $db->Execute($sql);
// delete associated downloads
while (!$downloads_remove->EOF) {
$db->Execute("delete from " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . "
where products_attributes_id='" . $downloads_remove->fields['products_attributes_id'] . "'");
$downloads_remove->MoveNext();
}
// count deleted attribute
$new_attribute++;
$products_only->MoveNext();
}
// display how many products were updated
if ($new_attribute < 1) {
// nothing was added due to duplicates
$messageStack->add(ERROR_OPTION_VALUES_NONE . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . ' for: ' . $zc_categories . ' ' . $new_attribute . ' products', 'caution');
} else {
// successful addition of new attributes that were not duplicates
$messageStack->add(SUCCESS_OPTION_VALUES_DELETE . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . ' for: ' . $zc_categories . ' ' . $new_attribute . ' products', 'success');
}
} else {
// warning nothing to copy
$messageStack->add(ERROR_OPTION_VALUES_NONE . TEXT_INFO_FROM . zen_options_name($options_id_from) . ' ' . zen_values_name($options_values_values_id_from) . TEXT_INFO_TO . zen_options_name($options_id_to) . ' ' . zen_values_name($options_values_values_id_to) . $zc_categories, 'warning');
}
} // mismatch
break;
}
}
?>
>
'0', 'text' => TEXT_SHOW_OPTION_NAMES_VALUES_COPIER_OFF),
array('id' => '1', 'text' => TEXT_SHOW_OPTION_NAMES_VALUES_COPIER_ON),
);
echo zen_draw_form('set_option_names_values_copier_form', FILENAME_OPTIONS_VALUES_MANAGER, '', 'get') . ' ' . zen_draw_pull_down_menu('reset_option_names_values_copier', $option_names_values_copier_array, $reset_option_names_values_copier, 'onChange="this.form.submit();"') .
zen_hide_session_id() .
zen_draw_hidden_field('action', 'set_option_names_values_copier') .
'';
?>
Execute("select products_options_values_id, products_options_values_name
from " . TABLE_PRODUCTS_OPTIONS_VALUES . "
where products_options_values_id = '" . (int)$_GET['value_id'] . "'
and language_id = '" . (int)$_SESSION['languages_id'] . "'");
?>
fields['products_options_values_name']; ?>
Execute("select p.products_id, pd.products_name, po.products_options_name, pa.options_id
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_ATTRIBUTES . " pa, "
. TABLE_PRODUCTS_OPTIONS . " po, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where pd.products_id = p.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and po.language_id = '" . (int)$_SESSION['languages_id'] . "'
and pa.products_id = p.products_id
and pa.options_values_id='" . (int)$_GET['value_id'] . "'
and po.products_options_id = pa.options_id
order by pd.products_name");
if ($products_values->RecordCount() > 0) {
?>
RecordCount() > 10) {
?>
'; ?> '; ?>
EOF) {
$rows++;
?>
fields['products_id']; ?>
fields['products_name']; ?>
fields["products_options_sort_order"]; ?>
fields['products_options_name']; ?>
MoveNext();
}
?>
'; ?> '; ?>
'; ?> '; ?>
Execute($values);
$value_page_start = ($per_page * $_GET['value_page']) - $per_page;
$num_rows = $value_query->RecordCount();
if ($num_rows <= $per_page) {
$num_pages = 1;
} else if (($num_rows % $per_page) == 0) {
$num_pages = ($num_rows / $per_page);
} else {
$num_pages = ($num_rows / $per_page) + 1;
}
$num_pages = (int) $num_pages;
// fix limit error on some versions
if ($value_page_start < 0) { $value_page_start = 0; }
$values = $values . " LIMIT $value_page_start, $per_page";
// Previous
if ($prev_value_page) {
echo ' << | ';
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $_GET['value_page']) {
echo '' . $i . ' | ';
} else {
echo '' . $i . ' | ';
}
}
// Next
if ($_GET['value_page'] != $num_pages) {
echo ' >> ';
}
?>
Execute($values);
while (!$values_values->EOF) {
$options_name = zen_options_name($values_values->fields['products_options_id']);
// iii 030813 added: Option Type Feature and File Uploading
// fetch products_options_id for use if the option value is deleted
// with TEXT and FILE Options, there are multiple options for the single TEXT
// value and only the single reference should be deleted
$option_id = $values_values->fields['products_options_id'];
$values_name = $values_values->fields['products_options_values_name'];
$products_options_values_sort_order = $values_values->fields['products_options_values_sort_order'];
$rows++;
?>
fields['products_options_values_id'])) {
echo '
';
?>
Execute("select products_options_id, products_options_name, products_options_type
from " . TABLE_PRODUCTS_OPTIONS . "
where language_id = '" . $_SESSION['languages_id'] . "' and products_options_type !='" . PRODUCTS_OPTIONS_TYPE_TEXT . "' and products_options_type !='" . PRODUCTS_OPTIONS_TYPE_FILE . "'
order by products_options_name");
while (!$options_values->EOF) {
echo '' . $options_values->fields['products_options_name'] . ' ';
$options_values->MoveNext();
}
$inputs = '';
$inputs = '';
for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
$inputs .= $languages[$i]['code'] . ': ';
}
$inputs2 .= TEXT_SORT . ' ';
?>
';
?>
Execute("select * from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . $_SESSION['languages_id'] . "' and products_options_name !='' and products_options_type !='" . PRODUCTS_OPTIONS_TYPE_TEXT . "' and products_options_type !='" . PRODUCTS_OPTIONS_TYPE_FILE . "' order by products_options_name");
while(!$options_values_from->EOF) {
$option_from_dropdown .= "\n" . ' ' . $options_values_from->fields['products_options_name'] . ' ';
$options_values_from->MoveNext();
}
$option_to_dropdown= $option_from_dropdown;
$option_from_dropdown = "\n" . '' . $option_from_dropdown;
$option_from_dropdown.= "\n" . ' ';
$option_to_dropdown = "\n" . '' . $option_to_dropdown;
$option_to_dropdown.= "\n" . ' ';
// build dropdown for option_values from
$options_values_values_from = $db->Execute("select * from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where language_id = '" . $_SESSION['languages_id'] . "' and products_options_values_id !='0' order by products_options_values_name");
while(!$options_values_values_from->EOF) {
$show_option_name= ' [' . strtoupper(zen_get_products_options_name_from_value($options_values_values_from->fields['products_options_values_id'])) . ']';
$option_values_from_dropdown .= "\n" . ' ' . $options_values_values_from->fields['products_options_values_name'] . $show_option_name . ' '; echo zen_draw_hidden_field('option_value_from_filter', $_GET['options_id_from']);
$options_values_values_from->MoveNext();
}
$option_values_to_dropdown = $option_values_from_dropdown;
$option_values_from_dropdown = "\n" . '' . $option_values_from_dropdown;
$option_values_from_dropdown .= "\n" . ' ';
$option_values_to_dropdown = "\n" . '' . $option_values_to_dropdown;
$option_values_to_dropdown .= "\n" . ' ';
$to_categories_id = TEXT_SELECT_OPTION_VALUES_TO_CATEGORIES_ID . ' ';
$options_id_from_products_id = TEXT_SELECT_OPTION_FROM_PRODUCTS_ID . ' ';
// eof: build dropdowns for delete and add
?>