webcron/editjob.php

86 lines
3.0 KiB
PHP
Raw Normal View History

2017-04-15 12:58:33 +02:00
<?php
require_once "include/initialize.inc.php";
$jobID = $_GET['jobID'];
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$jobnameqry = $db->prepare("SELECT * FROM jobs WHERE jobID = ?");
$jobnameqry->execute(array($_GET['jobID']));
$jobnameResult = $jobnameqry->fetchAll(PDO::FETCH_ASSOC);
if ($jobnameResult[0]["user"] != $_SESSION["userID"]) {
header("location:/overview.php");
exit;
}
$name = $jobnameResult[0]['name'];
$url = $jobnameResult[0]['url'];
2017-08-18 18:58:04 +02:00
$host = $jobnameResult[0]['host'];
2017-04-15 12:58:33 +02:00
$delay = $jobnameResult[0]['delay'];
2018-05-08 20:45:40 +02:00
$expected = $jobnameResult[0]['expected'];
2019-01-13 13:24:41 +01:00
$nextrun = date("d/m/Y H:i:s", $jobnameResult[0]['nextrun']);
2019-05-24 18:23:14 +02:00
$lastrun = ($jobnameResult[0]['lastrun'] == -1) ? -1 : date("d/m/Y H:i:s", $jobnameResult[0]['lastrun']);
2017-04-15 12:58:33 +02:00
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
$error = "";
2018-09-13 16:11:49 +02:00
if (isset($_GET["error"])) {
2017-04-15 12:58:33 +02:00
switch ($_GET["error"]) {
case "emptyfields":
$error = "Some fields were empty"; break;
case "invalidurl":
$error = "The URL is invalid"; break;
case "invaliddelay":
$error = "The delay is invalid"; break;
}
}
2019-05-24 18:35:12 +02:00
echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "expected" => $expected, 'nextrun' => $nextrun, 'lastrun' => $lastrun, "jobID" => $jobID, "error" => $error));
2017-04-15 12:58:33 +02:00
}
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST['name']) || empty($_POST['url'] || empty($_POST['delay']))) {
2017-05-10 11:35:45 +02:00
header("location:editjob.php?error=emptyfields");
2017-04-15 12:58:33 +02:00
exit;
}
$url = $_POST['url'];
$name = $_POST['name'];
$delay = $_POST['delay'];
2017-08-18 18:58:04 +02:00
$host = $_POST['host'];
2018-05-08 20:45:40 +02:00
$expected = $_POST['expected'];
2019-05-24 18:23:14 +02:00
$eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false;
2019-01-13 13:24:41 +01:00
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
2017-04-15 12:58:33 +02:00
$nextrun = $nextrunObj->getTimestamp();
2019-05-24 18:23:14 +02:00
if (!$eternal) {
$lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']);
2019-05-24 18:41:28 +02:00
$lastrun = $lastrunObj->getTimestamp();
2019-05-24 18:23:14 +02:00
} else {
$lastrun = -1;
}
2017-04-15 12:58:33 +02:00
if(!is_numeric($delay)) {
header("location:editjob.php?jobID=" . $jobID . "&error=invaliddelay");
exit;
}
if(!is_numeric($nextrun)) {
header("location:editjob.php?jobID=" . $jobID . "&error=invalidnextrun");
exit;
}
2019-05-24 18:23:14 +02:00
if(!is_numeric($lastrun)) {
header("location:editjob.php?jobID=" . $jobID . "&error=invalidlastrun");
exit;
}
2017-04-15 12:58:33 +02:00
2019-05-24 18:23:14 +02:00
$stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ?, lastrun = ? WHERE jobID = ?");
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $lastrun, $jobID));
2017-04-15 12:58:33 +02:00
header("location:overview.php?message=edited");
exit;
}
require_once 'include/finalize.inc.php';