<?php

include("setting.php");
//$datafile = "data.html";

//
$pass1 = $_POST["pass1"];
$pass2 = $_POST["pass2"];
$action = $_POST["action"];
$r_name1 = $_POST["r_name1"];
$r_name2 = $_POST["r_name2"];
$field2 = $_POST["field2"];
$newtext = $_POST["newtext"];

// connect db

$db = mysql_connect("localhost", "littlege_user2", "pass2");
mysql_select_db("littlege_db1");

// end connect db
$msg = "";

// time
$today = date("H:i:s");                           
$plus_time = strtotime ("+0 hour"); // +0 hours
$cur_date = date(Y."-".m."-".d, $plus_time);

//if(isset($action) && $REQUEST_METHOD == "POST")
//{
	if($pass1 == $password1 && $pass2 == $password2)
	{
		if($action == "save" && $r_name2 != "")
		{
			mysql_query("UPDATE info_table_lmg SET page_text = '$newtext', page_update = '$cur_date' WHERE page_name = '$r_name2'");
			$msg = $msg." New information is saved <br> (".$r_name2.")";
			$currenttext = $newtext;
			$r_name1 = $r_name2;
		}
	}
	else
	{
		$msg = $msg." Incorrect passwords <br> ";
		$currenttext = $newtext;
	}
	
//}

////

if($r_name1 != "" && $action == "nosave")
{
	$result = mysql_query("SELECT * FROM info_table_lmg WHERE page_name = '$r_name1'",$db);
	if($myrow = mysql_fetch_array($result))
	{
		$currenttext = $myrow["page_text"];
		$msg = $msg." View <br> (".$r_name1.")";
	}
}

//

if($action == "save" && $r_name2 != "")
{
	$result = mysql_query("SELECT * FROM info_table_lmg WHERE page_name = '$r_name2'",$db);
	if($myrow = mysql_fetch_array($result))
	{
		$currenttext = $myrow["page_text"];
	}
}

//////////////////////////////////////////////////////////////
?>
<HTML>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=windows-1251">
<title>
WYSIWYG Editor //
</title>

<style>
.field 
{
	font-family: Tahoma,Verdana;font-size:10pt;border: 2px double #EEEEEE;
}
.field2 
{
	font-family: Tahoma,Verdana;font-size:10pt;border: 2px outset #000000; font-weight:bold;color:white;background-color:#880000;
}
body
{
	SCROLLBAR-FACE-COLOR: #FFFFFF; 
	SCROLLBAR-HIGHLIGHT-COLOR: #CCCCCC; 
	SCROLLBAR-SHADOW-COLOR: #CCCCCC; 
	SCROLLBAR-3DLIGHT-COLOR: #EFEFEF; 
	SCROLLBAR-ARROW-COLOR: #B9BCA4; 
	SCROLLBAR-TRACK-COLOR: #F5F5F3; 
	SCROLLBAR-DARKSHADOW-COLOR: #F5F5F3;
	BACKGROUND-COLOR: #F5F5F3;
}
</style>


<BODY>
<table align="center" width="100%" height="100%">
<tr>
<td align="center" vAlign="middle">
<DIV id="ed1" style="width:80%;height:80%;"></DIV>
<br>

<form name="form1" method="POST" action="<?=$SCRIPT_NAME?>"  enctype="multipart/form-data">
<input type="hidden" name="action" value="nosave">
<input type="hidden" name="r_name2" value="<?=$r_name1?>">
<select name="r_name1" class="field2">
<option value="home_eng_1">home_eng_1</option>
<option value="history_eng_1">history_eng_1</option>
<option value="rules_eng_1">rules_eng_1</option>
<option value="entry_form_eng_1">entry_form_eng_1</option>
<option value="delegates_eng_2006_1">delegates_eng_2006_1</option>
<option value="delegates_eng_2007_1">delegates_eng_2007_1</option>
<option value="delegates_eng_2008_1">delegates_eng_2008_1</option>
<option value="delegates_eng_2009_1">delegates_eng_2009_1</option>
<option value="delegates_eng_2010_1">delegates_eng_2010_1</option>
<option value="partners_eng_1">partners_eng_1</option>
<option value="contact_eng_1">contact_eng_1</option>
</select>&nbsp;<INPUT type=button value="View Text" onClick="document.form1.submit();" class="field2" style="cursor:hand;" title="View Text">
<textarea name="newtext" class="field" style="display:none;"><?=$currenttext?></textarea>
<INPUT type=password value="<?=@$pass1?>" name="pass1" class="field" size="3"><font face="Tahoma,Verdana,Arial" size="1"><b>- Pass 1</b></font>
<INPUT type=password value="<?=@$pass2?>" name="pass2" class="field" size="3"><font face="Tahoma,Verdana,Arial" size="1"><b>- Pass2</b></font>
<INPUT type=button value="Save" onClick="saveText(editor.HTML);" class="field2" style="cursor:hand;" title="Save Information">
<INPUT type=button value="Images Manager" onClick="document.location.href='images/index.php'" class="field2" style="cursor:hand;" title="View / Add / Delete Images">
<br>
<font style="color: #BB0000; font-size: 8pt; font-weight: bold; font-family: Tahoma;">
<?php

echo($today);
echo("<br>");

if($msg == "")
{

}
else
{
	echo($msg);
}

?>
</font>

</form>
</td>
</tr>
</table>
<br>
<br>
<SCRIPT language="Jscript" type="text/Jscript" src="WHE/labels.js"></SCRIPT>
<SCRIPT language="Jscript" type="text/Jscript" src="WHE/panel.js"></SCRIPT>
<SCRIPT language="Jscript" type="text/Jscript" src="WHE/HTMLEditor.js"></SCRIPT>
<SCRIPT language="Javascript">

function saveText(htmlText)
{	
		var error = "";

		document.form1.newtext.value = htmlText;
		//
		/*
		if(document.form1.newtext.value.length <= 25)
		{
			error = error + "Enter text\n";
		}
		*/
		//
		if(document.form1.pass1.value=="")
		{
			error = error + "Enter password 1\n";
		}
		if(document.form1.pass2.value=="")
		{
			error = error + "Enter password 2\n";
		}

		if(error)
		{
			alert("- Message -\n\n" + error);
		}
		if(!error)
		{
			document.form1.action.value = "save";
			document.form1.submit();
		}

	
}
</SCRIPT>
<?php
//echo('<script>'."\n");
//echo('var HTML = "<body>'.$data_text.'</body>";'."\n");
//echo('</script>'."\n");
?>
<script language="JavaScript">
  var lang = "EN";
  var HTML = document.form1.newtext.value;
  if(HTML == "")
  {
	  //HTML = "<BODY><LINK href=js_css/center.css rel=stylesheet></BODY>";
	  HTML = "<BODY></BODY>";
  }
  HTMLEditor("editor","ALL",ed1,lang,HTML,"WHE/","images/");
  editor.PutHTML(HTML);
</script>

</BODY>
</HTML>
