<?php
/**********************************************************************/
# Title: MW- ver. 4.1
# Copyright By  Moy-weB  (http://moyweb.moy.su)
# Изготовлениш шаблонов (скинов), разработка дизайна, написание скриптов
# Версия для Lineage-II
# Corsar, I-Andi (2009)
/**********************************************************************/
require_once("header.php");
if (isset($_GET['id'])) 
{
$id = $_GET['id'];
if (!file_exists("../data/" . $id . ".php")) die ("Искомой страницы не существует. <a href='index.php'>На главную</a>");
include("../data/" . $id . ".php"); 
$file_menu = file("../data/menu.csv");
foreach( $file_menu as $line )
{
	$elem = explode (";", $line);
	if ( $elem[0] == $id ) 
	{
		$alias = $elem[1];
		$parent = trim($elem[3]);	
	}
}
?>
<br>
<h3>Редактирование  рекламы</h3>

	<table border=0 width="850">
	<tr><td valign="top" align="left">

<form action="admin_reklama.php" method="post">
<input type="hidden" name="action" value="do">
<input type="hidden" name="id" value="<? echo $id; ?>">
<!-- TinyMCE -->
<!----->

	<!-- This <div> holds alert messages to be display in the sample page. -->
	<div id="alerts">
		<noscript>
			<p>
				<strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
				support, like yours, you should still see the contents (HTML data) and you should
				be able to edit it normally, without a rich editor interface.
			</p>
		</noscript>
	</div>
	<!-- This <fieldset> holds the HTML that you will usually find in your
	     pages. -->
	<form action="admin_new.php" method="post">
<input type="hidden" name="action" value="do" />
			<p>
				<label for="editor1">
					 (<span id="count"> </span>
					languages!):</label><br/>
				<select disabled="disabled" id="languages" onchange="createEditor( this.value );">
					<script type="text/javascript">
					//<![CDATA[

						// Get the language list from the _languages.js file.
						for ( var i = 0 ; i < window.CKEDITOR_LANGS.length ; i++ )
						{
							document.write(
								'<option value="' + window.CKEDITOR_LANGS[i].code + '">' +
									window.CKEDITOR_LANGS[i].name +
								'</option>' );
						}

					//]]>
					</script>
				</select>
				<br/>

			</p>
			<p>
				<textarea cols="80" id="message" name="editor1"  rows="10"><? echo $reklama; ?></textarea>
				<script type="text/javascript">
				//<![CDATA[

					// Set the number of languages.
					document.getElementById( 'count' ).innerHTML = window.CKEDITOR_LANGS.length;

					var editor;

					function createEditor( languageCode )
					{
						if ( editor )
							editor.destroy();

						// Replace the <textarea id="editor"> with an CKEditor
						// instance, using default configurations.
						editor = CKEDITOR.replace( 'editor1',
							{
								language : languageCode,

								on :
								{
									instanceReady : function()
									{
										// Wait for the editor to be ready to set
										// the language combo.
										var languages = document.getElementById( 'languages' );
										languages.value = this.langCode;
										languages.disabled = false;
									}
								}
							} );
					}

					// At page startup, load the default language:
					createEditor( '' );

				//]]>
				</script>
			</p>
	 

<!----->
<!-- /tinyMCE -->
<table>
<tr>
</tr>
</table>
<input type="submit" value="Сохранить">
</form>
	</td>
	<td width=150 valign=top align=right>
	<div style="padding-top:60px;">
		<table border=0 width="150">
		<tr>
		<td>
<iframe src="admin_img_form.php" frameborder="0" width="150px" height="200px" marginwidth="0" marginheight="0"></iframe>
		</td>
		</tr>
		<tr>
		<td>
<iframe src="admin_file_form.php" frameborder="0" width="150px" height="200px" marginwidth="0" marginheight="0"></iframe>
		</td>
		</tr>
		</table>
	</div>	
	</td></tr></table>
<?php
}
if (isset($_POST['action']))
{
	if (!isset($_POST['editor1']))
	{
		die ("Не указаны необходимые данные. <a href='index.php'>На главную</a>");
	}

	$text = stripslashes($_POST['editor1']);
	$content = "<?php\r\n\$reklama = <<< EOT\r\n" . $text . "\r\n" .
		"EOT;\r\n?>";
	if (!function_exists('file_put_contents'))
	{
		function file_put_contents ($filename, $content)
		{
			if ($fp = @fopen($filename, 'w'))
			{
				$result = fwrite($fp, $content);
				fclose ($fp);
				return $result;
			}
			else
			{
				return false;
			}
		} 
	}
	if (!file_put_contents("../data/" . $_POST['id'] . ".php", $content)) die ("Ошибка записи");
	else 
	{
		echo ("Успешно изменено. <a href='index.php'>Вернуться на главную</a>");
	}
}
require_once("footer.php");
?>