diff --git a/application/controllers/User.php b/application/controllers/User.php index 94998733..ce1d59f5 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -812,6 +812,37 @@ class User extends CI_Controller { $this->load->view('interface_assets/footer'); } + + /** + * Deletes a user by their ID. + * + * This function first loads the 'user_model'. It then checks if the current user has the authorization level of 99. + * If not, it sets a flash message and redirects the user to the dashboard. + * + * If the user is authorized, it gets the user to be deleted by their ID from the URI segment 3. + * It then calls the 'delete' function from the 'user_model' with the user ID as a parameter. + * + * If the 'delete' function executes successfully, it sets the HTTP status code to 200. + * If the 'delete' function fails, it sets the HTTP status code to 500. + * + * @param int $id The ID of the user to delete. + */ + function delete_new($id) { + $this->load->model('user_model'); + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + $query = $this->user_model->get_by_id($this->uri->segment(3)); + + // call $this->user_model->delete and if no errors return true + if ($this->user_model->delete($id)) { + // request responds with a 200 status code and empty content + $this->output->set_status_header(200); + } else { + // request responds with a 500 status code and empty content + $this->output->set_status_header(500); + } + + } + function delete() { $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } diff --git a/application/views/user/main.php b/application/views/user/main.php index b06344a0..a8ff0851 100644 --- a/application/views/user/main.php +++ b/application/views/user/main.php @@ -53,7 +53,7 @@