<?php
/*
=====================================================
 Модуль создал: REZER (http://rezer.net)
=====================================================
 Файл: main.php
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Назначение: главная страница модуля
=====================================================
*/

if( !defined( "DATALIFEENGINE" ) ) die( "Hacking attempt!" );

if( $_REQUEST['type'] == "rss" ) include( ENGINE_DIR."/modules/board/rss.php" );

//--------------------------------------------------=-=-=-=-=
//	Настройка метатитлов
//--------------------------------------------------=-=-=-=-=

$module['title'][] = "Все категории";
$module['speedbar'][] = "Все категории";

//--------------------------------------------------=-=-=-=-=
//	Поиск при необходимости
//--------------------------------------------------=-=-=-=-=

$MainThisSearch = false;
if( $_REQUEST['BoardSearch'] == "---" ) $_REQUEST['BoardSearch'] = "";
if( $_REQUEST['board_type'] == "---" ) $_REQUEST['board_type'] = "";
if( ( $_REQUEST['BoardSearch'] != "" || $_REQUEST['board_type'] != "" ) && $Board->Config['fastsearch_on'] == "on" )
	{
		$module['title'][] = "Поиск";
		$module['speedbar'][] = "Поиск";
		
		if( isset( $_REQUEST['submit_search'] ) ) $_REQUEST['page'] = 1;
		$SearchTextForm = $Board->FilterSearchText( $_REQUEST['BoardSearch'] );
		$Story = $db->safesql( $SearchTextForm );
		$BoardType = intval( $_REQUEST['board_type'] );
				
		$SqlSearch = array();
		if( $Story ) $SqlSearch[] = "( `title` LIKE '%{$Story}%' OR `text` LIKE '%{$Story}%' )";
		if( $BoardType ) $SqlSearch[] = "`board_type`='{$BoardType}'";
		
		if( count( $SqlSearch ) > 0 )
			{
				$MainThisSearch = true;
				$SqlSearch = "AND ".implode( " AND ", $SqlSearch );
				$OnPage = $Board->Config['view_cat_on_page'] > 0 ? intval( $Board->Config['view_cat_on_page'] ) : 1;
				$CancelSearch = $Board->AltUrl ? "/board/" : "/index.php?do=board";
				
				$PageLink = "/board/search/".( $SearchTextForm ? urlencode( htmlspecialchars( $SearchTextForm ) ) : "---" )."/".( $BoardType ? $BoardType : "---" )."/page/{page}";
				$NewsList = array(
				
					"template"		=> "board/main/board.short.tpl",
					"template_nav"	=> "board/main/navigation.tpl",
					"template_info"	=> "board/main/info.tpl",
					"tpl_compile"	=> "board_content",
					"cashe_folder"	=> "",
					"cashe_file"	=> "",
					"cache"			=> false,
					"sql_count"		=> "SELECT COUNT(*) as count FROM ".PREFIX."_board_post WHERE approve='1' {$SqlRegion} {$SqlSearch}",
					"sql_query"		=> "SELECT * FROM ".PREFIX."_board_post WHERE approve='1' {$SqlRegion} {$SqlSearch} ORDER BY date DESC {limit}",
					"num"			=> $OnPage,
					"nav"			=> $PageLink,
					"search_info"	=> true,
					"search_text"	=> "По вашему запросу, найдено {posts} новостей на {total} страницах. <a href=\"{$CancelSearch}\">Отменить поиск</a>",
					"no_news_error" => "По вашему запросу ничего не найдено. <a href=\"{$CancelSearch}\">Отменить поиск</a>",
					
				);
					
				require( ENGINE_DIR."/modules/board/list.post.php" );
			}
	}

if( $MainThisSearch === false )
	{
		if( $Board->Config['rss_on'] == "yes" )
			{
				$rssLink = $MainLink;
				$rssLink .= $Board->AltUrl === true ? "rss.xml" : "&type=rss";
			}
		
		//--------------------------------------------------=-=-=-=-=
		//	Генерация категорий
		//--------------------------------------------------=-=-=-=-=
		
		$cats = $Board->OpenCache( "", "main_cats.tmp" );
		if( !$cats )
			{
				// Количество колонок
				$Columns = $Board->Config['main_page_max_columns'] > 0 ? intval( $Board->Config['main_page_max_columns'] ) : 1;
				
				// Подгружаем шаблоны для формирования
				$BoardCatMainTemplate = @file_get_contents( $tpl->dir."/board/main/category/main.tpl" );
				$BoardCatThreadTemplate = @file_get_contents( $tpl->dir."/board/main/category/thread.tpl" );
				
				// Сама генерация
				$cats = $Board->ListAllCategory( $BoardCatMainTemplate, $BoardCatThreadTemplate, $Columns );
				$Board->CreateCache( "", "main_cats.tmp", $cats );
			}
		
		//--------------------------------------------------=-=-=-=-=
		//	Последние новости
		//--------------------------------------------------=-=-=-=-=
		
		$order = array();
		if( $Board->Config['echo_post_supervip'] != "no" ) $order[] = "`super_vip_date` DESC";
		$order[] = "`date` DESC";
		$order = implode( ", ", $order );
		
		if( $Board->Config['main_page_on_last'] == "on" )
			{
				$MaxPost = $Board->Config['main_page_max_last'] > 0 ? intval( $Board->Config['main_page_max_last'] ) : 1;
				$NewsList = array(
						
					"template"		=> "board/main/board.short.tpl",
					"template_nav"	=> "board/main/navigation.tpl",
					"template_info"	=> "board/main/info.tpl",
					"tpl_compile"	=> "board_content",
					"cashe_folder"	=> "",
					"cashe_file"	=> "main_last_post.tmp",
					"cache"			=> true,
					"sql_count"		=> "SELECT COUNT(*) as count FROM ".PREFIX."_board_post WHERE approve='1'",
					"sql_query"		=> "SELECT * FROM ".PREFIX."_board_post WHERE approve='1' ORDER BY {$order} LIMIT 0,{$MaxPost}",
					"num"			=> $MaxPost,
					"nav"			=> false,
					"search_info"	=> true,
					"search_text"	=> "Последние добавленные {posts} объявлений.",
					"no_news_error" => "Последних объявлений для вывода не найдено.",
					"allow_edit"	=> false,							
				);
							
				require( ENGINE_DIR."/modules/board/list.post.php" );
			}
	}

//--------------------------------------------------=-=-=-=-=
//	Загрзука шаблона
//--------------------------------------------------=-=-=-=-=

$Folder = "main";
$BoardLoadMainTpl = true;
if( $Board->Config['fastsearch_on'] != "on" ) $BoardAllowSearch = false;

?>