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-09-15 07:01:37 +02:00
|
|
|
function __construct($name, $title, $source = null, $value = "", $form=null, $emptyString="--select--") {
|
2008-07-11 01:18:38 +02:00
|
|
|
if(!is_array($source)) {
|
|
|
|
$source = Geoip::getCountryDropDown();
|
|
|
|
}
|
2008-09-15 07:01:37 +02:00
|
|
|
parent::__construct($name, $title, $source, $value, $form, $emptyString);
|
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 05:26:24 +02:00
|
|
|
if($this->defaultToVisitorCountry && !$this->value || !isset($this->source[$this->value])) {
|
|
|
|
$this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::$default_country_code;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
return parent::Field();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|