webcron/webcron.old/addjob.php

75 lines
2.3 KiB
PHP
Raw Normal View History

2017-04-14 15:58:09 +02:00
<?php
require_once "include/initialize.inc.php";
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
$error = "";
2018-09-14 15:16:00 +02:00
if (isset($_GET["error"])) {
2017-04-14 15:58:09 +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;
}
}
$message = "";
2018-09-14 15:16:00 +02:00
if (isset($_GET["message"])) {
2017-04-14 15:58:09 +02:00
switch ($_GET["message"]) {
case "added":
$message = "The cronjob has been added"; break;
}
}
echo $twig->render('addjob.html.twig', array("message" => $message, "error" => $error));
}
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST['name']) || empty($_POST['url'] || empty($_POST['delay']))) {
header("location:addjob.php?error=emptyfields");
exit;
}
$url = $_POST['url'];
2017-08-18 18:58:04 +02:00
$host = $_POST['host'];
2017-04-14 15:58:09 +02:00
$name = $_POST['name'];
$delay = $_POST['delay'];
2018-05-08 20:45:40 +02:00
$expected = $_POST['expected'];
2019-05-24 18:23:23 +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 11:37:54 +02:00
$nextrun = $nextrunObj->getTimestamp();
2019-05-24 18:23:23 +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:23 +02:00
} else {
$lastrun = -1;
}
2017-04-14 15:58:09 +02:00
if(!is_numeric($delay)) {
header("location:addjob.php?error=invaliddelay");
exit;
}
2017-04-15 11:37:54 +02:00
if(!is_numeric($nextrun)) {
header("location:addjob.php?error=invalidnextrun");
exit;
}
2019-05-24 18:23:23 +02:00
if(!is_numeric($lastrun)) {
header("location:addjob.php?error=invalidlastrun");
exit;
}
2017-04-14 15:58:09 +02:00
2018-05-08 20:45:40 +02:00
$stmt = $db->prepare("INSERT INTO jobs(user, name, url, host, delay, nextrun, expected) VALUES(?, ?, ?, ?, ?, ?, ?)");
$stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun, $expected));
2017-04-14 15:58:09 +02:00
header("location:addjob.php?message=added");
exit;
}
require_once 'include/finalize.inc.php';