Added delete function

This commit is contained in:
Jeroen De Meerleer 2017-04-15 11:00:32 +02:00
parent d14da69d48
commit a14da30879
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 39 additions and 3 deletions

View File

@ -26,6 +26,18 @@
require_once "include/initialize.inc.php";
$message = "";
if (isset($_GET['action'])) {
$jobID = $_GET['jobID'];
if ($_GET['action'] == "delete") {
$deletestmt = $db->prepare("DELETE FROM jobs WHERE jobID = ? ");
$deletestmt->execute(array($jobID));
$delete2stmt = $db->prepare("DELETE FROM runs WHERE job = ? ");
$delete2stmt->execute(array($jobID));
$message = "Job was sucessfully deleted";
}
}
$allJobs = $db->prepare("SELECT * FROM jobs WHERE user = ?");
$allJobs->execute(array($_SESSION["userID"]));
$allJobsResult = $allJobs->fetchAll(PDO::FETCH_ASSOC);
@ -46,7 +58,7 @@ foreach($allJobsResult as $key=>$value) {
$count++;
}
$twig_vars = array('jobs' => $allJobsRendered);
$twig_vars = array('jobs' => $allJobsRendered, 'message' => $message);
//echo $twig->render('overview.html.twig', array('the' => 'variables', 'go' => 'here'));
echo $twig->render('overview.html.twig', $twig_vars);

View File

@ -1,10 +1,34 @@
{% extends "base.html.twig" %}
{% block content %}
<h2>Overview of your cronjobs</h2>
{% if not message == "" %}
<div class="alert alert-success fade in">
<a href="#" class="close" data-dismiss="alert">&times;</a>
{{ message }}
</div>
{% endif %}
<table class="table">
<tr><th>ID</th><th>Name</th><th>Delay</th><th>Next run</th><th></th></tr>
<tr>
<th>ID</th>
<th>Name</th>
<th>Delay</th>
<th>Next run</th>
<th></th>
</tr>
{% for job in jobs %}
<tr><td>{{ job.jobID }}</td><td>{{ job.name }}</td><td>{{ job.delay }}</td><td>{{ job.nextrun }}</td><td><a href="runs.php?jobID={{ job.jobID }}">View runs</a></tr>
<tr>
<td>{{ job.jobID }}</td>
<td>{{ job.name }}</td>
<td>{{ job.delay }}</td>
<td>{{ job.nextrun }}</td>
<td>
<div class="btn-group" role="group" aria-label="...">
<a href="runs.php?jobID={{ job.jobID }}" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></a>
<a href="overview.php?jobID={{ job.jobID }}&action=edit" class="btn btn-default"><span class="glyphicon glyphicon-edit"><span></a>
<a onclick="return confirm('Are you sure you want to delete this job?')" href="overview.php?jobID={{ job.jobID }}&action=delete" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
</div>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}