kopia lustrzana https://github.com/magicbug/Cloudlog
Merge pull request #2061 from AndreasK79/contest_session_database
[Contest logging] Moved contest session from local storage to databasepull/2064/head
commit
813bbd5a89
|
@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
|
|||
| be upgraded / downgraded to.
|
||||
|
|
||||
*/
|
||||
$config['migration_version'] = 116;
|
||||
$config['migration_version'] = 117;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -42,17 +42,39 @@ class Contesting extends CI_Controller {
|
|||
}
|
||||
|
||||
public function getSessionQsos() {
|
||||
//load model
|
||||
$this->load->model('Contesting_model');
|
||||
|
||||
$qso = $this->input->post('qso');
|
||||
|
||||
// get QSOs to fill the table
|
||||
$data = $this->Contesting_model->getSessionQsos($qso);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($this->Contesting_model->getSessionQsos($qso));
|
||||
}
|
||||
|
||||
public function getSession() {
|
||||
$this->load->model('Contesting_model');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($this->Contesting_model->getSession());
|
||||
}
|
||||
|
||||
public function deleteSession() {
|
||||
$this->load->model('Contesting_model');
|
||||
|
||||
$qso = $this->input->post('qso');
|
||||
|
||||
$data = $this->Contesting_model->deleteSession($qso);
|
||||
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
public function setSession() {
|
||||
$this->load->model('Contesting_model');
|
||||
|
||||
$this->Contesting_model->setSession();
|
||||
|
||||
return json_encode("ok");
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$this->load->model('Contesting_model');
|
||||
$this->load->library('form_validation');
|
||||
|
@ -161,10 +183,10 @@ class Contesting extends CI_Controller {
|
|||
$band = $this->input->post('band');
|
||||
$mode = $this->input->post('mode');
|
||||
$contest = $this->input->post('contest');
|
||||
$qso = $this->input->post('qso');
|
||||
|
||||
$this->load->model('Contesting_model');
|
||||
$result = $this->Contesting_model->checkIfWorkedBefore($call, $band, $mode, $contest, $qso);
|
||||
|
||||
$result = $this->Contesting_model->checkIfWorkedBefore($call, $band, $mode, $contest);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
if ($result->num_rows()) {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Migration_add_contest_session_table extends CI_Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
if (!$this->db->table_exists('contest_session')) {
|
||||
$this->dbforge->add_field(array(
|
||||
'id' => array(
|
||||
'type' => 'INT',
|
||||
'constraint' => 20,
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => TRUE,
|
||||
'unique' => TRUE
|
||||
),
|
||||
'contestid' => array(
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 100,
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
'exchangetype' => array(
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 20,
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
'exchangesent' => array(
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 20,
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
'serialsent' => array(
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 20,
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
'copytodok' => array(
|
||||
'type' => 'bigint',
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
'qso' => array(
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 100,
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
'station_id' => array(
|
||||
'type' => 'bigint',
|
||||
'unsigned' => TRUE,
|
||||
'auto_increment' => FALSE
|
||||
),
|
||||
));
|
||||
|
||||
$this->dbforge->add_key('id', TRUE);
|
||||
|
||||
$this->dbforge->create_table('contest_session');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->dbforge->drop_table('contest_session');
|
||||
}
|
||||
}
|
|
@ -26,8 +26,78 @@ class Contesting_model extends CI_Model {
|
|||
" ORDER BY COL_PRIMARY_KEY ASC";
|
||||
|
||||
$data = $this->db->query($sql);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data->result());
|
||||
return $data->result();
|
||||
}
|
||||
|
||||
function getSession() {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$sql = "SELECT * from contest_session where station_id = " . $station_id;
|
||||
|
||||
$data = $this->db->query($sql);
|
||||
return $data->row();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function deleteSession() {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$sql = "delete from contest_session where station_id = " . $station_id;
|
||||
|
||||
$this->db->query($sql);
|
||||
return;
|
||||
}
|
||||
|
||||
function setSession() {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$qso = "";
|
||||
|
||||
if ($this->input->post('callsign')) {
|
||||
$qso = xss_clean($this->input->post('start_date', true)) . ' ' . xss_clean($this->input->post('start_time', true)) . ',' . xss_clean($this->input->post('callsign', true)) . ',' . xss_clean($this->input->post('contestname', true));
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'contestid' => xss_clean($this->input->post('contestname', true)),
|
||||
'exchangetype' => xss_clean($this->input->post('exchangetype', true)),
|
||||
'exchangesent' => xss_clean($this->input->post('exch_sent', true)),
|
||||
'serialsent' => xss_clean($this->input->post('exch_serial_s', true)),
|
||||
'copytodok' => $this->input->post('copyexchangetodok', true) == "" ? 0 : xss_clean($this->input->post('copyexchangetodok', true)),
|
||||
'qso' => $qso,
|
||||
'station_id' => $station_id,
|
||||
);
|
||||
|
||||
$sql = "SELECT * from contest_session where station_id = " . $station_id;
|
||||
|
||||
$querydata = $this->db->query($sql);
|
||||
|
||||
if ($querydata->num_rows() == 0) {
|
||||
$this->db->insert('contest_session', $data);
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $querydata->row();
|
||||
|
||||
if ($result->qso != "") {
|
||||
$data['qso'] = $result->qso;
|
||||
}
|
||||
|
||||
$this->updateSession($data, $station_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function updateSession($data, $station_id) {
|
||||
$this->db->where('station_id', $station_id);
|
||||
|
||||
$this->db->update('contest_session', $data);
|
||||
}
|
||||
|
||||
function getActivecontests() {
|
||||
|
@ -137,12 +207,15 @@ class Contesting_model extends CI_Model {
|
|||
return true;
|
||||
}
|
||||
|
||||
function checkIfWorkedBefore($call, $band, $mode, $contest, $qso) {
|
||||
function checkIfWorkedBefore($call, $band, $mode, $contest) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('Stations');
|
||||
$station_id = $CI->Stations->find_active();
|
||||
|
||||
$qsoarray = explode(',', $qso);
|
||||
$contest_session = $this->getSession();
|
||||
|
||||
if ($contest_session) {
|
||||
$qsoarray = explode(',', $contest_session->qso);
|
||||
|
||||
$date = DateTime::createFromFormat('d-m-Y H:i:s', $qsoarray[0]);
|
||||
$date = $date->format('Y-m-d H:i:s');
|
||||
|
@ -160,4 +233,6 @@ class Contesting_model extends CI_Model {
|
|||
|
||||
return $query;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
$("#callsign").focus();
|
||||
|
||||
$(document).ready(function () {
|
||||
restoreContestSession();
|
||||
getSession().done(restoreContestSession);
|
||||
setRst($("#mode").val());
|
||||
});
|
||||
|
||||
// This erases the contest logging session which is stored in localStorage
|
||||
// Resets the logging form and deletes session from database
|
||||
function reset_contest_session() {
|
||||
$('#name').val("");
|
||||
$('.callsign-suggestions').text("");
|
||||
|
@ -18,7 +18,6 @@ function reset_contest_session() {
|
|||
$('#exch_sent').val("");
|
||||
$('#exch_rcvd').val("");
|
||||
$("#exch_gridsquare_r").val("");
|
||||
$("#exch_gridsquare_s").val("");
|
||||
|
||||
$("#callsign").focus();
|
||||
setRst($("#mode").val());
|
||||
|
@ -28,28 +27,42 @@ function reset_contest_session() {
|
|||
$(".contest_qso_table_contents").empty();
|
||||
$('#copyexchangetodok').prop('checked', false);
|
||||
|
||||
localStorage.removeItem("contestid");
|
||||
localStorage.removeItem("exchangetype");
|
||||
localStorage.removeItem("qso");
|
||||
localStorage.removeItem("exchangereceived");
|
||||
localStorage.removeItem("exchangesent");
|
||||
localStorage.removeItem("serialreceived");
|
||||
localStorage.removeItem("serialsent");
|
||||
localStorage.removeItem("gridsquarereceived");
|
||||
localStorage.removeItem("gridsquaresent");
|
||||
localStorage.removeItem("copytodok");
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/contesting/deleteSession',
|
||||
type: 'post',
|
||||
success: function (data) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Storing the contestid in contest session
|
||||
$('#contestname').change(function () {
|
||||
localStorage.setItem("contestid", $("#contestname").val());
|
||||
var formdata = new FormData(document.getElementById("qso_input"));
|
||||
setSession(formdata);
|
||||
});
|
||||
|
||||
// Storing the exchange type in contest session
|
||||
$('#exchangetype').change(function () {
|
||||
localStorage.setItem("exchangetype", $('#exchangetype').val());
|
||||
var exchangetype = $("#exchangetype").val();
|
||||
var formdata = new FormData(document.getElementById("qso_input"));
|
||||
setSession(formdata);
|
||||
setExchangetype(exchangetype);
|
||||
});
|
||||
|
||||
function setSession(formdata) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/contesting/setSession',
|
||||
type: 'post',
|
||||
data: formdata,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (data) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// realtime clock
|
||||
if ( ! manual ) {
|
||||
$(function ($) {
|
||||
|
@ -212,16 +225,17 @@ $("#callsign").keyup(function () {
|
|||
});
|
||||
|
||||
function checkIfWorkedBefore() {
|
||||
var call = $("#callsign").val();
|
||||
if (call.length >= 3) {
|
||||
$('#callsign_info').text("");
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/contesting/checkIfWorkedBefore',
|
||||
type: 'post',
|
||||
data: {
|
||||
'call': $("#callsign").val(),
|
||||
'call': call,
|
||||
'mode': $("#mode").val(),
|
||||
'band': $("#band").val(),
|
||||
'contest': $("#contestname").val(),
|
||||
'qso': localStorage.getItem("qso")
|
||||
'contest': $("#contestname").val()
|
||||
},
|
||||
success: function (result) {
|
||||
if (result.message == 'Worked before') {
|
||||
|
@ -229,6 +243,7 @@ function checkIfWorkedBefore() {
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function reset_log_fields() {
|
||||
|
@ -295,12 +310,16 @@ $('#band').change(function () {
|
|||
checkIfWorkedBefore();
|
||||
});
|
||||
|
||||
$('#exchangetype').change(function () {
|
||||
var exchangetype = $("#exchangetype").val();
|
||||
setExchangetype(exchangetype);
|
||||
});
|
||||
function setSerial(data) {
|
||||
var serialsent = 1;
|
||||
if (data.serialsent != "") {
|
||||
serialsent = parseInt(data.serialsent) + 1;
|
||||
}
|
||||
$("#exch_serial_s").val(serialsent);
|
||||
}
|
||||
|
||||
function setExchangetype(exchangetype) {
|
||||
getSession().done(setSerial);
|
||||
// Perhaps a better approach is to hide everything, then just enable the things you need
|
||||
$(".exchanger").hide();
|
||||
$(".exchanges").hide();
|
||||
|
@ -310,29 +329,21 @@ function setExchangetype(exchangetype) {
|
|||
$(".gridsquares").hide();
|
||||
$("#exch_serial_s").val("");
|
||||
|
||||
var serialsent = localStorage.getItem("serialsent");
|
||||
if (serialsent == null) {
|
||||
serialsent = 1;
|
||||
}
|
||||
|
||||
if (exchangetype == 'Exchange') {
|
||||
$(".exchanger").show();
|
||||
$(".exchanges").show();
|
||||
}
|
||||
else if (exchangetype == 'Serial') {
|
||||
$("#exch_serial_s").val(serialsent);
|
||||
$(".serials").show();
|
||||
$(".serialr").show();
|
||||
}
|
||||
else if (exchangetype == 'Serialexchange') {
|
||||
$("#exch_serial_s").val(serialsent);
|
||||
$(".exchanger").show();
|
||||
$(".exchanges").show();
|
||||
$(".serials").show();
|
||||
$(".serialr").show();
|
||||
}
|
||||
else if (exchangetype == 'Serialgridsquare') {
|
||||
$("#exch_serial_s").val(serialsent);
|
||||
$(".serials").show();
|
||||
$(".serialr").show();
|
||||
$(".gridsquarer").show();
|
||||
|
@ -428,10 +439,7 @@ function logQso() {
|
|||
contentType: false,
|
||||
enctype: 'multipart/form-data',
|
||||
success: function (html) {
|
||||
if (localStorage.getItem("qso") == null) {
|
||||
localStorage.setItem("qso", $("#start_date").val() + ' ' + $("#start_time").val() + ',' + $("#callsign").val().toUpperCase() + ',' + $("#contestname").val());
|
||||
}
|
||||
|
||||
setSession(formdata);
|
||||
$('#name').val("");
|
||||
|
||||
$('#callsign').val("");
|
||||
|
@ -445,17 +453,6 @@ function logQso() {
|
|||
}
|
||||
$("#callsign").focus();
|
||||
|
||||
// Store contest session
|
||||
localStorage.setItem("contestid", $("#contestname").val());
|
||||
localStorage.setItem("exchangetype", $("#exchangetype").val());
|
||||
localStorage.setItem("exchangereceived", $("#exch_rcvd").val().toUpperCase());
|
||||
localStorage.setItem("exchangesent", $("#exch_sent").val().toUpperCase());
|
||||
localStorage.setItem("serialreceived", $("#exch_serial_r").val());
|
||||
localStorage.setItem("serialsent", $("#exch_serial_s").val());
|
||||
localStorage.setItem("gridsquarereceived", $("#exch_gridsquare_r").val());
|
||||
localStorage.setItem("gridsquaresent", $("#exch_gridsquare_s").val());
|
||||
localStorage.setItem("copytodok", $('#copyexchangetodok').is(":checked"));
|
||||
|
||||
var qTable = $('.qsotable').DataTable();
|
||||
qTable.search('').draw();
|
||||
}
|
||||
|
@ -463,60 +460,41 @@ function logQso() {
|
|||
}
|
||||
}
|
||||
|
||||
// We are restoring the settings in the contest logging form here
|
||||
function restoreContestSession() {
|
||||
var dokcopy = localStorage.getItem("copytodok");
|
||||
if (dokcopy != null) {
|
||||
function getSession() {
|
||||
return $.ajax({
|
||||
url: base_url + 'index.php/contesting/getSession',
|
||||
type: 'post',
|
||||
});
|
||||
}
|
||||
|
||||
function restoreContestSession(data) {
|
||||
if (data) {
|
||||
if (data.copytodok == "1") {
|
||||
$('#copyexchangetodok').prop('checked', true);
|
||||
}
|
||||
|
||||
var contestname = localStorage.getItem("contestid");
|
||||
if (contestname != null) {
|
||||
$("#contestname").val(contestname);
|
||||
if (data.contestid != "") {
|
||||
$("#contestname").val(data.contestid);
|
||||
}
|
||||
|
||||
var exchangetype = localStorage.getItem("exchangetype");
|
||||
if (exchangetype != null) {
|
||||
$("#exchangetype").val(exchangetype);
|
||||
setExchangetype(exchangetype);
|
||||
if (data.exchangetype != "") {
|
||||
$("#exchangetype").val(data.exchangetype);
|
||||
setExchangetype(data.exchangetype);
|
||||
}
|
||||
|
||||
var exchangereceived = localStorage.getItem("exchangereceived");
|
||||
if (exchangereceived != null) {
|
||||
$("#exch_rcvd").val(exchangereceived);
|
||||
if (data.exchangesent != "") {
|
||||
$("#exch_sent").val(data.exchangesent);
|
||||
}
|
||||
|
||||
var exchangesent = localStorage.getItem("exchangesent");
|
||||
if (exchangesent != null) {
|
||||
$("#exch_sent").val(exchangesent);
|
||||
if (data.serialsent != "") {
|
||||
$("#exch_serial_s").val(data.serialsent);
|
||||
}
|
||||
|
||||
var serialreceived = localStorage.getItem("serialreceived");
|
||||
if (serialreceived != null) {
|
||||
$("#exch_serial_r").val(serialreceived);
|
||||
}
|
||||
|
||||
var serialsent = localStorage.getItem("serialsent");
|
||||
if (serialsent != null) {
|
||||
$("#exch_serial_s").val(serialsent);
|
||||
}
|
||||
|
||||
var gridsquarereceived = localStorage.getItem("gridsquarereceived");
|
||||
if (gridsquarereceived != null) {
|
||||
$("#exch_gridsquare_r").val(gridsquarereceived);
|
||||
}
|
||||
|
||||
var gridsquaresent = localStorage.getItem("gridsquaresent");
|
||||
if (gridsquaresent != null) {
|
||||
$("#exch_gridsquare_s").val(gridsquaresent);
|
||||
}
|
||||
|
||||
if (localStorage.getItem("qso") != null) {
|
||||
var qsodata = localStorage.getItem("qso");
|
||||
if (data.qso != "") {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/contesting/getSessionQsos',
|
||||
type: 'post',
|
||||
data: { 'qso': qsodata, },
|
||||
data: { 'qso': data.qso, },
|
||||
success: function (html) {
|
||||
var mode = '';
|
||||
|
||||
|
@ -557,4 +535,5 @@ function restoreContestSession() {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue