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

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

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

//-------------------------------------------------====
//	Само сохранение и вывод данных
//-------------------------------------------------====

$CountryID = intval( $_REQUEST['country'] );
$id = intval( $_REQUEST['id'] );
if( $id )
	{
		$Board->LoadListCity( $CountryID );
		//$CountryID = intval( $Board->DBIndex['city'][ $id ] );
		if( $Board->DB['city'][ $CountryID ][ $id ] )
			{
				if( isset( $_POST['submit'] ) )
					{
						$sort = intval( $_POST['sort'] );
						$Options['name'] = htmlspecialchars( stripslashes( CharsetConvert( $_POST['name'] ) ) );
						$Options['country'] = intval( $_POST['country'] );
						
						if( !$Options['name'] ) die( "<span style=\"color: #F00;\">Введите название</span>" );
		if( !$Options['country'] || !$Board->DB['country'][ $Options['country'] ] ) die( "<span style=\"color: #F00;\">Выберите страну</span>" );
						$Options = $db->safesql( $Board->CompileOpt( $Options ) );
						
						$db->query( "UPDATE ".PREFIX."_board_options SET `options`='{$Options}',`sort`='{$sort}' WHERE `id`='{$id}' LIMIT 1" );
						$Board->CleareAllCache();
						
						echo ThisClose();
						echo "<span style=\"color: green;\">Сохранено</span><script type=\"text/javascript\" language=\"javascript\">CloseCityWindow( '{$CountryID}' );</script>";
					}
						else
					{
						$name = htmlspecialchars( stripslashes( $Board->DB['city'][ $CountryID ][ $id ]['name'] ) );
						$sort = intval( $Board->DB['city'][ $CountryID ][ $id ]['sort'] );
						$SelectCountry = $Board->ReturnSelectCountry( $CountryID );
		
echo <<<HTML

<form method="post" action="" name="LightWindowForm" onsubmit="formSubmit( 'LightWindowForm', 'city/edit.city.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="{$name}" class="edit" style="width: 70%;" />
			</td>
		</tr>
		<tr>
			<td colspan="10" background="engine/skins/images/mline.gif" height="1"></td>
		</tr>
		<tr height="30px">
			<td width="150px">Страна: *</td>
			<td>
				<select name="country">
					{$SelectCountry}
				</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="{$sort}" style="text-align: center; width: 50px;" 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="hidden" name="id" value="{$id}" />
		<input type="submit" name="submit" value="Сохранить" class="edit" />
		<input type="button" value="Отмена" class="edit" onclick="OpenCloseLightWindow(); return false;" />
	</div>
</form>

HTML;

					}
			}
				else
			{
				echoReturn( "Города не существует, или он был удалён!" );
			}
	}
		else
	{
		echoReturn( "Не указан идентификатор города!" );
	}

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

$db->close();

?>