Cloudlog/application/controllers/Qso.php

356 lines
11 KiB
PHP
Raw Normal View History

2011-04-25 15:24:01 +00:00
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
TODO
- Update Edit
- Store Radio Information
- Upload to clublog (request api key)
*/
2011-04-25 15:24:01 +00:00
class QSO extends CI_Controller {
function __construct()
{
parent::__construct();
$this->lang->load('qso');
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
2011-04-25 15:24:01 +00:00
public function index()
{
$this->load->model('cat');
$this->load->model('stations');
2011-07-22 00:08:47 +00:00
$this->load->model('logbook_model');
2011-08-19 16:12:13 +00:00
$this->load->model('user_model');
$this->load->model('modes');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
2011-07-22 00:08:47 +00:00
$data['active_station_profile'] = $this->stations->find_active();
$data['notice'] = false;
$data['stations'] = $this->stations->all();
$data['radios'] = $this->cat->radios();
$data['query'] = $this->logbook_model->last_custom('5');
$data['dxcc'] = $this->logbook_model->fetchDxcc();
$data['iota'] = $this->logbook_model->fetchIota();
$data['modes'] = $this->modes->active();
$this->load->library('form_validation');
$this->form_validation->set_rules('start_date', 'Date', 'required');
$this->form_validation->set_rules('start_time', 'Time', 'required');
$this->form_validation->set_rules('callsign', 'Callsign', 'required');
if ($this->form_validation->run() == FALSE)
{
2011-11-04 17:32:03 +00:00
$data['page_title'] = "Add QSO";
$this->load->view('interface_assets/header', $data);
2011-11-04 17:32:03 +00:00
$this->load->view('qso/index');
$this->load->view('interface_assets/footer');
}
else
{
2011-07-22 00:08:47 +00:00
// Add QSO
2016-02-12 16:31:29 +00:00
// $this->logbook_model->add();
//change to create_qso function as add and create_qso duplicate functionality
$this->logbook_model->create_qso();
2011-07-22 00:08:47 +00:00
// Store Basic QSO Info for reuse
// Put data in an array first, then call set_userdata once.
// This solves the problem of CI dumping out the session
// cookie each time set_userdata is called.
// For more info, see http://bizhole.com/codeigniter-nginx-error-502-bad-gateway/
// $qso_data = [
// 18-Jan-2016 - make php v5.3 friendly!
$qso_data = array(
'start_date' => $this->input->post('start_date'),
'start_time' => $this->input->post('start_time'),
'time_stamp' => time(),
'band' => $this->input->post('band'),
'band_rx' => $this->input->post('band_rx'),
'freq' => $this->input->post('freq_display'),
'freq_rx' => $this->input->post('freq_display_rx'),
'mode' => $this->input->post('mode'),
'sat_name' => $this->input->post('sat_name'),
'sat_mode' => $this->input->post('sat_mode'),
'prop_mode' => $this->input->post('prop_mode'),
'radio' => $this->input->post('radio'),
'station_profile_id' => $this->input->post('station_profile'),
'transmit_power' => $this->input->post('transmit_power')
);
// ];
setcookie("radio", $qso_data['radio'], time()+3600*24*99);
setcookie("station_profile_id", $qso_data['station_profile_id'], time()+3600*24*99);
$this->session->set_userdata($qso_data);
// If SAT name is set make it session set to sat
if($this->input->post('sat_name')) {
$this->session->set_userdata('prop_mode', 'SAT');
}
// Get last 5 qsos
$data['query'] = $this->logbook_model->last_custom('5');
2011-07-22 00:08:47 +00:00
// Set Any Notice Messages
$data['notice'] = "QSO Added";
2011-07-22 00:08:47 +00:00
// Load view to create another contact
2011-11-04 17:32:03 +00:00
$data['page_title'] = "Add QSO";
$this->load->view('interface_assets/header', $data);
2011-11-04 17:32:03 +00:00
$this->load->view('qso/index');
$this->load->view('interface_assets/footer');
}
}
/*
* This is used for contest-logging and the ajax-call
*/
public function saveqso() {
$this->load->model('logbook_model');
$this->logbook_model->create_qso();
}
function edit() {
2011-07-22 00:08:47 +00:00
$this->load->model('logbook_model');
2011-08-19 16:12:13 +00:00
$this->load->model('user_model');
2020-05-17 13:08:21 +00:00
$this->load->model('modes');
2011-08-19 16:12:13 +00:00
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
2011-07-22 00:08:47 +00:00
$query = $this->logbook_model->qso_info($this->uri->segment(3));
$this->load->library('form_validation');
$this->form_validation->set_rules('time_on', 'Start Date', 'required');
$this->form_validation->set_rules('time_off', 'End Date', 'required');
$this->form_validation->set_rules('callsign', 'Callsign', 'required');
$data['qso'] = $query->row();
$data['dxcc'] = $this->logbook_model->fetchDxcc();
$data['iota'] = $this->logbook_model->fetchIota();
2020-05-17 13:08:21 +00:00
$data['modes'] = $this->modes->all();
2011-07-22 00:08:47 +00:00
if ($this->form_validation->run() == FALSE)
{
$this->load->view('qso/edit', $data);
}
else
{
2011-07-22 00:08:47 +00:00
$this->logbook_model->edit();
$this->session->set_flashdata('notice', 'Record Updated');
$this->load->view('qso/edit_done');
}
}
2020-08-24 18:16:06 +00:00
function edit_ajax() {
$this->load->model('logbook_model');
$this->load->model('user_model');
$this->load->model('modes');
2020-08-24 18:16:06 +00:00
$this->load->library('form_validation');
if(!$this->user_model->authorize(2)) {
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard');
}
$id = str_replace('"', "", $this->input->post("id"));
$query = $this->logbook_model->qso_info($id);
2020-08-24 18:16:06 +00:00
$data['qso'] = $query->row();
$data['dxcc'] = $this->logbook_model->fetchDxcc();
$data['iota'] = $this->logbook_model->fetchIota();
$data['modes'] = $this->modes->all();
2020-08-24 18:16:06 +00:00
$this->load->view('qso/edit_ajax', $data);
}
function qso_save_ajax() {
$this->load->model('logbook_model');
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) {
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard');
2020-08-24 18:16:06 +00:00
}
$this->logbook_model->edit();
2020-08-24 18:16:06 +00:00
}
function qsl_rcvd($id, $method) {
2019-06-15 18:20:20 +00:00
$this->load->model('logbook_model');
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
// Update Logbook to Mark Paper Card Received
$this->logbook_model->paperqsl_update($id, $method);
$this->session->set_flashdata('notice', 'QSL Card: Marked as Received');
redirect('logbook');
2019-06-15 18:20:20 +00:00
}
2020-08-24 18:16:06 +00:00
function qsl_rcvd_ajax() {
$id = str_replace('"', "", $this->input->post("id"));
$method = str_replace('"', "", $this->input->post("method"));
$this->load->model('logbook_model');
$this->load->model('user_model');
header('Content-Type: application/json');
if(!$this->user_model->authorize(2)) {
echo json_encode(array('message' => 'Error'));
}
else {
// Update Logbook to Mark Paper Card Received
$this->logbook_model->paperqsl_update($id, $method);
echo json_encode(array('message' => 'OK'));
}
}
2019-06-15 18:20:20 +00:00
/* Delete QSO */
function delete($id) {
$this->load->model('logbook_model');
$this->logbook_model->delete($id);
$this->session->set_flashdata('notice', 'QSO Deleted Successfully');
2011-10-18 22:06:34 +00:00
$data['message_title'] = "Deleted";
$data['message_contents'] = "QSO Deleted Successfully";
$this->load->view('messages/message', $data);
// If deletes from /logbook dropdown redirect
if (strpos($_SERVER['HTTP_REFERER'], '/logbook') !== false) {
redirect($_SERVER['HTTP_REFERER']);
}
2011-04-25 15:24:01 +00:00
}
2020-08-24 18:16:06 +00:00
/* Delete QSO */
function delete_ajax() {
$id = str_replace('"', "", $this->input->post("id"));
$this->load->model('logbook_model');
$this->logbook_model->delete($id);
header('Content-Type: application/json');
echo json_encode(array('message' => 'OK'));
return;
}
function band_to_freq($band, $mode) {
$this->load->library('frequency');
echo $this->frequency->convent_band($band, $mode);
}
/*
* Function is used for autocompletion of SOTA in the QSO entry form
*/
public function get_sota() {
$json = [];
if(!empty($this->input->get("query"))) {
$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
$sota = strtoupper($query);
$file = 'assets/json/sota.txt';
if (is_readable($file)) {
$lines = file($file, FILE_IGNORE_NEW_LINES);
$input = preg_quote($sota, '~');
$reg = '~^'. $input .'(.*)$~';
$result = preg_grep($reg, $lines);
$json = [];
$i = 0;
foreach ($result as &$value) {
// Limit to 100 as to not slowdown browser too much
if (count($json) <= 100) {
$json[] = ["name"=>$value];
}
}
}
}
header('Content-Type: application/json');
echo json_encode($json);
}
/*
* Function is used for autocompletion of DOK in the QSO entry form
*/
public function get_dok() {
$json = [];
if(!empty($this->input->get("query"))) {
$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
$sota = strtoupper($query);
$file = 'assets/json/dok.txt';
if (is_readable($file)) {
$lines = file($file, FILE_IGNORE_NEW_LINES);
$input = preg_quote($sota, '~');
$reg = '~^'. $input .'(.*)$~';
$result = preg_grep($reg, $lines);
$json = [];
$i = 0;
foreach ($result as &$value) {
// Limit to 100 as to not slowdown browser too much
if (count($json) <= 100) {
$json[] = ["name"=>$value];
}
}
}
}
header('Content-Type: application/json');
echo json_encode($json);
}
/*
* Function is used for autocompletion of Counties in the station profile form
*/
public function get_county() {
$json = [];
if(!empty($this->input->get("query"))) {
//$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
$county = $this->input->get("state");
$cleanedcounty = explode('(', $county);
$cleanedcounty = trim($cleanedcounty[0]);
$file = 'assets/json/US_counties.csv';
if (is_readable($file)) {
$lines = file($file, FILE_IGNORE_NEW_LINES);
$input = preg_quote($cleanedcounty, '~');
$reg = '~^'. $input .'(.*)$~';
$result = preg_grep($reg, $lines);
$json = [];
$i = 0;
foreach ($result as &$value) {
$county = explode(',', $value);
// Limit to 100 as to not slowdown browser too much
if (count($json) <= 100) {
$json[] = ["name"=>$county[1]];
}
}
}
}
header('Content-Type: application/json');
echo json_encode($json);
}
2011-08-19 16:12:13 +00:00
}