<?php
if (!defined('MODULE_FILE')) {
	Header("Location: ../../index.php");
	exit;
}
	require_once("multimodules/templ.php");
  require_once("config/config_confmulti.php");
  require_once("config/config-multimod.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "$defis Главная";

$maintpl=new multitpl;
$mainshablon="multimodules/template/main.tpl";

function modulnews() {
	global $db, $prefix, $module_name, $news, $mul;
	$newsnum=0;
	$tpl=new multitpl;
  $shablon="multimodules/template/news.tpl";
  $content='';
  $sqlcat='';
  $news['time'] = 60*60*$news['time'];
  if ($news['cat']!='') $sqlcat="AND s.catid IN (".$news['cat'].")";
  $cachefile="multimodules/cache/news-kesh.php";
 
  $refresh='0';
if (isset($_GET[$news['refresh']])) $refresh = intval($_GET[$news['refresh']]);
if (isset($_GET[$mul['refresh']])) $refresh = intval($_GET[$mul['refresh']]);

if (!file_exists($cachefile)) $news['time']='-1';
else $news['time'] = $news['time'] - mktime() + filemtime($cachefile);


if ($news['cache']=='0' || $news['time']<0 || $refresh=="1") {
  
  
	$result = $db->sql_query("SELECT sid, s.catid, s.aid, s.title, s.time, s.hometext, s.bodytext, s.comments, s.counter, s.topic, s.acomm, s.score, s.ratings, c.title, t.topicid, t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE s.time <= NOW() AND status='1' $sqlcat ORDER BY ".$news['order']." DESC LIMIT 0, ".$news['num']."");
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE s.time <= NOW() AND status='1' $sqlcat ORDER BY ".$news['order']." DESC LIMIT 0, ".$news['num'].""));
	if ($numstories>$news['num']) $numstories=$news['num'];
  $line=ceil($numstories/$news['kol']);
while (list($s_sid , $catid, $aid, $title, $time, $hometext, $bodytext, $comments, $counter, $topic, $acomm, $score, $ratings, $ctitle, $topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result)) {

//#########################################--Разделяем основную часть на краткую и подробную новости
if ((!$hometext || $hometext=='') && strlen(strip_tags($bodytext))>$news['cut']) {
$hometext = korotko($bodytext, $news['cut']);
$hometext = nl2br($hometext);
$hometext=strip_tags($hometext, '<br><br />');
} else if ((!$hometext || $hometext=='') && strlen(strip_tags($bodytext))<=$news['cut']) {
$hometext = nl2br($bodytext);
$hometext=preg_replace("/<br \/><br \/>+/","<br />",$hometext);
$hometext=preg_replace("/<br \/>
<br \/>+/","<br />",$hometext);
}
//###---
$hometext=bb_decode($hometext);
$bodytext=bb_decode($bodytext);

if($news['dimg']=='1') {
$hometext=preg_replace("|<img[\s\S]+>|iU","", $hometext);
$bodytext=preg_replace("|<img[\s\S]+>|iU","", $bodytext);
}


$newsnum++;

if ($news['nap']=='2' && $news['kol'] != '1') {
if ($newsnum=='1') $content .="<div class=\"post column first\">";
elseif ($newsnum==$line+1) $content .="<div class=\"post column\">";
$content .=$tpl->fastparse($shablon,array('news_id'=>$s_sid,'title'=>$title,'time'=>$time,'hometext'=>$hometext, 'user_add'=>$aid, 'cat_id'=> $catid,'bodytext'=>$bodytext,'comments'=>$comments,'counter'=>$counter,'id_topic'=>$topic,'cat_title'=>$ctitle,'topicname'=>$topicname,'topicimage'=>$topicimage,'topictext'=>$topictext), false);
$content .="<br />";
if ($newsnum==$line || $newsnum==$numstories) $content .="</div>";

} else {
if($news['kol']=='1') $classnews="onecolonka";
elseif($newsnum =='1' && $news['kol']=='2') $classnews="post column first";
elseif ($newsnum =='2' && $news['kol']=='2') $classnews="post column";

$content .="<div class=\"$classnews\">";
$content .=$tpl->fastparse($shablon,array('news_id'=>$s_sid,'title'=>$title,'time'=>$time,'hometext'=>$hometext, 'user_add'=>$aid, 'cat_id'=> $catid,'bodytext'=>$bodytext,'comments'=>$comments,'counter'=>$counter,'id_topic'=>$topic,'cat_title'=>$ctitle,'topicname'=>$topicname,'topicimage'=>$topicimage,'topictext'=>$topictext), false);
$content .="</div>";

if($newsnum=='2' && $news['kol']=='2') {$content .="<div class=\"clear\"></div>"; $newsnum=0;}

}

}
$content .="<div class=\"clear\"></div>";
if (($news['cache']==1 && $news['time']<0) || $refresh=="1") {
        $fp = fopen($cachefile, "w");
        $bcashe = "<?php\nif (!defined(\"MODULE_FILE\")) {\n Header(\"Location: ../index.php\");\n exit();\n }\n\n $"."content = <<<HTML\n $content \nHTML;\n\n\n?>";
        fwrite($fp, $bcashe);
        fclose($fp);
        }
} else {
    require($cachefile);
}

return $content;

}

function modulgames() {
	global $db, $prefix, $module_name, $games, $mul;
	$gamesnum=0;
	$tpl=new multitpl;
  $shablon="multimodules/template/games.tpl";
  $content='';
  $sqlcat='';
  $games['time'] = 60*60*$games['time'];
  if ($games['cat']!='') $sqlcat="AND g.cid IN (".$games['cat'].")";
$cachefile="multimodules/cache/games-kesh.php";

  $refresh='0';
if (isset($_GET[$games['refresh']])) $refresh = intval($_GET[$games['refresh']]);
if (isset($_GET[$mul['refresh']])) $refresh = intval($_GET[$mul['refresh']]);


if (!file_exists($cachefile)) $games['time']='-1';
else $games['time'] = $games['time'] - mktime() + filemtime($cachefile);



if ($games['cache']=='0' || $games['time']<0 || $refresh=="1") {

	$result = $db->sql_query("SELECT g.lid, g.cid, g.title, g.description, g.url, g.links, UNIX_TIMESTAMP(g.date) as formatted, g.name, g.votes, g.totalvotes, g.totalcomments, g.hits, c.cid, c.title, c.cimg FROM ".$prefix."_games AS g LEFT JOIN ".$prefix."_games_categories AS c ON (g.cid=c.cid) WHERE g.date <= now() AND status!='0' $sqlcat ORDER BY ".$games['order']." DESC LIMIT 0, ".$games['num']."");
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_games AS g LEFT JOIN ".$prefix."_games_categories AS c ON (g.cid=c.cid) WHERE g.date <= now() AND status!='0' $sqlcat ORDER BY ".$games['order']." DESC LIMIT 0, ".$games['num'].""));
	if ($numstories>$games['num']) $numstories=$games['num'];
  $line=ceil($numstories/$games['kol']);
  while (list($lid, $cid, $f_title, $description, $imgurl, $gamelink, $formatted, $aid, $votes, $totalvotes, $comment, $hits, $ccid, $ctitle, $cimg) = $db->sql_fetchrow($result)) {
  $description=bb_decode($description);
  $gamesnum++;
  $formatted = date("d.m.Y", $formatted);
if ($games['nap']=='2' && $games['kol'] != '1') {
if ($gamesnum=='1') $content .="<div class=\"post column first\">";
elseif ($gamesnum==$line+1) $content .="<div class=\"post column\">";

$content .=$tpl->fastparse($shablon,array('games_id'=>$lid,'title'=>$f_title,'time'=>$formatted,'description'=>$description, 'name'=>$aid, 'cat_id'=> $cid, 'comments'=>$comment,'counter'=>$hits,'img'=>$imgurl,'cat_title'=>$ctitle,'link'=>$gamelink), false);
$content .="<br />";
if ($gamesnum==$line || $gamesnum==$numstories) $content .="</div>";

} else {

if($games['kol']=='1') $classnews="onecolonka";
elseif($gamesnum =='1' && $games['kol']=='2') $classnews="post column first";
elseif ($gamesnum =='2' && $games['kol']=='2') $classnews="post column";

$content .="<div class=\"$classnews\">";
$content .=$tpl->fastparse($shablon,array('games_id'=>$lid,'title'=>$f_title,'time'=>$formatted,'description'=>$description, 'name'=>$aid, 'cat_id'=> $cid, 'comments'=>$comment,'counter'=>$hits,'img'=>$imgurl,'cat_title'=>$ctitle,'link'=>$gamelink), false);
$content .="</div>";

if($gamesnum=='2' && $games['kol']=='2') {$content .="<div class=\"clear\"></div>"; $gamesnum=0;}

}

}
$content .="<div class=\"clear\"></div>";
if (($games['cache']=='1' && $games['time']<0) || $refresh=="1") {
        $fp = fopen($cachefile, "w");
        $bcashe = "<?php\nif (!defined(\"MODULE_FILE\")) {\n Header(\"Location: ../index.php\");\n exit();\n }\n\n $"."content = <<<HTML\n $content \nHTML;\n\n?>";
        fwrite($fp, $bcashe);
        fclose($fp);
        }
} else {
    require($cachefile);
}
 return $content;

}

function modulpages() {
	global $db, $prefix, $module_name, $pages, $mul;
	$pagesnum=0;
	$tpl=new multitpl;
  $shablon="multimodules/template/pages.tpl";
  $content='';
  $sqlcat='';
  $pages['time'] = 60*60*$pages['time'];
 if ($pages['cat']!='') $sqlcat="AND p.cid IN (".$pages['cat'].")";
$cachefile="multimodules/cache/pages-kesh.php";

  $refresh='0';
if (isset($_GET[$pages['refresh']])) $refresh = intval($_GET[$pages['refresh']]);
if (isset($_GET[$mul['refresh']])) $refresh = intval($_GET[$mul['refresh']]);

if (!file_exists($cachefile)) $pages['time']='-1';
else $pages['time'] = $pages['time'] - mktime() + filemtime($cachefile);


if ($pages['cache']=='0' || $pages['time']<0 || $refresh=="1") {

	$result = $db->sql_query("SELECT p.pid, p.cid, p.title, p.hometext, p.date, p.counter, c.title, c.description FROM ".$prefix."_pages AS p LEFT JOIN ".$prefix."_pages_categories AS c ON (p.cid=c.cid) WHERE p.date <= now() AND p.active = '1' $sqlcat ORDER BY ".$pages['order']." DESC LIMIT 0, ".$pages['num']."");
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_pages AS p LEFT JOIN ".$prefix."_pages_categories AS c ON (p.cid=c.cid) WHERE p.date <= now() AND p.active = '1' $sqlcat ORDER BY ".$pages['order']." DESC LIMIT 0, ".$pages['num'].""));
	if ($numstories>$pages['num']) $numstories=$pages['num'];
  $line=ceil($numstories/$pages['kol']);
  while (list($pid, $cid, $p_title, $hometext, $date, $counter, $ctitle, $cdescr) = $db->sql_fetchrow($result)) {
  $hometext=bb_decode($hometext);
  $cdescr=bb_decode($cdescr);
  if($pages['dimg']=='1') $hometext=preg_replace("|<img[\s\S]+>|iU","", $hometext);
  $pagesnum++;
if ($pages['nap']=='2' && $pages['kol'] != '1') {
if ($pagesnum=='1') $content .="<div class=\"post column first\">";
elseif ($pagesnum==$line+1) $content .="<div class=\"post column\">";

$content .=$tpl->fastparse($shablon,array('pages_id'=>$pid,'title'=>$p_title,'time'=>$date,'article'=>$hometext, 'cat_id'=> $cid,'counter'=>$counter,'cat_title'=>$ctitle,'cat_text'=>$cdescr), false);
$content .="<br />";
if ($pagesnum==$line || $pagesnum==$numstories) $content .="</div>";

} else {

if($pages['kol']=='1') $classnews="onecolonka";
elseif($pagesnum =='1' && $pages['kol']=='2') $classnews="post column first";
elseif ($pagesnum =='2' && $pages['kol']=='2') $classnews="post column";

$content .="<div class=\"$classnews\">";
$content .=$tpl->fastparse($shablon,array('pages_id'=>$pid,'title'=>$p_title,'time'=>$date,'article'=>$hometext, 'cat_id'=> $cid,'counter'=>$counter,'cat_title'=>$ctitle,'cat_text'=>$cdescr), false);
$content .="</div>";

if($pagesnum=='2' && $pages['kol']=='2') {$content .="<div class=\"clear\"></div>"; $pagesnum=0;}

}

}
$content .="<div class=\"clear\"></div>";
if (($pages['cache']=='1' && $pages['time']<0) || $refresh=="1") {
        $fp = fopen($cachefile, "w");
        $bcashe = "<?php\nif (!defined(\"MODULE_FILE\")) {\n Header(\"Location: ../index.php\");\n exit();\n }\n\n $"."content = <<<HTML\n $content \nHTML;\n\n?>";
        fwrite($fp, $bcashe);
        fclose($fp);
        }
} else {
    require($cachefile);
}
 return $content;

}

function modulfiles() {
	global $db, $prefix, $module_name, $files, $mul;
	$filesnum=0;
	$tpl=new multitpl;
  $shablon="multimodules/template/files.tpl";
  $content='';
  $sqlcat='';
  $files['time'] = 60*60*$files['time'];
  if ($files['cat']!='') $sqlcat="AND f.cid IN (".$files['cat'].")";
$cachefile="multimodules/cache/files-kesh.php";

$refresh='0';
if (isset($_GET[$files['refresh']])) $refresh = intval($_GET[$files['refresh']]);
if (isset($_GET[$mul['refresh']])) $refresh = intval($_GET[$mul['refresh']]);

if (!file_exists($cachefile)) $files['time']='-1';
else $files['time'] = $files['time'] - mktime() + filemtime($cachefile);



if ($files['cache']=='0' || $files['time']<0 || $refresh=="1") {

  $result = $db->sql_query("SELECT f.lid, f.cid, f.title, f.description, f.url, f.img, UNIX_TIMESTAMP(f.date) as formatted, f.name, f.votes, f.totalvotes, f.totalcomments, f.hits, c.cid, c.title, c.cdescription FROM ".$prefix."_files AS f LEFT JOIN ".$prefix."_files_categories AS c ON (f.cid=c.cid) WHERE f.date <= now() AND status!='0' $sqlcat ORDER BY ".$files['order']." DESC LIMIT 0, ".$files['num']."");
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_files AS f LEFT JOIN ".$prefix."_files_categories AS c ON (f.cid=c.cid) WHERE f.date <= now() AND status!='0' $sqlcat ORDER BY ".$files['order']." DESC LIMIT 0, ".$files['num'].""));
	if ($numstories>$files['num']) $numstories=$files['num'];
  $line=ceil($numstories/$files['kol']);
  while (list($lid, $cid, $f_title, $description, $filelink, $imgurl, $formatted, $aid, $votes, $totalvotes, $comment, $hits, $ccid, $ctitle, $cdescr) = $db->sql_fetchrow($result)) {
  $description=bb_decode($description);
  $filesnum++;
  $formatted = date("d.m.Y", $formatted);
if ($files['nap']=='2' && $files['kol'] != '1') {
if ($filesnum=='1') $content .="<div class=\"post column first\">";
elseif ($filesnum==$line+1) $content .="<div class=\"post column\">";

$content .=$tpl->fastparse($shablon,array('files_id'=>$lid,'title'=>$f_title,'time'=>$formatted,'description'=>$description, 'name'=>$aid, 'cat_id'=> $cid, 'comments'=>$comment,'counter'=>$hits,'img'=>$imgurl,'cat_title'=>$ctitle,'link'=>$filelink), false);
$content .="<br />";
if ($filesnum==$line || $filesnum==$numstories) $content .="</div>";

} else {

if($files['kol']=='1') $classnews="onecolonka";
elseif($filesnum =='1' && $files['kol']=='2') $classnews="post column first";
elseif ($filesnum =='2' && $files['kol']=='2') $classnews="post column";

$content .="<div class=\"$classnews\">";
$content .=$tpl->fastparse($shablon,array('files_id'=>$lid,'title'=>$f_title,'time'=>$formatted,'description'=>$description, 'name'=>$aid, 'cat_id'=> $cid, 'comments'=>$comment,'counter'=>$hits,'img'=>$imgurl,'cat_title'=>$ctitle,'link'=>$filelink), false);
$content .="</div>";

if($filesnum=='2' && $files['kol']=='2') {$content .="<div class=\"clear\"></div>"; $filesnum=0;}

}

}
$content .="<div class=\"clear\"></div>";
if (($files['cache']=='1' && $files['time']<0) || $refresh=="1") {
        $fp = fopen($cachefile, "w");
        $bcashe = "<?php\nif (!defined(\"MODULE_FILE\")) {\n Header(\"Location: ../index.php\");\n exit();\n }\n\n $"."content = <<<HTML\n $content \nHTML;\n\n?>";
        fwrite($fp, $bcashe);
        fclose($fp);
        }
} else {
    require($cachefile);
}
 return $content;

}

function modullnews() {
	global $db, $prefix, $module_name, $lnews, $mul;
	$newsnum=0;
	$tpl=new multitpl;
  $shablon="multimodules/template/locked-news.tpl";
  $content='';
  $sqlcat='';
  $lnews['time'] = 60*60*$lnews['time'];
  if ($lnews['cat']!='') $sqlcat="AND sid IN (".$lnews['cat'].")";
  $cachefile="multimodules/cache/locked-news-kesh.php";
 if ($sqlcat!='') {
  $refresh='0';
if (isset($_GET[$lnews['refresh']])) $refresh = intval($_GET[$lnews['refresh']]);
if (isset($_GET[$mul['refresh']])) $refresh = intval($_GET[$mul['refresh']]);

if (!file_exists($cachefile)) $lnews['time']='-1';
else $lnews['time'] = $lnews['time'] - mktime() + filemtime($cachefile);


if ($lnews['cache']=='0' || $lnews['time']<0 || $refresh=="1") {
  
  
	$result = $db->sql_query("SELECT sid, s.catid, s.aid, s.title, s.time, s.hometext, s.bodytext, s.comments, s.counter, s.topic, s.acomm, s.score, s.ratings, c.title, t.topicid, t.topicname, t.topicimage, t.topictext FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE s.time <= NOW() AND status='1' $sqlcat");
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_stories_cat AS c on (s.catid=c.catid) LEFT JOIN ".$prefix."_topics AS t on (s.topic=t.topicid) WHERE s.time <= NOW() AND status='1' $sqlcat"));
	$line=ceil($numstories/$lnews['kol']);
while (list($s_sid , $catid, $aid, $title, $time, $hometext, $bodytext, $comments, $counter, $topic, $acomm, $score, $ratings, $ctitle, $topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result)) {

//#########################################--Разделяем основную часть на краткую и подробную новости
if ((!$hometext || $hometext=='') && strlen(strip_tags($bodytext))>$lnews['cut']) {
$hometext = korotko($bodytext, $lnews['cut']);
$hometext = nl2br($hometext);
$hometext=strip_tags($hometext, '<br><br />');
} else if ((!$hometext || $hometext=='') && strlen(strip_tags($bodytext))<=$lnews['cut']) {
$hometext = nl2br($bodytext);
$hometext=preg_replace("/<br \/><br \/>+/","<br />",$hometext);
$hometext=preg_replace("/<br \/>
<br \/>+/","<br />",$hometext);
}
//###---
$hometext=bb_decode($hometext);
$bodytext=bb_decode($bodytext);

if($lnews['dimg']=='1') {
$hometext=preg_replace("|<img[\s\S]+>|iU","", $hometext);
$bodytext=preg_replace("|<img[\s\S]+>|iU","", $bodytext);
}


$newsnum++;

if ($lnews['nap']=='2' && $lnews['kol'] != '1') {
if ($newsnum=='1') $content .="<div class=\"post column first\">";
elseif ($newsnum==$line+1) $content .="<div class=\"post column\">";
$content .=$tpl->fastparse($shablon,array('news_id'=>$s_sid,'title'=>$title,'time'=>$time,'hometext'=>$hometext, 'user_add'=>$aid, 'cat_id'=> $catid,'bodytext'=>$bodytext,'comments'=>$comments,'counter'=>$counter,'id_topic'=>$topic,'cat_title'=>$ctitle,'topicname'=>$topicname,'topicimage'=>$topicimage,'topictext'=>$topictext), false);
$content .="<br />";
if ($newsnum==$line || $newsnum==$numstories) $content .="</div>";

} else {
if($lnews['kol']=='1') $classnews="onecolonka";
elseif($newsnum =='1' && $lnews['kol']=='2') $classnews="post column first";
elseif ($newsnum =='2' && $lnews['kol']=='2') $classnews="post column";

$content .="<div class=\"$classnews\">";
$content .=$tpl->fastparse($shablon,array('news_id'=>$s_sid,'title'=>$title,'time'=>$time,'hometext'=>$hometext, 'user_add'=>$aid, 'cat_id'=> $catid,'bodytext'=>$bodytext,'comments'=>$comments,'counter'=>$counter,'id_topic'=>$topic,'cat_title'=>$ctitle,'topicname'=>$topicname,'topicimage'=>$topicimage,'topictext'=>$topictext), false);
$content .="</div>";

if($newsnum=='2' && $lnews['kol']=='2') {$content .="<div class=\"clear\"></div>"; $newsnum=0;}

}

}
$content .="<div class=\"clear\"></div>";
if (($lnews['cache']==1 && $lnews['time']<0) || $refresh=="1") {
        $fp = fopen($cachefile, "w");
        $bcashe = "<?php\nif (!defined(\"MODULE_FILE\")) {\n Header(\"Location: ../index.php\");\n exit();\n }\n\n $"."content = <<<HTML\n $content \nHTML;\n\n\n?>";
        fwrite($fp, $bcashe);
        fclose($fp);
        }
} else {
    require($cachefile);
}

return $content;

}
}


function modulsms() {
	global $db, $prefix, $module_name, $sms, $mul;
	$smsnum=0;
	$tpl=new multitpl;
  $shablon="multimodules/template/sms.tpl";
  $content='';
  $sqlcat='';
  $sms['time'] = 60*60*$sms['time'];
 if ($sms['cat']!='') $sqlcat="AND s.cid IN (".$sms['cat'].")";
$cachefile="multimodules/cache/sms-kesh.php";

  $refresh='0';
if (isset($_GET[$sms['refresh']])) $refresh = intval($_GET[$sms['refresh']]);
if (isset($_GET[$mul['refresh']])) $refresh = intval($_GET[$mul['refresh']]);

if (!file_exists($cachefile)) $sms['time']='-1';
else $sms['time'] = $sms['time'] - mktime() + filemtime($cachefile);


if ($sms['cache']=='0' || $sms['time']<0 || $refresh=="1") {

	$result = $db->sql_query("SELECT s.lid, s.cid, s.author, s.text, s.date, s.rating, c.title FROM ".$prefix."_smska AS s LEFT JOIN ".$prefix."_smska_cat AS c ON (s.cid=c.cid) ".$order." WHERE status ='1' $sqlcat ORDER BY ".$sms['order']." DESC LIMIT 0, ".$sms['num']."");
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_smska AS s LEFT JOIN ".$prefix."_smska_cat AS c ON (s.cid=c.cid) ".$order." WHERE status ='1' $sqlcat ORDER BY ".$sms['order']." DESC LIMIT 0, ".$sms['num'].""));
	if ($numstories>$sms['num']) $numstories=$sms['num'];
  $line=ceil($numstories/$sms['kol']);
  while (list($lid, $cid, $author, $text, $date, $rating, $ctitle) = $db->sql_fetchrow($result)) {
  $text=bb_decode($text);
  $smsnum++;
if ($sms['nap']=='2' && $sms['kol'] != '1') {
if ($smsnum=='1') $content .="<div class=\"post column first\">";
elseif ($smsnum==$line+1) $content .="<div class=\"post column\">";

$content .=$tpl->fastparse($shablon,array('sms_id'=>$lid, 'time'=>$date,'smska'=>$text, 'cat_id'=> $cid,'rating'=>$rating,'author'=>$author,'cat_title'=>$ctitle), false);
$content .="<br />";
if ($smsnum==$line || $smsnum==$numstories) $content .="</div>";

} else {

if($sms['kol']=='1') $classnews="onecolonka";
elseif($smsnum =='1' && $sms['kol']=='2') $classnews="post column first";
elseif ($smsnum =='2' && $sms['kol']=='2') $classnews="post column";

$content .="<div class=\"$classnews\">";
$content .=$tpl->fastparse($shablon,array('sms_id'=>$lid, 'time'=>$date,'smska'=>$text, 'cat_id'=> $cid,'rating'=>$rating,'author'=>$author,'cat_title'=>$ctitle), false);
$content .="</div>";

if($smsnum=='2' && $sms['kol']=='2') {$content .="<div class=\"clear\"></div>"; $smsnum=0;}

}

}
$content .="<div class=\"clear\"></div>";
if (($sms['cache']=='1' && $sms['time']<0) || $refresh=="1") {
        $fp = fopen($cachefile, "w");
        $bcashe = "<?php\nif (!defined(\"MODULE_FILE\")) {\n Header(\"Location: ../index.php\");\n exit();\n }\n\n $"."content = <<<HTML\n $content \nHTML;\n\n?>";
        fwrite($fp, $bcashe);
        fclose($fp);
        }
} else {
    require($cachefile);
}
 return $content;

}


function mainmulti() {
global $maintpl, $mainshablon, $lnews, $news, $games, $pages, $files, $sms;
$page='';
$lnew='';
$new='';
$game='';
$file='';
$smska='';
if ($pages['active']=='1') $page=modulpages();
if ($news['active']=='1') $new=modulnews();
if ($lnews['active']=='1') $lnew=modullnews();
if ($games['active']=='1') $game=modulgames();
if ($files['active']=='1') $file=modulfiles();
if ($sms['active']=='1') $smska=modulsms();
	head();
$maintpl->fastparse($mainshablon,array('news'=>$new,'locked-news'=>$lnew, 'games'=>$game, 'pages'=>$page, 'files'=>$file, 'smska'=>$smska), true);
	foot();
}




switch($op) {
	default:
	mainmulti();
	break;
}
?>