''){ $definedLim='1'; $defLimit=round(($curPage-1)*$perPage); } $sql=mysql_query("SELECT SQL_CALC_FOUND_ROWS ".(($rows <>'')? $rows:"*")." FROM ".$table." ".(($query <>'')? "WHERE ".$query:"")." ".(($definedLim <>'')? "LIMIT ".$defLimit.",".$perPage."":"")." ") or die("error:".mysql_error()." - SELECT ".(($rows <>'')? $rows:"*")." FROM ".$table." ".(($query <>'')? "WHERE ".$query:"")." ".(($definedLim <>'')? "LIMIT ".$defLimit.",".$perPage."":"")." "); if(mysql_num_rows($sql)>0){ while($row=mysql_fetch_assoc($sql)){ $result[]=$row; } $sql2 = "SELECT FOUND_ROWS()"; $count_row=mysql_fetch_row(mysql_query($sql2)); $counted=$count_row[0]; $results['counted']=$counted; $results['pages']=round($counted/$perPage); $results['showed']=$defLimit; $results['content']=$result; return $results; }else{ return false; } } function getRight($lang){ $sql=mysql_query("SELECT * FROM cms_category WHERE type='language' and path='/".$lang."' LIMIT 1"); $langInfo=mysql_fetch_assoc($sql); $sqlS1=mysql_query("SELECT * FROM cms_category WHERE type='folder' and parentID='".$langInfo['ID']."' ORDER BY position"); if(mysql_num_rows($sqlS1)>0){ while ($rowS1=mysql_fetch_assoc($sqlS1)) { $retS1=$rowS1; $sqlS2=mysql_query("SELECT * FROM cms_category WHERE type='folder' and parentID='".$rowS1['ID']."' ORDER BY position"); if(mysql_num_rows($sqlS2)>0){ while($rowS2=mysql_fetch_assoc($sqlS2)){ $retS2=$rowS2; $sqlS3=mysql_query("SELECT * FROM cms_category WHERE type='folder' and parentID='".$rowS2['ID']."' ORDER BY position"); if(mysql_num_rows($sqlS3)>0){ while($rowS3=mysql_fetch_assoc($sqlS3)){ $retS3=$rowS3; $sqlS4=mysql_query("SELECT * FROM cms_category WHERE type='folder' and parentID='".$rowS3['ID']."' ORDER BY position"); if(mysql_num_rows($sqlS4)>0){ while ($rowS4=mysql_fetch_assoc($sqlS4)){ $retS3['sub'][]=$rowS4; } } $retS2['sub'][]=$retS3; /******************* ****************************/ } } $retS1['sub'][]=$retS2; } } $returnS1[]=$retS1; } } // echo mysql_error(); return $returnS1; } function getElementsByNodeID($nodeID) { $arrNodePart1=$this->getNodesByparentID($nodeID); $arrNodePart2=$this->getContent($nodeID); $arrCurNode->folders=$arrNodePart1; $arrCurNode->content=$arrNodePart2; $arrCurNode->news=$this->getNewsByID($nodeID); $arrCurNode->gallery=$this->getGalleryByID($nodeID); $arrCurNode->contact=$this->getContactFormByID($nodeID); $arrCurNode->vote=$this->getVoteByparentID($nodeID); if(!is_object($arrCurNode)){ $arrCurNode=''; } return $arrCurNode; } function getContactFormByID($nodeID) { $arrNode=$this->dbQuerySelect('','cms_contactform',"ID='".round($nodeID)."'",'',''); if(!is_array($arrNode)){ $arrNode=''; } return $arrNode['content']; } function getContactFormByparentID($nodeID) { $arrNode=$this->dbQuerySelect('','cms_contactform',"parentID='".round($nodeID)."'",'',''); if(!is_array($arrNode)){ $arrNode=''; } return $arrNode['content']; } function getGalleryByID($nodeID) { $arrNode=$this->dbQuerySelect('cms_gallery.ID,cms_gallery.title, cms_gallery.parentID, cms_gallerypictures.ID as contentID, cms_gallerypictures.title as gallerytitle, cms_gallerypictures.pictureID as picID','cms_gallery LEFT JOIN cms_gallerypictures ON cms_gallerypictures.parentID=cms_gallery.parentID',"cms_gallery.parentID='".round($nodeID)."'",'',''); if(!is_array($arrNode)){ $arrNode=''; } if(is_array($arrNode['content'])){ foreach($arrNode['content'] as $newsContent){ $nContent->ID=$newsContent['ID']; $nContent->title=$newsContent['title']; $nContent->picID=$newsContent['picID']; $nContent->contenttitle=html_entity_decode($newsContent['gallerytitle']); $nContent->contentID=$newsContent['contentID']; $nContent->parentID=$newsContent['parentID']; $news[]=$nContent; } } return $news; } function getNewsByID($nodeID,$page) { $perpage=5; if($page=='' or $page=='0'){ $page=1;} $show=round(($page-1)*$perpage); $arrNode=$this->dbQuerySelect('cms_news.ID,cms_news.title, cms_newscontent.parentID, cms_newscontent.ID as contentID, cms_newscontent.title as contenttitle, cms_newscontent.sContent, cms_newscontent.fContent, cms_newscontent.date, cms_newscontent.safename','cms_news LEFT JOIN cms_newscontent ON cms_newscontent.parentID=cms_news.parentID',"cms_news.parentID='".round($nodeID)."' ORDER BY cms_newscontent.ID DESC",'5',$page); if(!is_array($arrNode)){ $arrNode=''; } if(is_array($arrNode['content'])){ foreach($arrNode['content'] as $newsContent){ $nContent->ID=$newsContent['ID']; $nContent->title=html_entity_decode($newsContent['title']); $nContent->contenttitle=html_entity_decode($newsContent['contenttitle']); $nContent->contentID=$newsContent['contentID']; $nContent->parentID=$newsContent['parentID']; $nContent->safename=$newsContent['safename']; $nContent->sContent=html_entity_decode($newsContent['sContent']); $nContent->fContent=html_entity_decode($newsContent['fContent']); $nContent->photo=$newsContent['photo']; $nContent->date=strftime("%d-%m-%y",$newsContent['date']); $news[]=$nContent; } } //$arrNode; $news['page']=round($arrNode['counted']/$perpage); //echo $ne //print_r($arrNode); //print_r($news); return $news; } function isContentByParentID($parentID){ if($this->dbQuerySelect('sContent,fContent','cms_content',"parentID='".round($parentID)."'",'','')){ return 1; }else{ return 0; } } function getNodePathesByID($ID){ $subNodes=$this->dbQuerySelect('','cms_category',"parentID='".round($ID)."' and hidden=0 ORDER BY position",'',''); } function getElemtntsByPath($path) { if($byPath=$this->getNodeByPath($path)){ $res->ID=$byPath->ID; $res->elements=$this->getElementsByNodeID($byPath->ID); return $res; }else{ return false; } } function getLangs() { $langs=$this->dbQuerySelect('','cms_category','type="language"','',''); return $langs['content']; } function getNodesAndContentByparentID($ID){ $subNodes=$this->getNodesByparentID($ID); if(is_array($subNodes)){ foreach($subNodes as $subNode){ $result->content=$this->getContent($subNode['ID']); $result->info=$subNode; $returno[]=$result; } return $returno; } } function getStructureByPath($path) { $sql=mysql_query("SELECT * FROM cms_category WHERE path='".$path."' and type='article' ORDER BY position LIMIT 1"); $row=mysql_fetch_assoc($sql); $rWork->title=$row['title']; $rWork->ID=$row['ID']; $rWork->parentID=$row['parentID']; $rWork->path=$row['path']; $rWork->content=$this->getContent($row['ID']); $rWork->vote=$this->getVoteByparentID($row['ID']); return $rWork; } function getNodeByPath($path,$page,$params) { //echo "PATH::::::::::::::::::".$path; $sql=mysql_query("SELECT * FROM cms_category WHERE path='".$path."' and hidden=0 ORDER BY position"); while($ro=mysql_fetch_assoc($sql)){ $rWork->title=$ro['title']; $rWork->ID=$ro['ID']; $rWork->parentID=$ro['parentID']; $rWork->path=$ro['path']; switch($ro['type']){ case 'article': $rWork->content=$this->getContent($ro['ID']); break; case'news': $rWork->news=$this->getNewsByID($ro['ID'],$page); break; case 'gallery': $rWork->gallery=$this->getGalleryByID($ro['ID']); break; case 'contactform': $rWork->contact=$this->getContactFormByparentID($ro['ID']); break; case 'vote': $rWork->vote=$this->getVoteByparentID($ro['ID']); break; case 'catalog': //////////////////////////////////////////////////////////////////////////// break; } $rWork->type=$ro['type']; $rWork->sub=$this->getNodeByparentID($ro['ID']); $rWorks[]=$rWork; unset($rWork); } //print_r($rWorks); return $rWorks; } function getIdByPath($path,$type){ $sql=mysql_query("SELECT * FROM cms_categories WHERE path='".$this->str_rep($path)."' ".(($type<>'')?"AND type='".$this->str_rep($type)."'":"")." "); if(mysql_num_rows($sql)>0){ while ($row=mysql_fetch_assoc($sql)) { $return[]=$row; } } return $return; } function getCatalog($params,$page){ global $db,$_REQUEST; $perpage='20'; if($page=='' or $page=='0'){ $page=1;} $show=round(($page-1)*$perpage); if($params['squery']<>''){ $squery=$this->str_rep($params['squery']); } $requestForSql=''; if($params['subcategory']<>''){ $cID=$db->get_var("SELECT ID FROM cms_city WHERE safename_".$_SESSION['lang']."='".$params['subcategory']."'"); }else{ $cID=$db->get_var("SELECT ID FROM cms_city WHERE safename_".$_SESSION['lang']."='".$params['category']."'"); } /* if($params['category']<>''){ $catID=$db->get_var("SELECT ID FROM cms_city WHERE safename_".$_SESSION['lang']."='".$params['category']."'"); $requestForSql.=" AND type='".$catID."'"; } if($params['subcategory']<>''){ $catID=$db->get_var("SELECT ID FROM cms_city WHERE safename_".$_SESSION['lang']."='".$params['subcategory']."'"); $requestForSql.=" AND subtype='".$catID."'"; } */ switch ($_SESSION['sortBy']){ default: case 'name': $sortBy = 'title'; break; case 'price': $sortBy = 'p.price'; break; case 'objom': // $sortBy = 'Round(objom)'; break; } $sqls="SELECT SQL_CALC_FOUND_ROWS p.*, p.title_".$_SESSION['lang']." AS title, p.safename_".$_SESSION['lang']." AS safename, p.sdescr_".$_SESSION['lang']." AS sdescr, p.descr_".$_SESSION['lang']." AS descr, p.price FROM cms_product as p LEFT JOIN product_cats AS c ON c.pID=p.ID WHERE c.cID=".$cID." ".(($requestForSql<>'')?"".$requestForSql:'')." ORDER BY $sortBy ASC LIMIT $show, $perpage"; $sql=mysql_query($sqls); //echo $sqls; $sql2 = "SELECT FOUND_ROWS()"; $count_row=mysql_fetch_row(mysql_query($sql2)); $counted=$count_row[0]; if($counted<>'' and $counted>0) { $pages=round($counted/$perpage); } $showed=$show; while($row=mysql_fetch_assoc($sql)){ $inTheBasket = $db->get_var("SELECT qtty FROM basket_tmp WHERE prodID='".$row['ID']."' AND session='".$params['PHPSESSID']."' "); if($inTheBasket==0){ $row['inBasket']=1; }else { $row['inBasket'] = $inTheBasket; } $product=$row; $row=''; $pix=''; $retz[]=$product; $product=''; } $products->catalog=$retz; $products->pages=$pages; $products->counted=$counted; return $products; } function getTopSales($limit){ global $db; //$sql = "SELECT SUM(o.qtty) AS mq, o.prodID,p.title_".$_SESSION['lang']." AS title, p.safename_".$_SESSION['lang']." AS safename, p.sdescr_".$_SESSION['lang']." AS sdescr, p.price, p.priceDeposit, p.type, p.subtype, p.alco, p.objom, p.filename FROM basket_pro AS o LEFT JOIN cms_product AS p ON p.ID=o.prodID WHERE p.ID IS NOT NULL GROUP BY o.prodID ORDER BY mq DESC ".(($limit>0)?"LIMIT $limit":""); $sql = "SELECT title_".$_SESSION['lang']." AS title, safename_".$_SESSION['lang']." AS safename, price, photo1,ID FROM cms_product WHERE firstpage=1 ORDER BY rand() LIMIT $limit"; $alcolist = object_2_array($db->get_results($sql)); foreach ($alcolist as $pfp){ if($pfp['type']>0){ $pathProd1 = $db->get_var("SELECT safename_".$_SESSION['lang']." FROM cms_city WHERE ID='".$pfp['type']."'"); } if($pfp['subtype']>0){ $pathProd1.="/".$db->get_var("SELECT safename_".$_SESSION['lang']." FROM cms_city WHERE ID='".$pfp['subtype']."'"); } $pfp['caturl']='/'.$_SESSION['lang'].'/catalog/'.$pathProd1.''; $inTheBasket = $db->get_var("SELECT qtty FROM basket_tmp WHERE prodID='".$pfp['ID']."' AND session='".$_REQUEST['PHPSESSID']."' "); if($inTheBasket==0){ $pfp['inBasket']=1; }else { $pfp['inBasket'] = $inTheBasket; } $ret[]=$pfp; } return $ret; } function getLatestProducts($limit){ global $db; $sql = "SELECT p.title_".$_SESSION['lang']." AS title, p.safename_".$_SESSION['lang']." AS safename, p.sdescr_".$_SESSION['lang']." AS sdescr, p.price, p.photo1, p.photo2, p.photo3, p.photo4,p.photo5 FROM cms_product AS p WHERE p.ID IS NOT NULL AND p.title_".$_SESSION['lang']."!='' ORDER BY p.ID DESC ".(($limit>0)?"LIMIT $limit":""); $alcolist = object_2_array($db->get_results($sql)); foreach ($alcolist as $pfp){ if($pfp['type']>0){ $pathProd1 = $db->get_var("SELECT safename_".$_SESSION['lang']." FROM cms_city WHERE ID='".$pfp['type']."'"); } if($pfp['subtype']>0){ $pathProd1.="/".$db->get_var("SELECT safename_".$_SESSION['lang']." FROM cms_city WHERE ID='".$pfp['subtype']."'"); } $pfp['caturl']='/'.$_SESSION['lang'].'/catalog/'.$pathProd1.''; $inTheBasket = $db->get_var("SELECT qtty FROM basket_tmp WHERE prodID='".$pfp['ID']."' AND session='".$_REQUEST['PHPSESSID']."' "); if($inTheBasket==0){ $pfp['inBasket']=1; }else { $pfp['inBasket'] = $inTheBasket; } $ret[]=$pfp; } return $ret; } function getProduct($ID){ $sqls="SELECT prod.* FROM cms_product as prod WHERE ID='".round($ID)."' "; $sql=mysql_query($sqls); if(mysql_num_rows($sql)==1){ $products=mysql_fetch_assoc($sql); } if(round($products['filename'])<>'0')$products['filename']=$products['filename']; if(round($products['photo2'])<>'0')$products['photos'][]=$products['photo2']; if(round($products['photo3'])<>'0')$products['photos'][]=$products['photo3']; if(round($products['photo1'])<>'0')$products['photos'][]=$products['photo1']; if(round($products['photo4'])<>'0')$products['photos'][]=$products['photo4']; if(round($products['photo5'])<>'0')$products['photos'][]=$products['photo5']; $products['data']=strftime("%d.%m.%Y %H:%M",$products['data']); //sprint_r($products); return $products; } function getProductByTitle($ID){ global $db; $sqls="SELECT p.*,p.sdescr_".$_SESSION['lang']." AS sdescr,p.descr_".$_SESSION['lang']." AS descr FROM cms_product AS p WHERE p.safename_".$_SESSION['lang']."='".$this->str_rep($ID)."' "; //echo $sqls; $sql=mysql_query($sqls); if(mysql_num_rows($sql)==1){ $products=mysql_fetch_assoc($sql); } $inthebasket=round($db->get_var("SELECT qtty FROM basket_tmp WHERE prodID='".$products['ID']."' AND session='".$_REQUEST['PHPSESSID']."' ")); $products['inBasket']=(($inthebasket>0)?$inthebasket:1); if(round($products['filename'])<>'0')$products['filename']=$products['filename']; if(round($products['photo1'])<>'0')$products['photos'][]=$products['photo1']; if(round($products['photo2'])<>'0')$products['photos'][]=$products['photo2']; if(round($products['photo3'])<>'0')$products['photos'][]=$products['photo3']; if(round($products['photo4'])<>'0')$products['photos'][]=$products['photo4']; if(round($products['photo5'])<>'0')$products['photos'][]=$products['photo5']; $products['data']=strftime("%d.%m.%Y %H:%M",$products['data']); //print_r($products); return $products; } function getProductByUserID($ID){ $sqls="SELECT prod.* FROM cms_uprod as prod WHERE userID='".round($ID)."' AND (moder=0 OR moder=1)"; $sql=mysql_query($sqls); if(mysql_num_rows($sql)>0){ while($row=mysql_fetch_assoc($sql)){ $products[]=$row; } } return $products; } function getNodeByparentID($pID) { //echo '-----------------------------'; $sqlz=mysql_query("SELECT * FROM cms_category WHERE parentID='".round($pID)."' and hidden=0 ORDER BY position"); while($rowz=mysql_fetch_assoc($sqlz)){ $rWorkz->title=$rowz['title']; $rWorkz->ID=$rowz['ID']; $rWorkz->parentID=$rowz['parentID']; $rWorkz->path=$rowz['path']; $rWorkz->type=$rowz['type']; switch($rowz['type']){ default: break; case 'language': case 'folder': $rWorkz->sub=$this->getNodeByparentID($rowz['ID']); break; case 'article': $rWorkz->content=$this->getContent($rowzwz['ID']); break; case 'news': $rWorkz->news=$this->getNewsByID($rowz['ID'],1); break; case 'gallery': $rWorkz->gallery=$this->getGalleryByID($rowzw['ID']); break; case 'contactform': $rWorkz->contact=$this->getContactFormByparentID($rowzw['ID']); break; case 'vote': $rWorkz->vote=$this->getVoteByparentID($rowzw['ID']); break; } $rWorkzs[]=$rWorkz; unset($rWorkz); } // //print_r($rWorkzs); return $rWorkzs; } /** * Getting all info about votes by ID of catalog, and parentID of voting * returns object (->) of all */ function getVoteByparentID($nodeID){ $vote=$this->dbQuerySelect('','cms_vote',"parentID='".round($nodeID)."'",'',''); $vote=$vote['content'][0]; //print_r($vote); $re->ID=$vote['ID']; $re->parentID=$vote['parentID']; $re->title=$vote['title']; $re->question=$vote['question']; $re->ans1=$vote['ans1']; $re->ans2=$vote['ans2']; $re->ans3=$vote['ans3']; $re->ans4=$vote['ans4']; $re->ans5=$vote['ans5']; $re->tans1=$vote['tans1']; $re->tans2=$vote['tans2']; $re->tans3=$vote['tans3']; $re->tans4=$vote['tans4']; $re->tans5=$vote['tans5']; $re->total=round($vote['tans1']+$vote['tans2']+$vote['tans3']+$vote['tans4']+$vote['tans5']); //print ''; //print ''; return $re; } function getNodeByID($nodeID) { $arrNode=$this->dbQuerySelect('','cms_category',"ID='".round($nodeID)."' ORDER BY position",'',''); if(!is_array($arrNode)){ $arrNode=''; } //print_r($arrNode['content']); return $arrNode['content']; } function getContent($parentID) { $res=$this->dbQuerySelect('','cms_content',"parentID='".round($parentID)."'",'',''); if(!is_array($res)){ $res=''; } // print_r($res); $sco=$res['content']; $cc=$sco[0]; $resto->sContent=$cc['sContent']; $resto->fContent=$cc['fContent']; $resto->title=$cc['title']; //print_r($cc); return $resto; } function getContentByID($parentID) { $res=$this->dbQuerySelect('','cms_content',"ID='".round($parentID)."'",'',''); if(!is_array($res)){ $res=''; } //print_r($res); return $res['content']; } /** * Sending in admin user to pred. link * * @param $link - where navigate */ function navigateTo($link){ print ''; header("Location:?path=".$link.""); } /** * Sending user to pred. link * * @param $link - where navigate */ function navigateToUser($link){ print ''; header("Location:".$link.""); //echo '-- >>>>!'.$link; } function dbQuerySelect2($rows,$table,$query,$perPage,$curPage,$type){ if($perPage>0){ $defLimit=round($perPage*$curPage)+1; } $sql=mysql_query("SELECT ".(($type=='full')?"SQL_CALC_FOUND_ROWS":"")." ".(($rows <>'')? $rows:"*")." FROM ".$table." ".(($query <>'')? "WHERE ".$query:"")." ".(($defLimit <>'')? "LIMIT ".$defLimit.",".$perPage."":"")." ")/* or die("SCRIPT IS DEAD :(")*/; echo mysql_error(); //echo "SELECT ".(($type=='full')?"SQL_CALC_FOUND_ROWS":"")." ".(($rows <>'')? $rows:"*")." FROM ".$table." ".(($query <>'')? "WHERE ".$query:"")." ".(($defLimit <>'')? "LIMIT ".$defLimit.",".$perPage."":"")." "; if(mysql_num_rows($sql)>0){ while($row=mysql_fetch_assoc($sql)){ $result[]=$row; } if($type=='full') { $sql2 = "SELECT FOUND_ROWS()"; $count_row=mysql_fetch_row(mysql_query($sql2)); $counted=$count_row[0]; $results['counted']=$counted; if($counted<>'' and $counted>0 and $perPage<>'') { $results['pages']=round($counted/$perPage); } $results['showed']=$defLimit; $results['content']=$result; }else{ $results=$result; } return $results; }else{ return false; } } function getNavigation($lang){ $nav=$this->dbQuerySelect2('','cms_category',"path='/".$lang."' and type='language'",'','','null'); $navigation=$this->dbQuerySelect2('','cms_category',"type='folder' and parentID='".round($nav[0]['ID'])."' and hidden=0 ORDER BY position",'','','null'); foreach ($navigation as $nvg){ /* First line of subnav */ $nvgs=$this->dbQuerySelect2('','cms_category',"type='folder' and parentID='".round($nvg['ID'])."' and hidden=0 ORDER BY position",'','','null'); if($nvgs){ foreach ($nvgs as $navig){ /* Second line of subnav */ $nvgz=$this->dbQuerySelect2('','cms_category',"type='folder' and parentID='".round($navig['ID'])."' and hidden=0 ORDER BY position",'','','null'); if($nvgz){ $navig['sub']=$nvgz; $nvgz=''; } $renav[]=$navig; $nvgz=''; $navig=''; /*second line */ } $nvg['sub']=$renav; $renav=''; } // $nvg['sub']=$nvgs; /* First line of subnav end */ $result[]=$nvg; $nvg=''; $navig=''; $nvgz=''; $nvgs=''; $nvgewr=''; } // print_r($result); return $result; } function array_multisearch( $needle, $haystack, $strict=false, $path=array() ) { if( !is_array($haystack) ) { return false; } foreach( $haystack as $key => $val ) { if( is_array($val) && $subPath = $this->array_multisearch($needle, $val, $strict, $path) ) { $path = array_merge($path, array($key), $subPath); return $path; } elseif( (!$strict && $val == $needle) || ($strict && $val === $needle) ) { $path[] = $key; return $path; } } return false; } function str_rep($str) { if(is_numeric($str)) { $str=round($str,5); $str=floor($str); $str=round(($str/10)*10,5); } else { //$str=str_replace(" ",' ',$str); ///$str=str_replace("&",'&',$str); $str=str_replace("\'",'',$str); $str=str_replace('\'','',$str); $str=str_replace("\`",'',$str); $str=str_replace('\'','',$str); $str=str_replace("",'-->',$str); $str=preg_replace("/