diff --git a/application/controllers/Timeline.php b/application/controllers/Timeline.php index 87321556..29ee5416 100644 --- a/application/controllers/Timeline.php +++ b/application/controllers/Timeline.php @@ -25,26 +25,47 @@ class Timeline extends CI_Controller { $band = 'All'; } - if ($this->input->post('mode') != NULL) { // Band is not set when page first loads. + if ($this->input->post('mode') != NULL) { $mode = $this->input->post('mode'); } else { $mode = 'All'; } - if ($this->input->post('awardradio') != NULL) { // Band is not set when page first loads. + if ($this->input->post('awardradio') != NULL) { $award = $this->input->post('awardradio'); } else { $award = 'dxcc'; } + if ($this->input->post('qsl') != NULL) { + $qsl = $this->input->post('qsl'); + } + else { + $qsl = '0'; + } + + if ($this->input->post('lotw') != NULL) { + $lotw = $this->input->post('lotw'); + } + else { + $lotw = '0'; + } + + if ($this->input->post('eqsl') != NULL) { + $eqsl = $this->input->post('eqsl'); + } + else { + $eqsl = '0'; + } + $this->load->model('modes'); $this->load->model('bands'); $data['modes'] = $this->modes->active(); - $data['timeline_array'] = $this->Timeline_model->get_timeline($band, $mode, $award); + $data['timeline_array'] = $this->Timeline_model->get_timeline($band, $mode, $award, $qsl, $lotw, $eqsl); $data['worked_bands'] = $this->bands->get_worked_bands(); $data['bandselect'] = $band; $data['modeselect'] = $mode; diff --git a/application/models/Timeline_model.php b/application/models/Timeline_model.php index 72203337..684bd732 100644 --- a/application/models/Timeline_model.php +++ b/application/models/Timeline_model.php @@ -3,7 +3,7 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); class Timeline_model extends CI_Model { - function get_timeline($band, $mode, $award) { + function get_timeline($band, $mode, $award, $qsl, $lotw, $eqsl) { $CI =& get_instance(); $CI->load->model('logbooks_model'); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); @@ -15,16 +15,16 @@ class Timeline_model extends CI_Model $location_list = "'".implode("','",$logbooks_locations_array)."'"; switch ($award) { - case 'dxcc': $result = $this->get_timeline_dxcc($band, $mode, $location_list); break; - case 'was': $result = $this->get_timeline_was($band, $mode, $location_list); break; - case 'iota': $result = $this->get_timeline_iota($band, $mode, $location_list); break; - case 'waz': $result = $this->get_timeline_waz($band, $mode, $location_list); break; + case 'dxcc': $result = $this->get_timeline_dxcc($band, $mode, $location_list, $qsl, $lotw, $eqsl); break; + case 'was': $result = $this->get_timeline_was($band, $mode, $location_list, $qsl, $lotw, $eqsl); break; + case 'iota': $result = $this->get_timeline_iota($band, $mode, $location_list, $qsl, $lotw, $eqsl); break; + case 'waz': $result = $this->get_timeline_waz($band, $mode, $location_list, $qsl, $lotw, $eqsl); break; } return $result; } - public function get_timeline_dxcc($band, $mode, $location_list) { + public function get_timeline_dxcc($band, $mode, $location_list, $qsl, $lotw, $eqsl) { $sql = "select min(date(COL_TIME_ON)) date, prefix, col_country, end, adif from " .$this->config->item('table_name'). " thcv join dxcc_entities on thcv.col_dxcc = dxcc_entities.adif @@ -44,6 +44,8 @@ class Timeline_model extends CI_Model $sql .= " and col_mode ='" . $mode . "'"; } + $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl); + $sql .= " group by col_dxcc, col_country order by date desc"; @@ -52,7 +54,7 @@ class Timeline_model extends CI_Model return $query->result(); } - public function get_timeline_was($band, $mode, $location_list) { + public function get_timeline_was($band, $mode, $location_list, $qsl, $lotw, $eqsl) { $sql = "select min(date(COL_TIME_ON)) date, col_state from " .$this->config->item('table_name'). " thcv where station_id in (" . $location_list . ")"; @@ -74,6 +76,8 @@ class Timeline_model extends CI_Model $sql .= " and COL_DXCC in ('291', '6', '110')"; $sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')"; + $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl); + $sql .= " group by col_state order by date desc"; @@ -82,7 +86,7 @@ class Timeline_model extends CI_Model return $query->result(); } - public function get_timeline_iota($band, $mode, $location_list) { + public function get_timeline_iota($band, $mode, $location_list, $qsl, $lotw, $eqsl) { $sql = "select min(date(COL_TIME_ON)) date, col_iota, name, prefix from " .$this->config->item('table_name'). " thcv join iota on thcv.col_iota = iota.tag @@ -102,6 +106,8 @@ class Timeline_model extends CI_Model $sql .= " and col_mode ='" . $mode . "'"; } + $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl); + $sql .= " and col_iota <> '' group by col_iota, name, prefix order by date desc"; @@ -110,7 +116,7 @@ class Timeline_model extends CI_Model return $query->result(); } - public function get_timeline_waz($band, $mode, $location_list) { + public function get_timeline_waz($band, $mode, $location_list, $qsl, $lotw, $eqsl) { $sql = "select min(date(COL_TIME_ON)) date, col_cqz from " .$this->config->item('table_name'). " thcv where station_id in (" . $location_list . ")"; @@ -129,6 +135,8 @@ class Timeline_model extends CI_Model $sql .= " and col_mode ='" . $mode . "'"; } + $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl); + $sql .= " and col_cqz <> '' group by col_cqz order by date desc"; @@ -136,5 +144,39 @@ class Timeline_model extends CI_Model return $query->result(); } + + + // Adds confirmation to query + function addQslToQuery($qsl, $lotw, $eqsl) { + $sql = ''; + if ($lotw == 1 and $qsl == 0 and $eqsl == 0) { + $sql .= " and col_lotw_qsl_rcvd = 'Y'"; + } + + if ($qsl == 1 and $lotw == 0 and $eqsl == 0) { + $sql .= " and col_qsl_rcvd = 'Y'"; + } + + if ($eqsl == 1 and $lotw == 0 and $qsl == 0) { + $sql .= " and col_eqsl_qsl_rcvd = 'Y'"; + } + + if ($lotw == 1 and $qsl == 1 and $eqsl == 0) { + $sql .= " and (col_lotw_qsl_rcvd = 'Y' or col_qsl_rcvd = 'Y')"; + } + + if ($qsl == 1 and $lotw == 0 and $eqsl == 1) { + $sql .= " and (col_qsl_rcvd = 'Y' or col_eqsl_qsl_rcvd = 'Y')"; + } + + if ($eqsl == 1 and $lotw == 1 and $qsl == 0) { + $sql .= " and (col_eqsl_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; + } + + if ($qsl == 1 && $lotw == 1 && $eqsl == 1) { + $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y' or col_eqsl_qsl_rcvd = 'Y')"; + } + return $sql; + } }