summaryrefslogtreecommitdiffstats
path: root/application/controllers
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-05-05 22:32:18 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-05-05 22:32:18 +0200
commit93e06f76dfa2cb49a2edfcb6b70dd3c6cf3272d6 (patch)
treebe71bae47aa0251aa4459e121530adfa0a78e71c /application/controllers
parentf3cb1c31e30a0d31eb545439fe3ad7da68ccb189 (diff)
Rework file deletion; allow to delete multiple IDs at once
This removes the old form which was used to delete a single upload and replaces it with checkboxes on the history page. All checked IDs will be removed at once, instead of requiring the user to click through multiple pages. The old file/delete page is kept for compatibility with CLI clients. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers')
-rw-r--r--application/controllers/file.php65
1 files changed, 46 insertions, 19 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index 079802dbc..2a56df96c 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -180,37 +180,64 @@ class File extends CI_Controller {
echo $cached;
}
- // Allow users to delete their own IDs
- function delete()
+ function do_delete()
{
$this->muser->require_access();
- $id = $this->uri->segment(3);
- $this->data["id"] = $id;
+ $ids = $this->input->post("ids");
+ $errors = array();
+ $msgs = array();
+ $deleted_count = 0;
+ $total_count = 0;
- $process = $this->input->post("process");
- if ($this->var->cli_client) {
- $process = true;
+ if (!$ids) {
+ show_error("No IDs specified");
}
- if ($id && !$this->file_mod->id_exists($id)) {
- $this->output->set_status_header(404);
- $this->data["msg"] = "Unknown ID.";
- } elseif ($process) {
+ foreach ($ids as $id) {
+ $total_count++;
+
+ if (!$this->file_mod->id_exists($id)) {
+ $errors[] = "'$id' didn't exist anymore.";
+ continue;
+ }
+
if ($this->file_mod->delete_id($id)) {
- $this->load->view($this->var->view_dir.'/header', $this->data);
- $this->load->view($this->var->view_dir.'/deleted', $this->data);
- $this->load->view($this->var->view_dir.'/footer', $this->data);
- return;
+ $msgs[] = "'$id' has been removed.";
+ $deleted_count++;
} else {
- $this->data["msg"] = "Deletion failed. Do you really own that file?";
+ $errors[] = "'$id' couldn't be deleted.";
}
}
- $this->data["filedata"] = $this->file_mod->get_filedata($id);
- $this->data["can_delete"] = $this->data["filedata"]["user"] == $this->muser->get_userid();
+ $this->data["errors"] = $errors;
+ $this->data["msgs"] = $msgs;
+ $this->data["deleted_count"] = $deleted_count;
+ $this->data["total_count"] = $total_count;
+
+ $this->load->view($this->var->view_dir.'/header', $this->data);
+ $this->load->view($this->var->view_dir.'/deleted', $this->data);
+ $this->load->view($this->var->view_dir.'/footer', $this->data);
+ }
+
+ function delete()
+ {
+ $this->muser->require_access();
+
+ $id = $this->uri->segment(3);
+ $this->data["id"] = $id;
+
+ if ($id && !$this->file_mod->id_exists($id)) {
+ $this->output->set_status_header(404);
+ echo "Unknown ID '$id'.\n";
+ return;
+ }
- $this->file_mod->display_info($id);
+ if ($this->file_mod->delete_id($id)) {
+ echo "$id has been deleted.\n";
+ } else {
+ echo "Deletion failed. Do you really own that file?\n";
+ }
}
// Handle pastes