load->library('qra');
$this->load->helper('file');
// Load Database connections
$this->load->model('logbook_model');
// Get QSOs with Valid QRAs
$qsos = $this->logbook_model->kml_get_all_qsos();
//header('Content-type: text/xml');
//header("Cache-Control: no-cache");
$output = "";
$output .= "";
$output .= "";
foreach ($qsos->result() as $row)
{
$output .= "";
//print_r($row);
if($row->COL_GRIDSQUARE != null) {
$stn_loc = $this->qra->qra2latlong($row->COL_GRIDSQUARE);
$lat = $stn_loc[0];
$lng = $stn_loc[1];
} else {
$query = $this->db->query('
SELECT *
FROM dxcc
WHERE prefix = SUBSTRING( \''.$row->COL_CALL.'\', 1, LENGTH( prefix ) )
ORDER BY LENGTH( prefix ) DESC
LIMIT 1
');
foreach ($query->result() as $dxcc) {
$lat = $dxcc->lat;
$lng = $dxcc->long;
}
}
$timestamp = strtotime($row->COL_TIME_ON);
$output .= "".$row->COL_CALL."";
$output .= "Date/Time: ".date('Y-m-d H:i:s', ($timestamp))."
Band: ".$row->COL_BAND."
]]>";
$output .= "";
$output .= "".$lng.",".$lat.",0";
$output .= "";
$output .= "";
}
$output .= "";
$output .= "";
if ( ! write_file('kml/qsos.kml', $output))
{
echo 'Unable to write the file';
}
else
{
header("Content-Disposition: attachment; filename=\"qsos.kml\"");
echo $output;
}
}
}