<?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 : '');

if(@$_REQUEST["browser"]=="ie")
	$onsubmit="onsubmit=\"updateRTEs();\"";
else
	$onsubmit="onsubmit=\"updateRTEs();return this.elements['".$cfield."'].value;\"";

echo "<html><body style=\"margin:0;\"><form name=\"rteform\" ".$onsubmit.">";
echo "<script type=\"text/javascript\" src=\"include/richtext.js\"></script>";
echo "<script language=\"JavaScript\" type=\"text/javascript\">\r\n";
echo "var TEXT_VIEW_SOURCE='".jsreplace(##message VIEW_SOURCE##)."';\r\n";
echo "initRTE('include/images/', 'include/', '');\r\n";
echo "</script>";
echo "<script language=\"JavaScript\" type=\"text/javascript\">\r\n";
echo "writeRichText('".$cfield."', '";
if($data)
	echo jsreplace($data[$field]);
echo "', " . $nWidth . ", " . $nHeight . ", true, false);\r\n".
"</script>";
echo "</form></body></html>";

return;

?>
