diff --git a/application/controllers/Update.php b/application/controllers/Update.php index 733f9a17e..3eeb84cc6 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -389,11 +389,17 @@ class Update extends CI_Controller { } - public function update_tle() { - $this->load->model('Update_model'); + public function update_tle() { + $this->load->model('Update_model'); $result = $this->Update_model->tle(); echo $result; - } + } + + public function update_lotw_sats() { + $this->load->model('Update_model'); + $result = $this->Update_model->lotw_sats(); + echo $result; + } function version_check() { // set the last run in cron table for the correct cron id diff --git a/application/models/Update_model.php b/application/models/Update_model.php index ad24d3335..f03626c26 100644 --- a/application/models/Update_model.php +++ b/application/models/Update_model.php @@ -359,13 +359,79 @@ class Update_model extends CI_Model { curl_close($curl); - $mtime = microtime(); - $mtime = explode(" ",$mtime); - $mtime = $mtime[1] + $mtime[0]; - $endtime = $mtime; - $totaltime = ($endtime - $starttime); - echo "This page was created in ".$totaltime." seconds
"; - echo "Records inserted: " . $count . "
"; + $mtime = microtime(); + $mtime = explode(" ",$mtime); + $mtime = $mtime[1] + $mtime[0]; + $endtime = $mtime; + $totaltime = ($endtime - $starttime); + echo "This page was created in ".$totaltime." seconds
"; + echo "Records inserted: " . $count . "
"; } + function lotw_sats() { + $url = 'https://lotw.arrl.org/lotw/config.tq6'; + $curl = curl_init($url); + + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_BINARYTRANSFER,true); + curl_setopt($curl, CURLOPT_TIMEOUT, 10); + + $response = curl_exec($curl); + if (curl_errno($curl)) { + echo __('cURL error:').' '.curl_error($curl).' ('.curl_errno($curl).')'; + return; + } + curl_close($curl); + $xml = simplexml_load_string(gzdecode($response)); + + $existingSats = array(); + $this->db->select('name, lotw'); + $query = $this->db->get('satellite'); + foreach($query->result() as $row) { + $existingSats[$row->name] = $row->lotw; + } + //$existingSats = $query->result_array(); + + print ''; + print ''; + foreach ($xml->tqslconfig->satellites->satellite as $sat) { + $name = $sat->attributes()->{'name'}; + $startDate = $sat->attributes()->{'startDate'}; + $endDate = $sat->attributes()->{'endDate'}; + $displayname = $sat; + $status = ''; + + if (array_key_exists("$name", $existingSats)) { + if ($existingSats["$name"] == 'N') { + $this->db->set('lotw', 'Y'); + $this->db->where('name', $name); + $this->db->update('satellite'); + if ($this->db->affected_rows() > 0) { + $status = __('SAT already existing. LoTW status updated.'); + } else { + $status = __('SAT already existing. Updating LoTW status failed.'); + } + } else { + $status = __('SAT already existing. Ignored.'); + } + } else { + $data = array( + 'name' => $name, + 'displayname' => $displayname, + 'lotw' => 'Y', + ); + if ($this->db->insert('satellite', $data)) { + $status = __('New SAT. Inserted.'); + } else { + $status = __('New SAT. Insert failed.'); + } + } + print(''); + } + print '
'.__('Name').''.__('Display Name').''.__('Start Date').''.__('End Date').''.__('Status').'
'.$name.''.$displayname.''.$startDate.''.$endDate.''.$status.'
'; + return; + } + } diff --git a/application/views/satellite/index.php b/application/views/satellite/index.php index 5040cc0fa..2a82f47c0 100644 --- a/application/views/satellite/index.php +++ b/application/views/satellite/index.php @@ -34,7 +34,7 @@ satname) ?> displayname ? htmlentities($sat->displayname) : '' ?> '.$sat->orbit.''; + echo '">'.($sat->orbit ?? __('unknown')).''; ?> modename ?? '') ?> ';