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

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



//--------------------------------------------------=-=-=-=-=
//	Определяем идентификационный номер объявления
//--------------------------------------------------=-=-=-=-=

$id = intval( $_REQUEST['id'] );
if( $id )
	{
		//--------------------------------------------------=-=-=-=-=
		//	Достаём объявление из базы
		//--------------------------------------------------=-=-=-=-=
		
		$result = $db->query( "SELECT * FROM ".PREFIX."_board_post WHERE `id`='{$id}' LIMIT 1" );
		$Allow = ( $db->num_rows( $result ) > 0 ) ? true : false;
		$errorAllow = "Объявление под номером \"{$id}\" не найдено.";
		
		if( $Allow === true )
			{
				$row = $db->get_row( $result );
				$approve = intval( $row['approve'] );
				$category = intval( $row['category'] );
				
				//	Смотрим, какую папку с шаблонами грузить
				$RowCat = $Board->DB['category'][ $category ];
				$Folder = $RowCat['template'] != "" ? totranslit( $RowCat['template'] ) : "default";
				
				if( $approve != 1 )
					{
						$Allow = false;
						$errorAllow = "Объявление на данный момент ещё не проверено администрацией сайта. После проверки оно будет опубликовано на сайте.";
					}
			}
				
		if( $Allow === true )
			{
				$id = $row['id'];
				$author = stripslashes( $row['author'] );
				$author_id = intval( $row['author_id'] );
				$date = strtotime( $row['date'] );
				$end_date = strtotime( $row['end_date'] );
				$text = stripslashes( $row['text'] );
				$title = htmlspecialchars( stripslashes( $row['title'] ) );
				$alt_name = stripslashes( $row['alt_name'] );
				$price = intval( $row['price'] );
				$currency = intval( $row['currency'] );
				$board_type = intval( $row['board_type'] );
				$country = intval( $row['country'] );
				$city = intval( $row['city'] );
				$fio = htmlspecialchars( stripslashes( $row['fio'] ) );
				$phone = htmlspecialchars( stripslashes( $row['phone'] ) );
				$email = htmlspecialchars( stripslashes( $row['email'] ) );
				$http = htmlspecialchars( stripslashes( $row['http'] ) );
				$allow_comm = intval( $row['allow_comm'] );
				$comm_num = intval( $row['comm_num'] );
				$views = intval( $row['views'] );
				$Board->RequestCat = $category;
				$Board->LoadListCity( $country );
				$BoardCategory = $category;
				$super_vip_date = intval( $row['super_vip_date'] );
				$vip_date = intval( $row['vip_date'] );
				$color = htmlspecialchars( stripslashes( $row['color'] ) );
				$color_date = intval( $row['color_date'] );
						
				$super_vip_date = $super_vip_date > 0 ? date( "Y-m-d H:i:s", ( $super_vip_date + ( $config['date_adjust'] * 60 ) ) ) : "";
				$vip_date = $vip_date > 0 ? date( "Y-m-d H:i:s", ( $vip_date + ( $config['date_adjust'] * 60 ) ) ) : "";
				$color_date = $color_date > 0 ? date( "Y-m-d H:i:s", ( $color_date + ( $config['date_adjust'] * 60 ) ) ) : "";
				
				$board_type = $Board->DB['board_type'][ $board_type ] != "" ? $Board->DB['board_type'][ $board_type ]['name'] : "---";
				$currency = $Board->DB['currency'][ $currency ] != "" ? $Board->DB['currency'][ $currency ]['symbol'] : "---";
				$city = $Board->DB['city'][ $country ][ $city ] != "" ? $city = $Board->DB['city'][ $country ][ $city ]['name'] : "---";
				
				$country = $Board->DB['country'][ $country ] != "" ? $Board->DB['country'][ $country ]['name'] : "---";
				
				
				$Board->UpdateViews( $id );
				
				//--------------------------------------------------=-=-=-=-=
				//	Настройка метатитлов
				//--------------------------------------------------=-=-=-=-=
				
				$SpeedBarCat = $Board->SpeedBarCat( $category );
				
				for( $i = count( $SpeedBarCat ); $i > 0; $i-- ) $module['title'][] = $SpeedBarCat[ ( $i - 1 ) ]['title'];
				for( $i = count( $SpeedBarCat ); $i > 0; $i-- ) $module['speedbar'][] = "<a href=\"".$SpeedBarCat[ ( $i - 1 ) ]['link']."\">".$SpeedBarCat[ ( $i - 1 ) ]['title']."</a>";
				$module['title'][] = $title;
				$module['speedbar'][] = $title;
				
				//--------------------------------------------------=-=-=-=-=
				//	Комментарии
				//--------------------------------------------------=-=-=-=-=
				
				// Грузим файл комментариев
				include_once( ENGINE_DIR."/modules/board/comments.php" );
				$TplComments = $tpl->result['board_comments'];
				$TplAddComments = $tpl->result['board_addcomments'];
				
				//--------------------------------------------------=-=-=-=-=
				//	Выводим саму новость
				//--------------------------------------------------=-=-=-=-=
				
				$tpl->Load_Template( "board/{$Folder}/board.full.tpl" );
				$tpl->set( "{title}", $title );
				
				if( $TplComments )
					{
						$tpl->set( "[comments]", "" );
						$tpl->set( "[/comments]", "" );
						$tpl->set_block( "'\\[not-comments\\](.*?)\\[/not-comments\\]'si", "" );
					}
						else
					{
						$TplComments = "<div id=\"BoardCommentsList\"></div>";
						$tpl->set( "[not-comments]", "<span id=\"BoardNotComment\">" );
						$tpl->set( "[/not-comments]", "</span>" );
						$tpl->set_block( "'\\[comments\\](.*?)\\[/comments\\]'si", "" );
					}
								
				if( $TplAddComments )
					{
						$tpl->set( "[add-comments]", "" );
						$tpl->set( "[/add-comments]", "" );
						$tpl->set_block( "'\\[not-addcomments\\](.*?)\\[/not-addcomments\\]'si", "" );
					}
						else
					{
						$tpl->set( "{error_add}", $error_add );
						$tpl->set( "[not-addcomments]", "" );
						$tpl->set( "[/not-addcomments]", "" );
						$tpl->set_block( "'\\[add-comments\\](.*?)\\[/add-comments\\]'si", "" );
					}
									
				if( !$not_comments )
					{
						$tpl->set( "[allow-comments]", "<form method=\"post\" action=\"\" name=\"AddBoardComment\" onsubmit=\"BoardAddComments(); return false;\">" );
						$tpl->set( "[/allow-comments]", "</form>" );
					}
						else
					{
						$tpl->set_block( "'\\[allow-comments\\](.*?)\\[/allow-comments\\]'si", "" );
					}
				
				// Ссылка на автора объявления
				if( $config['allow_alt_url'] == "yes" )
					{
						$author_profile = "/user/{$author}/";
						$author_news = "/user/{$author}/news/";
					}
						else
					{
						$author_profile = "/index.php?subaction=userinfo&user={$author}";
						$author_news = "/index.php?subaction=allnews&user={$author}";
					}
		
				$author = "<a onclick=\"ShowProfile('{$author}', '{$author_profile}', '{$author_id}'); return false;\" href=\"{$author_profile}\">{$author}</a>";
		
				// Работаем с датой
				if( date( "Ymd", $date ) == date( "Ymd", $_TIME ) )
					$tpl->set( "{date}", $lang['time_heute'].langdate( ", H:i", $date ) );
				elseif( date( "Ymd", $date ) == date( "Ymd", ( $_TIME - 86400 ) ) )
					$tpl->set( "{date}", $lang['time_gestern'].langdate( ", H:i", $date ) );
				else
					$tpl->set( "{date}", langdate( $config['timestamp_comment'], $date ) );
							
				$tpl->copy_template = preg_replace ( "#\{date=(.+?)\}#ie", "langdate('\\1', '{$date}')", $tpl->copy_template );
		
				// Ссылка на редактирование объявления
				if( $config['allow_alt_url'] == "yes" )
					{
						$link_edit = "/board/edit/{$id}/";
						$link_del = "/board/del/{$id}/";
					}
						else
					{
						$link_edit = "/index.php?do=board&action=edit&id={$id}";
						$link_del = "/index.php?do=board&action=del&id={$id}";
					}
						
				if( $Board->AllowEditPost( $author_id, $approve ) )
					{
						$tpl->set( "[allow-edit]", "<span id=\"board-edit-{$id}\">");
						$tpl->set( "[/allow-edit]", "</span>" );
						$tpl->set( "{edit-link}", $link_edit );
						$tpl->set( "{del-link}", $link_del );
						$tpl->set( "{vip-link}", "javascript:void(0);\" onclick=\"BoardVip( '{$id}' ); return false;" );
						$tpl->set( "{color-link}", "javascript:void(0);\" onclick=\"BoardColor( '{$id}' ); return false;" );
					}
						else
					{
						$tpl->copy_template = preg_replace( "#\\[allow-edit\\](.+?)\\[/allow-edit\\]#is", "", $tpl->copy_template );
					}
		
				// Ссылка на объявление
				$full_link = $Board->ReturnLinkPost( $id, $alt_name, $category );
				$tpl->set( "{full-link}", $full_link );
				$tpl->set( "[full-link]", "<a href=\"{$full_link}\">" );
				$tpl->set( "[/full-link]", "</a>" );
		
				// Ссылка на комментарии
				if( $comm_num > 0 )
					{
						$tpl->set( "[com-link]", "<a href=\"{$full_link}#comment\">" );
						$tpl->set( "[/com-link]", "</a>");
					}
						else
					{
						$tpl->set( "[com-link]", "" );
						$tpl->set( "[/com-link]", "" );
					}
						
				if( $NewsList['tag_id'] === true )
					$tpl->set( "{id}", $id );
				else
					$tpl->set( "{id}", "" );
					
				$tpl->copy_template = preg_replace( "#\\[not-approve\\](.+?)\\[/not-approve\\]#is", ( $approve == 1 ? "" : "\\1" ), $tpl->copy_template );
						
				$tpl->copy_template = preg_replace( "#\\[super-vip\\](.+?)\\[/super-vip\\]#is", ( $super_vip_date ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[no-super-vip\\](.+?)\\[/no-super-vip\\]#is", ( $super_vip_date ? "" : "\\1" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[vip\\](.+?)\\[/vip\\]#is", ( $vip_date ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[no-vip\\](.+?)\\[/no-vip\\]#is", ( $vip_date ? "" : "\\1" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[color\\](.+?)\\[/color\\]#is", ( $color_date ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[no-color\\](.+?)\\[/no-color\\]#is", ( $color_date ? "" : "\\1" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[allow-vip\\](.+?)\\[/allow-vip\\]#is", ( ( !in_array( $Board->Config['echo_post_vip'], array( "hand", "auto" ) ) && !in_array( $Board->Config['echo_post_supervip'], array( "hand", "auto" ) ) ) ? "" : "\\1" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[allow-color\\](.+?)\\[/allow-color\\]#is", ( ( !in_array( $Board->Config['echo_post_color'], array( "hand", "auto" ) ) ) ? "" : "\\1" ), $tpl->copy_template );
				
				
				$tpl->copy_template = preg_replace( "#\\[fio\\](.+?)\\[/fio\\]#is", ( $fio ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[email\\](.+?)\\[/email\\]#is", ( $email ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[http\\](.+?)\\[/http\\]#is", ( $http ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[price\\](.+?)\\[/price\\]#is", ( $price > 0 ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[phone\\](.+?)\\[/phone\\]#is", ( $phone ? "\\1" : "" ), $tpl->copy_template );
				
				$nextUp = date( "Y-m-d H:i:s", ( ( $vip_date ? strtotime( $vip_date ) : $date ) + ( ( ( 60 * 60 ) * 24 ) * 3 ) ) );
						
				$tpl->set( "{id}", $id );
				$tpl->set( "{color}", $color );
				
				$tpl->set( "{notepad}", $Board->NotepadPost( $id ) );
				$tpl->set( "{price}", $Board->ReplacePrice( $price ) );
				$tpl->set( "{currency}", $currency );
				$tpl->set( "{board_type}", $board_type );
				$tpl->set( "{country}", $country );
				$tpl->set( "{city}", $city );
				$tpl->set( "{category}", $Board->ReturnLinkHrefCategory( $category ) );
				
				$tpl->set( "{fio}", ( $fio ? $fio : "Нет данных" ) );
				$tpl->set( "{phone}", ( $phone ? $phone : "Нет данных" ) );
				$tpl->set( "{email}", ( $email ? ( $Board->Config['echo_post_emailform'] == "yes" ? "<a href=\"javascript:void(0);\" onclick=\"BoardSendEmail( '{$id}' ); return false;\">Написать письмо</a><div id=\"BoardSendEmail_{$id}\" style=\"display: none;\">&nbsp;</div>" : "<a href=\"mailto:{$email}\" target=\"_blank\">{$email}</a>" ) : "Нет данных" ) );
				$tpl->set( "{http}", ( $http ? $http : "Нет данных" ) );
				
				$tpl->set( "{city}", $city );
				
				$tpl->copy_template = preg_replace( "#\\[emailFriend\\](.+?)\\[/emailFriend\\]#is", ( $Board->Config['echo_post_friendform'] == "yes" ? "<a href=\"javascript:void(0);\" onclick=\"BoardSendEmailFriend( '{$id}' ); return false;\">\\1</a><div id=\"BoardSendEmailFriend_{$id}\" style=\"display: none;\">&nbsp;</div>" : "" ), $tpl->copy_template );
				$tpl->set( "{title}", $title );
				$tpl->set( "{author}", $author );
				$tpl->set( "{views}", $views );
				$tpl->set( "{text}", $text );
				
				$tpl->copy_template = $Board->ParsePhotosNews( $tpl->copy_template, $row['photos'] );	

				if( $Board->Field !== false ) $tpl->copy_template = $Board->Field->ParseTags( $tpl->copy_template, $row['xfields'] );
				
				$tpl->set( "{comments}", "<div id=\"board_comments\">".$TplComments."</div>" );
				$tpl->set( "{addcomments}", $TplAddComments );
				
				$tpl->copy_template .= "<script language=\"javascript\" type=\"text/javascript\">hs.align = 'center';
				hs.transitions = ['expand', 'crossfade'];
				hs.addSlideshow({
					interval: 4000,
					repeat: false,
					useControls: true,
					fixedControls: 'fit',
					overlayOptions: {
						opacity: .75,
						position: 'bottom center',
						hideOnMouseOut: true
					}
				});</script>";
				
				$tpl->compile( "board_content" );
				$tpl->clear();
				
				// Запрещаем выводить форму поиска
				$BoardLoadMainTpl = false;
				
				// Ключевые слова и описание для поисковиков
				if( $RowCat['description'] ) $metatags['description'] = stripslashes( $RowCat['description'] );
				if( $RowCat['keywords'] ) $metatags['keywords'] = stripslashes( $RowCat['keywords'] );
			}
				else
			{
				$tpl->Load_Template( "info.tpl" );
				$tpl->set( "{title}", "Ошибка" );
				$tpl->set( "{error}", $errorAllow );
				$tpl->compile( "board_content" );
				$tpl->clear();
			}

//--------------------------------------------------=-=-=-=-=
//	В случае ошибки, выводим информацию
//--------------------------------------------------=-=-=-=-=

	}
		else
	{
		$tpl->Load_Template( "info.tpl" );
		$tpl->set( "{title}", "Ошибка" );
		$tpl->set( "{error}", "Вы не указали идентификационный номер объявления." );
		$tpl->compile( "board_content" );
		$tpl->clear();
	}

// Разрешаем вывод формы поиска
$BoardLoadMainTpl = ( in_array( $Board->Config['echo_post_blocksearch'], array( "yes", "yes_no_search" ) ) ) ? true : false;
if( $Board->Config['echo_post_blocksearch'] == "yes_no_search" ) $BoardAllowSearch = false;

if( $BoardLoadMainTpl !== true )
	{
		$tpl->result['board'] = $tpl->result['board'].$tpl->result['board_content'];
		unset( $tpl->result['board_content'] );	
	}

?>