<?
require_once( './user_base.php' );
require_once( LSK_PATH_ENGINE.'/fckeditor/fckeditor.php');

$con = new LskDBConnector();
$Sections = new LskSections( $con );
$Book = new LskGuestbook( $con );
$ItemID  = $_GET['item_id'];
$Row=$Book->GetRowInfo($ItemID);

$IS_Comment=(strtolower($_GET['mode'])=='comment');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Гостевая книга</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link rel=stylesheet type=text/css href="./style.css">
</head>
<script>
//------------------------------------------------------------------------------
function selectOption( element_id, value )
{
	var obj = document.getElementById( element_id );

	for (var i=0; i < obj.options.length; i++)
	{
		if (obj.options[i].value == value )
			obj.options[i].selected = true;
	}
}
</script>
<body bgcolor="#CCCCCC">

<?
PrintHeader( 'Гостевая книга' );
?>

<!--------------------------------------------------------->
<!--               NAVIGATOR                             -->
<!--------------------------------------------------------->
<? include('./navigator.php'); ?>

<?php

$Pars['visible']	= 0;
$Pars['name']		= $_POST['NewName'];
$Pars['mail']		= $_POST['NewMail'];
$Pars['text']		= $_POST['NewText'];
$Pars['comment']	= $Row['comment'];

if ( isset($_POST['Add']) ) {
    $Pars['comment']	= 'Комментарий отсутствует.';
    $Book->Add($Pars);
}
elseif ( isset($_POST['Update']) ){
    $Pars['visible']	= 1;
	if ($IS_Comment) {
	    $Pars['text']	= $Row['text'];
	    $Pars['comment']= $_POST['NewText'];
	}
	$Book->Update( $ItemID, $Pars);
	echo '<script>location.replace( \'guestbook_edit.php\' )</script>';
}
elseif ( isset($_POST['Delete']) ) $Book->RemoveArray( $_POST['todelete'] );
elseif ( isset($_POST['Approve']) )
{
	$Book->SetVisibleAll( false );
	$Book->SetVisibleArray( $_POST['approved'], true );
}
?>

<!--------------------------------------------------------->
<!--               SECTIONS                              -->
<!--------------------------------------------------------->
<table align="left" border="1" bordercolor="#000000" bgcolor="#C6D0E9" style="border-collapse:collapse;">
<form name="form_link" action="" method="post" enctype="multipart/form-data">
<tr><td><strong>Разделы (Видимость):</strong>
<tr><td><? include('./sections.php'); ?>
</form>
</table>

<!--------------------------------------------------------->
<!--               WORK                                  -->
<!--------------------------------------------------------->
<table align="center" border="1" bordercolor="#000000" bgcolor="#C6D0E9" >
<form name="form_spots" action="" method="post" enctype="multipart/form-data">
<tr>
<td>
<table width="600">
<?
$Template = '
	<tr><th align="left" width="50%">Сообщениe от <i>$_name</i> ( $_mail )<th align="left" width="50%">Комментарий:
	<tr><td colspan="2"><table border="0" width="100%"><tr><td width="50%">$_text<td>$_comment</table>
	<tr><td><input type="button" onclick="location.replace( \'guestbook_edit.php?mode=Correct&item_id=$_id\' )" value="Редактировать">
			<input type="button" onclick="location.replace( \'guestbook_edit.php?mode=Comment&item_id=$_id\' )" value="Комментировать">
		<td align="right">Удалить<input name="todelete[]" value="$_id" type="checkbox"><br>Разрешить<input name="approved[]" value="$_id" type="checkbox" $_cvisible>';
$Book->PrintAllTemplate( $Template, true );
?>
	<tr><td colspan="2" align="left"><hr>
		Имя:&nbsp;&nbsp;&nbsp;<input type="text" name="NewName" align="left" value="<?=$Row['name']?>"><br>
		Адрес:<input type="text" align="left" name="NewMail" value="<?=$Row['mail']?>">
		<input type="submit" name="Approve" value="Разрешить отмеченные">
		<input type="submit" name="Delete" onclick=<?=_CONFIRM?> value="Удалить отмеченные">

	<tr><td colspan="2">
<?
$oFCKeditor = new FCKeditor( 'NewText' );
$oFCKeditor->BasePath = '../lsk_engine/fckeditor/';
$oFCKeditor->Value = $IS_Comment?$Row['comment']:$Row['text'];
$oFCKeditor->ToolbarSet	= 'lskNewsToolbar';
$oFCKeditor->Width  = '100%';
$oFCKeditor->Height = '200';
$oFCKeditor->Create();

$SubmitName=isset($_GET['item_id'])?'Update':'Add';
?>
<input type="hidden" name="mode_t" id="_mode_t" value="<?=$_GET['mode']?>">
<tr><td><input type="submit" name="<?=$SubmitName?>" value="<?=isset($_GET['item_id'])?'Изменить':'Добавить'; ?>">
<td>
</table>
</form>
</table>
</body>
</html>