<?
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ALMap
//
// Author: Christian Mähler
// Version: 9
// Last update: December 2002
//
// Base library for map&guide mapping 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 ALMap extends ALBasic
{
 	  // public variables for reading and writing data

    var $ParaBitmapPath;		// where to find the bitmaps on the map server (not on web server!)
    var $ShowCustomers;			// show address layer in map?
    var $VisibleCustomers;	// which address layer to show?
    var $MapObjectList;			// objects to be drawn in map
    var $MapRequestRect;		// rectangle of map to be drawn
    var $MapResponse;				// answer from map object

		// private variables for internal map object usage
		
    var $mapfilename; 			// filename for map
    var $arr_cst;     			// array containing the CST (objects to draw in map)
    var $num_cst;     			// number of CST (objects to draw in map)

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ALMap - Constructor
// set default parameters to object

function ALMap()
{
 			$this->ALBasic();
	 		$this->NR_MAPREQUEST=2;					// base number for server ACTION
}
		
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// CheckRes
// does the result consist of all necessary information?

function CheckRes()
{
    if ($this->BFGetParam($this->eATAns,"SERVER","LOGICALRECT","0,0,0,0")=="0,0,0,0" )
    {
       $this->MapResponse = "Mapping error";
       return $this->BPStat_Error;
    }
    else 
		   return $this->BPStat_Success;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// GetCSTCount
// splits an objectlist and finds number of CST entries

function GetCSTCount()
{
    $tmp = explode("^", $this->MapObjectList);
    $this->num_cst = count($tmp);
    for ($i = 1; $i<= count($tmp);$i++)
     $this->arr_cst[$i] = $tmp[$i-1];

 		$this->Log_to_file("ALMap.GetCSTCount: passed successfully: hits: ".count($tmp));		 
}
 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SetOrder
// set all parameters, necessary for geocoding

function SetOrder()
{
    $this->BPRequest["SERVER"]["ACTION"] = 2;
    $this->BPRequest["CLIENT"]["REQUEST"] =  "TRUE";
		$this->BPRequest["CLIENT"]["MAPSBYSTREAM"] =  (($this->BPMapsByStream)  ? "TRUE" : "FALSE");

		// add logical rect for map if applicable
    if (!empty($this->MapRequestRect)) 
			 $this->BPRequest["CLIENT"]["LOGICALRECT"] = $this->MapRequestRect;
    
    // add list of customer tables (address layer) to be drawn in map
    if (strtoupper($this->ShowCustomers) == "TRUE")
    {
     $this->BPRequest["CLIENT"]["SHOWCUSTOMERS"] = $this->ShowCustomers;
     if (!empty($this->VisibleCustomers)) 
		 		$this->BPRequest["CLIENT"]["VISIBLECUSTOMERS"]  = $this->VisibleCustomers;
    }
    else
       if (!empty($this->ShowCustomers)) 
			   $this->BPRequest["CLIENT"]["SHOWCUSTOMERS"]= $this->ShowCustomers;
    
		// where to find bitmaps for draawing objects in map on map server
    if (!empty($this->ParaBitmapPath)) 
			 $this->BPRequest["CLIENT"]["BITMAPPATH"] = $this->ParaBitmapPath;
    
		// if we have a non-empty objectlist, we have to build the CST entries
    if (!empty($this->MapObjectList))
    {
       $this->GetCSTCount();    
       for ($i = 1 ; $i<$this->num_cst ; $i++)
       {
        $cst = "CST" . $i;
        $this->BPRequest["CLIENT"][$cst] = $this->arr_cst[$i];
       }
    }
		
		$this->Log_to_file("ALMap.SetOrder: passed successfully");		 

} // SetOrder

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// MapRequest
// build request, send request, get answer and check answer

function MapRequest()
{
    // check parameter
    if ($this->BPStat_Error == $this->BFCheckParam($this->NR_MAPREQUEST))
		{
		 		$this->Log_to_file("ALMap.MapRequest: Too less parameters ");
		    return $this->BPStat_Error;
		}

    // set request type
    $order   = $this->SetOrder(); 

	  // build request
    $request = $this->BFBuildOrder();
    
    // send request
	  $answerlength=$this->BFWriteOrder($request);

		// if length is less than 45 byte, we had an error
		if($answerlength>45)
		{
     	// receive answer
      $this->BFReadALSAnswer($this->NR_MAPREQUEST);
 	    // return result code
      return $this->CheckRes();
		}
		else
		  return $this->BPStat_Error;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// MapRequestRect
// returns bounding rect

function MapRequestRect()
{
   	return $this->BFGetParam($this->eATAns,"SERVER","LOGICALRECT","0,0,0,0");
}

}// end of class definition
 
