<?php 

include "../admin/adminses.php";
$whatpage = preg_replace("/[^a-z0-9-_]/i","",$_REQUEST['what']);
include "../engine/functions.php";
require_once("../admin/fckeditor/fckeditor.php");
$sBasePath = $_SERVER['PHP_SELF'] ;
@$updateornot = $_POST["Submit"];
@$title = $_POST["title"];
@$content = $_POST["article"];
@$myinclude = trim($_POST["myinclude"]);
@$description = trim($_POST["description"]);
@$keywords = trim($_POST["keywords"]);

if (empty($updateornot)) {
$d='../articles/';
	$dir = opendir($d);
	while ($f = readdir($dir)) {
 				$thefile=$whatpage . ".dat";

 				$pos = strpos($f, $thefile);
 				if ($pos === false) {

	 			} else {
				
				$myFile = '../articles/' . $thefile;

				$fh = fopen($myFile, 'r');
				$data = fread($fh, filesize($myFile));
				fclose($fh);

			 $title = explode("<!-- Kan_title -->",$data);
       @$contentcenter .=  "<b>Страница: </b>" . $title[1] . "<br />";
			 $sitetitle="Редакция страницы:  " . $title[1];

       $content = explode("<!-- Kan_content -->",$data);
			 $myinclude = explode("<!-- Kan_myinclude -->",$data);
			 $myinclude=$myinclude[1];
			 $description = explode("<!-- Kan_description -->",$data);
			 $description=$description[1];
			 $keywords = explode("<!-- Kan_keywords -->",$data);
			 $keywords = $keywords[1];

$url=$_SERVER['PHP_SELF'] . "?what=$whatpage";			 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
                <meta http-equiv="content-type" content="text/html;charset=windows-1251" />
		<title><?php echo $sitetitle;?></title>
		<meta name="description" content="Kan-Sdudio" />
		<style type="text/css" media="screen"><!--
body {
	font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #6B6B6B;
}
TD.header  {
	background-image: url("images/CMS.jpg");
	height: 78px
	}
TD.area {
font-family: Tahoma;
}
.links { color: #fff; font: 10px Tahoma, Verdana; word-spacing: 0.05em }
.links a { color: #fff }
.links a:hover { color: #fff; text-decoration: underline }
div.sub_text{
		margin-top: -10px;
		margin-left: 2px;
		color: white;
		font-family: Arial;}
h1 {
	color: white;
	border: 0px none;
	padding: 0;
	margin: 0;
	font-weight: bold;
	letter-spacing: -2px;}
h3 {
	color: #000000;
	font-size: 16px;
	font-weight: bold
	}
h2 {
	color: #000000;
	font-size: 12px;
	font-weight: bold
	}
TD.main_cell {
	height: 500px;
	}
TD {
	font-size: 12px
	}

.Nav {
	font-size: 12px
	}

A {
	color: #A70303
	}

A:hover {
	color: #000000
	}


.arrowlistmenu{
width: 180px; /*width of menu*/
}

.arrowlistmenu .headerbar{
font: bold 14px Arial;
color: white;
background: black url(images/titlebar.png) repeat-x center left;
margin-bottom: 10px; /*bottom spacing between header and rest of content*/
text-transform: uppercase;
padding: 4px 0 4px 18px; /*header text is indented 10px*/
}

.arrowlistmenu ul{
list-style-type: none;
margin: 0;
padding: 0;
margin-bottom: 8px; /*bottom spacing between each UL and rest of content*/
}

.arrowlistmenu ul li{
padding-bottom: 2px; /*bottom spacing between menu items*/
}

.arrowlistmenu ul li a{
color: #A70303;
background: url(images/arrowbullet.png) no-repeat center left; /*custom bullet list image*/
display: block;
padding: 2px 0;
padding-left: 19px; /*link text is indented 19px*/
text-decoration: none;
font-weight: bold;
border-bottom: 1px solid #dadada;
}

.arrowlistmenu ul li a:visited{
color: #A70303;
}

.arrowlistmenu ul li a:hover{ /*hover state CSS*/
color: #FF0000;
background-color: #F3F3F3;
}

.arrowlistmenu ul li a:active{ /*hover state CSS*/
color: #A70303;
background-color: #F5E5CE;
}
--></style>

	</head>

	<body bgcolor="#2E2E2E">
		<div align="center">
			<table align="center" width="940" border="0" cellspacing="0" cellpadding="0" bgcolor="white">
				<tr>
					<td bgcolor="#646464"></td>
				</tr>
				<tr>
					<td class="header" style="padding: 0px;" bgcolor="#939393">
					</td>
				</tr>
							<tr>
					<td style="border-bottom: 1px solid #dadada;"></td>
				</tr>
				<tr>
					<td class="main_cell" valign="top">
						<table style="height: 100%;" width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td style="border-right: 1px dashed #666666; padding: 5px;" valign="top" align="left" width="160">
                                <div class="arrowlistmenu">

<h3 class="headerbar">Навигация</h3>
<ul>
<li><a href="../admin/index.php">Начало</a></li>
<li><a href="../admin/add.php">Добавить страницу</a></li>
<li><a href="../admin/settings.php">Настройки</a></li>
<li><a href="../admin/menueditor.php">Редакция меню</a></li>
<li><a href="../admin/cateditor.php">Редакция категорий</a></li>
<li><a href="../admin/templateeditor.php">Редакция шаблона</a></li>
<li><a href="../" target="_blank">ПЕРЕЙТИ НА САЙТ</a></li>
</ul>
</div><center>
<form method="POST" action="../admin/login.php" > 
<input type="hidden" name="name" value="usersite">
<input type="hidden" name="pass" value="kandidat">
<input type="submit" style="margin-top:10px; display:block; border:1px solid #CCCCCC; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;" value="Выйти" name="logout"> 
</form></center></td>
								<td style="padding: 5px;" valign="top" align="left">

<?php
echo "<form action=\"$url\" method=\"post\" name=\"my_form\">
<br /><label for=\"title\"><b>Заголовок:</b></label>
<input type=\"text\" name=\"title\" id=\"title\" value=\"$title[1]\" size=40><br><br>"; 
$old= "$content[1]";
$oFCKeditor = new FCKeditor('article') ;
$oFCKeditor->BasePath	= '../admin/fckeditor/' ;
$oFCKeditor->Value		= $content[1] ;
$oFCKeditor->Height	= 500 ;
$oFCKeditor->Create() ;
echo "<label for=\"myinclude\"><b>ИМЯ php-кода:</b>&nbsp;&nbsp;&nbsp;</label>
<input type=\"myinclude\" name=\"myinclude\" id=\"myinclude\" value=\"$myinclude\" size=10><font color=#FF000> <i>находится в папке /mycode</i></font><br><br> 
<label for=\"description\"><b>Описание:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input type=\"description\" name=\"description\" id=\"description\" value=\"$description\"><br /><br /> 
<label for=\"keywords\"><b>Ключевые слова:</b></label>
<input type=\"text\" name=\"keywords\" id=\"keywords\" value=\"$keywords\"><br /> 
<br /><br />
<div align=\"center\"><input type=\"submit\" class=\"submit-button\" id=\"Submit\" name=\"Submit\" value=\"Изменить\" /></div><br />
</form>";
				break;
  			}
	
	}
}else{
$myFile = "../articles/" . $whatpage . ".dat";

unlink($myFile);

	@chmod("../articles/".$whatpage.".dat", 0777);
	$ourFileName = "../articles/".$whatpage.".dat";
	$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
	fclose($ourFileHandle);

@$somecontent .= "<!-- Kan_title -->\n";
$somecontent .= $title;
$somecontent .= "<!-- Kan_title -->\n";
$somecontent .= "<!-- Kan_content -->\n";
$somecontent .= $content;
$somecontent .= "<!-- Kan_content -->\n";
$somecontent .= "<!-- Kan_myinclude -->\n";
$somecontent .= $myinclude;
$somecontent .= "<!-- Kan_myinclude -->\n";
$somecontent .= "<!-- Kan_description -->\n";
$somecontent .= $description;
$somecontent .= "<!-- Kan_description -->\n";
$somecontent .= "<!-- Kan_keywords -->\n";
$somecontent .= $keywords;
$somecontent .= "<!-- Kan_keywords -->\n";

$filename=$ourFileName;
if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'a')) {
         echo "Невозможно окрыть файл ($filename)";
         exit;
   }
$somecontent=stripslashes($somecontent);
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Невозможна запись в файл ($filename)";
       exit;
   }
  
   fclose($handle);
    @chmod("../articles/".$whatpage.".dat", 0604);
       $sitetitle="Редакция страницы";
@$contentcenter .=  "<h3>Успешно изменена</h3> Страница: <b>".$whatpage."<br /><br />" .  $title. "</b><br /><br />
Если изменяли заголовок страницы, то отредактируйте также меню ссылок, введите новый заголовок:<br /><b>" .  $title. "</b><br /> для страницы: <b>".$whatpage."</b><br /><br />
Перейти в раздел <a href=\"../admin/menueditor.php\">Ред.меню</a>";
include "admintemplate.php";
exit();
}

} 

?></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
			    <td style="padding: 5px;" valign="top">
						<hr noshade="noshade" size="1" />
 					Powered by : <a href="http://www.Kan-Studio.ru">Kandidat CMS v.1.3.6 Pro</a>, дизайн : <a href="http://www.clike.ru/">Clike.ru</a></td>
				</tr>
			</table>
			<p></p>
		</div>
	</body>

</html>