runs.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. $jobnameqry = $db->prepare("SELECT name, user, url FROM jobs WHERE jobID = ?");
  27. $jobnameqry->execute(array($_GET['jobID']));
  28. $jobnameResult = $jobnameqry->fetchAll(PDO::FETCH_ASSOC);
  29. if ($jobnameResult[0]["user"] != $_SESSION["userID"]) {
  30. header("location:/overview.php");
  31. exit;
  32. }
  33. $jobName = $jobnameResult[0]['name'];
  34. $rebootjob = strpos($jobnameResult[0]["url"],"reboot") === 0 ? true : false;
  35. $runsForJobQry = "SELECT runs.*, jobs.jobID FROM runs, jobs WHERE runs.job = jobs.jobID AND runs.job = ?";
  36. $allruns = true;
  37. if(!(isset($_GET['allruns']) && $_GET['allruns'] == 1)) {
  38. $runsForJobQry .= " AND runs.statuscode <> jobs.expected";
  39. $allruns = false;
  40. }
  41. $runsForJob = $db->prepare($runsForJobQry);
  42. $runsForJob->execute(array($_GET['jobID']));
  43. $runsForJobResult = $runsForJob->fetchAll(PDO::FETCH_ASSOC);
  44. $loader = new Twig_Loader_Filesystem('templates');
  45. $twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
  46. $runsForJobRendered = array();$count = 0;
  47. foreach($runsForJobResult as $key=>$value) {
  48. $runsForJobRendered[$count]["runID"] = $value["runID"];
  49. $runsForJobRendered[$count]["statuscode"] = $value["statuscode"];
  50. $runsForJobRendered[$count]["result"] = $value["result"];
  51. $runsForJobRendered[$count]["timestamp"] = date("d/m/Y H:i:s", $value["timestamp"]);
  52. $count++;
  53. }
  54. $twig_vars = array('jobID' => $_GET['jobID'], 'rebootjob' => $rebootjob, 'runs' => $runsForJobRendered, 'allruns' => $allruns, "title" => $jobName);
  55. //echo $twig->render('overview.html.twig', array('the' => 'variables', 'go' => 'here'));
  56. echo $twig->render('runs.html.twig', $twig_vars);
  57. require_once 'include/finalize.inc.php';