diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index a4f6766e4..e3e7dad7a 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -617,6 +617,12 @@ class Logbook extends CI_Controller { $data['query'] = $this->logbook_model->get_qso($id); $data['dxccFlag'] = $this->dxccflag->get($data['query']->result()[0]->COL_DXCC); + // Check for note for this callsign and current user + $callsign = $data['query']->result()[0]->COL_CALL; + $user_id = $this->session->userdata('user_id'); + $this->load->model('note'); + $data['contacts_note_id'] = $this->note->get_note_id_by_category($user_id, 'Contacts', $callsign); + if ($this->session->userdata('user_measurement_base') == NULL) { $data['measurement_base'] = $this->config->item('measurement_base'); } diff --git a/application/controllers/Notes.php b/application/controllers/Notes.php index 8e8e5f68b..997b14b52 100644 --- a/application/controllers/Notes.php +++ b/application/controllers/Notes.php @@ -253,31 +253,17 @@ class Notes extends CI_Controller { $category = $this->input->get('category', TRUE); $title = $this->input->get('title', TRUE); $id = $this->input->get('id', TRUE); // Optional, for edit - $check_title = $title; - if ($category === 'Contacts') { - $this->load->library('callbook'); - $check_title = strtoupper($this->callbook->get_plaincall($title)); - } - $where = [ - 'cat' => $category, - 'user_id' => $user_id, - 'title' => $check_title - ]; - $query = $this->db->get_where('notes', $where); $exists = false; $note_id = null; - if ($id) { - foreach ($query->result() as $note) { - if ($note->id != $id) { - $exists = true; - $note_id = $note->id; - break; - } - } - } else { - if ($query->num_rows() > 0) { + $this->load->model('note'); + $note_id_found = $this->note->get_note_id_by_category($user_id, $category, $title); + if ($note_id_found) { + // If editing, ignore current note + if ($id && $note_id_found == $id) { + $exists = false; + } else { $exists = true; - $note_id = $query->row()->id; + $note_id = $note_id_found; } } $response = ['exists' => $exists]; diff --git a/application/models/Note.php b/application/models/Note.php index ba1ef8438..c2b4d1d29 100644 --- a/application/models/Note.php +++ b/application/models/Note.php @@ -162,6 +162,24 @@ class Note extends CI_Model { return $result; } + // Return note ID for given category and title (callsign for Contacts), else false + public function get_note_id_by_category($user_id, $category, $title) { + $check_title = $title; + if ($category === 'Contacts') { + $this->load->library('callbook'); // Used for callsign parsing + $check_title = strtoupper($this->callbook->get_plaincall($title)); + } + $query = $this->db->get_where('notes', [ + 'cat' => $category, + 'user_id' => $user_id, + 'title' => $check_title + ]); + if ($query->num_rows() > 0) { + return $query->row()->id; + } + return false; + } + // Search notes with pagination and sorting for the logged-in user public function search_paginated($criteria = [], $page = 1, $per_page = 25, $sort_col = null, $sort_dir = null) { $user_id = $this->session->userdata('user_id'); diff --git a/application/views/view_log/qso.php b/application/views/view_log/qso.php index 3090954c0..9615b4f05 100644 --- a/application/views/view_log/qso.php +++ b/application/views/view_log/qso.php @@ -81,7 +81,13 @@ - COL_CALL)); ?> Lookup <?php echo strtoupper($row->COL_CALL); ?> on QRZ.com Lookup <?php echo strtoupper($row->COL_CALL); ?> on HamQTH Lookup <?php echo strtoupper($row->COL_CALL); ?> on eQSL.cc Clublog Log Search + COL_CALL)); ?> Lookup <?php echo strtoupper($row->COL_CALL); ?> on QRZ.com Lookup <?php echo strtoupper($row->COL_CALL); ?> on HamQTH Lookup <?php echo strtoupper($row->COL_CALL); ?> on eQSL.cc Clublog Log Search + + " style="margin-left:2px;vertical-align:middle;"> + + + +