From 1a52776f3e3d79f81f7043a77941421d936e6777 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 13 Feb 2025 14:44:12 +0000 Subject: [PATCH] Prevent mysql error if no date is given at edit --- application/controllers/Qso.php | 17 +++++++++++------ application/models/Logbook_model.php | 11 +++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index d3af14190..d22c1acad 100644 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -294,13 +294,18 @@ class QSO extends CI_Controller { } function qso_save_ajax() { - $this->load->model('logbook_model'); - $this->load->model('user_model'); - if(!$this->user_model->authorize(2)) { - $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); - } + $this->load->library('form_validation'); + $this->load->model('logbook_model'); + $this->load->model('user_model'); + if(!$this->user_model->authorize(2)) { + $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); + } + $this->form_validation->set_rules('time_on', 'Start Date', 'required'); + $this->form_validation->set_rules('time_off', 'End Date', 'required'); - $this->logbook_model->edit(); + if ($this->form_validation->run()) { + $this->logbook_model->edit(); + } } function qsl_rcvd($id, $method) { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index c7c56e98f..2031ced41 100644 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1424,9 +1424,16 @@ class Logbook_model extends CI_Model { $distance = null; } + $time_on=$this->input->post('time_on'); + $time_off=$this->input->post('time_off'); + + if (($time_off ?? '') == '') { + $time_off=$time_on; + } + $data = array( - 'COL_TIME_ON' => $this->input->post('time_on'), - 'COL_TIME_OFF' => $this->input->post('time_off'), + 'COL_TIME_ON' => $time_on, + 'COL_TIME_OFF' => $time_off, 'COL_CALL' => strtoupper(trim($this->input->post('callsign'))), 'COL_BAND' => $this->input->post('band'), 'COL_BAND_RX' => $this->input->post('band_rx'),