index-file.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. define('DS', DIRECTORY_SEPARATOR);
  3. define('APP_PATH_ROOT', dirname(__FILE__));
  4. define('APP_PATH_LIB', APP_PATH_ROOT . '/se-lib');
  5. define('APP_PATH_WWW', APP_PATH_ROOT);
  6. define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
  7. session_start();
  8. date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
  9. error_reporting(1);
  10. ini_set('error_reporting', 1);
  11. ini_set('display_startup_errors','1');
  12. //display_startup_errors(0);
  13. #TEST $_SESSION['DEBUG'] = 3;// TODO: TEST
  14. if (!isset($_SESSION['DEBUG'])) $_SESSION['DEBUG'] = 0;// set default value
  15. if (file_exists(APP_PATH_ROOT . "/config/.config_{$_SERVER['SERVER_NAME']}.php")) {
  16. require APP_PATH_ROOT . "/config/.config_{$_SERVER['SERVER_NAME']}.php";
  17. }
  18. if (file_exists(APP_PATH_ROOT . "/.config.php")) include APP_PATH_ROOT . "/.config.php";
  19. require_once APP_PATH_ROOT . "/superedit-SEF.php";
  20. SEF('DEBUG_S');
  21. require_once APP_PATH_LIB . '/' . 'Lib.php';
  22. Lib::loadClass('V');
  23. Lib::loadClass('DB');
  24. Lib::loadClass('User');
  25. Lib::loadClass('S');
  26. Lib::loadClass('Http');
  27. Lib::loadClass('HttpException');
  28. if (!User::logged()) {
  29. Http::sendHeaderByCode(401);
  30. exit;
  31. }
  32. /* example:
  33. [zasobID] => 636
  34. [id] => 2773
  35. [file] => 2014-07-11_wizytowki_michal_zaleski_wzor_bn2.bcard/Screen Shot 2014-07-11 at 15.58.15.png
  36. */
  37. $zasobID = V::get('zasobID', 0, $_GET, 'int');
  38. $recordID = V::get('id', 0, $_GET, 'int');
  39. $fileName = V::get('file', '', $_GET);
  40. if (!$zasobID || !$recordID || empty($fileName)) {
  41. Http::sendHeaderByCode(406);
  42. exit;
  43. }
  44. if (false !== strpos($fileName, '../')) {
  45. Http::sendHeaderByCode(403);
  46. die('..');
  47. }
  48. $userAcl = User::getAcl();
  49. $tblAcl = $userAcl->getTableAcl($zasobID);
  50. if (!$tblAcl->isInitialized()) {
  51. Http::sendHeaderByCode(404);
  52. die("Brak konfiguracji dla ".$tblAcl->getName()."!");
  53. }
  54. Lib::loadClass('TableAjax');
  55. if (!class_exists('TableAjax')) {
  56. Http::sendHeaderByCode(404);
  57. die('Error: cls not exists TableAjax');
  58. }
  59. $tblObj = new TableAjax($tblAcl);
  60. try {
  61. $tblObj->sendFileContent($recordID, $fileName);
  62. }
  63. catch (HttpException $e) {
  64. Http::sendHeaderByCode($e->getCode());
  65. header('Content-Type: text/html; charset=utf-8');
  66. echo $e->getMessage();
  67. }
  68. catch (Exception $e) {
  69. header('Content-Type: text/html; charset=utf-8');
  70. echo 'Error ' . $e->getCode() . ':' . $e->getMessage();
  71. }