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

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

$CountryID = intval( $_REQUEST['country_id'] );

if( !$CountryID )
	{
		opentable();
		tableheader( "Список стран и городов" );
	}

if( count( $Board->DB['country'] ) > 0 )
	{
		$list .= showStart();
		foreach( $Board->DB['country'] as $key => $row )
			{
				$id = $row['id'];
				$name = stripslashes( $row['name'] );
				
				if( $CountryID )
					{
						$Board->LoadListCity( $id );
						if( count( $Board->DB['city'][ $id ] ) > 0 )
							{
								$CityList = showStart();
								foreach( $Board->DB['city'][ $id ] as $CityID => $CityRow )
									{
										$CityRow = $Board->DB['city'][ $id ][ $CityID ];
										$CityName = htmlspecialchars( stripslashes( $CityRow['name'] ) );
										$sort = intval( $CityRow['sort'] );
$CityList .= <<<HTML

<div id="del_City_{$CityID}">
	<table width="100%" border="0">
		<tr height="30px" onmouseover="this.bgColor='#F1F7FE'" onmouseout="this.bgColor='#FFFFFF'">
			<td width="70px" align="center" id="StatusIDCity_{$CityID}">{$CityID}</td>
			<td><a href="javascript:void(0);" onclick="EditCity( '{$CityID}', '{$CountryID}' ); return false;">{$CityName}</a></td>
			<td width="100px" align="center">
				<input type="text" name="sort[{$CityID}]" value="{$sort}" style="text-align: center; width: 50px;" class="edit" />
			</td>
			<td width="100px" align="center">
				<a onclick="return dropdownmenu( this, event, MenuCity( '{$CityID}', '{$CountryID}' ), '120px')" href="javascript:void(0);">
					<img src="engine/skins/images/browser_action.gif" border="0">
				</a>
			</td>
			<td width="30px">
				<input type="checkbox" name="CheckCity[]" value="{$CityID}" />
			</td>
		</tr>
		<tr>
			<td colspan="10" background="engine/skins/images/mline.gif" height="1"></td>
		</tr>
	</table>
</div>

HTML;
									}
							}
								else
							{
								$CityList = showStart()."<div style=\"padding: 15px; text-align: center;\">Городов не обнаружено</div>".showStart();
							}
					}
						else
					{
						$CityList = showStart()."<div style=\"padding: 15px; text-align: center;\" id=\"StatusUpdateCityList_{$id}\"><a href=\"javascript:void(0);\" onclick=\"EchoCityList( '{$id}', 'yes' );\">Нажмите для показа городов данной страны</a></div>".showStart();	
					}
					
$CityList = <<<HTML

<table width="100%" border="0" style="margin: 2px 0px 2px 0px;">
	<tr>
		<td width="70px" align="center">ID</td>
		<td>Название</td>
		<td width="100px" align="center">Сортировка</td>
		<td width="100px" align="center">Действие</td>
		<td width="30px">
			<input type="checkbox" name="ChecboxAll" onclick="CheckboxAllSelect( 'country_{$id}' );" />
		</td>
	</tr>
</table>
<div class="hr_line"></div>
{$CityList}
HTML;
				
				if( count( $Board->DB['city'][ $id ] ) > 0 ) $CityList = <<<HTML
<form name="country_{$id}" method="post" action="" onsubmit="SetFormSubmit( 'country_{$id}' ); return false;">
	{$CityList}
	<div class="hr_line"></div>
	<div style="padding: 5px;">
		<table width="100%" border="0">
			<tr>
				<td>&nbsp;</td>
				<td align="right">
					<span id="status_country_{$id}"></span>
					<select name="action" id="action_country_{$id}">
						<option value=""> - Выберите действие - </option>
						<option value="sort">Отсортировать</option>
						<option value="del">Удалить</option>
					</select>
					<input type="submit" name="submit" value="Сохранить" class="edit" />
					<input type="hidden" name="TypeAction" value="city" />
					<input type="hidden" name="country_id" value="{$id}" />
				</td>
			</tr>
		</table>
	</div>
</form>
HTML;
					
$tablename = <<<HTML

<table width="100%">
	<tr style="cursor: pointer;" onclick="ShowOrHide( 'country_{$id}' ); EchoCityList( '{$id}' );">
		<td>ID: $id &raquo; $name</td>
		<td width="50px" align="right" id="StatusCountryId_{$id}">
			<a onClick="return dropdownmenu(this, event, MenuCountry( '{$id}' ), '120px')" href="javascript:void(0);"><img src="engine/skins/images/browser_action.gif" border="0"></a>
		</td>
		<td width="5px">&nbsp;</td>
	</tr>
</table>

HTML;
				if( !$CountryID )
					{
						echo "<div id=\"delCountry_{$id}\">";
						opentable();
						tableheaderList( $tablename );
						echo "<div id=\"country_{$id}\" style=\"display: none;\"><div class=\"unterline\"></div>";
						echo $CityList;
						echo "</div>";
						closetable();
						echo "</div>";
					}
						else
					{
						if( $CountryID == $id )
							{
								echo "<div class=\"unterline\"></div>{$CityList}";
								die();
							}
					}
			}
	}
		else
	{
		echo showStart()."<div style=\"padding: 15px; text-align: center;\">Стран не обнаружено</div>".showStart();
	}

echo <<<HTML

<div class="hr_line"></div>
<div style="padding: 5px;">
	<input type="button" value="Добавить страну" class="edit" onclick="AddCountry(); return false;" />
	<input type="button" value="Добавить город" class="edit" onclick="AddCity(); return false;" />
</div>

HTML;

closetable();

?>