<?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##
/////////////////////////////////////////////////////////////
//	check if logged in
/////////////////////////////////////////////////////////////
if(!@$_SESSION["UserID"] || !CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Edit"))
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}
##endif##

/////////////////////////////////////////////////////////////
//init variables
/////////////////////////////////////////////////////////////


$pageName = "edit.php";

$filename="";
$status="";
$message="";
$usermessage="";
$error_happened=false;
$readevalues=false;
$bodyonload="";
$key=array();
$next=array();
$prev=array();

$body=array();
$showKeys = array();
$showValues = array();
$showRawValues = array();
$showFields = array();
$showDetailKeys = array();
$IsSaved = false;
$HaveData = true;
$inlineedit = (postvalue("editType")=="inline") ? true : false;
##if @TABLE.bInlineEdit##
$templatefile = ( $inlineedit ) ? "##@TABLE.strShortTableName s##_inline_edit.htm" : "##@TABLE.strShortTableName##_edit.htm";
##else##
$templatefile = "##@TABLE.strShortTableName##_edit.htm";
##endif##


include('include/xtempl.php');
$xt = new Xtempl();



//	Before Process event
if(function_exists("BeforeProcessEdit"))
	BeforeProcessEdit($conn);

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

/////////////////////////////////////////////////////////////
//	process entered data, read and save
/////////////////////////////////////////////////////////////

if(@$_POST["a"]=="edited")
{
	$strWhereClause=KeyWhere($keys);
	##if @TABLE.nSecOptions!=ADVSECURITY_ALL && @BUILDER.nLoginMethod==SECURITY_TABLE && @BUILDER.bCreateLoginPage##
	//	select only owned records
	$strWhereClause=whereAdd($strWhereClause,SecuritySQL("Edit"));
	##endif##
##if @TABLE.arrEventHandlers[strEventID=="EVENT_BEFOREEDIT" || strEventID=="EVENT_AFTEREDIT"].len##
//	read old values
	$strSQL=gSQLWhere($strWhereClause);
	$rsold=db_query($strSQL,$conn);
	$dataold=db_fetch_array($rsold);
##endif##
	$evalues=array();
	$efilename_values=array();
	$files_delete=array();
	$files_move=array();
	$files_save=array();
	$blobfields=array();
##if @BUILDER.nDatabaseType==nDATABASE_Oracle##
	$blobs=array();
##endif##

##foreach Fields as @f filter IsUpdatable(@f) && (@f.bInlineEdit || @f.bEditPage)##
##if !@f.bEditPage##
	$condition = $inlineedit;
##elseif !@f.bInlineEdit##
	$condition = !$inlineedit;
##else##
	$condition = 1;
##endif##

	if($condition)
	{
	$value = postvalue("value_##@f.strName g##");
	$type=postvalue("type_##@f.strName g##");
	if(FieldSubmitted("##@f.strName s##"))
	{
##if @f.strEditFormat==EDIT_FORMAT_DATABASE_FILE && @f.ListFormatObj.strFilename || @f.strEditFormat==EDIT_FORMAT_FILE##
		$value=prepare_for_db("##@f.strName s##",$value,$type,postvalue("filename_##@f.strName g##"));
##else##
		$value=prepare_for_db("##@f.strName s##",$value,$type);
##endif##
	}
	else
		$value=false;
##if @f.strEditFormat==EDIT_FORMAT_READONLY##
##if @f.bAutoUpdate && @f.strDefaultValue.len##
	$value = ##@f.strDefaultValue##;
##else##
	$value = false;
##endif##
##endif##
	if($value!==false)
	{	
##if (@f.bResizeOnUpload || @f.bCreateThumbnail) && @f.strEditFormat==EDIT_FORMAT_FILE##
		if($value)
			$contents = GetUploadedFileContents("file_##@f.strName g##");
##endif##

##if @f.bCreateThumbnail && (@f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE || @f.strEditFormat==EDIT_FORMAT_FILE)##
	##if @f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE##
		if($value)
		{
			$ext = CheckImageExtension(GetUploadedFileName("value_##@f.strName g##"));
			$thumb = CreateThumbnail($value,##@f.nThumbnailSize##,$ext);
		}
		else
			$thumb="";

		$blobfields[]="##@f.strThumbnail s##";
		$evalues["##@f.strThumbnail s##"]=$thumb;
	##else##
		if($value)
		{
			$ext = CheckImageExtension(GetUploadedFileName("file_##@f.strName g##"));
			$thumb = CreateThumbnail($contents,##@f.nThumbnailSize##,$ext);
			$file = GetUploadFolder("##@f.strName s##")."##@f.strThumbnail s##".$value;
			$files_save[] = array("file"=>$thumb,"filename"=>$file);
		}
	##endif##
##endif##

##if @f.bResizeOnUpload && (@f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE || @f.strEditFormat==EDIT_FORMAT_FILE)##
	// resize image on upload
		if($value)
		{
	##if @f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE##
			$ext = CheckImageExtension(GetUploadedFileName("value_##@f.strName g##"));
			$thumb = CreateThumbnail($value,##@f.nNewSize##,$ext);
			$blobfields[]="##@f.strName s##";
			$value=$thumb;
	##endif##
		}
##endif##

##if @f.strEditFormat==EDIT_FORMAT_DATABASE_FILE || @f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE##
		$blobfields[]="##@f.strName s##";
##endif##		
		$evalues["##@f.strName s##"]=$value;
##if @f.strEditFormat==EDIT_FORMAT_DATABASE_FILE && @f.ListFormatObj.strFilename##
		$efilename_values["##@f.ListFormatObj.strFilename s##"]=$filename;
##endif##			
	}
##if @f.strEditFormat==EDIT_FORMAT_DATABASE_FILE && @f.ListFormatObj.strFilename##
	if($filename)
		$efilename_values["##@f.ListFormatObj.strFilename s##"]=$filename;
##endif##			

##foreach @TABLE.arrKeyFields as @k##
##if @k==@f.strName##
//	update key value
	if($value!==false)
		$keys["##@k s##"]=$value;
##endif##
##endfor##

//	processibng ##@f.strName## - end
	}
##endfor##

	foreach($efilename_values as $ekey=>$value)
		$evalues[$ekey]=$value;
//	do event
	$retval=true;
	if(function_exists("BeforeEdit"))
		$retval=BeforeEdit($evalues,$strWhereClause,$dataold,$keys,$usermessage,$inlineedit);
	if($retval)
	{		
		if(DoUpdateRecord($strOriginalTableName,$evalues,$blobfields,$strWhereClause))
		{
			$IsSaved=true;
//	after edit event
			if(function_exists("AfterEdit"))
			{
				foreach($dataold as $idx=>$val)
				{
					if(!array_key_exists($idx,$evalues))
						$evalues[$idx]=$val;
				}
				AfterEdit($evalues,KeyWhere($keys),$dataold,$keys,$inlineedit);
			}
		}
	}
	else
	{
		$readevalues=true;
		$message = $usermessage;
		$status="DECLINED";
	}
}

// PRG rule, to avoid POSTDATA resend
if ($IsSaved && no_output_done() && !$inlineedit )
{
	// saving message
	$_SESSION["message"] = ($message ? $message : "");
	// key get query
	$keyGetQ = "";
	##foreach @TABLE.arrKeyFields as @k##
		$keyGetQ.="editid##@index##=".rawurldecode($keys["##@k s##"])."&";
	##endfor##
	// cut last &
	$keyGetQ = substr($keyGetQ, 0, strlen($keyGetQ)-1);	
	// redirect
	header("Location: ##@TABLE.strShortTableName##_".$pageName."?".$keyGetQ);
	// turned on output buffering, so we need to stop script
	exit();
}
// for PRG rule, to avoid POSTDATA resend. Saving mess in session
if (!$inlineedit && isset($_SESSION["message"])){
	$message = $_SESSION["message"];
	unset($_SESSION["message"]);
}



/////////////////////////////////////////////////////////////
//	read current values from the database
/////////////////////////////////////////////////////////////

$strWhereClause=KeyWhere($keys);
##if @TABLE.nSecOptions!=ADVSECURITY_ALL && @BUILDER.nLoginMethod==SECURITY_TABLE && @BUILDER.bCreateLoginPage##
//	select only owned records
$strWhereClause=whereAdd($strWhereClause,SecuritySQL("Edit"));
##endif##

$strSQL=gSQLWhere($strWhereClause);

$strSQLbak = $strSQL;
//	Before Query event
if(function_exists("BeforeQueryEdit"))
	BeforeQueryEdit($strSQL,$strWhereClause);

if($strSQLbak == $strSQL)
	$strSQL=gSQLWhere($strWhereClause);
LogInfo($strSQL);
$rs=db_query($strSQL,$conn);
$data=db_fetch_array($rs);

if(!$data)
{
	if(!$inlineedit)
	{
		header("Location: ##@TABLE.strShortTableName##_list.##@ext##?a=return");
		exit();
	}
	else
		$data=array();
}

$readonlyfields=array();

##foreach Fields as @f filter (@f.bEditPage || @f.bInlineEdit)##
##if @f.bAutoUpdate && @f.strDefaultValue.len##
//if(!$data["##@f.strName s##"])
	$data["##@f.strName s##"] = ##@f.strDefaultValue##;
##endif##
##if @f.strEditFormat==EDIT_FORMAT_READONLY##
  ##if !NeedEncode(@f)##
$readonlyfields["##@f.strName s##"] = GetData($data,"##@f.strName s##", "##@f.strViewFormat s##");
  ##else##
$readonlyfields["##@f.strName s##"] = htmlspecialchars(GetData($data,"##@f.strName s##", "##@f.strViewFormat s##"));
  ##endif##
##endif##
##endfor##

if($readevalues)
{
##foreach Fields as @f filter  (@f.bEditPage || @f.bInlineEdit) && @f.strEditFormat!=EDIT_FORMAT_DATABASE_FILE && @f.strEditFormat!=EDIT_FORMAT_DATABASE_IMAGE && @f.strEditFormat!=EDIT_FORMAT_FILE && @f.strEditFormat!=EDIT_FORMAT_READONLY##
	$data["##@f.strName s##"]=$evalues["##@f.strName s##"];
##endfor##
}

/////////////////////////////////////////////////////////////
//	assign values to $xt class, prepare page for displaying
/////////////////////////////////////////////////////////////

//Array of includes js files	
//Basic includes js files
$includes="";
//javascript code
$jscode="";
//event for onsubmit
$onsubmit="";
//////////////////////////////////////////////////////////////////	
//	Begin Add validation params for InlineEdit or Edit	
//	validation stuff
	$onsubmit="$('#message_block').html('');";
	$regex='';
	$regexmessage='';
	$RTEfunc="";
	$regextype = "";
	$arrValidate = array();
//	for inlineEdit
	$editValidateTypes = array();
	$editValidateFields = array();
	$editValidateUseRTE = array();
	$editValidateCBList = array();
	$editValidateRegex = array();
	$editValidateRegexmes = array();	
	$editValidateRegexmestype = array();	
##foreach Fields as @f filter @f.bEditPage && (UseRTEINNOVA(@f) || UseRTEBASIC(@f))##
##if @first##
if(!$inlineedit)
{
##endif##
//	notvalidate field like INNOVA or RTEBASIC - ##@f.strName g##
	##if UseRTEINNOVA(@f)##
	$strRTE="INNOVA_FLY";
	##else##
	$strRTE="RTE_FLY";
	##endif##
	$RTEfunc.='setDataFromRTEInnova($(\'#value_##@f.strName g##\'),\''.$strRTE.'\',$(\'#editform\'),\'value_##@f.strName g##\');'; 
##if @last##
}
##endif##
##endfor##
//	Begin Edit validation	
//if use InnovaEditor or RTE on page add when useRTE will be with  -  "_FLY"
//if use InnovaEditor or RTE on page InineEdit when useRTE will be with out  -  "_FLY"
##foreach Fields as @f filter @f.bEditPage || (@f.bInlineEdit && @f.bListPage)##
##if @first##
if(!$inlineedit)
{	
	AddJSFile("validate");
	if(@$_REQUEST["language"])
		$language = $_REQUEST["language"];
	// may be elseif ?
	if(@$_SESSION["language"])
		$language = $_SESSION["language"];
	else
		$language = 'English';
	
	$jscode.="window.current_language='".jsreplace($language)."';\r\n";
	
	$jscode.="editValid = new validation();\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_REQUIRED='".jsreplace(##message INLINE_FIELD_REQUIRED##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_ZIPCODE='".jsreplace(##message INLINE_FIELD_ZIPCODE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_EMAIL='".jsreplace(##message INLINE_FIELD_EMAIL##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_NUMBER='".jsreplace(##message INLINE_FIELD_NUMBER##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_CURRENCY='".jsreplace(##message INLINE_FIELD_CURRENCY##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_PHONE='".jsreplace(##message INLINE_FIELD_PHONE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_PASSWORD1='".jsreplace(##message INLINE_FIELD_PASSWORD1##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_PASSWORD2='".jsreplace(##message INLINE_FIELD_PASSWORD2##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_STATE='".jsreplace(##message INLINE_FIELD_STATE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_SSN='".jsreplace(##message INLINE_FIELD_SSN##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_DATE='".jsreplace(##message INLINE_FIELD_DATE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_TIME='".jsreplace(##message INLINE_FIELD_TIME##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_CC='".jsreplace(##message INLINE_FIELD_CC##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_SSN='".jsreplace(##message INLINE_FIELD_SSN##)."';\r\n";	
}
##endif##
##if NeedValidationOnEdit(@f)##
//	validate field - ##@f.strName g##
##if @f.strEditFormat!=EDIT_FORMAT_TEXT_FIELD && @f.strEditFormat!=EDIT_FORMAT_TIME##
	$validatetype="";
##else##
##if @f.EditFormatObj.strValidateAs==VALIDATE_AS_NUMBER##
	$validatetype="IsNumeric";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_PASSWORD##
	$validatetype="IsPassword";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_EMAIL##
	$validatetype="IsEmail";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_CURRENCY##
	$validatetype="IsMoney";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_ZIPCODE##
	$validatetype="IsZipCode";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_PHONENUMBER##
	$validatetype="IsPhoneNumber";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_STATE##
	$validatetype="IsState";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_SSN##
	$validatetype="IsSSN";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_CC##
	$validatetype="IsCC";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_TIME##
	$validatetype="IsTime";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_REGEXP##
	$validatetype="Regular expression";
	$regex = "##@f.strRegex##";
	$regexmessage = "##@f.strRegexMessage.text s##";
	$regextype = "##@f.strRegexMessage.nameType s##";
##else##
	$validatetype="##@f.EditFormatObj.strValidateAs##";
	##if @f.EditFormatObj.strValidateAs##
	AddJSFile("validate/".$validatetype,"validate");
	##endif##	
##endif##
##endif##
##if @f.EditFormatObj.bRequired && @f.strEditFormat!=EDIT_FORMAT_CHECKBOX && @f.strEditFormat!=EDIT_FORMAT_READONLY##
	$second_validatetype="IsRequired";
##else##
	$second_validatetype="";
##endif##
##if UseRTEFCK(@f)##
	$strRTE='FCK';
##elseif UseRTEINNOVA(@f)##
	$strRTE='INNOVA'.(!$inlineedit ? '_FLY' : '');
##elseif  UseRTEBASIC(@f)##
	$strRTE='RTE'.(!$inlineedit ? '_FLY' : '');	
##else##
	$strRTE='';
##endif##
##if @f.nControlType==LCT_CBLIST##
	$lookup='CBList';
##elseif @f.nControlType==LCT_LIST || @f.nControlType==LCT_AJAX##
	$lookup='disp';
##elseif @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && @f.nLookupType!=LT_LOOKUPTABLE && @f.nSelectSize>1##	
	$lookup='list';
##else##
	$lookup='';	
##endif##
	$arrValidate[] = array(0 => "##@f.strName g##", 1 => $validatetype, 2 => $second_validatetype, 3 => $strRTE,
						   4 => $lookup, 5 => $regex, 6 => $regexmessage, 7 => $regextype);
##endif##
##endfor##
for($i=0;$i<count($arrValidate);$i++)
{
	if($arrValidate[$i][1])
	{
		if(!$inlineedit)
		{
			if ($arrValidate[$i][1]=="Regular expression")
				$bodyonload.="editValid.addRegex(document.editform['value_".$arrValidate[$i][0]."'],'".$arrValidate[$i][1]."','".
					jsreplace($arrValidate[$i][5])."','".jsreplace($arrValidate[$i][6])."','".jsreplace($arrValidate[$i][7])."');\r\n";
			else
				$bodyonload.="editValid.add(document.editform['value_".$arrValidate[$i][0]."'],'".$arrValidate[$i][1]."','".$arrValidate[$i][3]."','".$arrValidate[$i][4]."');\r\n";
		}
		else{
				//	Add Inline validation params
				$editValidateTypes[] = $arrValidate[$i][1];
				$editValidateFields[] = $arrValidate[$i][0];
				$editValidateUseRTE[] = $arrValidate[$i][3];
				$editValidateCBList[] = $arrValidate[$i][4];
				$editValidateRegex[] = jsreplace($arrValidate[$i][5]);
				$editValidateRegexmes[] = jsreplace($arrValidate[$i][6]);
				$editValidateRegexmestype[] = jsreplace($arrValidate[$i][7]);
			}
	}
	if($arrValidate[$i][2])
	{
		if(!$inlineedit)
		{
			if($arrValidate[$i][3]=='INNOVA_FLY' || $arrValidate[$i][3]=='RTE_FLY')
			{
				$bodyonload.='$("td[@class^=\'editshade_lb\']").each(function(i){';
				$bodyonload.='if($("iframe[@name=\'value_'.$arrValidate[$i][0].'\']",this).length)';
				$bodyonload.='editValid.add($("iframe[@name=\'value_'.$arrValidate[$i][0].'\']",this),"'.$arrValidate[$i][2].'","'.$arrValidate[$i][3].'","'.$arrValidate[$i][4].'");});';
			}
			else
				$bodyonload.="editValid.add(document.editform['".($arrValidate[$i][4]=='disp' ? "display_" : "")."value_".$arrValidate[$i][0].($arrValidate[$i][4]=='CBList' || $arrValidate[$i][4]=='list' ? "[]" : "")."'],'".$arrValidate[$i][2]."','".$arrValidate[$i][3]."','".$arrValidate[$i][4]."');\r\n";
		}
		else{
				//	Add Inline validation params	
				$editValidateTypes[] = $arrValidate[$i][2];
				$editValidateFields[] = $arrValidate[$i][0];
				$editValidateUseRTE[] = $arrValidate[$i][3];
				$editValidateCBList[] = $arrValidate[$i][4];
				$editValidateRegex[] = jsreplace($arrValidate[$i][5]);
				$editValidateRegexmes[] = jsreplace($arrValidate[$i][6]);
				$editValidateRegexmestype[] = jsreplace($arrValidate[$i][7]);
			}
	}		
}	
//	End Add validation params for InlineEdit or Edit
//////////////////////////////////////////////////////////////
##foreach Fields as @f filter (@f.bEditPage || @f.bInlineEdit) && @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && (@f.nControlType==LCT_LIST || @f.bAllowToAdd)##
##if @first##
AddJSFile("ui");
AddJSFile("ui.core","ui");
AddJSFile('ui.resizable','ui.core');
AddJSFile("onthefly");
##endif##
##endfor##

////////////////////// time picker
##foreach Fields as @f filter (@f.bEditPage || @f.bInlineEdit) && @f.useTimePicker##
##if @first##
	AddJSFile("ui");
	AddJSFile("jquery.utils","ui");
	AddJSFile("ui.dropslide","jquery.utils");
	AddJSFile("ui.timepickr","ui.dropslide");
	AddCSSFile("ui.dropslide");
##endif##
##endfor##
//////////////////////

	
AddJSFile("customlabels");
$jscode.= "window.locale_dateformat = ".$locale_info["LOCALE_IDATE"].";\r\n".
	"window.locale_datedelimiter = \"".$locale_info["LOCALE_SDATE"]."\";\r\n".
	"window.bLoading=false;\r\n".
	"window.TEXT_PLEASE_SELECT='".jsreplace(##message PLEASE_SELECT##)."';\r\n";	
	
	
##foreach Fields as @f filter @f.bEditPage && UseCalendar(@f)##
##if @first##
//	include datepicker files

	$jscode.="window.TEXT_MONTH_JAN='".jsreplace(##message MONTH_JAN##)."';\r\n";
	$jscode.="window.TEXT_MONTH_FEB='".jsreplace(##message MONTH_FEB##)."';\r\n";
	$jscode.="window.TEXT_MONTH_MAR='".jsreplace(##message MONTH_MAR##)."';\r\n";
	$jscode.="window.TEXT_MONTH_APR='".jsreplace(##message MONTH_APR##)."';\r\n";
	$jscode.="window.TEXT_MONTH_MAY='".jsreplace(##message MONTH_MAY##)."';\r\n";
	$jscode.="window.TEXT_MONTH_JUN='".jsreplace(##message MONTH_JUN##)."';\r\n";
	$jscode.="window.TEXT_MONTH_JUL='".jsreplace(##message MONTH_JUL##)."';\r\n";
	$jscode.="window.TEXT_MONTH_AUG='".jsreplace(##message MONTH_AUG##)."';\r\n";
	$jscode.="window.TEXT_MONTH_SEP='".jsreplace(##message MONTH_SEP##)."';\r\n";
	$jscode.="window.TEXT_MONTH_OCT='".jsreplace(##message MONTH_OCT##)."';\r\n";
	$jscode.="window.TEXT_MONTH_NOV='".jsreplace(##message MONTH_NOV##)."';\r\n";
	$jscode.="window.TEXT_MONTH_DEC='".jsreplace(##message MONTH_DEC##)."';\r\n";
	
	$jscode.="window.TEXT_DAY_SU='".jsreplace(##message DAY_SU##)."';\r\n";
	$jscode.="window.TEXT_DAY_MO='".jsreplace(##message DAY_MO##)."';\r\n";
	$jscode.="window.TEXT_DAY_TU='".jsreplace(##message DAY_TU##)."';\r\n";
	$jscode.="window.TEXT_DAY_WE='".jsreplace(##message DAY_WE##)."';\r\n";
	$jscode.="window.TEXT_DAY_TH='".jsreplace(##message DAY_TH##)."';\r\n";
	$jscode.="window.TEXT_DAY_FR='".jsreplace(##message DAY_FR##)."';\r\n";
	$jscode.="window.TEXT_DAY_SA='".jsreplace(##message DAY_SA##)."';\r\n";
	
	$jscode.="window.TEXT_TODAY='".jsreplace(##message TODAY##)."';\r\n";	
	
	AddJSFile("calendar");
##endif##
##endfor##	
	
	
if(!$inlineedit)
{
	if($bodyonload)
	{
		if($RTEfunc)
			$onsubmit="if(editValid.validate()){".$RTEfunc."return true;}else return false;";
		else
			$onsubmit="return editValid.validate();";
	}
	elseif($RTEfunc)
		$onsubmit=$RTEfunc."return true;";
	$includes.="<script language=\"JavaScript\" src=\"include/jquery.js\"></script>\r\n";
##if Fields[bEditPage && bUseiBox && bShowThumbnail].len##
	AddJSFile("ibox");
	AddCSSFile("ibox");
##endif##
	AddJSFile("ajaxsuggest");	
	
	$includes.="<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n";
	
	
	
	$jscode.="SUGGEST_TABLE='##@TABLE.strShortTableName##_searchsuggest.php';\r\n";
	$includes.="<div id=\"search_suggest\"></div>\r\n";

##foreach Fields as @f filter @f.bEditPage##
	$xt->assign("##@f.strName g##_fieldblock",true);
##endfor##

	if(strlen($onsubmit))
		$onsubmit="onSubmit=\"".$onsubmit."\"";
	$body["begin"]=$includes."
	<form name=\"editform\" id=\"editform\" encType=\"multipart/form-data\" method=\"post\" action=\"##@TABLE.strShortTableName##_edit.##@ext##\" ".$onsubmit.">".
	"<input type=hidden name=\"a\" value=\"edited\">";
##foreach @TABLE.arrKeyFields as @k##
	$body["begin"].="<input type=\"hidden\" name=\"editid##@index##\" value=\"".htmlspecialchars($keys["##@k s##"])."\">";
##if Field(@k).strViewFormat==FORMAT_HTML || Field(@k).strViewFormat==FORMAT_FILE_IMAGE || Field(@k).strViewFormat==FORMAT_FILE || Field(@k).strViewFormat==FORMAT_HYPERLINK || Field(@k).strViewFormat==FORMAT_EMAILHYPERLINK || Field(@k).strViewFormat==FORMAT_CHECKBOX##
	$xt->assign("show_key##@index##", htmlspecialchars($data["##@k s##"]));
##else##
	$xt->assign("show_key##@index##", htmlspecialchars(GetData($data,"##@k s##", "##Field(@k).strViewFormat##")));
##endif##
##endfor##

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Begin Next Prev button
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
##if @TABLE.moveNext##
if(!@$_SESSION[$strTableName."_noNextPrev"])
{
	$where_next=$where_prev="";
	$order_next=$order_prev="";
	$arrFieldForSort=array();
	$arrHowFieldSort=array();
	$where=$_SESSION[$strTableName."_where"];
	##foreach @TABLE.arrKeyFields as @k##
	if(GetFieldIndex("##@k s##"))
		$key[]=GetFieldIndex("##@k s##");
	##endfor##
//if session mass sorting empty, then create it as a sheet
	if(@$_SESSION[$strTableName."_arrFieldForSort"] && @$_SESSION[$strTableName."_arrHowFieldSort"])
	{
		$arrFieldForSort=$_SESSION[$strTableName."_arrFieldForSort"];
		$arrHowFieldSort=$_SESSION[$strTableName."_arrHowFieldSort"];
		$lenArr=count($arrFieldForSort);
	}
	else
	{
		if(count($g_orderindexes))
		{
			for($i=0;$i<count($g_orderindexes);$i++)
			{
				$arrFieldForSort[]=$g_orderindexes[$i][0];
				$arrHowFieldSort[]=$g_orderindexes[$i][1];
			}
		}
		elseif($gstrOrderBy!='')
			$_SESSION[$strTableName."_noNextPrev"] = 1;
		if(count($key))
		{
			for($i=0;$i<count($key);$i++)
			{
				$idsearch=array_search($key[$i],$arrFieldForSort);
				if($idsearch===false)
				{
					$arrFieldForSort[]=$key[$i];
					$arrHowFieldSort[]="ASC";
				}
			}
		}
		$_SESSION[$strTableName."_arrFieldForSort"]=$arrFieldForSort;
		$_SESSION[$strTableName."_arrHowFieldSort"]=$arrHowFieldSort;
		$lenArr=count($arrFieldForSort);
	}
//if session order by empty, then create a line order		
	if(@$_SESSION[$strTableName."_order"]) 
		$order_next=$_SESSION[$strTableName."_order"];
	elseif($lenArr>0)
	{
		for($i=0;$i<$lenArr;$i++)
			$order_next .=(GetFieldByIndex($arrFieldForSort[$i]) ? ($order_next!="" ? ", " : " ORDER BY ").$arrFieldForSort[$i]." ".$arrHowFieldSort[$i] : "");
	}
//create a line where and order for the two queries
	if($lenArr>0 and count($key) and !$_SESSION[$strTableName."_noNextPrev"])
	{
		if($where)
			$where .=" and ";
		$scob="";
		$flag=0;
		for($i=0;$i<$lenArr;$i++)
		{
			$fieldName=GetFieldByIndex($arrFieldForSort[$i]);
			if($fieldName)
			{
				$order_prev .=($order_prev!="" ? ", " : " ORDER BY ").$arrFieldForSort[$i].($arrHowFieldSort[$i]=="ASC" ? " DESC" : " ASC");
				$dbg=GetFullFieldName($fieldName);
				if(!is_null($data[$fieldName]))
				{
					$mdv=make_db_value($fieldName,$data[$fieldName]);
					$ga=($arrHowFieldSort[$i]=="ASC" ? ">" : "<");
					$gd=($arrHowFieldSort[$i]=="ASC" ? "<" : ">");
					$gasc=$dbg.$ga.$mdv;
					$gdesc=$dbg.$gd.$mdv;
					$gravn=($i!=$lenArr-1 ? $dbg."=".$mdv : "");
					$ganull=($ga=="<" ? " or ".$dbg." IS NULL" : "");
					$gdnull=($gd=="<" ? " or ".$dbg." IS NULL" : "");
				}
				else
				{
					$gasc=($arrHowFieldSort[$i]=="ASC" ? $dbg." IS NOT NULL" : "");
					$gdesc=($arrHowFieldSort[$i]=="ASC" ? "" : $dbg." IS NOT NULL");
					$gravn=($i!=$lenArr-1 ? $dbg." IS NULL" : "");
					$ganull=$gdnull="";
				}
				$where_next .=($where_next!="" ? " and (" : " (").($gasc=="" && $gravn=="" ? " 1=0 " : ($gasc!="" ? $gasc.$ganull : "").($gasc!="" && $gravn!="" ? " or " : "").$gravn." ");
				$where_prev .=($where_prev!="" ? " and (" : " (").($gdesc=="" && $gravn=="" ? " 1=0 " : ($gdesc!="" ? $gdesc.$gdnull : "").($gdesc!="" && $gravn!="" ? " or " : "").$gravn." ");
				$scob .=")";
			}
			else 
				$flag=1;
		}
		$where_next =$where_next.$scob;
		$where_prev =$where_prev.$scob;
		$where_next=whereAdd($where_next,SecuritySQL("Edit"));
		$where_prev=whereAdd($where_prev,SecuritySQL("Edit"));
		if($flag==1)
		{
			$order_next="";
			for($i=0;$i<$lenArr;$i++)
				$order_next .=(GetFieldByIndex($arrFieldForSort[$i]) ? ($order_next!="" ? ", " : " ORDER BY ").$arrFieldForSort[$i]." ".$arrHowFieldSort[$i] : "");
		}
		$sql_next=gSQLWhere($where.$where_next).$order_next;
		$sql_prev=gSQLWhere($where.$where_prev).$order_prev;
		if($where_next!="" and $order_next!="" and $where_prev!="" and $order_prev!="")
		{
		##if @BUILDER.nDatabaseType==nDATABASE_MySQL || @BUILDER.nDatabaseType==nDATABASE_PostgreSQL##
			$sql_next.=" limit 1";
			$sql_prev.=" limit 1";
		##elseif @BUILDER.nDatabaseType==nDATABASE_MSSQLServer || @BUILDER.nDatabaseType==nDATABASE_Access##
			$sql_next=AddTop($sql_next, 1);
			$sql_prev=AddTop($sql_prev, 1);
		##elseif @BUILDER.nDatabaseType==nDATABASE_Oracle##
			$sql_next=AddRowNumber($sql_next, 1);
			$sql_prev=AddRowNumber($sql_prev, 1);
		##endif##
		
		##foreach @TABLE.arrKeyFields as @k##	
			$res_next=db_query($sql_next,$conn);		
			if($row_next=db_fetch_array($res_next))
				$next[##@index##]=$row_next["##@k s##"];
		
			$res_prev=db_query($sql_prev,$conn);	
			if($row_prev=db_fetch_array($res_prev))
				$prev[##@index##]=$row_prev["##@k s##"];
		##endfor##
		}
	}
}
	$nextlink=$prevlink="";$resetlink="";
	if(count($next))
	{
		$xt->assign("next_button",true);
	##foreach @TABLE.arrKeyFields as @k##
		##if !@first##
		$nextlink .="&";
		##endif##
		$nextlink .="editid##@index##=".htmlspecialchars(rawurlencode($next[##@index##]));
	##endfor##
		$xt->assign("nextbutton_attrs","align=\"absmiddle\" onclick=\"window.location.href='##@TABLE.strShortTableName##_edit.##@ext##?".$nextlink."'\"");
		$resetlink.="$('#next').attr('style','');$('#next').attr('disabled','');";
	}
	else 
		$xt->assign("next_button",false);
	if(count($prev))
	{
		$xt->assign("prev_button",true);
	##foreach @TABLE.arrKeyFields as @k##
		##if !@first##
		$prevlink .="&";
		##endif##
		$prevlink .="editid##@index##=".htmlspecialchars(rawurlencode($prev[##@index##]));
	##endfor##
		$xt->assign("prevbutton_attrs","align=\"absmiddle\" onclick=\"window.location.href='##@TABLE.strShortTableName##_edit.##@ext##?".$prevlink."'\"");
		$resetlink.="$('#prev').attr('style','');$('#prev').attr('disabled','');";
	}
	else 
		$xt->assign("prev_button",false);
	$xt->assign("resetbutton_attrs","onclick=\"flag_but=0; resetEditors(); ".$resetlink."\"");
##endif##

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//End Next Prev button
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
	$xt->assign("backbutton_attrs","onclick=\"window.location.href='##@TABLE.strShortTableName##_list.##@ext##?a=return'\"");
	$xt->assign("save_button",true);
	$xt->assign("reset_button",true);
	$xt->assign("back_button",true);
}

##foreach @TABLE.arrKeyFields as @k##
$showKeys[] = rawurlencode($keys["##@k s##"]);
##endfor##

if($message)
{
	$xt->assign("message_block",true);
	$xt->assign("message",$message);
}

/////////////////////////////////////////////////////////////
//process readonly and auto-update fields
/////////////////////////////////////////////////////////////
$record_id= postvalue("recordID");
##foreach @TABLE.arrFieldObj as @f filter (@f.bEditPage || @f.bInlineEdit) && @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && @f.bUseCategory##
##if !@f.bInlineEdit##
$condition=!$inlineedit;
##elseif !@f.bEditPage##
$condition=$inlineedit;
##else##
$condition=true;
##endif##
if($condition)
{
	$output = loadSelectContent("##@f.strName s##",$data["##@f.strCategoryControlField s##"],$data["##@f.strName s##"]);
	$txt = ""; 
	foreach( $output as $value ) 
	{
		$txt .= jsreplace($value)."\\n";
	}
	##if @f.nSelectSize==1 && @f.nControlType!=LCT_CBLIST##
	$jscode .= "preloadSelectContent('".$txt."', 'value_##@f.strName g##', '".jsreplace($data["##@f.strName s##"])."','".$record_id."');\r\n";
	##else##
	$arr = splitvalues($data["##@f.strName s##"]);
	$val="";
	foreach($arr as $value)
		$val.= jsreplace($value)."\\n";
	$jscode .= "preloadMultiSelectContent('".$txt."', 'value_##@f.strName g##', '".$val."','".$record_id."');\r\n";
	##endif##
}
##endfor##

	if($inlineedit) 
	{
		$jscode.= "inlineEditValid".$record_id." = new validation();\r\n";
		##foreach Fields as @f filter @f.bInlineEdit && @f.bListPage##
		##if @first##
			$types_separated = implode(",", $editValidateTypes);
			$fields_separated = implode(",", $editValidateFields);
			$useRTE_separated = implode(",", $editValidateUseRTE);
			$CBList_separated = implode(",", $editValidateCBList);
			$regex_separated = implode(",", $editValidateRegex);
			$regexmes_separated = implode(",", $editValidateRegexmes);
			$regexmestype_separated = implode(",", $editValidateRegexmestype);
			$jscode.= "var editValidateTypes = String('".$types_separated."').split(',');\r\n";
			$jscode.= "var editValidateFields = String('".$fields_separated."').split(',');\r\n";
			$jscode.= "var editValidateUseRTE = String('".$useRTE_separated."').split(',');\r\n";
			$jscode.= "var editValidateCBList = String('".$CBList_separated."').split(',');\r\n";
			$jscode.= "var editValidateRegex = String('".$regex_separated."').split(',');\r\n";
			$jscode.= "var editValidateRegexmes = String('".$regexmes_separated."').split(',');\r\n";
			$jscode.= "var editValidateRegexmestype = String('".$regexmestype_separated."').split(',');\r\n";
			$jscode.='$("span[@id^=edit'.$record_id.'_]").each(function(i){
						var j;
						for(j=0;j<editValidateFields.length;j++)
						{
							if(editValidateFields[j]==this.id.substr(this.id.indexOf("_")+1))
							{
								if($(this).attr("type")=="Innova" || $(this).attr("type")=="RTE")
									inlineEditValid'.$record_id.'.add(this, editValidateTypes[j],editValidateUseRTE[j],editValidateCBList[j]);
								else{
										if($("input[@type=text],input[@type=hidden],input[@type=password],input[@type=file],select",this).length)
										{
											if(editValidateCBList[j]=="list")
												elem = $("select",this);
											else	
												elem = $("input[@type=text],input[@type=hidden],input[@type=password],input[@type=file],select",this);
											if(editValidateTypes[j]=="Regular expression")
												inlineEditValid'.$record_id.'.addRegex(elem, editValidateTypes[j],editValidateRegex[j],editValidateRegexmes[j],editValidateRegexmestype[j]);
											else
												inlineEditValid'.$record_id.'.add(elem, editValidateTypes[j],editValidateUseRTE[j],editValidateCBList[j]);	
										}
									}
							}
						}
					});';
		##endif##
		##endfor##		
	}
	else
		$jscode.= "flag_but=0;\r\n change();".$bodyonload."\r\n SetToFirstControl('editform');\r\n";
	
##if @TABLE.bInlineEdit##
/////////////////////////////////////////////////////////////
//	return new data to the List page or report an error
/////////////////////////////////////////////////////////////

if (postvalue("a")=="edited" && $inlineedit ) 
{
	if(!$data)
	{
		$data=$evalues;
		$HaveData=false;
	}
	//Preparation   view values

//	detail tables
##foreach @BUILDER.Tables as @t filter @t.arrMasterTables[strMasterTable==@TABLE.strDataSourceTable].len##
	$masterquery="mastertable=##@TABLE.strDataSourceTable us##";
	##foreach @t.arrMasterTables[strMasterTable==@TABLE.strDataSourceTable].arrMasterKeys as @dk##
	$masterquery.="&masterkey##@index##=".rawurlencode($data["##@dk s##"]);
	##endfor##
	$showDetailKeys["##@t.strShortTableName##"]=$masterquery;
##endfor##

	$keylink="";
	##foreach @TABLE.arrKeyFields as @k##
	$keylink.="&key##@index##=".htmlspecialchars(rawurlencode(@$data["##@k s##"]));
	##endfor##

	##foreach Fields as @f filter @f.bListPage order @f.nListPageOrder##

//	##@f.strName## - ##@f.strViewFormat##

		$value="";
		##if @f.strViewFormat==FORMAT_DATABASE_IMAGE##
			##if @f.bShowThumbnail && !@f.bOriginalView##
			$value.="<a";
			##if @f.bUseiBox##
				$value .= " rel='ibox'";
			##else##
				$value .= " target=_blank";
			##endif##
			$value.=" href=\"##@TABLE.strShortTableName s##_imager.php?field=##@f.strName uhs##".$keylink."\">";
			$value.= "<img id=\"img_##@f.strName##_".$record_id."\" border=0";
			$value.=" src=\"##@TABLE.strShortTableName s##_imager.php?field=##@f.strThumbnail uhs##&alt=##@f.strName uhs##".$keylink."\">";
			$value.= "</a>";
			##else##
			$value = "<img";
			##if @f.ListFormatObj.nImageWidth && !@f.bOriginalView##
			$value.=" width=##@f.ListFormatObj.nImageWidth##";
			##endif##
			##if @f.ListFormatObj.nImageHeight && !@f.bOriginalView##
			$value.=" height=##@f.ListFormatObj.nImageHeight##";
			##endif##
			$value.=" id=\"img_##@f.strName##_".$record_id."\" border=0";
			$value.=" src=\"##@TABLE.strShortTableName s##_imager.php?field=##@f.strName uhs##".$keylink."\">";
		##endif##
		##elseif @f.strViewFormat==FORMAT_FILE_IMAGE##
		if(CheckImageExtension($data["##@f.strName s##"])) 
		{
		##if @f.bShowThumbnail && !@f.bOriginalView##
				 	// show thumbnail
			$thumbname="##@f.strThumbnail s##".$data["##@f.strName s##"];
			if(substr("##@f.strhlPrefix s##",0,7)!="http://" && !myfile_exists(GetUploadFolder("##@f.strName s##").$thumbname))
				$thumbname=$data["##@f.strName s##"];
			$value="<a";
			##if @f.bUseiBox##
				$value .= " rel='ibox'";
			##else##
				$value .= " target=_blank";
			##endif##
			$value.=" href=\"".htmlspecialchars(AddLinkPrefix("##@f.strName s##",$data["##@f.strName s##"]))."\">";
			$value.="<img";
			if($thumbname==$data["##@f.strName s##"])
			{
				##if @f.ListFormatObj.nImageWidth##
				$value.=" width=##@f.ListFormatObj.nImageWidth##";
				##endif##
				##if @f.ListFormatObj.nImageHeight##
				$value.=" height=##@f.ListFormatObj.nImageHeight##";
				##endif##
			}
			$value.=" id=\"img_##@f.strName##_".$record_id."\" border=0";
			$value.=" src=\"".htmlspecialchars(AddLinkPrefix("##@f.strName s##",$thumbname))."\"></a>";
		##else##
			$value="<img";
			##if @f.ListFormatObj.nImageWidth && !@f.bOriginalView##
			$value.=" width=##@f.ListFormatObj.nImageWidth##";
			##endif##
			##if @f.ListFormatObj.nImageHeight && !@f.bOriginalView##
			$value.=" height=##@f.ListFormatObj.nImageHeight##";
			##endif##
			$value.=" id=\"img_##@f.strName##_".$record_id."\" border=0";
			$value.=" src=\"".htmlspecialchars(AddLinkPrefix("##@f.strName s##",$data["##@f.strName s##"]))."\">";
		##endif##
		}
		##elseif @f.strViewFormat==FORMAT_DATABASE_FILE##
			##if @f.ListFormatObj.strFilename##
		$filename=$data["##@f.ListFormatObj.strFilename s##"];
		if(!$filename)
			$filename="file.bin";
			##else##
		$filename="file.bin";
			##endif##
		if(strlen($data["##@f.strName s##"]))
		{
			$value="<a href=\"##@TABLE.strShortTableName##_getfile.php?filename=".rawurlencode($filename)."&field=##@f.strName uhs##".$keylink."\">";
			$value.=htmlspecialchars($filename);
			$value.="</a>";
		}
		##elseif (@f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD || @f.strEditFormat==EDIT_FORMAT_RADIO) && pLookupObj.nLookupType == LT_LOOKUPTABLE##
		$value=DisplayLookupWizard("##@f.strName s##",$data["##@f.strName s##"],$data,$keylink,MODE_LIST);
		##elseif NeedEncode(@f)##
		$value = ProcessLargeText(GetData($data,"##@f.strName s##", "##@f.strViewFormat##"),"","",MODE_LIST);
		##else##
		$value = GetData($data,"##@f.strName s##", "##@f.strViewFormat##");
		##endif##
//		$smarty->assign("show_##@f.strName g##",$value);
		$showValues[] = $value;
		$showFields[] = "##@f.strName g##";
		##if IsBinaryField(@f)##
		$showRawValues[] = "";
		##else##
		$showRawValues[] = substr($data["##@f.strName s##"],0,100);
		##endif##
	##endfor##

/////////////////////////////////////////////////////////////
//	start inline output
/////////////////////////////////////////////////////////////

	echo "<textarea id=\"data\">";
	if($IsSaved)
	{
		if($HaveData)
			echo "saved";
		else
			echo "savnd";
		print_inline_array($showKeys);
		echo "\n";
		print_inline_array($showValues);
		echo "\n";
		print_inline_array($showFields);
		echo "\n";
		print_inline_array($showRawValues);
		echo "\n";
		print_inline_array($showDetailKeys,true);
		echo "\n";
		print_inline_array($showDetailKeys);
		echo "\n";
		echo str_replace(array("&","<","\\","\r","\n"),array("&amp;","&lt;","\\\\","\\r","\\n"),$usermessage);
	}
	else
	{
		if($status=="DECLINED")
			echo "decli";
		else
			echo "error";
		echo str_replace(array("&","<","\\","\r","\n"),array("&amp;","&lt;","\\\\","\\r","\\n"),$message);
	}
	echo "</textarea>";
	exit();
} 
##endif##

/////////////////////////////////////////////////////////////
//	prepare Edit Controls
/////////////////////////////////////////////////////////////

$jscode.="\r\n window.rteIdArr=".jsreplace("new Object").";\r\n";

##foreach Fields as @f filter @f.bInlineEdit || @f.bEditPage##
//##@f.EditFormatObj.bUseRTE##
##if UseRTEFCK(@f) || UseRTEINNOVA(@f)##
$jscode.="window.rteIdArr['##@f.strName s##']=new Array();\r\n";
$jscode.="window.rteIdArr['##@f.strName s##'][0]='##@BUILDER.strRTEType##';\r\n";
$jscode.="window.rteIdArr['##@f.strName s##'][1]='##@f.strName s##';\r\n";
##endif##
$control_##@f.strName g##=array();
$control_##@f.strName g##["func"]="xt_buildeditcontrol";
$control_##@f.strName g##["params"] = array();
$control_##@f.strName g##["params"]["field"]="##@f.strName s##";
$control_##@f.strName g##["params"]["value"]=@$data["##@f.strName s##"];

$control_##@f.strName g##["params"]["id"]=$record_id;
if($inlineedit)
	$control_##@f.strName g##["params"]["mode"]="inline_edit";
else
	$control_##@f.strName g##["params"]["mode"]="edit";
$xt->assignbyref("##@f.strName g##_editcontrol",$control_##@f.strName g##);

##endfor##

PrepareJSCode($jscode,$record_id);
	
if($inlineedit)
{
	$jscode = str_replace(array("&","<",">"),array("&amp;","&lt;","&gt;"),$jscode);
	$xt->assignbyref("linkdata",$jscode);
}
else{
	$body["end"]="</form><script>".$jscode."</script>";	
	$xt->assignbyref("body",$body);
}
##foreach Fields as @f filter (@f.bEditPage || @f.bInlineEdit) && UseRTEFCK(@f)##
##if @first##
include("plugins/fckeditor/fckeditor.php");
##endif##
##endfor##

/////////////////////////////////////////////////////////////
//display the page
/////////////////////////////////////////////////////////////
if(function_exists("BeforeShowEdit"))
	BeforeShowEdit($xt,$templatefile);
	
$xt->display($templatefile);

?>
