index.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Public Printer Control System
  4. *
  5. * Copyright © 2018 - 2019, Aaron Speer, aaron.speerfamily.ie ajamesspeer@gmail.com.
  6. * All Rights Reserved.
  7. */
  8. exec("find tmp -mmin +4 | sed 's/\s/\\&/g' | xargs rm -rf");
  9. exec("mkdir tmp");
  10. // awkward command to clear files older then 4 minutes from tmp
  11. use App\Controllers\HomeController;
  12. use App\Controller;
  13. //use App\Models\HomeModel;
  14. $error_reporting = 1; // 1 = errors 0 = none
  15. if ($error_reporting == 1){
  16. ini_set('display_errors', 1);
  17. ini_set('display_startup_errors', 1);
  18. error_reporting(E_ALL);}
  19. session_start();
  20. $_SESSION["messages"] = null;
  21. if (array_key_exists("messages", $_COOKIE)) {
  22. }
  23. else{
  24. $_COOKIE["messages"] = null;
  25. }
  26. require(__DIR__ . "/../vendor/autoload.php");
  27. global $config;
  28. $config = parse_ini_file(__DIR__ . "/../config/config.php");
  29. $loader = new Twig_Loader_Filesystem(__DIR__ . "/../views/");
  30. $twig = new Twig_Environment($loader);
  31. $twig->addGlobal('config', $config);
  32. require(__DIR__ . "/../app/View.php");
  33. $router = new AltoRouter();
  34. $router->setBasePath('');
  35. $router->map('GET','/', "App\Controllers\HomeController#index", 'home');
  36. $router->map('GET|POST','/upload', "App\Controllers\HomeController#upload", 'upload');
  37. $router->map('GET|POST','/printt', "App\Controllers\HomeController#print", 'print');
  38. $match = $router->match();
  39. list( $controller, $action ) = explode( '#', $match['target'] );
  40. if ( is_callable(array($controller, $action)) ) {
  41. $obj = new $controller($twig);
  42. call_user_func_array(array($obj,$action), array($match['params']));
  43. } else if ($match['target']==''){
  44. echo 'Error: no route was matched';
  45. //possibly throw a 404 error
  46. } else {
  47. echo 'Error: can not call '.$controller.'#'.$action;
  48. //possibly throw a 404 error
  49. }