VM暫存
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 line
4.7KB

  1. <?php
  2. /*
  3. file: qcar3.php 查車系統3
  4. */
  5. if (!defined('BASEPATH')) exit('No direct script access allowed');
  6. // ----- 定義常數(路徑, cache秒數) -----
  7. define('APP_VERSION', '100'); // 版本號
  8. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  9. define('APP_NAME', 'qcar3'); // 應用系統名稱
  10. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  11. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  12. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  13. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  14. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  15. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  16. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  17. class Qcar3 extends CI_Controller
  18. {
  19. var $vars = array(); // 共用變數
  20. function __construct()
  21. {
  22. parent::__construct();
  23. // ----- 程式開發階段log設定 -----
  24. if (@ENVIRONMENT == 'development')
  25. {
  26. ini_set('display_errors', '1');
  27. //error_reporting(E_ALL ^ E_NOTICE);
  28. error_reporting(E_ALL);
  29. }
  30. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  31. $this->load->model('qcar3_model');
  32. }
  33. // 發生錯誤時集中在此處理
  34. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  35. {
  36. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  37. //error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  38. error_log($str, 3, LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  39. }
  40. // 顯示靜態網頁(html檔)
  41. protected function show_page($page_name, &$data = null)
  42. {
  43. $page_file = PAGE_PATH.$page_name.'.php';
  44. $last_modified_time = filemtime($page_file);
  45. // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁
  46. // header('Cache-Control:max-age='.MAX_AGE); // cache 1個月
  47. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT');
  48. header('Etag: '. APP_VERSION);
  49. header('Cache-Control: public');
  50. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  51. {
  52. header('HTTP/1.1 304 Not Modified');
  53. }
  54. else
  55. {
  56. $this->load->view(APP_NAME.'/'.$page_name, $data);
  57. }
  58. }
  59. public function index()
  60. {
  61. $this->show_page('main_page'); // 1122x630
  62. }
  63. // 顯示logs
  64. public function show_logs()
  65. {
  66. $lines = $this->uri->segment(3); // 顯示行數
  67. if (empty($lines)) $lines = 40; // 無行數參數, 預設為40行
  68. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  69. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  70. passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_FILE); // 利用linux指令顯示倒數幾行的logs內容
  71. echo "\n----- " . LOG_FILE . ' -----';
  72. echo '</pre></body></html>';
  73. }
  74. // 車位查詢結果頁
  75. public function show_result()
  76. {
  77. $lpr = $this->uri->segment(3); // 車牌號碼
  78. $data = $this->qcar3_model->q_pks($lpr);
  79. $data['lpr'] = strtoupper($lpr);
  80. $this->show_page('result_page', $data); // 1280x1080
  81. }
  82. // 車位查詢結果頁 (2)
  83. public function show_result2()
  84. {
  85. $lpr = $this->uri->segment(3); // 車牌號碼
  86. $data = $this->qcar3_model->q_pks($lpr);
  87. $data['lpr'] = strtoupper($lpr);
  88. $this->show_page('result_page2', $data); // 2560x1440
  89. }
  90. // 車位查詢
  91. public function q_pks()
  92. {
  93. $lpr = $this->input->post('lpr', true);
  94. $data = $this->qcar3_model->q_pks($lpr);
  95. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  96. }
  97. // 取得進場資訊 (模糊比對)
  98. public function q_fuzzy_pks()
  99. {
  100. $input = $this->input->post('fuzzy_input', true);
  101. $data = $this->qcar3_model->q_fuzzy_pks($input);
  102. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  103. }
  104. }