<?php 
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");

include("include/dbcommon.php");

$table = postvalue("table");
if (!checkTableName($table))
	exit(0);

include("include/".$table."_variables.php");

if((!isLogged() || !CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search")) && postvalue("action")<>"add")
	return;

$ptype = postvalue("ptype");
$field = postvalue("field");
$pSet = new ProjectSettings($strTableName, $ptype);
if(!$pSet->checkFieldPermissions($field) && @$_GET["action"] <> "add")
	return;

//	construct sql
$data = false;
if(@$_GET["action"]<>"add")
{
	$keysArr = $pSet->getTableKeys();
	$keys = array();
	foreach ($keysArr as $ind=>$k)
		$keys[$k] = postvalue("key".($ind+1));
	
	$where = KeyWhere($keys);
		if($pSet->getAdvancedSecurityType() == ADVSECURITY_VIEW_OWN)
		$where = whereAdd($where,SecuritySQL("Search"));	
	$sql = $gQuery->gSQLWhere($where);
	$rs = db_query($sql,$conn);
	if(!$rs)
		return;
	$data = db_fetch_array($rs);
}
else 
{
	$data = array();
	$data[$field] = @$_SESSION[$strTableName."_".$field."_rte"];
}

$nWidth = $pSet->getNCols($field);
$nHeight = $pSet->getNRows($field);
$id = postvalue("id");
$cfieldname = GoodFieldName($field)."_".($id!=='' ? $id : '1');
$cfield = "value_".GoodFieldName($field)."_".($id!=='' ? $id : '1');
$onsubmit = "";
if(@$_REQUEST["browser"]!="ie")
	$onsubmit = "onsubmit = \"return document.getElementById('".$cfield."').value;\"";
	
echo '<html>
		<body style="margin:0;">
		<form name="innovaform" '.$onsubmit.'>
			<script type="text/javascript" src="plugins/innovaeditor/scripts/innovaeditor.js"></script>
			<textarea id="'.$cfield.'" name="'.$cfield.'" style="width:'.($nWidth).'px;height:'.($nHeight).'px;">';
			
if($data)
	echo htmlspecialchars($data[$field]);
	
echo'		</textarea>
			<script>
				oEdit'.$cfieldname.' = new InnovaEditor("oEdit'.$cfieldname.'");
				oEdit'.$cfieldname.'.mode = "HTMLBody";
				oEdit'.$cfieldname.'.width = "'.($nWidth).'px";
				oEdit'.$cfieldname.'.height = "'.($nHeight).'px";
				oEdit'.$cfieldname.'.cmdAssetManager = "modalDialogShow(\"'.$projectPath.'/plugins/innovaeditor/assetmanager/assetmanager.php\",640,445);";
				oEdit'.$cfieldname.'.arrCustomButtons = [["AssetManager", oEdit'.$cfieldname.'.cmdAssetManager, "Asset Manager", "btnCustom1.gif"]];
				//oEdit'.$cfieldname.'.features = ["Preview"];
				oEdit'.$cfieldname.'.REPLACE("'.$cfield.'");
			</script>
		</form>
	</body>
</html>';
return;
?>