Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Новость
- * @version $Id: NewsItemBlock.php,v 1.3 2008-01-14 15:29:46 miha Exp $
- */
- class allProducts extends Block
- {
- function renderer($catid, $id, &$data) {
- global $TPL;
- global $sBasePath;
- global $locale;
- global $DB;
- global $lang;
- global $Categories;
- $action = valid_data(parse_outside_data("action"));
- $act = (int) valid_data(parse_outside_data("act"));
- $block_id = (int) valid_data(parse_outside_data("block_id"));
- $brand_id = (int) valid_data(parse_outside_data("brand_id"));
- $model_id = (int) valid_data(parse_outside_data("model_id"));
- $product_id = (int) valid_data(parse_outside_data("product_id"));
- $ok_pr_id = (int) valid_data(parse_outside_data("ok_pr_id"));
- $limit = $data['A']['intdata'];
- if (!$limit)
- $limit = 12;
- /*$per_row = $data['C']['intdata'];
- if (!$per_row)
- */
- $per_row = 3;
- $page = (int) valid_data(parse_outside_data("offset"));
- $CatalogCategories = new CatalogCategories;
- $Brands = new Brands;
- $CatalogTypes = new CatalogCategoryTypes;
- if ((FRONTEND == 'admin') && ( (($block_id == $id ) && ($action == 'editblock' )) || ($action=='newblock')) )
- {
- $TPL->assign("editing_search_block", 1);
- $TPL->assign("editing_search_block_id", $id);
- $TPL -> assign("catalog_categories", $CatalogCategories -> categories);
- }
- else
- {
- if ($action)
- {
- switch($action)
- {
- case "add_comment":
- $errors=array();
- $user_id = (int)valid_data(parse_outside_data("user_id"));
- $name = valid_data(parse_outside_data("name"));
- if(empty($name))
- $errors[] = $CA_LANG_STR['Feedback']['err'] . sprintf($CA_LANG_STR['Feedback']['err_no_text'], $CA_LANG_STR['Comment']['name']);
- $comment = valid_data(parse_outside_data("comment"));
- if ( !strlen($comment) )
- $errors[] = $CA_LANG_STR['Feedback']['err'] . sprintf($CA_LANG_STR['Feedback']['err_no_text'], $CA_LANG_STR['Comment']['comment_text']);
- $captcha = valid_data(parse_outside_data("code_img"));
- if ( !$captcha || ($captcha != $_SESSION['code_generated_by_image']) )
- $errors[]=$CA_LANG_STR['Feedback']['err_no_captcha'];
- if(!sizeof($errors))
- {
- $comment = str_replace("\r", "", $comment);
- $comment = str_replace("\n.", "", $comment);
- $sql = "insert into ".TPREFIX."comments (name, comment, user_id, ".($model_id?"model_id":"product_id").") " .
- "values('$name', '$comment', $user_id, ".($model_id?$model_id:$product_id).")";
- $DB->execute($sql);
- $TPL->assign("SENT", 1);
- }
- if(sizeof($errors))
- {
- $TPL->assign("ERRORS", $errors);
- $TPL->assign("POST", $_POST);
- }
- unset($action);
- break;
- case "search":
- if ($act)
- {
- //$limit = 12;
- $TPL->assign("actt", 1);
- $sq = "";
- $mbrand = (int) valid_data(parse_outside_data("mbrand"));
- if ($mbrand)
- {
- $sq .= " and label_id=$mbrand ";
- $TPL -> assign("mmbrand", $mmbrand);
- }
- $mmodel = (int) valid_data(parse_outside_data("mmodel"));
- if ($mmodel)
- {
- $sq .= " and model_id=$mmodel ";
- $TPL -> assign("mmodel", $mmodel);
- }
- $yyear = (int) valid_data(parse_outside_data("yyear"));
- if ($yyear)
- {
- $sq .= " and year='$yyear' ";
- $TPL -> assign("yyear", $yyear);
- }
- $engine = (int) valid_data(parse_outside_data("engine"));
- if ($engine)
- {
- $sq .= " and engine_id=$engine ";
- $TPL -> assign("engine", $engine);
- }
- $sql = "select * from ".TPREFIX."auto_records where category_id=".$data['B']['intdata']." $sq";
- echo "<h1 style='color: blue;'>$sql</h1>";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $records[]=$res->fields;
- if ($i < ($res->getNumOfRows()-1))
- $ss .= $records[$i]['id'].", ";
- else
- $ss .= $records[$i]['id'];
- $res->nextRow();
- }
- $sql = "select * from ".TPREFIX."auto_record_characteristics where record_id in ($ss)";
- echo "<h1 style='color: pink;'>$sql</h1>";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $recs[$res->fields['record_id']][]=$res->fields;
- $res->nextRow();
- }
- $sql="";
- $i=0;
- if (count($recs))
- {
- $real_sql = "select distinct characteristic_id, value, m_p_id from ".TPREFIX."mp_characteristic_values where model_product='p' and (";
- foreach($recs as $key=>$val)
- {
- for($j=0;$j<count($val);$j++)
- {
- if ($i || $j)
- $sql .= " or ";
- $sql .= " (characteristic_id = ".$val[$j]['characteristic_id'] . " and value = '".$val[$j]['value'] . "') ";
- }
- //$sql .= ")";
- $i++;
- }
- $real_sql .= $sql.")";
- $res = $DB -> execute($real_sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $p_ids[$res->fields['m_p_id']][$res->fields['characteristic_id']]= $res->fields['value'];
- $res->nextRow();
- }
- if (count($p_ids))
- {
- foreach($p_ids as $pid=>$pval)
- {
- foreach($recs as $key=>$val)
- {
- $a = 1;
- if (count($val))
- {
- foreach($val as $k=>$v)
- {
- echo "tovar $pid: char=".$v['characteristic_id']."; it value=".$pval[$v['characteristic_id']]." = need value=".$v['value']."<br>";
- if ($pval[$v['characteristic_id']]!=$v['value'])
- {
- $a = 0;
- break;
- }
- else
- echo "<b>oki</b><br>";
- }
- if ($a)
- {
- if (!$ok[$pid])
- $product_ids[] = $pid;
- $ok[$pid]=1;
- }
- }
- }
- }
- }
- }
- }
- $categ = $CatalogCategories -> categories_by_id[$data['B']['intdata']];
- $cat_type = $CatalogTypes -> types_by_id[$categ['category_type']];
- $char = $_POST['char'];
- $brand = $_POST['brand'];
- if (!$act)
- {
- if (count($char))
- {
- $c_sql = "";
- $i = 0;
- foreach($_POST['char'] as $key => $vall)
- {
- if ($vall)
- $ch[$key] = trim($vall);
- }
- echo "<h2>";
- print_r($ch);
- echo "</h2>";
- if (count($ch))
- {
- foreach($ch as $key => $val)
- {
- if ($i < (count($ch) -1))
- {
- $c_sql .= "((characteristic_id = $key) and (value='$val')) or ";
- $ccc_sql .= "$key, ";
- }
- else
- {
- $c_sql .= "((characteristic_id = $key) and (value='$val')) ";
- $ccc_sql .= "$key";
- }
- $i++;
- }
- $rrr = "select model_product from ".TPREFIX."characteristics where id in ($ccc_sql)";
- $res = $DB -> execute($rrr);
- for($i=0; $i<$res -> getNumOfRows(); $i++)
- {
- if ($res -> fields['model_product'] == 'm')
- {
- $model_chars_in_all = 1;
- echo "<h1 style='color: viol;'>proverili! est modeli</h1>";
- }
- if ($res -> fields['model_product'] == 'p')
- {
- $product_chars_in_all = 1;
- echo "<h1 style='color: viol;'>proverili! est</h1>";
- }
- $res->nextRow();
- }
- if (!$model_chars_in_all)
- echo "<h1 style='color: viol;'>proverili! net</h1>";
- $sql = "select distinct m_p_id, model_product, characteristic_id from ".TPREFIX."mp_characteristic_values where $c_sql";
- echo "<br><br><br><i>".$sql."</i><br><br><br>";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res -> getNumOfRows();$i++)
- {
- if ($res->fields['model_product'] == 'm')
- {
- if (!$m_ok[$res->fields['characteristic_id']])
- $m_cs[] = $res->fields['characteristic_id'];
- $m_ok[$res->fields['characteristic_id']][$res->fields['m_p_id']] = 1;
- if (!$am[$res->fields['m_p_id']])
- $mmodels[] = $res->fields['m_p_id'];
- $am[$res->fields['m_p_id']]=1;
- echo "<h2>opa!!!! mi kak-to siuda popali!</h2>";
- //$models[] = $res->fields['m_p_id'];
- }
- else
- {
- if (!$p_ok[$res->fields['characteristic_id']])
- $p_cs[] = $res->fields['characteristic_id'];
- $p_ok[$res->fields['characteristic_id']][$res->fields['m_p_id']] = 1;
- if (!$ap[$res->fields['m_p_id']])
- $pproduct_ids[] = $res->fields['m_p_id'];
- $ap[$res->fields['m_p_id']]=1;
- //$product_ids[] = $res->fields['m_p_id'];
- //$aa[$res->fields['m_p_id']]=1;
- }
- $res->nextRow();
- }
- print_r($mmodels);
- if (count($m_cs) && count($mmodels))
- {
- for($i=0;$i<count($mmodels);$i++)
- {
- $a = 1;
- for($j=0;$j<count($m_cs);$j++)
- {
- if (!$m_ok[ $m_cs[$j] ][ $mmodels[$i] ])
- $a = 0;
- }
- if ($a)
- $models[] = $mmodels[$i];
- }
- }
- echo "<h1 style='color: green'>models === ";
- print_r($models);
- echo "</h1>";
- if (count($p_cs) && count($pproduct_ids))
- {
- for($i=0;$i<count($pproduct_ids);$i++)
- {
- $a = 1;
- for($j=0;$j<count($p_cs);$j++)
- {
- if (!$p_ok[ $p_cs[$j] ][ $pproduct_ids[$i] ])
- $a = 0;
- else
- echo "<br> ok: ".$p_cs[$j]." pid: ".$pproduct_ids[$i]."<br><br><br>";
- }
- if ($a)
- {
- $product_ids[] = $pproduct_ids[$i];
- $aa[$pproduct_ids[$i]] = 1;
- }
- }
- }
- echo "<h1 style='color: pink'>";
- print_r($aa);
- echo "</h1>";
- if (count($models) && $model_chars_in_all)
- {
- echo "<h1 style='color: blue;'>kakie-to models</h1>";
- for($i=0;$i<count($models);$i++)
- {
- if ($i<(count($models)-1))
- $m_sql .= $models[$i].", ";
- else
- $m_sql .= $models[$i];
- }
- $model_sql = "select id from ".TPREFIX."products where model_id in($m_sql)";
- $res = $DB -> execute($model_sql);
- for($i=0;$i<$res -> getNumOfRows();$i++)
- {
- if (($aa[$res->fields['id']]) || !$product_chars_in_all)
- {
- $pppps[] = $res->fields['id'];
- $aappps[$res->fields['id']]=1;
- }
- $res->nextRow();
- }
- $product_ids = $pppps;
- $aa = $aappps;
- }
- if ($model_chars_in_all && !(count($models)))
- {
- $product_ids = 0;
- $aa = 0;
- }
- }
- }
- if ($brand)
- {
- $sql = "select id from ".TPREFIX."products where brand_id=$brand";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res -> getNumOfRows();$i++)
- {
- if (!$ch || $aa[$res->fields['id']])
- {
- $p_ids[] = $res->fields['id'];
- echo "<p color='viol'>added</p>";
- }
- $res->nextRow();
- }
- $product_ids = $p_ids;
- }
- }
- if (!$ch && !$brand && !$act)
- unset($action);
- else
- {
- print_r($product_ids);
- echo "</b>fin<br><br><br>";
- for($i=0;$i<count($product_ids);$i++)
- {
- if ($i<(count($product_ids)-1))
- $mm_sql .= $product_ids[$i].", ";
- else
- $mm_sql .= $product_ids[$i];
- }
- $sql = "select * from ".TPREFIX."products where id in ($mm_sql) order by model_id, brand_id, name";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $products[] = $res->fields;
- $ps[ $res->fields['id'] ] = $res->fields['model_id'];
- if (!$mmm[$res->fields['model_id']])
- {
- $models[] = $res->fields['model_id'];
- $mmm[$res->fields['model_id']] = 1;
- }
- $res -> nextRow();
- }
- $Models = new Models;
- //$limit = 12;
- $counter = count($products);
- if ($counter)
- {
- $pg_q = ceil($counter / $limit);
- for($i=0;$i<$pg_q;$i++)
- $pager[$i] = $i+1;
- $TPL->assign("op", 1);
- if (count($pager) > 1)
- {
- $TPL->assign("pager", $pager);
- }
- $TPL->assign("ch", $ch);
- $TPL->assign("brand", $brand);
- if (!$page || ($page < 0))
- $page = 0;
- if ($page > $pg_q-1)
- $page = $pg_q-1;
- $TPL->assign("page", $page);
- $start = $page * $limit;
- $end = $start+$limit;
- if ($end > count($products))
- $end = count($products);
- }
- for($i=$start;$i<$end;$i++)
- {
- $model = $Models -> models_by_id[$products[$i]['model_id']];
- $model['brand_name'] = $Brands -> brands_by_id[$model['brand_id']]['name'];
- $model['cat_name'] = $CatalogCategories -> categories_by_id[$cat_type['id']]['name'];
- //$model['image'] = str_replace("_small.", "_middle.", $model['image']);
- $model['p_name'] = $products[$i]['name'];
- $model['p_id'] = $products[$i]['id'];
- $sql = "SELECT `c`.`name`as`name`,`a`.`value`as`value` FROM `".TPREFIX."mp_characteristic_values`as`a` LEFT JOIN `".TPREFIX."products`as`b` ON `b`.`id`=`a`.`m_p_id` LEFT JOIN `".TPREFIX."characteristics`as`c` ON `a`.`characteristic_id`=`c`.`id` WHERE `a`.`m_p_id`='".$model['p_id']."' AND `c`.`id`=8";
- $res = $DB -> execute($sql);
- $model['season'] = is_null($res->fields)?array('name'=>'Сезонность', 'value'=>1):$res->fields;
- if($model['season']['value'] == 1) $model['season']['value'] = "<img src=\"/imgseasons/1/image.gif\" alt=\"летняя\">";
- elseif((int)$model['season']['value'] == 2) $model['season']['value'] = "<img src=\"/imgseasons/2/image.gif\" alt=\"зимняя\">";
- elseif((int)$model['season']['value'] == 3) $model['season']['value'] = "<img src=\"/imgseasons/3/image.gif\" alt=\"всесезонная\">";
- else $model['season']['value'] = "<img src=\"/imgseasons/1/image.gif\" alt=\"летняя\">";
- if ($products[$i]['act'] || $products[$i]['raspr'])
- {
- $aa = $products[$i]['price_opt'];
- $bb = $products[$i]['raspr_price'];
- if ($products[$i]['act'] && $products[$i]['raspr'])
- {
- if (!$aa && !$bb)
- $opp = $products[$i]['price'];
- elseif(!$aa && $bb)
- $opp = $bb;
- elseif(!$bb && $aa)
- $opp = $aa;
- else
- $opp = (($aa <= $bb) ? $aa : $bb);
- }
- elseif ($products[$i]['act'] && !$products[$i]['raspr'])
- $opp = $aa;
- elseif (!$products[$i]['act'] && $products[$i]['raspr'])
- $opp = $bb;
- $products[$i]['act'] = 1;
- $products[$i]['price_opt'] = $opp;
- }
- $model['prr'] = $products[$i];
- $pmm[] = $model;
- }
- $TPL -> assign("models", $pmm);
- $TPL -> assign("show_models", 1);
- }
- break;
- case "show_p_se":
- $categ = $CatalogCategories -> categories_by_id[$data['B']['intdata']];
- $cat_type = $CatalogTypes -> types_by_id[$categ['category_type']];
- $page = (int) valid_data(parse_outside_data("offset"));
- $TPL -> assign("page", $page);
- $TPL->assign("op", 1);
- if ($act)
- {
- $TPL->assign("actt", 1);
- $mbrand = (int) valid_data(parse_outside_data("mbrand"));
- if ($mbrand)
- $TPL -> assign("mmbrand", $mmbrand);
- $mmodel = (int) valid_data(parse_outside_data("mmodel"));
- if ($mmodel)
- $TPL -> assign("mmodel", $mmodel);
- $yyear = (int) valid_data(parse_outside_data("yyear"));
- if ($yyear)
- $TPL -> assign("yyear", $yyear);
- $engine = (int) valid_data(parse_outside_data("engine"));
- if ($engine)
- $TPL -> assign("engine", $engine);
- }
- $char = $_POST['char'];
- $brand = $_POST['brand'];
- if (!$act)
- {
- if (count($char))
- {
- $i = 0;
- foreach($_POST['char'] as $key => $vall)
- {
- if ($vall)
- $ch[$key] = trim($vall);
- }
- }
- $TPL->assign("ch", $ch);
- $TPL->assign("brand", $brand);
- }
- if ($ok_pr_id)
- {
- $TPL -> assign("one_product", 1);
- $bb = "select model_id from ".TPREFIX."products where id=$ok_pr_id";
- echo "<h1 style='color: blue;'>$bb</h1>";
- $res = $DB->execute($bb);
- $model_id = $res->fields['model_id'];
- $TPL->assign("only_product_to_show", $ok_pr_id);
- }
- if($model_id)
- {
- $TPL -> assign("chmme", 1);
- $TPL -> assign("one_model", 1);
- $Models = new Models;
- echo "<h1>mur mur mur</h1>";
- $model = $Models -> models_by_id[$model_id];
- $model['brand_name'] = $Brands -> brands_by_id[$model['brand_id']]['name'];
- $model['show_f_p_ch'] = $cat_type['show_f_p_ch'];
- if ($model['image'])
- {
- $model['image'] = str_replace("_small.", ".", $model['image']);
- $model['image_big2'] = str_replace(".", "_biggest.", $model['image']);
- }
- $res = $DB -> execute("select count(id) as counter from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")."");
- $counter = $res -> fields['counter'];
- if ($counter)
- {
- $llimit = 10;
- $page_num = ceil($counter / $llimit);
- if ( (!$page) || ($page < 0))
- $page = 0;
- if ($page > $page_num - 1)
- $page = $page_num - 1;
- $TPL -> assign("current_page", $page);
- for($i=0; $i < $page_num;$i++)
- $pager[$i] = $i+1;
- if (count($pager)>1)
- $TPL -> assign("pager", $pager);
- $start = $page * $llimit;
- $sql = "select *, DATE_FORMAT(dt, 'd.m.Y') as dt2 from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")." order by dt desc LIMIT $start, $llimit";
- echo "<h1 style='color: green;'>$sql</h1>";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $comments[] = $res->fields;
- $res -> nextRow();
- }
- $TPL->assign("comments", $comments);
- }
- $cat_names = $Categories->get_cat_path_view(& $catid);
- for($i=0;$i<count($cat_names);$i++)
- $cat_names[$i]['last']=0;
- $cat_names[]=array("name"=>$model['brand_name'], "cat"=>$catid."/brand".$model['brand_id'], "last"=>0);
- $cat_names[]=array("name"=>$model['name'], "cat"=>$catid."/model".$model['id'], "last"=>($ok_pr_id?0:1));
- /*
- $cat_names[]=array("name"=>"Результаты поиска", "cat"=>"javascript: document.forms.search_products_back.submit();", "last"=>0, "js" => 1);
- */
- $titl = $Categories->records[$catid]['name']." ".$model['brand_name']." ".$model['name'];
- $TPL -> assign("TITLE", $titl);
- $TPL -> assign("KEYWORDS", $titl);
- $TPL -> assign("DESCRIPTION", $titl);
- $res = $DB->execute("select * from ".TPREFIX."products where model_id=$model_id order by name");
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $products[] = $res->fields;
- $products_by_id[$res->fields['id']] = $res->fields['name'];
- if ( $i < ($res->getNumOfRows())-1 )
- $p_ids .= $res->fields['id'].", ";
- else
- $p_ids .= $res->fields['id'];
- $res->nextRow();
- }
- $sql = "select * from ".TPREFIX."characteristics where cat_type_id=".$cat_type['id']." order by prio";
- echo "<h1 style='color: green;'>$sql</h1>";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfrows();$i++)
- {
- if ($res->fields['model_product'] == 'm')
- $m_chs[] = $res->fields;
- else
- {
- $p_chs[] = $res->fields;
- $p_chs_by_id[$res->fields['id']] = $res->fields;
- }
- if ( $i < ($res->getNumOfRows())-1 )
- $m_q .= $res->fields['id'].", ";
- else
- $m_q .= $res->fields['id'];
- $res->nextRow();
- }
- $sql = "select * from ".TPREFIX."mp_characteristic_values where characteristic_id in ($m_q) and ( ( (model_product='m') AND (m_p_id=$model_id)) OR ( (model_product='p') AND (m_p_id in ($p_ids)) ))";
- $res = $DB->execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- if ($res->fields['model_product']=='m')
- $mcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
- else
- {
- $pcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
- $pcv2[$res->fields['characteristic_id']][$res->fields['m_p_id']] = $res->fields['value'];
- }
- $res->nextRow();
- }
- for($i=0;$i<count($m_chs);$i++)
- {
- $cc = new Characteristic($m_chs[$i]['id'], $m_chs[$i]);
- $m_chs[$i]['html'] = $cc -> show_public_val($mcv[$model_id][$m_chs[$i]['id']]);
- }
- if (count($pcv2))
- {
- for($i=0;$i<count($p_chs);$i++)
- {
- $key = $p_chs[$i]['id'];
- $val = $pcv2[$key];
- if ($val)
- {
- $cc = new Characteristic($key, $p_chs_by_id[$key]);
- if (count($val))
- {
- foreach($val as $k => $v)
- {
- if ($cc -> data['show_inside'])
- $chs_by_products[$k][] = array("name" => $cc->data['name'], "html" => $cc -> show_public_val($v));
- }
- }
- }
- }
- }
- for($i=0;$i<count($products);$i++)
- {
- if ($_SESSION['p_array'][$products[$i]['id']])
- $products[$i]['qqq'] = $_SESSION['p_array'][$products[$i]['id']];
- $products[$i]['characteristics'] = $chs_by_products[$products[$i]['id']];
- }
- if ($ok_pr_id)
- {
- $cat_names[]=array("name"=>$products_by_id[$ok_pr_id], "cat"=>$catid."/product".$ok_pr_id, "last"=>1);
- if ($titl)
- $titl .= " " . $products_by_id[$ok_pr_id]['name'];
- else
- $titl .= $products_by_id[$ok_pr_id]['name'];
- $TPL -> assign("TITLE", $titl);
- $TPL -> assign("KEYWORDS", $titl);
- $TPL -> assign("DESCRIPTION", $titl);
- }
- $TPL->assign('CAT_PATH', $cat_names);
- $model['characteristics'] = $m_chs;
- $TPL->assign("ccount", ( count($m_chs) + count($products[0]['characteristics']) + 3 ) );
- $TPL -> assign("MODEL", $model);
- for($i=0;$i<count($products);$i++)
- {
- if ($products[$i]['act'] || $products[$i]['raspr'])
- {
- $aa = $products[$i]['price_opt'];
- $bb = $products[$i]['raspr_price'];
- if ($products[$i]['act'] && $products[$i]['raspr'])
- {
- if (!$aa && !$bb)
- $op = $products[$i]['price'];
- elseif(!$aa && $bb)
- $op = $bb;
- elseif(!$bb && $aa)
- $op = $aa;
- else
- $op = (($aa <= $bb) ? $aa : $bb);
- }
- elseif ($products[$i]['act'] && !$products[$i]['raspr'])
- $op = $aa;
- elseif (!$products[$i]['act'] && $products[$i]['raspr'])
- $op = $bb;
- $products[$i]['act'] = 1;
- $products[$i]['price_opt'] = $op;
- }
- }
- $TPL -> assign("products", $products);
- }
- break;
- default:
- unset($action);
- break;
- }
- }
- if (!$action)
- {
- $categ = $CatalogCategories -> categories_by_id[$data['B']['intdata']];
- $cat_type = $CatalogTypes -> types_by_id[$categ['category_type']];
- if ($cat_type['choose_model'])
- {
- $TPL -> assign("chmme", 1);
- echo "puh!";
- if ($brand_id || $model_id || $product_id)
- {
- if ($product_id)
- {
- $TPL -> assign("one_product", 1);
- $res = $DB->execute("select model_id from ".TPREFIX."products where id=$product_id");
- $model_id = $res->fields['model_id'];
- $TPL->assign("only_product_to_show", $product_id);
- }
- if($model_id)
- {
- $TPL -> assign("one_model", 1);
- $Models = new Models;
- $model = $Models -> models_by_id[$model_id];
- $model['brand_name'] = $Brands -> brands_by_id[$model['brand_id']]['name'];
- $model['show_f_p_ch'] = $cat_type['show_f_p_ch'];
- if ($model['image'])
- {
- $model['image'] = str_replace("_small.", ".", $model['image']);
- $model['image_big2'] = str_replace(".", "_biggest.", $model['image']);
- }
- $res = $DB -> execute("select count(id) as counter from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")."");
- $counter = $res -> fields['counter'];
- if ($counter)
- {
- $llimit = 10;
- $page_num = ceil($counter / $llimit);
- if ( (!$page) || ($page < 0))
- $page = 0;
- if ($page > $page_num - 1)
- $page = $page_num - 1;
- $TPL -> assign("current_page", $page);
- for($i=0; $i < $page_num;$i++)
- $pager[$i] = $i+1;
- if (count($pager)>1)
- $TPL -> assign("pager", $pager);
- $start = $page * $llimit;
- $sql = "select *, DATE_FORMAT(dt, 'd.m.Y') as dt2 from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")." order by dt desc LIMIT $start, $llimit";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $comments[] = $res->fields;
- $res -> nextRow();
- }
- $TPL->assign("comments", $comments);
- }
- $cat_names = $Categories->get_cat_path_view(& $catid);
- for($i=0;$i<count($cat_names);$i++)
- $cat_names[$i]['last']=0;
- $cat_names[]=array("name"=>$model['brand_name'], "cat"=>$catid."/brand".$model['brand_id'], "last"=>0);
- $cat_names[]=array("name"=>$model['name'], "cat"=>$catid."/model".$model['id'], "last"=>($product_id?0:1));
- $titl = $Categories->records[$catid]['name']." ".$model['brand_name']." ".$model['name'];
- $TPL -> assign("TITLE", $titl);
- $TPL -> assign("KEYWORDS", $titl);
- $TPL -> assign("DESCRIPTION", $titl);
- $res = $DB->execute("select * from ".TPREFIX."products where model_id=$model_id order by name");
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $products[] = $res->fields;
- $products_by_id[$res->fields['id']] = $res->fields['name'];
- if ( $i < ($res->getNumOfRows())-1 )
- $p_ids .= $res->fields['id'].", ";
- else
- $p_ids .= $res->fields['id'];
- $res->nextRow();
- }
- $sql = "select * from ".TPREFIX."characteristics where cat_type_id=".$cat_type['id'];
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfrows();$i++)
- {
- if ($res->fields['model_product'] == 'm')
- $m_chs[] = $res->fields;
- else
- {
- $p_chs[] = $res->fields;
- $p_chs_by_id[$res->fields['id']] = $res->fields;
- }
- if ( $i < ($res->getNumOfRows())-1 )
- $m_q .= $res->fields['id'].", ";
- else
- $m_q .= $res->fields['id'];
- $res->nextRow();
- }
- $sql = "select * from ".TPREFIX."mp_characteristic_values where characteristic_id in ($m_q) and ( ( (model_product='m') AND (m_p_id=$model_id)) OR ( (model_product='p') AND (m_p_id in ($p_ids)) ))";
- $res = $DB->execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- if ($res->fields['model_product']=='m')
- $mcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
- else
- {
- $pcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
- $pcv2[$res->fields['characteristic_id']][$res->fields['m_p_id']] = $res->fields['value'];
- }
- $res->nextRow();
- }
- for($i=0;$i<count($m_chs);$i++)
- {
- $cc = new Characteristic($m_chs[$i]['id'], $m_chs[$i]);
- $m_chs[$i]['html'] = $cc -> show_public_val($mcv[$model_id][$m_chs[$i]['id']]);
- }
- if (count($pcv2))
- {
- foreach($pcv2 as $key=>$val)
- {
- $cc = new Characteristic($key, $p_chs_by_id[$key]);
- if (count($val))
- {
- foreach($val as $k => $v)
- {
- if ($cc -> data['show_inside'])
- $chs_by_products[$k][] = array("name" => $cc->data['name'], "html" => $cc -> show_public_val($v));
- }
- }
- }
- }
- for($i=0;$i<count($products);$i++)
- {
- if ($_SESSION['p_array'][$products[$i]['id']])
- $products[$i]['qqq'] = $_SESSION['p_array'][$products[$i]['id']];
- $products[$i]['characteristics'] = $chs_by_products[$products[$i]['id']];
- }
- if ($product_id)
- {
- $cat_names[]=array("name"=>$products_by_id[$product_id], "cat"=>$catid."/product".$product_id, "last"=>1);
- if ($titl)
- $titl .= " " . $products_by_id[$product_id]['name'];
- else
- $titl .= $products_by_id[$product_id]['name'];
- $TPL -> assign("TITLE", $titl);
- $TPL -> assign("KEYWORDS", $titl);
- $TPL -> assign("DESCRIPTION", $titl);
- }
- $TPL->assign('CAT_PATH', $cat_names);
- $model['characteristics'] = $m_chs;
- $TPL->assign("ccount", ( count($m_chs) + count($products[0]['characteristics']) + 3 ) );
- $TPL -> assign("MODEL", $model);
- for($i=0;$i<count($products);$i++)
- {
- if ($products[$i]['act'] || $products[$i]['raspr'])
- {
- $aa = $products[$i]['price_opt'];
- $bb = $products[$i]['raspr_price'];
- if ($products[$i]['act'] && $products[$i]['raspr'])
- {
- if (!$aa && !$bb)
- $op = $products[$i]['price'];
- elseif(!$aa && $bb)
- $op = $bb;
- elseif(!$bb && $aa)
- $op = $aa;
- else
- $op = (($aa <= $bb) ? $aa : $bb);
- }
- elseif ($products[$i]['act'] && !$products[$i]['raspr'])
- $op = $aa;
- elseif (!$products[$i]['act'] && $products[$i]['raspr'])
- $op = $bb;
- $products[$i]['act'] = 1;
- $products[$i]['price_opt'] = $op;
- }
- }
- $TPL -> assign("products", $products);
- }
- elseif ($brand_id)
- {
- //$limit=12;
- $TPL -> assign("show_models", 1);
- $TPL -> assign("brand_id", $brand_id);
- $Models = new Models;
- if (!$Brands)
- $Brands = new Brands;
- //$models = $Models -> models_by_brand[$brand_id];
- $counter = count($Models -> models_by_brand[$brand_id]);
- $cat_names = $Categories->get_cat_path_view(& $catid);
- for($i=0;$i<count($cat_names);$i++)
- $cat_names[$i]['last']=0;
- $cat_names[]=array("name"=>$Brands -> brands_by_id[$brand_id]['name'], "cat"=>$catid."/brand".$brand_id, "last"=>1);
- $TPL->assign('CAT_PATH', $cat_names);
- $titl = $Categories->records[$catid]['name']." ".$Brands -> brands_by_id[$brand_id]['name'];
- $TPL -> assign("TITLE", $titl);
- $TPL -> assign("KEYWORDS", $titl);
- $TPL -> assign("DESCRIPTION", $titl);
- if ($counter)
- {
- $pg_q = ceil($counter / $limit);
- for($i=0;$i<$pg_q;$i++)
- $pager[$i] = $i+1;
- if (count($pager) > 1)
- $TPL->assign("pager", $pager);
- if (!$page || ($page < 0))
- $page = 0;
- if ($page > $pg_q-1)
- $page = $pg_q-1;
- $TPL->assign("page", $page);
- $start = $page * $limit;
- $end = $start+$limit;
- if ($end > count($Models -> models_by_brand[$brand_id]))
- $end = count($Models -> models_by_brand[$brand_id]);
- }
- $i=0;
- for($j=$start;$j<$end;$j++)
- {
- $models[$i] = $Models -> models_by_brand[$brand_id][$j];
- $models[$i]['cat_name'] = $CatalogCategories -> categories_by_id[$cat_type['id']]['name'];
- $models[$i]['brand_name'] = $Brands -> brands_by_id[$brand_id]['name'];
- $models[$i]['image'] = str_replace("_small.", "_middle.", $models[$i]['image']);
- $i++;
- }
- $TPL -> assign("models", $models);
- }
- else
- {
- unset($brand_id);
- unset($model_id);
- unset($product_id);
- }
- }
- if (!$brand_id && !$model_id && !$product_id)
- {
- $brands = $Brands -> brands_by_category[$categ['id']];
- for($i=0;$i<count($brands);$i++)
- {
- $brands[$i]['logo'] = str_replace("/".$brands[$i]['id']."/","/preview/".$brands[$i]['id']."/",$brands[$i]['logo']);
- }
- $TPL -> assign("brands", $brands);
- $TPL -> assign("show_brands", 1);
- }
- }
- else
- {
- //echo "<font style='color: red;font-size: 36px;'>".$cat_type['choose_model']."</font>";
- $TPL -> assign("no_model", 1);
- if (!$product_id)
- {
- $TPL -> assign("show_products", 1);
- $sql = "select count(id) as counter from ".TPREFIX."products where category_id=".$data['B']['intdata'];
- $res = $DB -> execute($sql);
- $counter = $res->fields['counter'];
- if ($counter)
- {
- $pg_q = ceil($counter / $limit);
- for($i=0;$i<$pg_q;$i++)
- $pager[$i] = $i+1;
- if (count($pager) > 1)
- $TPL->assign("pager", $pager);
- if (!$page || ($page < 0))
- $page = 0;
- if ($page > $pg_q-1)
- $page = $pg_q-1;
- $TPL->assign("page", $page);
- $start = $page * $limit;
- $sql = "select * from ".TPREFIX."products where category_id=".$data['B']['intdata']." order by id desc LIMIT $start, $limit";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $products[] = $res->fields;
- $res -> nextRow();
- }
- for($i=0;$i<count($products);$i++)
- {
- if ($products[$i]['act'] || $products[$i]['raspr'])
- {
- $aa = $products[$i]['price_opt'];
- $bb = $products[$i]['raspr_price'];
- if ($products[$i]['act'] && $products[$i]['raspr'])
- {
- if (!$aa && !$bb)
- $op = $products[$i]['price'];
- elseif(!$aa && $bb)
- $op = $bb;
- elseif(!$bb && $aa)
- $op = $aa;
- else
- $op = (($aa <= $bb) ? $aa : $bb);
- }
- elseif ($products[$i]['act'] && !$products[$i]['raspr'])
- $op = $aa;
- elseif (!$products[$i]['act'] && $products[$i]['raspr'])
- $op = $bb;
- $products[$i]['price_opt'] = $op;
- $products[$i]['act'] = 1;
- }
- }
- $TPL->assign("products", $products);
- }
- }
- else
- {
- $cat_names = $Categories->get_cat_path_view(& $catid);
- for($i=0;$i<count($cat_names);$i++)
- $cat_names[$i]['last']=0;
- $TPL -> assign("one_product", 1);
- $res = $DB->execute("select * from ".TPREFIX."products where id=$product_id");
- $product = $res->fields;
- if ($product['act'] || $product['raspr'])
- {
- $aa = $product['price_opt'];
- $bb = $product['raspr_price'];
- if ($product['act'] && $product['raspr'])
- {
- if (!$aa && !$bb)
- $op = $product['price'];
- elseif(!$aa && $bb)
- $op = $bb;
- elseif(!$bb && $aa)
- $op = $aa;
- else
- $op = (($aa <= $bb) ? $aa : $bb);
- }
- elseif ($product['act'] && !$product['raspr'])
- $op = $aa;
- elseif (!$product['act'] && $product['raspr'])
- $op = $bb;
- $product['act'] = 1;
- $product['price_opt'] = $op;
- }
- $res = $DB -> execute("select count(id) as counter from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")."");
- $counter = $res -> fields['counter'];
- if ($counter)
- {
- $llimit = 10;
- $page_num = ceil($counter / $llimit);
- if ( (!$page) || ($page < 0))
- $page = 0;
- if ($page > $page_num - 1)
- $page = $page_num - 1;
- $TPL -> assign("current_page", $page);
- for($i=0; $i < $page_num;$i++)
- $pager[$i] = $i+1;
- if (count($pager)>1)
- $TPL -> assign("pager", $pager);
- $start = $page * $llimit;
- $sql = "select *, DATE_FORMAT(dt, 'd.m.Y') as dt2 from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")." order by dt desc LIMIT $start, $llimit";
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $comments[] = $res->fields;
- $res -> nextRow();
- }
- $TPL->assign("comments", $comments);
- }
- $cat_names[]=array("name"=>$product['name'], "cat"=>$catid."/product".$product_id, "last"=>1);
- $TPL->assign('CAT_PATH', $cat_names);
- $titl = $Categories->records[$catid]['name']." ".$product['name'];
- $TPL -> assign("TITLE", $titl);
- $TPL -> assign("KEYWORDS", $titl);
- $TPL -> assign("DESCRIPTION", $titl);
- $sql = "select * from ".TPREFIX."characteristics where cat_type_id=".$CatalogCategories->categories_by_id[$product['category_id']]['category_type'];
- $res = $DB -> execute($sql);
- for($i=0;$i<$res->getNumOfrows();$i++)
- {
- $p_chs[] = $res->fields;
- $p_chs_by_id[$res->fields['id']] = $res->fields;
- $res->nextRow();
- }
- $sql = "select * from ".TPREFIX."mp_characteristic_values where model_product='p' AND m_p_id = ".$product['id'];
- $res = $DB->execute($sql);
- for($i=0;$i<$res->getNumOfRows();$i++)
- {
- $pcv[$res->fields['characteristic_id']] = $res->fields['value'];
- $res->nextRow();
- }
- if (count($pcv))
- {
- foreach($pcv as $key=>$val)
- {
- $cc = new Characteristic($key, $p_chs_by_id[$key]);
- $just_chas[] = array("name" => $cc->data['name'], "html" => $cc -> show_public_val($val));
- }
- }
- if (count($just_chas))
- {
- $TPL->assign("width", ceil(100 / count($just_chas)));
- $product['characteristics'] = $just_chas;
- }
- if ($product['image'])
- $product['image_big2'] = str_replace("_small.", "_biggest.", $product['image']);
- $TPL -> assign("product", $product);
- }
- }
- }
- }
- }
- function updater(&$data)
- {
- $p_type = $_POST['p_type'];
- $green = $_POST['green'];
- if ($green)
- $data['green'] = 1;
- else
- $data['green'] = 0;
- switch($p_type)
- {
- case "new":
- $data['new'] = 1;
- break;
- case "leader":
- $data['leader'] = 1;
- break;
- case "act":
- $data['act'] = 1;
- break;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement