diff --git a/application/controllers/contest.php b/application/controllers/contest.php index 618a6b9f..1026cf93 100644 --- a/application/controllers/contest.php +++ b/application/controllers/contest.php @@ -6,29 +6,83 @@ class Contest extends CI_Controller { // Displays available contests public function index() { + // Load database items $this->load->model('contests'); $data['contests'] = $this->contests->list_contests(); + // Load views $this->load->view('layout/header'); $this->load->view('contest/main', $data); $this->load->view('layout/footer'); } + /* + Displays contest logging view based on the ID provided, allowing users to log in contest mode giving them serial numbers and scoring information. + */ public function view($id) { + + // Load database information $this->load->model('contests'); + $data['info'] = $this->contests->information($id); + $data['log'] = $this->contests->contest_log_view($data['info']->start, $data['info']->end, $data['info']); + $data['summary'] = $this->contests->contest_summary_bands($data['info']->start, $data['info']->end, $data['info']); + + + + // Run validation checks on QSO submission + $this->load->library('form_validation'); + + $this->form_validation->set_rules('start_time', 'Time', 'required'); + $this->form_validation->set_rules('callsign', 'Callsign', 'required'); + $this->form_validation->set_rules('sent_serial', 'Sent Serial Number', 'required'); + $this->form_validation->set_rules('rst_recv', 'Recevied RST', 'required'); + $this->form_validation->set_rules('recv_serial', 'Received Serial Number', 'required'); + + if($data['info']->qra == "Y") { + $this->form_validation->set_rules('locator', 'Received QRA', 'required'); + } + + // Load Views + if ($this->form_validation->run() == FALSE) + { + $this->load->view('layout/header'); + $this->load->view('contest/log', $data); + $this->load->view('layout/footer'); + } else { + $contest_id = $id; + // Add QSO + $this->contests->add($contest_id); + + // Store Basic QSO Info for reuse + $this->session->set_userdata('band', $this->input->post('band')); + $this->session->set_userdata('freq', $this->input->post('freq')); + $this->session->set_userdata('mode', $this->input->post('mode')); + + $data['info'] = $this->contests->information($id); + $data['log'] = $this->contests->contest_log_view($data['info']->start, $data['info']->end, $data['info']); - $this->load->view('layout/header'); - $this->load->view('contest/log', $data); - $this->load->view('layout/footer'); + // Set Any Notice Messages + $data['notice'] = "QSO Added"; + + $this->load->view('layout/header'); + $this->load->view('contest/log', $data); + $this->load->view('layout/footer'); + } } - // Create a contest + /* + Create a contest, these are linked to templates for scoring information. contests are per entry like a weekly RSGB Club contest etc. + */ public function create() { + + // Load database items $this->load->model('contests'); $data['templates'] = $this->contests->list_templates(); $this->load->helper(array('form', 'url')); + + // Run Validation $this->load->library('form_validation'); $this->form_validation->set_rules('contest_name', 'Contest Name', 'required'); @@ -45,6 +99,9 @@ class Contest extends CI_Controller { } } + /* + Create a template, Contest Templates are sets of parameters for a series or single contest selecting items like scoring, bands and modes available. + */ public function add_template() { $this->load->helper(array('form', 'url')); diff --git a/application/models/contests.php b/application/models/contests.php index cdf36424..4d2ac9ae 100644 --- a/application/models/contests.php +++ b/application/models/contests.php @@ -65,6 +65,99 @@ class Contests extends CI_Model { return $this->db->get('contests'); } + function contest_summary_bands($start_date, $end_date, $info) { + $query = $this->db->query('SELECT DISTINCT (COL_BAND) AS band, count( * ) AS count, COL_TIME_ON FROM '.$this->config->item('table_name').' WHERE COL_TIME_ON >= \''.$start_date.'\' AND COL_TIME_ON <= \''.$end_date.'\' GROUP BY band ORDER BY count DESC'); + + return $query; + } + + function contest_log_view($start_date, $end_date, $info) { + $this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME,COL_STX_STRING,COL_SRX_STRING, COL_COUNTRY, COL_PRIMARY_KEY'); + $this->db->where('COL_TIME_ON >=', $start_date); + $this->db->where('COL_TIME_ON <=', $end_date); + if($info->band_160 == "Y") { + $this->db->where('COL_BAND', '160m'); + } + if($info->band_80 == "Y") { + $this->db->where('COL_BAND', '80m'); + } + if($info->band_40 == "Y") { + $this->db->where('COL_BAND', '40m'); + } + if($info->band_20 == "Y") { + $this->db->where('COL_BAND', '20m'); + } + if($info->band_15 == "Y") { + $this->db->where('COL_BAND', '15m'); + } + if($info->band_10 == "Y") { + $this->db->where('COL_BAND', '10m'); + } + if($info->band_6m == "Y") { + $this->db->where('COL_BAND', '6m'); + } + if($info->band_4m == "Y") { + $this->db->where('COL_BAND', '4m'); + } + if($info->band_2m == "Y") { + $this->db->where('COL_BAND', '2m'); + } + if($info->band_70cm == "Y") { + $this->db->where('COL_BAND', '70cm'); + } + if($info->band_23cm == "Y") { + $this->db->where('COL_BAND', '23cm'); + } + if($info->mode_ssb == "Y") { + $this->db->where('COL_MODE', 'SSB'); + } + if($info->mode_cw == "Y") { + $this->db->where('COL_MODE', 'CW'); + } + //$this->db->order_by("COL_PRIMARY_KEY", "asc"); + $this->db->order_by("COL_TIME_ON", "desc"); + $this->db->limit(10); + + return $this->db->get($this->config->item('table_name')); + + } + + function add($contest_id) { + // Join date+time + $datetime = date('Y-m-d') ." ". $this->input->post('start_time'); + + // Create array with QSO Data + $data = array( + 'COL_TIME_ON' => $datetime, + 'COL_TIME_OFF' => $datetime, + 'COL_CALL' => strtoupper($this->input->post('callsign')), + 'COL_BAND' => $this->input->post('band'), + 'COL_FREQ' => $this->input->post('freq'), + 'COL_MODE' => $this->input->post('mode'), + 'COL_RST_RCVD' => $this->input->post('rst_recv'), + 'COL_SRX_STRING' => $this->input->post('recv_serial'), + 'COL_RST_SENT' => $this->input->post('rst_sent'), + 'COL_STX_STRING' => $this->input->post('sent_serial'), + 'COL_GRIDSQUARE' => $this->input->post('locator'), + 'COL_COUNTRY' => $this->input->post('country'), + 'COL_QSLSDATE' => date('Y-m-d'), + 'COL_QSLRDATE' => date('Y-m-d'), + 'COL_QSL_SENT' => 'N', + 'COL_QSL_RCVD' => 'N', + ); + + // Add QSO to database + $this->db->insert($this->config->item('table_name'), $data); + + // Update contest file stored serial number. + $data = array( + 'serial_num' => $this->input->post('sent_serial'), + ); + + $this->db->where('id', $contest_id); + $this->db->update('contests', $data); + } + } ?> \ No newline at end of file diff --git a/application/views/contest/log.php b/application/views/contest/log.php index ad6f62f0..f310d6b4 100644 --- a/application/views/contest/log.php +++ b/application/views/contest/log.php @@ -1,6 +1,316 @@ + + + + + + + + +serial_num + 1; + if($serial_number <= 49) { + $new_serial = "00".$serial_number; + } + + if($serial_number >= 49 && $serial_number <= 100) { + $new_serial = "0".$serial_number; + } + + if($serial_number > 100) { + $new_serial = $serial_number; + } + + ?> + + +
| Date | +Time | +Band | +Call | +Mode | +RST(S) | +Serial | +Recv | +Serial | +COL_TIME_ON); echo date('d/m/y', $timestamp); ?> | +COL_TIME_ON); echo date('H:i', $timestamp); ?> | +COL_BAND; ?> | +COL_PRIMARY_KEY; ?>">COL_CALL); ?> | +COL_MODE; ?> | +COL_RST_SENT; ?> | +COL_STX_STRING; ?> | +COL_RST_RCVD; ?> | +COL_SRX_STRING; ?> | + + + + +