add; > 0 => edit
function get_option_form ($x_option, $id)
{
global $tpl_block, $tpl_section, $db_prefix;
if (empty ($x_option)) return '';
$tpl = load_tpl ('var', $tpl_section['product_option']);
$x_opt_tmp = explode (';', $x_option);
// get all options
$opt_def = array ();
$res = sql_query ("SELECT * FROM ".$db_prefix."cf_define WHERE as_prod_opt='1' ORDER BY field_order");
while ($row = sql_fetch_array ($res))
{
$opt_def[$row['field_id']]['title'] = $row['field_title'];
$opt_def[$row['field_id']]['help'] = $row['field_help'];
$opt_def[$row['field_id']]['type'] = $row['field_type'];
$opt_def[$row['field_id']]['option'] = $row['field_option'];
}
$row['block_prod_opt'] = '';
foreach ($x_opt_tmp as $key)
{
$type = empty ($opt_def[$key]['type']) ? 'err' : $opt_def[$key]['type'];
$err = FALSE;
$fid = $key.'_'.$id;
$row['form'] = '';
switch ($type)
{
case 'varchar':
// get option name and price
$p = strpos ($opt_def[$key]['option'], '|');
$price = trim (substr ($opt_def[$key]['option'], 0, $p - 1));
$val = trim (substr ($opt_def[$key]['option'], $p + 1));
// create form
$row['form'] = "";
break;
case 'textarea':
$p = strpos ($opt_def[$key]['option'], '|');
$val = substr ($opt_def[$key]['option'], $p + 1);
$row['form'] = "";
break;
case 'file':
$row['form'] = "";
break;
case 'select':
case 'radio':
// first, build options in an array (array[option_name] = option_name)
$foo = explode ("\r\n", $opt_def[$key]['option']);
$foo = array_pair ($foo, $foo);
$fii = array ();
foreach ($foo as $k => $v)
{
$p = strpos ($v, '|');
$price = trim (substr ($v, 0, $p - 1));
$val = trim (substr ($v, $p + 1));
// use safe_send to 'encrypt' the options (not really an encryption, just safe send)
$k = safe_send ($k);
$fii[$k] = $val;
if ($price > 0) $sign = '+ '; else $sign = '- ';
if (!empty ($price)) $fii[$k] = $val.' ('.$sign.num_format ($price, 0, 1).')';
}
if ($type == 'select')
$row['form'] = create_select_form ($fid, $fii);
else
$row['form'] = create_radio_form ($fid, $fii, '', 'v');
break;
case 'multi':
// definition
$foo = explode ("\r\n", $opt_def[$key]['option']);
$foo = array_pair ($foo, $foo);
$fii = array ();
foreach ($foo as $k => $v)
{
$p = strpos ($v, '|');
$price = trim (substr ($v, 0, $p - 1));
$val = trim (substr ($v, $p + 1));
$k = safe_send ($k);
$fii[$k] = $val;
if ($price > 0) $sign = '+ '; else $sign = '- ';
if (!empty ($price)) $fii[$k] = $val.' ('.$sign.num_format ($price, 0, 1).')';
}
$fuu = explode ("\r\n", $val[$key]);
$row['form'] = create_checkbox_form ($fid, $fii, $fuu, 1);
break;
default:
// prod opt is not defined! (perhaps removed?)
// then we remove the prod_opt from database
$err = TRUE;
$kj = array_search ($key, $x_opt_tmp);
unset ($x_opt_tmp[$kj]);
$new_x = implode (';',$x_opt_tmp);
sql_query ("UPDATE ".$db_prefix."products SET x_option='$new_x' WHERE item_id='$id' LIMIT 1");
break;
}
if (!$err)
{
$row['title'] = $opt_def[$key]['title'];
$row['help'] = empty ($info['help']) ? '' : addslashes ($info['help']);
$row['block_prod_opt'] .= quick_tpl ($tpl_block['prod_opt'], $row);
}
}
return quick_tpl ($tpl, $row);
}
require './includes/user_init.php';
// close shop?
if ($config['close_site']) msg_die ('site_closed');
$item_id = seo_param (get_param ('item_id'));
$add = get_param ('add');
// load tpl
$sub_product = $see_also = $prod_opt = $custom_field = $qty_more = $call_price = $url = TRUE;
$tpl = load_tpl ('detail.tpl');
// fetch cf
fetch_custom_field ();
// item id exists?
$row = sql_qquery ("SELECT * FROM ".$db_prefix."products WHERE item_id = '$item_id' AND (owner='' OR owner='$current_user_id') LIMIT 1");
if (empty($row['title'])) msg_die ('ITEM_ID_NOT_FOUND');
$cat_id = $row['cat_id'];
// update stat_hits
sql_query ("UPDATE ".$db_prefix."products SET stat_hits=stat_hits+1, stat_last_hit='$sql_now' WHERE item_id = '$item_id' LIMIT 1");
// image gallery
$i = 0; $ok = FALSE;
$txt['block_thumb'] = '';
while (!$ok)
{
$i++;
$fn = $item_id.'_'.$i;
$folder = get_folder ('products', $item_id);
if (file_exists ($folder.'/'.$fn.'.jpg'))
{
// use make_thumb ($fn, 'gallery', '', $i) => to show only pic #1
$row['image'] = make_thumb ($fn, 'gallery');
$txt['block_thumb'] .= quick_tpl ($tpl_block['thumb'], $row);
}
else
$ok = TRUE;
}
// if no image
if ($i == 1) $txt['block_thumb'] = "
";
// custom
$custom = get_custom_field ($row['item_id']);
$row['custom_field'] = $custom['auto_design'];
$row = array_merge ($row, $custom);
if (empty ($row['custom_field'])) $custom_field = FALSE;
// price & saving/discount
if (($row['price'] < $row['price_msrp']) && !$row['call_price'])
{
$discount_status = 1;
$row['discount_pct'] = num_format (((($row['price_msrp'] - $row['price']) / $row['price_msrp']) * 100));
}
else
{
$discount_status = 0;
$row['discount_pct'] = '';
}
// URL button
if (empty ($row['url'])) $url = FALSE;
// min max buy
$minmax = explode ('|', $row['min_max_buy']);
$min_buy = $minmax[0];
$max_buy = $minmax[1];
$row['min_buy'] = num_format ($min_buy);
$row['max_buy'] = empty ($max_buy) ? '~' : ($row['stock'] < $max_buy ? num_format ($row['stock']) : num_format ($max_buy));
if (empty ($max_buy) && ($min_buy == 1)) $qty_more = FALSE;
// subscription
if ($row['stock']) unset ($notify['rst']);
// option select
$row['prod_opt'] = get_option_form ($row['x_option'], $item_id);
if (empty ($row['prod_opt'])) $prod_opt = FALSE;
// see also?
if (empty ($row['see_also']))
$see_also = FALSE;
else
{
$txt['block_see_also'] = '';
$t = explode (',', $row['see_also']);
foreach ($t as $val)
{
$row['see_box'] = make_promo ($val, 'see_also');
$txt['block_see_also'] .= quick_tpl ($tpl_block['see_also'], $row);
}
}
// subproduct
$row['subproduct_item'] = ''; $sp = 0;
$ressp = sql_query ("SELECT * FROM ".$db_prefix."products WHERE parent_product = '$item_id'");
while ($rowsp = sql_fetch_array ($ressp))
{
$sp++;
$cat_id = $rowsp['cat_id'];
// price & saving/discount
if ($rowsp['price'] < $rowsp['price_msrp'])
{
$discount_status = 1;
$rowsp['discount_pct'] = num_format (((($rowsp['price_msrp'] - $rowsp['price']) / $rowsp['price_msrp']) * 100));
}
else
{
$discount_status = 0;
}
// output
$rowsp['sp'] = $sp;
$rowsp['subproduct_opt'] = get_option_form ($rowsp['x_option'], $rowsp['item_id']);
$rowsp['weight'] = num_format ($rowsp['weight'], 1);
$rowsp['short_note'] = (empty($rowsp['short_note']))? $lang['l_no_description'] : $rowsp['short_note'];
$rowsp['note'] = (empty($rowsp['note']))? $lang['l_no_description'] : $rowsp['note'];
$rowsp['xe_price'] = get_xe_price ($rowsp['price'], 'list');
$rowsp['price'] = num_format ($rowsp['price'], 0, 1);
$rowsp['price_msrp'] = num_format ($rowsp['price_msrp'], 0, 1);
$rowsp['image'] = make_thumb ($rowsp['item_id'].'_1', 'list');
if ($config['enable_adp'] == 3) $rowsp['item_id'] = create_seo_url ($rowsp['item_id'], $rowsp['title']);
$row['subproduct_item'] .= quick_tpl ($tpl_section['subproduct_item'], $rowsp);
}
if ($sp) $row['subproduct'] = quick_tpl ($tpl_section['subproduct'], $row); else $sub_product = FALSE;
// flush
$row['xe_price'] = get_xe_price ($row['price'], 'detail');
$row['digital'] = $row['digital_prod'] ? $lang['l_digital_icon'] : '';
$row['note'] = convert_smilies ($row['note']);
$row['weight'] = num_format ($row['weight'], 1);
$row['notify_select'] = create_select_form ('sub_type', $notify);
$row['short_note'] = (empty($row['short_note']))? $lang['l_no_description'] : $row['short_note'];
$row['note'] = (empty($row['note']))? $lang['l_no_description'] : $row['note'];
$row['distro'] = get_distro ($row['distro']);
$row['price'] = num_format ($row['price'], 0, 1);
$row['price_msrp'] = num_format ($row['price_msrp'], 0, 1);
$txt['where_am_i'] = where_am_i ($row['cat_id']);
// call for price
if ($row['call_price'])
{
$row['price'] = $lang['l_detail_call_price'];
$row['xe_price'] = '';
}
else
$call_price = FALSE;
// BUY button
if ($row['stock'] && !$call_price)
$row['buy'] = "";
elseif ($call_price)
$row['buy'] = 'Call for Price';
else
$row['buy'] = "";
// stock
if (!$row['stock']) $row['stock'] = $lang['l_stock_empty']; else $row['stock'] = sprintf ($lang['l_stock_ready'], $row['stock']);
$txt = array_merge ($txt, $row);
$txt['main_body'] = quick_tpl (load_tpl ('detail.tpl'), $txt);
$wai = strip_tags ($txt['where_am_i']);
generate_html_header ("$wai $config[cat_separator] $row[title]", strip_tags ($row['short_note']));
flush_tpl ();
?>s interesting, in
that they were all post-dissolution projects of Icon of Coil:
Northborne, Komor Kommando, and Combichrist.






