From 4d0a9af624ba80bb0c33066f86eda2235f1b4e74 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 15 Oct 2025 14:32:48 +0200 Subject: [PATCH] [Winkey] Added 5 more macros --- application/controllers/Qso.php | 102 +++++++++------- .../views/qso/components/winkeysettings.php | 112 ++++++------------ application/views/qso/index.php | 7 ++ assets/js/winkey.js | 35 ++++++ 4 files changed, 135 insertions(+), 121 deletions(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 1c1216aed..4345ccbf7 100644 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -212,65 +212,79 @@ class QSO extends CI_Controller { } function winkeysettings() { + $this->load->model('user_options_model'); - // Load model Winkey - $this->load->model('winkey'); + $cwmacros = []; + for ($i = 1; $i <= 10; $i++) { + $row = $this->user_options_model + ->get_options('cwmacros', ['option_name' => "macro{$i}"]) + ->row(); - // call settings from model winkey - $data['result'] = $this->winkey->settings($this->session->userdata('user_id'), $this->stations->find_active()); + // Decode JSON stored in option_value + $decoded = json_decode($row->option_value); - $this->load->view('qso/components/winkeysettings', $data); + // Make sure it's an object (in case it's null) + $name = isset($decoded->name) ? $decoded->name : ''; + $macro = isset($decoded->macro) ? $decoded->macro : ''; + + $cwmacros["macro{$i}"] = [ + 'name' => $name, + 'macro' => $macro, + ]; + } + + $this->load->view('qso/components/winkeysettings', $cwmacros); } function cwmacrosave(){ - // Get the data from the form - $function1_name = $this->input->post('function1_name', TRUE); - $function1_macro = $this->input->post('function1_macro', TRUE); + $this->load->model('user_options_model'); + for ($i = 1; $i <= 10; $i++) { + $data = [ + 'name' => $this->input->post("function{$i}_name", TRUE), + 'macro' => $this->input->post("function{$i}_macro", TRUE), + ]; - $function2_name = $this->input->post('function2_name', TRUE); - $function2_macro = $this->input->post('function2_macro', TRUE); - - $function3_name = $this->input->post('function3_name', TRUE); - $function3_macro = $this->input->post('function3_macro', TRUE); - - $function4_name = $this->input->post('function4_name', TRUE); - $function4_macro = $this->input->post('function4_macro', TRUE); - - $function5_name = $this->input->post('function5_name', TRUE); - $function5_macro = $this->input->post('function5_macro', TRUE); - - $data = [ - 'user_id' => $this->session->userdata('user_id'), - 'station_location_id' => $this->stations->find_active(), - 'function1_name' => $function1_name, - 'function1_macro' => $function1_macro, - 'function2_name' => $function2_name, - 'function2_macro' => $function2_macro, - 'function3_name' => $function3_name, - 'function3_macro' => $function3_macro, - 'function4_name' => $function4_name, - 'function4_macro' => $function4_macro, - 'function5_name' => $function5_name, - 'function5_macro' => $function5_macro, - ]; - - // Load model Winkey - $this->load->model('winkey'); - - // save the data - $this->winkey->save($data); + $this->user_options_model->set_option('cwmacros', "macro{$i}", array("macro{$i}" => json_encode($data))); + } echo "Macros Saved, Press Close and lets get sending!"; } function cwmacros_json() { - // Load model Winkey - $this->load->model('winkey'); + $this->load->model('user_options_model'); + $cwmacros = []; + for ($i = 1; $i <= 10; $i++) { + $row = $this->user_options_model + ->get_options('cwmacros', ['option_name' => "macro{$i}"]) + ->row(); + + // Decode JSON stored in option_value + $decoded = json_decode($row->option_value); + + // Make sure it's an object (in case it's null) + $name = isset($decoded->name) ? $decoded->name : ''; + $macro = isset($decoded->macro) ? $decoded->macro : ''; + + $cwmacros["macro{$i}"] = [ + 'name' => $name, + 'macro' => $macro, + ]; + } + + // Build the JSON result structure + $result = []; + $i = 1; + foreach ($cwmacros as $macro) { + $result["function{$i}_name"] = $macro['name']; + $result["function{$i}_macro"] = $macro['macro']; + $i++; + } + + // Output as JSON header('Content-Type: application/json; charset=utf-8'); + echo json_encode($result, JSON_PRETTY_PRINT); - // Call settings_json from model winkey - echo $this->winkey->settings_json($this->session->userdata('user_id'), $this->stations->find_active()); } function edit_ajax() { diff --git a/application/views/qso/components/winkeysettings.php b/application/views/qso/components/winkeysettings.php index 22241c582..9639f9902 100644 --- a/application/views/qso/components/winkeysettings.php +++ b/application/views/qso/components/winkeysettings.php @@ -1,80 +1,38 @@
-
- -
- -
-
- -
- -
- -
-
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
- -
-
- -
- -
- -
-
+ +
+ +
+ +
+ +
+ +
+ +
+
+ + +
+ +
diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 93586d393..e5a8da0e4 100644 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -761,6 +761,13 @@ switch ($date_format) { + +
+ + + + +
diff --git a/assets/js/winkey.js b/assets/js/winkey.js index 7a319beda..990c4c662 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -353,6 +353,16 @@ function getMacros() { function4Macro = data.function4_macro; function5Name = data.function5_name; function5Macro = data.function5_macro; + function6Name = data.function6_name; + function6Macro = data.function6_macro; + function7Name = data.function7_name; + function7Macro = data.function7_macro; + function8Name = data.function8_name; + function8Macro = data.function8_macro; + function9Name = data.function9_name; + function9Macro = data.function9_macro; + function10Name = data.function10_name; + function10Macro = data.function10_macro; const morsekey_func1_Button = document.getElementById('morsekey_func1'); morsekey_func1_Button.textContent = 'F1 (' + function1Name + ')'; @@ -368,6 +378,21 @@ function getMacros() { const morsekey_func5_Button = document.getElementById('morsekey_func5'); morsekey_func5_Button.textContent = 'F5 (' + function5Name + ')'; + + const morsekey_func6_Button = document.getElementById('morsekey_func6'); + morsekey_func6_Button.textContent = 'F6 (' + function6Name + ')'; + + const morsekey_func7_Button = document.getElementById('morsekey_func7'); + morsekey_func7_Button.textContent = 'F7 (' + function7Name + ')'; + + const morsekey_func8_Button = document.getElementById('morsekey_func8'); + morsekey_func8_Button.textContent = 'F8 (' + function8Name + ')'; + + const morsekey_func9_Button = document.getElementById('morsekey_func9'); + morsekey_func9_Button.textContent = 'F9 (' + function9Name + ')'; + + const morsekey_func10_Button = document.getElementById('morsekey_func10'); + morsekey_func10_Button.textContent = 'F10 (' + function10Name + ')'; }); } @@ -425,6 +450,16 @@ function winkey_macro_save() { function4_macro: $('#function4_macro').val(), function5_name: $('#function5_name').val(), function5_macro: $('#function5_macro').val(), + function6_name: $('#function6_name').val(), + function6_macro: $('#function6_macro').val(), + function7_name: $('#function7_name').val(), + function7_macro: $('#function7_macro').val(), + function8_name: $('#function8_name').val(), + function8_macro: $('#function8_macro').val(), + function9_name: $('#function9_name').val(), + function9_macro: $('#function9_macro').val(), + function10_name: $('#function10_name').val(), + function10_macro: $('#function10_macro').val(), }, success: function (html) { BootstrapDialog.alert({