overview.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 substantial 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. $message = "";
  27. if (isset($_GET['action'])) {
  28. $jobID = $_GET['jobID'];
  29. if ($_GET['action'] == "delete") {
  30. $deletestmt = $db->prepare("DELETE FROM jobs WHERE jobID = ? ");
  31. $deletestmt->execute(array($jobID));
  32. $delete2stmt = $db->prepare("DELETE FROM runs WHERE job = ? ");
  33. $delete2stmt->execute(array($jobID));
  34. $message = "Job was sucessfully deleted";
  35. }
  36. }
  37. if (isset($_GET["message"])) {
  38. $message = "";
  39. switch ($_GET["message"]) {
  40. case "edited":
  41. $message = "The cronjob has been edited"; break;
  42. }
  43. }
  44. $allJobs = $db->prepare("SELECT * FROM jobs WHERE user = ? ORDER BY name ASC");
  45. $allJobs->execute(array($_SESSION["userID"]));
  46. $allJobsResult = $allJobs->fetchAll(PDO::FETCH_ASSOC);
  47. $loader = new Twig_Loader_Filesystem('templates');
  48. $twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
  49. //var_dump($alljobsResult);
  50. //exit;
  51. $allJobsRendered = array();$count = 0;
  52. foreach($allJobsResult as $key=>$value) {
  53. $allJobsRendered[$count]["jobID"] = $value["jobID"];
  54. $allJobsRendered[$count]["name"] = $value["name"];
  55. $allJobsRendered[$count]["host"] = $value["host"];
  56. $allJobsRendered[$count]["nextrun"] = date("d/m/Y H:i:s", $value["nextrun"]);
  57. $allJobsRendered[$count]["norun"] = ($value['nextrun'] > $value['lastrun'] && $value['lastrun'] > 0) ? true : false;
  58. $allJobsRendered[$count]["delay"] = secondsToInterval($value["delay"]);
  59. $count++;
  60. }
  61. $twig_vars = array('jobs' => $allJobsRendered, 'message' => $message);
  62. echo $twig->render('overview.html.twig', $twig_vars);
  63. require_once 'include/finalize.inc.php';
  64. function secondsToInterval($time) {
  65. $days = floor($time / (60 * 60 * 24));
  66. $time -= $days * (60 * 60 * 24);
  67. $hours = floor($time / (60 * 60));
  68. $time -= $hours * (60 * 60);
  69. $minutes = floor($time / 60);
  70. $time -= $minutes * 60;
  71. $seconds = floor($time);
  72. $time -= $seconds;
  73. return "{$days}d {$hours}h {$minutes}m {$seconds}s";
  74. }