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

include("include/dbcommon.php");
include("include/Leads_Management_variables.php");

add_nocache_headers();

//	check if logged in
if(!@$_SESSION["UserID"] || !CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}

include('include/xtempl.php');
include('classes/runnerpage.php');
include("classes/searchclause.php");
$xt = new Xtempl();


$query = $gQuery->Copy();

$filename = "";	
$message = "";
$key = array();
$next = array();
$prev = array();
$all = postvalue("all");
$pdf = postvalue("pdf");
$mypage = 1;

//Show view page as popUp or not
$inlineview = (postvalue("onFly") ? true : false);

//If show view as popUp, get parent Id
if($inlineview)
	$parId = postvalue("parId");
else
	$parId = 0;

//Set page id	
if(postvalue("id"))
	$id = postvalue("id");
else
	$id = 1;

//$isNeedSettings = true;//($inlineview && postvalue("isNeedSettings") == 'true') || (!$inlineview);	
	
// assign an id			
$xt->assign("id",$id);

//array of params for classes
$params = array("pageType" => PAGE_VIEW, "id" =>$id, "tName"=>$strTableName);
$params["xt"] = &$xt;
//Get array of tabs for edit page
$params['useTabsOnView'] = useTabsOnView($strTableName);
if($params['useTabsOnView'])
	$params['arrViewTabs'] = GetViewTabs($strTableName);
$pageObject = new RunnerPage($params);

// SearchClause class stuff
$pageObject->searchClauseObj->parseRequest();
$_SESSION[$strTableName.'_advsearch'] = serialize($pageObject->searchClauseObj);

// proccess big google maps

// add onload event
$onLoadJsCode = GetTableData($pageObject->tName, ".jsOnloadView", '');
$pageObject->addOnLoadJsEvent($onLoadJsCode);

// add button events if exist
$pageObject->addButtonHandlers();

//For show detail tables on master page view
$dpParams = array();
if($pageObject->isShowDetailTables)
{
	$ids = $id;
	$mKeys["Lead-BOM"] = GetMasterKeysByDetailTable("Lead-BOM", $strTableName);
	$dpParams['strTableNames'][] = "Lead-BOM";
	$dpParams['ids'][] = ++$ids;
	$pageObject->jsSettings['tableSettings'][$strTableName]['dpParams'] = array('tableNames'=>$dpParams['strTableNames'], 'ids'=>$dpParams['ids']);
	$pageObject->AddJSFile("include/detailspreview");
}


//	Before Process event
if($eventObj->exists("BeforeProcessView"))
	$eventObj->BeforeProcessView($conn);

$strWhereClause = '';
$strHavingClause = '';
if(!$all)
{
//	show one record only
	$keys=array();
	$strWhereClause="";
	$keys["Leadid"]=postvalue("editid1");
	$strWhereClause = KeyWhere($keys);
	$strWhereClause = whereAdd($strWhereClause,SecuritySQL("Search"));
	$strSQL = gSQLWhere($strWhereClause);
}
else
{
	if ($_SESSION[$strTableName."_SelectedSQL"]!="" && @$_REQUEST["records"]=="") 
	{
		$strSQL = $_SESSION[$strTableName."_SelectedSQL"];
		$strWhereClause=@$_SESSION[$strTableName."_SelectedWhere"];
	}
	else
	{
		$strWhereClause=@$_SESSION[$strTableName."_where"];
		$strHavingClause=@$_SESSION[$strTableName."_having"];
		if($strWhereClause=="")
			$strWhereClause = whereAdd($strWhereClause,SecuritySQL("Search"));
		$strSQL=gSQLWhere($strWhereClause,$strHavingClause);
	}
//	order by
	$strOrderBy=$_SESSION[$strTableName."_order"];
	if(!$strOrderBy)
		$strOrderBy=$gstrOrderBy;
	$strSQL.=" ".trim($strOrderBy);
}

$strSQLbak = $strSQL;
if($eventObj->exists("BeforeQueryView"))
	$eventObj->BeforeQueryView($strSQL,$strWhereClause);
if($strSQLbak == $strSQL)
{
	$strSQL=gSQLWhere($strWhereClause,$strHavingClause);
	if($all)
	{
		$numrows=gSQLRowCount($strWhereClause,$strHavingClause);
		$strSQL.=" ".trim($strOrderBy);
	}
}
else
{
//	changed $strSQL - old style	
	if($all)
	{
		$numrows=GetRowCount($strSQL);
	}
}

if(!$all)
{
	LogInfo($strSQL);
	$rs=db_query($strSQL,$conn);
}
else
{
//	 Pagination:
	$nPageSize=0;
	if(@$_REQUEST["records"]=="page" && $numrows)
	{
		$mypage=(integer)@$_SESSION[$strTableName."_pagenumber"];
		$nPageSize=(integer)@$_SESSION[$strTableName."_pagesize"];
		if($numrows<=($mypage-1)*$nPageSize)
			$mypage=ceil($numrows/$nPageSize);
		if(!$nPageSize)
			$nPageSize=$gPageSize;
		if(!$mypage)
			$mypage=1;
		$strSQL.=" limit ".(($mypage-1)*$nPageSize).",".$nPageSize;
	}
	$rs=db_query($strSQL,$conn);
}

$data=db_fetch_array($rs);

if($eventObj->exists("ProcessValuesView"))
	$eventObj->ProcessValuesView($data);

$out="";
$first=true;

$templatefile="";
$fieldsArr = array();
$arr = array();
$arr['fName'] = "City";
$arr['viewFormat'] = ViewFormat("City", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "State";
$arr['viewFormat'] = ViewFormat("State", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Postal Code";
$arr['viewFormat'] = ViewFormat("Postal Code", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Address";
$arr['viewFormat'] = ViewFormat("Address", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Leadid";
$arr['viewFormat'] = ViewFormat("Leadid", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Region";
$arr['viewFormat'] = ViewFormat("Region", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Customer Name";
$arr['viewFormat'] = ViewFormat("Customer Name", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Contact Person";
$arr['viewFormat'] = ViewFormat("Contact Person", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Lead Details";
$arr['viewFormat'] = ViewFormat("Lead Details", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Lead Status";
$arr['viewFormat'] = ViewFormat("Lead Status", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Alligned Vendor";
$arr['viewFormat'] = ViewFormat("Alligned Vendor", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Requirement Details";
$arr['viewFormat'] = ViewFormat("Requirement Details", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Proposed Solution Details";
$arr['viewFormat'] = ViewFormat("Proposed Solution Details", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Employee Name";
$arr['viewFormat'] = ViewFormat("Employee Name", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Proposed Closure Date";
$arr['viewFormat'] = ViewFormat("Proposed Closure Date", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Projected Closure QTR";
$arr['viewFormat'] = ViewFormat("Projected Closure QTR", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Approx Value";
$arr['viewFormat'] = ViewFormat("Approx Value", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Approx Closure Date";
$arr['viewFormat'] = ViewFormat("Approx Closure Date", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "First Quote Remarks";
$arr['viewFormat'] = ViewFormat("First Quote Remarks", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Final Quote Remarks";
$arr['viewFormat'] = ViewFormat("Final Quote Remarks", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Quoted Price";
$arr['viewFormat'] = ViewFormat("Quoted Price", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "Discussion Highlights";
$arr['viewFormat'] = ViewFormat("Discussion Highlights", $strTableName);
$fieldsArr[] = $arr;
$arr = array();
$arr['fName'] = "WIN / Lost Analysis";
$arr['viewFormat'] = ViewFormat("WIN / Lost Analysis", $strTableName);
$fieldsArr[] = $arr;

$pageObject->setGoogleMapsParams($fieldsArr);

while($data)
{
	$xt->assign("show_key1", htmlspecialchars(GetData($data,"Leadid", "")));

	$keylink="";
	$keylink.="&key1=".htmlspecialchars(rawurlencode(@$data["Leadid"]));

////////////////////////////////////////////
//City - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"City", ""),"","",MODE_VIEW);
	$xt->assign("City_value",$value);
	if(!$pageObject->isAppearOnTabs("City"))
		$xt->assign("City_fieldblock",true);
	else
		$xt->assign("City_tabfieldblock",true);
////////////////////////////////////////////
//State - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"State", ""),"","",MODE_VIEW);
	$xt->assign("State_value",$value);
	if(!$pageObject->isAppearOnTabs("State"))
		$xt->assign("State_fieldblock",true);
	else
		$xt->assign("State_tabfieldblock",true);
////////////////////////////////////////////
//Postal Code - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Postal Code", ""),"","",MODE_VIEW);
	$xt->assign("Postal_Code_value",$value);
	if(!$pageObject->isAppearOnTabs("Postal Code"))
		$xt->assign("Postal_Code_fieldblock",true);
	else
		$xt->assign("Postal_Code_tabfieldblock",true);
////////////////////////////////////////////
//Address - HTML
	
	$value="";
	$value = GetData($data,"Address", "HTML");
	$xt->assign("Address_value",$value);
	if(!$pageObject->isAppearOnTabs("Address"))
		$xt->assign("Address_fieldblock",true);
	else
		$xt->assign("Address_tabfieldblock",true);
////////////////////////////////////////////
//Leadid - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Leadid", ""),"","",MODE_VIEW);
	$xt->assign("Leadid_value",$value);
	if(!$pageObject->isAppearOnTabs("Leadid"))
		$xt->assign("Leadid_fieldblock",true);
	else
		$xt->assign("Leadid_tabfieldblock",true);
////////////////////////////////////////////
//Region - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Region", ""),"","",MODE_VIEW);
	$xt->assign("Region_value",$value);
	if(!$pageObject->isAppearOnTabs("Region"))
		$xt->assign("Region_fieldblock",true);
	else
		$xt->assign("Region_tabfieldblock",true);
////////////////////////////////////////////
//Customer Name - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Customer Name", ""),"","",MODE_VIEW);
	$xt->assign("Customer_Name_value",$value);
	if(!$pageObject->isAppearOnTabs("Customer Name"))
		$xt->assign("Customer_Name_fieldblock",true);
	else
		$xt->assign("Customer_Name_tabfieldblock",true);
////////////////////////////////////////////
//Contact Person - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Contact Person", ""),"","",MODE_VIEW);
	$xt->assign("Contact_Person_value",$value);
	if(!$pageObject->isAppearOnTabs("Contact Person"))
		$xt->assign("Contact_Person_fieldblock",true);
	else
		$xt->assign("Contact_Person_tabfieldblock",true);
////////////////////////////////////////////
//Lead Details - HTML
	
	$value="";
	$value = GetData($data,"Lead Details", "HTML");
	$xt->assign("Lead_Details_value",$value);
	if(!$pageObject->isAppearOnTabs("Lead Details"))
		$xt->assign("Lead_Details_fieldblock",true);
	else
		$xt->assign("Lead_Details_tabfieldblock",true);
////////////////////////////////////////////
//Lead Status - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Lead Status", ""),"","",MODE_VIEW);
	$xt->assign("Lead_Status_value",$value);
	if(!$pageObject->isAppearOnTabs("Lead Status"))
		$xt->assign("Lead_Status_fieldblock",true);
	else
		$xt->assign("Lead_Status_tabfieldblock",true);
////////////////////////////////////////////
//Alligned Vendor - 
	
	$value="";
	$value=DisplayLookupWizard("Alligned Vendor",$data["Alligned Vendor"],$data,$keylink,MODE_VIEW);
	$xt->assign("Alligned_Vendor_value",$value);
	if(!$pageObject->isAppearOnTabs("Alligned Vendor"))
		$xt->assign("Alligned_Vendor_fieldblock",true);
	else
		$xt->assign("Alligned_Vendor_tabfieldblock",true);
////////////////////////////////////////////
//Requirement Details - HTML
	
	$value="";
	$value = GetData($data,"Requirement Details", "HTML");
	$xt->assign("Requirement_Details_value",$value);
	if(!$pageObject->isAppearOnTabs("Requirement Details"))
		$xt->assign("Requirement_Details_fieldblock",true);
	else
		$xt->assign("Requirement_Details_tabfieldblock",true);
////////////////////////////////////////////
//Proposed Solution Details - HTML
	
	$value="";
	$value = GetData($data,"Proposed Solution Details", "HTML");
	$xt->assign("Proposed_Solution_Details_value",$value);
	if(!$pageObject->isAppearOnTabs("Proposed Solution Details"))
		$xt->assign("Proposed_Solution_Details_fieldblock",true);
	else
		$xt->assign("Proposed_Solution_Details_tabfieldblock",true);
////////////////////////////////////////////
//Employee Name - 
	
	$value="";
	$value=DisplayLookupWizard("Employee Name",$data["Employee Name"],$data,$keylink,MODE_VIEW);
	$xt->assign("Employee_Name_value",$value);
	if(!$pageObject->isAppearOnTabs("Employee Name"))
		$xt->assign("Employee_Name_fieldblock",true);
	else
		$xt->assign("Employee_Name_tabfieldblock",true);
////////////////////////////////////////////
//Proposed Closure Date - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Proposed Closure Date", ""),"","",MODE_VIEW);
	$xt->assign("Proposed_Closure_Date_value",$value);
	if(!$pageObject->isAppearOnTabs("Proposed Closure Date"))
		$xt->assign("Proposed_Closure_Date_fieldblock",true);
	else
		$xt->assign("Proposed_Closure_Date_tabfieldblock",true);
////////////////////////////////////////////
//Projected Closure QTR - 
	
	$value="";
	$value=DisplayLookupWizard("Projected Closure QTR",$data["Projected Closure QTR"],$data,$keylink,MODE_VIEW);
	$xt->assign("Projected_Closure_QTR_value",$value);
	if(!$pageObject->isAppearOnTabs("Projected Closure QTR"))
		$xt->assign("Projected_Closure_QTR_fieldblock",true);
	else
		$xt->assign("Projected_Closure_QTR_tabfieldblock",true);
////////////////////////////////////////////
//Approx Value - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Approx Value", ""),"","",MODE_VIEW);
	$xt->assign("Approx_Value_value",$value);
	if(!$pageObject->isAppearOnTabs("Approx Value"))
		$xt->assign("Approx_Value_fieldblock",true);
	else
		$xt->assign("Approx_Value_tabfieldblock",true);
////////////////////////////////////////////
//Approx Closure Date - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Approx Closure Date", ""),"","",MODE_VIEW);
	$xt->assign("Approx_Closure_Date_value",$value);
	if(!$pageObject->isAppearOnTabs("Approx Closure Date"))
		$xt->assign("Approx_Closure_Date_fieldblock",true);
	else
		$xt->assign("Approx_Closure_Date_tabfieldblock",true);
////////////////////////////////////////////
//First Quote Remarks - HTML
	
	$value="";
	$value = GetData($data,"First Quote Remarks", "HTML");
	$xt->assign("First_Quote_Remarks_value",$value);
	if(!$pageObject->isAppearOnTabs("First Quote Remarks"))
		$xt->assign("First_Quote_Remarks_fieldblock",true);
	else
		$xt->assign("First_Quote_Remarks_tabfieldblock",true);
////////////////////////////////////////////
//Final Quote Remarks - HTML
	
	$value="";
	$value = GetData($data,"Final Quote Remarks", "HTML");
	$xt->assign("Final_Quote_Remarks_value",$value);
	if(!$pageObject->isAppearOnTabs("Final Quote Remarks"))
		$xt->assign("Final_Quote_Remarks_fieldblock",true);
	else
		$xt->assign("Final_Quote_Remarks_tabfieldblock",true);
////////////////////////////////////////////
//Quoted Price - 
	
	$value="";
	$value = ProcessLargeText(GetData($data,"Quoted Price", ""),"","",MODE_VIEW);
	$xt->assign("Quoted_Price_value",$value);
	if(!$pageObject->isAppearOnTabs("Quoted Price"))
		$xt->assign("Quoted_Price_fieldblock",true);
	else
		$xt->assign("Quoted_Price_tabfieldblock",true);
////////////////////////////////////////////
//Discussion Highlights - HTML
	
	$value="";
	$value = GetData($data,"Discussion Highlights", "HTML");
	$xt->assign("Discussion_Highlights_value",$value);
	if(!$pageObject->isAppearOnTabs("Discussion Highlights"))
		$xt->assign("Discussion_Highlights_fieldblock",true);
	else
		$xt->assign("Discussion_Highlights_tabfieldblock",true);
////////////////////////////////////////////
//WIN / Lost Analysis - HTML
	
	$value="";
	$value = GetData($data,"WIN / Lost Analysis", "HTML");
	$xt->assign("WIN___Lost_Analysis_value",$value);
	if(!$pageObject->isAppearOnTabs("WIN / Lost Analysis"))
		$xt->assign("WIN___Lost_Analysis_fieldblock",true);
	else
		$xt->assign("WIN___Lost_Analysis_tabfieldblock",true);

$jsKeysObj = 'window.recKeysObj = {';
	$jsKeysObj .= "'".jsreplace("Leadid")."': '".(jsreplace(@$data["Leadid"]))."', ";
$jsKeysObj = substr($jsKeysObj, 0, strlen($jsKeysObj)-2);
$jsKeysObj .= '};';
$pageObject->AddJsCode($jsKeysObj);	

/////////////////////////////////////////////////////////////
if($pageObject->isShowDetailTables)
{
	$options = array();
	//array of params for classes
	$options["mode"] = LIST_DETAILS;
	$options["pageType"] = PAGE_LIST;
	$options["masterPageType"] = PAGE_VIEW;
	$options["mainMasterPageType"] = PAGE_VIEW;
	$options['masterTable'] = $strTableName;
	$options['firstTime'] = 1;
	
	if(count($dpParams['ids']))
	{
		$xt->assign("detail_tables",true);
		include('classes/listpage.php');
		include('classes/listpage_embed.php');
		include('classes/listpage_dpinline.php');
	}
	
	$dControlsMap = array();
	
	$flyId = $ids+1;
	for($d=0;$d<count($dpParams['ids']);$d++)
	{
		$strTableName = $dpParams['strTableNames'][$d];
		include("include/".GetTableURL($strTableName)."_settings.php");
		if(!CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
		{
			$strTableName = "Leads-Management";		
			continue;
		}
		$options['xt'] = new Xtempl();
		$options['id'] = $dpParams['ids'][$d];
		$options['flyId'] = $flyId++;
		$mkr=1;
		foreach($mKeys[$strTableName] as $mk)
			$options['masterKeysReq'][$mkr++] = $data[$mk];

		$listPageObject = ListPage::createListPage($strTableName, $options);
		// prepare code
		$listPageObject->prepareForBuildPage();
		$flyId = $listPageObject->recId+1;
		// show page
		if(!$pdf && $listPageObject->isDispGrid())
		{
			//add detail settings to master settings
			$listPageObject->fillSetCntrlMaps();
			$pageObject->jsSettings['tableSettings'][$strTableName]	= $listPageObject->jsSettings['tableSettings'][$strTableName];				
			$dControlsMap[$strTableName]['video'] = $listPageObject->controlsHTMLMap[$strTableName][PAGE_LIST][$dpParams['ids'][$d]]['video'];
			$dControlsMap[$strTableName]['gMaps'] = $listPageObject->controlsHTMLMap[$strTableName][PAGE_LIST][$dpParams['ids'][$d]]['gMaps'];
			foreach($listPageObject->jsSettings['global']['shortTNames'] as $keySet=>$val)
			{
				if(!array_key_exists($keySet,$pageObject->settingsMap["globalSettings"]['shortTNames']))
					$pageObject->settingsMap["globalSettings"]['shortTNames'][$keySet] = $val;
			}		
			
			//Add detail's js files to master's files
			$pageObject->copyAllJSFiles($listPageObject->grabAllJSFiles());
			
			//Add detail's css files to master's files	
			$pageObject->copyAllCSSFiles($listPageObject->grabAllCSSFiles());
		}
		$xt->assign("displayDetailTable_".GoodFieldName($strTableName), array("func" => "showDetailTable","params" => array("dpObject" => $listPageObject, "dpParams" => $strTableName)));
	}	
	$strTableName = "Leads-Management";		
	$pageObject->controlsMap['dControlsMap'] = $dControlsMap;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Begin prepare for Next Prev button
if(!@$_SESSION[$strTableName."_noNextPrev"] && !$inlineview && !$pdf)
{
	$pageObject->getNextPrevRecordKeys($data,"Search",$next,$prev);
}	
//End prepare for Next Prev button
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	
if ($pageObject->googleMapCfg['isUseGoogleMap'])
{
	$pageObject->initGmaps();
}

$pageObject->addCommonJs();

//fill tab groups name and sections name to controls
$pageObject->fillCntrlTabGroups();
	
if(!$inlineview)
{
	$pageObject->body["begin"].= "<div id=\"master_details\" onmouseover=\"RollDetailsLink.showPopup();\" onmouseout=\"RollDetailsLink.hidePopup();\"> </div>";
	$pageObject->body["begin"].="<script type=\"text/javascript\" src=\"include/jquery.js\"></script>\r\n";
	$pageObject->body["begin"].="<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n";
	if ($pageObject->debugJSMode === true)
	{			
		/*$pageObject->body["begin"].="<script type=\"text/javascript\" src=\"include/runnerJS/Runner.js\"></script>\r\n".
			"<script type=\"text/javascript\" src=\"include/runnerJS/Util.js\"></script>\r\n".
			"<script type=\"text/javascript\" src=\"include/runnerJS/Observer.js\"></script>\r\n";*/
			$pageObject->body["begin"].="<script language=\"JavaScript\" src=\"include/runnerJS/RunnerBase.js\"></script>\r\n";	
	}
	else
	{
		$pageObject->body["begin"].="<script language=\"JavaScript\" src=\"include/runnerJS/RunnerBase.js\"></script>\r\n";
	}
		$pageObject->jsSettings['tableSettings'][$strTableName]["keys"] = $keys;
	$pageObject->jsSettings['tableSettings'][$strTableName]["prevKeys"] = $prev;
	$pageObject->jsSettings['tableSettings'][$strTableName]["nextKeys"] = $next; 
		
	$pageObject->body["end"].="<script>".$pageObject->PrepareJS()."</script>";	
	
	// assign body end
	$pageObject->body['end'] = array();
	$pageObject->body['end']["method"] = "assignBodyEnd";		
	$pageObject->body['end']["object"] = &$pageObject;	
	
	$xt->assignbyref("body",$pageObject->body);
	$xt->assign("flybody",true);
}
else
{
	$xt->assign("footer","");
	$xt->assign("flybody",$pageObject->body);
	$xt->assign("body",true);
	
	$pageObject->fillSetCntrlMaps();
	
	$returnJSON['controlsMap'] = $pageObject->controlsHTMLMap;
	$returnJSON['settings'] = $pageObject->jsSettings;	
}
$xt->assign("style_block",true);
$xt->assign("stylefiles_block",true);

if(!$pdf && !$all && !$inlineview)
{
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Begin show Next Prev button
    $nextlink=$prevlink="";
	if(count($next))
    {
		$xt->assign("next_button",true);
	 		$nextlink .="editid1=".htmlspecialchars(rawurlencode($next[1]));
		$xt->assign("nextbutton_attrs","id=\"nextButton".$id."\" onclick=\"window.location.href='Leads_Management_view.php?".$nextlink."'\"");
	}
	else 
		$xt->assign("next_button",false);	
	if(count($prev))
	{
		$xt->assign("prev_button",true);
			$prevlink .="editid1=".htmlspecialchars(rawurlencode($prev[1]));
		$xt->assign("prevbutton_attrs","id=\"prevButton".$id."\" onclick=\"window.location.href='Leads_Management_view.php?".$prevlink."'\"");
	}
    else 
		$xt->assign("prev_button",false);
//End show Next Prev button
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$xt->assign("back_button",true);
	$xt->assign("backbutton_attrs","id=\"backButton".$id."\"");
}

$oldtemplatefile=$templatefile;
$templatefile = "Leads_Management_view.htm";

if(!$all)
{
	if($eventObj->exists("BeforeShowView"))
		$eventObj->BeforeShowView($xt,$templatefile,$data);
	
	if(!$pdf)
	{
		if(!$inlineview)
			$xt->display($templatefile);
		else{
				$xt->load_template($templatefile);
				$returnJSON['html'] = $xt->fetch_loaded('style_block').$xt->fetch_loaded('flybody');
				if($pageObject->isShowDetailTables)
					$returnJSON['html'].= $xt->fetch_loaded('detail_tables');
				$returnJSON['idStartFrom'] = $id+1;
				echo (my_json_encode($returnJSON)); 
			}
	}	
	break;
}
}


?>
