webcron/config.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2018-09-13 12:38:12 +02:00
<?php
require_once "include/initialize.inc.php";
if ($_SERVER["REQUEST_METHOD"] == "GET") {
2018-09-14 12:25:10 +02:00
$message = "";
if (isset($_GET["message"])) {
switch ($_GET["message"]) {
case "edited":
$message = "The config has been edited"; break;
}
}
$error = "";
2018-09-13 12:38:12 +02:00
if (isset($_GET["error"])) {
switch ($_GET["error"]) {
case "emptyfields":
$error = "Some fields were empty"; break;
}
}
2018-09-14 12:25:10 +02:00
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
2018-09-13 12:38:12 +02:00
2018-09-14 12:25:10 +02:00
$configs = load_config_categorized();
2018-09-13 12:38:12 +02:00
2018-09-14 12:25:10 +02:00
$twig_vars = array('config' => $configs, "error" => $error, "message" => $message);
2018-09-13 12:38:12 +02:00
2018-09-14 12:25:10 +02:00
echo $twig->render('config.html.twig', $twig_vars);
2018-09-13 12:38:12 +02:00
}
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
2018-09-14 12:25:10 +02:00
foreach($_POST as $key => $value) {
if (empty($value)) {
header("location:config.php?error=emptyfields"); exit;
}
2018-09-13 12:38:12 +02:00
2018-09-14 12:25:10 +02:00
$keydb = str_replace('_', '.', $key);
$stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?");
$stmt->execute(array($value, $keydb));
}
2018-09-13 12:38:12 +02:00
2018-09-14 12:25:10 +02:00
header("location:config.php?message=edited");
2018-09-13 12:38:12 +02:00
exit;
}
require_once 'include/finalize.inc.php';