session_start(session_id());
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
Header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
Header("Pragma: no-cache"); // HTTP/1.1
Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
include_once("connect.php");
define("SELF", basename(__FILE__));
$sqlcats = array();
$result = mysql_query("SELECT * FROM `cats`") or die(mysql_error());
while($row = mysql_fetch_array($result)){
$row = slashes($row);
$sqlcats[$row['type']][$row['id']] = $row['name'];
}
mysql_free_result($result);
$LIMIT_ON_PAGE = 25;
$LIMIT_ARROWS = 3;
$FROM = is_numeric($_GET['num']) ? $_GET['num'] : 0;
##########################
if(count($_GET)){
$sql = " WHERE 1=1 ";
$line = "";
if($_GET['letter']){
$sql .= " AND `name` LIKE '".$_GET['letter']."%' ";
$line .= "ÔÓËÒÍ ÔÓ ·ÛÍ‚Â: " . $_GET['letter'] . "; ";
}
if($_GET['categoryid']){
$sql .= " AND `cat`='".$_GET['categoryid']."' ";
$line .= ($sqlcats[1][$_GET['categoryid']] && strlen($sqlcats[1][$_GET['categoryid']]))? "͇Ú„Óˡ: " . $sqlcats[1][$_GET['categoryid']] . "; " : "";
}
if($_GET['partid']){
$sql .= " AND `rubrik`='".$_GET['partid']."' ";
$line .= ($sqlcats[2][$_GET['partid']] && strlen($sqlcats[2][$_GET['partid']]))? "‡Á‰ÂÎ: " . $sqlcats[2][$_GET['partid']] . "; " : "";
}
if($_GET['ageid']){
$sql .= " AND `group`='".$_GET['ageid']."' ";
$line .= ($sqlcats[3][$_GET['ageid']] && strlen($sqlcats[3][$_GET['ageid']]))? "‚ÓÁ‡ÒÚ̇ˇ „ÛÔÔ‡: " . $sqlcats[3][$_GET['ageid']] . "; " : "";
}
if($_GET['word'] && strlen(trim($_GET['word']))>2 && preg_replace("`(\s|\*)`", "", $_GET['word']) != ""){
$word = trim(strip_tags($_GET['word']));
$showword = $word;
$search = array ("'&(quot|#34);'i", "'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i",
"'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'(\d+);'e",
"'`'", "'\*'"); // evaluate as php
$replace = array ("", "", "", "", " ",
chr(161), chr(162), chr(163), chr(169), "chr(\\1)",
"", "_");
$word = preg_replace($search, $replace, $word);
if(strlen($word)){
$position_of = strpos($word, "+");
if($position_of === false){
$sql .= " AND ( `desc` LIKE '%".$word."%' OR `name` LIKE '%".$word."%' OR `author` LIKE '%".$word."%' ) ";
$parserwords = array(trim($word));//$words;
$line .= "Íβ˜Â‚ÓÈ Ù‡„ÏÂÌÚ: \"" . stripslashes($_GET['word']) . "\"; ";
}
else{
$sql_words = "";
$words = explode("+", $word);
$parserwords = $words;
foreach($words as $n=>$oneword){
$oneword = trim($oneword);
if(strlen($oneword) > 2){
$words[$n] = " `desc` LIKE '%".$oneword."%' OR `name` LIKE '%".$oneword."%' OR `author` LIKE '%".$oneword."%' ";
$parserwords[$n] = $oneword;
}
}
$sql_words = implode(" OR ", $words);
$sql .= " AND ( ".$sql_words." ) ";
$line .= "Íβ˜Â‚˚ ه„ÏÂÌÚ˚: \"" . stripslashes($_GET['word']) . "\"; ";
}
}
}
$query = "SELECT COUNT(`id`) FROM `data` " . $sql . "";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$HowMany = $row[0];
mysql_free_result($result);
}
##########################
include "tpl.php";
$tpl = new tplTemplatez('main.tpl');
$tpl->tplAssign('cat',getcat(1));
$tpl->tplAssign('rub',getcat(2));
$tpl->tplAssign('group',getcat(3));
if(count($_GET)){
if(strlen($_GET['letter']))
$query = "SELECT * FROM `data` " . $sql . " ORDER BY `name` ASC, `click` DESC LIMIT ".$FROM.", ".$LIMIT_ON_PAGE."";
else
$query = "SELECT * FROM `data` " . $sql . " ORDER BY `click` DESC LIMIT ".$FROM.", ".$LIMIT_ON_PAGE."";
$data = array();
$result = mysql_query($query) or die(mysql_error());
$n = $FROM;
while($row = mysql_fetch_array($result)){
$row = slashes($row);
$n++;
foreach($parserwords as $parser){
$parser = str_replace("_", ".", urldecode($parser));
$row['name'] = preg_replace("`($parser)`i", "\\1", $row['name']);
$row['desc'] = preg_replace("`($parser)`i", "\\1", $row['desc']);
$row['author'] = preg_replace("`($parser)`i", "\\1", $row['author']);
}
$data[] = array('clicks' => "̇ʇÚËÈ:".$row['click'],'id' => $row['id'], 'author' => ($row['author']?$row['author']."
":""), 'name' => $row['name'],'url' => $row['url'],'desc' => $row['desc'],'cat1'=>"| ".catname($row['cat']),'rub1'=>"| ".catname($row['rubrik']),'grp1'=>"| ".catname($row['group']),'line'=>$line);
}
mysql_free_result($result);
if(!count($data))
$data[] = array('id' => '','author' => '', 'name' => 'ÕË˜Â„Ó Ì ̇ȉÂÌÓ','url' => '','desc' => '','cat1'=>'','rub1'=>'','grp1'=>'','line'=>'','clicks' => '');
}
include "alfavit.php";
foreach($data as $k=>$v)
$tpl->tplParse($v,'data');
$tpl->tplAssign('pages', listing($LIMIT_ON_PAGE, $LIMIT_ARROWS, $FROM, $HowMany, $classP="listing", $classA="listing_", $wordnext=" ÒÎÂ‰Û˛˘Ë ÂÁÛθڇÚ˚ ", $wordprev=" Ô‰˚‰Û˘Ë ÂÁÛθڇÚ˚ "));
$tpl->tplAssign('line',$line);
$tpl->tplParse(); // parsing for all, because we have some vars (} they don't belong any block
$tpl->tplPrint(); // print
?>