archosaur2

php код который собирает страницу

Jul 16th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 66.76 KB | None | 0 0
  1. <?php
  2. function createContent(){
  3.    
  4.     global $db;
  5.     global $db2;
  6.     global $contentAction;
  7.     global $uri;
  8.     global $gloablURL;
  9.     global $XYU;
  10.     global $pageDescription;
  11.     global $pageKeyWords;
  12.     global $pageTitle;
  13.     global $tplService;
  14.     global $tpl;
  15.     global $lang;
  16.     global $orderUrl;
  17.  
  18.     $orderBy= 'ORDER BY `ind` ASC';
  19.     for($i=1;$i<count($uri);$i++)
  20.     {
  21.         if($uri[$i]=='asc')
  22.         {
  23.             $orderUrl='asc';
  24.             $orderBy='ORDER BY `price` ASC';
  25.             unset($uri[$i]);
  26.         }
  27.         else if($uri[$i]=='desc')
  28.         {
  29.             $orderUrl='desc';
  30.             $orderBy='ORDER BY `price` DESC';
  31.             unset($uri[$i]);
  32.         }
  33.        
  34.     }
  35.     if($lang=='/en')
  36.     {
  37.         $slogan='Your treasury';
  38.         $metal = 'Metal';
  39.         $wood = 'Wood';
  40.         $stone = 'Stone';
  41.         $glass = 'Glass';
  42.         $other = 'Other';
  43.         $cartTitle = 'The Loot';
  44.         $welcomeHeader = '';
  45.         $welcomeText = '<strong>Conquistador</strong>&mdash; it\'s your personal treasury. The shop offers original gifts and souvenirs, which are suitable for any celebration. All the items are high-quality handmade products, so your gift would always be unique and special.';
  46.         $smContacts = 'Shop of unique gifts';
  47.         $footerText = 'All materials copyright protected by copyright law and their complete or partial copying without permission is prohibited.';
  48.         $copyright = 'Shop of unique gifts';
  49.         $cabinet_auth = 'My account';
  50.         $cabinet_noauth = 'Log in | Register';
  51.         $emptyCategoryMessage = 'The category is being updated. Please visit this page later.';
  52.  
  53.     }
  54.     else if($lang=='/ua')
  55.     {
  56.         $uotpl = 'Ua';
  57.         $action_text = 'Акцii';
  58.         $top_text = 'Топ';
  59.         $slogan='Твоя скарбниця';
  60.         $metal = 'Метал';
  61.         $wood = 'Дерево';
  62.         $stone = 'Камiнь';
  63.         $glass = 'Скло';
  64.         $other = 'Iнше';
  65.         $cartTitle = 'Награбоване';
  66.         $welcomeHeader = '';
  67.         $welcomeText = '<strong>Конкiстадор</strong> – це Ваша скарбниця оригінальних, гідних предметів ручної роботи,
  68. створених з натуральних матеріалів. Ми безпосередньо співпрацюємо з майстрами з
  69. України і ближнього зарубіжжя, щоб докласти Вам дійсно унікальні подарунки найвищої якості.';
  70.         $smContacts = 'Магазин унікальних подарунків';
  71.         $footerText = 'Всі права на матеріали сайту захищені законом про авторське право та їх повне або часткове копіювання без дозволу заборонено.';
  72.         $copyright = 'Магазин унікальних подарунків';
  73.         $cabinet_auth = 'Мiй кабiнет';
  74.         $cabinet_noauth = 'Увiйти | Реєстрацiя';
  75.         $emptyCategoryMessage = 'Данний роздiл наповнюється. Будь ласка, заходьте пізніше.';
  76.     }
  77.     else
  78.     {
  79.         $uotpl = '';
  80.         $action_text = 'Акции';
  81.         $top_text = 'Топ';
  82.         $slogan='Твоя сокровищница';
  83.         $metal = 'Металл';
  84.         $wood = 'Дерево';
  85.         $stone = 'Камень';
  86.         $glass = 'Стекло';
  87.         $other = 'Разное';
  88.         $cartTitle = 'Награбленное';
  89.         $welcomeHeader = '';
  90.         $welcomeText = '<strong>Конкистадор</strong> – это Ваша сокровищница оригинальных, достойных предметов ручной работы,
  91. созданных из натуральных материалов. Мы непосредственно сотрудничаем с мастерами из
  92. Украины и ближнего зарубежья, чтобы предложить Вам действительно уникальные подарки высочайшего качества.';
  93.         $smContacts = 'Магазин уникальных подарков';
  94.         $footerText = 'Все права на материалы сайта защищены законом об авторском праве и их полное или частичное копирование без разрешения запрещено.';
  95.         $copyright = 'Магазин уникальных подарков';
  96.         $cabinet_auth = 'Мой кабинет';
  97.         $cabinet_noauth = 'Вход | Регистрация';
  98.  
  99.         $emptyCategoryMessage = 'Данный раздел в стадии наполнения. Зайдите, пожалуйста, позже.';
  100.     }
  101.     if (!empty($_SESSION['UID']))
  102.         $tpl->set('#cabinet',null,array('cabinet'=>$cabinet_auth,'lang'=>$lang));
  103.     else
  104.         $tpl->set('#cabinet',null,array('cabinet'=>$cabinet_noauth,'lang'=>$lang));
  105.  
  106.     $tpl->set('#footerContent',null,array('text'=>$footerText,'copyright'=>$copyright));
  107.     $tpl->set('#smContacts',null,array('smContacts'=>$smContacts));
  108.     if($uri['1']!='shop')
  109.     $tpl->set('#welcome',null,array('welcomeHeader'=>$welcomeHeader,'welcomeText'=>$welcomeText));
  110.     else
  111.     {
  112.         $aforizm = $db->queryOneRecord("SELECT * FROM `aforizm` ORDER BY RAND() LIMIT 1");
  113.         $tpl->set('#welcome','shop',array('welcomeText'=>$aforizm['text']));
  114.     }
  115.     $tpl->set('#cartTitle',null,array('cartTitle'=>$cartTitle));
  116.  
  117.  
  118.     $baselang = substr($lang, '1');
  119.     $baselang = '_'.$baselang;
  120.     if($baselang!='_en' AND $baselang!='_ua') $baselang='';
  121.     $tpl->set('#topMenu',null,array('lang'=>$lang,'slogan'=>$slogan,'wood'=>$wood,'metal'=>$metal,'stone'=>$stone,'glass'=>$glass,'other'=>$other));
  122.     $inner = '';
  123.     $metaArray = Array(
  124.         'title'=>'title',
  125.         'description'=>'description',
  126.         'keywords'=>'keywords'
  127.     );
  128.     $footer = createFooter();
  129.     $UID = $_SESSION['UID'];
  130.     if(!empty($_SESSION['UID'])){
  131.         $U = $db->queryOneRecord("select * from `users` where `id`='{$_SESSION['UID']}' limit 1");
  132.     }
  133.    
  134.         $EUR = $db->queryOneRecord("SELECT * FROM `sitedate` WHERE `id`='2'");
  135.         $USD = $db->queryOneRecord("SELECT * FROM `sitedate` WHERE `id`='1'");
  136.         $currency = $USD['value'];
  137.     $uriEl = uriLastEl();
  138.         if(!empty($contentAction) AND empty($uri['2'])){
  139.             $metaData=$db->queryOneRecord("SELECT * FROM `meta` WHERE `module`='$contentAction'");
  140.            
  141.             $metaArray = Array(
  142.                 'keywords'    => $metaData['keywords'],
  143.                 'description' => $metaData['description'],
  144.                 'title'       => $metaData['title']
  145.             );
  146.         }
  147.         else if(!empty($contentAction) AND !empty($uri['2'])){
  148.            $metaData=$db->queryOneRecord("SELECT * FROM `meta` WHERE `module`='".$uri['2']."'");
  149.            $metaArray = Array(
  150.                 'keywords'    => $metaData['keywords'],
  151.                 'description' => $metaData['description'],
  152.                 'title'       => $metaData['title']
  153.             );
  154.         }
  155.     $contentTemplate = $contentAction;
  156.     $contentTemplate=strtr($contentTemplate,
  157.             array(
  158.                 "signin"=>"sign",
  159.                 "account"=>"sign",
  160.                 )
  161.      );
  162.     $tpl->set('#body',null,Array(
  163.         'wrapperClass'=>$contentTemplate
  164.     ));
  165.     $tpl->set('#content',$contentTemplate);
  166.     $metaArray = Array(
  167.                 'keywords'    => $metaData['keywords'],
  168.                 'description' => $metaData['description'],
  169.                 'title'       => $metaData['title']
  170.             );
  171.     if($uri[1]=='cart')
  172.     {
  173.         if($uri['2']=='finish')
  174.             $metaArray = Array(
  175.                     'keywords'    => 'Заказ оформлен - интернет-магазин conquistador.com.ua',
  176.                     'description' => 'Заказ оформлен - интернет-магазин conquistador.com.ua',
  177.                     'title'       => 'Заказ оформлен - интернет-магазин conquistador.com.ua',
  178.             );
  179.         if($uri['2']=='order')
  180.             $metaArray = Array(
  181.                     'keywords'    => 'Оформление заказа - интернет-магазин conquistador.com.ua',
  182.                     'description' => 'Оформление заказа - интернет-магазин conquistador.com.ua',
  183.                     'title'       => 'Оформление заказа - интернет-магазин conquistador.com.ua',
  184.             ); 
  185.         if($uri['2']=='order')
  186.             $metaArray = Array(
  187.                     'keywords'    => 'Оформление заказа - интернет-магазин conquistador.com.ua',
  188.                     'description' => 'Оформление заказа - интернет-магазин conquistador.com.ua',
  189.                     'title'       => 'Оформление заказа - интернет-магазин conquistador.com.ua',
  190.             );
  191.     }
  192.     if($contentAction=="index"){
  193.             $count=0;
  194.             if(!$UID){
  195.                 $basCount = count($_SESSION['basket']);
  196.             }else{
  197.                 $basItems = $db->queryAllRecords("select * from `basketitems` where `uid`='$UID'");
  198.                 $basCount = count($basItems);
  199.             }
  200.  
  201.             if($basCount>1) $compresion = '<a href="/comparison/">Сравнить</a>';
  202.  
  203.                 $items = $db->queryAllRecords("SELECT `items`.`id`,`items`.`actionprice` AS `price`,`items`.`url` AS `url`, `items`.`iid`,
  204.                                                      `brands`.`url` AS `brand`,`items`.`hit`,`items`.`new`,
  205.                                                      `sitedate`.`value`/`items`.`price` AS `price2`,`items`.`descriptor` AS `name`,`items`.`descriptor_en` AS `name_en`,
  206.                                                       `items`.`descriptor_ua` AS `name_ua`,`items`.`file2`,`items`.`prev-width`
  207.                                                       FROM `items`
  208.                                                       JOIN `partisions` AS `brands` ON `items`.`iid`=`brands`.`id`
  209.                                                       JOIN `sitedate` ON `sitedate`.`id`='1'
  210.                                                       WHERE `items`.`show`!='true' AND `items`.`action`='true' order by `items`.`iid` DESC LIMIT 5");
  211.                 for($i=0;$i<count($items);$i++){
  212.                     $items[$i]['lang'] = $lang;
  213.                     $tag = null;
  214.                     $test = checkInBasket($items[$i]['id']);
  215.                     $test = intval ($test);
  216.                     if (file_exists($_SERVER['DOCUMENT_ROOT'].'/items_img/'.$items[$i]['iid'].'/'.$items[$i]['id'].'/'.$items[$i]['url'].'-prev.jpg'))  
  217.                                             $items[$i]['file2']='/items_img/'.$items[$i]['iid'].'/'.$items[$i]['id'].'/'.$items[$i]['url'].'-prev.jpg';
  218.                     $classes = Array('toBaskcet','outFromBasket');
  219.                     $lableses = Array('Отложить','Убрать');
  220.                     $part = $db->queryOneRecord("SELECT `url` FROM `partisions` WHERE `id`=(
  221.                                                  SELECT `iid` FROM `partisions` WHERE `url`='{$items[$i]['brand']}')");
  222.                     if($part['url']!='')$items[$i]['part']=$part['url'];
  223.                     else $items[$i]['part']=$items[$i]['brand'];
  224.                     $class = $classes[$test];
  225.                     $items[$i]['name']=$items[$i]['name'.$baselang];
  226.                     $baskLable = $lableses[$test];
  227.                     $items[$i]['baskClass'] =$class;
  228.                     $items[$i]['baskLable'] =$baskLable;
  229.                     $curr1 = '&euro;';
  230.                     $curr2 = '$';
  231.                     if($lang=='/en')
  232.             {
  233.                 $items[$i]['price']=roundPrice('uah',$items[$i]['price'],$currency);
  234.                 $items[$i]['price2']=roundPrice('usd',$items[$i]['price'],$currency);
  235.                 $items[$i]['price']=roundPrice('eur',$items[$i]['price'],$EUR['value']);
  236.                
  237.             }
  238.             else
  239.             {
  240.                 $items[$i]['price']=roundPrice('uah',$items[$i]['price'],$currency);
  241.                 $items[$i]['price2']=roundPrice('usd',$items[$i]['price'],$currency);
  242.             }
  243.            
  244.                 if($items[$i]['price']==0){
  245.                 $items[$i]['price2'] = null;
  246.                 if($lang=='/en')
  247.                     $items[$i]['price'] = "no price";
  248.                 else
  249.                     $items[$i]['price'] = "Цена не указана";
  250.                 }
  251.                 else
  252.                 {
  253.                 if($lang=='/en')
  254.                 {
  255.                     $items[$i]['price']=$curr1.$items[$i]['price'];
  256.                     $items[$i]['price2']=$curr2.$items[$i]['price2'];
  257.                 }
  258.                 else
  259.                 {
  260.                     $items[$i]['price']=$items[$i]['price'].' грн';
  261.                     $items[$i]['price2']=$curr2.$items[$i]['price2'];
  262.                 }
  263.                 }
  264.                     if($items[$i]['new']) $tag .= "new ";
  265.                     if($items[$i]['hit']) $tag .= "hit ";
  266.                    
  267.                     $items[$i]['tag'] = $tag;
  268.                 }
  269.                 $tpl->set('.indexProduct',null, $items);
  270.                 $items = $db->queryAllRecords("SELECT `items`.`id`,`items`.`price` AS `price`,`items`.`url` AS `url`,`items`.`iid`,
  271.                                                      `brands`.`url` AS `brand`,`items`.`hit`,`items`.`new`,
  272.                                                      `sitedate`.`value`/`items`.`price` AS `price2`,`items`.`descriptor` AS `name`,`items`.`descriptor_en` AS `name_en`,
  273.                                                       `items`.`descriptor_ua` AS `name_ua`,`items`.`file2`,`items`.`prev-width`
  274.                                                       FROM `items`
  275.                                                       JOIN `partisions` AS `brands` ON `items`.`iid`=`brands`.`id`
  276.                                                       JOIN `sitedate` ON `sitedate`.`id`='1'
  277.                                                       WHERE `items`.`show`!='true' AND `items`.`hit`='true' order by `items`.`iid` DESC LIMIT 5"); //
  278.        
  279.                 for($i=0;$i<count($items);$i++){
  280.                             $items[$i]['lang'] = $lang;
  281.                             $tag = null;
  282.                             $test = checkInBasket($items[$i]['id']);
  283.                             $test = intval ($test);
  284.                             if (file_exists($_SERVER['DOCUMENT_ROOT'].'/items_img/'.$items[$i]['iid'].'/'.$items[$i]['id'].'/'.$items[$i]['url'].'-prev.jpg'))  
  285.                                             $items[$i]['file2']='/items_img/'.$items[$i]['iid'].'/'.$items[$i]['id'].'/'.$items[$i]['url'].'-prev.jpg';
  286.                             $classes = Array('toBaskcet','outFromBasket');
  287.                             $lableses = Array('Отложить','Убрать');
  288.                             $part = $db->queryOneRecord("SELECT `url` FROM `partisions` WHERE `id`=(
  289.                                                         SELECT `iid` FROM `partisions` WHERE `url`='{$items[$i]['brand']}')");
  290.                             if($part['url']!='')$items[$i]['part']=$part['url'];
  291.                             else $items[$i]['part']=$items[$i]['brand'];
  292.                             $class = $classes[$test];
  293.                             $items[$i]['name']=$items[$i]['name'.$baselang];
  294.                             $baskLable = $lableses[$test];
  295.                             $items[$i]['baskClass'] =$class;
  296.                             $items[$i]['baskLable'] =$baskLable;
  297.                             $curr1 = '&euro;';
  298.                             $curr2 = '$';
  299.                             if($lang=='/en')
  300.                     {
  301.                         $items[$i]['price']=roundPrice('uah',$items[$i]['price'],$currency);
  302.                         $items[$i]['price2']=roundPrice('usd',$items[$i]['price'],$currency);
  303.                         $items[$i]['price']=roundPrice('eur',$items[$i]['price'],$EUR['value']);
  304.  
  305.                     }
  306.                     else
  307.                     {
  308.                         $items[$i]['price']=roundPrice('uah',$items[$i]['price'],$currency);
  309.                         $items[$i]['price2']=roundPrice('usd',$items[$i]['price'],$currency);
  310.                     }
  311.  
  312.                         if($items[$i]['price']==0){
  313.                             $items[$i]['price2'] = null;
  314.                             if($lang=='/en')
  315.                                 $items[$i]['price'] = "no price";
  316.                             else
  317.                                 $items[$i]['price'] = "Цена не указана";
  318.                             }
  319.                             else
  320.                             {
  321.                                     if($lang=='/en')
  322.                                     {
  323.                                         $items[$i]['price']=$curr1.$items[$i]['price'];
  324.                                         $items[$i]['price2']=$curr2.$items[$i]['price2'];
  325.                                     }
  326.                                     else
  327.                                     {
  328.                                         $items[$i]['price']=$items[$i]['price'].' грн';
  329.                                         $items[$i]['price2']=$curr2.$items[$i]['price2'];
  330.                                     }
  331.                             }
  332.  
  333.                             if($items[$i]['new']) $tag .= "new ";
  334.                             if($items[$i]['hit']) $tag .= "hit ";
  335.  
  336.                             $items[$i]['tag'] = $tag;
  337.                 }
  338.                 $tpl->set('#mainAction','def',array('action'=>$action_text));
  339.                 $tpl->set('#mainTop','def',array('top'=>$top_text));
  340.                 $tpl->set('.indexTopProduct',null, $items);
  341.                 $tpl->set('#indexProductCart',null,array('incart'=>$basCount));
  342.  
  343.         }else if ($contentAction=="shop"){
  344.            
  345.             $tpl->set('#shopContent');
  346.                 if(!empty($uri['2']) AND empty($uri['3'])){
  347.                     $metaData = $db->queryOneRecord("SELECT `title`,`keywords`, `description` FROM `partisions` WHERE `url`='".$uri['2']."' LIMIT 1");
  348.                 }
  349.                 if(!empty($uri['3']) AND empty($uri['4'])){
  350.                     $metaData = $db->queryOneRecord("SELECT `title`,`keywords`, `description` FROM `partisions` WHERE `url`='".$uri['3']."' LIMIT 1");
  351.                    
  352.                 }
  353.                 if(!empty($uri['4'])){
  354.                     $metaData = $db->queryOneRecord("SELECT `title`,`keywords`, `description` FROM `items` WHERE `url`='".$uri['4']."' LIMIT 1");
  355.                 }
  356.                     $metaArray = Array(
  357.                         'keywords'    => $metaData['keywords'],
  358.                         'description' => $metaData['description'],
  359.                         'title'       => $metaData['title']
  360.                     );
  361.                
  362.         $cat = null;
  363.         $position = null;
  364.         $items = Array();
  365.         $allOk=true;
  366.         $catalog = $db->queryAllRecords("select `name`,`type`,`url` from `partisions` where `iid`='0' order by `ind` DESC");
  367.         $mainContainer = $tpl->set('#shopMainMenuContainer',null,null,true);
  368.         $mainLisTpl = $tpl->set('#partitionList',null,null,true);
  369.         $fly = Array();
  370.         $catalogCount = 0;
  371.         if(!empty($uri['4'])) $uriEl=$uri['3'];
  372.         if(!empty($uri['2']) AND preg_match('/^page[0-9]{1,3}$/',$uri['3'])){
  373.                                 $uriEl=$uri['2'];
  374.                             }
  375.                             else if(!empty($uri['2']) AND empty($uri['3'])){
  376.                                 $uriEl=$uri['2'];
  377.                             }
  378.                             else if(!empty($uri['3']) AND !preg_match('/^page[0-9]{1,3}$/',$uri['3'])){
  379.                                 $uriEl=$uri['3'];
  380.                             }
  381.                             else if(!empty($uri['3']) AND preg_match('/^page[0-9]{1,3}$/',$uri['3'])){
  382.                                 $uriEl=$uri['2'];
  383.                             }
  384.                             else if(!empty($uri['3']) AND preg_match('/^page[0-9]{1,3}$/',$uri['4'])){
  385.                                 $uriEl=$uri['3'];
  386.                             }
  387.         $currentID=$db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uriEl}'");
  388.         $catTitle = $currentID['name'.$baselang];
  389.                 $currentIID = $currentID['iid'];
  390.         $currentID=$currentID['id'];
  391.         $tpl->set('#catTitle',null,array('category-Title'=>$catTitle));
  392.         for($i=0;$i<count($catalog);$i++){
  393.             if($catalog[$i]['url']==$uri[2]){
  394.                 $catalog[$i]['class']='active';
  395.                 if(!empty($uri[3]))$catalog[$i]['class']='active Lnk';
  396.             }else $catalog[$i]['class']='inline';
  397.             $catalog[$i]['lang']=$lang;
  398.             if($catalog[$i]['type']){
  399.                 $tmpVar = null;
  400.                 foreach($fly as $f){
  401.                     $tmpVar .= $tpl->replace($mainLisTpl,$f);
  402.                 }
  403.                 $catalogueMain .= $tpl->replace($mainContainer,Array('content'=>$tmpVar));
  404.                 $fly = Array();
  405.                 $catalogCount = 0;
  406.             }else{
  407.                 $fly[] = $catalog[$i];
  408.             }
  409.             $catalogCount++;
  410.         }
  411.         $mainContainer = $tpl->set('#shopMainMenuHolder',null,Array('content'=>$catalogueMain));
  412.                         $uriLE = uriLastEl();
  413.                         if(!empty($uri['2'])){
  414.                             if(!empty($uri['2']) AND preg_match('/^page[0-9]{1,3}$/',$uri['3'])){
  415.                                 $uriLe=$uri['2'];
  416.                             }
  417.                             else if(!empty($uri['2']) AND empty($uri['3'])){
  418.                                 $uriLe=$uri['2'];
  419.                             }
  420.                             else if(!empty($uri['3']) AND !preg_match('/^page[0-9]{1,3}$/',$uri['3'])){
  421.                                 $uriLe=$uri['3'];
  422.                             }
  423.                             else if(!empty($uri['3']) AND preg_match('/^page[0-9]{1,3}$/',$uri['4'])){
  424.                                 $uriLe=$uri['3'];
  425.                             }
  426.                             $currCAT = $db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uriLe}'");
  427.                             $treeArray = treee($currentID);
  428.                             $treeArrayLength = count($treeArray);
  429.                             if($treeArrayLength>1){
  430.                                 $pathLi = $tpl->set("#pathFinderLi",null,null,true);
  431.                                 $pathInsideUl = $tpl->set("#pathFinderInsideContainer",null,null,true);
  432.                                 $pathinsideLi = $tpl->set("#pathFinderInsideLi",null,null,true);
  433.                                 $pathinsideWidthUl = $tpl->set("#pathFinderInsideUl",null,null,true);
  434.                                 $pathinsideLiActive = $tpl->set("#pathFinderInsideLiActive",null,null,true);
  435.                                 for($i=$treeArrayLength-1;$i>-1;$i--){
  436.                                     $item = &$treeArray[$i];
  437.                                     $item['part']=$uri[2];
  438.                                     $itemList = null;
  439.                                     if($item['part']!=$item['url'])
  440.                                         $item['part']= "{$item['part']}/{$item['url']}";
  441.                                         foreach($item['items'] as &$it){
  442.                                             $it['part']=$uri[2];
  443.                                            
  444.                                             if($it['active'])
  445.                                                 $itemList.=$tpl->replace($pathinsideLi,$it);
  446.                                             else
  447.                                                 $itemList.=$tpl->replace($pathinsideLiActive,$it);
  448.                                         }
  449.                                         $item['inside']=$tpl->replace($pathInsideUl,Array('content'=>$itemList));
  450.                                         $item['lang']=$lang;
  451.                                     $breadcrumbs.=$tpl->replace($pathLi,$item);
  452.                                 }
  453.                                 //$tpl->set("#pathFinder",null,Array('content'=>$breadcrumbs));
  454.                             }
  455.                 }
  456.                
  457.         //----------Если мы в корне каталога-------------//
  458.                     if(empty($uri['2'])){
  459.                         $catalogueTplId = 'root';
  460.                                                 header('Location:/');
  461.                        
  462.                     }else{
  463.                         $catalogueTplId = 'items';
  464.                     }
  465.                    
  466.         //----------Если мы в /каталог/категория-------------//
  467.                     if(empty($uri['3']) AND !empty($uri['2'])){
  468.                        
  469.                          $currentID=$db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uri['2']}' AND `iid`='0'");
  470.                          $currentID=$currentID['id'];
  471.                          if(empty($childNodes))$partitionList = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `iid`='{$currentID}'");
  472.                          else $partitionList=$childNodes;
  473.                          if(count($partitionList)>0){
  474.                            if(empty($XYU)){ parseChildEl(getChildElements($currentID));
  475.                             $XYU=substr($XYU,0,-1);
  476.                            }
  477.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` IN($XYU)
  478.                                 $orderBy LIMIT 0,12");
  479.                          }
  480.                          else
  481.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` ='{$currentID}' $orderBy  LIMIT 0,12");
  482.                        
  483.                          if (empty($items)) $emptyCategoryFlag = true;
  484.                          if($emptyCategoryFlag != true) $tpl->set('#sortBlock'.$orderUrl,'def',array('lang'=>$lang,'part'=>$uri['2'],'url'=>'','page'=>''));
  485.                          
  486.                     }
  487.         //----------Если мы в /каталог/категория/страницаХ-------------//
  488.                     if(!empty($uri['3']) AND preg_match('/^page[0-9]{1,3}$/',$uri['3'])){
  489.                     $tpl->set('#sortBlock'.$orderUrl,'def',array('lang'=>$lang,'part'=>$uri['2'],'url'=>'','page'=>'/'.$uri['3']));
  490.                    
  491.                         $currentID=$db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uri['2']}' AND `iid`='0'");
  492.                         $currentID=$currentID['id'];
  493.                         preg_match('/[0-9]*$/',$uri['3'],$pageID);
  494.                         $limits=countLimits($pageID['0']);
  495.                         $partitionList = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `iid`='{$currentID}'");
  496.                          if(count($partitionList)>0){
  497.                             if(empty($XYU)){parseChildEl(getChildElements($currentID));
  498.                             $XYU=substr($XYU,0,-1);
  499.                             }
  500.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` IN($XYU) $orderBy LIMIT {$limits['0']},{$limits['1']}");
  501.                     }
  502.                          else
  503.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` ='{$currentID}' $orderBy LIMIT {$limits['0']},{$limits['1']}");
  504.                     }
  505.         //----------Если мы в /каталог/категория/подкатегория-------------//
  506.  
  507.                         if(!empty($uri['3']) AND !preg_match('/^page[0-9]{1,3}$/',$uri['3']) AND empty($uri['4'])){
  508.                         $tpl->set('#sortBlock'.$orderUrl,'def',array('lang'=>$lang,'part'=>$uri['2'],'url'=>'/'.$uri['3'],'page'=>''));
  509.                         $currentID=$db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uri['3']}'");
  510.                         $currentID=$currentID['id'];
  511.                         $partitionList = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `iid`='{$currentID}'");
  512.                          if(count($partitionList)>0){
  513.                             if(empty($XYU)){parseChildEl(getChildElements($currentID));
  514.                             $XYU=substr($XYU,0,-1);
  515.                             }
  516.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` IN ($XYU) $orderBy LIMIT 0,12");
  517.                          }
  518.                          else
  519.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` = '$currentID' $orderBy LIMIT 0,12");
  520.                         //echo $currCAT['iid'];
  521.                         if($currCAT['iid']!='0')
  522.                         {
  523.                             $inonelevel = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `iid`!={$currCAT['iid']} AND `name` LIKE '%{$currCAT['name']}%'");
  524.                             if(!empty($inonelevel))
  525.                             {
  526.                                 $tpl->set('#iflinked');
  527.                                 $tpl->set('.linkedMenuElement',null,$inonelevel);
  528.                             }
  529.                         }
  530.                     }
  531.          //----------Если мы в /каталог/категория/подкатегория/страницаX-------------//
  532.                         if(!empty($uri['4']) AND preg_match('/^page[0-9]{1,3}$/',$uri['4'])){
  533.                         $tpl->set('#sortBlock'.$orderUrl,'def',array('lang'=>$lang,'part'=>$uri['2'],'url'=>'/'.$uri['3'],'page'=>'/'.$uri['4']));
  534.                         preg_match('/[0-9]*$/',$uri['4'],$pageID);
  535.                         $limits=countLimits($pageID['0']);
  536.                         $currentID=$db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uri['3']}'");
  537.                         $currentID=$currentID['id'];
  538.                         $partitionList = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `iid`='{$currentID}'");
  539.                          if(count($partitionList)>0){
  540.                            if(empty($XYU)){ parseChildEl(getChildElements($currentID));
  541.                             $XYU=substr($XYU,0,-1);
  542.                            }
  543.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` IN ($XYU) $orderBy LIMIT {$limits['0']},{$limits['1']}");
  544.                          }
  545.                          else
  546.                          $items=$db->queryAllRecords("SELECT * FROM `items` WHERE `show`!='true' AND `iid` = '$currentID' $orderBy LIMIT {$limits['0']},{$limits['1']}");
  547.                     }
  548.                     if(!empty($items)){
  549.                     foreach($items as $itms){
  550.                             $pqr.=$itms['iid'].",";
  551.                          }
  552.                          $qstr=substr($pqr, 0, -1);
  553.                          if(!empty($items))$scts=$db->queryAllRecords("SELECT `url`,`id` FROM `partisions` WHERE `id` IN($qstr) LIMIT 0,12");
  554.                          $partUrls = Array();
  555.                         foreach($scts as $s)
  556.                             $partUrls[$s['id']]=$s['url'];
  557.                         foreach($items as &$itms){
  558.                             $itms['part'] = $uri[2];
  559.                             $itms['brand'] = $partUrls[$itms['iid']];
  560.                          }
  561.                     }
  562.                     $curr1 = '&euro;';
  563.                     $curr2 = '$';
  564.         for($i=0;$i<count($items);$i++){
  565.         if($items[$i]['action']=='true') $items[$i]['price']=$items[$i]['actionprice'];
  566.         $items[$i]['lang']=$lang;
  567.                 if (file_exists($_SERVER['DOCUMENT_ROOT'].'/items_img/'.$items[$i]['iid'].'/'.$items[$i]['id'].'/'.$items[$i]['url'].'-prev.jpg'))  
  568.                                             $items[$i]['file2']='/items_img/'.$items[$i]['iid'].'/'.$items[$i]['id'].'/'.$items[$i]['url'].'-prev.jpg';
  569.                 if($lang=='/en')
  570.                 {
  571.                     $baskClass = 'toBaskcet';
  572.                     $baskLable = 'Buy it!';
  573.                 }
  574.                 if($lang=='/ua')
  575.                 {
  576.                     $baskClass = 'toBaskcet';
  577.                     $baskLable = 'Купити!';
  578.                 }
  579.                 else if($lang!='/en' AND $lang!='/ua')
  580.                 {
  581.                     $baskClass = 'toBaskcet';
  582.                     $baskLable = 'Купить!';
  583.                 }
  584.            
  585.             if($lang=='/en')
  586.             {
  587.                 $items[$i]['price']=roundPrice('uah',$items[$i]['price'],$currency);
  588.                 $items[$i]['price2']=roundPrice('usd',$items[$i]['price'],$currency);
  589.                 $items[$i]['price']=roundPrice('eur',$items[$i]['price'],$EUR['value']);
  590.                
  591.             }
  592.             else
  593.             {
  594.                 $items[$i]['price']=roundPrice('uah',$items[$i]['price'],$currency);
  595.                 $items[$i]['price2']=roundPrice('usd',$items[$i]['price'],$currency);
  596.             }
  597.            
  598.             if($items[$i]['price']==0){
  599.                 $items[$i]['price2'] = null;
  600.                 if($lang=='/en')
  601.                     $items[$i]['price'] = "no price";
  602.                 else
  603.                     $items[$i]['price'] = "Цена не указана";
  604.             }
  605.             else
  606.             {
  607.                 if($lang=='/en')
  608.                 {
  609.                     $items[$i]['price']=$curr1.$items[$i]['price'];
  610.                     $items[$i]['price2']=$curr2.$items[$i]['price2'];
  611.                 }
  612.                 else
  613.                 {
  614.                     $items[$i]['price']=$items[$i]['price'].' грн';
  615.                     $items[$i]['price2']=$curr2.$items[$i]['price2'];
  616.                 }
  617.             }
  618.                
  619.                
  620.             if(!empty($items[$i]['file2']) AND file_exists("gallery/photo/{$items[$i]['file2']}"))
  621.                 $items[$i]['img'] = "/gallery/photo/{$items[$i]['file2']}";
  622.             else
  623.                 $items[$i]['img'] = "/img/shop/nophoto.gif";
  624.             if(checkInBasket($items[$i]['id'])){
  625.                 if($lang=='/en')
  626.                 {
  627.                     $baskClass = 'outFromBasket';
  628.                     $baskLable = 'Remove from cart';
  629.                 }
  630.                 if($lang=='/ua')
  631.                 {
  632.                     $baskClass = 'outFromBasket';
  633.                     $baskLable = 'Прибрати';
  634.                 }
  635.                 else if($lang!='/en' AND $lang!='/ua')
  636.                 {
  637.                     $baskClass = 'outFromBasket';
  638.                     $baskLable = 'Убрать';
  639.                 }
  640.             }
  641.             if($lang=='/en')
  642.                 $items[$i]['articleTitle']='Article: ';
  643.             else
  644.                 $items[$i]['articleTitle']='Артикул: ';
  645.                
  646.             $items[$i]['name']=$items[$i]['name'.$baselang];
  647.             $items[$i]['caption'] = strip_tags($items[$i]['caption'.$baselang]);
  648.             $items[$i]['basketClass'] = $baskClass;
  649.             $items[$i]['basketLable'] = $baskLable;
  650.                     }
  651.         if(!empty($uri[4]) AND !preg_match('/^page[0-9]{1,3}$/',$uri['4'])){
  652.             $currentID=$db->queryOneRecord("SELECT * FROM `partisions` WHERE `url`='{$uri['3']}'");
  653.             $currentID=$currentID['id'];
  654.             //П�?ДАРЫ ПОзиция карточка товара
  655.             $catalogueTplId = 'position';
  656.             $cart = $_SESSION['basket'];
  657.             //foreach($cart as $c)
  658.             //{
  659.             //    echo $c['0'].' ';
  660.             //}
  661.             if($lang=='/en')
  662.                 $tpl->set('#priceTitle',null,array('priceTitle'=>'Price'));
  663.             else if($lang=='/ua')
  664.                 $tpl->set('#priceTitle',null,array('priceTitle'=>'Цiна'));
  665.             else
  666.                 $tpl->set('#priceTitle',null,array('priceTitle'=>'Цена'));
  667.             $items = $db->queryOneRecord("select * from `items` where `url`='".$uri[4]."' order by `ind` limit 1");
  668.             $pageTitle = $items['title'];
  669.             $metaArray = Array(
  670.                 'keywords'    => $items['keywords'.$baselang],
  671.                 'description' => $items['description'.$baselang],
  672.                 'title'       => $items['title'.$baselang]
  673.             );
  674.             $items['stock'] = (!empty($items['stok']))?'Нет в наличии':'Есть в наличии';
  675.             if(checkInBasket($items['id'])){
  676.                 if($lang=='/en')
  677.                 {
  678.                     $baskClass = 'outFromBasket';
  679.                     $baskLable = 'Remove from cart';
  680.                 }
  681.                 if($lang=='/ua')
  682.                 {
  683.                     $baskClass = 'outFromBasket';
  684.                     $baskLable = 'Прибрати';
  685.                 }
  686.                 else if($lang!='/en' AND $lang!='/ua')
  687.                 {
  688.                     $baskClass = 'outFromBasket';
  689.                     $baskLable = 'Убрать';
  690.                 }
  691.             }
  692.             if($baselang!='_en' AND $baselang!='_ua')
  693.                 $baselang = '';
  694.             $items['name']=$items['name'.$baselang];
  695.             if($items['action']=='true') $items['price']=$items['actionprice'];
  696.             $items['text']=$items['text'.$baselang];
  697.             $items['caption']=$items['caption'.$baselang];
  698.             $items['descriptor']=$items['descriptor'.$baselang];
  699.             $items['title']=$items['title'.$baselang];
  700.             $items['keywords']=$items['keywords'.$baselang];
  701.             $items['description']=$items['description'.$baselang];
  702.             $items['top']=$items['top'.$baselang];
  703.             $items['header']=$items['header'.$baselang];
  704.             if($items['action']=='true') $items['price']=$items['actionprice'];
  705.             if($items['price']!=''){
  706.                 if($lang!='/en')
  707.                 {
  708.                     $items['price']=roundPrice('uah',$items['price'],$currency);
  709.                     $items['price2']=roundPrice('usd',$items['price'],$currency);
  710.                     $items['price']=$items['price'].' грн';
  711.                     $items['price2']=$curr2.$items['price2'];
  712.                 }
  713.                 else
  714.                 {
  715.                     $items['price']=roundPrice('uah',$items['price'],$currency);
  716.                     $items['price2']=roundPrice('usd',$items['price'],$currency);
  717.                     $items['price']=roundPrice('eur',$items['price'],$EUR['value']);
  718.                     $items['price']=$curr1.$items['price'];
  719.                     $items['price2']=$curr2.$items['price2'];
  720.                 }
  721.             }else{
  722.                 $items['price2'] = null;
  723.                 if($lang=='/en')
  724.                     $items['price'] = "no price";
  725.                 else
  726.                     $items['price'] = "Цена не указана";
  727.             }
  728.             if($lang=='/en')
  729.                 {
  730.                     $baskClass = 'toBaskcet';
  731.                     $baskLable = 'Buy it!';
  732.                 }
  733.                 if($lang=='/ua')
  734.                 {
  735.                     $baskClass = 'toBaskcet';
  736.                     $baskLable = 'Купити!';
  737.                 }
  738.                 else if($lang!='/en' AND $lang!='/ua')
  739.                 {
  740.                     $baskClass = 'toBaskcet';
  741.                     $baskLable = 'Купить!';
  742.                 }
  743.  
  744.             if(checkInBasket($items['id'])){
  745.                 if($lang=='/en')
  746.                 {
  747.                     $baskClass = 'outFromBasket';
  748.                     $baskLable = 'Remove from cart';
  749.                 }
  750.                 if($lang=='/ua')
  751.                 {
  752.                     $baskClass = 'outFromBasket';
  753.                     $baskLable = 'Прибрати';
  754.                 }
  755.                 else if($lang!='/en' AND $lang!='/ua')
  756.                 {
  757.                     $baskClass = 'outFromBasket';
  758.                     $baskLable = 'Убрать';
  759.                 }
  760.             }
  761.             if($lang=='/en')
  762.                 $items['articleTitle']='Article:';
  763.             else
  764.                 $items['articleTitle']='Артикул:';
  765.                
  766.             $items['basketClass'] = $baskClass;
  767.            
  768.             $items['basketLable'] = $baskLable;
  769.             $items['comments'] = createComments($items['id']);
  770.             if(!empty($items['file1']) && file_exists("gallery/photo/{$items['file1']}"))
  771.                 $items['img'] = "/gallery/photo/{$items['file1']}";
  772.             else
  773.                 $items['img'] = "/img/shop/nophoto.gif";
  774.                 $tableIn = null;
  775.                 $table = explode(";",$items['table']);
  776.                
  777.                 $fly = Array();
  778.                 foreach($table as $elem){
  779.                     $lines = explode("—",$elem);
  780.                    
  781.                     $fly[] = Array(
  782.                         'var'=>$lines[0],
  783.                         'val'=>$lines[1]
  784.                     );
  785.                 }
  786.                 $tpl->set('.tableItems',null,$fly);        
  787.             $position = $items;
  788.         }
  789.         //Картинки на странице товара
  790.         //собираем массив
  791.        // foreach ($items as $key => $value) {
  792.  
  793.             //if (strstr($key, 'photo_') && $value != '')
  794.  
  795.                 $photo['big'] = '/items_img/'.$items['iid'].'/'.$items['id'].'/'.$items['url'].'-1-big.jpg';  
  796.                 $photo['zoom'] = '/items_img/'.$items['iid'].'/'.$items['id'].'/'.$items['url'].'-1-zoom.jpg';
  797.                
  798.                 $tpl->set('#mainImage',null,$photo);
  799.                 $j=0;
  800.                 for($i=1;$i<=5;$i++)
  801.                 {
  802.                     if (file_exists($_SERVER['DOCUMENT_ROOT'].'/items_img/'.$items['iid'].'/'.$items['id'].'/'.$items['url'].'-'.$i.'-big.jpg'))  
  803.                     {
  804.                         $thumbs[$j]['zoom']='/items_img/'.$items['iid'].'/'.$items['id'].'/'.$items['url'].'-'.$i.'-zoom.jpg';
  805.                         $thumbs[$j]['thumb']='/items_img/'.$items['iid'].'/'.$items['id'].'/'.$items['url'].'-'.$i.'-big.jpg';
  806.                     }
  807.                         $j++;
  808.                 }
  809.         //}
  810.         //echo '<img src="/items_img/'.$items['iid'].'/'.$items['id'].'/'.$items['url'].'-big.jpg'.'"/>';
  811.         //Вызываем шаблон.Он генерит стока элементов вредных скока элементов в массиве
  812.         $tpl->set('.positionThumbs',null,$thumbs);
  813.         $tpl->set('#catalogue',$catalogueTplId,$position);
  814.         $tpl->set('.catalogueItemsList',null,$items);
  815.  
  816.         // Получаем дерево категорий
  817.         $globalParent = getParentRec($currentID);
  818.         $parent = get_parent($currentID);
  819.         $categories = get_ctgs_tree( 0, 0 );
  820.         if(empty($uri['3']))
  821.             $globalLevel = '0';
  822.         else if(!empty($uri['3']))
  823.         {
  824.             $category = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `iid`='{$currentID}'");
  825.             if(!empty($category))
  826.             $globalLevel = '2';
  827.             else
  828.             $globalLevel = '3';
  829.         }
  830.         $i=0;
  831.         foreach($categories as $c)
  832.         {
  833.             $c_query .=$c['id'].',';
  834.         }
  835.         $c_query = substr($c_query,0,-1);
  836.         //print_r($categories);
  837.         //$categories = $db->queryAllRecords("SELECT * FROM `partisions` WHERE `id` IN ($c_query) ORDER BY `name`");
  838.         //print_r($categories);
  839.         foreach ($categories as $ctg)
  840.         {
  841.             $level = $ctg['level'];
  842.             if($globalLevel != 0)
  843.             {
  844.             if($level == 1)
  845.             {
  846.                 if($ctg['iid']==$globalParent['id'])
  847.                 {
  848.                 $levelOne[$i]['name']=$ctg['name'.$baselang];
  849.                 $levelOne[$i]['lang']=$lang;
  850.                 $levelOne[$i]['part']=$globalParent['url'];
  851.                 $levelOne[$i]['url']=$ctg['url'];
  852.                 $parent_parent = get_parent($parent['iid']);
  853.                 if($ctg['id']==$currentID OR $ctg['id']==$currentIID OR $ctg['id']==$parent_parent['iid'])
  854.                     $levelOne[$i]['class']='active';
  855.                 else
  856.                     $levelOne[$i]['class']='inline';
  857.                 }
  858.             }
  859.             if($level == 2)
  860.                 {
  861.                 if($ctg['iid']==$currentID)
  862.                 {
  863.                     $l2MenuElements[$i]['name']=$ctg['name'.$baselang];
  864.                     $l2MenuElements[$i]['lang']=$lang;
  865.                     $l2MenuElements[$i]['part']=$globalParent['url'];
  866.                     $l2MenuElements[$i]['url']=$ctg['url'];
  867.                     if($ctg['id']==$currentID OR $ctg['id']==$currentIID)
  868.                     $l2MenuElements[$i]['class']='active';
  869.                     else
  870.                     $l2MenuElements[$i]['class']='inline';
  871.                 }
  872.                 }
  873.             }
  874.             if($globalLevel!=0)
  875.             {
  876.             if($globalLevel==2 OR $globalLevel==3)
  877.             {
  878.                 if($level == 2)
  879.                 {
  880.                 if($ctg['iid']==$currentIID)
  881.                 {
  882.                     $l2MenuElements[$i]['name']=$ctg['name'.$baselang];
  883.                     $l2MenuElements[$i]['lang']=$lang;
  884.                     $l2MenuElements[$i]['part']=$globalParent['url'];
  885.                     $l2MenuElements[$i]['url']=$ctg['url'];
  886.                     if($ctg['id']==$currentID OR $ctg['id']==$currentIID)
  887.                     $l2MenuElements[$i]['class']='active';
  888.                     else
  889.                     $l2MenuElements[$i]['class']='inline';
  890.                 }
  891.                 }
  892.                 if($level == 3)
  893.                 {
  894.                 if($ctg['iid']==$currentID)
  895.                 {
  896.                     $middleMenuElements[$i]['name'] = $ctg['name'.$baselang];
  897.                     $middleMenuElements[$i]['lang'] = $lang;
  898.                     $middleMenuElements[$i]['part'] = $globalParent['url'];
  899.                     $middleMenuElements[$i]['url'] = $ctg['url'];
  900.                     if($ctg['id']==$currentID OR $ctg['id']==$currentIID)
  901.                     $middleMenuElements[$i]['class']='active';
  902.                     else
  903.                     $middleMenuElements[$i]['class']='inline';
  904.                 }
  905.                 }
  906.             }
  907.             if($globalLevel==3)
  908.             {
  909.                 if($level == 2)
  910.                 {
  911.                 $parent = get_parent($currentIID);
  912.                 if($ctg['id']==$currentIID OR $parent['iid']==$ctg['iid'])
  913.                 {
  914.                     $l2MenuElements[$i]['name']=$ctg['name'.$baselang];
  915.                     $l2MenuElements[$i]['lang']=$lang;
  916.                     $l2MenuElements[$i]['part']=$globalParent['url'];
  917.                     $l2MenuElements[$i]['url']=$ctg['url'];
  918.                     if($ctg['id']==$currentID OR $ctg['id']==$currentIID)
  919.                     $l2MenuElements[$i]['class']='active';
  920.                     else
  921.                     $l2MenuElements[$i]['class']='inline';
  922.                 }
  923.                 }
  924.                 if($level == 3)
  925.                 {
  926.                 if($ctg['iid']==$currentID OR $ctg['iid']==$currentIID)
  927.                 {
  928.                     $middleMenuElements[$i]['name'] = $ctg['name'.$baselang];
  929.                     $middleMenuElements[$i]['lang'] = $lang;
  930.                     $middleMenuElements[$i]['part'] = $globalParent['url'];
  931.                     $middleMenuElements[$i]['url'] = $ctg['url'];
  932.                     if($ctg['id']==$currentID OR $ctg['id']==$currentIID)
  933.                     $middleMenuElements[$i]['class']='active';
  934.                     else
  935.                     $middleMenuElements[$i]['class']='inline';
  936.                 }
  937.                 }
  938.             }
  939.             }
  940.             else
  941.             {
  942.             if($level == 1)
  943.             {
  944.                 if($ctg['iid']==$globalParent['id'])
  945.                 {
  946.                 $levelOne[$i]['name']=$ctg['name'.$baselang];
  947.                 $levelOne[$i]['lang']=$lang;
  948.                 $levelOne[$i]['part']=$globalParent['url'];
  949.                 $levelOne[$i]['url']=$ctg['url'];
  950.                 }
  951.             }
  952.             }
  953.             $i++;
  954.         }
  955.  
  956.                 if($emptyCategoryFlag != true)
  957.                 {
  958.                     $tpl->set('#menuSidebar',null,null);
  959.                     $tpl->set('.levelPartMenu',null,$levelOne);
  960.                     $tpl->set('.menuLevelTwo',null,$l2MenuElements);
  961.                     $tpl->set('.middleMenuElement',null,$middleMenuElements);
  962.                     $tpl->set('#mainCategoryName',null,array('name'=>$globalParent['name'.$baselang],'lang'=>$lang,'url'=>$globalParent['url']));
  963.  
  964.                 }
  965.                 else
  966.                  $tpl -> set ("#emptyCategory", null, array('message'=>$emptyCategoryMessage));
  967.  
  968.         if($catalogueTplId=='items'){
  969.  
  970.                
  971.                
  972.  
  973.  
  974.             if(!empty($uri['2'])){
  975.             $tpl->set('#filters','def',Array(
  976.                 'minprice'=>$minprice,
  977.                 'maxprice'=>$maxprice
  978.             ));
  979.            
  980.             if(count($filters))
  981.                 $tpl->set('#filtersHead','def',Array('header'=>'Отфильтровать'));
  982.            
  983.             $tpl->set('.filtersItemsList',null,$filters);
  984.             $tpl->set('#filterJs');
  985.                     }
  986.         }else if($catalogueTplId=='root'){
  987.             //fuck
  988.        
  989.         }else{
  990.            
  991.         }
  992.        
  993.        
  994.                
  995.  
  996.                 if(empty($uri['4']) OR (!empty($uri['4']) AND preg_match('/^page[0-9]{1,3}$/',$uri['4'])))
  997.         $pageList = null;
  998.                 if(!empty($uri['2']) AND (!empty($uri['3']) AND preg_match('/^page[0-9]{1,3}$/',$uri['3'])))
  999.                             $pageList.=createPagesList($uri['2']);
  1000.                     else if(!empty($uri['2']) AND (empty($uri['3'])))
  1001.                             $pageList.=createPagesList($uri['2']);
  1002.                     else if(!empty($uri['2']) AND (!empty($uri['3']) AND !preg_match('/^page[0-9]{1,3}$/',$uri['4'])))
  1003.                             $pageList.=createPagesList($uri['3']);
  1004.                     else if(!empty($uri['2']) AND (!empty($uri['3']) AND preg_match('/^page[0-9]{1,3}$/',$uri['4'])))
  1005.                             $pageList.=createPagesList($uri['3']);
  1006.     }else if ($contentAction=="comparison"){
  1007.         if(isset($_SESSION['UID'])){
  1008.             $UID = $_SESSION['UID'];
  1009.             $it = $db->queryAllRecords("select * from `basketitems` where `uid`='$UID'");
  1010.             $_SESSION['basket'] = Array();
  1011.             foreach($it as $e){
  1012.                 $_SESSION['basket'][] = Array($e['itemid'],$e['size'],$e['type'],$e['price']);
  1013.             }
  1014.         }
  1015.         $fills = Array('name','price');
  1016.         $fillsL = Array('Товар','цена');
  1017.         $lables = Array();
  1018.         $typs = Array();
  1019.         $items = Array();
  1020.         $qItems = Array();
  1021.         for($i=0;$i<count($_SESSION['basket']);$i++){
  1022.             $fly = Array();
  1023.             $itemData = $db->queryOneRecord("select * from `items` where `id`='".$_SESSION['basket'][$i][0]."'");
  1024.             $qItems[] = $itemData;
  1025.             $lines = explode(';',$itemData['table']);
  1026.             foreach($lines as $l){
  1027.                 $itLi = explode('—',$l);
  1028.                 $name = $itLi[0];
  1029.                 $teg = toTeg($name);
  1030.                 $fly[]= Array($teg,$itLi[1]);
  1031.                 $test = true;
  1032.                 foreach($typs as $t){
  1033.  
  1034.                     if($t==$teg)
  1035.                         $test = false;
  1036.                 }
  1037.                 if($test && !empty($teg)){
  1038.                     $typs[] = $teg;
  1039.                     $lables[] = $name;
  1040.                 }
  1041.             }
  1042.             $items[$i] = $fly;
  1043.         }
  1044.         $tdTpl = $tpl->set('#tdTpl',null,null,true);
  1045.         $trTpl = $tpl->set('#trTpl',null,null,true);
  1046.         $co = 0;
  1047.         foreach($fills as $f){
  1048.             $td = null;
  1049.             for($i=0;$i<count($_SESSION['basket']);$i++){
  1050.                 $itemId = $_SESSION['basket'][$i][0];
  1051.                 $val = $qItems[$i][$f];
  1052.  
  1053.                 if($f=='price'){
  1054.                     $val = $val*$currency.'грн '.$val.'$';
  1055.                 }
  1056.  
  1057.        
  1058.                 $td .= $tpl->replace($tdTpl,Array('content'=>$val));
  1059.             }
  1060.             $tr .= $tpl->replace($trTpl,Array(
  1061.                 'content'=>$td,
  1062.                 'lable'=>null,
  1063.                 'class'=>(($co==0)?'name':null)
  1064.             ));
  1065.             $co++;
  1066.         }
  1067.         $classCounter = 0;
  1068.         for($j=0;$j<count($typs);$j++){
  1069.             $t = $typs[$j];
  1070.             $l = $lables[$j];
  1071.             $td = null;
  1072.             for($i=0;$i<count($items);$i++){
  1073.                 $test = true;
  1074.                 foreach($items[$i] as $it){
  1075.                     if($it[0]==$t){
  1076.                         $value = $it[1];
  1077.                    
  1078.                         $td .= $tpl->replace($tdTpl,Array('content'=>$value));
  1079.                         $test = false;
  1080.                     }
  1081.                 }
  1082.                 if($test){
  1083.                     $td .= $tpl->replace($tdTpl,Array('content'=>'—'));
  1084.                 }
  1085.             }
  1086.             $class = ($classCounter%2==0)?' class="line"':'';
  1087.             $tr .= $tpl->replace($trTpl,Array('content'=>$td,'lable'=>$l));
  1088.             $classCounter++;
  1089.         }
  1090.         $tpl->set("#comp",null,Array('content'=>$tr));
  1091.     }else if($contentAction=="info"){
  1092.         $tpl->set('#info','index');
  1093.         $path = $db->queryAllRecords("select * from `articlepart` order by `ind` DESC");
  1094.         foreach($path as &$pth){
  1095.             if($pth['url']==$uri['2']) $pth['tpl']='active';
  1096.         }
  1097.         $tpl->set('.infoPath',null,$path);
  1098.         if(empty($uri[2])){
  1099.             $infoTplPosition = 'index';
  1100.             $tpl->set('#indexImage');
  1101.             $headersTpl = Array('#newHeader','#rewHeader');
  1102.             $templates = Array('.infoIndexNewsTheme','.infoIndexReviewsTheme');
  1103.             $parts = $db->queryAllRecords("select `name`,`url`,`id` from `articlepart` order by `ind` ASC limit 2");
  1104.             $counter = 0;
  1105.             foreach($parts as $p){
  1106.                 $news = $db->queryAllRecords("select * from `articles` where `iid`='{$p['id']}' order by `ind` DESC limit 5");
  1107.                 foreach($news as &$n){
  1108.                     $n['comments'] = countComments('articles',$n['id']);
  1109.                     $n['part'] = $p['url'];
  1110.                 }
  1111.                 $tpl->set($headersTpl[$counter],null,Array('name'=>$p['name']));
  1112.                 $tpl->set($templates[$counter],null,$news);
  1113.                 $counter++;
  1114.             }
  1115.         }else if(!empty($uri[2]) && empty($uri[4])){
  1116.             $infoTplPosition = 'list';
  1117.             $page = $db->queryOneRecord("select `id`,`name`,`url` from `articlepart` where `url`='{$uri[2]}'");
  1118.             if(empty($page))header("location: /404");
  1119.             $pageName = $page['name'];
  1120.         }else if(!empty($uri[4])){
  1121.             $infoTplPosition = 'page';
  1122.         }
  1123.         $tpl->set('#container',$infoTplPosition,Array(
  1124.             'name'=>$pageName
  1125.         ));
  1126.         if($infoTplPosition == 'index'){
  1127.             $news = $db->queryAllRecords("select * from `articles` where `iid`='247' limit 5");
  1128.             $reviews = $db->queryAllRecords("select * from `articles` where `iid`='246' limit 5");
  1129.             foreach($news as &$i){
  1130.                 $i['part'] = $page['news'];
  1131.                 $i['page'] = 0;
  1132.             }
  1133.             foreach($reviews as &$i){
  1134.                 $i['part'] = $page['Obzor'];
  1135.                 $i['page'] = 0;
  1136.             }
  1137.            
  1138.             $tpl->set('.infoIndexNewsTheme',null,$news);
  1139.             $tpl->set('.infoIndexReviewsTheme',null,$reviews);
  1140.        
  1141.         }else if($infoTplPosition == 'list'){
  1142.             $counts = $db->queryAllRecords("select `id` from `articles` where `iid`='{$page['id']}'");
  1143.             $counts = count($counts);
  1144.            
  1145.             $leedsOnPage = 6;
  1146.             if($counts>$leedsOnPage){
  1147.                
  1148.                 $pageId = $uri[3];
  1149.                 if(!empty($pageId)){
  1150.                     $pageId = explode("-",$pageId);
  1151.                     $pageId = intval($pageId[1]);
  1152.                 }else $pageId = 1;
  1153.                 if($pageId==0)$pageId=1;
  1154.                
  1155.                 $pageId--;
  1156.                
  1157.                 $leftLimit = $pageId*$leedsOnPage;
  1158.                 $rightLimit = $leedsOnPage;
  1159.                
  1160.                 $pageLables = Array('Предыдущая','Следующая');
  1161.                 $PC = 0;
  1162.                 foreach($pageLables as $lable){
  1163.                     $fly = Array();
  1164.                     $tmpId = $pageId+$PC;
  1165.                    
  1166.                     if($tmpId==0){
  1167.                         $tmpId = 1;$fly['tpl']='passive';
  1168.                     }else if($tmpId>$counts-1){
  1169.                         $tmpId = $counts;
  1170.                     }
  1171.                    
  1172.                     $fly['part']=$uri[2];
  1173.                     $fly['id']=$tmpId;
  1174.                     $fly['name']=$lable;
  1175.                    
  1176.                     $pages[] = $fly;
  1177.                     $PC=2;
  1178.                 }
  1179.                 $tpl->set('.pageSlider',null,$pages);
  1180.                 $limit = "limit $leftLimit,$rightLimit";
  1181.             }else{
  1182.                 $tpl->set('#pagesEmpty');
  1183.             }
  1184.        
  1185.        
  1186.             $items = $db->queryAllRecords("select * from `articles` where `iid`='{$page['id']}' $limit");
  1187.             foreach($items as &$i){
  1188.                 $i['part'] = $page['url'];
  1189.                 $i['page'] = 0;
  1190.             }
  1191.             $tpl->set('.infoNewsTheme',null,$items);
  1192.            
  1193.            
  1194.            
  1195.            
  1196.         }else{
  1197.             $item = $db->queryOneRecord("select * from `articles` where `url`='{$uri[4]}'");   
  1198.             if(empty($item))header("location: /404");          
  1199.            
  1200.             $item['comments'] = createComments($item['id']);
  1201.            
  1202.             $tpl->set('#pageContainer','def',$item);
  1203.         }
  1204.     }else if($contentAction=="cart"){
  1205.     //print_r($_SESSION['basket']);
  1206.         $cartAction = !empty($uri['2'])?$uri['2']:'index';
  1207.         $cartPage = 'index';
  1208.             $tpl->set('#cartOrderGet',$uotpl,null);
  1209.             $tpl->set('#cartSummT',$uotpl,null);
  1210.         if(!empty($UID)){
  1211.             $itemsPrew = $db->queryAllRecords("
  1212.                 select DISTINCT
  1213.                 `items`.`id`,`items`.`iid`,`items`.`url`,`items`.`id` as `itemid`,`name`,`price`,`price`,`size`,`file3` from `items`,`basketitems`
  1214.                 where `items`.`id` in
  1215.                 (select `itemid` from `basketitems` where `uid`='$UID' and `type`='prew')
  1216.             ");
  1217.  
  1218.             $itemsTrue = $db->queryAllRecords("
  1219.                 select DISTINCT
  1220.                 `items`.`id`,`items`.`iid`,`items`.`action`,`items`.`url`,`items`.`id` as `itemid`,`name`,`name_en`,`name_ua`,`items`.`actionprice`,`price`,`price`,`size`,`file3` from `items`,`basketitems` where `items`.`id` in
  1221.                 (select `itemid` from `basketitems` where `uid`='$UID' and `type`='')
  1222.             ");
  1223.         }else{
  1224.             if(count($_SESSION['basket'])>0){
  1225.             foreach($_SESSION['basket'] as $b){
  1226.                 $fly = Array();
  1227.                 $fly = $db->queryOneRecord("select * from `items` where `id`='{$b[0]}'");
  1228.                 $fly['size'] = $b[1];
  1229.                 $fly['itemid'] = $b[0];
  1230.                 if($b[2]=='prew') $itemsPrew[] = $fly;
  1231.                 else $itemsTrue[] = $fly;
  1232.             }
  1233.             }
  1234.  
  1235.         }
  1236.  
  1237.  
  1238.  
  1239.         $summCount = count($itemsPrew)+count($itemsTrue);
  1240.         if($summCount==0) $cartPage = 'empty';
  1241.            
  1242.  
  1243.         $summ = null;
  1244.         for($i=0;$i<2;$i++){
  1245.             $e = ($i==0)? $itemsPrew : $itemsTrue;
  1246.             if(!empty($e)){
  1247.             foreach($e as &$item){
  1248.             if($item['action']=='true') $item['price']=$item['actionprice'];
  1249.                 if($lang=='' OR $lang=='/ru' OR $lang=='/ua')
  1250.                 {
  1251.                
  1252.                 $item['price'] = roundPrice('uah',$item['price']);    
  1253.                 $item['cost']=$item['price']*$item['size'];
  1254.                 }
  1255.                 else
  1256.                 {
  1257.                 $item['price'] = roundPrice('eur',$item['price'],$EUR['value']);
  1258.                 $item['cost']=$item['price']*$item['size'];
  1259.                 }
  1260.                 $summ += $item['cost'];
  1261.                 $p = getParentRec($item['iid']);
  1262.                 $b = getParent($item['iid']);
  1263.                 $item['part']=$p['url'];
  1264.                 $item['brand']=$b['url'];
  1265.                 if (file_exists($_SERVER['DOCUMENT_ROOT'].'/items_img/'.$item['iid'].'/'.$item['id'].'/'.$item['url'].'-prev.jpg'))  
  1266.                                             $item['file2']='/items_img/'.$item['iid'].'/'.$item['id'].'/'.$item['url'].'-prev.jpg';
  1267.                 //}else if(!empty($item['file1']) && file_exists("gallery/photo/{$item['file1']}")){
  1268.                 //  $item['file2']="/gallery/photo/{$item['file1']}";
  1269.                 //}else{
  1270.                 //  $item['file2']="/img/nophoto.png";
  1271.                 //}
  1272.                
  1273.                 if($i==1)$summ+=$item['price2'];
  1274.             }
  1275.             }
  1276.             if($i==0)
  1277.                 $itemsPrew  = $e;
  1278.             else
  1279.                 $itemsTrue  = $e;
  1280.  
  1281.         }
  1282.         $fills = Array('name','phone','email','text','deliver','buy');
  1283.         foreach($fills as $f) $form[$f]=$_POST[$f];
  1284.  
  1285.  
  1286.         if($summCount>1){
  1287.             $tpl->set('#cartComparsion','else');
  1288.         }
  1289.         $tpl->set('#cartBody',$cartAction,$form);
  1290.  
  1291.         $tpl->set("#cartPage",$cartPage);
  1292.         $tpl->set("#reserverHeader",$uotpl,null);
  1293.         //$tpl->set("#reserverHeader2",$uotpl,null);
  1294.         //$tpl->set('.reserverItems'.$uotpl,null,$itemsPrew);
  1295.         $tpl->set('.orderItems'.$uotpl,null,$itemsTrue);
  1296.         $tpl->set('#cartSummT',$uotpl,null);
  1297.         if($cartAction=='order'){
  1298.         if(empty($itemsTrue))
  1299.             header('location:/cart');
  1300.             $delivery = $db->queryAllRecords("select * from `listmenu` where `type`='deliver' order by `id`");
  1301.             foreach($delivery as &$d){
  1302.                 if($d['id']==$_POST['deliver'])$d['selected']='selected="selected"';
  1303.                 else $d['selected']=null;
  1304.             }
  1305.  
  1306.             $buy = $db->queryAllRecords("select * from `listmenu` where `type`='pay' order by `id`");
  1307.             foreach($buy as &$d){
  1308.                 if($d['id']==$_POST['buy'])$d['selected']='selected="selected"';
  1309.                 else $d['selected']=null;
  1310.             }
  1311.             if(!empty($_SESSION['UID']))
  1312.             $userData = $db->queryOneRecord("SELECT * FROM `buyers` WHERE `id`={$_SESSION['UID']}");
  1313.             else
  1314.             $userData = array();
  1315.             $tpl->set('#payName',$uotpl,array('name'=>$userData['name']));     
  1316.             $tpl->set('#payPhone',$uotpl,array('phone'=>$userData['phone']));
  1317.             $tpl->set('#payMail',$uotpl,array('email'=>$userData['email']));   
  1318.             $tpl->set("#payDetails",$uotpl,null);
  1319.             $tpl->set('.payType','def',$buy);
  1320.             $tpl->set('#payHeader',$uotpl,$buy);
  1321.             $tpl->set('.delivery','def',$delivery);
  1322.             $tpl->set('#orderContent',$uotpl,null);
  1323.             $tpl->set('#cartSumm',$uotpl,Array('summ'=>$summ));
  1324.             $tpl->set('.orderItems'.$uotpl,'def',$itemsTrue);
  1325.         }
  1326.         else if ($cartAction == 'finish')
  1327.         {
  1328.             //print_r($_REQUEST);
  1329.             if($_SESSION['UID']!='')
  1330.                 $tpl->set('#payFinish',$uotpl,null);
  1331.             else
  1332.                 $tpl->set('#payFinish',$uotpl,array());
  1333.  
  1334.         }
  1335.         else
  1336.         {
  1337.         $tpl->set('.reserverItems'.$uotpl,null,$itemsTrue);
  1338.         }
  1339.         if($_POST['action']=='buy'){
  1340.             //print_r($_POST);
  1341.             if(!empty($form['name']) && $form['phone']){
  1342.                 if(!empty($itemsTrue)){
  1343.  
  1344.                     if(!empty($form['deliver'])){
  1345.                         foreach($delivery as $d){
  1346.                             if($d['id']==$form['deliver']){
  1347.                                 $form['deliver'] = $d['name'];
  1348.                             }
  1349.                         }
  1350.                     }
  1351.  
  1352.                     if(!empty($form['buy'])){
  1353.                         foreach($buy as $d){
  1354.                             if($d['id']==$form['buy']) $form['buy'] = $d['name'];
  1355.                         }
  1356.                     }
  1357.  
  1358.                     foreach($form as $k=>$f){
  1359.                         $fillsStr .= "`$k`='$f',";
  1360.                     }
  1361.  
  1362.                     $newId = $db->queryOneRecord("SELECT MAX(id) FROM `orders`");$newId=$newId[0]+1;
  1363.                     $q = "
  1364.                         insert into `orders` set
  1365.                         `id`='$newId',
  1366.                         `iid`='$UID',
  1367.                         `type`='new',
  1368.                         $fillsStr
  1369.                         `currency`='$currency'
  1370.                     ";
  1371.  
  1372.                     $insert = $db->query($q);
  1373.                     //fuck
  1374.                     //print_r($itemsTrue);
  1375.                     foreach($itemsTrue as $it){
  1376.                     if($it['action']=='true') $it['price']=$it['actionprice'];
  1377.                         $insert = $db->query("
  1378.                             insert into `orderitems` set
  1379.                             `iid`='$newId',
  1380.                             `itemid`='{$it['itemid']}',
  1381.                             `count`='{$it['size']}',
  1382.                             `buyprice`='{$it['price']}'
  1383.                         ");
  1384.                     }
  1385.                     if(!empty($UID)){
  1386.                         $delete = $db->query("delete from `basketitems` where `uid`='$UID' and `type`=''");
  1387.                     }else{
  1388.                         //print_r($_SESSION['basket']);
  1389.                         $baskLen = count($_SESSION['basket']);
  1390.                         for($i=0;$i<$baskLen;$i++){
  1391.                             //print_r($_SESSION['basket']);
  1392.                             //$_SESSION['basket'][$i][2];
  1393.                             if($_SESSION['basket'][$i][2]==''){
  1394.                                 //echo $_SESSION['basket'][0];
  1395.                                 unset($_SESSION['basket'][$i]);
  1396.                                 //array_splice($_SESSION['basket'], $i, 1, null);
  1397.                                 //$i--;
  1398.                             }
  1399.                         }
  1400.                     }
  1401.                    
  1402.                     /* === */
  1403.  
  1404.  
  1405.  
  1406.                     $msg = ('Пользователь <a href="http://conquistador.com.ua/admin/ru/orders/new/">оформил заказ</a>');
  1407.                     SendMsgToAdmins('Оформлен заказ!', $msg);
  1408.  
  1409.  
  1410.                     header("location: $lang/cart/finish");
  1411.                 }
  1412.             }
  1413.         }
  1414.  
  1415.  
  1416.     }
  1417.  
  1418.     else if($contentAction=="content"){
  1419.         if(!empty($uri[3])) header("location: /404");
  1420.         //fuck
  1421.    
  1422.         $lnk = $uri[2];
  1423.         $article = $db->queryOneRecord("select * from `sitecontent` where `url`='$lnk'");
  1424.         if(empty($article)) header("location: /404");
  1425.        
  1426.  
  1427.         $metaArray = Array(
  1428.             'keywords'    => $article['keywords'],
  1429.             'description' => $article['description'],
  1430.             'title'       => $article['title']
  1431.         );
  1432.        
  1433.  
  1434.         $setArray['name']= $article['name'];
  1435.         $setArray['caption']=$article['caption'];
  1436.         $setArray['text']=$article['text'];
  1437.  
  1438.         $tpl->set('#module','index',$setArray);
  1439.  
  1440.     }else if($contentAction=="account"){
  1441.  
  1442.         $tpl->set('#globalClass','def',Array('class'=>$contentAction));
  1443.  
  1444.  
  1445.             if($UID!=''){
  1446.                 $display='none';
  1447.             if($_POST['action']=='update'){
  1448.                     $display='block';
  1449.                     $userinfocurrent=$db->queryOneRecord("SELECT * FROM `buyers` WHERE `id`='$UID'");
  1450.                     if(check_pwd($_POST['password'],$userinfocurrent['password']) AND check_pwd($_POST['password2'],$userinfocurrent['password'])){
  1451.                     $name = $_POST['name'];
  1452.                     $phone = $_POST['phone'];
  1453.                     $password = hash_pwd($_POST['password']);
  1454.             $email = $_POST['email'];
  1455.                     $pref = "UPDATE `buyers` SET";
  1456.                     $postf = "WHERE `id`='$UID'";
  1457.                     $db->query("$pref `name`='$name',`phone`='$phone', `password`='$password',`email`='$email' $postf");
  1458.                     $userActionResult='�?нформация успешно обновлена';
  1459.                     }else{
  1460.                         $userActionResult='Неверный пароль или пароли не совпадают!';
  1461.                     }
  1462.                     //header('location:/account');
  1463.  
  1464.             }if($_POST['action']=='chpass'){
  1465.                     $display='block';
  1466.                     $userinfocurrent=$db->queryOneRecord("SELECT * FROM `buyers` WHERE `id`='$UID'");
  1467.                     if(check_pwd($_POST['oldpassword'],$userinfocurrent['password'])
  1468.                             AND $_POST['newpassword']==$_POST['newpassword2']){
  1469.  
  1470.                     $password = hash_pwd($_POST['newpassword']);
  1471.                     $pref = "UPDATE `buyers` SET";
  1472.                     $postf = "WHERE `id`='$UID'";
  1473.                     $db->query("$pref `password`='$password' $postf");
  1474.                     $userActionResult='Пароль успешно изменен';
  1475.                     }else{
  1476.                         $userActionResult='Неверный пароль или пароли не совпадают!';
  1477.                     }
  1478.                     //header('location:/account');
  1479.         }
  1480.  
  1481.         $fills = Array('id','date','name','phone','type','summ');
  1482.         $Array = $db->queryAllRecords("select * from `orders` WHERE `iid`='".$UID."' order by `date` DESC");
  1483.         if($lang=='' OR $lang=='/ru')
  1484.             {
  1485.             $itemsTr = $tpl->set('#orderItemsList','def',null,true);
  1486.             $uotpl = '';
  1487.             }
  1488.             else if ($lang=='/ua')
  1489.             {
  1490.             $itemsTr = $tpl->set('#orderItemsList','ua',null,true);
  1491.             $uotpl = 'Ua';
  1492.             }
  1493.             else if ($lang=='/en')
  1494.             {
  1495.             $itemsTr = $tpl->set('#orderItemsList','en',null,true);
  1496.             $uotpl = 'En';
  1497.             }
  1498.             $tpl->set('#userData',$uotpl,null);
  1499.             $tpl->set('#userChpass',$uotpl,null);
  1500.             $tpl->set('#accountHeader',$uotpl,null);
  1501.         $tableHtml = null;
  1502.  
  1503.         if(count($Array)>0){
  1504.             $tpl->set('#basket','cart',null);
  1505.  
  1506.             $tpl->set('#userOrdersHeader',$uotpl,null);
  1507.             foreach($Array as &$e){
  1508.                 $buyCurrency = $e['currency'];
  1509.                 $summ = null;
  1510.                 $inline = null;
  1511.                 $total = null;
  1512.                 $positions = null;
  1513.  
  1514.                 $items = $db->queryAllRecords("SELECT `items`.`id` as `itemid`,`items`.`price`,`items`.`name`,`items`.`name_en`,`items`.`name_ua`,`items`.`url`,`orderitems`.`buyprice`,`orderitems`.`count` FROM `items` JOIN `orderitems` ON `items`.`id`=`orderitems`.`itemid` AND `orderitems`.`iid`='{$e['id']}' WHERE `items`.`id` IN (SELECT `itemid` FROM `orderitems` WHERE `iid`={$e['id']})");
  1515.                 //print_r($items);
  1516.  
  1517.                 $tmpId = null;
  1518.                 foreach($items as &$f){
  1519.                     //print_r($f);
  1520.                     if($lang=='/ua' OR $lang=='' OR $lang=='/ru')
  1521.                     {
  1522.                         $price = roundPrice('uah',$f['price']);
  1523.                     $f['price']=$price;
  1524.                         $f['buyprice']=roundPrice('uah',$f['buyprice']);
  1525.                     }
  1526.                     else
  1527.                     {
  1528.                     $tmplt = 'en';
  1529.                         $price = roundPrice('eur',roundPrice('uah',$f['price']),$EUR['value']);
  1530.                         $f['price']=$price;
  1531.                         $f['buyprice']=roundPrice('eur',$f['buyprice'],$EUR['value']);
  1532.                     }
  1533.                     $summ = $f['count']*$f['buyprice'];
  1534.                     $f['cost'] = $summ;
  1535.                     $total += $summ;
  1536.  
  1537.                     if($f['itemid']!=$tmpId){
  1538.                         $positions .= $tpl->replace($itemsTr,$f);
  1539.                         $tmpId = $f['itemid'];
  1540.                     }
  1541.                 }
  1542.                 $date = explode(" ",$e['date']);
  1543.                 $day = explode("-",$date[0]);
  1544.                 $time = $date[1];
  1545.                 $e['date'] = "{$day[2]}.{$day[1]}.{$day[0]} в {$date[1]}";
  1546.  
  1547.                 $e['items'] = $positions;
  1548.                 $e['total'] = $total;
  1549.             }//
  1550.  
  1551.             $tpl->set('.userOrders'.$uotpl,'def',$Array);
  1552.         }else{
  1553.             $tpl->set('#basket','empty'.$uotpl,null);
  1554.        }
  1555.  
  1556.  
  1557.                           //#basket empty{{
  1558.  
  1559.  
  1560.         $B = $db->queryOneRecord("select * from `buyers` where `id`='$UID'");
  1561.         $bName=$B['name'];
  1562.         $bPhone=$B['phone'];
  1563.         $bMail=$B['email'];
  1564.         $bPass=$B['password'];
  1565.         $bPass2=$B['password'];
  1566.  
  1567.  
  1568.  
  1569.             }
  1570.             else{
  1571.                 Header("location:/signin");
  1572.             }
  1573.         $tpl->set('#position','account',Array(
  1574.             'userName'=>$bName,
  1575.             'userPhone'=>$bPhone,
  1576.             'email'=>$bMail,
  1577.         ));
  1578.  
  1579.     }else if($contentAction=="signin" ){
  1580.         $tpl->set('#globalClass','def',Array('class'=>$contentAction));
  1581.         $tpl->set('#position','login',null);
  1582.         if($uri['2']=='recovered')
  1583.         {
  1584.             $tpl->set('#msg',null,array('msg'=>'Новый пароль отправлен на указанный e-mail адрес'));
  1585.         }
  1586.         else
  1587.         {
  1588.         $tpl->set('#signTitle',null,null);
  1589.         $tpl->set('#tabTitles',null,null);
  1590.         if($UID==''){
  1591.                 if($_POST['action']=='restorepw'){
  1592.                   restore_pwd($_POST['email']);
  1593.                 }
  1594.  
  1595.         if($_POST['action']=='register' || $_POST['action']=='update'){
  1596.  
  1597.             $name = $_POST['name'];
  1598.             $password = $_POST['password'];
  1599.             $email = $_POST['email'];
  1600.             $phone = $_POST['phone'];
  1601.             $arr = Array('phone','password','password2','name');$necessarily = $arr;
  1602.             $mach = Array('phone','name');
  1603.             $val = sign('buyers',$arr,$necessarily,$mach);
  1604.             if($val==true){
  1605.                 if($_POST['action']=='register'){
  1606.                     $newId = $db->queryOneRecord("SELECT max( id ) FROM `buyers`");$newId=$newId[0]+1;
  1607.                     $pref = "
  1608.                     INSERT INTO `buyers` SET
  1609.                     `id`='$newId',
  1610.                     ";
  1611.                     $postf = null;
  1612.                 }else{
  1613.                     $pref = "UPDATE `buyers` SET";
  1614.                     $UID = $_SESSION['UID'];
  1615.                     $postf = "WHERE `id`='$UID'";
  1616.                 }
  1617.                 $items = $db->query("
  1618.                 $pref
  1619.                `name`='$name',`password`='".hash_pwd($password)."',`email`='$email',`phone`='$phone' $postf");
  1620.  
  1621.                if($_POST['action']=='register'){
  1622.                     $_SESSION['UID'] = $newId;
  1623.                     header( 'Location: /account') ;
  1624.                }
  1625.             }else{
  1626.                 $alert = $val;
  1627.             }
  1628.         }else if($_POST['action']=='login'){
  1629.  
  1630.  
  1631.             $phone_chk=validate_phone($_POST['phone']);
  1632.             if($phone_chk!=false){
  1633.                 $user_pw=$db->queryOneRecord("SELECT * FROM `buyers` WHERE `phone`='".$phone_chk."'");
  1634.                 $val = check_pwd($_POST['password'],$user_pw['password']);
  1635.  
  1636.                 if($val==true){
  1637.                     $phone=$_POST['phone'];
  1638.                     $B = $db->queryOneRecord("select * from `buyers` where `phone`='$phone'");
  1639.                     $_SESSION['UID'] = $B['id'];
  1640.                                     Header('Location:/account');
  1641.                 }
  1642.             }else{
  1643.  
  1644.             }
  1645.  
  1646.         }
  1647.  
  1648.             $Header = 'Авторизация';
  1649.             $sabmitLable = 'Зарегистрироваться';
  1650.             $actionReg = 'register';
  1651.             $prewForm = null;
  1652.  
  1653.             $alert=null;
  1654.             $email = null;
  1655.             $password = null;
  1656.             $password2 = null;
  1657.             $name = null;
  1658.  
  1659.             $email = $_POST['email'];
  1660.             $password = $_POST['password'];
  1661.             $password2 = $_POST['password2'];
  1662.             $name = $_POST['name'];
  1663.  
  1664.  
  1665.         }else{
  1666.             Header('Location:/account');
  1667.         }
  1668.  
  1669.         $tpl->set('#fills','def',Array(
  1670.             'name'=>null,
  1671.             'email'=>null,
  1672.             'password'=>null,
  1673.             'password2'=>null
  1674.         ));
  1675.        
  1676.         }
  1677.    
  1678.     }else if($contentAction=="logout"){
  1679.         session_destroy();
  1680.         Header('Location:/');
  1681.  
  1682.     }else if($contentAction=="map"){
  1683.  
  1684.      $lang = (empty($lang)) ? 'ru' : str_replace('/','',$lang);
  1685.         $filename = "tpl/sitemap_". $lang . ".html";
  1686.        
  1687.         if (!file_exists($filename) or !is_readable($filename)) $smdata = "Failed to read sitemap file $filename";
  1688.         else  $smdata = file_get_contents ($filename);
  1689.  
  1690.      $tpl->set('#sitemap-container',null, array('sm-content' => $smdata));
  1691.  
  1692.  }else if($contentAction=="mail"){
  1693.  
  1694.             if(!empty($_SESSION['feedBackUserName'])) $nameSend = $_SESSION['feedBackUserName'];
  1695.             if(!empty($_SESSION['feedBackUserMail'])) $emailSend = $_SESSION['feedBackUserMail'];
  1696.  
  1697.             if(isset($_SESSION['userId'])){
  1698.                 $user = $db->queryOneRecord("select * from `articles` where `id`='{$_SESSION['userId']}' limit 1");
  1699.                 $nameUser = $user['name'];
  1700.                 $mailUser = $user['email'];
  1701.             }
  1702.  
  1703.             if($_POST['action']=="feedback"){
  1704.                 $nameSend = $_POST['name'];
  1705.                 $emailSend = $_POST['email'];
  1706.                 $textSend = $_POST['text'];
  1707.  
  1708.                 if(!empty($nameSend) && !empty($emailSend) && !empty($textSend)){
  1709.                     $s_name = $_SERVER['SERVER_NAME'];
  1710.                     $items = $db->query("INSERT INTO `feedback` SET `name`='$nameSend', `email`='$emailSend', `text`='$textSend'");
  1711.  
  1712.  
  1713.                     $admins = $db->queryAllRecords("select * from `users` where `email`!=''");
  1714.                     $sub = $tplService->set('#feedBackAdminMail','def',Array(
  1715.                         'userName'=>$nameSend,
  1716.                     ),true);
  1717.  
  1718.                     $textToAdmin = $tplService->set('#feedBackAdminMail','def',Array(
  1719.                         'userName'=>$nameSend,
  1720.                         'email'=>$emailSend,
  1721.                         'text'=>$textSend
  1722.                     ),true);
  1723.  
  1724.  
  1725.                     foreach($admins as $userAdmin){
  1726.                         sendMail(
  1727.                             $userAdmin['email'],
  1728.                             $textToAdmin,
  1729.                             'Cross Feedback',
  1730.                             'Магазин '.$s_name,
  1731.                             'admin@'.$s_name
  1732.                         );
  1733.                     }
  1734.  
  1735.                     $messag = 'Сообщение успешно отправлено!';
  1736.                     $textSend = null;
  1737.                     $_SESSION['feedBackUserName'] = $nameSend;
  1738.                     $_SESSION['feedBackUserMail'] = $emailSend;
  1739.                 }else{
  1740.                     $messag = 'Необходимо заполнить все поля!';
  1741.                 }
  1742.             }
  1743.  
  1744.         $tpl->set('#fills','def',Array(
  1745.             'err'=>$messag,
  1746.             'name'=>$nameSend,
  1747.             'email'=>$emailSend,
  1748.             'text'=>$textSend,
  1749.         ));
  1750.     }
  1751.     else if($contentAction=="search"){
  1752.  
  1753.         require_once('search.php');
  1754.  
  1755.         if (empty($result)) $tpl->set('#emptyCategory', null, array('message' => 'По запросу &laquo;'.$good_query.'&raquo; ничего не найдено.'));
  1756.         else                {
  1757.             $tpl->set('#emptyCategory', null, array('message' => 'По запросу  &laquo;'.$good_query.'&raquo; найдены такие позиции:'));
  1758.             $output = $db->queryAllRecords('SELECT * FROM `items` WHERE id IN ('.implode ($result, ',').') AND `show` != "true"');
  1759.             foreach($output as &$r)
  1760.             {
  1761.                 $tmp_b=get_parent($r['iid']);
  1762.                 $tmp_p=getParentRec($r['iid']);
  1763.                 $r['part'] = $tmp_p['url'];
  1764.                 $r['brand'] = $tmp_b['url'];
  1765.                 $r['lang'] = $lang;
  1766.                 $r['price2'] = roundPrice('usd',$r['price'],$USD['value']);
  1767.                 if (file_exists($_SERVER['DOCUMENT_ROOT'].'/items_img/'.$r['iid'].'/'.$r['id'].'/'.$r['url'].'-prev.jpg'))  
  1768.                 $r['file2']='/items_img/'.$r['iid'].'/'.$r['id'].'/'.$r['url'].'-prev.jpg';
  1769.             }
  1770.             // {part} {brand} {url}
  1771.  
  1772.  
  1773.  
  1774.             $tpl->set('.catalogueItemsList', 'def', $output);
  1775.         }
  1776.  
  1777.     }
  1778.     $tpl->set('#meta','def',$metaArray);
  1779.     return $inner;
  1780. }
  1781. ?>
Advertisement
Add Comment
Please, Sign In to add comment