Skip to content
Snippets Groups Projects
Commit 238bf65d authored by Robert Goldmann's avatar Robert Goldmann
Browse files

implemented adminarea --> add/update/delete subtask

parent 51f3ec2c
Branches
Tags
No related merge requests found
......@@ -48,6 +48,11 @@ $(document).ready(function()
editTask(this.dataset.id, this.dataset.milestoneid);
});
$('.button-save-subtask').click(function()
{
editSubtask(this.dataset.id, this.dataset.taskid);
});
$('.button-delete-roadmap').click(function()
{
var r = confirm("Do you really want to delete this roadmap?");
......@@ -75,6 +80,15 @@ $(document).ready(function()
}
});
$('.button-delete-subtask').click(function()
{
var r = confirm("Do you really want to delete this subtask?");
if(r == true)
{
deleteSubtask(this.dataset.id, this.dataset.taskid);
}
});
$('#checkbox-done').click(function()
{
var checked = document.getElementById("checkbox-done").checked;
......@@ -407,3 +421,77 @@ function deleteTask(task_ID, milestone_ID)
}
});
}
function editSubtask(subtask_ID, task_ID)
{
var edit = document.getElementById('edit').innerHTML;
var title = $('#title').val();
var description = $('#description').val();;
var done = document.getElementById("checkbox-done").checked;
if(isNull(title))
{
alert("Title shouldn't be empty!");
return;
}
if(done)
{
done = 1;
}
else
{
done = 0;
}
$.post('../admin/helper/edit-subtask.php',
{
"title": title,
"description": description,
"done": done,
"edit": edit,
"ID": subtask_ID,
"task-ID": task_ID
}, function(data, error)
{
data = data.toString().trim();
switch(data)
{
case "error":
alert('An error occurred');
break;
case "error-edit":
alert('An error occurred while editing the subtask with the ID ' + subtask_ID);
break;
case "error-insert":
alert('An error occurred while inserting the new task');
break;
default:
window.location.href = "../admin/admin-subtasks.php?id=" + task_ID;
break;
}
});
}
function deleteSubtask(subtask_ID, task_ID)
{
$.post('../admin/helper/delete-subtask.php',
{
"subtask_ID": subtask_ID,
}, function(data, error)
{
data = data.toString().trim();
if(data != "error")
{
window.location.href = "../admin/admin-subtasks.php?id=" + task_ID;
}
else
{
alert('An error occurred while deleting the subtask with the ID ' + subtask_ID);
}
});
}
\ No newline at end of file
<!DOCTYPE html>
<?php
include_once('../getLanguageJSON.php');
include_once('../mysql.php');
if(!isset($_GET['taskID']))
{
header('Location: ../error.php?message=error_param_missing');
exit;
}
$taskID = $_GET['taskID'];
if(!is_numeric($taskID) || $taskID < 1)
{
header('Location: ../error.php?message=error_param_invalid');
exit;
}
if(!isset($_GET['edit']))
{
$_GET['edit'] = "false";
$ID = 0;
$db = new DB();
$db->createTables();
}
else
{
if(!isset($_GET['id']))
{
header('Location: ../error.php?message=error_param_missing');
exit;
}
$ID = $_GET['id'];
if(!is_numeric($ID) || $ID < 1)
{
header('Location: ../error.php?message=error_param_invalid');
exit;
}
$db = new DB();
$db->createTables();
$subtask = $db->getSubtask($ID);
if($subtask == false)
{
header('Location: ../error.php?message=error_subtask_not_existing');
exit;
}
}
?>
<html xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8"/>
<?php
if($_GET['edit'] == "false")
{
echo '<title>New Subtask</title>';
}
else
{
echo '<title>Edit Subtask</title>';
}
?>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="../../materialize/css/materialize.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="../../css/style.css"/>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="../../js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="../../materialize/js/materialize.min.js"></script>
<script type="text/javascript" src="../../js/main.js"></script>
<script type="text/javascript" src="../../js/ResizeSensor.js"></script>
<script type="text/javascript" src="../../js/ElementQueries.js"></script>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body class="grey lighten-3">
<div class="hide" id="edit"><?php echo $_GET['edit'];?></div>
<div id="main">
<div class="container">
<?php
if($_GET['edit'] == "false")
{
echo '<h2 class="center-align" id="headline">New Subtask</h2>';
}
else
{
echo '<h2 class="center-align" id="headline">Edit Subtask</h2>';
}
?>
<div class="row center-align">
<div class="col s6 m8 offset-m2 l6 offset-l3">
<div class="input-field col s12">
<input id="title" name="title" type="text" value="<?php if(isset($subtask)){echo $subtask['Title'];}?>">
<label for="title">Title</label>
</div>
</div>
</div>
<div class="row center-align">
<div class="col s6 m8 offset-m2 l6 offset-l3">
<div class="input-field col s12">
<input id="description" name="description" type="text" value="<?php if(isset($subtask)){echo $subtask['Description'];}?>">
<label for="description">Description</label>
</div>
</div>
</div>
<div class="row center-align">
<div class="col s6 m8 offset-m2 l6 offset-l3">
<div class="col s12 left-align">
<input type="checkbox" id="checkbox-done"
<?php
if(isset($subtask))
{
if($subtask['Status'] == "1")
{
echo "checked";
}
}
?>
/>
<label for="checkbox-done">Done</label>
</div>
</div>
</div>
<div class="row center-align margin-top">
<div class="col s12 m8 offset-m2 l6 offset-l3">
<a class="waves-effect waves-light btn blue darken-3" href="admin-subtasks.php?id=<?php echo $taskID;?>"><i class="material-icons left">arrow_back</i>Back</a>
<a class="waves-effect waves-light btn blue darken-3 margin-left button-save-subtask" data-id="<?php echo $ID;?>" data-taskid="<?php echo $taskID;?>"><i class="material-icons left">save</i>Save</a>
</div>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<?php
include_once('../getLanguageJSON.php');
include_once('../mysql.php');
if(!isset($_GET['id']))
{
header('Location: ../error.php?message=error_param_missing');
exit;
}
$ID = $_GET['id'];
if(!is_numeric($ID) || $ID < 1)
{
header('Location: ../error.php?message=error_param_invalid');
exit;
}
$db = new DB();
$db->createTables();
$task = $db->getTask($ID);
if($task == false)
{
header('Location: ../error.php?message=error_subtask_not_existing');
exit;
}
?>
<html xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8"/>
<title>Subtasks - Adminarea</title>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="../../materialize/css/materialize.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="../../css/style.css"/>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="../../js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="../../materialize/js/materialize.min.js"></script>
<script type="text/javascript" src="../../js/main.js"></script>
<script type="text/javascript" src="../../js/ResizeSensor.js"></script>
<script type="text/javascript" src="../../js/ElementQueries.js"></script>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body class="grey lighten-3">
<a class="waves-effect waves-light btn blue darken-3" href="admin-tasks.php?id=<?php echo $task['MilestoneID'];?>"><i class="material-icons left">arrow_back</i>Back</a>
<div id="main">
<div class="container">
<h2 class="center-align" id="headline"><?php echo $task['Title'];?></h2>
<h4 class="center-align" id="headline">Subtasks</h4>
<div class="row">
<div class="col s12 m8 offset-m2 l6 offset-l3 center-align">
<a class="waves-effect waves-light btn blue darken-3" href="admin-edit-subtask.php?taskID=<?php echo $ID;?>"><i
class="material-icons left">add</i>New</a>
</div>
</div>
<div class="row">
<div class="col s12 m10 offset-m1 l8 offset-l2">
<table class="bordered">
<thead>
<tr>
<th data-field="id">ID</th>
<th data-field="project-name">Title</th>
<th data-field="project-name">Status</th>
</tr>
</thead>
<tbody>
<?php
$tasks = $db->getSubtasks($ID);
if($tasks == false)
{
echo '<td colspan="6" class="center-align">No Subtasks</td>';
exit;
}
else
{
for($i = 0; $i < sizeof($tasks); $i++)
{
$status = $tasks[$i]['Status'];
echo '<tr>' .
'<td>' . $tasks[$i]['ID'] . '</td>' .
'<td>' . $tasks[$i]['Title'] . '</td>';
if($status == "0")
{
echo '<td><i class="material-icons red-text">build</i></td>';
}
else
{
echo '<td><i class="material-icons green-text">check</i></td>';
}
echo '<td class="right-align">' .
'<a class="btn-flat no-padding tooltipped" href="admin-edit-subtask.php?id=' . $tasks[$i]['ID'] . '&taskID='. $ID .'&edit=true" data-position="bottom" data-delay="50" data-tooltip="Edit"><i class="material-icons left">edit</i></a>' .
'<a class="btn-flat button-delete-subtask no-padding tooltipped" data-id="' . $tasks[$i]['ID'] . '" data-taskid="' . $ID . '" data-position="bottom" data-delay="50" data-tooltip="Delete"><i class="material-icons left">delete</i></a>' .
'</td>' .
'</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
......@@ -23,7 +23,7 @@ $db->createTables();
$milestone = $db->getMilestone($ID);
if($milestone == false)
{
header('Location: ../error.php?message=error_milestone_not_existing');
header('Location: ../error.php?message=error_task_not_existing');
exit;
}
......
<?php
include_once('../../mysql.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(!isset($_POST['subtask_ID']))
{
echo "error";
exit;
}
$db = new DB();
$db->createTables();
if($db->deleteSubtask($_POST['subtask_ID']) == false)
{
echo "error";
exit;
}
else
{
echo "success";
exit;
}
}
else
{
echo "error";
exit;
}
\ No newline at end of file
<?php
include_once('../../mysql.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(!isset($_POST['edit']))
{
echo "error";
exit;
}
if(!isset($_POST['ID']))
{
echo "error-edit";
exit;
}
if(!isset($_POST['task-ID']))
{
echo "error-edit";
exit;
}
if(!isset($_POST['title']))
{
echo "error-edit";
exit;
}
if(!isset($_POST['description']))
{
echo "error-edit";
exit;
}
if(!isset($_POST['done']))
{
echo "error-edit";
exit;
}
$db = new DB();
$db->createTables();
if($_POST['edit'] == "true")
{
if($db->updateSubtask($_POST['ID'], $_POST['task-ID'], $_POST['title'], $_POST['description'], $_POST['done']) == false)
{
echo "error-edit";
exit;
}
else
{
echo "success";
exit;
}
}
else
{
if($db->insertSubtask($_POST['task-ID'], $_POST['title'], $_POST['description'], $_POST['done']) == false)
{
echo "error-insert";
exit;
}
else
{
echo "success";
exit;
}
}
}
else
{
echo "error";
exit;
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
"error_roadmap_not_existing": "ERROR: no roadmap with this ID existing",
"error_milestone_not_existing": "ERROR: no milestone with this ID existing",
"error_task_not_existing": "ERROR: no task with this ID existing",
"error_subtask_not_existing": "ERROR: no subtask with this ID existing",
"error_no_milestones": "ERROR: no milestones for this roadmap",
"error_database_connection" : "An error occurred while getting data from the server."
}
\ No newline at end of file
......@@ -98,9 +98,8 @@ class DB
return $statement->execute();
}
function insertSubtask($taskID, $title, $description)
function insertSubtask($taskID, $title, $description, $status)
{
$status = "0";
$statement = self::$db->prepare("INSERT INTO subtasks VALUES('', :taskID, :title, :description, :status);");
$statement->bindParam("taskID", $taskID);
$statement->bindParam("title", $title);
......@@ -182,7 +181,6 @@ class DB
$statement = self::$db->prepare("UPDATE subtasks SET TaskID = :taskID, Title = :title, Description = :description, Status = :status WHERE ID = :subtaskID;");
$statement->bindParam("subtaskID", $subtaskID);
$statement->bindParam("taskID", $taskID);
$statement->bindParam("milestoneID", $milestoneID);
$statement->bindParam("title", $title);
$statement->bindParam("description", $description);
$statement->bindParam("status", $status);
......@@ -275,6 +273,15 @@ class DB
return $statement->fetchAll();
}
function getSubtask($taskID)
{
$statement = self::$db->prepare("SELECT * FROM subtasks WHERE subtasks.ID=:taskID;");
$statement->bindParam("taskID", $taskID);
$statement->execute();
return $statement->fetch();
}
function getNumberOfOpenSubtasks($taskID)
{
$statement = self::$db->prepare("SELECT COUNT(*) AS 'count' FROM subtasks WHERE subtasks.TaskID=:taskID AND status = '0';");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment