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.

105 lines
4.3KB

  1. <?php
  2. /*
  3. file: Txdata.php 交易資訊系統
  4. */
  5. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  6. class Txdata extends CI_Controller
  7. {
  8. var $vars = array(); // 共用變數
  9. function __construct()
  10. {
  11. parent::__construct();
  12. // ----- 程式開發階段log設定 -----
  13. if (@ENVIRONMENT == 'development')
  14. {
  15. ini_set('display_errors', '1');
  16. //error_reporting(E_ALL ^ E_NOTICE);
  17. error_reporting(E_ALL);
  18. }
  19. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  20. /*
  21. // 共用記憶體
  22. $this->vars['mcache'] = new Memcache;
  23. $this->vars['mcache']->connect(MEMCACHE_HOST, MEMCACHE_PORT) or die ('Could not connect memcache');
  24. // mqtt subscribe
  25. $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid());
  26. if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); }
  27. */
  28. // ----- 定義常數(路徑, cache秒數) -----
  29. define('APP_VERSION', '100'); // 版本號
  30. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  31. define('APP_NAME', 'txdata'); // 應用系統名稱
  32. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  33. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  34. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  35. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  36. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  37. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  38. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  39. $this->load->model('txdata_model');
  40. // $this->parkingquery_model->init($this->vars);
  41. }
  42. // 發生錯誤時集中在此處理
  43. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  44. {
  45. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  46. //error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  47. error_log($str, 3, LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  48. }
  49. // 顯示靜態網頁(html檔)
  50. protected function show_page($page_name, &$data = null)
  51. {
  52. $page_file = PAGE_PATH.$page_name.'.php';
  53. $last_modified_time = filemtime($page_file);
  54. // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁
  55. // header('Cache-Control:max-age='.MAX_AGE); // cache 1個月
  56. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT');
  57. header('Etag: '. APP_VERSION);
  58. header('Cache-Control: public');
  59. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  60. {
  61. header('HTTP/1.1 304 Not Modified');
  62. }
  63. else
  64. {
  65. $this->load->view(APP_NAME.'/'.$page_name, $data);
  66. }
  67. }
  68. // 取得場站費率設定
  69. // http://203.75.167.89/txdata.html/get_price_plan/12112/0
  70. public function get_price_plan()
  71. {
  72. $station_no = $this->uri->segment(3);
  73. $tx_type = $this->uri->segment(4);
  74. $data = $this->txdata_model->get_price_plan($station_no, $tx_type);
  75. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  76. }
  77. // 取得特殊日期設定
  78. // http://203.75.167.89/txdata.html/get_date_plan/12345678/23456789
  79. public function get_date_plan()
  80. {
  81. $inTime = $this->uri->segment(3);
  82. $balanceTime = $this->uri->segment(4);
  83. $data = $this->txdata_model->get_date_plan($inTime, $balanceTime);
  84. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  85. }
  86. }