diff --git a/application/models/Eqsl_images.php b/application/models/Eqsl_images.php index c9073831d..81b038627 100644 --- a/application/models/Eqsl_images.php +++ b/application/models/Eqsl_images.php @@ -26,7 +26,7 @@ class Eqsl_images extends CI_Model { } } $image=$this->get_imagePath('p',$row->user_id).'/'.$row->image_file; - log_message("Error",$image); // todo: chk and unlink + unlink($image); return $image; } } @@ -61,7 +61,7 @@ class Eqsl_images extends CI_Model { $eqsl_dir = "eqsl_card"; // make sure this is the same as in Debug_model.php function migrate_userdata() - if ($user_id ?? '' == '') { + if (($user_id ?? '') == '') { $user_id = $this->session->userdata('user_id'); } diff --git a/application/models/Qsl_model.php b/application/models/Qsl_model.php index c0907dc66..800deb734 100644 --- a/application/models/Qsl_model.php +++ b/application/models/Qsl_model.php @@ -54,7 +54,7 @@ class Qsl_model extends CI_Model { // 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... $qsl_img=$this->db->query('SELECT e.filename, e.id, qso.station_id, s.user_id FROM qsl_images e INNER JOIN '.$this->config->item('table_name').' qso ON (e.qsoid = qso.COL_PRIMARY_KEY) inner join station_profile s on (s.station_id=qso.station_id) where qso.COL_PRIMARY_KEY=?',$qso_id); foreach ($qsl_img->result() as $row) { - if ($user_id ?? '' == '') { // Calling as User? Check if User-id matches User-id from QSO + 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 @@ -150,7 +150,7 @@ class Qsl_model extends CI_Model { $qsl_dir = "qsl_card"; // make sure this is the same as in Debug_model.php function migrate_userdata() - if ($user_id ?? '' == '') { + if (($user_id ?? '') == '') { $user_id = $this->session->userdata('user_id'); } diff --git a/application/models/Stations.php b/application/models/Stations.php index 4f7bfce53..f3e2f0438 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -202,7 +202,7 @@ class Stations extends CI_Model { $this->user_options_model->set_option('eqsl_default_qslmsg', 'key_station_id', array(xss_clean($this->input->post('station_id', true)) => $eqsl_default_qslmsg)); } - function delete($id,$force = false) { + function delete($id,$force = false, $user_id = null) { // Clean ID $clean_id = $this->security->xss_clean($id); @@ -215,7 +215,7 @@ class Stations extends CI_Model { $this->user_options_model->del_option('eqsl_default_qslmsg', 'key_station_id', array('option_key' => $id)); // Delete Contents of log for that station_id - $this->deletelog($clean_id); + $this->deletelog($clean_id, $user_id); // Delete Station Profile, links, contests and oqrs-requests $this->db->query("DELETE c FROM contest_session c WHERE c.station_id =?",$clean_id); @@ -224,15 +224,18 @@ class Stations extends CI_Model { $this->db->delete('station_profile', array('station_id' => $clean_id)); } - function deletelog($id) { + function deletelog($id, $user_id = null) { // Clean ID $clean_id = $this->security->xss_clean($id); - // Todo: Fetch EACH COL_PRIMARY_KEY (via inner join) from Log-table and delete also eQSL-file within filesystem (Function missing here) depending on path-configuration - $this->db->query("DELETE e FROM `eQSL_images` e inner join ".$this->config->item('table_name')." qsos where e.qso_id=qsos.COL_PRIMARY_KEY and qsos.station_id=?",$clean_id); - // Todo: Fetch EACH COL_PRIMARY_KEY (via inner join) from Log-table and delete also QSL-file within filesystem (Function missing here) depending on path-configuration - $this->db->query("DELETE q FROM qsl_images q inner join ".$this->config->item('table_name')." qsos WHERE q.qsoid=qsos.COL_PRIMARY_KEY and qsos.station_id = ?",$clean_id); + $this->load->model('qsl_model'); + $this->load->model('eqsl_images'); + $qsos=$this->db->query("select COL_PRIMARY_KEY as id from ".$this->config->item('table_name')." where station_id=?",$clean_id); + foreach ($qsos->result() as $qso) { + $this->qsl_model->del_image_for_qso($qso->id, $user_id); + $this->eqsl_images->del_image($qso->id, $user_id); + } // Delete QSOs $this->db->query("DELETE FROM ".$this->config->item('table_name')." WHERE station_id = ?",$clean_id); } diff --git a/application/models/User_model.php b/application/models/User_model.php index 2027c6896..cd29c6e20 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -334,7 +334,7 @@ class User_Model extends CI_Model { $this->load->model('Stations'); $stations = $this->Stations->all_of_user($user_id); foreach ($stations->result() as $row) { - $this->Stations->delete($row->station_id,true); + $this->Stations->delete($row->station_id,true, $user_id); } // Delete QSOs from $this->config->item('table_name') $this->db->query("DELETE FROM bandxuser WHERE userid = ?",$user_id);