Skip to content
9 changes: 1 addition & 8 deletions application/controllers/Qsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,8 @@ public function upload() {
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('Qsl_model');

$path = $this->Qsl_model->get_imagePath('p');
$file = $this->Qsl_model->getFilename($id)->row();
$filename = $file->filename;
unlink($path.'/'.$filename);

$this->Qsl_model->deleteQsl($id);
}

Expand Down Expand Up @@ -174,4 +167,4 @@ function viewQsl() {
$this->load->view('qslcard/qslcarousel', $data);
}

}
}
56 changes: 37 additions & 19 deletions application/models/Eqsl_images.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ function get_image($qso_id) {
}
}

function del_image($qso_id, $user_id = null) {
// QSO belongs to station_profile. But since we have folders for Users (and therefore an extra indirect relation) we need to lookup user for station first...
$eqsl_img=$this->db->query('SELECT e.image_file,e.id, qso.station_id, s.user_id FROM `eQSL_images` e INNER JOIN '.$this->config->item('table_name').' qso ON (e.qso_id = qso.COL_PRIMARY_KEY) inner join station_profile s on (s.station_id=qso.station_id) where qso.COL_PRIMARY_KEY=?',$qso_id);
foreach ($eqsl_img->result() as $row) {
if (($user_id ?? '') == '') { // Calling as User? Check if User-id matches User-id from QSO
$user_id = $this->session->userdata('user_id');
if ($row->user_id != $user_id) {
return "No Image"; // Image doesn't belong to user, so return
}
}
$image=$this->get_imagePath('p',$row->user_id).'/'.$row->image_file;
unlink($image);
$this->db->delete('eQSL_images', array('id' => $row->id));
return $image;
}
}

function save_image($qso_id, $image_name) {
$data = array(
'qso_id' => $qso_id,
Expand All @@ -36,36 +53,37 @@ function eqsl_qso_list() {
}

// return path of eQsl file : u=url / p=real path
function get_imagePath($pathorurl='u') {
function get_imagePath($pathorurl='u', $user_id = null) {

// test if new folder directory option is enabled
$userdata_dir = $this->config->item('userdata');

if (isset($userdata_dir)) {

$eqsl_dir = "eqsl_card"; // make sure this is the same as in Debug_model.php function migrate_userdata()

$user_id = $this->session->userdata('user_id');

if (($user_id ?? '') == '') {
$user_id = $this->session->userdata('user_id');
}

// check if there is a user_id in the session data and it's not empty
if ($user_id != '') {
// create the folder
if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir)) {
mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir, 0755, true);
}

// and return it
if ($pathorurl=='u') {
return $userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
} else {
return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
}
} else {

// create the folder
if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir)) {
mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir, 0755, true);
}

// and return it
if ($pathorurl=='u') {
return $userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
} else {
return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
}
} else {
log_message('info', 'Can not get eqsl image path because no user_id in session data');
}
} else {

} else {
// if the config option is not set we just return the old path
return 'images/eqsl_card_images';
}
Expand Down
25 changes: 17 additions & 8 deletions application/models/Logbook_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3045,14 +3045,23 @@ function total_countries_confirmed_lotw() {
}

/* Delete QSO based on the QSO ID */
function delete($id) {
if ($this->check_qso_is_accessible($id)) {
$this->db->where('COL_PRIMARY_KEY', $id);
$this->db->delete($this->config->item('table_name'));
} else {
return;
}
}
function delete($id) {
if ($this->check_qso_is_accessible($id)) {
$this->load->model('qsl_model');
$this->load->model('eqsl_images');

$this->qsl_model->del_image_for_qso($id);
$this->eqsl_images->del_image($id);

$this->db->where('COL_PRIMARY_KEY', $id);
$this->db->delete($this->config->item('table_name'));

$this->db->where('qsoid', $id);
$this->db->delete("oqrs");
} else {
return;
}
}

/* Used to check if the qso is already in the database */
function import_check($datetime, $callsign, $band, $mode, $station_callsign, $station_id = null) {
Expand Down
Loading