From 4f824438734254b54e65e61ea29708ef93390e36 Mon Sep 17 00:00:00 2001
From: Florian Bieringer <florian.bieringer@uni-passau.de>
Date: Fri, 6 Nov 2015 11:22:05 +0100
Subject: [PATCH] Add delete option

---
 controllers/myplugins.php    | 11 +++++++++++
 controllers/presenting.php   |  6 ------
 views/myplugins/delete.php   |  8 ++++++++
 views/presenting/details.php |  7 +------
 4 files changed, 20 insertions(+), 12 deletions(-)
 create mode 100644 views/myplugins/delete.php

diff --git a/controllers/myplugins.php b/controllers/myplugins.php
index e4f87d4..ca345e1 100644
--- a/controllers/myplugins.php
+++ b/controllers/myplugins.php
@@ -167,4 +167,15 @@ class MypluginsController extends MarketController
         $this->redirect('presenting/details/' . $this->release->plugin->getId());
     }
 
+
+    public function delete_action($plugin_id) {
+        $this->marketplugin = MarketPlugin::find($plugin_id);
+        if (Request::submitted('delete') && $this->marketplugin->isWritable()) {
+            CSRFProtection::verifyUnsafeRequest();
+            $this->marketplugin->delete();
+            $this->redirect('myplugins/overview');
+        }
+    }
+
+
 }
\ No newline at end of file
diff --git a/controllers/presenting.php b/controllers/presenting.php
index c0058cb..867991e 100644
--- a/controllers/presenting.php
+++ b/controllers/presenting.php
@@ -149,11 +149,6 @@ class PresentingController extends MarketController
     public function details_action($plugin_id) {
         Navigation::addItem('/pluginmarket/presenting/details', new AutoNavigation(_('Details'), $this->url_for('presenting/details/'.$plugin_id)));
         $this->marketplugin = new MarketPlugin($plugin_id);
-        if (Request::isPost() && Request::submitted("delete_plugin") && $this->marketplugin->isRootable()) {
-            $this->marketplugin->delete();
-            PageLayout::postMessage(MessageBox::success(_("Plugin wurde gel�scht.")));
-            $this->redirect('presenting/overview');
-        }
         $this->marketplugin['rating'] = $this->marketplugin->calculateRating();
         $this->marketplugin->store();
 
@@ -327,5 +322,4 @@ class PresentingController extends MarketController
 
     }
 
-
 }
diff --git a/views/myplugins/delete.php b/views/myplugins/delete.php
new file mode 100644
index 0000000..bc836ca
--- /dev/null
+++ b/views/myplugins/delete.php
@@ -0,0 +1,8 @@
+<form method="post" action="<?= $controller->url_for('myplugins/delete/' . $marketplugin->getId()) ?>">
+    <?= CSRFProtection::tokenTag() ?>
+    <p><?= sprintf(_('Soll das Plugin %s wirklich unwiederruflich gel�scht werden?'), htmlReady($marketplugin->name)) ?></p>
+
+    <div data-dialog-button>
+        <?= \Studip\Button::create(_('Endg�ltig l�schen'), 'delete') ?>
+    </div>
+</form>
\ No newline at end of file
diff --git a/views/presenting/details.php b/views/presenting/details.php
index 2dbd3d6..2a44662 100644
--- a/views/presenting/details.php
+++ b/views/presenting/details.php
@@ -282,16 +282,11 @@ if ($icon) {
 
 <div style="text-align: center">
 <? if ($marketplugin->isWritable()) : ?>
+    <?= \Studip\LinkButton::create(_("Plugin l�schen"), $controller->url_for('myplugins/delete/' . $marketplugin->getId()), array('data-dialog' => 1)) ?>
     <?= \Studip\LinkButton::create(_("bearbeiten"), $controller->url_for('myplugins/edit/' . $marketplugin->getId()), array('data-dialog' => 1)) ?>
     <?= \Studip\LinkButton::create(_("Release hinzuf�gen"), $controller->url_for('myplugins/add_release/' . $marketplugin->getId()), array('data-dialog' => 1)) ?>
 <? endif ?>
 <? if ($marketplugin['user_id'] !== $GLOBALS['user']->id) : ?>
     <?= \Studip\LinkButton::create(_("Plugin abonnieren"), $controller->url_for('presenting/register_for_pluginnews/' . $marketplugin->getId()), array('title' => _("Neuigkeiten des Plugins per Nachricht bekommen."), 'data-dialog' => "1")) ?>
 <? endif ?>
-<? if ($marketplugin->isRootable()) : ?>
-    <form action="?" method="post" style="display: inline-block; margin: 0px;">
-        <input type="hidden" name="plugin_id" value="<?= htmlReady($marketplugin->getId()) ?>">
-        <?= \Studip\Button::create(_("L�schen"), "delete_plugin", array('onclick' => "return window.confirm('"._("Plugin wirklich unwiderrufbar l�schen?")."');")) ?>
-    </form>
-<? endif ?>
 </div>
-- 
GitLab