Execute("insert into " . TABLE_PRODUCTS_OPTIONS . " (products_options_id, products_options_name, language_id, products_options_sort_order, products_options_type, products_options_images_per_row, products_options_images_style, products_options_rows) values ('" . (int)$products_options_id . "', '" . zen_db_input($option_name) . "', '" . (int)$languages[$i]['id'] . "', '" . (int)$products_options_sort_order[$languages[$i]['id']] . "', '" . (int)zen_db_input($option_type) . "', '" . (int)zen_db_input($products_options_images_per_row) . "', '" . (int)zen_db_input($products_options_images_style) . "', '" . (int)(($products_options_rows <= 1 and $option_type == PRODUCTS_OPTIONS_TYPE_TEXT) ? 1 : zen_db_input($products_options_rows)) . "' )"); } // iii 030811 added: For TEXT and FILE option types, automatically add // PRODUCTS_OPTIONS_VALUE_TEXT to the TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS switch ($option_type) { case PRODUCTS_OPTIONS_TYPE_TEXT: case PRODUCTS_OPTIONS_TYPE_FILE: $db->Execute("insert into " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " (products_options_values_id, products_options_id) values ('" . PRODUCTS_OPTIONS_VALUES_TEXT_ID . "', '" . (int)$products_options_id . "')"); break; } // alert if possible duplicate $duplicate_option= ''; for ($i=0, $n=sizeof($languages); $i<$n; $i ++) { $option_name = zen_db_prepare_input($option_name_array[$languages[$i]['id']]); if (!empty($option_name)) { $check= $db->Execute("select count(products_options_name) as count from " . TABLE_PRODUCTS_OPTIONS . " where language_id= '" . $languages[$i]['id'] . "' and products_options_name='" . zen_db_input($option_name) . "'"); if ($check->fields['count'] > 1) { $duplicate_option .= ' ' . strtoupper(zen_get_language_name($languages[$i]['id'])) . ' : ' . $option_name; } } } if (!empty($duplicate_option)) { $messageStack->add_session(ATTRIBUTE_POSSIBLE_OPTIONS_NAME_WARNING_DUPLICATE . ' ' . $option_id . ' - ' . $duplicate_option, 'caution'); } zen_redirect(zen_href_link(FILENAME_OPTIONS_NAME_MANAGER, $_SESSION['page_info'] . '&option_order_by=' . $option_order_by)); break; case 'update_option_name': //clr 030714 update to add option type to products_option. $option_name_array = $_POST['option_name']; $option_type = $_POST['option_type']; $option_id = zen_db_prepare_input($_POST['option_id']); $products_options_sort_order_array = $_POST['products_options_sort_order']; $products_options_length_array = $_POST['products_options_length']; $products_options_comment_array = $_POST['products_options_comment']; $products_options_size_array = $_POST['products_options_size']; $products_options_images_per_row_array = $_POST['products_options_images_per_row']; $products_options_images_style_array = $_POST['products_options_images_style']; $products_options_rows_array = $_POST['products_options_rows']; for ($i=0, $n=sizeof($languages); $i<$n; $i ++) { $option_name = zen_db_prepare_input($option_name_array[$languages[$i]['id']]); $products_options_sort_order = (int)zen_db_prepare_input($products_options_sort_order_array[$languages[$i]['id']]); $products_options_length = zen_db_prepare_input($products_options_length_array[$languages[$i]['id']]); $products_options_comment = zen_db_prepare_input($products_options_comment_array[$languages[$i]['id']]); $products_options_size = zen_db_prepare_input($products_options_size_array[$languages[$i]['id']]); $products_options_images_per_row = (int)zen_db_prepare_input($products_options_images_per_row_array[$languages[$i]['id']]); $products_options_images_style = (int)zen_db_prepare_input($products_options_images_style_array[$languages[$i]['id']]); $products_options_rows = (int)zen_db_prepare_input($products_options_rows_array[$languages[$i]['id']]); // zen_db_query("update " . TABLE_PRODUCTS_OPTIONS . " set products_options_name = '" . zen_db_input($option_name) . "', products_options_type = '" . $option_type . "' where products_options_id = '" . (int)$option_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'"); $db->Execute("update " . TABLE_PRODUCTS_OPTIONS . " set products_options_name = '" . zen_db_input($option_name) . "', products_options_type = '" . $option_type . "', products_options_length = '" . zen_db_input($products_options_length) . "', products_options_comment = '" . zen_db_input($products_options_comment) . "', products_options_size = '" . zen_db_input($products_options_size) . "', products_options_sort_order = '" . zen_db_input($products_options_sort_order) . "', products_options_images_per_row = '" . zen_db_input($products_options_images_per_row) . "', products_options_images_style = '" . zen_db_input($products_options_images_style) . "', products_options_rows = '" . zen_db_input($products_options_rows) . "' where products_options_id = '" . (int)$option_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'"); } switch ($option_type) { case PRODUCTS_OPTIONS_TYPE_TEXT: case PRODUCTS_OPTIONS_TYPE_FILE: // disabled because this could cause trouble if someone changed types unintentionally and deleted all their option values. Shops with small numbers of values per option should consider uncommenting this. // zen_db_query("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . $_POST['option_id'] . "'"); // add in a record if none exists when option type is switched $check_type = $db->Execute("select count(products_options_id) as count from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id='" . $_POST['option_id'] . "' and products_options_values_id ='0'"); if ($check_type->fields['count'] == 0) { $db->Execute("insert into " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " (products_options_values_to_products_options_id, products_options_id, products_options_values_id) values (NULL, '" . $_POST['option_id'] . "', '" . PRODUCTS_OPTIONS_VALUES_TEXT_ID . "')"); } break; default: // if switched from file or text remove 0 $db->Execute("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id='" . $_POST['option_id'] . "' and products_options_values_id = '" . PRODUCTS_OPTIONS_VALUES_TEXT_ID . "'"); break; } // alert if possible duplicate $duplicate_option= ''; for ($i=0, $n=sizeof($languages); $i<$n; $i ++) { $option_name = zen_db_prepare_input($option_name_array[$languages[$i]['id']]); $check= $db->Execute("select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where language_id= '" . $languages[$i]['id'] . "' and products_options_name='" . zen_db_input($option_name) . "'"); if ($check->RecordCount() > 1 and !empty($option_name)) { $duplicate_option .= ' ' . strtoupper(zen_get_language_name($languages[$i]['id'])) . ' : ' . $option_name; } } if (!empty($duplicate_option)) { $messageStack->add_session(ATTRIBUTE_POSSIBLE_OPTIONS_NAME_WARNING_DUPLICATE . ' ' . $option_id . ' - ' . $duplicate_option, 'caution'); } zen_redirect(zen_href_link(FILENAME_OPTIONS_NAME_MANAGER, $_SESSION['page_info'] . '&option_order_by=' . $option_order_by)); break; case 'delete_option': // demo active test if (zen_admin_demo()) { $_GET['action']= ''; $messageStack->add_session(ERROR_ADMIN_DEMO, 'caution'); zen_redirect(zen_href_link(FILENAME_OPTIONS_NAME_MANAGER, $_SESSION['page_info'] . '&option_order_by=' . $option_order_by)); } $option_id = zen_db_prepare_input($_GET['option_id']); $remove_option_values = $db->Execute("select products_options_id, products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id='" . (int)$option_id . "'"); while (!$remove_option_values->EOF) { $db->Execute("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id='" . $remove_option_values->fields['products_options_values_id'] . "' and products_options_values_id !=0"); $remove_option_values->MoveNext(); } $db->Execute("delete from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$option_id . "'"); $db->Execute("delete from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$option_id . "'"); zen_redirect(zen_href_link(FILENAME_OPTIONS_NAME_MANAGER, $_SESSION['page_info'] . '&option_order_by=' . $option_order_by)); break; ///////////////////////////////////// // additional features case 'update_options_values': // get products to update with at least one option_value for selected options_name $update_to = $_GET['update_to']; $update_action = $_GET['update_action']; switch($update_to) { case (0): // all products $all_update_products = $db->Execute("select distinct products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where options_id='" . $_POST['options_id'] . "'"); break; case (1): // one product $product_to_update = $_POST['product_to_update']; $all_update_products = $db->Execute("select distinct products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where options_id='" . $_POST['options_id'] . "' and products_id='" . $product_to_update . "'"); break; case (2): // category of products $category_to_update = $_POST['category_to_update']; // re-write with categories $all_update_products = $db->Execute("select distinct pa.products_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc on pa.products_id = ptc.products_id where ptc.categories_id ='" . $category_to_update . "' and pa.options_id='" . $_POST['options_id'] . "' and pa.products_id = ptc.products_id"); break; } if ($all_update_products->RecordCount() < 1) { $messageStack->add_session(ERROR_PRODUCTS_OPTIONS_VALUES, 'caution'); } else { //die('I want to update ' . $_GET['update_to'] . ' : update action: ' . $update_action . ' product: ' . $_POST['product_to_update'] . ' category: ' . $_POST['category_to_update'] . ' found records: ' . $all_update_products->RecordCount() . ' - ' . $all_update_products->fields['products_id']); if ($update_action == 0) { // action add while (!$all_update_products->EOF) { // get all option_values $all_options_values = $db->Execute("select products_options_id, products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id='" . $_POST['options_id'] . "'"); $updated = 'false'; while (!$all_options_values->EOF) { $check_all_options_values = $db->Execute("select products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $all_update_products->fields['products_id'] . "' and options_id='" . $all_options_values->fields['products_options_id'] . "' and options_values_id='" . $all_options_values->fields['products_options_values_id'] . "'"); if ($check_all_options_values->RecordCount() < 1) { // add missing options_value_id $updated = 'true'; $db->Execute("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " (products_id, options_id, options_values_id) values ('" . $all_update_products->fields['products_id'] . "', '" . $all_options_values->fields['products_options_id'] . "', '" . $all_options_values->fields['products_options_values_id'] . "')"); } else { // skip it the attribute is there } $all_options_values->MoveNext(); } if ($updated == 'true') { zen_update_attributes_products_option_values_sort_order($all_update_products->fields['products_id']); } $all_update_products->MoveNext(); } if ($updated='true') { $messageStack->add_session(SUCCESS_PRODUCTS_OPTIONS_VALUES, 'success'); } else { $messageStack->add_session(ERROR_PRODUCTS_OPTIONS_VALUES, 'error'); } } else { // action delete while (!$all_update_products->EOF) { // get all option_values $all_options_values = $db->Execute("select products_options_id, products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id='" . $_POST['options_id'] . "'"); $updated = 'false'; while (!$all_options_values->EOF) { $check_all_options_values = $db->Execute("select products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $all_update_products->fields['products_id'] . "' and options_id='" . $all_options_values->fields['products_options_id'] . "' and options_values_id='" . $all_options_values->fields['products_options_values_id'] . "'"); if ($check_all_options_values->RecordCount() >= 1) { // delete for this product with Option Name options_value_id // echo '
This should be deleted: ' . zen_get_products_name($all_options_values->fields['products_options_id']); // change to delete // should add download delete $db->Execute("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $all_update_products->fields['products_id'] . "' and options_id='" . $_POST['options_id'] . "'"); } else { // skip this option_name does not exist } $all_options_values->MoveNext(); } $all_update_products->MoveNext(); } } // update_action } // no products found zen_redirect(zen_href_link(FILENAME_OPTIONS_NAME_MANAGER, $_SESSION['page_info'] . '&option_order_by=' . $option_order_by)); break; //////////////////////////////////// // copy features case 'copy_options_values': $options_id_from = $_POST['options_id_from']; $options_id_to = $_POST['options_id_to']; if ($options_id_from == $options_id_to) { // cannot copy to self $messageStack->add(ERROR_OPTION_VALUES_COPIED . ' from: ' . zen_options_name($options_id_from) . ' to: ' . zen_options_name($options_id_to), 'warning'); } else { // successful copy $start_id = $db->Execute("select pov.products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov order by pov.products_options_values_id DESC LIMIT 1"); $copy_from_values = $db->Execute("select pov.* from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov left join " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " povtpo on pov.products_options_values_id= povtpo.products_options_values_id where povtpo.products_options_id='" . $options_id_from . "' order by povtpo.products_options_values_id"); if ($copy_from_values->RecordCount() > 0) { // successful copy $next_id = ($start_id->fields['products_options_values_id'] + 1); while(!$copy_from_values->EOF) { $current_id = $copy_from_values->fields['products_options_values_id']; $sql = "insert into " . TABLE_PRODUCTS_OPTIONS_VALUES . " (products_options_values_id, language_id, products_options_values_name, products_options_values_sort_order) values ('" . $next_id . "', '" . $copy_from_values->fields['language_id'] . "', '" . $copy_from_values->fields['products_options_values_name'] . "', '" . $copy_from_values->fields['products_options_values_sort_order'] . "')"; $db->Execute($sql); $copy_from_values->MoveNext(); if ($copy_from_values->fields['products_options_values_id'] != $current_id or $copy_from_values->EOF) { $sql = "insert into " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " (products_options_values_to_products_options_id, products_options_id, products_options_values_id) values (0, '" . $options_id_to . "', '" . $next_id . "')"; $db->Execute($sql); $next_id++; } } $messageStack->add(SUCCESS_OPTION_VALUES_COPIED . ' from: ' . zen_options_name($options_id_from) . ' to: ' . zen_options_name($options_id_to), 'success'); } else { // warning nothing to copy $messageStack->add(ERROR_OPTION_VALUES_NONE . ' from: ' . zen_options_name($options_id_from) . ' to: ' . zen_options_name($options_id_to), 'warning'); } } break; //////////////////////////////////// } } //iii 031103 added to get results from database option type query $products_options_types_list = array(); // $products_options_type_array = $db->Execute("select products_options_types_id, products_options_types_name from " . TABLE_PRODUCTS_OPTIONS_TYPES . " where language_id='" . $_SESSION['languages_id'] . "' order by products_options_types_id"); $products_options_type_array = $db->Execute("select products_options_types_id, products_options_types_name from " . TABLE_PRODUCTS_OPTIONS_TYPES . " order by products_options_types_id"); while (!$products_options_type_array->EOF) { $products_options_types_list[$products_options_type_array->fields['products_options_types_id']] = $products_options_type_array->fields['products_options_types_name']; $products_options_type_array->MoveNext(); } //CLR 030312 add function to draw pulldown list of option types // Draw a pulldown for Option Types //iii 031103 modified to use results of database option type query from above function draw_optiontype_pulldown($name, $default = '') { global $products_options_types_list; $values = array(); foreach ($products_options_types_list as $id => $text) { $values[] = array('id' => $id, 'text' => $text); } return zen_draw_pull_down_menu($name, $values, $default); } //CLR 030312 add function to translate type_id to name // Translate option_type_values to english string //iii 031103 modified to use results of database option type query from above function translate_type_to_name($opt_type) { global $products_options_types_list; return $products_options_types_list[$opt_type]; return 'Error ' . $opt_type; } ?> > <?php echo TITLE; ?>
  '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_NAME_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_id, products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$_GET['option_id'] . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'"); ?> Execute($options); while (!$options_values->EOF) { $rows++; ?> fields['products_options_id'])) { echo ''; $inputs = ''; $inputs2 = ''; for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) { $option_name = $db->Execute("select products_options_name, products_options_sort_order, products_options_size, products_options_length, products_options_comment, products_options_images_per_row, products_options_images_style, products_options_rows from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . $options_values->fields['products_options_id'] . "' and language_id = '" . $languages[$i]['id'] . "'"); $inputs .= $languages[$i]['code'] . ': ' . TEXT_SORT . ' 
'; $inputs2 .= $languages[$i]['code'] . ':  ' . ' ' . TEXT_OPTION_VALUE_COMMENTS . '' . '

' . TEXT_OPTION_VALUE_ROWS . '' . ' ' . TEXT_OPTION_VALUE_SIZE . '' . ' ' . TEXT_OPTION_VALUE_MAX . '' . '

' . TEXT_OPTION_ATTRIBUTE_IMAGES_PER_ROW . '' . ' ' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE . '' . '

'; } //CLR 030212 - Add column for option type ?> ' . "\n"; } else { //CLR 030212 - Add column for option type ?> Execute("select max(products_options_id) + 1 as next_id from " . TABLE_PRODUCTS_OPTIONS); $next_id = $max_options_id_values->fields['next_id']; $options_values->MoveNext(); } ?> '; $inputs = ''; for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) { $inputs .= $languages[$i]['code'] . ': ' . TEXT_SORT . '' . ' 
'; } //CLR 030212 - Add column for option type ?> '; ?>
 fields['products_options_name']; ?> 
Execute("select p.products_id, pd.products_name, pov.products_options_values_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pd.products_id = p.products_id and pov.language_id = '" . (int)$_SESSION['languages_id'] . "' and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' and pa.products_id = p.products_id and pa.options_id='" . (int)$_GET['option_id'] . "' and pov.products_options_values_id = pa.options_values_id order by pd.products_name"); if ($products->RecordCount()>0) { ?> RecordCount()> 10) { ?> EOF) { $rows++; ?> MoveNext(); } ?>

' . TEXT_OPTION_NAME . ': ' . zen_options_name((int)$_GET['option_id']) . '
' . TEXT_WARNING_OF_DELETE; ?>

'; ?> 
        
 fields['products_id']; ?>   fields['products_name']; ?>   fields['products_options_values_name']; ?> 


'; ?> 

' . TEXT_OPTION_NAME . ': ' . zen_options_name((int)$_GET['option_id']) . '
' . TEXT_OK_TO_DELETE; ?>

'; ?>   '; ?> 
  
Execute($options); $option_page_start = ($per_page * $_GET['option_page']) - $per_page; $num_rows = $option_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 ($option_page_start < 0) { $option_page_start = 0; } $options = $options . " LIMIT $option_page_start, $per_page"; // Previous if ($prev_option_page) { echo ' << | '; } for ($i = 1; $i <= $num_pages; $i++) { if ($i != $_GET['option_page']) { echo '' . $i . ' | '; } else { echo '' . $i . ' | '; } } // Next if ($_GET['option_page'] != $num_pages) { echo ' >> '; } //CLR 030212 - Add column for option type ?>
                  
 fields['products_options_id']; ?>  fields['products_options_type']); ?>     '; ?> 
 
  ' . TEXT_OPTION_IMAGE_STYLE . '
' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE_0 . '
' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE_1 . '
' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE_2 . '
' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE_3 . '
' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE_4 . '
' . TEXT_OPTION_ATTRIBUTE_IMAGES_STYLE_5 . '
'; ?>
 fields["products_options_id"]; ?>   fields["products_options_name"]; ?>   fields["products_options_type"]); ?>   fields["products_options_sort_order"]; ?>   fields["products_options_size"]; ?>   fields["products_options_length"]; ?>     fields['products_options_id'] . '&option_order_by=' . $option_order_by . '&option_page=' . $_GET['option_page'] . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') ) . '">'; ?>  fields['products_options_id'] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . '&option_order_by=' . $option_order_by, 'NONSSL') , '">'; ?>