Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 40.77 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Новость
  4.  * @version $Id: NewsItemBlock.php,v 1.3 2008-01-14 15:29:46 miha Exp $
  5.  */
  6. class allProducts extends Block
  7. {
  8.     function renderer($catid, $id, &$data) {
  9.         global $TPL;
  10.         global $sBasePath;
  11.         global $locale;
  12.         global $DB;
  13.         global $lang;
  14.         global $Categories;
  15.        
  16.        
  17.         $action = valid_data(parse_outside_data("action"));
  18.         $act = (int) valid_data(parse_outside_data("act"));
  19.         $block_id = (int) valid_data(parse_outside_data("block_id"));
  20.        
  21.         $brand_id = (int) valid_data(parse_outside_data("brand_id"));
  22.         $model_id = (int) valid_data(parse_outside_data("model_id"));
  23.         $product_id = (int) valid_data(parse_outside_data("product_id"));
  24.        
  25.         $ok_pr_id = (int) valid_data(parse_outside_data("ok_pr_id"));
  26.  
  27.         $limit = $data['A']['intdata'];
  28.        
  29.         if (!$limit)
  30.             $limit = 12;
  31.        
  32.         /*$per_row = $data['C']['intdata'];
  33.         if (!$per_row)
  34.         */
  35.             $per_row = 3;
  36.            
  37.         $page = (int) valid_data(parse_outside_data("offset"));
  38.        
  39.         $CatalogCategories = new CatalogCategories;
  40.         $Brands = new Brands;
  41.         $CatalogTypes = new CatalogCategoryTypes;
  42.        
  43.         if ((FRONTEND == 'admin') && ( (($block_id == $id ) && ($action == 'editblock' )) || ($action=='newblock')) )
  44.         {
  45.             $TPL->assign("editing_search_block", 1);
  46.             $TPL->assign("editing_search_block_id", $id);
  47.            
  48.             $TPL -> assign("catalog_categories", $CatalogCategories -> categories);
  49.         }
  50.         else
  51.         {
  52.             if ($action)
  53.             {
  54.                
  55.                 switch($action)
  56.                 {
  57.                     case "add_comment":
  58.                         $errors=array();
  59.                    
  60.                         $user_id = (int)valid_data(parse_outside_data("user_id"));
  61.    
  62.                         $name = valid_data(parse_outside_data("name"));
  63.                         if(empty($name))
  64.                             $errors[] = $CA_LANG_STR['Feedback']['err'] . sprintf($CA_LANG_STR['Feedback']['err_no_text'], $CA_LANG_STR['Comment']['name']);
  65.                    
  66.                         $comment = valid_data(parse_outside_data("comment"));
  67.                         if ( !strlen($comment) )
  68.                             $errors[] = $CA_LANG_STR['Feedback']['err'] . sprintf($CA_LANG_STR['Feedback']['err_no_text'], $CA_LANG_STR['Comment']['comment_text']);
  69.                         $captcha = valid_data(parse_outside_data("code_img"));
  70.                         if ( !$captcha || ($captcha != $_SESSION['code_generated_by_image']) )
  71.                             $errors[]=$CA_LANG_STR['Feedback']['err_no_captcha'];
  72.    
  73.                         if(!sizeof($errors))
  74.                         {
  75.                             $comment = str_replace("\r", "", $comment);
  76.                             $comment = str_replace("\n.", "", $comment);
  77.                        
  78.                             $sql = "insert into ".TPREFIX."comments (name, comment, user_id, ".($model_id?"model_id":"product_id").") " .
  79.                             "values('$name', '$comment', $user_id, ".($model_id?$model_id:$product_id).")";
  80.                            
  81.                            
  82.                             $DB->execute($sql);
  83.                        
  84.                             $TPL->assign("SENT", 1);
  85.                         }
  86.                         if(sizeof($errors))
  87.                         {
  88.                             $TPL->assign("ERRORS", $errors);
  89.                             $TPL->assign("POST", $_POST);
  90.                         }
  91.                        
  92.                         unset($action);
  93.                     break;
  94.                    
  95.                     case "search":
  96.                    
  97.                         if ($act)
  98.                         {
  99.                             //$limit = 12;
  100.                             $TPL->assign("actt", 1);
  101.                             $sq = "";
  102.                             $mbrand = (int) valid_data(parse_outside_data("mbrand"));
  103.                             if ($mbrand)
  104.                             {
  105.                                 $sq .= " and label_id=$mbrand ";
  106.                                 $TPL -> assign("mmbrand", $mmbrand);
  107.                             }  
  108.                             $mmodel = (int) valid_data(parse_outside_data("mmodel"));
  109.                             if ($mmodel)
  110.                             {
  111.                                 $sq .= " and model_id=$mmodel ";
  112.                                 $TPL -> assign("mmodel", $mmodel);
  113.                             }  
  114.                             $yyear = (int) valid_data(parse_outside_data("yyear"));
  115.                             if ($yyear)
  116.                             {
  117.                                 $sq .= " and year='$yyear' ";
  118.                                 $TPL -> assign("yyear", $yyear);
  119.                             }
  120.                                
  121.                             $engine = (int) valid_data(parse_outside_data("engine"));
  122.                             if ($engine)
  123.                             {
  124.                                 $sq .= " and engine_id=$engine ";
  125.                                 $TPL -> assign("engine", $engine);
  126.                             }
  127.                            
  128.                             $sql = "select * from ".TPREFIX."auto_records where category_id=".$data['B']['intdata']." $sq";
  129.                             echo "<h1 style='color: blue;'>$sql</h1>";
  130.                             $res = $DB -> execute($sql);   
  131.                             for($i=0;$i<$res->getNumOfRows();$i++)
  132.                             {
  133.                                 $records[]=$res->fields;
  134.                                 if ($i < ($res->getNumOfRows()-1))
  135.                                     $ss .= $records[$i]['id'].", ";
  136.                                 else
  137.                                     $ss .= $records[$i]['id'];
  138.                                 $res->nextRow();
  139.                             }
  140.                            
  141.                             $sql = "select * from ".TPREFIX."auto_record_characteristics where record_id in ($ss)";
  142.                             echo "<h1 style='color: pink;'>$sql</h1>";
  143.                             $res = $DB -> execute($sql);
  144.                             for($i=0;$i<$res->getNumOfRows();$i++)
  145.                             {
  146.                                 $recs[$res->fields['record_id']][]=$res->fields;
  147.                                 $res->nextRow();
  148.                             }
  149.                            
  150.                             $sql="";
  151.                             $i=0;
  152.                             if (count($recs))
  153.                             {
  154.                                 $real_sql = "select distinct characteristic_id, value, m_p_id from ".TPREFIX."mp_characteristic_values where model_product='p' and (";
  155.                                
  156.                                 foreach($recs as $key=>$val)
  157.                                 {
  158.                                     for($j=0;$j<count($val);$j++)
  159.                                     {
  160.                                         if ($i || $j)
  161.                                             $sql .= " or ";
  162.                                         $sql .= " (characteristic_id = ".$val[$j]['characteristic_id'] . " and value = '".$val[$j]['value'] . "') ";
  163.                                     }
  164.                                     //$sql .= ")";
  165.                                     $i++;
  166.                                 }
  167.                                 $real_sql .= $sql.")";
  168.                                 $res = $DB -> execute($real_sql);
  169.                                 for($i=0;$i<$res->getNumOfRows();$i++)
  170.                                 {
  171.                                     $p_ids[$res->fields['m_p_id']][$res->fields['characteristic_id']]= $res->fields['value'];
  172.                                     $res->nextRow();
  173.                                 }
  174.                                
  175.                            
  176.                                 if (count($p_ids))
  177.                                 {
  178.                                     foreach($p_ids as $pid=>$pval)
  179.                                     {
  180.                                         foreach($recs as $key=>$val)
  181.                                         {
  182.                                             $a = 1;
  183.                                             if (count($val))
  184.                                             {
  185.                                                 foreach($val as $k=>$v)
  186.                                                 {
  187.                                                     echo "tovar $pid: char=".$v['characteristic_id']."; it value=".$pval[$v['characteristic_id']]." = need value=".$v['value']."<br>";
  188.                                                     if ($pval[$v['characteristic_id']]!=$v['value'])
  189.                                                     {
  190.                                                         $a = 0;
  191.                                                         break;
  192.                                                     }
  193.                                                     else
  194.                                                         echo "<b>oki</b><br>";
  195.                                                 }
  196.                                                 if ($a)
  197.                                                 {
  198.                                                     if (!$ok[$pid])
  199.                                                         $product_ids[] = $pid;
  200.                                                     $ok[$pid]=1;
  201.                                                 }
  202.                                             }
  203.                                         }
  204.                                        
  205.                                     }
  206.                                 }
  207.                             }
  208.                         }
  209.                         $categ = $CatalogCategories -> categories_by_id[$data['B']['intdata']];
  210.                         $cat_type = $CatalogTypes -> types_by_id[$categ['category_type']];
  211.                        
  212.                         $char = $_POST['char'];
  213.                         $brand = $_POST['brand'];
  214.                         if (!$act)
  215.                         {
  216.                         if (count($char))
  217.                         {
  218.                             $c_sql = "";
  219.                             $i = 0;
  220.                            
  221.                             foreach($_POST['char'] as $key => $vall)
  222.                             {
  223.                                
  224.                                 if ($vall)
  225.                                     $ch[$key] = trim($vall);
  226.                                
  227.                                
  228.                             }
  229.                             echo "<h2>";
  230.                             print_r($ch);
  231.                             echo "</h2>";
  232.                             if (count($ch))
  233.                             {
  234.                                 foreach($ch as $key => $val)
  235.                                 {
  236.                                     if ($i < (count($ch) -1))
  237.                                     {
  238.                                         $c_sql .= "((characteristic_id = $key) and (value='$val')) or ";
  239.                                         $ccc_sql .= "$key, ";
  240.                                     }
  241.                                     else
  242.                                     {
  243.                                         $c_sql .= "((characteristic_id = $key) and (value='$val')) ";
  244.                                         $ccc_sql .= "$key";
  245.                                     }
  246.                                     $i++;
  247.                                 }
  248.                                 $rrr = "select model_product from ".TPREFIX."characteristics where id in ($ccc_sql)";
  249.                                 $res = $DB -> execute($rrr);
  250.                                
  251.                                 for($i=0; $i<$res -> getNumOfRows(); $i++)
  252.                                 {
  253.                                     if ($res -> fields['model_product'] == 'm')
  254.                                     {
  255.                                         $model_chars_in_all = 1;
  256.                                         echo "<h1 style='color: viol;'>proverili! est modeli</h1>";
  257.                                     }
  258.                                     if ($res -> fields['model_product'] == 'p')
  259.                                     {
  260.                                         $product_chars_in_all = 1;
  261.                                         echo "<h1 style='color: viol;'>proverili! est</h1>";
  262.                                     }
  263.                                    
  264.                                     $res->nextRow();
  265.                                 }
  266.                                 if (!$model_chars_in_all)
  267.                                     echo "<h1 style='color: viol;'>proverili! net</h1>";
  268.                                    
  269.                                 $sql = "select distinct m_p_id, model_product, characteristic_id from ".TPREFIX."mp_characteristic_values where $c_sql";
  270.                                 echo "<br><br><br><i>".$sql."</i><br><br><br>";
  271.                                 $res = $DB -> execute($sql);
  272.                                 for($i=0;$i<$res -> getNumOfRows();$i++)
  273.                                 {
  274.                                     if ($res->fields['model_product'] == 'm')
  275.                                     {
  276.                                        
  277.                                         if (!$m_ok[$res->fields['characteristic_id']])
  278.                                             $m_cs[] = $res->fields['characteristic_id'];
  279.                                        
  280.                                         $m_ok[$res->fields['characteristic_id']][$res->fields['m_p_id']] = 1;
  281.                                        
  282.                                         if (!$am[$res->fields['m_p_id']])
  283.                                             $mmodels[] = $res->fields['m_p_id'];
  284.                                        
  285.                                         $am[$res->fields['m_p_id']]=1;
  286.                                        
  287.                                         echo "<h2>opa!!!! mi kak-to siuda popali!</h2>";
  288.                                         //$models[] = $res->fields['m_p_id'];
  289.                                     }
  290.                                     else
  291.                                     {
  292.                                         if (!$p_ok[$res->fields['characteristic_id']])
  293.                                             $p_cs[] = $res->fields['characteristic_id'];
  294.                                        
  295.                                         $p_ok[$res->fields['characteristic_id']][$res->fields['m_p_id']] = 1;
  296.                                        
  297.                                         if (!$ap[$res->fields['m_p_id']])
  298.                                             $pproduct_ids[] = $res->fields['m_p_id'];
  299.                                        
  300.                                         $ap[$res->fields['m_p_id']]=1;
  301.                                        
  302.                                         //$product_ids[] = $res->fields['m_p_id'];
  303.                                         //$aa[$res->fields['m_p_id']]=1;
  304.                                     }
  305.                                     $res->nextRow();
  306.                                 }
  307.                                
  308.                                
  309.                                 print_r($mmodels);
  310.                                 if (count($m_cs) && count($mmodels))
  311.                                 {
  312.                                     for($i=0;$i<count($mmodels);$i++)
  313.                                     {
  314.                                         $a = 1;
  315.                                         for($j=0;$j<count($m_cs);$j++)
  316.                                         {
  317.                                             if (!$m_ok[ $m_cs[$j] ][ $mmodels[$i] ])
  318.                                                 $a = 0;
  319.                                         }
  320.                                         if ($a)
  321.                                             $models[] = $mmodels[$i];
  322.                                     }
  323.                                 }
  324.                                
  325.                                 echo "<h1 style='color: green'>models === ";
  326.                                 print_r($models);
  327.                                 echo "</h1>";
  328.                                
  329.                                 if (count($p_cs) && count($pproduct_ids))
  330.                                 {
  331.                                     for($i=0;$i<count($pproduct_ids);$i++)
  332.                                     {
  333.                                         $a = 1;
  334.                                         for($j=0;$j<count($p_cs);$j++)
  335.                                         {
  336.                                             if (!$p_ok[ $p_cs[$j] ][ $pproduct_ids[$i] ])
  337.                                                 $a = 0;
  338.                                             else
  339.                                                 echo "<br> ok: ".$p_cs[$j]." pid: ".$pproduct_ids[$i]."<br><br><br>";
  340.                                         }
  341.                                         if ($a)
  342.                                         {
  343.                                             $product_ids[] = $pproduct_ids[$i];
  344.                                             $aa[$pproduct_ids[$i]] = 1;                                        
  345.                                         }
  346.                                     }
  347.                                 }
  348.                                
  349.                                 echo "<h1 style='color: pink'>";
  350.                                 print_r($aa);
  351.                                 echo "</h1>";
  352.                                
  353.                                 if (count($models) && $model_chars_in_all)
  354.                                 {
  355.                                     echo "<h1 style='color: blue;'>kakie-to models</h1>";
  356.                                     for($i=0;$i<count($models);$i++)
  357.                                     {
  358.                                         if ($i<(count($models)-1))
  359.                                             $m_sql .= $models[$i].", ";
  360.                                         else
  361.                                             $m_sql .= $models[$i];
  362.                                     }
  363.                                    
  364.                                     $model_sql = "select id from ".TPREFIX."products where model_id in($m_sql)";
  365.                                     $res = $DB -> execute($model_sql);
  366.                                     for($i=0;$i<$res -> getNumOfRows();$i++)
  367.                                     {
  368.                                         if (($aa[$res->fields['id']]) || !$product_chars_in_all)
  369.                                         {
  370.                                             $pppps[] = $res->fields['id'];
  371.                                             $aappps[$res->fields['id']]=1;
  372.                                         }
  373.                                         $res->nextRow();
  374.                                     }
  375.                                    
  376.                                     $product_ids = $pppps;
  377.                                     $aa = $aappps;
  378.                                 }
  379.                                 if ($model_chars_in_all && !(count($models)))
  380.                                 {
  381.                                     $product_ids = 0;
  382.                                     $aa = 0;
  383.                                 }
  384.                                
  385.                             }
  386.                         }
  387.                         if ($brand)
  388.                         {
  389.                             $sql = "select id from ".TPREFIX."products where brand_id=$brand";
  390.                             $res = $DB -> execute($sql);
  391.                             for($i=0;$i<$res -> getNumOfRows();$i++)
  392.                             {
  393.                                 if (!$ch || $aa[$res->fields['id']])
  394.                                 {
  395.                                     $p_ids[] = $res->fields['id'];
  396.                                     echo "<p color='viol'>added</p>";
  397.                                 }
  398.                                 $res->nextRow();
  399.                             }
  400.                             $product_ids = $p_ids;
  401.                            
  402.                         }
  403.                         }
  404.                         if (!$ch && !$brand && !$act)
  405.                             unset($action);
  406.                         else
  407.                         {
  408.                                 print_r($product_ids);
  409.                                 echo "</b>fin<br><br><br>";
  410.                                
  411.                         for($i=0;$i<count($product_ids);$i++)
  412.                         {
  413.                             if ($i<(count($product_ids)-1))
  414.                                 $mm_sql .= $product_ids[$i].", ";
  415.                             else
  416.                              $mm_sql .= $product_ids[$i];
  417.                         }
  418.                        
  419.                         $sql = "select * from ".TPREFIX."products where id in ($mm_sql) order by model_id, brand_id, name";
  420.                         $res = $DB -> execute($sql);
  421.                         for($i=0;$i<$res->getNumOfRows();$i++)
  422.                         {
  423.                             $products[] = $res->fields;
  424.                            
  425.                             $ps[ $res->fields['id'] ] = $res->fields['model_id'];
  426.                            
  427.                             if (!$mmm[$res->fields['model_id']])
  428.                             {
  429.                                 $models[] = $res->fields['model_id'];
  430.                                 $mmm[$res->fields['model_id']] = 1;
  431.                             }
  432.                             $res -> nextRow();
  433.                         }
  434.                         $Models = new Models;
  435.                         //$limit = 12;
  436.                         $counter = count($products);
  437.                            
  438.                         if ($counter)
  439.                         {
  440.                             $pg_q = ceil($counter / $limit);
  441.                            
  442.                             for($i=0;$i<$pg_q;$i++)
  443.                                 $pager[$i] = $i+1;
  444.                                
  445.                             $TPL->assign("op", 1);
  446.                             if (count($pager) > 1)
  447.                             {
  448.                                 $TPL->assign("pager", $pager);
  449.                             }  
  450.                             $TPL->assign("ch", $ch);
  451.                             $TPL->assign("brand", $brand);
  452.                            
  453.                             if (!$page || ($page < 0))
  454.                                 $page = 0;
  455.                             if ($page > $pg_q-1)
  456.                                 $page = $pg_q-1;
  457.    
  458.                             $TPL->assign("page", $page);
  459.                            
  460.                             $start = $page * $limit;
  461.                            
  462.                             $end = $start+$limit;
  463.                             if ($end > count($products))
  464.                                 $end = count($products);
  465.                            
  466.                         }
  467.                    
  468.                         for($i=$start;$i<$end;$i++)
  469.                         {
  470.                             $model = $Models -> models_by_id[$products[$i]['model_id']];
  471.                             $model['brand_name'] = $Brands -> brands_by_id[$model['brand_id']]['name'];
  472.                             $model['cat_name'] = $CatalogCategories -> categories_by_id[$cat_type['id']]['name'];
  473.                                 //$model['image'] = str_replace("_small.", "_middle.", $model['image']);
  474.                             $model['p_name'] = $products[$i]['name'];
  475.                             $model['p_id'] = $products[$i]['id'];
  476.                                                         $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";
  477.                                                         $res = $DB -> execute($sql);
  478.                                                         $model['season'] = is_null($res->fields)?array('name'=>'Сезонность', 'value'=>1):$res->fields;
  479.                                                         if($model['season']['value'] == 1) $model['season']['value'] = "<img src=\"/imgseasons/1/image.gif\" alt=\"летняя\">";
  480.                                                         elseif((int)$model['season']['value'] == 2) $model['season']['value'] = "<img src=\"/imgseasons/2/image.gif\" alt=\"зимняя\">";
  481.                                                         elseif((int)$model['season']['value'] == 3) $model['season']['value'] = "<img src=\"/imgseasons/3/image.gif\" alt=\"всесезонная\">";
  482.                                                         else $model['season']['value'] = "<img src=\"/imgseasons/1/image.gif\" alt=\"летняя\">";
  483.  
  484.                                                         if ($products[$i]['act'] || $products[$i]['raspr'])
  485.                             {
  486.                                 $aa = $products[$i]['price_opt'];
  487.                                 $bb = $products[$i]['raspr_price'];
  488.                    
  489.                                 if ($products[$i]['act'] && $products[$i]['raspr'])
  490.                                 {
  491.                                     if (!$aa && !$bb)
  492.                                         $opp = $products[$i]['price'];
  493.                                     elseif(!$aa && $bb)
  494.                                         $opp = $bb;
  495.                                     elseif(!$bb && $aa)
  496.                                         $opp = $aa;
  497.                                     else
  498.                                         $opp = (($aa <= $bb) ? $aa : $bb);
  499.                                 }
  500.                                 elseif ($products[$i]['act'] && !$products[$i]['raspr'])
  501.                                     $opp = $aa;
  502.                                 elseif (!$products[$i]['act'] && $products[$i]['raspr'])
  503.                                     $opp = $bb;
  504.                        
  505.                                 $products[$i]['act'] = 1;
  506.                                 $products[$i]['price_opt'] = $opp;
  507.                             }
  508.  
  509.                             $model['prr'] = $products[$i];
  510.                             $pmm[] = $model;   
  511.                         }
  512.                        
  513.                         $TPL -> assign("models", $pmm);
  514.                         $TPL -> assign("show_models", 1);
  515.                         }
  516.                     break;
  517.                    
  518.                     case "show_p_se":
  519.                         $categ = $CatalogCategories -> categories_by_id[$data['B']['intdata']];
  520.                         $cat_type = $CatalogTypes -> types_by_id[$categ['category_type']];
  521.                         $page = (int) valid_data(parse_outside_data("offset"));
  522.                         $TPL -> assign("page", $page);
  523.                         $TPL->assign("op", 1);
  524.                         if ($act)
  525.                         {
  526.                             $TPL->assign("actt", 1);
  527.                             $mbrand = (int) valid_data(parse_outside_data("mbrand"));
  528.                             if ($mbrand)
  529.                                 $TPL -> assign("mmbrand", $mmbrand);
  530.                        
  531.                             $mmodel = (int) valid_data(parse_outside_data("mmodel"));
  532.                             if ($mmodel)
  533.                                 $TPL -> assign("mmodel", $mmodel);
  534.                             $yyear = (int) valid_data(parse_outside_data("yyear"));
  535.                             if ($yyear)
  536.                                 $TPL -> assign("yyear", $yyear);
  537.                                
  538.                             $engine = (int) valid_data(parse_outside_data("engine"));
  539.                             if ($engine)
  540.                                 $TPL -> assign("engine", $engine);
  541.                         }
  542.                            
  543.                         $char = $_POST['char'];
  544.                         $brand = $_POST['brand'];
  545.                         if (!$act)
  546.                         {
  547.                             if (count($char))
  548.                             {
  549.                                 $i = 0;
  550.                                 foreach($_POST['char'] as $key => $vall)
  551.                                 {
  552.                                     if ($vall)
  553.                                         $ch[$key] = trim($vall);
  554.                                 }
  555.                             }
  556.                             $TPL->assign("ch", $ch);
  557.                             $TPL->assign("brand", $brand);
  558.                         }
  559.                        
  560.                         if ($ok_pr_id)
  561.                         {
  562.                             $TPL -> assign("one_product", 1);
  563.                             $bb = "select model_id from ".TPREFIX."products where id=$ok_pr_id";
  564.                             echo "<h1 style='color: blue;'>$bb</h1>";
  565.                             $res = $DB->execute($bb);
  566.                             $model_id = $res->fields['model_id'];
  567.                             $TPL->assign("only_product_to_show", $ok_pr_id);
  568.                         }
  569.                         if($model_id)
  570.                         {
  571.                             $TPL -> assign("chmme", 1);
  572.                             $TPL -> assign("one_model", 1);
  573.                             $Models = new Models;
  574.                             echo "<h1>mur mur mur</h1>";
  575.                             $model = $Models -> models_by_id[$model_id];
  576.                             $model['brand_name'] = $Brands -> brands_by_id[$model['brand_id']]['name'];
  577.                             $model['show_f_p_ch'] = $cat_type['show_f_p_ch'];
  578.                             if ($model['image'])
  579.                             {
  580.                                 $model['image'] = str_replace("_small.", ".", $model['image']);
  581.                                 $model['image_big2'] = str_replace(".", "_biggest.", $model['image']);
  582.                             }
  583.                            
  584.                             $res = $DB -> execute("select count(id) as counter from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")."");
  585.                             $counter = $res -> fields['counter'];
  586.                
  587.                             if ($counter)
  588.                             {
  589.                                 $llimit = 10;
  590.                                 $page_num = ceil($counter / $llimit);
  591.                    
  592.                                 if ( (!$page) || ($page < 0))
  593.                                     $page = 0;
  594.                                    
  595.                                 if ($page > $page_num - 1)
  596.                                     $page = $page_num - 1;
  597.                                
  598.                                 $TPL -> assign("current_page", $page);
  599.                                
  600.                                 for($i=0; $i < $page_num;$i++)
  601.                                     $pager[$i] = $i+1;
  602.                                    
  603.                                 if (count($pager)>1)
  604.                                     $TPL -> assign("pager", $pager);
  605.                                    
  606.                                 $start = $page * $llimit;
  607.                                 $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";
  608.                                 echo "<h1 style='color: green;'>$sql</h1>";
  609.                                 $res = $DB -> execute($sql);
  610.            
  611.                                 for($i=0;$i<$res->getNumOfRows();$i++)
  612.                                 {
  613.                                     $comments[] = $res->fields;
  614.                                     $res -> nextRow();
  615.                                 }
  616.                                 $TPL->assign("comments", $comments);
  617.                             }
  618.                    
  619.                
  620.                             $cat_names = $Categories->get_cat_path_view(& $catid);
  621.                             for($i=0;$i<count($cat_names);$i++)
  622.                                 $cat_names[$i]['last']=0;
  623.                             $cat_names[]=array("name"=>$model['brand_name'], "cat"=>$catid."/brand".$model['brand_id'], "last"=>0);
  624.                             $cat_names[]=array("name"=>$model['name'], "cat"=>$catid."/model".$model['id'], "last"=>($ok_pr_id?0:1));
  625.                            
  626.                             /*
  627.                             $cat_names[]=array("name"=>"Результаты поиска", "cat"=>"javascript: document.forms.search_products_back.submit();", "last"=>0, "js" => 1);
  628.                             */
  629.                            
  630.                             $titl =  $Categories->records[$catid]['name']." ".$model['brand_name']." ".$model['name'];
  631.                                                        
  632.                             $TPL -> assign("TITLE", $titl);
  633.                             $TPL -> assign("KEYWORDS", $titl);
  634.                             $TPL -> assign("DESCRIPTION", $titl);
  635.                            
  636.                            
  637.                             $res = $DB->execute("select * from ".TPREFIX."products where model_id=$model_id order by name");
  638.                             for($i=0;$i<$res->getNumOfRows();$i++)
  639.                             {
  640.                                 $products[] = $res->fields;
  641.                                 $products_by_id[$res->fields['id']] = $res->fields['name'];
  642.                                 if ( $i < ($res->getNumOfRows())-1 )
  643.                                     $p_ids .= $res->fields['id'].", ";
  644.                                 else
  645.                                     $p_ids .= $res->fields['id'];
  646.                                
  647.                                 $res->nextRow();
  648.                             }
  649.                            
  650.                             $sql = "select * from ".TPREFIX."characteristics where cat_type_id=".$cat_type['id']." order by prio";
  651.                             echo "<h1 style='color: green;'>$sql</h1>";
  652.                             $res = $DB -> execute($sql);
  653.                            
  654.                             for($i=0;$i<$res->getNumOfrows();$i++)
  655.                             {
  656.                                 if ($res->fields['model_product'] == 'm')
  657.                                     $m_chs[] = $res->fields;
  658.                                 else
  659.                                 {
  660.                                     $p_chs[] = $res->fields;
  661.                                     $p_chs_by_id[$res->fields['id']] = $res->fields;
  662.                                 }
  663.                                 if ( $i < ($res->getNumOfRows())-1 )
  664.                                     $m_q .= $res->fields['id'].", ";
  665.                                 else
  666.                                     $m_q .= $res->fields['id'];
  667.                                 $res->nextRow();
  668.                             }
  669.                            
  670.                            
  671.                             $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)) ))";
  672.                             $res = $DB->execute($sql);
  673.                             for($i=0;$i<$res->getNumOfRows();$i++)
  674.                             {
  675.                                 if ($res->fields['model_product']=='m')
  676.                                     $mcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
  677.                                 else
  678.                                 {
  679.                                     $pcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
  680.                                     $pcv2[$res->fields['characteristic_id']][$res->fields['m_p_id']] = $res->fields['value'];
  681.                                 }
  682.                                 $res->nextRow();
  683.                             }
  684.                            
  685.                            
  686.                             for($i=0;$i<count($m_chs);$i++)
  687.                             {
  688.                                 $cc = new Characteristic($m_chs[$i]['id'], $m_chs[$i]);
  689.                                 $m_chs[$i]['html'] = $cc -> show_public_val($mcv[$model_id][$m_chs[$i]['id']]);
  690.                             }
  691.                            
  692.                             if (count($pcv2))
  693.                             {
  694.                                 for($i=0;$i<count($p_chs);$i++)
  695.                                 {
  696.                                     $key = $p_chs[$i]['id'];
  697.                                     $val = $pcv2[$key];
  698.                                     if ($val)
  699.                                     {
  700.                                         $cc = new Characteristic($key, $p_chs_by_id[$key]);
  701.                                    
  702.                                         if (count($val))
  703.                                         {
  704.                                             foreach($val as $k => $v)
  705.                                             {
  706.                                                 if ($cc -> data['show_inside'])
  707.                                                     $chs_by_products[$k][] = array("name" => $cc->data['name'], "html" => $cc -> show_public_val($v));
  708.                                             }
  709.                                         }
  710.                                     }  
  711.                                 }
  712.                             }
  713.                            
  714.                            
  715.                             for($i=0;$i<count($products);$i++)
  716.                             {
  717.                                 if ($_SESSION['p_array'][$products[$i]['id']])
  718.                                                                     $products[$i]['qqq'] = $_SESSION['p_array'][$products[$i]['id']];
  719.                                 $products[$i]['characteristics'] = $chs_by_products[$products[$i]['id']];
  720.                             }
  721.                             if ($ok_pr_id)
  722.                             {
  723.                                 $cat_names[]=array("name"=>$products_by_id[$ok_pr_id], "cat"=>$catid."/product".$ok_pr_id, "last"=>1);
  724.                                
  725.                                 if ($titl)
  726.                                     $titl .=  " " . $products_by_id[$ok_pr_id]['name'];
  727.                                 else
  728.                                     $titl .= $products_by_id[$ok_pr_id]['name'];
  729.                                 $TPL -> assign("TITLE", $titl);
  730.                                 $TPL -> assign("KEYWORDS", $titl);
  731.                                 $TPL -> assign("DESCRIPTION", $titl);
  732.                             }
  733.                                
  734.                             $TPL->assign('CAT_PATH', $cat_names);
  735.                
  736.                             $model['characteristics'] = $m_chs;
  737.                             $TPL->assign("ccount", ( count($m_chs) +  count($products[0]['characteristics']) + 3 ) );
  738.                             $TPL -> assign("MODEL", $model);
  739.                             for($i=0;$i<count($products);$i++)
  740.                             {
  741.                                 if ($products[$i]['act'] || $products[$i]['raspr'])
  742.                     {
  743.                        
  744.                        
  745.                         $aa = $products[$i]['price_opt'];
  746.                         $bb = $products[$i]['raspr_price'];
  747.                    
  748.                         if ($products[$i]['act'] && $products[$i]['raspr'])
  749.                         {
  750.                             if (!$aa && !$bb)
  751.                                 $op = $products[$i]['price'];
  752.                             elseif(!$aa && $bb)
  753.                                 $op = $bb;
  754.                             elseif(!$bb && $aa)
  755.                                 $op = $aa;
  756.                             else
  757.                                 $op = (($aa <= $bb) ? $aa : $bb);
  758.                        
  759.                         }
  760.                         elseif ($products[$i]['act'] && !$products[$i]['raspr'])
  761.                             $op = $aa;
  762.                         elseif (!$products[$i]['act'] && $products[$i]['raspr'])
  763.                             $op = $bb;
  764.                     $products[$i]['act'] = 1;
  765.                         $products[$i]['price_opt'] = $op;
  766.                     }
  767.                             }
  768.                             $TPL -> assign("products", $products);
  769.                         }                  
  770.                     break;
  771.                    
  772.                     default:
  773.                         unset($action);
  774.                     break;
  775.                 }
  776.             }
  777.             if (!$action)
  778.             {
  779.                 $categ = $CatalogCategories -> categories_by_id[$data['B']['intdata']];
  780.                 $cat_type = $CatalogTypes -> types_by_id[$categ['category_type']];
  781.                
  782.                 if ($cat_type['choose_model'])
  783.                 {
  784.                     $TPL -> assign("chmme", 1);
  785.                     echo "puh!";
  786.                     if ($brand_id || $model_id || $product_id)
  787.                     {
  788.                         if ($product_id)
  789.                         {
  790.                             $TPL -> assign("one_product", 1);
  791.                             $res = $DB->execute("select model_id from ".TPREFIX."products where id=$product_id");
  792.                             $model_id = $res->fields['model_id'];
  793.                            
  794.                             $TPL->assign("only_product_to_show", $product_id);
  795.                         }
  796.    
  797.                         if($model_id)
  798.                         {
  799.                             $TPL -> assign("one_model", 1);
  800.                             $Models = new Models;
  801.                            
  802.                             $model = $Models -> models_by_id[$model_id];
  803.                             $model['brand_name'] = $Brands -> brands_by_id[$model['brand_id']]['name'];
  804.                             $model['show_f_p_ch'] = $cat_type['show_f_p_ch'];
  805.                             if ($model['image'])
  806.                             {
  807.                                 $model['image'] = str_replace("_small.", ".", $model['image']);
  808.                                 $model['image_big2'] = str_replace(".", "_biggest.", $model['image']);
  809.                             }
  810.                            
  811.                             $res = $DB -> execute("select count(id) as counter from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")."");
  812.                             $counter = $res -> fields['counter'];
  813.                
  814.                             if ($counter)
  815.                             {
  816.                                 $llimit = 10;
  817.                                 $page_num = ceil($counter / $llimit);
  818.                    
  819.                                 if ( (!$page) || ($page < 0))
  820.                                     $page = 0;
  821.                                    
  822.                                 if ($page > $page_num - 1)
  823.                                     $page = $page_num - 1;
  824.                                
  825.                                 $TPL -> assign("current_page", $page);
  826.                                
  827.                                 for($i=0; $i < $page_num;$i++)
  828.                                     $pager[$i] = $i+1;
  829.                                    
  830.                                 if (count($pager)>1)
  831.                                     $TPL -> assign("pager", $pager);
  832.                                    
  833.                                 $start = $page * $llimit;
  834.                                 $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";
  835.                                
  836.                                 $res = $DB -> execute($sql);
  837.            
  838.                                 for($i=0;$i<$res->getNumOfRows();$i++)
  839.                                 {
  840.                                     $comments[] = $res->fields;
  841.                                     $res -> nextRow();
  842.                                 }
  843.                                 $TPL->assign("comments", $comments);
  844.                             }
  845.                    
  846.                
  847.                             $cat_names = $Categories->get_cat_path_view(& $catid);
  848.                             for($i=0;$i<count($cat_names);$i++)
  849.                                 $cat_names[$i]['last']=0;
  850.                            
  851.                             $cat_names[]=array("name"=>$model['brand_name'], "cat"=>$catid."/brand".$model['brand_id'], "last"=>0);
  852.                             $cat_names[]=array("name"=>$model['name'], "cat"=>$catid."/model".$model['id'], "last"=>($product_id?0:1));
  853.                            
  854.                             $titl =  $Categories->records[$catid]['name']." ".$model['brand_name']." ".$model['name'];
  855.                                                        
  856.                             $TPL -> assign("TITLE", $titl);
  857.                             $TPL -> assign("KEYWORDS", $titl);
  858.                             $TPL -> assign("DESCRIPTION", $titl);
  859.                            
  860.                            
  861.                             $res = $DB->execute("select * from ".TPREFIX."products where model_id=$model_id order by name");
  862.                             for($i=0;$i<$res->getNumOfRows();$i++)
  863.                             {
  864.                                 $products[] = $res->fields;
  865.                                 $products_by_id[$res->fields['id']] = $res->fields['name'];
  866.                                 if ( $i < ($res->getNumOfRows())-1 )
  867.                                     $p_ids .= $res->fields['id'].", ";
  868.                                 else
  869.                                     $p_ids .= $res->fields['id'];
  870.                                
  871.                                 $res->nextRow();
  872.                             }
  873.                            
  874.                             $sql = "select * from ".TPREFIX."characteristics where cat_type_id=".$cat_type['id'];
  875.                        
  876.                             $res = $DB -> execute($sql);
  877.                            
  878.                             for($i=0;$i<$res->getNumOfrows();$i++)
  879.                             {
  880.                                 if ($res->fields['model_product'] == 'm')
  881.                                     $m_chs[] = $res->fields;
  882.                                 else
  883.                                 {
  884.                                     $p_chs[] = $res->fields;
  885.                                     $p_chs_by_id[$res->fields['id']] = $res->fields;
  886.                                 }
  887.                                 if ( $i < ($res->getNumOfRows())-1 )
  888.                                     $m_q .= $res->fields['id'].", ";
  889.                                 else
  890.                                     $m_q .= $res->fields['id'];
  891.                                 $res->nextRow();
  892.                             }
  893.                            
  894.                            
  895.                             $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)) ))";
  896.                             $res = $DB->execute($sql);
  897.                             for($i=0;$i<$res->getNumOfRows();$i++)
  898.                             {
  899.                                 if ($res->fields['model_product']=='m')
  900.                                     $mcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
  901.                                 else
  902.                                 {
  903.                                     $pcv[$res->fields['m_p_id']][$res->fields['characteristic_id']] = $res->fields['value'];
  904.                                     $pcv2[$res->fields['characteristic_id']][$res->fields['m_p_id']] = $res->fields['value'];
  905.                                 }
  906.                                 $res->nextRow();
  907.                             }
  908.                            
  909.                            
  910.                             for($i=0;$i<count($m_chs);$i++)
  911.                             {
  912.                                 $cc = new Characteristic($m_chs[$i]['id'], $m_chs[$i]);
  913.                                 $m_chs[$i]['html'] = $cc -> show_public_val($mcv[$model_id][$m_chs[$i]['id']]);
  914.                             }
  915.                            
  916.                             if (count($pcv2))
  917.                             {
  918.                                 foreach($pcv2 as $key=>$val)
  919.                                 {
  920.                                     $cc = new Characteristic($key, $p_chs_by_id[$key]);
  921.                                    
  922.                                     if (count($val))
  923.                                     {
  924.                                         foreach($val as $k => $v)
  925.                                         {
  926.                                             if ($cc -> data['show_inside'])
  927.                                                 $chs_by_products[$k][] = array("name" => $cc->data['name'], "html" => $cc -> show_public_val($v));
  928.                                         }
  929.                                     }
  930.                                    
  931.                                 }
  932.                             }
  933.                            
  934.                            
  935.                             for($i=0;$i<count($products);$i++)
  936.                             {
  937.                                 if ($_SESSION['p_array'][$products[$i]['id']])
  938.                                     $products[$i]['qqq'] = $_SESSION['p_array'][$products[$i]['id']];
  939.                                  $products[$i]['characteristics'] = $chs_by_products[$products[$i]['id']];
  940.                             }
  941.                             if ($product_id)
  942.                             {
  943.                                 $cat_names[]=array("name"=>$products_by_id[$product_id], "cat"=>$catid."/product".$product_id, "last"=>1);
  944.                                
  945.                                 if ($titl)
  946.                                     $titl .=  " " . $products_by_id[$product_id]['name'];
  947.                                 else
  948.                                     $titl .= $products_by_id[$product_id]['name'];
  949.                                 $TPL -> assign("TITLE", $titl);
  950.                                 $TPL -> assign("KEYWORDS", $titl);
  951.                                 $TPL -> assign("DESCRIPTION", $titl);
  952.                             }
  953.                                
  954.                             $TPL->assign('CAT_PATH', $cat_names);
  955.                
  956.                             $model['characteristics'] = $m_chs;
  957.                             $TPL->assign("ccount", ( count($m_chs) +  count($products[0]['characteristics']) + 3 ) );
  958.                             $TPL -> assign("MODEL", $model);
  959.                             for($i=0;$i<count($products);$i++)
  960.                             {
  961.                                 if ($products[$i]['act'] || $products[$i]['raspr'])
  962.                     {
  963.                        
  964.                        
  965.                         $aa = $products[$i]['price_opt'];
  966.                         $bb = $products[$i]['raspr_price'];
  967.                    
  968.                         if ($products[$i]['act'] && $products[$i]['raspr'])
  969.                         {
  970.                             if (!$aa && !$bb)
  971.                                 $op = $products[$i]['price'];
  972.                             elseif(!$aa && $bb)
  973.                                 $op = $bb;
  974.                             elseif(!$bb && $aa)
  975.                                 $op = $aa;
  976.                             else
  977.                                 $op = (($aa <= $bb) ? $aa : $bb);
  978.                        
  979.                         }
  980.                         elseif ($products[$i]['act'] && !$products[$i]['raspr'])
  981.                             $op = $aa;
  982.                         elseif (!$products[$i]['act'] && $products[$i]['raspr'])
  983.                             $op = $bb;
  984.                     $products[$i]['act'] = 1;
  985.                         $products[$i]['price_opt'] = $op;
  986.                     }
  987.                             }
  988.                             $TPL -> assign("products", $products);
  989.                         }
  990.                         elseif ($brand_id)
  991.                         {
  992.                            
  993.                             //$limit=12;
  994.                             $TPL -> assign("show_models", 1);
  995.                             $TPL -> assign("brand_id", $brand_id);
  996.                            
  997.                             $Models = new Models;
  998.                             if (!$Brands)
  999.                             $Brands = new Brands;
  1000.                             //$models = $Models -> models_by_brand[$brand_id];
  1001.                            
  1002.                             $counter = count($Models -> models_by_brand[$brand_id]);
  1003.                             $cat_names = $Categories->get_cat_path_view(& $catid);
  1004.                             for($i=0;$i<count($cat_names);$i++)
  1005.                                 $cat_names[$i]['last']=0;
  1006.                            
  1007.                            
  1008.                             $cat_names[]=array("name"=>$Brands -> brands_by_id[$brand_id]['name'], "cat"=>$catid."/brand".$brand_id, "last"=>1);
  1009.                             $TPL->assign('CAT_PATH', $cat_names);
  1010.                            
  1011.                             $titl =  $Categories->records[$catid]['name']." ".$Brands -> brands_by_id[$brand_id]['name'];
  1012.                             $TPL -> assign("TITLE", $titl);
  1013.                             $TPL -> assign("KEYWORDS", $titl);
  1014.                             $TPL -> assign("DESCRIPTION", $titl);
  1015.  
  1016.                            
  1017.                             if ($counter)
  1018.                             {
  1019.                                 $pg_q = ceil($counter / $limit);
  1020.                                
  1021.                                 for($i=0;$i<$pg_q;$i++)
  1022.                                     $pager[$i] = $i+1;
  1023.                                    
  1024.                                 if (count($pager) > 1)
  1025.                                     $TPL->assign("pager", $pager);
  1026.                                    
  1027.                              
  1028.                                 if (!$page || ($page < 0))
  1029.                                     $page = 0;
  1030.                                 if ($page > $pg_q-1)
  1031.                                     $page = $pg_q-1;
  1032.        
  1033.                                 $TPL->assign("page", $page);
  1034.                                
  1035.                                 $start = $page * $limit;
  1036.                                
  1037.                                 $end = $start+$limit;
  1038.                                 if ($end > count($Models -> models_by_brand[$brand_id]))
  1039.                                     $end = count($Models -> models_by_brand[$brand_id]);
  1040.                                
  1041.                             }
  1042.                    
  1043.                             $i=0;
  1044.                             for($j=$start;$j<$end;$j++)
  1045.                             {
  1046.                                 $models[$i] = $Models -> models_by_brand[$brand_id][$j];
  1047.                                 $models[$i]['cat_name'] = $CatalogCategories -> categories_by_id[$cat_type['id']]['name'];
  1048.                                 $models[$i]['brand_name'] = $Brands -> brands_by_id[$brand_id]['name'];
  1049.                                 $models[$i]['image'] = str_replace("_small.", "_middle.", $models[$i]['image']);
  1050.                                 $i++;
  1051.                             }
  1052.                             $TPL -> assign("models", $models);
  1053.                         }
  1054.                         else
  1055.                         {
  1056.                             unset($brand_id);
  1057.                             unset($model_id);
  1058.                             unset($product_id);
  1059.                         }
  1060.                     }
  1061.                     if (!$brand_id && !$model_id && !$product_id)
  1062.                     {
  1063.                         $brands = $Brands -> brands_by_category[$categ['id']];
  1064.                         for($i=0;$i<count($brands);$i++)
  1065.                         {
  1066.                             $brands[$i]['logo'] = str_replace("/".$brands[$i]['id']."/","/preview/".$brands[$i]['id']."/",$brands[$i]['logo']);
  1067.                         }
  1068.                         $TPL -> assign("brands", $brands);
  1069.                         $TPL -> assign("show_brands", 1);
  1070.                     }
  1071.                 }
  1072.                 else
  1073.                 {
  1074.                     //echo "<font style='color: red;font-size: 36px;'>".$cat_type['choose_model']."</font>";
  1075.                     $TPL -> assign("no_model", 1);
  1076.                     if (!$product_id)
  1077.                     {
  1078.                         $TPL -> assign("show_products", 1);
  1079.                         $sql = "select count(id) as counter from ".TPREFIX."products where category_id=".$data['B']['intdata'];
  1080.                         $res = $DB -> execute($sql);
  1081.                        
  1082.                         $counter = $res->fields['counter'];
  1083.                        
  1084.                         if ($counter)
  1085.                         {
  1086.                             $pg_q = ceil($counter / $limit);
  1087.                            
  1088.                             for($i=0;$i<$pg_q;$i++)
  1089.                                 $pager[$i] = $i+1;
  1090.                                
  1091.                             if (count($pager) > 1)
  1092.                                 $TPL->assign("pager", $pager);
  1093.                                
  1094.                             if (!$page || ($page < 0))
  1095.                                 $page = 0;
  1096.                             if ($page > $pg_q-1)
  1097.                                 $page = $pg_q-1;
  1098.    
  1099.                             $TPL->assign("page", $page);
  1100.                            
  1101.                             $start = $page * $limit;
  1102.                            
  1103.                             $sql = "select * from ".TPREFIX."products where category_id=".$data['B']['intdata']." order by id desc LIMIT $start, $limit";
  1104.                             $res = $DB -> execute($sql);
  1105.                            
  1106.                             for($i=0;$i<$res->getNumOfRows();$i++)
  1107.                             {
  1108.                                 $products[] = $res->fields;
  1109.                                 $res -> nextRow();
  1110.                             }
  1111.                             for($i=0;$i<count($products);$i++)
  1112.                             {
  1113.                                 if ($products[$i]['act'] || $products[$i]['raspr'])
  1114.                     {
  1115.                        
  1116.                        
  1117.                         $aa = $products[$i]['price_opt'];
  1118.                         $bb = $products[$i]['raspr_price'];
  1119.                    
  1120.                         if ($products[$i]['act'] && $products[$i]['raspr'])
  1121.                         {
  1122.                             if (!$aa && !$bb)
  1123.                                 $op = $products[$i]['price'];
  1124.                             elseif(!$aa && $bb)
  1125.                                 $op = $bb;
  1126.                             elseif(!$bb && $aa)
  1127.                                 $op = $aa;
  1128.                             else
  1129.                                 $op = (($aa <= $bb) ? $aa : $bb);
  1130.                        
  1131.                         }
  1132.                         elseif ($products[$i]['act'] && !$products[$i]['raspr'])
  1133.                             $op = $aa;
  1134.                         elseif (!$products[$i]['act'] && $products[$i]['raspr'])
  1135.                             $op = $bb;
  1136.                    
  1137.                         $products[$i]['price_opt'] = $op;
  1138.                         $products[$i]['act'] = 1;
  1139.                     }
  1140.                             }
  1141.                            
  1142.                             $TPL->assign("products", $products);
  1143.                            
  1144.                         }
  1145.                
  1146.                     }
  1147.                     else
  1148.                     {
  1149.                         $cat_names = $Categories->get_cat_path_view(& $catid);
  1150.                         for($i=0;$i<count($cat_names);$i++)
  1151.                             $cat_names[$i]['last']=0;
  1152.                    
  1153.                        
  1154.                         $TPL -> assign("one_product", 1);
  1155.                                
  1156.                         $res = $DB->execute("select * from ".TPREFIX."products where id=$product_id");
  1157.                         $product = $res->fields;
  1158.                         if ($product['act'] || $product['raspr'])
  1159.                     {
  1160.                        
  1161.                        
  1162.                         $aa = $product['price_opt'];
  1163.                         $bb = $product['raspr_price'];
  1164.                    
  1165.                         if ($product['act'] && $product['raspr'])
  1166.                         {
  1167.                             if (!$aa && !$bb)
  1168.                                 $op = $product['price'];
  1169.                             elseif(!$aa && $bb)
  1170.                                 $op = $bb;
  1171.                             elseif(!$bb && $aa)
  1172.                                 $op = $aa;
  1173.                             else
  1174.                                 $op = (($aa <= $bb) ? $aa : $bb);
  1175.                        
  1176.                         }
  1177.                         elseif ($product['act'] && !$product['raspr'])
  1178.                             $op = $aa;
  1179.                         elseif (!$product['act'] && $product['raspr'])
  1180.                             $op = $bb;
  1181.                     $product['act'] = 1;
  1182.                         $product['price_opt'] = $op;
  1183.                     }
  1184.                        
  1185.                         $res = $DB -> execute("select count(id) as counter from ".TPREFIX."comments where ".($product_id ? "product_id = $product_id": "model_id=$model_id")."");
  1186.                         $counter = $res -> fields['counter'];
  1187.            
  1188.                         if ($counter)
  1189.                         {
  1190.                             $llimit = 10;
  1191.                             $page_num = ceil($counter / $llimit);
  1192.                
  1193.                             if ( (!$page) || ($page < 0))
  1194.                                 $page = 0;
  1195.                                
  1196.                             if ($page > $page_num - 1)
  1197.                                 $page = $page_num - 1;
  1198.                            
  1199.                             $TPL -> assign("current_page", $page);
  1200.                            
  1201.                             for($i=0; $i < $page_num;$i++)
  1202.                                 $pager[$i] = $i+1;
  1203.                                
  1204.                             if (count($pager)>1)
  1205.                                 $TPL -> assign("pager", $pager);
  1206.                                
  1207.                             $start = $page * $llimit;
  1208.                             $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";
  1209.                            
  1210.                             $res = $DB -> execute($sql);
  1211.        
  1212.                             for($i=0;$i<$res->getNumOfRows();$i++)
  1213.                             {
  1214.                                 $comments[] = $res->fields;
  1215.                                 $res -> nextRow();
  1216.                             }
  1217.                             $TPL->assign("comments", $comments);
  1218.                         }
  1219.                            
  1220.                         $cat_names[]=array("name"=>$product['name'], "cat"=>$catid."/product".$product_id, "last"=>1);
  1221.                         $TPL->assign('CAT_PATH', $cat_names);
  1222.                        
  1223.                        
  1224.                         $titl =  $Categories->records[$catid]['name']." ".$product['name'];
  1225.                         $TPL -> assign("TITLE", $titl);
  1226.                         $TPL -> assign("KEYWORDS", $titl);
  1227.                         $TPL -> assign("DESCRIPTION", $titl);
  1228.                
  1229.                        
  1230.                         $sql = "select * from ".TPREFIX."characteristics where cat_type_id=".$CatalogCategories->categories_by_id[$product['category_id']]['category_type'];
  1231.                         $res = $DB -> execute($sql);
  1232.                                
  1233.                         for($i=0;$i<$res->getNumOfrows();$i++)
  1234.                         {
  1235.                             $p_chs[] = $res->fields;
  1236.                             $p_chs_by_id[$res->fields['id']] = $res->fields;
  1237.                             $res->nextRow();
  1238.                         }
  1239.                                
  1240.                                
  1241.                         $sql = "select * from ".TPREFIX."mp_characteristic_values where  model_product='p' AND m_p_id = ".$product['id'];
  1242.                         $res = $DB->execute($sql);
  1243.                         for($i=0;$i<$res->getNumOfRows();$i++)
  1244.                         {
  1245.                             $pcv[$res->fields['characteristic_id']] = $res->fields['value'];
  1246.                             $res->nextRow();
  1247.                         }
  1248.                                
  1249.                                
  1250.                         if (count($pcv))
  1251.                         {
  1252.                             foreach($pcv as $key=>$val)
  1253.                             {
  1254.                                 $cc = new Characteristic($key, $p_chs_by_id[$key]);
  1255.                                 $just_chas[] = array("name" => $cc->data['name'], "html" => $cc -> show_public_val($val));
  1256.                             }
  1257.                         }
  1258.                         if (count($just_chas))
  1259.                         {
  1260.                             $TPL->assign("width", ceil(100 / count($just_chas)));
  1261.                             $product['characteristics'] = $just_chas;
  1262.                         }
  1263.                        
  1264.                         if ($product['image'])
  1265.                             $product['image_big2'] = str_replace("_small.", "_biggest.", $product['image']);
  1266.        
  1267.                         $TPL -> assign("product", $product);
  1268.                     }
  1269.                 }
  1270.             }
  1271.            
  1272.            
  1273.         }
  1274.        
  1275.        
  1276.     }
  1277.    
  1278.     function updater(&$data)
  1279.     {
  1280.         $p_type = $_POST['p_type'];
  1281.        
  1282.         $green = $_POST['green'];
  1283.         if ($green)
  1284.             $data['green'] = 1;
  1285.         else
  1286.             $data['green'] = 0;
  1287.        
  1288.         switch($p_type)
  1289.         {
  1290.             case "new":
  1291.                 $data['new'] = 1;
  1292.             break;
  1293.             case "leader":
  1294.                 $data['leader'] = 1;
  1295.             break;
  1296.             case "act":
  1297.                 $data['act'] = 1;
  1298.             break;
  1299.         }
  1300.        
  1301.        
  1302.        
  1303.     }
  1304. }
  1305.  
  1306. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement