diff --git a/adminstuds.php b/adminstuds.php
index f8b0d43..a26a08c 100644
--- a/adminstuds.php
+++ b/adminstuds.php
@@ -189,7 +189,12 @@ if (isset($_POST['remove_all_votes'])) {
exit;
}
if (isset($_POST['confirm_remove_all_votes'])) {
- $adminPollService->cleanVotes($poll_id);
+ // TODO Add log
+ if ($adminPollService->cleanVotes($poll_id)) {
+ $message = new Message('success', _('All votes deleted.'));
+ } else {
+ $message = new Message('danger', _('Failed to delete all votes.'));
+ }
}
// -------------------------------
@@ -242,6 +247,7 @@ if (isset($_POST['remove_all_comments'])) {
exit;
}
if (isset($_POST['confirm_remove_all_comments'])) {
+ // TODO Add log
if ($adminPollService->cleanComments($poll_id)) {
$message = new Message('success', _('All comments deleted.'));
} else {
@@ -261,7 +267,18 @@ if (isset($_POST['delete_poll'])) {
exit;
}
if (isset($_POST['confirm_delete_poll'])) {
- // TODO
+ // TODO Add log
+ if ($adminPollService->deleteEntirePoll($poll_id)) {
+ $message = new Message('success', _('Poll fully deleted.'));
+ } else {
+ $message = new Message('danger', _('Failed to delete the poll.'));
+ }
+ $smarty->assign('poll_id', $poll_id);
+ $smarty->assign('admin_poll_id', $admin_poll_id);
+ $smarty->assign('title', _('Poll') . ' - ' . $poll->title);
+ $smarty->assign('message', $message);
+ $smarty->display('poll_deleted.tpl');
+ exit;
}
// -------------------------------
@@ -269,6 +286,7 @@ if (isset($_POST['confirm_delete_poll'])) {
// -------------------------------
if (!empty($_POST['delete_column'])) {
+ // TODO Add log
$column = filter_input(INPUT_POST, 'delete_column', FILTER_DEFAULT);
if ($adminPollService->deleteSlot($poll_id, $column)) {
diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php
index aab3fc1..b6864ab 100644
--- a/app/classes/Framadate/FramaDB.php
+++ b/app/classes/Framadate/FramaDB.php
@@ -127,7 +127,7 @@ class FramaDB {
* @param $poll_id int The ID of the given poll.
* @return bool|null true if action succeeded.
*/
- function deleteVotesByAdminPollId($poll_id) {
+ function deleteVotesByPollId($poll_id) {
$prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ?');
return $prepared->execute([$poll_id]);
}
@@ -197,13 +197,18 @@ class FramaDB {
$prepared->execute([$poll_id, $datetime]);
}
+ function deleteSlotsByPollId($poll_id) {
+ $prepared = $this->prepare('DELETE FROM sujet_studs WHERE id_sondage = ?');
+ $prepared->execute([$poll_id]);
+ }
+
/**
* Delete all comments of a given poll.
*
* @param $poll_id int The ID of the given poll.
* @return bool|null true if action succeeded.
*/
- function deleteCommentsByAdminPollId($poll_id) {
+ function deleteCommentsByPollId($poll_id) {
$prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ?');
return $prepared->execute([$poll_id]);
}
@@ -223,4 +228,9 @@ class FramaDB {
return $prepared->execute([$poll_id, $comment_id]);
}
+ function deleteByPollId($poll_id) {
+ $prepared = $this->prepare('DELETE FROM sondage WHERE poll_id = ?');
+ $prepared->execute([$poll_id]);
+ }
+
}
diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php
index 9d9c106..4559ce6 100644
--- a/app/classes/Framadate/Services/AdminPollService.php
+++ b/app/classes/Framadate/Services/AdminPollService.php
@@ -40,7 +40,7 @@ class AdminPollService {
* @return bool|null true is action succeeded
*/
function cleanComments($poll_id) {
- return $this->connect->deleteCommentsByAdminPollId($poll_id);
+ return $this->connect->deleteCommentsByPollId($poll_id);
}
/**
@@ -61,7 +61,22 @@ class AdminPollService {
* @return bool|null true is action succeeded
*/
function cleanVotes($poll_id) {
- return $this->connect->deleteVotesByAdminPollId($poll_id);
+ return $this->connect->deleteVotesByPollId($poll_id);
+ }
+
+ /**
+ * Delete the entire given poll.
+ *
+ * @param $poll_id int The ID of the poll
+ * @return bool true is action succeeded
+ */
+ function deleteEntirePoll($poll_id) {
+ /*$this->connect->deleteVotesByPollId($poll_id);
+ $this->connect->deleteCommentsByPollId($poll_id);
+ $this->connect->deleteSlotsByPollId($poll_id);
+ $this->connect->deleteByPollId($poll_id);*/
+
+ return true;
}
/**
@@ -69,6 +84,7 @@ class AdminPollService {
*
* @param $poll_id int The ID of the poll
* @param $slot string The name of the slot
+ * @return bool true if action succeeded
*/
public function deleteSlot($poll_id, $slot) {
$ex = explode('@', $slot);
diff --git a/old_adminstuds.php b/old_adminstuds.php
index 945be49..46a8b8e 100644
--- a/old_adminstuds.php
+++ b/old_adminstuds.php
@@ -42,97 +42,6 @@ function send_mail_admin() {
}
-// reload
-// TODO OPZ Pourquoi recharger
-// $dsujet= $sujets->FetchObject(false);
-// $dsondage= $sondage->FetchObject(false);
-
-if (isset($_POST['ajoutsujet'])) {
- Utils::print_header( _('Add a column') .' - ' . stripslashes($poll->title));
-
- bandeau_titre(_('Make your polls'));
-
- //on recupere les données et les sujets du sondage
-
- echo '
-
-
-
-
-
';
-
- bandeau_pied();
-
- die();
-}
-
-//action si bouton confirmation de suppression est activé
-if (isset($_POST["confirmesuppression"])) {
- $nbuser=$user_studs->RecordCount();
- $date=date('H:i:s d/m/Y:');
-
- if (Utils::remove_sondage($connect, $poll_id)) {
- // on ecrit dans le fichier de logs la suppression du sondage
- error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, 'admin/logs_studs.txt');
-
- // Email sent
- send_mail_admin();
- //affichage de l'ecran de confirmation de suppression de sondage
- Utils::print_header(_("Your poll has been removed!"));
-
- bandeau_titre(_("Make your polls"));
-
- echo '
-