<?php
include ('../db.php');
include ('config.inc.php');
$title="Редактирование";
$LINK = mysqli_connect($SQLSERVER, $SQLUSER, $SQLPASSWORD,$SQLBASE) or die(mysqli_error($LINK));
mysqli_query($LINK,"SET NAMES 'utf8'");
mysqli_query($LINK,"SET CHARACTER SET 'utf8'");
$footer="</body></html>";
$type = 'page';
if (isset($_GET['type'])) {
$type = $_GET['type'];
}
$item="";
if (isset($_GET['item'])) {
$item = $_GET['item'];
};
$array = array();
$response = GetId($item,$LINK);
include ('panel.inc.php');
$p_id = $item;
if (isset($_POST['type'])) {
switch ($_POST['type']) {
case 'page':
$response = GetId($_POST['id'],$LINK);
$array = mysqli_fetch_assoc($response);
$p_name = $_POST['name'];
$p_cnt =$_POST['content'];
$p_template =$_POST['template'];
$p_id =$_POST['id'];
if ($array['id']=="") {
$response = AddPage($p_id,$p_name,$p_template,$p_cnt,$LINK);
$item = $p_id;
} else {
$response = ModifyPage($p_id,$p_name,$p_template,$p_cnt,$LINK);
}
break;
case 'template':
$response = TemplateCheck($_POST['id'],$LINK);
$array = mysqli_fetch_assoc($response);
$p_cnt =$_POST['content'];
$p_id =$_POST['id'];
if ($array['id']=="") {
AddTemplate($p_id,$p_cnt,$LINK);
} else {
ModifyTemplate($p_id,$p_cnt,$LINK);
}
break;
case 'block':
$response = GetRealChankId($_POST['id'],$LINK);
$array = mysqli_fetch_assoc($response);
$p_cnt =$_POST['content'];
$p_id =$_POST['id'];
if ($array['id']=="") {
AddChank($p_id,$p_cnt,$LINK);
} else {
ModifyChank($p_id,$p_cnt,$LINK);
}
default :
break;
}
$type = $_POST['type'];
$item = $_POST['id'];
}
switch ($type) {
case 'page':
$response = GetId($item,$LINK);
$response = GetTemplateId($item,$LINK);
$array = mysqli_fetch_assoc($response);
$idt = $array['template'];
$response = GetPageName($item,$LINK);
$array = mysqli_fetch_assoc($response);
$name = $array['name'];
$response = GetIdContent($item,$LINK);
$array = mysqli_fetch_assoc($response);
$content = $array['content'];
break;
case 'template':
$response = GetTemplate($item,$LINK);
$array = mysqli_fetch_assoc($response);
$content = $array['content'];
break;
case 'block':
$response = GetChank($item,$LINK);
$array = mysqli_fetch_assoc($response);
$content = $array['content'];
break;
}
echo '<div align="center">';
echo '<form action="edit.php" method="post" id="mainform">';
echo '<table width="80%" border="1">';
echo '<tr>';
echo '<td height="120px" align="center"><label>Идентификатор: </label></td>';
echo '<td align="center"><input type="text" name="id" value="'.$item.'"></td>';
echo '</tr>';
if ($type=='page') {
echo '<tr>';
echo ' <td height="120px" align="center"><label>Имя страницы: </label></td>';
echo ' <td align="center"><input type="text" name="name" value="'.$name.'"></td>';
echo ' </tr>';
echo ' <tr>';
echo ' <td height="120px" align="center"><label>Шаблон: </label></td>';
echo ' <td align="center"><input type="text" name="template" value="'.$idt.'"></td>';
echo ' </tr>';
};
echo ' <tr>';
echo ' <td colspan="2" align="center">';
echo ' <textarea id="mytextbox" form="mainform" name="content" style="height: 450px; width: 900px" value="">'.$content.'</textarea>';
echo ' </td>';
echo ' </tr>';
echo '<tr>';
echo ' <td colspan="2" align="center">';
echo ' <br><br>';
echo ' <input type="hidden" name="item" value="'.$item.'">';
echo ' <input type="hidden" name="type" value="'.$type.'">';
echo ' <input type="submit" class="btn" value="Сохранить" width="80">';
echo ' </table>';
echo ' </form>';
echo ' <form action="index.php" method="get">';
echo ' <input type="hidden" name="id" value="'.$type.'">';
echo ' <input type="submit" class="btn" value="Закрыть" width="80">';
echo ' </form>';
echo ' </div>';
echo $footer;
?>