From fdd4a2df8c311eb72bff17ae0a762726673d2406 Mon Sep 17 00:00:00 2001 From: Patrick Burns Date: Tue, 26 Mar 2024 22:08:16 -0500 Subject: [PATCH 1/2] realized my old branch/PR was started off of main and not dev, got a new one up now --- application/controllers/Logbook.php | 2 + application/controllers/Sstv.php | 95 +++++++++++++ .../language/english/general_words_lang.php | 4 + .../migrations/175_add_sstv_images_table.php | 37 +++++ application/models/Sstv_model.php | 91 ++++++++++++ application/views/interface_assets/footer.php | 130 ++++++++++++++++++ application/views/sstv/sstvcarousel.php | 38 +++++ application/views/view_log/qso.php | 60 ++++++++ 8 files changed, 457 insertions(+) create mode 100644 application/controllers/Sstv.php create mode 100644 application/migrations/175_add_sstv_images_table.php create mode 100644 application/models/Sstv_model.php create mode 100644 application/views/sstv/sstvcarousel.php diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 054de873..65fbe634 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -618,7 +618,9 @@ class Logbook extends CI_Controller { } $this->load->model('Qsl_model'); + $this->load->model('Sstv_model'); $data['qslimages'] = $this->Qsl_model->getQslForQsoId($id); + $data['sstvimages'] = $this->Sstv_model->getSstvForQsoId($id); $data['primary_subdivision'] = $this->subdivisions->get_primary_subdivision_name($data['query']->result()[0]->COL_DXCC); $data['secondary_subdivision'] = $this->subdivisions->get_secondary_subdivision_name($data['query']->result()[0]->COL_DXCC); $data['max_upload'] = ini_get('upload_max_filesize'); diff --git a/application/controllers/Sstv.php b/application/controllers/Sstv.php new file mode 100644 index 00000000..c229a13a --- /dev/null +++ b/application/controllers/Sstv.php @@ -0,0 +1,95 @@ +lang->load('qslcard'); + $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'); } + } + + public function uploadSSTV() { + $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'); } + + if (!file_exists('./assets/sstvimages')) { + mkdir('./assets/sstvimages', 0755, true); + } + $qsoid = $this->input->post('qsoid'); + + $results = array(); + if (isset($_FILES['sstvimages']) && $_FILES['sstvimages']['error'][0] == 0) + { + for($i=0; $i $_FILES['sstvimages']['name'][$i], + 'type' => $_FILES['sstvimages']['type'][$i], + 'tmp_name' => $_FILES['sstvimages']['tmp_name'][$i], + 'error' => $_FILES['sstvimages']['error'][$i], + 'size' => $_FILES['sstvimages']['size'][$i] + ); + $result = $this->uploadSSTVImage($qsoid, $file); + array_push($results, $result); + } + } + + header("Content-type: application/json"); + echo json_encode($results); + } + + function uploadSSTVImage($qsoid, $file) { + $config['upload_path'] = './assets/sstvimages'; + $config['allowed_types'] = 'jpg|gif|png|jpeg|JPG|PNG|bmp'; + $array = explode(".", $file['name']); + $ext = end($array); + $config['file_name'] = $qsoid . '.sstv.' . '_' . time() . '.' . $ext; + + $this->load->library('upload', $config); + + $_FILES['sstvimage'] = $file; + if ( ! $this->upload->do_upload('sstvimage')) { + // Upload of SSTV image Failed + $error = array('error' => $this->upload->display_errors()); + + return $error; + } + else { + // Load database queries + $this->load->model('Sstv_model'); + + //Upload of SSTV image was successful + $data = $this->upload->data(); + + // Now we need to insert info into database about file + $filename = $data['file_name']; + $insertid = $this->Sstv_model->saveSstvImages($qsoid, $filename); + + $result['status'] = 'Success'; + $result['insertid'] = $insertid; + $result['filename'] = $filename; + return $result; + } + } + + + // Deletes SSTV Image + public function delete() { + $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'); } + + $id = $this->input->post('id'); + $this->load->model('Sstv_model'); + + $path = './assets/sstvimages/'; + $file = $this->Sstv_model->getSSTVFilename($id)->row(); + $filename = $file->filename; + unlink($path.$filename); + + $this->Sstv_model->deleteSstv($id); + } +} diff --git a/application/language/english/general_words_lang.php b/application/language/english/general_words_lang.php index d61b9f67..b2a019f8 100644 --- a/application/language/english/general_words_lang.php +++ b/application/language/english/general_words_lang.php @@ -74,6 +74,10 @@ $lang['general_word_invalid_ignore'] = 'Invalid (Ignore)'; $lang['general_word_qslcard'] = 'QSL Card'; $lang['general_word_qslcard_management'] = 'QSL Management'; $lang['general_word_qslcards'] = 'QSL Cards'; +$lang['general_word_sstv_management'] = 'SSTV Management'; +$lang['general_word_sstvimages'] = 'SSTV Images'; +$lang['general_sstv_upload'] = 'Uploaded SSTV images'; +$lang['general_sstv_upload_button'] = 'Upload SSTV image(s)'; $lang['general_word_qslcard_direct'] = 'Direct'; $lang['general_word_qslcard_bureau'] = 'Bureau'; $lang['general_word_qslcard_electronic'] = 'Electronic'; diff --git a/application/migrations/175_add_sstv_images_table.php b/application/migrations/175_add_sstv_images_table.php new file mode 100644 index 00000000..657b53e3 --- /dev/null +++ b/application/migrations/175_add_sstv_images_table.php @@ -0,0 +1,37 @@ +dbforge->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 5, + 'unsigned' => TRUE, + 'auto_increment' => TRUE + ), + 'qsoid' => array( + 'type' => 'VARCHAR', + 'constraint' => '250', + ), + 'filename' => array( + 'type' => 'VARCHAR', + 'constraint' => '250', + ), + 'modified' => array( + 'type' => 'timestamp', + 'null' => TRUE, + ), + )); + $this->dbforge->add_key('id', TRUE); + $this->dbforge->create_table('sstv_images'); + } + + public function down() + { + echo "not possible"; + } +} \ No newline at end of file diff --git a/application/models/Sstv_model.php b/application/models/Sstv_model.php new file mode 100644 index 00000000..9541c6d6 --- /dev/null +++ b/application/models/Sstv_model.php @@ -0,0 +1,91 @@ +security->xss_clean($qsoid); + + // be sure that QSO belongs to user + $CI = &get_instance(); + $CI->load->model('logbook_model'); + if (!$CI->logbook_model->check_qso_is_accessible($clean_id)) { + return; + } + + $data = array( + 'qsoid' => $clean_id, + 'filename' => $filename + ); + + $this->db->insert('sstv_images', $data); + + return $this->db->insert_id(); + } + + function getSSTVFilename($id) + { + // Clean ID + $clean_id = $this->security->xss_clean($id); + + // be sure that QSO belongs to user + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $this->db->select('qsoid'); + $this->db->from('sstv_images'); + $this->db->where('id', $clean_id); + $qsoid = $this->db->get()->row()->qsoid; + if (!$CI->logbook_model->check_qso_is_accessible($qsoid)) { + return; + } + + $this->db->select('filename'); + $this->db->from('sstv_images'); + $this->db->where('id', $clean_id); + + return $this->db->get(); + } + + + function deleteSstv($id) + { + // Clean ID + $clean_id = $this->security->xss_clean($id); + + // be sure that QSO belongs to user + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $this->db->select('qsoid'); + $this->db->from('sstv_images'); + $this->db->where('id', $clean_id); + $qsoid = $this->db->get()->row()->qsoid; + if (!$CI->logbook_model->check_qso_is_accessible($qsoid)) { + return; + } + + // Delete Mode + $this->db->delete('sstv_images', array('id' => $clean_id)); + } + + + function getSstvForQsoId($id) + { + // Clean ID + $clean_id = $this->security->xss_clean($id); + + // be sure that QSO belongs to user + $CI = &get_instance(); + $CI->load->model('logbook_model'); + if (!$CI->logbook_model->check_qso_is_accessible($clean_id)) { + return; + } + + $this->db->select('*'); + $this->db->from('sstv_images'); + $this->db->where('qsoid', $clean_id); + + return $this->db->get()->result(); + } + +} diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 002ac060..daf67e70 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2535,6 +2535,67 @@ if ($this->session->userdata('user_id') != null) { }); } + + + +