diff --git a/application/controllers/Qrz.php b/application/controllers/Qrz.php index 4a8643c7..29e1e856 100644 --- a/application/controllers/Qrz.php +++ b/application/controllers/Qrz.php @@ -25,7 +25,8 @@ class Qrz extends CI_Controller { if ($station_ids) { foreach ($station_ids as $station_id) { - $qrz_api_key = $this->logbook_model->exists_qrz_api_key($station_id); + $result = $this->logbook_model->exists_qrz_api_key($station_id); + $qrz_api_key = $result->qrzapikey; if($this->mass_upload_qsos($station_id, $qrz_api_key)) { echo "QSOs have been uploaded to QRZ.com."; log_message('info', 'QSOs have been uploaded to QRZ.com.'); @@ -58,23 +59,26 @@ class Qrz extends CI_Controller { $data['qsos'] = $this->logbook_model->get_qrz_qsos($station_id); $errormessages=array(); - if ($data['qsos']) { - foreach ($data['qsos'] as $qso) { - $adif = $this->logbook_model->create_adif_from_data($qso); + $CI =& get_instance(); + $CI->load->library('AdifHelper'); - if ($qso['COL_QRZCOM_QSO_UPLOAD_STATUS'] == 'M') { + if ($data['qsos']) { + foreach ($data['qsos']->result() as $qso) { + $adif = $CI->adifhelper->getAdifLine($qso); + + if ($qso->COL_QRZCOM_QSO_UPLOAD_STATUS == 'M') { $result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif, true); } else { $result = $this->logbook_model->push_qso_to_qrz($qrz_api_key, $adif); } if ($result['status'] == 'OK') { - $this->markqso($qso['COL_PRIMARY_KEY']); + $this->markqso($qso->COL_PRIMARY_KEY); $i++; } else { - log_message('error', 'QRZ upload failed for qso: Call: ' . $qso['COL_CALL'] . ' Band: ' . $qso['COL_BAND'] . ' Mode: ' . $qso['COL_MODE'] . ' Time: ' . $qso['COL_TIME_ON']); + log_message('error', 'QRZ upload failed for qso: Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON); log_message('error', 'QRZ upload failed with the following message: ' .$result['message']); - $errormessages[] = $result['message'] . ' Call: ' . $qso['COL_CALL'] . ' Band: ' . $qso['COL_BAND'] . ' Mode: ' . $qso['COL_MODE'] . ' Time: ' . $qso['COL_TIME_ON']; + $errormessages[] = $result['message'] . ' Call: ' . $qso->COL_CALL . ' Band: ' . $qso->COL_BAND . ' Mode: ' . $qso->COL_MODE . ' Time: ' . $qso->COL_TIME_ON; } } $result['status'] = 'OK'; @@ -124,8 +128,8 @@ class Qrz extends CI_Controller { $postData = $this->input->post(); $this->load->model('logbook_model'); - $qrz_api_key = $this->logbook_model->exists_qrz_api_key($postData['station_id']); - + $result = $this->logbook_model->exists_qrz_api_key($postData['station_id']); + $qrz_api_key = $result->qrzapikey; header('Content-type: application/json'); $result = $this->mass_upload_qsos($postData['station_id'], $qrz_api_key); if ($result['status'] == 'OK') { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 35d86f3b..a4984701 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -338,22 +338,25 @@ class Logbook_model extends CI_Model { $data['COL_RX_PWR'] = str_replace("W", "", $data['COL_RX_PWR']); } - $result = $this->exists_qrz_api_key($data['station_id']); - - // Push qso to qrz if apikey is set - if ($result) { - if ($result->qrzrealtime == 1) { - $adif = $this->create_adif_from_data($data); - $result = $this->push_qso_to_qrz($result->qrzapikey, $adif); - IF ($result['status'] == 'OK') { - $data['COL_QRZCOM_QSO_UPLOAD_STATUS'] = 'Y'; - $data['COL_QRZCOM_QSO_UPLOAD_DATE'] = date("Y-m-d H:i:s", strtotime("now")); - } - } - } + // Add QSO to database + $this->db->insert($this->config->item('table_name'), $data); - // Add QSO to database - $this->db->insert($this->config->item('table_name'), $data); + $last_id = $this->db->insert_id(); + + $result = $this->exists_qrz_api_key($data['station_id']); + + // Push qso to qrz if apikey is set, and realtime upload is enabled + if (isset($result->qrzapikey) && $result->qrzrealtime == 1) { + $CI =& get_instance(); + $CI->load->library('AdifHelper'); + $qso = $this->get_qso($last_id)->result(); + + $adif = $CI->adifhelper->getAdifLine($qso[0]); + $result = $this->push_qso_to_qrz($result->qrzapikey, $adif); + if ($result['status'] == 'OK') { + $this->mark_qrz_qsos_sent($last_id); + } + } } /* @@ -434,133 +437,6 @@ class Logbook_model extends CI_Model { return true; } - /* - * Function is used to build an ADIF string from an array that contains the QSO data - */ - function create_adif_from_data($data) { - $adif = '' . $data['COL_CALL']; - $adif .= '' . $data['COL_BAND']; - $adif .= '' . $data['COL_MODE']; - - if ($data['COL_SUBMODE']) { - $adif .= '' . $data['COL_SUBMODE']; - } - - if($data['COL_FREQ'] != "0") { - $freq_in_mhz = $data['COL_FREQ'] / 1000000; - $adif .= '' . $freq_in_mhz; - } - - $date_on = strtotime($data['COL_TIME_ON']); - $new_date = date('Ymd', $date_on); - $adif .= '' . $new_date; - $time_on = strtotime($data['COL_TIME_ON']); - $new_on = date('His', $time_on); - $adif .= '' . $new_on; - $time_off = strtotime($data['COL_TIME_OFF']); - $new_off = date('His', $time_off); - $adif .= '' . $new_off; - $adif .= '' . $data['COL_RST_RCVD']; - $adif .= '' . $data['COL_RST_SENT']; - - if ($data['COL_QSL_RCVD']) { - $adif .= '' . $data['COL_QSL_RCVD']; - } - - $adif .= '' . $data['COL_QSL_SENT']; - $adif .= '' . $data['COL_COUNTRY']; - $adif .= '' . $data['COL_STATION_CALLSIGN']; - $adif .= '' . $data['COL_DXCC']; - $adif .= '' . $data['COL_CQZ']; - //$adif .= '' . $data['COL_ITUZ']; -- not yet implemented - - if(isset($data['COL_LOTW_QSL_SENT'])) { - $adif .= '' . $data['COL_LOTW_QSL_SENT']; - } - - if(isset($data['COL_LOTW_QSL_RCVD'])) { - $adif .= '' . $data['COL_LOTW_QSL_RCVD']; - } - - if($data['COL_IOTA']) { - $adif .= '' . $data['COL_IOTA']; - } - - if($data['COL_GRIDSQUARE']) { - $adif .= '' . $data['COL_GRIDSQUARE']; - } - - if($data['COL_SOTA_REF']) { - $adif .= '' . $data['COL_SOTA_REF']; - } - - if($data['COL_COMMENT']) { - $adif .= '' . $data['COL_COMMENT']; - } - - if($data['COL_SAT_NAME']) { - if($data['COL_SAT_MODE'] != 0 || $data['COL_SAT_MODE'] !="") { - $adif .= '' . $data['COL_SAT_MODE']; - $adif .= 'sat_name:' . strlen($data['COL_SAT_NAME']) . '>' . $data['COL_SAT_NAME']; - } - } - - if($data['COL_STATE']) { - $adif .= '' . $data['COL_STATE']; - } - - if($data['COL_PROP_MODE']) { - $adif .= '' . $data['COL_PROP_MODE']; - } - - if($data['COL_NAME']) { - $adif .= '' . $data['COL_NAME']; - } - - if($data['COL_OPERATOR']) { - $adif .= '' . $data['COL_OPERATOR']; - } - - if($data['COL_MY_CITY']) { - $adif .= '' . $data['COL_MY_CITY']; - } - - if($data['COL_MY_COUNTRY']) { - $adif .= '' . $data['COL_MY_COUNTRY']; - } - - if($data['COL_MY_DXCC']) { - $adif .= '' . $data['COL_MY_DXCC']; - } - - if($data['COL_MY_IOTA']) { - $adif .= '' . $data['COL_MY_IOTA']; - } - - if($data['COL_MY_SOTA_REF']) { - $adif .= '' . $data['COL_MY_SOTA_REF']; - } - - if($data['COL_MY_CQ_ZONE']) { - $adif .= '' . $data['COL_MY_CQ_ZONE']; - } - - if($data['COL_MY_ITU_ZONE']) { - $adif .= '' . $data['COL_MY_ITU_ZONE']; - } - - if($data['COL_MY_CNTY']) { - $adif .= '' . $data['COL_MY_CNTY']; - } - - if(strpos($data['COL_MY_GRIDSQUARE'], ',') !== false ) { - $adif .= '' . $data['COL_MY_GRIDSQUARE']; - } - - $adif .= ''; - return $adif; - } - /* Edit QSO */ function edit() { $entity = $this->get_entity($this->input->post('dxcc_id')); @@ -887,16 +763,18 @@ class Logbook_model extends CI_Model { * Function returns the QSOs from the logbook, which have not been either marked as uploaded to qrz, or has been modified with an edit */ function get_qrz_qsos($station_id){ - $sql = 'select * from ' . $this->config->item('table_name') . - ' where station_id = ' . $station_id . + $sql = 'select * from ' . $this->config->item('table_name') . ' thcv ' . + ' join station_profile on thcv.station_id = station_profile.station_id' . + ' where thcv.station_id = ' . $station_id . ' and (COL_QRZCOM_QSO_UPLOAD_STATUS is NULL or COL_QRZCOM_QSO_UPLOAD_STATUS = "" or COL_QRZCOM_QSO_UPLOAD_STATUS = "M" or COL_QRZCOM_QSO_UPLOAD_STATUS = "N")'; $query = $this->db->query($sql); - return $query->result_array(); + return $query; } + /* * Function returns all the station_id's with QRZ API Key's */ @@ -916,8 +794,6 @@ class Logbook_model extends CI_Model { } } - - function get_last_qsos($num) { $CI =& get_instance();