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

include("include/dbcommon.php");
include("include/##@TABLE.strShortTableName##_variables.php");

##if @BUILDER.bCreateLoginPage##
if(!@$_SESSION["UserID"] || !CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
{ 
	return;
}
##endif##

$field = @$_GET["field"];
if(!CheckFieldPermissions($field))
	return;

//	construct sql


$keys=array();
##foreach @TABLE.arrKeyFields as @k##
$keys["##@k s##"]=postvalue("key##@index##");
##endfor##
$where=KeyWhere($keys);

/*
$sql=$gstrSQL;
$sql = AddWhere($sql,$where);
*/



##if @TABLE.nSecOptions==ADVSECURITY_VIEW_OWN  && @BUILDER.nLoginMethod==SECURITY_TABLE && @BUILDER.bCreateLoginPage##
$where=whereAdd($where,SecuritySQL("Search"));
//$sql = AddWhere($sql,SecuritySQL("Search"));
##endif##

$sql = gSQLWhere($where);

$rs = db_query($sql,$conn);
if(!$rs)
  return;

$data=db_fetch_array($rs);

$nWidth = GetNCols($field);
$nHeight = GetNRows($field);
$id=postvalue("id");
$cfieldname=GoodFieldName($field).($id!='' ? "_".$id : '');
$cfield="value_".GoodFieldName($field).($id!='' ? "_".$id : '');

$onsubmit="";
if(@$_REQUEST["browser"]!="ie")
	$onsubmit="onsubmit=\"return document.getElementById('".$cfield."').value;\"";
echo "<html><body style=\"margin:0\"><form name=\"innovaform\" ".$onsubmit.">";
echo "<script type=\"text/javascript\" src=\"plugins/innovaeditor/scripts/innovaeditor.js\"></script>";
echo "<textarea id='".$cfield."' name='" . $cfield . "' style='width: " . ($nWidth) . "px;height: " . ($nHeight) . "px;'>"  ;
if($data)
	echo htmlspecialchars($data[$field]) ;
echo "</textarea>";
echo "<script>";
echo "var oEdit" . $cfieldname . " = new InnovaEditor('oEdit" . $cfieldname . "');";
echo "oEdit" . $cfieldname . ".mode='HTMLBody';";
echo "oEdit" . $cfieldname . ".width='" . ($nWidth) . "px';";
echo "oEdit" . $cfieldname . ".height='" . ($nHeight) . "px';";
echo "oEdit" . $cfieldname . ".REPLACE('" . $cfield . "');";
echo "</script>";
echo "</form></body></html>";

return;

?>
