SetRealStore($gOptions['main_real_store']); // Save Partner Jump if ( isset($_GET['partner']) ) save_partner_jump(); // Define client if ( !isset($_SESSION['client']) ) { new_client(); } // Get base shop options $gOptions = $gData->GetShopValues(''); if ($_SESSION['payment']['multiplex'] > 0) { $gOptions['main_base_curr'] = $_SESSION['payment']['curr_name']; $gOptions['main_prec'] = $_SESSION['payment']['curr_prec']; } // Make path for back make_back_path(); // Define what to do $action = $_GET['action']; if ( isset($_POST['action']) ) $action = $_POST['action']; $gConfigID = $_GET['id']*1; if ( $action == '' && $gConfigID > 0 ) $action = 'show_config'; // Save shop statistic if ( $gConfigID > 0 && $action == 'show_config' ) { save_shop_stat('config', $gConfigID); } // Action switch ( $action ) { case 'show_config' : show_config(); break; case 'define_goods' : if ( isset($_POST['config_form']) ) save_goods_config(); define_goods_how(); break; case 'from_goods' : save_from_goods(); header("Location: ./config.php?id=".$gConfigID.'&'.session_name()."=".session_id()); break; case 'save_to_basket' : save_to_basket(); header("Location: ./basket.php?".session_name()."=".session_id()); break; default : conf_tree(); } // switch // Echo page compilate time echo_page_time($gEndPoint); } /** * Function conf_tree * Print config tree **/ function conf_tree() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES); $gTpl->DefineTemplate(array('blank' => 'blank.htm', 'main' => '_config/tree/main.htm', 'unit' => '_config/tree/unit.htm', 'elem_file' => '_config/tree/elem_file.htm', 'elem_folder' => '_config/tree/elem_folder.htm', 'page_title' => '_config/tree/page_title.htm' )); $conf = $gData->GetConfTree(); $rows = $gData->GetNumRows($conf); for ( $n = 1; $n <= $rows; $n++ ) { $hash = $gData->FetchRow($conf); // common vars $gTpl->Assign(array('ID' => $hash[0], 'NAME' => htmlspecialchars($hash[1]), 'DESCR' => $hash[2], 'LEVEL' => $hash[3] )); // if folder if ( $hash[7] == 1) { $gTpl->Parse('ELEMENT', 'elem_folder'); } // if not folder else { $gTpl->Parse('ELEMENT', 'elem_file'); } $gTpl->Parse('UNIT', '.unit'); } if ( $rows == 0) { $gTpl->Assign('CONTENT', ''); } else { $gTpl->Parse('CONTENT', 'main'); } // Echo shop variables echo_shop_variables('in_techpage', true); // Additional modules use_php_mod('config'); $gTpl->Parse('PAGETITLE', 'page_title'); // Parse main page $gTpl->Parse('BLANK', 'blank'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('BLANK'); } /** * Function show_config * Print configuration **/ function show_config() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint, $gConfigID; $goods_name_max = $gOptions['main_goods_name']; $goods_descr_max = $gOptions['main_goods_descr']; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES); $gTpl->DefineTemplate(array('blank' => 'blank.htm', 'main' => '_config/step1/main.htm', 'unit' => '_config/step1/unit.htm', 'icon' => '_config/step1/icon.htm', 'option' => '_config/step1/option.htm', 'page_title' => '_config/step1/page_title.htm' )); // Get Conf params $hash_conf = $gData->GetConfig($gConfigID); // Define how goods $goods_how = array(); if ( is_array($_SESSION['config_'.$gConfigID]) ) { foreach ( $_SESSION['config_'.$gConfigID] as $goods_code) { $goods_how[$goods_code['id']] = $goods_code['how']; } } // Start conf unit $conf_unit = $gData->GetConfUnit($gConfigID); $rows = $gData->GetNumRows($conf_unit); $unit_list = ''; for ( $n = 1; $n <= $rows; $n++ ) { $hash = $gData->FetchRow($conf_unit); // Parse unit goods $unit_goods = $gData->GetConfGoods($hash[0], $hash_conf['sort_type'] == 1); $rows_unit_goods = $gData->GetNumRows($unit_goods); $gTpl->Clear('OPTION'); $gTpl->Assign('HOW', 0); $hidden = ''; for ( $i = 1; $i <= $rows_unit_goods; $i++ ) { $hash_goods = $gData->FetchRow($unit_goods); // Info currency if ( $_SESSION['payment']['multiplex']*1 > 0 ) { $price = round($hash_goods[5]*$_SESSION['payment']['multiplex']*1, 2); } else { $price = $hash_goods[5]; } $goods_name = $hash_goods[3]; if ( strlen($goods_name) > $goods_name_max && $goods_name_max > 0 ) $goods_name = substr($goods_name, 0, $goods_name_max).'...'; $gTpl->Assign(array('ID' => $hash_goods[0], 'CODE' => htmlspecialchars($hash_goods[1]), 'NAME' => htmlspecialchars($goods_name), 'MEAS' => htmlspecialchars($hash_goods[2]), 'STATUS' => $hash_goods[4], 'PRICE' => number_format($price, $gOptions['main_prec'], "," ,"'"), 'SELECT' => '' )); if ( $_SESSION['config_'.$gConfigID][$hash[0]]['id'] == $hash_goods[0] ) { $gTpl->Assign(array('SELECT' => 'Selected', 'HOW' => $goods_how[$hash_goods[0]]*1 )); } $gTpl->Parse('OPTION', '.option'); $hidden .= ''."\r\n"; } // parse conf unit vars $gTpl->Assign(array('ID' => $hash[0], 'NAME' => htmlspecialchars($hash[2]), 'DESCR' => $hash[3], 'HIDDEN' => $hidden, 'ICON' => '' )); if ( is_file('./files/conf_unit'.$hash[0].'.jpg') ) { $gTpl->Parse('ICON', 'icon'); } $gTpl->Parse('UNIT', '.unit'); $unit_list .= $hash[0].','; } if ( $rows == 0) { $gTpl->Assign('CONTENT', ''); } else { $gTpl->Assign(array('ID' => $hash_conf['id'], 'NAME' => htmlspecialchars($hash_conf['name']), 'DESCR' => $hash_conf['descr'], 'UNITLIST' => rtrim($unit_list, ',') )); $gTpl->Parse('CONTENT', 'main'); } // Echo shop variables echo_shop_variables('in_techpage', true); // Additional modules use_php_mod('config'); $gTpl->Parse('PAGETITLE', 'page_title'); // Parse main page $gTpl->Parse('BLANK', 'blank'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('BLANK'); } /** * Function save_goods_config * Save goods configuration in session **/ function save_goods_config() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint, $gConfigID; $_SESSION['config_'.$gConfigID] = array(); $conf_unit = $gData->GetConfUnit($gConfigID); $rows = $gData->GetNumRows($conf_unit); for ( $n = 1; $n <= $rows; $n++ ) { $hash = $gData->FetchRow($conf_unit); if ( $_POST['how'.$hash[0]]*1 > 0 ) { $_SESSION['config_'.$gConfigID][$hash[0]]['id'] = $_POST['conf_unit'.$hash[0]]*1; $_SESSION['config_'.$gConfigID][$hash[0]]['how'] = $_POST['how'.$hash[0]]*1; } else { unset($_SESSION['config_'.$gConfigID][$hash[0]]); } } } /** * Function save_from_goods * Save goods configuration in session from goods **/ function save_from_goods() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint, $gConfigID; // Clear current config unset($_SESSION['config_'.$gConfigID]); $_SESSION['config_'.$gConfigID] = array(); $conf_unit = $gData->GetConfUnit($gConfigID); $rows = $gData->GetNumRows($conf_unit); for ( $n = 1; $n <= $rows; $n++ ) { $hash = $gData->FetchRow($conf_unit); $unit_goods = $gData->GetConfGoods($hash[0], false); $goods = $gData->TestConfComp($_GET['goods_id']*1); if ( $goods[1] > 0 ) { $_SESSION['config_'.$gConfigID][$hash[0]]['id'] = $goods[0]; $_SESSION['config_'.$gConfigID][$hash[0]]['how'] = $goods[1]; } } } /** * Function define_goods_how * Step 2: define how goods and parameters of them **/ function define_goods_how() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint, $gConfigID; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES); $gTpl->DefineTemplate(array('blank' => 'blank.htm', 'main' => '_config/step2/main.htm', 'unit' => '_config/step2/unit.htm', 'between_row' => '_config/step2/between_row.htm', 'no_order' => '_config/step2/no_order.htm', 'order_form' => '_config/step2/order_form.htm', 'price_client' => '_config/step2/price_client.htm', 'price_new' => '_config/step2/price_new.htm', 'price_simple' => '_config/step2/price_simple.htm', 'apendix_name' => '_config/step2/apendix_name.htm', 'status0' => '_config/step2/status0.htm', 'status1' => '_config/step2/status1.htm', 'status2' => '_config/step2/status2.htm', 'status3' => '_config/step2/status3.htm', 'status4' => '_config/step2/status4.htm', 'hit' => '_config/step2/hit.htm', 'new' => '_config/step2/new.htm', 'page_title' => '_config/step2/page_title.htm' )); // Get Conf params $hash_conf = $gData->GetConfig($gConfigID); // Request goods $goods_list = ''; foreach ( $_SESSION['config_'.$gConfigID] as $goods_code) { if ( $goods_code['id'] != 0 ) $goods_list .= $goods_code['id'].','; $goods_how[$goods_code['id']] = $goods_code['how']; } $goods_list = rtrim($goods_list, ','); if ( strlen($goods_list) == 0 ) header("Location: ./config.php?id=".$gConfigID.'&'.session_name()."=".session_id()); // Start parse goods $col_cnt = 1; $ic_value = $_SESSION['payment']['multiplex']; $goods = $gData->GetConfGoodsList($goods_list); $rows_goods = $gData->GetNumRows($goods); for ( $i = 1; $i <= $rows_goods; $i++ ) { $hash = $gData->FetchRow($goods); // Calc prices list($new_price, $disc_proc, $disc_suma, $price_offer, $can_buy) = calc_goods_price($hash[0], $hash[6], $hash[11]); $price = $hash[6]; $left_sum = $price - $new_price; // Parsing parameters $gTpl->Assign('PARAM', ''); $param = $gData->GetParamGoods($hash[0]); $param_rows = $gData->GetNumRows($param); $param_base_exists = false; $param_code = ''; if ( $param_rows > 0 ) { $tpl_sub = new FastTemplate('./'.TEMPLATES.'/_config/step2/param'); $tpl_sub->DefineTemplate(array('main' => 'main.htm')); for ( $n = 1; $n <= $param_rows; $n++ ) { $hash_param = $gData->FetchRow($param); if ( $hash_param[2] == 0) { // Select value will be in pop-up window $file = 'form'; $options = ''; $values_how = ''; } else { // Select value through combobox $file = 'list'; $values = $gData->GetParamGoodsValues($hash[0], $hash_param[0], $hash[24]); $val_rows = $gData->GetNumRows($values); $options = ''; $values_how = ''; for ( $m = 1; $m <= $val_rows; $m++ ) { $hash_value = $gData->FetchRow($values); if ( strlen($hash_value[5]) > 0 ) { // Special fixed price for "real goods" or add price for "modification" if ( $hash_value[7] == 1 ) continue; if ( $hash_param[9] == 0 ) { // Phis type of param is "real goods" $add_price = round($hash_value[5]*(1-$disc_proc/100), 2) - ($disc_suma+$new_price); } else { // Phis type of param is "modification" $add_price = $hash_value[5]; $add_price = round($add_price*(1-$disc_proc/100), 2); } } else { // Price calc with proc and sum if ( $hash_param[9] == 0 ) { // Phis type of param is "real goods" $param_price = round($price*(1+$hash_value[3]/100), 2)+$hash_value[4]; $add_price = round($param_price*(1-$disc_proc/100), 2) - ($disc_suma+$new_price); } else { // Phis type of param is "modification" $add_price = round($price*$hash_value[3]/100, 2)+$hash_value[4]; $add_price = round($add_price*(1-$disc_proc/100), 2); } } $sum_price = $add_price + $new_price; $sign = ''; if ( $add_price >= 0 ) { $sign = '+'; } if ( $ic_value > 0 ) { $add_price = round($add_price*$ic_value, 2); $sum_price = round($sum_price*$ic_value, 2); } $options .= ''; $values_how .= ''; $values_how .= ''; } } $tpl_sub->ClearTpl('unit'); $tpl_sub->DefineTemplate(array('unit' => $file.'.htm')); $tpl_sub->Assign(array('NAME' => htmlspecialchars($hash_param[1]), 'STOREID' => $hash[0], 'ID' => $hash_param[0], 'GRPID' => $hash_param[9], 'GRPTYPE' => ( $hash_param[9] == 0 ) ? 'radio' : 'checkbox', 'OPTIONS' => $options, 'VALUESHOW' => $values_how, 'WINSIZE' => $hash_param[5].','.$hash_param[6].','. $hash_param[7].','.$hash_param[8] )); $param_code .= $hash_param[0].'I'; if ( $hash_param[9] == 0 ) $param_base_exists = true; $tpl_sub->Parse('UNIT', '.unit'); } $tpl_sub->Assign('PARAMCODE', $param_code); $tpl_sub->Parse('MAIN', 'main'); $gTpl->Assign('PARAM', $tpl_sub->Fetch('MAIN')); } // Parse between row if ( ($col_cnt == GOODS_COL_CNT) && ($i <> $rows_goods) ) { $gTpl->Parse('BETWEENROW', 'between_row'); $col_cnt = 1; } else { $gTpl->Assign('BETWEENROW', ''); $col_cnt += 1; } // Parse icon if ( is_file('./files/store'.$hash[0].'.jpg') ) { $img_file = 'files/store'.$hash[0].'.jpg'; } else { $img_file = 'files/store_default.jpg'; } // Parse apendix if ( is_file('./files/apendix'.$hash[0].'.htm') ) { if ( $hash[13] == 0) { $gTpl->Assign('APENDIXLINK', "href=\"javascript: ShowApendix($hash[0], $hash[15], $hash[16], $hash[17], $hash[18])\""); } else { $gTpl->Assign('APENDIXLINK', "href=\"goods.php?id=$hash[0]\""); } $gTpl->Parse('APENDIXNAME', 'apendix_name'); } else { $gTpl->Assign(array('APENDIXNAME' => '', 'APENDIXLINK' => '' )); } // Info currency if ( $ic_value > 0 ) { $price = round($price*$ic_value, 2); $new_price = round($new_price*$ic_value, 2); $left_sum = round($left_sum*$ic_value, 2); } // Price offer $gTpl->Assign(array('PRICE' => number_format($price, $gOptions['main_prec'], "," ,"'"), 'NEWPRICE' => number_format($new_price, $gOptions['main_prec'], "," ,"'"), 'LEFTSUM' => number_format($left_sum, $gOptions['main_prec'], "," ,"'"), 'CALCPRICE' => number_format($new_price, $gOptions['main_prec'], "." ,""), 'STOREID' => $hash[0] )); $gTpl->Parse('PRICEOFFER', $price_offer); // Order form if ( $hash[4] == 1 ) { $gTpl->Parse('ORDER', 'no_order'); } else { // max order goods $max_order = ( $param_base_exists ) ? '?' : $hash[24]; $start_order = $goods_how[$hash[0]]*1; if ( $start_order < $hash[9] ) $start_order = $hash[9]; $gTpl->Assign(array('CALCPRICE' => number_format($new_price, $gOptions['main_prec'], "." ,""), 'SUMA' => number_format($new_price*$start_order, $gOptions['main_prec'], "." ,""), 'STEPORDER' => $hash[8], 'MINORDER' => $hash[9], 'STARTORDER'=> $start_order, 'MAXORDER' => $max_order )); $gTpl->Parse('ORDER', 'order_form'); } // Parse status if ( $param_base_exists ) { $gTpl->Parse('STATUS', 'status4'); } else { $gTpl->Parse('STATUS', 'status'.$hash[4]); } // Echo unit $gTpl->Assign(array('CODE' => htmlspecialchars($hash[1]), 'NAME' => htmlspecialchars($hash[3]), 'NOTE' => $hash[5], 'ICON' => $img_file, 'MEAS' => htmlspecialchars($hash[2]), 'LABEL' => '', 'RANK' => ( $i == 1 ) ? '_first' : ( ( $i == $end ) ? '_last' : '' ), 'ALT' => htmlspecialchars(str_replace('{NAME}', $hash[3], $hash[26])), 'LINKTITLE' => htmlspecialchars(str_replace('{NAME}', $hash[3], $hash[25])) )); if ( $hash[22]*1 > 0 ) $gTpl->Parse('LABEL', 'new'); if ( $hash[23]*1 > 0 ) $gTpl->parse('LABEL', 'hit'); $gTpl->Parse('UNIT', '.unit'); } // Parse main page $gTpl->Assign(array('ID' => $hash_conf['id'], 'NAME' => htmlspecialchars($hash_conf['name']), 'DESCR' => $hash_conf['descr'], 'GOODSLIST' => $goods_list, 'COLSPAN' => GOODS_COL_CNT )); $gTpl->Parse('CONTENT', 'main'); // Echo shop variables echo_shop_variables('in_techpage', true); // Additional modules use_php_mod('config'); $gTpl->Parse('PAGETITLE', 'page_title'); // Parse main page $gTpl->Parse('BLANK', 'blank'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('BLANK'); } /** * Function save_to_basket * Save ordered goods to basket **/ function save_to_basket() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint; $goods_list = explode('X', rtrim($_POST['goods_list'], 'X')); $time = 0; foreach ($goods_list as $goods_code) { $goods_list = explode('&', $goods_code); $goods = array(); foreach ($goods_list as $param) { list($key, $value) = explode('=', $param); $goods[$key] = $value; } buy_goods($goods['how']*1, $goods['store_id']*1, $goods['param_value_id']*1, $goods['modify_code'], $time); $time++; } } ?>