config.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * The MIT License
  4. *
  5. * Copyright 2017-2018 Jeroen De Meerleer <me@jeroened.be>.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantia²l portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. require_once "include/initialize.inc.php";
  26. if ($_SERVER["REQUEST_METHOD"] == "GET") {
  27. $message = "";
  28. if (isset($_GET["message"])) {
  29. switch ($_GET["message"]) {
  30. case "edited":
  31. $message = "The config has been edited"; break;
  32. }
  33. }
  34. $error = "";
  35. if (isset($_GET["error"])) {
  36. switch ($_GET["error"]) {
  37. case "emptyfields":
  38. $error = "Some fields were empty"; break;
  39. }
  40. }
  41. $loader = new Twig_Loader_Filesystem('templates');
  42. $twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
  43. $configs = load_config_categorized();
  44. $twig_vars = array('config' => $configs, "error" => $error, "message" => $message);
  45. echo $twig->render('config.html.twig', $twig_vars);
  46. }
  47. elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
  48. foreach($_POST as $key => $value) {
  49. if (empty($value)) {
  50. header("location:config.php?error=emptyfields"); exit;
  51. }
  52. $keydb = str_replace('_', '.', $key);
  53. $stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?");
  54. $stmt->execute(array($value, $keydb));
  55. }
  56. header("location:config.php?message=edited");
  57. exit;
  58. }
  59. require_once 'include/finalize.inc.php';