<?
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ALNext
//
// Author: Christian Mähler
// Version: 9.5
// Last update: April 2003
//
// Base library for map&guide next search functionality.
// Please note that only English speaking properties are used
// there is no support for German speaking properties as
// known by the original COM objects under Windows
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//++++++++++ INCLUDE ++++++++++++++++++++++++++//" 
@include_once(dirname(__FILE__)."/albasic.inc.php");
//+++++++++++++++++++++++++++++++++++++++++++++//"

class ALNext extends ALBasic
{
 	  // public variables for reading and writing data

		var $Filter1;										// filter for address layer search
		var $Filter2;										// filter for address layer search
		var $Filter3;										// filter for address layer search						 
		var $Filter4;										// filter for address layer search	
		var $Filter5;										// filter for address layer search	
		var $ShowInfo;									// show CST entries in the result				
		var $Response;								  // response string for error messages
		var $RowCount;									// count nunber of results (CST)		
		var $ShowCompleteRadius;				// show the search radius as map radius and not the radius defined by the result 
		var $SearchByCoord;							// search string for direct search around coordinates 
		var $SearchByTown;						  // search string for search around a city with geocoding
		var $Customers;									// define list of address layer to be searched
		var $Filter;										// add filter to search
		var $ReturnFields;							// define returnfields
		var $ShowCompleteRadius;				// show complete radius of search
		var $AddToMap;									// add additional info to map?
		var $ShowInfo;									//
		var $GraphFilter;								// use this grahical filter for search
		var $ExportFile;								// define an export file where the result is written to as CSV
		var $NextID;										// define the NextID returned after a radius search for fast zomming
		var $ShowInitRect;							// add the variable SHOWINITRECT to the request string
		var $Logicalrect;								// logicalrect to draw 
		var $ShowSpiderLines;						// show spiderlines from center to hits
		var $TrafficInfoIDs;						// show these traffic info ID
		var $VisibleCustomers;					// list of layers to show
		var $ShowCustomers;							// show additional layer ?
		var $UsePin;										// show the pin in the map after a radius search
		var $FileName;									// define filename for map 
		
		// private variables
		
		var $NR_NEXTREQUEST;		   			// internal service number
		var $temp_row;						 			// needed by ReadRow and FieldValue
						
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Constructor
// set all parameters, necessary for geocoding. Contructor sets default
// parameter 

function ALNext()
{
   $this->ALBasic();
   $this->NR_NEXTREQUEST=1; // don't change this value!!
	 
   $this->Customers="";			// set default values
   $this->GraphFilter="";
	 $this->AddToMap=false;
	 $this->ShowInfo=true;
	 $this->RowCount=0;
	 
   $this->Log_to_file("ALNext.ALNext: Constructor passed successfully");
}
		
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SetOrder
// build request string depending on internal values as ACTION and
// based on the request as defined by the user

function SetOrder()
{
    $this->BPRequest["SERVER"]["ACTION"] 			 = $this->NR_NEXTREQUEST;
		$this->BPRequest["CLIENT"]["MAPSBYSTREAM"] = (($this->BPMapsByStream) ? "TRUE" : "FALSE");
    $this->BPRequest["CLIENT"]["REQUEST"] 		 = "TRUE";
    $this->BPRequest["CLIENT"]["CUSTOMERS"] 	 = $this->Customers;
    $this->BPRequest["CLIENT"]["GRAPHFILTER"]  = $this->GraphFilter;
		if($this->SearchByCoord!="")
				$this->BPRequest["CLIENT"]["SEARCHBYCOORD"]=$this->SearchByCoord;
		else
				$this->BPRequest["CLIENT"]["SEARCHBYTOWN"]=$this->SearchByTown;
				
		$this->BPRequest["CLIENT"][$this->Customers."RETURNFIELDS"]  = $this->ReturnFields;	
		$this->BPRequest["CLIENT"]["ADDTOMAP"] = (($this->AddToMap) ? "TRUE" : "FALSE");;		

		if($this->Filter1!="") $this->BPRequest["CLIENT"][$this->Customers."FILTER1"]==$this->Filter1;
		if($this->Filter2!="") $this->BPRequest["CLIENT"][$this->Customers."FILTER2"]==$this->Filter2;
		if($this->Filter3!="") $this->BPRequest["CLIENT"][$this->Customers."FILTER3"]==$this->Filter3;						 
		if($this->Filter4!="") $this->BPRequest["CLIENT"][$this->Customers."FILTER4"]==$this->Filter4;	
		if($this->Filter5!="") $this->BPRequest["CLIENT"][$this->Customers."FILTER5"]==$this->Filter5;	
		
		$this->BPRequest["CLIENT"]["SHOWINFO"] = (($this->ShowInfo) ? "TRUE" : "FALSE");
		
 		$this->Log_to_file("ALNext.SetOrder: Passed successfully");		
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ReadRow
// read row with number RowNum into internal object cache
// values can be read by FieldValue 

function ReadRow($RowNum)
{
 	 if($RowNum<0 || $RowNum>$this->RowCount || !$this->ShowInfo)
	 {
	 	 $this->Log_to_file("ALNext.ReadRow: row number too large or no CST available ");
	 	 return "";
	 }
	
	 $this->temp_row=$this->BFGetParam(0,"SERVER","CST".$RowNum,"");
	 
   return $this->temp_row;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FieldValue
// read from current row (defined by ReadRow) the content of the 
// column with the name fName. The list of fName was defined by ReturnFields

function FieldValue($fName)
{
 	 if($fName=="" || !$this->ShowInfo || $this->temp_row=="")
	 {
	 	 $this->Log_to_file("ALNext.FieldValue: field name is empty or no CST available or no row read by ReadRow() ");
	 	 return "";
	 }
	 
	 $temp_col=explode(",",$this->ReturnFields);
	 $i=0;
	 $col_num=-1;
	 foreach($temp_col as $key => $value)
	   if($key==$fName) 
		 		$col_num=$i;
		 else
		 		$i++;
 
 	 if ($col_num==-1)
	 		return "";
	 else
   {
	 		$temp_row_content=explode(",",$temp_row);
			return $temp_row_content[$col_num];
	 }
	 	 		 
 	 return "";
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// CheckRes
// check how many hits were found and build answer accordingly 

function CheckRes()
{
    if ($this->BFGetParam(0,strtoupper($this->Customers),"NUMCST",$this->BFGetParam(0,"SERVER","NUMCST",""))=="" )
    {
       $this->Response = "Next search error";
			 $this->Log_to_file("ALNext.NextRequest: no NUMCST in result ");
       return $this->BPStat_Error;
    }
    else 
		   return $this->BPStat_Success;

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Execute
// send next search request to server. the next search is based on an
// address layer known by the server 

function NextSearch()
{
 	 return $this->Execute();
}

function Execute()
{
    // check parameter
    if (($this->BPStat_Error == $this->BFCheckParam($this->NR_NEXTREQUEST)) || ($this->BPMapsByStream && $this->BPStreamDirectory==''))
		{
		 		$this->Log_to_file("ALNext.NextRequest: Too less parameters ");
		    return $this->BPStat_Error;
		}
    
    // set request type
    $this->SetOrder();
	 
	  // build request
    $reqerr=$request = $this->BFBuildOrder(); 

    // send request to server
    $answerlength=$this->BFWriteOrder($request);

		// if length is less than 45 byte, we had an error
		if($answerlength>45)
		{
     	// receive answer
      $reqerr=$this->BFReadALSAnswer($this->NR_NEXTREQUEST);
 	    
			$this->RowCount=intval($this->BFGetParam(0,strtoupper($this->Customers),"NUMCST",$this->BFGetParam(0,"SERVER","NUMCST","0")));			
			$this->Logicalrect=$this->BFGetParam(0,"SERVER","LOGICALRECT","");
			
			// return result code
	  	// count number of hits

    	return $this->CheckRes();
		}
		else
		  return $this->BPStat_Error;
}

} //end of class definition
 
?>