<?php
# ----------------------------------------------------------------------------------
# Erased currencies must be added as disabled
# ----------------------------------------------------------------------------------

$currencies = array(
                       'CHF' => array(
                                         'name'      => 'Swiss Franc',
                                         'symbol'    => 'CHF',
                                         'abrv'      => 'CHF',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'MYR' => array(
                                         'name'      => 'Malaysian Ringgit',
                                         'symbol'    => 'MYR',
                                         'abrv'      => 'MYR',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'AUD' => array(
                                         'name'      => 'Australian Dollar',
                                         'symbol'    => '$',
                                         'abrv'      => 'AUD',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'USD' => array(
                                         'name'      => 'US Dollar',
                                         'symbol'    => '$',
                                         'abrv'      => 'USD',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'CAD' => array(
                                         'name'      => 'Canadian Dollar',
                                         'symbol'    => '$',
                                         'abrv'      => 'CAD',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'NZD' => array(
                                         'name'      => 'New Zealand Dollars',
                                         'symbol'    => 'NZ$',
                                         'abrv'      => 'NZD',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'SAR' => array(
                                         'name'      => 'Saudi Riyal',
                                         'symbol'    => 'SR',
                                         'abrv'      => 'SAR',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'TRY' => array(
                                         'name'      => 'Turkish Lira',
                                         'symbol'    => 'TL',
                                         'abrv'      => 'TRY',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'SEK' => array(
                                         'name'      => 'Swedish Krona',
                                         'symbol'    => 'Sk',
                                         'abrv'      => 'SEK',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'SGD' => array(
                                         'name'      => 'Singapore Dollar',
                                         'symbol'    => '$',
                                         'abrv'      => 'SGD',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'EUR' => array(
                                         'name'      => 'Euro',
                                         'symbol'    => '€',
                                         'abrv'      => 'EUR',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'INR' => array(
                                         'name'      => 'Indian Rupees',
                                         'symbol'    => 'Rs.',
                                         'abrv'      => 'INR',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'PHP' => array(
                                         'name'      => 'Philippine Peso',
                                         'symbol'    => 'PHP',
                                         'abrv'      => 'PHP',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'JPY' => array(
                                         'name'      => 'Yen',
                                         'symbol'    => '¥',
                                         'abrv'      => 'JPY',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'GBP' => array(
                                         'name'      => 'Pound Sterling (GBP)',
                                         'symbol'    => '£',
                                         'abrv'      => 'GBP',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'IDR' => array(
                                         'name'      => 'Indonesia Rupiah (Rp)',
                                         'symbol'    => 'Rp',
                                         'abrv'      => 'IDR',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                       'ARS' => array(
                                         'name'      => 'Argentine Peso',
                                         'symbol'    => '$',
                                         'abrv'      => 'ARS',
                                         'alignment' => 'left',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),
                        'AED' => array(
                                         'name'      => 'United Arab Emirates Dirham',
                                         'symbol'    => 'AED',
                                         'abrv'      => 'AED',
                                         'alignment' => 'right',
                                         'precision' => 2,
                                         'rate'      => 1,
                                         'enabled'   => 0,
                                     ),

                   );

$query = "SELECT `abrv` FROM `currency`";
$result = mysql_query($query) or die("ERROR in query: $query");

while(list($abrv) = mysql_fetch_row($result)){
    if(array_key_exists(strtoupper($abrv), $currencies)){
        unset($currencies[strtoupper($abrv)]);
    }
}

foreach($currencies AS $currency){
    $query2 = "INSERT INTO `currency` "
             ."("
                 ."`name`, "
                 ."`symbol`, "
                 ."`abrv`, "
                 ."`alignment`, "
                 ."`precision`, "
                 ."`rate`, "
                 ."`enabled`"
             .") "
             ."VALUES ("
                 ."'".$currency['name']."', "
                 ."'".$currency['symbol']."', "
                 ."'".$currency['abrv']."', "
                 ."'".$currency['alignment']."', "
                 .$currency['precision'].", "
                 .$currency['rate'].", "
                 .$currency['enabled']
             .")";
    
    mysql_query($query2) or die("ERROR in query: $query");
}



/*
 * Fucntion to update the TLD Data
 */
function convertTlds() {
    
    $datalist = array();
    $result = mysql_query("SELECT * FROM tld");
    $fail = 0;
     
	// Add the values to the datalist
	while($rows = mysql_fetch_assoc($result)) {
		
		if(isset($rows['active'])) {
			$fail = 1;
		}
		
		$datalist[$rows['name']][] = $rows;
	}  

	// Check to see if we have to fail as a security precaution
	if($fail == 0) {
		// DROP THE TABLE
		mysql_query("DROP TABLE tld");
		
		// CREATE THE TABLE
		mysql_query("CREATE TABLE `tld` (
                              `id` int(11) NOT NULL AUTO_INCREMENT,
                              `name` varchar(15) NOT NULL DEFAULT '',
                              `plugin` varchar(25) NOT NULL DEFAULT '',
                              `pricing` text NOT NULL,
                              `active` smallint(1) NOT NULL DEFAULT '1',
                              `dnsmgmt` smallint(1) NOT NULL,
                              `autorenew` smallint(1) NOT NULL,
                              PRIMARY KEY (`id`)
                            ) DEFAULT CHARACTER SET utf8, ENGINE=MyISAM AUTO_INCREMENT=0 ;");

		
		// Now add the final new TLD's
		foreach($datalist AS $key) {
			
			// Calcualte the pricing array
			$pricingarray = array();
			foreach($key AS $var) {
				$pricingarray[] = array('period' => $var['period'],
										'price' => $var['price'],
										'renew' => $var['renewal'],
										'transfer' => $var['transferprice']
				);
			}
			
			// Format other vars
			$workingarray = array();
			$workingarray['name'] = $key[0]['name'];
			$workingarray['plugin'] = $key[0]['plugin'];
			$workingarray['pricing'] = serialize($pricingarray);
			
			// Add it
			mysql_query("INSERT INTO tld VALUES('', '".$workingarray['name']."', '".$workingarray['plugin']."', '".$workingarray['pricing']."', '1', '', '1')");
		}
		
	}

}
convertTlds(); // Run it
?>
