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

//-------------------------------------------------====
//	Инициализация
//-------------------------------------------------====

define( "ROOT_DIR", "../../.." );
define( "ENGINE_DIR", "../.." );

$OptAjax = array( "tpl" => true );
require_once( ENGINE_DIR."/ajax/board/OptAjax.php" );

//-------------------------------------------------====
//	Принятие и проверка входящих данных
//-------------------------------------------------====

$id = intval( $_REQUEST['id'] );
if( !$id ) echoReturn( "Приняты не все данные, попробуйте снова!" );
if( !in_array( $Board->Config['echo_post_vip'], array( "hand", "auto" ) ) && !in_array( $Board->Config['echo_post_supervip'], array( "hand", "auto" ) ) ) echoReturn( "Поднятие объявлений выключено администрацией!" );

//-------------------------------------------------====
//	Выполнение и вывод в зависимости от запроса
//-------------------------------------------------====

$result = $db->query( "SELECT `title`,`alt_name`,`author`,`category`,`email` FROM ".PREFIX."_board_post WHERE `id`='{$id}' AND `approve`='1'" );
if( $db->num_rows( $result ) > 0 )
	{
		$row = $db->get_row( $result );
		$author = stripslashes( $row['author'] );
		$title = stripslashes( $row['title'] );
		$emailTo = $row['email'];
		$alt_name = $row['alt_name'];
		$category = intval( $row['category'] );
		
		$linkBoard = "http://".$_SERVER['HTTP_HOST'].$Board->ReturnLinkPost( $id, $alt_name, $category );
		$userEmail = $is_logged ? $member_id['email'] : "";
		
		if( isset( $_POST['submit'] ) )
			{
				$type = $_POST['type'];
				switch( $type ){
					
					case "vip":
						if( !in_array( $Board->Config['echo_post_vip'], array( "hand", "auto" ) ) ) die( "<span style=\"color: #F00;\">VIP отключён администрацией сайта!</span>" );
						
						$day = intval( $_POST['day'] );
						if( $day > 0 )
							{
								if( !file_exists( ENGINE_DIR."/inc/payments/management/init.php" ) ) die( "<span style=\"color: #F00;\">Автоматическая оплата не возможна!</span>" );
								require_once( ENGINE_DIR."/inc/payments/management/init.php" );
								$template = @file_get_contents( $tpl->dir."/board/modal/pay.system.list.tpl" );
								$buyOptions = array(
									"board_id" => $id,
									"type_vip" => $type,
									"day" => $day,
								);
								$tpl->result['board'] = $Payments->ListPaySystem( "dle_board", $template, $buyOptions );
							}
								else
							{
								$tpl->Load_Template( "board/modal/vip.tpl" );
								
								$tpl->set( "{id}", $id );
								$tpl->set( "{title}", $title );
								$tpl->set( "{link}", $linkBoard );
								$tpl->set( "{statusSend}", "statusBoardVip_{$id}" );
								$tpl->set( "{price}", $Board->Config['echo_post_vipprice'] );
								
								$tpl->copy_template = preg_replace( "#\\[auto\\](.+?)\\[/auto\\]#is", ( $Board->Config['echo_post_vip'] == "auto" ? "\\1" : "" ), $tpl->copy_template );
								$tpl->copy_template = preg_replace( "#\\[hand\\](.+?)\\[/hand\\]#is", ( $Board->Config['echo_post_vip'] == "hand" ? "\\1" : "" ), $tpl->copy_template );
								
								$tpl->copy_template = "
									<form method=\"post\" action=\"\" name=\"BoardVip_{$id}\" onsubmit=\"BoardformSubmit( 'BoardVip_{$id}', 'vip.php', 'BoardSetVip_{$id}', 'arrow-ajax.gif', 'statusBoardVip_{$id}' ); return false;\">
										{$tpl->copy_template}
										<input type=\"hidden\" name=\"id\" value=\"{$id}\" />
										<input type=\"hidden\" name=\"type\" value=\"{$type}\" />
									</form>
								";
								$tpl->compile( "board" );
								$tpl->clear();
							}
						break;
						
					case "super_vip":
						if( !in_array( $Board->Config['echo_post_supervip'], array( "hand", "auto" ) ) ) die( "<span style=\"color: #F00;\">SUPER VIP отключён администрацией сайта!</span>" );
						
						$day = intval( $_POST['day'] );
						if( $day > 0 )
							{
								if( !file_exists( ENGINE_DIR."/inc/payments/management/init.php" ) ) die( "<span style=\"color: #F00;\">Автоматическая оплата не возможна!</span>" );
								require_once( ENGINE_DIR."/inc/payments/management/init.php" );
								$template = @file_get_contents( $tpl->dir."/board/modal/pay.system.list.tpl" );
								$buyOptions = array(
									"board_id" => $id,
									"type_vip" => $type,
									"day" => $day,
								);
								$tpl->result['board'] = $Payments->ListPaySystem( "dle_board", $template, $buyOptions );
							}
								else
							{
								$tpl->Load_Template( "board/modal/super_vip.tpl" );
						
								$tpl->set( "{id}", $id );
								$tpl->set( "{title}", $title );
								$tpl->set( "{link}", $linkBoard );
								$tpl->set( "{statusSend}", "statusBoardVip_{$id}" );
								$tpl->set( "{price}", $Board->Config['echo_post_supervipprice'] );
									
								$tpl->copy_template = preg_replace( "#\\[auto\\](.+?)\\[/auto\\]#is", ( $Board->Config['echo_post_supervip'] == "auto" ? "\\1" : "" ), $tpl->copy_template );
								$tpl->copy_template = preg_replace( "#\\[hand\\](.+?)\\[/hand\\]#is", ( $Board->Config['echo_post_supervip'] == "hand" ? "\\1" : "" ), $tpl->copy_template );
								
								$tpl->copy_template = "
									<form method=\"post\" action=\"\" name=\"BoardVip_{$id}\" onsubmit=\"BoardformSubmit( 'BoardVip_{$id}', 'vip.php', 'BoardSetVip_{$id}', 'arrow-ajax.gif', 'statusBoardVip_{$id}' ); return false;\">
										{$tpl->copy_template}
										<input type=\"hidden\" name=\"id\" value=\"{$id}\" />
										<input type=\"hidden\" name=\"type\" value=\"{$type}\" />
									</form>
								";
								$tpl->compile( "board" );
								$tpl->clear();
							}
						
						break;
					
					default:die( "<span style=\"color: #F00;\">Выберите тип поднятия объявления!</span>" );
				}
			}
				else
			{
				$tpl->Load_Template( "board/modal/vip-select.tpl" );
				
				$tpl->set( "{id}", $id );
				$tpl->set( "{title}", $title );
				$tpl->set( "{link}", $linkBoard );
				$tpl->set( "{statusSend}", "statusBoardVip_{$id}" );
								
				$tpl->copy_template = preg_replace( "#\\[vip\\](.+?)\\[/vip\\]#is", ( in_array( $Board->Config['echo_post_vip'], array( "hand", "auto" ) ) ? "\\1" : "" ), $tpl->copy_template );
				$tpl->copy_template = preg_replace( "#\\[super-vip\\](.+?)\\[/supervip\\]#is", ( in_array( $Board->Config['echo_post_supervip'], array( "hand", "auto" ) ) ? "\\1" : "" ), $tpl->copy_template );
				
				$tpl->copy_template = "
					<form method=\"post\" action=\"\" name=\"BoardVip_{$id}\" onsubmit=\"BoardformSubmit( 'BoardVip_{$id}', 'vip.php', 'BoardSetVip_{$id}', 'arrow-ajax.gif', 'statusBoardVip_{$id}' ); return false;\">
						{$tpl->copy_template}
						<input type=\"hidden\" name=\"id\" value=\"{$id}\" />
					</form>
				";
				$tpl->compile( "board" );
				$tpl->clear();
			}
	}
		else
	{
		echo "Объявление не найдено!";	
	}

$tpl->resulr['board'] = str_replace( "{THEME}", $THEME, $tpl->result['board'] );
echo $tpl->result['board'];

//-------------------------------------------------====
//	Завершение работы
//-------------------------------------------------====

$db->close();

?>