load->library('migration');
		if ( ! $this->migration->latest())
		{
			show_error($this->migration->error_string());
		}
	
		// Download latest file.
		$url = "https://secure.clublog.org/cty.php?api=a11c3235cd74b88212ce726857056939d52372bd";
		
		$gz = gzopen($url, 'r');
		$data = "";
		while (!gzeof($gz)) {
		  $data .= gzgetc($gz);
		}
		gzclose($gz);
		
		file_put_contents('./updates/cty.xml', $data);
	
		// Set timeout to unlimited
		set_time_limit(0);
	
		// Load Database connectors
		$this->load->model('dxcc');
		// Load the cty file
		$xml_data = simplexml_load_file("updates/cty.xml");
		
		$this->dxcc->empty_table("dxcc");
		
		echo "
Prefix List
";
		
		echo "";
		echo "";
		echo "| Prefix";
		echo " | Country Name";
		echo " | DXCC Expire Date";
		echo " | 
";
		
		foreach ($xml_data->prefixes as $prefixs) {
			foreach ($prefixs->prefix as $callsign) {
				$endinfo = strtotime($callsign->end);
				
				if($endinfo) {
					$end_date = date('Y-m-d H:i:s',$endinfo);
				} else {
					$end_date = "";
				}
			
				if(!$callsign->cqz) {
					$data = array(
					   'prefix' => (string) $callsign->call,
					   'name' =>  (string) $callsign->entity,
					);
				} else {
					$data = array(
					   'prefix' => (string)  $callsign->call,
					   'name' =>  (string) $callsign->entity,
					   'cqz' => (string) $callsign->cqz,
					   'ituz' => (string) $callsign->ituz,
					   'cont' => (string) $callsign->cont,
					   'long' => (string) $callsign->long,
					   'lat' => (string) $callsign->lat,
						 'end_date' => $end_date,
					);	
				}
			
				echo "";
				echo "| ".$callsign->call."";
				echo " | ".ucwords(strtolower($callsign->entity))."";
				echo " | ".$end_date."";
				echo " | ".$callsign->deleted."";
				echo " | 
";
				$this->db->insert('dxcc', $data); 
			}
		}
		echo "";
		
				// empty table
		$this->dxcc->empty_table("dxccexceptions");
		
		echo "Exceptions
";
		
		echo "";
		
		foreach ($xml_data->exceptions as $exceptions) {
			foreach ($exceptions->exception as $callsign) {
			
			echo "";
				echo "| ".$callsign->call."";
				echo " | ".$callsign->entity."";
			echo " | 
";
				
				if(!$callsign->start) {
					$data = array(
						'prefix' => (string)  $callsign->call,
						'name' =>  (string) $callsign->entity,
						'cqz' => (string) $callsign->cqz,
						'ituz' => (string) $callsign->ituz,
						'cont' => (string) $callsign->cont,
						'long' => (string) $callsign->long,
						'lat' => (string) $callsign->lat
					);	
				} else {
				
					$startinfo = strtotime($callsign->start);
				
					if($startinfo) {
						$start = date('Y-m-d H:i:s',$startinfo);
					} else {
						$start = "";
					}
				
					$endinfo = strtotime($callsign->end);
				
					if($endinfo) {
						$end = date('Y-m-d H:i:s',$endinfo);
					} else {
						$end = "";
					}
				
					$data = array(
						'prefix' => (string) $callsign->call,
						'name' =>  (string) $callsign->entity,
						'cqz' => (string) $callsign->cqz,
						'ituz' => (string) $callsign->ituz,
						'cont' => (string) $callsign->cont,
						'long' => (string) $callsign->long,
						'lat' => (string) $callsign->lat,
						'start' => $start,
						'end' => $end
					);	
				}
				$this->db->insert('dxccexceptions', $data); 
				
			}
		}
		
		echo "";
		
	}
	
	public function lotw_users() {
		// Load Database connectors
		$this->load->model('lotw');
		
		$this->lotw->empty_table("lotw_list");
		
		$lines = file('http://www.hb9bza.net/lotw/lotw1.txt');
		// Loop through our array, show HTML source as HTML source; and line numbers too.
		foreach ($lines as $line_num => $line) {
			 echo "Line #{$line_num} : " . htmlspecialchars($line) . "
\n";
			 
			 $data = array(
					'Callsign' => $line,
				);
			$this->db->insert('lotw_list', $data); 
			 
		}
	}
}
?>