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

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

define( "ROOT_DIR", "../../../../.." );
define( "ENGINE_DIR", "../../../.." );
require_once( ENGINE_DIR."/ajax/board/admin/OptAjax.php" );

//-------------------------------------------------====
//	Само добавление и вывод данных
//-------------------------------------------------====

if( isset( $_POST['submit'] ) )
	{
		$sort = intval( $_POST['sort'] );
		$Options['name'] = htmlspecialchars( stripslashes( CharsetConvert( $_POST['name'] ) ) );
		$Options['AllowCats'] = $_REQUEST['AllowCats'];
		
		if( count( $Options['AllowCats'] ) < 1 || !is_array( $Options['AllowCats'] ) )
			$Options['AllowCats'] = "all";
		else
			$Options['AllowCats'] = implode( ",", $Options['AllowCats'] );
		
		if( !$Options['name'] ) die( "<span style=\"color: #F00;\">Введите название</span>" );
		$Options = $db->safesql( $Board->CompileOpt( $Options ) );
		
		$db->query( "INSERT INTO ".PREFIX."_board_options (`type`,`options`,`sort`) VALUES ('board_type','{$Options}','{$sort}')" );
		$Board->CleareAllCache();
		
		echo ThisClose();
		echo "<span style=\"color: green;\">Тип добавлен</span><script type=\"text/javascript\" language=\"javascript\">CloseWindow( 'board_type' );</script>";
	}
		else
	{
		$AllowCats = $Board->SelectCategory( array( "all" ), "", "", "", true );
		
echo <<<HTML

<form method="post" action="" name="LightWindowForm" onsubmit="formSubmit( 'LightWindowForm', 'board/add.board_type.php', 'LightWindowStatus', 'status.gif', 'LightWindowStatus', 'off' ); return false;">
	<table width="100%" border="0">
		<tr>
			<td colspan="10" background="engine/skins/images/mline.gif" height="1"></td>
		</tr>
		<tr height="30px">
			<td width="150px">Название типа: *</td>
			<td>
				<input type="text" name="name" value="" class="edit" style="width: 70%;" />
			</td>
		</tr>
		<tr>
			<td colspan="10" background="engine/skins/images/mline.gif" height="1"></td>
		</tr>
		<tr height="110px">
			<td style="padding: 0px 0px 0px 5px;">Категории: *</td>
			<td>
				<select name="AllowCats[]" multiple="multiple" style="height: 100px;">
					{$AllowCats}
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="10" background="engine/skins/images/mline.gif" height="1"></td>
		</tr>
		<tr height="30px">
			<td>Сортировка</td>
			<td>
				<input type="text" name="sort" value="1" style="text-align: center; width: 80px;" class="edit" />
			</td>
		</tr>
		<tr>
			<td colspan="10" background="engine/skins/images/mline.gif" height="1"></td>
		</tr>
	</table>
	<div style="text-align: right; padding: 10px 0px 0px 0px;">
		<span id="LightWindowStatus" style="padding: 0px 10px 0px 0px;"></span>
		<input type="submit" name="submit" value="Добавить" class="edit" />
		<input type="button" value="Отмена" class="edit" onclick="OpenCloseLightWindow(); return false;" />
	</div>
</form>

HTML;

	}

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

$db->close();

?>