2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* A simple extension to dropdown field, pre-configured to list countries.
|
|
|
|
* It will default to the country of the current visiotr.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class CountryDropdownField extends DropdownField {
|
2008-09-18 23:33:23 +02:00
|
|
|
protected $defaultToVisitorCountry = true;
|
|
|
|
|
2008-10-15 14:39:09 +02:00
|
|
|
function __construct($name, $title, $source = null, $value = "", $form=null) {
|
2008-11-10 04:51:35 +01:00
|
|
|
if(!is_array($source)) $source = Geoip::getCountryDropDown();
|
|
|
|
if(!$value) $value = Geoip::visitor_country();
|
|
|
|
|
2008-10-15 14:39:09 +02:00
|
|
|
parent::__construct($name, $title, $source, $value, $form);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-09-18 23:33:23 +02:00
|
|
|
function defaultToVisitorCountry($val) {
|
|
|
|
$this->defaultToVisitorCountry = $val;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Field() {
|
2008-10-15 14:39:09 +02:00
|
|
|
$source = $this->getSource();
|
|
|
|
if($this->defaultToVisitorCountry && !$this->value || !isset($source[$this->value])) {
|
2008-10-15 05:26:24 +02:00
|
|
|
$this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::$default_country_code;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
return parent::Field();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-10 04:51:35 +01:00
|
|
|
?>
|