Location: PHPKode > projects > Moc10 PHP Library > library/Moc10/Form/Element/Select.php
<?php
/**
 * Moc10 Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.TXT.
 * It is also available through the world-wide-web at this URL:
 * http://www.moc10phplibrary.com/LICENSE.TXT
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to hide@address.com so we can send you a copy immediately.
 *
 * @category   Moc10
 * @package    Moc10_Form
 * @author     Nick Sagona, III <hide@address.com>
 * @copyright  Copyright (c) 2009-2011 Moc 10 Media, LLC. (http://www.moc10media.com)
 * @license    http://www.moc10phplibrary.com/LICENSE.TXT     New BSD License
 */

/**
 * Moc10_Form_Element_Select
 *
 * @category   Moc10
 * @package    Moc10_Form
 * @author     Nick Sagona, III <hide@address.com>
 * @copyright  Copyright (c) 2009-2011 Moc 10 Media, LLC. (http://www.moc10media.com)
 * @license    http://www.moc10phplibrary.com/LICENSE.TXT     New BSD License
 * @version    1.9.7
 */

class Moc10_Form_Element_Select extends Moc10_Form_Element
{

    /**
     * Current values
     * @var array
     */
    public $values = array();

    /**
     * Constructor
     *
     * Instantiate the select form element object.
     *
     * @param  string $name
     * @param  string|array $value
     * @param  string|array $marked
     * @param  string $indent
     * @return void
     */
    public function __construct($name, $value = null, $marked = null, $indent = null)
    {

        $lang = new Moc10_Language();

        // If the value flag is YEAR-based, calculate the year range for the select drop-down menu.
        if (is_string($value) && (strpos($value, 'YEAR') !== false)) {
            $years = array('----' => '----');
            $yearAry = array();
            $yearAry = explode('_', $value);
            if (isset($yearAry[1]) && isset($yearAry[2])) {
                if ($yearAry[1] < $yearAry[2]) {
                    for ($i = $yearAry[1]; $i <= $yearAry[2]; $i++) {
                        $years[$i] = $i;
                    }
                } else {
                    for ($i = $yearAry[1]; $i >= $yearAry[2]; $i--) {
                        $years[$i] = $i;
                    }
                }
            } else if (isset($yearAry[1])) {
                $year = date('Y');
                if ($year < $yearAry[1]) {
                    for ($i = $year; $i <= $yearAry[1]; $i++) {
                        $years[$i] = $i;
                    }
                } else {
                    for ($i = $year; $i >= $yearAry[1]; $i--) {
                        $years[$i] = $i;
                    }
                }
            } else {
                $year = date('Y');
                for ($i = $year; $i <= ($year + 10); $i++) {
                    $years[$i] = $i;
                }
            }
            $val = $years;
        // Else, if the value flag is one of the pre-defined array values, set the value of the select drop-down menu to it.
        } else {
            switch ($value) {
                // Months, numeric short values.
                case 'MONTHS_SHORT':
                    $val = array('--' => '--', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
                    break;
                // Months, long name values.
                case 'MONTHS_LONG':
                    $val = array('--' => '------', '01' => $lang->__('January'), '02' => $lang->__('February'), '03' => $lang->__('March'), '04' => $lang->__('April'), '05' => $lang->__('May'), '06' => $lang->__('June'), '07' => $lang->__('July'), '08' => $lang->__('August'), '09' => $lang->__('September'), '10' => $lang->__('October'), '11' => $lang->__('November'), '12' => $lang->__('December'));
                    break;
                // Days of Month, numeric short values.
                case 'DAYS_OF_MONTH':
                    $val = array('--' => '--', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31');
                    break;
                // Days of Week, long name values.
                case 'DAYS_OF_WEEK':
                    $sun = $lang->__('Sunday');
                    $mon = $lang->__('Monday');
                    $tue = $lang->__('Tuesday');
                    $wed = $lang->__('Wednesday');
                    $thu = $lang->__('Thursday');
                    $fri = $lang->__('Friday');
                    $sat = $lang->__('Saturday');
                    $val = array('--' => '------', $sun => $sun, $mon => $mon, $tue => $tue, $wed => $wed, $thu => $thu, $fri => $fri, $sat => $sat);
                    break;
                // Hours, 12-hour values.
                case 'HOURS':
                    $val = array('--' => '--', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
                    break;
                // Military Hours, 24-hour values.
                case 'MILITARY_HOURS':
                    $val = array('--' => '--', '00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23');
                    break;
                // Minutes, incremental by 1 minute.
                case 'MINUTES':
                    $val = array('--' => '--', '00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31', '32' => '32', '33' => '33', '34' => '34', '35' => '35', '36' => '36', '37' => '37', '38' => '38', '39' => '39', '40' => '40', '41' => '41', '42' => '42', '43' => '43', '44' => '44', '45' => '45', '46' => '46', '47' => '47', '48' => '48', '49' => '49', '50' => '50', '51' => '51', '52' => '52', '53' => '53', '54' => '54', '55' => '55', '56' => '56', '57' => '57', '58' => '58', '59' => '59');
                    break;
                // Minutes, incremental by 5 minutes.
                case 'MINUTES_BY_5':
                    $val = array('--' => '--', '00' => '00', '05' => '05', '10' => '10', '15' => '15', '20' => '20', '25' => '25', '30' => '30', '35' => '35', '40' => '40', '45' => '45', '50' => '50', '55' => '55');
                    break;
                // Minutes, incremental by 15 minutes.
                case 'MINUTES_BY_15':
                    $val = array('--' => '--', '00' => '00', '15' => '15', '30' => '30', '45' => '45');
                    break;
                // US States, short name values.
                case 'US_STATES_SHORT':
                    $val = array('--' => '--', 'AK' => 'AK', 'AL' => 'AL', 'AR' => 'AR', 'AZ' => 'AZ', 'CA' => 'CA', 'CO' => 'CO', 'CT' => 'CT', 'DC' => 'DC', 'DE' => 'DE', 'FL' => 'FL', 'GA' => 'GA', 'HI' => 'HI', 'IA' => 'IA', 'ID' => 'ID', 'IL' => 'IL', 'IN' => 'IN', 'KS' => 'KS', 'KY' => 'KY', 'LA' => 'LA', 'MA' => 'MA', 'MD' => 'MD', 'ME' => 'ME', 'MI' => 'MI', 'MN' => 'MN', 'MO' => 'MO', 'MS' => 'MS', 'MT' => 'MT', 'NC' => 'NC', 'ND' => 'ND', 'NE' => 'NE', 'NH' => 'NH', 'NJ' => 'NJ', 'NM' => 'NM', 'NV' => 'NV', 'NY' => 'NY', 'OH' => 'OH', 'OK' => 'OK', 'OR' => 'OR', 'PA' => 'PA', 'RI' => 'RI', 'SC' => 'SC', 'SD' => 'SD', 'TN' => 'TN', 'TX' => 'TX', 'UT' => 'UT', 'VA' => 'VA', 'VT' => 'VT', 'WA' => 'WA', 'WI' => 'WI', 'WV' => 'WV', 'WY' => 'WY');
                    break;
                // US States, long name values.
                case 'US_STATES_LONG':
                    $val = array('--' => '------', 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DC' => 'District of Columbia', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming');
                    break;
                // US Territories, short name values.
                case 'US_TERR_SHORT':
                    $val = array('--' => '--', 'AS' => 'AS', 'FM' => 'FM', 'GU' => 'GU', 'MH' => 'MH', 'MP' => 'MP', 'PW' => 'PW', 'PR' => 'PR', 'VI' => 'VI', 'AE' => 'AE', 'AA' => 'AA', 'AP' => 'AP');
                    break;
                // US Territories, long name values.
                case 'US_TERR_LONG':
                    $val = array('--' => '------', 'AS' => 'American Samoa', 'FM' => 'Federated States of Micronesia', 'GU' => 'Guam', 'MH' => 'Marshall Islands', 'MP' => 'Northern Mariana Islands', 'PW' => 'Palau', 'PR' => 'Puerto Rico', 'VI' => 'Virgin Islands', 'AE' => 'Armed Forces', 'AA' => 'Armed Forces Americas', 'AP' => 'Armed Forces Pacific');
                    break;
                // Canadian Provinces, short name values.
                case 'CA_PROVINCES_SHORT':
                    $val = array('--' => '--', 'AB' => 'AB', 'BC' => 'BC', 'MB' => 'MB', 'NB' => 'NB', 'NL' => 'NL', 'NT' => 'NT', 'NS' => 'NS', 'NU' => 'NU', 'ON' => 'ON', 'PE' => 'PE', 'QC' => 'QC', 'SK' => 'SK', 'YT' => 'YT');
                    break;
                // Canadian Provinces, long name values.
                case 'CA_PROVINCES_LONG':
                    $val = array('--' => '------', 'AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba', 'NB' => 'New Brunswick', 'NL' => 'Newfoundland and Labrador', 'NT' => 'Northwest Territories', 'NS' => 'Nova Scotia', 'NU' => 'Nunavut', 'ON' => 'Ontario', 'PE' => 'Prince Edward Island', 'QC' => 'Quebec', 'SK' => 'Saskatchewan', 'YT' => 'Yukon');
                    break;
                // Mexican States, short name values.
                case 'MEX_STATES_SHORT':
                    $val = array('--' => '--', 'AG' => 'AG', 'BC' => 'BC', 'BS' => 'BS', 'CM' => 'CM', 'CS' => 'CS', 'CH' => 'CH', 'CO' => 'CO', 'CL' => 'CL', 'DF' => 'DF', 'DG' => 'DG', 'GT' => 'GT', 'GR' => 'GR', 'HG' => 'HG', 'JA' => 'JA', 'ME' => 'ME', 'MI' => 'MI', 'MO' => 'MO', 'NA' => 'NA', 'NL' => 'NL', 'OA' => 'OA', 'PB' => 'PB', 'QE' => 'QE', 'QR' => 'QR', 'SL' => 'SL', 'SI' => 'SI', 'SO' => 'SO', 'TB' => 'TB', 'TM' => 'TM', 'TL' => 'TL', 'VE' => 'VE', 'YU' => 'YU', 'ZA' => 'ZA');
                    break;
                // Mexican States, long name values.
                case 'MEX_STATES_LONG':
                    $val = array('--' => '------', 'AG' => 'Aguascalientes', 'BC' => 'Baja California', 'BS' => 'Baja California Sur', 'CM' => 'Campeche', 'CS' => 'Chiapas', 'CH' => 'Chihuahua', 'CO' => 'Coahuila', 'CL' => 'Colima', 'DF' => 'Federal District', 'DG' => 'Durango', 'GT' => 'Guanajuato', 'GR' => 'Guerrero', 'HG' => 'Hidalgo', 'JA' => 'Jalisco', 'ME' => 'Mexico State', 'MI' => 'Michoac&#225;n', 'MO' => 'Morelos', 'NA' => 'Nayarit', 'NL' => 'Nuevo Le&#243;n', 'OA' => 'Oaxaca', 'PB' => 'Puebla', 'QE' => 'Quer&#233;taro', 'QR' => 'Quintana Roo', 'SL' => 'San Luis Potos&#237;', 'SI' => 'Sinaloa', 'SO' => 'Sonora', 'TB' => 'Tabasco', 'TM' => 'Tamaulipas', 'TL' => 'Tlaxcala', 'VE' => 'Veracruz', 'YU' => 'Yucat&#225;n', 'ZA' => 'Zacatecas');
                    break;
                // UK Counties, long name values.
                case 'UK_COUNTIES':
                    $val = array('--' => '------', 'Aberdeenshire' => 'Aberdeenshire', 'Alderney' => 'Alderney', 'Angus/Forfarshire' => 'Angus/Forfarshire', 'Argyllshire' => 'Argyllshire', 'Avon' => 'Avon', 'Ayrshire' => 'Ayrshire', 'Banffshire' => 'Banffshire', 'Bedfordshire' => 'Bedfordshire', 'Berkshire' => 'Berkshire', 'Berwickshire' => 'Berwickshire', 'Buckinghamshire' => 'Buckinghamshire', 'Buteshire' => 'Buteshire', 'Caithness' => 'Caithness', 'Cambridgeshire' => 'Cambridgeshire', 'Cheshire' => 'Cheshire', 'Clackmannanshire' => 'Clackmannanshire', 'Clwyd' => 'Clwyd', 'Cornwall' => 'Cornwall', 'County Antrim' => 'County Antrim', 'County Armagh' => 'County Armagh', 'County Down' => 'County Down', 'County Fermanagh' => 'County Fermanagh', 'County Londonderry' => 'County Londonderry', 'County Tyrone' => 'County Tyrone', 'Cumbria' => 'Cumbria', 'Derbyshire' => 'Derbyshire', 'Devon' => 'Devon', 'Dorset' => 'Dorset', 'Dumbartonshire' => 'Dumbartonshire', 'Dumfriesshire' => 'Dumfriesshire', 'Durham' => 'Durham', 'Dyfed' => 'Dyfed', 'East Lothian' => 'East Lothian', 'East Sussex' => 'East Sussex', 'East Yorkshire' => 'East Yorkshire', 'Essex' => 'Essex', 'Fair Isle' => 'Fair Isle', 'Fife' => 'Fife', 'Gloucestershire' => 'Gloucestershire', 'Greater London' => 'Greater London', 'Greater Manchester' => 'Greater Manchester', 'Guernsey' => 'Guernsey', 'Gwent' => 'Gwent', 'Gwynedd' => 'Gwynedd', 'Hampshire' => 'Hampshire', 'Herefordshire' => 'Herefordshire', 'Herm' => 'Herm', 'Hertfordshire' => 'Hertfordshire', 'Huntingdonshire' => 'Huntingdonshire', 'Inner Hebrides' => 'Inner Hebrides', 'Inverness-shire' => 'Inverness-shire', 'Isle of Man' => 'Isle of Man', 'Isle of Wight' => 'Isle of Wight', 'Isles of Scilly' => 'Isles of Scilly', 'Jersey' => 'Jersey', 'Kent' => 'Kent', 'Kincardineshire' => 'Kincardineshire', 'Kinross-shire' => 'Kinross-shire', 'Kirkcudbrightshire' => 'Kirkcudbrightshire', 'Lanarkshire' => 'Lanarkshire', 'Lancashire' => 'Lancashire', 'Leicestershire' => 'Leicestershire', 'Lincolnshire' => 'Lincolnshire', 'Merseyside' => 'Merseyside', 'Mid Glamorgan' => 'Mid Glamorgan', 'Middlesex' => 'Middlesex', 'Midlothian/Edinburghshire' => 'Midlothian/Edinburghshire', 'Morayshire' => 'Morayshire', 'Nairnshire' => 'Nairnshire', 'Norfolk' => 'Norfolk', 'North Yorkshire' => 'North Yorkshire', 'Northamptonshire' => 'Northamptonshire', 'Northumberland' => 'Northumberland', 'Nottinghamshire' => 'Nottinghamshire', 'Orkney' => 'Orkney', 'Outer Hebrides' => 'Outer Hebrides', 'Oxfordshire' => 'Oxfordshire', 'Peeblesshire' => 'Peeblesshire', 'Perthshire' => 'Perthshire', 'Powys' => 'Powys', 'Renfrewshire' => 'Renfrewshire', 'Ross-shire' => 'Ross-shire', 'Roxburghshire' => 'Roxburghshire', 'Rutland' => 'Rutland', 'Sark' => 'Sark', 'Selkirkshire' => 'Selkirkshire', 'Shetland' => 'Shetland', 'Shropshire' => 'Shropshire', 'Somerset' => 'Somerset', 'South Glamorgan' => 'South Glamorgan', 'South Yorkshire' => 'South Yorkshire', 'Staffordshire' => 'Staffordshire', 'Stirlingshire' => 'Stirlingshire', 'Suffolk' => 'Suffolk', 'Surrey' => 'Surrey', 'Sutherland' => 'Sutherland', 'Tyne and Wear' => 'Tyne and Wear', 'Warwickshire' => 'Warwickshire', 'West Glamorgan' => 'West Glamorgan', 'West Lothian/Linlithgowshire' => 'West Lothian/Linlithgowshire', 'West Midlands' => 'West Midlands', 'West Sussex' => 'West Sussex', 'West Yorkshire' => 'West Yorkshire', 'Wigtownshire' => 'Wigtownshire', 'Wiltshire' => 'Wiltshire', 'Worcestershire' => 'Worcestershire');
                    break;
                // Ireland Counties, long name values.
                case 'IRELAND_COUNTIES':
                    $val = array('--' => '------', 'Carlow' => 'Carlow', 'Cavan' => 'Cavan', 'Clare' => 'Clare', 'Cork' => 'Cork', 'Donegal' => 'Donegal', 'Dublin' => 'Dublin', 'Galway' => 'Galway', 'Kerry' => 'Kerry', 'Kildare' => 'Kildare', 'Kilkenny' => 'Kilkenny', 'Laois' => 'Laois', 'Leitrim' => 'Leitrim', 'Limerick' => 'Limerick', 'Longford' => 'Longford', 'Louth' => 'Louth', 'Mayo' => 'Mayo', 'Meath' => 'Meath', 'Monaghan' => 'Monaghan', 'Offaly' => 'Offaly', 'Roscommon' => 'Roscommon', 'Sligo' => 'Sligo', 'Tipperary' => 'Tipperary', 'Waterford' => 'Waterford', 'Westmeath' => 'Westmeath', 'Wexford' => 'Wexford', 'Wicklow' => 'Wicklow');
                    break;
                // Countries, long name values.
                case 'COUNTRIES':
                    $val = array('--' => '------', 'AF' => 'Afghanistan', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AS' => 'American Samoa', 'AD' => 'Andorra', 'AO' => 'Angola', 'AI' => 'Anguilla', 'AQ' => 'Antarctica', 'AG' => 'Antigua and Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AW' => 'Aruba', 'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BM' => 'Bermuda', 'BT' => 'Bhutan', 'BO' => 'Bolivia', 'BA' => 'Bosnia and Herzegowina', 'BW' => 'Botswana', 'BV' => 'Bouvet Island', 'BR' => 'Brazil', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'KH' => 'Cambodia', 'CM' => 'Cameroon', 'CA' => 'Canada', 'CV' => 'Cape Verde', 'KY' => 'Cayman Islands', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', 'CO' => 'Colombia', 'KM' => 'Comoros', 'CG' => 'Congo', 'CD' => 'Congo, the Democratic Republic of the', 'CK' => 'Cook Islands', 'CR' => 'Costa Rica', 'CI' => 'Cote d&#39;Ivoire', 'HR' => 'Croatia (Hrvatska)', 'CU' => 'Cuba', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'TP' => 'East Timor', 'EC' => 'Ecuador', 'EG' => 'Egypt', 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'EE' => 'Estonia', 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', 'FO' => 'Faroe Islands', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 'FX' => 'France, Metropolitan', 'GF' => 'French Guiana', 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', 'DE' => 'Germany', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GB' => 'Great Britain', 'GR' => 'Greece', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GU' => 'Guam', 'GT' => 'Guatemala', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HT' => 'Haiti', 'HM' => 'Heard and Mc Donald Islands', 'VA' => 'Holy See (Vatican City State)', 'HN' => 'Honduras', 'HK' => 'Hong Kong', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran (Islamic Republic of)', 'IQ' => 'Iraq', 'IE' => 'Ireland', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 'JP' => 'Japan', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 'KI' => 'Kiribati', 'KP' => 'Korea, Democratic People&#39;s Republic of', 'KR' => 'Korea, Republic of', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Lao People&#39;s Democratic Republic', 'LV' => 'Latvia', 'LB' => 'Lebanon', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libyan Arab Jamahiriya',
                                 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MO' => 'Macau', 'MK' => 'Macedonia, The Former Yugoslav Republic of', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 'MH' => 'Marshall Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MX' => 'Mexico', 'FM' => 'Micronesia, Federated States of', 'MD' => 'Moldova, Republic of', 'MC' => 'Monaco', 'MN' => 'Mongolia', 'MS' => 'Montserrat', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'MM' => 'Myanmar', 'NA' => 'Namibia', 'NR' => 'Nauru', 'NP' => 'Nepal', 'NL' => 'Netherlands', 'AN' => 'Netherlands Antilles', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 'PH' => 'Philippines', 'PN' => 'Pitcairn', 'PL' => 'Poland', 'PT' => 'Portugal', 'PR' => 'Puerto Rico', 'QA' => 'Qatar', 'RE' => 'Reunion', 'RO' => 'Romania', 'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint LUCIA', 'VC' => 'Saint Vincent and the Grenadines', 'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome and Principe', 'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 'SK' => 'Slovakia (Slovak Republic)', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'GS' => 'South Georgia and the South Sandwich Islands', 'ES' => 'Spain', 'LK' => 'Sri Lanka', 'SH' => 'St. Helena', 'PM' => 'St. Pierre and Miquelon', 'SD' => 'Sudan', 'SR' => 'Suriname', 'SJ' => 'Svalbard and Jan Mayen Islands', 'SZ' => 'Swaziland', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan, Province of China', 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania, United Republic of', 'TH' => 'Thailand', 'TG' => 'Togo', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TT' => 'Trinidad and Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'TC' => 'Turks and Caicos Islands', 'TV' => 'Tuvalu', 'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 'UK' => 'United Kingdom', 'US' => 'United States', 'UM' => 'United States Minor Outlying Islands', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VE' => 'Venezuela', 'VN' => 'Viet Nam', 'VG' => 'Virgin Islands (British)', 'VI' => 'Virgin Islands (U.S.)', 'WF' => 'Wallis and Futuna Islands', 'EH' => 'Western Sahara', 'YE' => 'Yemen', 'YU' => 'Yugoslavia', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe');
                    break;
                // Else, set the custom array of values passed.
                default:
                    $val = $value;
            }
        }

        $this->values = $val;
        $this->setMarked($marked);

        parent::__construct('select', $name, $val, $marked, $indent);

    }

    /**
     * Set the current marked value. The marked value is based on the key of the associative array (not the value.)
     *
     * @param  string $val
     * @return void
     */
    public function setMarked($val)
    {

        $this->marked = null;

        if (array_key_exists($val, $this->values) !==  false) {
            $this->marked = $this->values[$val];
        }

    }

}
Return current item: Moc10 PHP Library