<?php 
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");
include("include/dbcommon.php");
include("classes/searchclause.php");
session_cache_limiter("none");

include("include/Potential_Customer_List_variables.php");

if(!@$_SESSION["UserID"])
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}
if(!CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Export"))
{
	echo "<p>"."You don't have permissions to access this table"."<a href=\"login.php\">"."Back to login page"."</a></p>";
	return;
}

// Modify query: remove blob fields from fieldlist.
// Blob fields on an export page are shown using imager.php (for example).
// They don't need to be selected from DB in export.php itself.
$gQuery->ReplaceFieldsWithDummies(GetBinaryFieldsIndices());

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

$strWhereClause="";
$strHavingClause="";
$selected_recs=array();
$options = "1";

header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 
include('include/xtempl.php');
include('classes/runnerpage.php');
$xt = new Xtempl();

$id = postvalue("id") != "" ? postvalue("id") : 1;
//array of params for classes
$params = array("pageType" => PAGE_EXPORT, "id" =>$id, "tName"=>$strTableName);
$params["xt"] = &$xt;
if(!$eventObj->exists("ListGetRowCount") && !$eventObj->exists("ListQuery"))
	$params["needSearchClauseObj"] = false;
$pageObject = new RunnerPage($params);

if (@$_REQUEST["a"]!="")
{
	$options = "";
	$sWhere = "1=0";	

//	process selection
	$selected_recs=array();
	if (@$_REQUEST["mdelete"])
	{
		foreach(@$_REQUEST["mdelete"] as $ind)
		{
			$keys=array();
			$keys["idCL"]=refine($_REQUEST["mdelete1"][mdeleteIndex($ind)]);
			$selected_recs[]=$keys;
		}
	}
	elseif(@$_REQUEST["selection"])
	{
		foreach(@$_REQUEST["selection"] as $keyblock)
		{
			$arr=explode("&",refine($keyblock));
			if(count($arr)<1)
				continue;
			$keys=array();
			$keys["idCL"]=urldecode($arr[0]);
			$selected_recs[]=$keys;
		}
	}

	foreach($selected_recs as $keys)
	{
		$sWhere = $sWhere . " or ";
		$sWhere.=KeyWhere($keys);
	}


	$strSQL = gSQLWhere($sWhere);
	$strWhereClause=$sWhere;
	
	$_SESSION[$strTableName."_SelectedSQL"] = $strSQL;
	$_SESSION[$strTableName."_SelectedWhere"] = $sWhere;
	$_SESSION[$strTableName."_SelectedRecords"] = $selected_recs;
}

if ($_SESSION[$strTableName."_SelectedSQL"]!="" && @$_REQUEST["records"]=="") 
{
	$strSQL = $_SESSION[$strTableName."_SelectedSQL"];
	$strWhereClause=@$_SESSION[$strTableName."_SelectedWhere"];
	$selected_recs = $_SESSION[$strTableName."_SelectedRecords"];
}
else
{
	$strWhereClause=@$_SESSION[$strTableName."_where"];
	$strHavingClause=@$_SESSION[$strTableName."_having"];
	$strSQL=gSQLWhere($strWhereClause,$strHavingClause);
}

$mypage=1;
if(@$_REQUEST["type"])
{
//	order by
	$strOrderBy=$_SESSION[$strTableName."_order"];
	if(!$strOrderBy)
		$strOrderBy=$gstrOrderBy;
	$strSQL.=" ".trim($strOrderBy);

	$strSQLbak = $strSQL;
	if($eventObj->exists("BeforeQueryExport"))
		$eventObj->BeforeQueryExport($strSQL,$strWhereClause,$strOrderBy);
//	Rebuild SQL if needed
	if($strSQL!=$strSQLbak)
	{
//	changed $strSQL - old style	
		$numrows=GetRowCount($strSQL);
	}
	else
	{
		$strSQL = gSQLWhere($strWhereClause,$strHavingClause);
		$strSQL.=" ".trim($strOrderBy);
		$rowcount=false;
		if($eventObj->exists("ListGetRowCount"))
		{
			$masterKeysReq=array();
			for($i = 0; $i < count($pageObject->detailKeysByM); $i ++)
				$masterKeysReq[]=$_SESSION[$strTableName."_masterkey".($i + 1)];
			$rowcount=$eventObj->ListGetRowCount($pageObject->searchClauseObj,$_SESSION[$strTableName."_mastertable"],$masterKeysReq,$selected_recs);
		}
		if($rowcount!==false)
			$numrows=$rowcount;
		else
			$numrows=gSQLRowCount($strWhereClause,$strHavingClause);
	}
	LogInfo($strSQL);

//	 Pagination:

	$nPageSize = 0;
	if(@$_REQUEST["records"]=="page" && $numrows)
	{
		$mypage = (integer)@$_SESSION[$strTableName."_pagenumber"];
		$nPageSize = (integer)@$_SESSION[$strTableName."_pagesize"];
		
		if(!$nPageSize)
			$nPageSize = GetTableData($strTableName,".pageSize",0);
				
		if($nPageSize<0)
			$nPageSize = 0;
			
		if($nPageSize>0)
		{
			if($numrows<=($mypage-1)*$nPageSize)
				$mypage = ceil($numrows/$nPageSize);
		
			if(!$mypage)
				$mypage = 1;
			
					$strSQL.=" limit ".(($mypage-1)*$nPageSize).",".$nPageSize;
		}
	}
	$listarray = false;
	if($eventObj->exists("ListQuery"))
		$listarray = $eventObj->ListQuery($pageObject->searchClauseObj,$_SESSION[$strTableName."_arrFieldForSort"],$_SESSION[$strTableName."_arrHowFieldSort"],$_SESSION[$strTableName."_mastertable"],$masterKeysReq,$selected_recs,$nPageSize,$mypage);
	if($listarray!==false)
		$rs = $listarray;
	elseif($nPageSize>0)
	{
					$rs = db_query($strSQL,$conn);
	}
	else
		$rs = db_query($strSQL,$conn);

	if(!ini_get("safe_mode"))
		set_time_limit(300);
	
	if(@$_REQUEST["type"]=="excel")
	{
//	remove grouping
		$locale_info["LOCALE_SGROUPING"]="0";
		$locale_info["LOCALE_SMONGROUPING"]="0";
		ExportToExcel();
	}
	else if(@$_REQUEST["type"]=="word")
	{
		ExportToWord();
	}
	else if(@$_REQUEST["type"]=="xml")
	{
		ExportToXML();
	}
	else if(@$_REQUEST["type"]=="csv")
	{
		$locale_info["LOCALE_SGROUPING"]="0";
		$locale_info["LOCALE_SDECIMAL"]=".";
		$locale_info["LOCALE_SMONGROUPING"]="0";
		$locale_info["LOCALE_SMONDECIMALSEP"]=".";
		ExportToCSV();
	}
	db_close($conn);
	return;
}

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

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

if($options)
{
	$xt->assign("rangeheader_block",true);
	$xt->assign("range_block",true);
}

$xt->assign("exportlink_attrs", 'id="saveButton'.$pageObject->id.'"');

$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->fillSetCntrlMaps();
$pageObject->body['end'] .= '<script>';
$pageObject->body['end'] .= "window.controlsMap = '".jsreplace(my_json_encode($pageObject->controlsHTMLMap))."';";
$pageObject->body['end'] .= "window.settings = '".jsreplace(my_json_encode($pageObject->jsSettings))."';";
$pageObject->body['end'] .= '</script>';
$pageObject->addCommonJs();		
	
$pageObject->body["end"] .= "<script>".$pageObject->PrepareJS()."</script>";
$xt->assignbyref("body",$pageObject->body);

$xt->display("Potential_Customer_List_export.htm");

function ExportToExcel()
{
	global $cCharset;
	header("Content-Type: application/vnd.ms-excel");
	header("Content-Disposition: attachment;Filename=Potential_Customer_List.xls");

	echo "<html>";
	echo "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
	
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$cCharset."\">";
	echo "<body>";
	echo "<table border=1>";

	WriteTableData();

	echo "</table>";
	echo "</body>";
	echo "</html>";
}

function ExportToWord()
{
	global $cCharset;
	header("Content-Type: application/vnd.ms-word");
	header("Content-Disposition: attachment;Filename=Potential_Customer_List.doc");

	echo "<html>";
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$cCharset."\">";
	echo "<body>";
	echo "<table border=1>";

	WriteTableData();

	echo "</table>";
	echo "</body>";
	echo "</html>";
}

function ExportToXML()
{
	global $nPageSize,$rs,$strTableName,$conn,$eventObj;
	header("Content-Type: text/xml");
	header("Content-Disposition: attachment;Filename=Potential_Customer_List.xml");
	if($eventObj->exists("ListFetchArray"))
		$row = $eventObj->ListFetchArray($rs);
	else
		$row = db_fetch_array($rs);	
	if(!$row)
		return;
		
	global $cCharset;
	
	echo "<?xml version=\"1.0\" encoding=\"".$cCharset."\" standalone=\"yes\"?>\r\n";
	echo "<table>\r\n";
	$i=0;
	
	
	while((!$nPageSize || $i<$nPageSize) && $row)
	{
		$values = array();
			$values["idCL"] = GetData($row,"idCL","");
			$values["Customer Name"] = GetData($row,"Customer Name","");
			$values["City"] = GetData($row,"City","");
			$values["Address"] = GetData($row,"Address","");
			$values["Web address"] = GetData($row,"Web address","");
			$values["State"] = GetData($row,"State","");
			$values["Area"] = GetData($row,"Area","");
			$values["Country"] = GetData($row,"Country","");
			$values["Customer Status"] = GetData($row,"Customer Status","");
			$values["Postal Code"] = GetData($row,"Postal Code","");
			$values["Assigned Executive"] = GetData($row,"Assigned Executive","");
			$values["Region"] = GetData($row,"Region","");
			$values["Aligned Partner"] = GetData($row,"Aligned Partner","");
			$values["Customer_Category"] = GetData($row,"Customer_Category","");
			$values["Breif About the Company"] = GetData($row,"Breif About the Company","");
			$values["Existing Setup"] = GetData($row,"Existing Setup","");
			$values["Interaction Summary"] = GetData($row,"Interaction Summary","");
			$values["Commercial Summary"] = GetData($row,"Commercial Summary","");
			$values["Assigned Date"] = GetData($row,"Assigned Date","");
			$values["Last Updated on"] = GetData($row,"Last Updated on","");
		
		
		$eventRes = true;
		if ($eventObj->exists('BeforeOut'))
		{			
			$eventRes = $eventObj->BeforeOut($row, $values);
		}
		if ($eventRes)
		{
			$i++;
			echo "<row>\r\n";
			foreach ($values as $fName => $val)
			{
				$field = htmlspecialchars(XMLNameEncode($fName));
				echo "<".$field.">";
				echo htmlspecialchars($values[$fName]);
				echo "</".$field.">\r\n";
			}
			echo "</row>\r\n";
		}
		
		
		if($eventObj->exists("ListFetchArray"))
			$row = $eventObj->ListFetchArray($rs);
		else
			$row = db_fetch_array($rs);	
	}
	echo "</table>\r\n";
}

function ExportToCSV()
{
	global $rs,$nPageSize,$strTableName,$conn,$eventObj;
	header("Content-Type: application/csv");
	header("Content-Disposition: attachment;Filename=Potential_Customer_List.csv");
	
	if($eventObj->exists("ListFetchArray"))
		$row = $eventObj->ListFetchArray($rs);
	else
		$row = db_fetch_array($rs);	
	if(!$row)
		return;
	
		
		
	$totals=array();

	
// write header
	$outstr="";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"idCL\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Customer Name\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"City\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Address\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Web address\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"State\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Area\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Country\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Customer Status\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Postal Code\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Assigned Executive\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Region\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Aligned Partner\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Customer_Category\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Breif About the Company\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Existing Setup\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Interaction Summary\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Commercial Summary\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Assigned Date\"";
	if($outstr!="")
		$outstr.=",";
	$outstr.= "\"Last Updated on\"";
	echo $outstr;
	echo "\r\n";

// write data rows
	$iNumberOfRows = 0;
	while((!$nPageSize || $iNumberOfRows<$nPageSize) && $row)
	{
		
		
		$values = array();
			$format="";
			$values["idCL"] = GetData($row,"idCL",$format);
			$format="";
			$values["Customer Name"] = GetData($row,"Customer Name",$format);
			$format="";
			$values["City"] = GetData($row,"City",$format);
			$format="";
			$values["Address"] = GetData($row,"Address",$format);
			$format=FORMAT_NONE;
			$values["Web address"] = GetData($row,"Web address",$format);
			$format="";
			$values["State"] = GetData($row,"State",$format);
			$format="";
			$values["Area"] = GetData($row,"Area",$format);
			$format="";
			$values["Country"] = GetData($row,"Country",$format);
			$format="";
			$values["Customer Status"] = GetData($row,"Customer Status",$format);
			$format="";
			$values["Postal Code"] = GetData($row,"Postal Code",$format);
			$format="";
			$values["Assigned Executive"] = GetData($row,"Assigned Executive",$format);
			$format="";
			$values["Region"] = GetData($row,"Region",$format);
			$format="";
			$values["Aligned Partner"] = GetData($row,"Aligned Partner",$format);
			$format="";
			$values["Customer_Category"] = GetData($row,"Customer_Category",$format);
			$format="";
			$values["Breif About the Company"] = GetData($row,"Breif About the Company",$format);
			$format="";
			$values["Existing Setup"] = GetData($row,"Existing Setup",$format);
			$format="";
			$values["Interaction Summary"] = GetData($row,"Interaction Summary",$format);
			$format="";
			$values["Commercial Summary"] = GetData($row,"Commercial Summary",$format);
			$format="Short Date";
			$values["Assigned Date"] = GetData($row,"Assigned Date",$format);
			$format="Short Date";
			$values["Last Updated on"] = GetData($row,"Last Updated on",$format);

		$eventRes = true;
		if ($eventObj->exists('BeforeOut'))
		{			
			$eventRes = $eventObj->BeforeOut($row,$values);
		}
		if ($eventRes)
		{
			$outstr="";			
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["idCL"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Customer Name"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["City"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Address"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Web address"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["State"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Area"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Country"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Customer Status"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Postal Code"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Assigned Executive"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Region"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Aligned Partner"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Customer_Category"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Breif About the Company"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Existing Setup"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Interaction Summary"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Commercial Summary"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Assigned Date"]).'"';
			if($outstr!="")
				$outstr.=",";
			$outstr.='"'.str_replace('"','""',$values["Last Updated on"]).'"';
			echo $outstr;
		}
		
		$iNumberOfRows++;
		if($eventObj->exists("ListFetchArray"))
			$row = $eventObj->ListFetchArray($rs);
		else
			$row = db_fetch_array($rs);	
			
		if(((!$nPageSize || $iNumberOfRows<$nPageSize) && $row) && $eventRes)
			echo "\r\n";
	}
}


function WriteTableData()
{
	global $rs,$nPageSize,$strTableName,$conn,$eventObj;
	
	if($eventObj->exists("ListFetchArray"))
		$row = $eventObj->ListFetchArray($rs);
	else
		$row = db_fetch_array($rs);	
	if(!$row)
		return;
// write header
	echo "<tr>";
	if($_REQUEST["type"]=="excel")
	{
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Id CL").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Customer Name").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("City").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Address").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Web Address").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("State").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Area").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Country").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Customer Status").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Postal Code").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Assigned Executive").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Region").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Aligned Partner").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Customer Category").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Breif About the Company").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Existing Setup").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Interaction Summary").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Commercial Summary").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Assigned Date").'</td>';	
		echo '<td style="width: 100" x:str>'.PrepareForExcel("Last Updated on").'</td>';	
	}
	else
	{
		echo "<td>"."Id CL"."</td>";
		echo "<td>"."Customer Name"."</td>";
		echo "<td>"."City"."</td>";
		echo "<td>"."Address"."</td>";
		echo "<td>"."Web Address"."</td>";
		echo "<td>"."State"."</td>";
		echo "<td>"."Area"."</td>";
		echo "<td>"."Country"."</td>";
		echo "<td>"."Customer Status"."</td>";
		echo "<td>"."Postal Code"."</td>";
		echo "<td>"."Assigned Executive"."</td>";
		echo "<td>"."Region"."</td>";
		echo "<td>"."Aligned Partner"."</td>";
		echo "<td>"."Customer Category"."</td>";
		echo "<td>"."Breif About the Company"."</td>";
		echo "<td>"."Existing Setup"."</td>";
		echo "<td>"."Interaction Summary"."</td>";
		echo "<td>"."Commercial Summary"."</td>";
		echo "<td>"."Assigned Date"."</td>";
		echo "<td>"."Last Updated on"."</td>";
	}
	echo "</tr>";

	$totals=array();
// write data rows
	$iNumberOfRows = 0;
	while((!$nPageSize || $iNumberOfRows<$nPageSize) && $row)
	{
			
		$values = array();	

					
							$format="";
			
			$values["idCL"] = GetData($row,"idCL",$format);
					
							$format="";
			
			$values["Customer Name"] = GetData($row,"Customer Name",$format);
					
							$format="";
			
			$values["City"] = GetData($row,"City",$format);
					
							$format="";
			
			$values["Address"] = GetData($row,"Address",$format);
					
							$format=FORMAT_NONE;
			
			$values["Web address"] = GetData($row,"Web address",$format);
					
							$format="";
			
			$values["State"] = GetData($row,"State",$format);
					
							$format="";
			
			$values["Area"] = GetData($row,"Area",$format);
					
							$format="";
			
			$values["Country"] = GetData($row,"Country",$format);
					
							$format="";
			
			$values["Customer Status"] = GetData($row,"Customer Status",$format);
					
							$format="";
			
			$values["Postal Code"] = GetData($row,"Postal Code",$format);
					
							$format="";
			
			$values["Assigned Executive"] = GetData($row,"Assigned Executive",$format);
					
							$format="";
			
			$values["Region"] = GetData($row,"Region",$format);
					
							$format="";
			
			$values["Aligned Partner"] = GetData($row,"Aligned Partner",$format);
					
							$format="";
			
			$values["Customer_Category"] = GetData($row,"Customer_Category",$format);
					
							$format="";
			
			$values["Breif About the Company"] = GetData($row,"Breif About the Company",$format);
					
							$format="";
			
			$values["Existing Setup"] = GetData($row,"Existing Setup",$format);
					
							$format="";
			
			$values["Interaction Summary"] = GetData($row,"Interaction Summary",$format);
					
							$format="";
			
			$values["Commercial Summary"] = GetData($row,"Commercial Summary",$format);
					
							$format="Short Date";
			
			$values["Assigned Date"] = GetData($row,"Assigned Date",$format);
					
							$format="Short Date";
			
			$values["Last Updated on"] = GetData($row,"Last Updated on",$format);

		
		$eventRes = true;
		if ($eventObj->exists('BeforeOut'))
		{			
			$eventRes = $eventObj->BeforeOut($row, $values);
		}
		if ($eventRes)
		{
			$iNumberOfRows++;
			echo "<tr>";

							echo '<td>';
						
			
									$format="";
									echo htmlspecialchars($values["idCL"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Customer Name"]);
					else
						echo htmlspecialchars($values["Customer Name"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["City"]);
					else
						echo htmlspecialchars($values["City"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Address"]);
					else
						echo htmlspecialchars($values["Address"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format=FORMAT_NONE;
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Web address"]);
					else
						echo htmlspecialchars($values["Web address"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["State"]);
					else
						echo htmlspecialchars($values["State"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Area"]);
					else
						echo htmlspecialchars($values["Area"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Country"]);
					else
						echo htmlspecialchars($values["Country"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Customer Status"]);
					else
						echo htmlspecialchars($values["Customer Status"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Postal Code"]);
					else
						echo htmlspecialchars($values["Postal Code"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Assigned Executive"]);
					else
						echo htmlspecialchars($values["Assigned Executive"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Region"]);
					else
						echo htmlspecialchars($values["Region"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Aligned Partner"]);
					else
						echo htmlspecialchars($values["Aligned Partner"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Customer_Category"]);
					else
						echo htmlspecialchars($values["Customer_Category"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Breif About the Company"]);
					else
						echo htmlspecialchars($values["Breif About the Company"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Existing Setup"]);
					else
						echo htmlspecialchars($values["Existing Setup"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Interaction Summary"]);
					else
						echo htmlspecialchars($values["Interaction Summary"]);
			echo '</td>';
							if($_REQUEST["type"]=="excel")
					echo '<td x:str>';
				else
					echo '<td>';
						
			
									$format="";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Commercial Summary"]);
					else
						echo htmlspecialchars($values["Commercial Summary"]);
			echo '</td>';
							echo '<td>';
						
			
									$format="Short Date";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Assigned Date"]);
					else
						echo htmlspecialchars($values["Assigned Date"]);
			echo '</td>';
							echo '<td>';
						
			
									$format="Short Date";
									if($_REQUEST["type"]=="excel")
						echo PrepareForExcel($values["Last Updated on"]);
					else
						echo htmlspecialchars($values["Last Updated on"]);
			echo '</td>';
			echo "</tr>";
		}		
		
		
		if($eventObj->exists("ListFetchArray"))
			$row = $eventObj->ListFetchArray($rs);
		else
			$row = db_fetch_array($rs);	
	}
	
}

function XMLNameEncode($strValue)
{	
	$search=array(" ","#","'","/","\\","(",")",",","[");
	$ret=str_replace($search,"",$strValue);
	$search=array("]","+","\"","-","_","|","}","{","=");
	$ret=str_replace($search,"",$ret);
	return $ret;
}

function PrepareForExcel($str)
{
	$ret = htmlspecialchars($str);
	if (substr($ret,0,1)== "=") 
		$ret = "&#61;".substr($ret,1);
	return $ret;

}


?>
