From 36e0550145bd1eb1cc0bf1f6bb7bd8f7dd59e327 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Wed, 18 Jan 2017 17:40:50 +0100 Subject: [PATCH] Fixed #17 --- js/main.js | 1 + php/admin/helper/delete-subtask.php | 8 +++- php/index.php | 6 +-- php/mysql.php | 61 +++++++++++++++++++++++------ 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/js/main.js b/js/main.js index 7fd4c4e..b56a24f 100644 --- a/js/main.js +++ b/js/main.js @@ -493,6 +493,7 @@ function deleteSubtask(subtask_ID, task_ID) $.post('../admin/helper/delete-subtask.php', { "subtask_ID": subtask_ID, + "task_ID": task_ID }, function(data, error) { diff --git a/php/admin/helper/delete-subtask.php b/php/admin/helper/delete-subtask.php index 4775bda..fc66551 100644 --- a/php/admin/helper/delete-subtask.php +++ b/php/admin/helper/delete-subtask.php @@ -9,10 +9,16 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') exit; } + if(!isset($_POST['task_ID'])) + { + echo "error"; + exit; + } + $db = new DB(); $db->createTables(); - if($db->deleteSubtask($_POST['subtask_ID']) == false) + if($db->deleteSubtask($_POST['subtask_ID'], $_POST['task_ID']) == false) { echo "error"; exit; diff --git a/php/index.php b/php/index.php index d27c510..df0e0b8 100644 --- a/php/index.php +++ b/php/index.php @@ -490,17 +490,17 @@ function printMilestoneDoneWithTasks($color, $currentMilestone, $isFirstMileston if($numberOfOpenSubtasks != false) { $numberOfOpenSubtasks = $numberOfOpenSubtasks['count']; - if($numberOfOpenSubtasks == sizeof($subtasks)) + if($numberOfOpenSubtasks == 0) { echo '<li>' . - '<div class="collapsible-header bold"><i class="material-icons green-text">check</i>Layout<span class="right">' . $numberOfOpenSubtasks . '/' . sizeof($subtasks) . '</span></div>' . + '<div class="collapsible-header bold"><i class="material-icons green-text">check</i>Layout<span class="right">' . sizeof($subtasks) . '/' . sizeof($subtasks) . '</span></div>' . '<div class="collapsible-body">' . '<ul class="collapsible white margin-left-and-right no-shadow margin-top-and-bottom" data-collapsible="accordion">'; } else { echo '<li>' . - '<div class="collapsible-header bold"><i class="material-icons red-text">build</i>Layout<span class="right">' . $numberOfOpenSubtasks . '/' . sizeof($subtasks) . '</span></div>' . + '<div class="collapsible-header bold"><i class="material-icons red-text">build</i>Layout<span class="right">' . (sizeof($subtasks) - $numberOfOpenSubtasks) . '/' . sizeof($subtasks) . '</span></div>' . '<div class="collapsible-body">' . '<ul class="collapsible white margin-left-and-right no-shadow margin-top-and-bottom" data-collapsible="accordion">'; } diff --git a/php/mysql.php b/php/mysql.php index 25773cb..5c436f4 100644 --- a/php/mysql.php +++ b/php/mysql.php @@ -105,8 +105,11 @@ class DB $statement->bindParam("title", $title); $statement->bindParam("description", $description); $statement->bindParam("status", $status); + $success = $statement->execute(); - return $statement->execute(); + $this->checkParentTask($taskID); + + return $success; } //======================================== @@ -129,6 +132,14 @@ class DB return $statement->execute(); } + function reopenTask($taskID) + { + $statement = self::$db->prepare("UPDATE tasks SET status='0' WHERE ID = :taskID;"); + $statement->bindParam("taskID", $taskID); + + return $statement->execute(); + } + function finishSubTask($subtaskID) { $statement = self::$db->prepare("UPDATE subtasks SET status='1' WHERE ID = :subtaskID;"); @@ -185,9 +196,35 @@ class DB $statement->bindParam("description", $description); $statement->bindParam("status", $status); - return $statement->execute(); + $success = $statement->execute(); + $this->checkParentTask($taskID); + + return $success; } + function checkParentTask($taskID) + { + $subTasks = $this->getSubtasks($taskID); + $counter = 0; + for($m = 0; $m < sizeof($subTasks); $m++) + { + $currentSubTask = $subTasks[$m]; + if ($currentSubTask['Status'] == 1) + { + $counter = $counter + 1; + } + } + + if($counter == sizeof($subTasks)) + { + $this->finishTask($taskID); + } + else + { + $this->reopenTask($taskID); + } + } + //======================================== //----------------- get ------------------ //======================================== @@ -295,13 +332,13 @@ class DB //--------------- delete ----------------- //======================================== - function deleteRoadmap($roadmapID) - { - $statement = self::$db->prepare("DELETE FROM roadmaps WHERE roadmaps.ID=:roadmapID;"); - $statement->bindParam("roadmapID", $roadmapID); - $statement->execute(); + function deleteRoadmap($roadmapID) + { + $statement = self::$db->prepare("DELETE FROM roadmaps WHERE roadmaps.ID=:roadmapID;"); + $statement->bindParam("roadmapID", $roadmapID); + $statement->execute(); - return $statement->execute(); + return $statement->execute(); } function deleteMilestone($milestoneID) @@ -322,12 +359,14 @@ class DB return $statement->execute(); } - function deleteSubtask($subtaskID) + function deleteSubtask($subtaskID, $taskID) { $statement = self::$db->prepare("DELETE FROM subtasks WHERE subtasks.ID=:subtaskID;"); $statement->bindParam("subtaskID", $subtaskID); - $statement->execute(); + $success = $statement->execute(); - return $statement->execute(); + $this->checkParentTask($taskID); + + return $success; } } \ No newline at end of file -- GitLab