We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    it makes no difference.

    I can use
    WHERE sc.`id` IN (44,48) AND sc.`published`= 1 AND sc.`deleted`= 0 

    for my documents 44 and 48 which are in folder 42


    or
    WHERE sc.`parent` IN (42) AND sc.`published`= 1 AND sc.`deleted`= 0 


    I get the same results
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 36571
      • 145 Posts
      OK, I ran the query in myphpadmin and it returned the same list.

      (but you have hardcoded lat and long in your query now??)
      


      What do you mean by this??

      Could the problem be to do with the fact that the db_custom class is being used to send the postcode.

      You can see the current script in action here: http://moneyadvice.digitalime.com/search.html

      Perhaps it would be an idea to just get rid of everything, except the curl class and the query and start from scratch, but in a mondx context.

        • 4172
        • 5,888 Posts
        What do you mean by this??

        I mean you have now

                                          (((acos(sin((51.4926591*pi()/180)) * sin((lat_tvcv.value*pi()/180)) 
                                                +cos((51.4926591*pi()/180)) * cos((lat_tvcv.value*pi()/180)) * cos(((-0.0542387- lng_tvcv.value)
                                                *pi()/180))))*180/pi())*60*1.1515)


        but it should be

                                          (((acos(sin((".$latitude."*pi()/180)) * sin((lat_tvcv.value*pi()/180)) 
                                                +cos((".$latitude."*pi()/180)) * cos((lat_tvcv.value*pi()/180)) * cos(((".$longitude."- lng_tvcv.value)
                                                *pi()/180))))*180/pi())*60*1.1515)




        Perhaps it would be an idea to just get rid of everything, except the curl class and the query and start from scratch, but in a mondx context.

        this idea is not so bad
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 36571
          • 145 Posts
          this idea is not so bad


          I will get working on it wink

          Also, the problem with the hardcoded lat and long was just a moment of stupidity on my part. I think I have been staring at this code for a bit too long. All fixed now.

          The only remaining problem is having multiple parents. When I set

          &parents='209,304,418';


          all distances are returned as zero. Any ideas why this may be happening?

          EDIT: It would be cool to make parents a variable, so that it could be set directly in the snippet call. Something like:

          $parents= isset($parents) ? $parents: '0';


          What do you reckon?
            • 4310
            • 2,310 Posts
            @danielw
            I don’t want to rain on your parade but the demo link produces completely inaccurate results with a couple of UK post codes I tried.
            e.g. Coventry & Taunton are both 40 miles from Nottingham (NG8 2FE) huh
              • 36571
              • 145 Posts
              Hey bunk58,

              yes, I know some of geocoding leaves a bit to desired, but I am working on it. The current test site is still a LONG way from public consumption.

              From the site:
              If you can’t see a map here, or the location of the centre is completely wrong, please let us know and we will get our finest team trained monkeys working on the bug right away. Contact us at [email protected].
              ;)

              Thanks for the feedback. Will get on it.
                • 36571
                • 145 Posts
                Anybody got any bright ideas why multiple parents don’t work? It’s odd, because I can’t really see any reason why they wouldn’t be. Hmmm.

                @bunk58 Hopefully the results should slowly be improving now. Feel free to test it out and let me know if it still tells you Wrexham is near Glasgow. wink
                  • 4310
                  • 2,310 Posts
                  The distances are better but not correct yet e.g. Canterbury to Ipswich 57.4 miles wink
                  Have you definitely tried :
                  WHERE sc.`parent` IN ('.$parents.') AND sc.`published`= 1 AND sc.`deleted`= 0  
                    • 36571
                    • 145 Posts
                    Yes. I have, and it just returns ’That Postcode was not recognised’ which means that the query is either outputting zero rows ro just general gibberish.

                    The complete code as it stands now looks like this:

                    <?php
                    /** 
                    * Set variables
                    */	
                    
                    //$parents= isset($parents) ? $parents: '0'; // Where the documents containing the lat and long coordinates are located
                    //$tpl=isset($tpl) ? $tpl: ''; // The template chunk to use when outputting the returned documents
                    //$display=isset($display) ? $display: '50'; // The number of results to display. Default 50.
                    /** 
                    * The curl class
                    */	
                    class curl {
                    
                    	/** 
                    	* Constructor
                    	*/	
                    	function curl() {
                    	
                    
                    		
                    	}
                    
                    	function init_curl($ch,$url,$postfields=null,$follow=null,$cookie=null,$referer=null) {
                    		
                    		// Set url
                    		curl_setopt($ch, CURLOPT_URL, $url);
                    		
                    		// Enable Post
                    		if($postfields) {
                    			curl_setopt ($ch, CURLOPT_POST, 1);
                    			curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields);
                    		}
                    		
                    		if($follow) {
                    		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1 ); 		
                    		}
                    				
                    		if($referer) {
                    		curl_setopt($ch, CURLOPT_REFERER, $referer);
                    		}
                    						
                    		//Enable SSL
                    		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                    		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                    		
                    	
                    		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
                    		
                    		//Return results as string
                    		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                    				
                    		return $ch;
                    	
                    	} // end function
                    	
                    
                    	/*
                    	Grabs a page
                    	*/
                    
                    	function get_page($options) {
                    
                    	//Set options
                    	foreach($options AS $key=>$value) {
                    	$$key = $value;	
                    	}	
                    			
                    		$ch = curl_init();		
                    		$ch = $this->init_curl($ch,$url,$postfields,$follow,$cookie);
                    		$page = curl_exec($ch);
                    		curl_close($ch);
                    		return $page;
                    	
                    	
                    	}
                    	
                    	
                    } // end class
                    
                    
                    
                    /**
                     * A postcode finder class
                     *
                     */
                    class postcode_finder {
                    
                    	/**
                    	* Constructor
                    	*
                    	*/
                    	function postcode_finder($array) {
                    	
                    		if(is_array($array)) {
                    			foreach($array AS $key=>$value) {
                    			$this->$key = $value;
                    			}
                    		}	
                    	
                    		//DO stuff
                    	
                    	}
                    
                    	/**
                    	/**
                    	* Returns a lat / long of a given postcode
                    	*
                    	*/	
                    	function get_lat_long($postcode,$domain=null) {
                    		
                    		if(!$domain) {
                    		$domain = "co.uk";
                    		}
                    
                    		$url = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=ABQIAAAAdN8m5F_H4c8QnCWINywTCRQismpbGqJLdUil0k2vBhWw9rjFrhQVLNLfqmHZNGHxY1tlASp_Wx06bQ";
                    						
                    		$json = $this->curl->get_page(array("url"=>$url));
                    						
                    		$store_data = json_decode(str_replace(""","\"",htmlentities($json))); //Take care of accents
                    								
                    		$lng = $store_data->Placemark[0]->Point->coordinates[0];			
                    		$lat = $store_data->Placemark[0]->Point->coordinates[1];
                    		
                    			//Return
                    			if($lng && $lat) {
                    	
                    				return array('lat'=>$lat,
                    							 'lng'=>$lng
                    							 );
                    						 
                    			} else {
                    			
                    				return false;
                    			
                    			}
                    
                    	}
                    
                    
                    	/**
                    	* Get a list of our stores, sorted by distance to this postcode
                    	*
                    	*/	
                    	function get_stores_list($postcode) {
                    	
                    		//If it's a UK postcode then format correctly
                    		$postcode = $this->checkPostcode($postcode);
                    	
                    		$latlng = $this->get_lat_long($postcode);
                    		
                    		if(!$latlng) { //Unrecognised postcode
                    		return false;
                    		}
                    		
                    		$latitude = $latlng['lat'];
                    		$longitude = $latlng['lng'];		
                    		//print_r($latlng);//For Debugging
                                //   print_r($addr);//For Debugging (does not seem to work)
                                   $parents="304";//MAKE THIS MULTIPLE PARENTS
                    		
                           global $modx;
                    			$query = "SELECT distinct 
                                                             sc.pagetitle, 
                                                             sc.content, 
                                                             sc.id, 
                                                                (((acos(sin((".$latitude."*pi()/180)) * sin((lat_tvcv.value*pi()/180)) 
                                                            +cos((".$latitude."*pi()/180)) * cos((lat_tvcv.value*pi()/180)) * cos(((".$longitude."- lng_tvcv.value)
                                                            *pi()/180))))*180/pi())*60*1.1515)
                                                            as distance 
                                            FROM (`modx_site_content` AS sc,
                                                        `modx_site_tmplvars` AS lat_tv ,
                                                        `modx_site_tmplvars` AS lng_tv) 
                                          LEFT JOIN `modx_site_tmplvar_contentvalues` AS lat_tvcv 
                                          ON lat_tvcv.contentid = sc.id AND lat_tvcv.tmplvarid = lat_tv.id 
                                          LEFT JOIN `modx_site_tmplvar_contentvalues` AS lng_tvcv 
                                          ON lng_tvcv.contentid = sc.id AND lng_tvcv.tmplvarid = lng_tv.id 
                                          WHERE sc.`parent` IN (".$parents.") AND sc.`published`= '1' AND sc.`deleted`= '0'  
                                          AND lat_tv.name = 'latitude' 
                                         AND lng_tv.name = 'longitude' 
                                        ORDER BY distance ASC
                                        LIMIT 0,50
                    					";
                    
                                           $rs=$modx->db->query($query);
                                            $stores=$modx->db->makeArray($rs);	
                    			//print_r($stores); //For debugging.
                    			return $stores;
                    
                    
                    	
                    	}
                    
                    
                    	/**
                    	* Checks whether supplied postcode is a valid UK postcode
                    	*/
                    	function checkPostcode($toCheck) {
                    	
                    	  $orig = $toCheck;
                    	
                    	  // Permitted letters depend upon their position in the postcode.
                    	  $alpha1 = "[abcdefghijklmnoprstuwyz]";                          // Character 1
                    	  $alpha2 = "[abcdefghklmnopqrstuvwxy]";                          // Character 2
                    	  $alpha3 = "[abcdefghjkstuw]";                                   // Character 3
                    	  $alpha4 = "[abehmnprvwxy]";                                     // Character 4
                    	  $alpha5 = "[abdefghjlnpqrstuwxyz]";                             // Character 5
                    	  
                    	  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
                    	  $pcexp[0] = '^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$';
                    	
                    	  // Expression for postcodes: ANA NAA
                    	  $pcexp[1] =  '^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$';
                    	
                    	  // Expression for postcodes: AANA NAA
                    	  $pcexp[2] =  '^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$';
                    	  
                    	  // Exception for the special postcode GIR 0AA
                    	  $pcexp[3] =  '^(gir)(0aa)$';
                    	  
                    	  // Standard BFPO numbers
                    	  $pcexp[4] = '^(bfpo)([0-9]{1,4})$';
                    	  
                    	  // c/o BFPO numbers
                    	  $pcexp[5] = '^(bfpo)(c\/o[0-9]{1,3})$';
                    	
                    	  // Load up the string to check, converting into lowercase and removing spaces
                    	  $postcode = strtolower($toCheck);
                    	  $postcode = str_replace (' ', '', $postcode);
                    	
                    	  // Assume we are not going to find a valid postcode
                    	  $valid = false;
                    	  
                    	  // Check the string against the six types of postcodes
                    	  foreach ($pcexp as $regexp) {
                    	  
                    		if (ereg($regexp,$postcode, $matches)) {
                    		  
                    		  // Load new postcode back into the form element  
                    		  $toCheck = strtoupper ($matches[1] . ' ' . $matches [2]);
                    		  
                    		  // Take account of the special BFPO c/o format
                    		  $toCheck = ereg_replace ('C\/O', 'c/o ', $toCheck);
                    		  
                    		  // Remember that we have found that the code is valid and break from loop
                    		  $valid = true;
                    		  break;
                    		}
                    	  }
                    			
                    	  // Return with the reformatted valid postcode in uppercase if the postcode was 
                    	  // valid
                    	  if ($valid){
                    	  return $toCheck;
                    	  } else {
                    	  $this->non_standard_postcode = true;
                    	  return $orig;
                    	  };
                    	  
                    	}	
                    
                    
                    }
                    
                    //If we have a post
                    if($_GET['postcode']) {
                    	$curl = new curl();
                    	$finder = new postcode_finder(array('curl'=>$curl));						  
                    	$stores = $finder->get_stores_list($_GET['postcode']);						  
                    }
                    
                    
                    ?>
                    
                    
                    
                    																							  
                    				<form action="" method="GET">
                    					<fieldset>
                    					<div style="float:left; width:370px; font-size:15px; font-weight:bold; margin-right:18px">Search for your nearest free and independent advice centre. Just enter your postcode or the name of your town to get started.</div>
                    <input type="text" name="postcode" value="<?= $_GET['postcode'] ?>" style="font-size:20px; padding:4px; font-weight:bold; font-family:arial" size="40" maxlength="80"> 						
                    						<input type="submit" value="SEARCH" style="font-size:15px; padding:4px">
                    					
                    					</fieldset>
                    				</form>
                    				
                    				<? if ($_GET['postcode']) { ?>
                    				
                    					<? if ($stores) { ?>
                    										
                    						<h2 style="background-color:padding:2px">The following centres were found near to you</h2>
                    					
                    						<? 
                    
                    $docids=array();
                    foreach($stores AS $store) {  
                    
                    $modx->setPlaceholder($store['id'].'.distance',number_format($store['distance'],2));
                    $docids[]=$store['id'];
                    
                    }
                    
                    $params=array();
                    $params['documents']=implode(',',$docids);
                    $params['tpl']='listtpl';
                    $params['parents']='$parents';
                    $params['display']='10';
                    $params['extenders']='customsort,request';
                    return $modx->runSnippet('Ditto',$params);
                    
                    				
                    					
                    					 }  else { ?>
                    					
                    <h2 style="background-color:padding:2px">That postcode was not recognised</h2>					
                    					
                    					
                    					<? } ?>	
                    					
                    				
                    				<? } ?>	
                    			</div>	
                    				</div>		
                    			
                    
                    </body>
                    </html>
                    ?>



                    Like I say, it works fine with 1 parent, and is now completely modx native, thanks to Bruno. It just has this small glitch that I want to get rid of.
                      • 4172
                      • 5,888 Posts
                      <?php
                      /** 
                      * Set variables
                      */	
                      
                      $parents= isset($parents) ? $parents: '0'; // Where the documents containing the lat and long coordinates are located
                      $tpl=isset($tpl) ? $tpl: 'listtpl'; // The template chunk to use when outputting the returned documents
                      $display=isset($display) ? $display: '50'; // The number of results to display. Default 50.
                      /** 
                      * The curl class
                      */	
                      class curl {
                      
                      	/** 
                      	* Constructor
                      	*/	
                      	function curl() {
                      	
                      
                      		
                      	}
                      
                      	function init_curl($ch,$url,$postfields=null,$follow=null,$cookie=null,$referer=null) {
                      		
                      		// Set url
                      		curl_setopt($ch, CURLOPT_URL, $url);
                      		
                      		// Enable Post
                      		if($postfields) {
                      			curl_setopt ($ch, CURLOPT_POST, 1);
                      			curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfields);
                      		}
                      		
                      		if($follow) {
                      		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1 ); 		
                      		}
                      				
                      		if($referer) {
                      		curl_setopt($ch, CURLOPT_REFERER, $referer);
                      		}
                      						
                      		//Enable SSL
                      		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                      		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                      		
                      	
                      		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
                      		
                      		//Return results as string
                      		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                      				
                      		return $ch;
                      	
                      	} // end function
                      	
                      
                      	/*
                      	Grabs a page
                      	*/
                      
                      	function get_page($options) {
                      
                      	//Set options
                      	foreach($options AS $key=>$value) {
                      	$$key = $value;	
                      	}	
                      			
                      		$ch = curl_init();		
                      		$ch = $this->init_curl($ch,$url,$postfields,$follow,$cookie);
                      		$page = curl_exec($ch);
                      		curl_close($ch);
                      		return $page;
                      	
                      	
                      	}
                      	
                      	
                      } // end class
                      
                      
                      
                      /**
                       * A postcode finder class
                       *
                       */
                      class postcode_finder {
                      
                      	/**
                      	* Constructor
                      	*
                      	*/
                      	function postcode_finder($array) {
                      	
                      		if(is_array($array)) {
                      			foreach($array AS $key=>$value) {
                      			$this->$key = $value;
                      			}
                      		}	
                      	
                      		//DO stuff
                      	
                      	}
                      
                      	/**
                      	/**
                      	* Returns a lat / long of a given postcode
                      	*
                      	*/	
                      	function get_lat_long($postcode,$domain=null) {
                      		
                      		if(!$domain) {
                      		$domain = "co.uk";
                      		}
                      
                      		$url = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=ABQIAAAAdN8m5F_H4c8QnCWINywTCRQismpbGqJLdUil0k2vBhWw9rjFrhQVLNLfqmHZNGHxY1tlASp_Wx06bQ";
                      						
                      		$json = $this->curl->get_page(array("url"=>$url));
                      						
                      		$store_data = json_decode(str_replace(""","\"",htmlentities($json))); //Take care of accents
                      								
                      		$lng = $store_data->Placemark[0]->Point->coordinates[0];			
                      		$lat = $store_data->Placemark[0]->Point->coordinates[1];
                      		
                      			//Return
                      			if($lng && $lat) {
                      	
                      				return array('lat'=>$lat,
                      							 'lng'=>$lng
                      							 );
                      						 
                      			} else {
                      			
                      				return false;
                      			
                      			}
                      
                      	}
                      
                      
                      	/**
                      	* Get a list of our stores, sorted by distance to this postcode
                      	*
                      	*/	
                      	function get_stores_list($postcode,$parents) {
                      	
                      		//If it's a UK postcode then format correctly
                      		$postcode = $this->checkPostcode($postcode);
                      	
                      		$latlng = $this->get_lat_long($postcode);
                      		
                      		if(!$latlng) { //Unrecognised postcode
                      		return false;
                      		}
                      		
                      		$latitude = $latlng['lat'];
                      		$longitude = $latlng['lng'];		
                      		//print_r($latlng);//For Debugging
                                  //   print_r($addr);//For Debugging (does not seem to work)
                                     //$parents="304";//MAKE THIS MULTIPLE PARENTS
                      		
                             global $modx;
                      			$query = "SELECT distinct 
                                                               sc.pagetitle, 
                                                               sc.content, 
                                                               sc.id, 
                                                                  (((acos(sin((".$latitude."*pi()/180)) * sin((lat_tvcv.value*pi()/180)) 
                                                              +cos((".$latitude."*pi()/180)) * cos((lat_tvcv.value*pi()/180)) * cos(((".$longitude."- lng_tvcv.value)
                                                              *pi()/180))))*180/pi())*60*1.1515)
                                                              as distance 
                                              FROM (`modx_site_content` AS sc,
                                                          `modx_site_tmplvars` AS lat_tv ,
                                                          `modx_site_tmplvars` AS lng_tv) 
                                            LEFT JOIN `modx_site_tmplvar_contentvalues` AS lat_tvcv 
                                            ON lat_tvcv.contentid = sc.id AND lat_tvcv.tmplvarid = lat_tv.id 
                                            LEFT JOIN `modx_site_tmplvar_contentvalues` AS lng_tvcv 
                                            ON lng_tvcv.contentid = sc.id AND lng_tvcv.tmplvarid = lng_tv.id 
                                            WHERE sc.`parent` IN (".$parents.") AND sc.`published`= '1' AND sc.`deleted`= '0'  
                                            AND lat_tv.name = 'latitude' 
                                           AND lng_tv.name = 'longitude' 
                                          ORDER BY distance ASC
                                          LIMIT 0,50
                      					";
                      
                                             $rs=$modx->db->query($query);
                                              $stores=$modx->db->makeArray($rs);	
                      			//print_r($stores); //For debugging.
                      			return $stores;
                      
                      
                      	
                      	}
                      
                      
                      	/**
                      	* Checks whether supplied postcode is a valid UK postcode
                      	*/
                      	function checkPostcode($toCheck) {
                      	
                      	  $orig = $toCheck;
                      	
                      	  // Permitted letters depend upon their position in the postcode.
                      	  $alpha1 = "[abcdefghijklmnoprstuwyz]";                          // Character 1
                      	  $alpha2 = "[abcdefghklmnopqrstuvwxy]";                          // Character 2
                      	  $alpha3 = "[abcdefghjkstuw]";                                   // Character 3
                      	  $alpha4 = "[abehmnprvwxy]";                                     // Character 4
                      	  $alpha5 = "[abdefghjlnpqrstuwxyz]";                             // Character 5
                      	  
                      	  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
                      	  $pcexp[0] = '^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$';
                      	
                      	  // Expression for postcodes: ANA NAA
                      	  $pcexp[1] =  '^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$';
                      	
                      	  // Expression for postcodes: AANA NAA
                      	  $pcexp[2] =  '^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$';
                      	  
                      	  // Exception for the special postcode GIR 0AA
                      	  $pcexp[3] =  '^(gir)(0aa)$';
                      	  
                      	  // Standard BFPO numbers
                      	  $pcexp[4] = '^(bfpo)([0-9]{1,4})$';
                      	  
                      	  // c/o BFPO numbers
                      	  $pcexp[5] = '^(bfpo)(c\/o[0-9]{1,3})$';
                      	
                      	  // Load up the string to check, converting into lowercase and removing spaces
                      	  $postcode = strtolower($toCheck);
                      	  $postcode = str_replace (' ', '', $postcode);
                      	
                      	  // Assume we are not going to find a valid postcode
                      	  $valid = false;
                      	  
                      	  // Check the string against the six types of postcodes
                      	  foreach ($pcexp as $regexp) {
                      	  
                      		if (ereg($regexp,$postcode, $matches)) {
                      		  
                      		  // Load new postcode back into the form element  
                      		  $toCheck = strtoupper ($matches[1] . ' ' . $matches [2]);
                      		  
                      		  // Take account of the special BFPO c/o format
                      		  $toCheck = ereg_replace ('C\/O', 'c/o ', $toCheck);
                      		  
                      		  // Remember that we have found that the code is valid and break from loop
                      		  $valid = true;
                      		  break;
                      		}
                      	  }
                      			
                      	  // Return with the reformatted valid postcode in uppercase if the postcode was 
                      	  // valid
                      	  if ($valid){
                      	  return $toCheck;
                      	  } else {
                      	  $this->non_standard_postcode = true;
                      	  return $orig;
                      	  };
                      	  
                      	}	
                      
                      
                      }
                      
                      //If we have a post
                      if($_GET['postcode']) {
                      	$curl = new curl();
                      	$finder = new postcode_finder(array('curl'=>$curl));						  
                      	$stores = $finder->get_stores_list($_GET['postcode'],$parents);						  
                      }
                      
                      
                      ?>
                      
                      
                      
                      																							  
                      				<form action="" method="GET">
                      					<fieldset>
                      					<div style="float:left; width:370px; font-size:15px; font-weight:bold; margin-right:18px">Search for your nearest free and independent advice centre. Just enter your postcode or the name of your town to get started.</div>
                      <input type="text" name="postcode" value="<?= $_GET['postcode'] ?>" style="font-size:20px; padding:4px; font-weight:bold; font-family:arial" size="40" maxlength="80"> 						
                      						<input type="submit" value="SEARCH" style="font-size:15px; padding:4px">
                      					
                      					</fieldset>
                      				</form>
                      				
                      				<? if ($_GET['postcode']) { ?>
                      				
                      					<? if ($stores) { ?>
                      										
                      						<h2 style="background-color:padding:2px">The following centres were found near to you</h2>
                      					
                      						<? 
                      
                      $docids=array();
                      foreach($stores AS $store) {  
                      
                      $modx->setPlaceholder($store['id'].'.distance',number_format($store['distance'],2));
                      $docids[]=$store['id'];
                      
                      }
                      
                      $params=array();
                      $params['documents']=implode(',',$docids);
                      $params['tpl']=$tpl;
                      //$params['parents']='$parents';you cannot use documents and parents at same time!!!!
                      $params['display']=$display;
                      $params['extenders']='customsort,request';
                      return $modx->runSnippet('Ditto',$params);
                      
                      				
                      					
                      					 }  else { ?>
                      					
                      <h2 style="background-color:padding:2px">That postcode was not recognised</h2>					
                      					
                      					
                      					<? } ?>	
                      					
                      				
                      				<? } ?>	
                      			</div>	
                      				</div>		
                      			
                      
                      </body>
                      </html>
                      ?>
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!