diff --git a/controllers/Qcar3.php b/controllers/Qcar3.php new file mode 100644 index 0000000..d2e21b6 --- /dev/null +++ b/controllers/Qcar3.php @@ -0,0 +1,126 @@ +load->model('qcar3_model'); + } + + + // 發生錯誤時集中在此處理 + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) + { + $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n"; + //error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名 + error_log($str, 3, LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名 + } + + + // 顯示靜態網頁(html檔) + protected function show_page($page_name, &$data = null) + { + $page_file = PAGE_PATH.$page_name.'.php'; + $last_modified_time = filemtime($page_file); + + // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁 + // header('Cache-Control:max-age='.MAX_AGE); // cache 1個月 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT'); + header('Etag: '. APP_VERSION); + header('Cache-Control: public'); + + if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time) + { + header('HTTP/1.1 304 Not Modified'); + } + else + { + $this->load->view(APP_NAME.'/'.$page_name, $data); + } + } + + + public function index() + { + $this->show_page('main_page'); // 1122x630 + } + + // 顯示logs + public function show_logs() + { + $lines = $this->uri->segment(3); // 顯示行數 + if (empty($lines)) $lines = 40; // 無行數參數, 預設為40行 + + // echo '
';
+        echo '
';
+		passthru('/usr/bin/tail -n ' . $lines . '  ' . LOG_FILE);		// 利用linux指令顯示倒數幾行的logs內容 
+        echo "\n----- " . LOG_FILE . ' -----';   
+        echo '
'; + } + + // 車位查詢結果頁 + public function show_result() + { + $lpr = $this->uri->segment(3); // 車牌號碼 + $data = $this->qcar3_model->q_pks($lpr); + $data['lpr'] = strtoupper($lpr); + $this->show_page('result_page', $data); // 1280x1080 + } + + // 車位查詢結果頁 (2) + public function show_result2() + { + $lpr = $this->uri->segment(3); // 車牌號碼 + $data = $this->qcar3_model->q_pks($lpr); + $data['lpr'] = strtoupper($lpr); + $this->show_page('result_page2', $data); // 2560x1440 + } + + // 車位查詢 + public function q_pks() + { + $lpr = $this->input->post('lpr', true); + $data = $this->qcar3_model->q_pks($lpr); + echo json_encode($data, JSON_UNESCAPED_UNICODE); + } + + // 取得進場資訊 (模糊比對) + public function q_fuzzy_pks() + { + $input = $this->input->post('fuzzy_input', true); + $data = $this->qcar3_model->q_fuzzy_pks($input); + echo json_encode($data, JSON_UNESCAPED_UNICODE); + } + +} diff --git a/models/Qcar3_model.php b/models/Qcar3_model.php new file mode 100644 index 0000000..72edb14 --- /dev/null +++ b/models/Qcar3_model.php @@ -0,0 +1,147 @@ +load->database(); + } + + // 查車 + public function q_pks($lpr) + { + $sql = "select p.pksno, p.pic_name, p.update_time, p.in_time, p.posx, p.posy, m.group_id, g.group_name, g.floors + from pks p, pks_group_member m, pks_groups g + where p.pksno = m.pksno + and m.group_id = g.group_id + and g.group_type = 1 + and p.lpr = '{$lpr}' + limit 1"; + $rows = $this->db->query($sql)->row_array(); + + //if (!empty($rows['pic_name'])) $rows['pic_name'] = str_replace('.jpg', '', $rows['pic_name']); + //else $rows['pksno'] = 0; // 如無該筆資料, 車位號碼設為0 + + return $rows; + } + + // 模糊比對 + function getLevenshteinSQLStatement($word, $target) + { + $words = array(); + + if(strlen($word) >= 5) + { + for ($i = 0; $i < strlen($word); $i++) { + // insertions + $words[] = substr($word, 0, $i) . '_' . substr($word, $i); + // deletions + $words[] = substr($word, 0, $i) . substr($word, $i + 1); + // substitutions + //$words[] = substr($word, 0, $i) . '_' . substr($word, $i + 1); + } + } + else + { + for ($i = 0; $i < strlen($word); $i++) { + // insertions + $words[] = substr($word, 0, $i) . '_' . substr($word, $i); + } + } + + // last insertion + $words[] = $word . '_'; + //return $words; + + $fuzzy_statement = ' ('; + foreach ($words as $idx => $word) + { + $fuzzy_statement .= " {$target} LIKE '%{$word}%' OR "; + } + $last_or_pos = strrpos($fuzzy_statement, 'OR'); + if($last_or_pos !== false) + { + $fuzzy_statement = substr_replace($fuzzy_statement, ')', $last_or_pos, strlen('OR')); + } + + return $fuzzy_statement; + } + + // 取得進場資訊 (模糊比對) + public function q_fuzzy_pks($word) + { + if(empty($word) || strlen($word) <= 0 || strlen($word) > 10) + { + return null; + } + + $sql = "SELECT station_no, lpr, in_time, pic_name as pks_pic_name + FROM pks + WHERE {$this->getLevenshteinSQLStatement($word, 'lpr')} + ORDER BY lpr ASC"; + $retults = $this->db->query($sql)->result_array(); + + if(count($retults) > 0) + { + foreach ($retults as $idx => $rows) + { + $pks_pic_path = ''; + if(!empty($rows['pks_pic_name'])) + { + //$pks_pic_path = APP_URL.'pks_pics/'.str_replace('.jpg', '', $rows['pks_pic_name']); + $pks_pic_path = SERVER_URL.'pkspic/'.$rows['pks_pic_name']; + } + + $data['result'][$idx] = array + ( + 'lpr'=> $rows['lpr'], + 'pks_pic_path' => $pks_pic_path, + 'station_no' => $rows['station_no'], + 'in_time' => $rows['in_time'] + ); + } + } + /* + else + { + // 讀取入場資料 + $sql = "SELECT cario.station_no as station_no, cario.obj_id as lpr, cario.in_time as in_time, cario.in_pic_name as pks_pic_name + FROM cario + WHERE {$this->getLevenshteinSQLStatement($word, 'obj_id')} + AND in_out = 'CI' AND finished = 0 AND err = 0 AND out_time IS NULL + ORDER BY lpr ASC"; + // AND in_time > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 5 DAY) + $retults = $this->db->query($sql)->result_array(); + + if(count($retults) > 0) + { + foreach ($retults as $idx => $rows) + { + $pks_pic_path = ''; + if(!empty($rows['pks_pic_name'])) + { + $pic_name = str_replace('.jpg', '', $rows['pks_pic_name']); + $arr = explode('-', $pic_name); + //$pks_pic_path = SERVER_URL.'carspic/'.substr($arr[7], 0, 8).'/'.$pic_name.'.jpg'; + $pks_pic_path = SERVER_URL.'carpic/'.substr($arr[7], 0, 8).'/'.$pic_name.'.jpg'; + } + + $data['result'][$idx] = array + ( + 'lpr'=> $rows['lpr'], + 'pks_pic_path' => $pks_pic_path, + 'station_no' => $rows['station_no'], + 'in_time' => $rows['in_time'] + ); + } + } + } + */ + return $data; + } + +} diff --git a/views/qcar3/main_page.php b/views/qcar3/main_page.php new file mode 100644 index 0000000..1f657c7 --- /dev/null +++ b/views/qcar3/main_page.php @@ -0,0 +1,472 @@ + + + + + + + + + 歐特儀自動化服務機 + + + + + + + + + + + + + + + +
+ +
+
+
+ +   +
+ +
+ + + +
+
+
+
+ 車位查詢 +
+
+
+
+
+
+ +
+ +    + +    + +    + +
+
+
+ +
+ + + + + + + +
+ +
+ +
+ +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/views/qcar3/result_page.php b/views/qcar3/result_page.php new file mode 100644 index 0000000..9cad94b --- /dev/null +++ b/views/qcar3/result_page.php @@ -0,0 +1,440 @@ + + + + + + + + + 歐特儀自動化服務機 + + + + + + + + + + + + + + + +
+ +
+
+
+ +   +
+
+ + + +
+
+
+
+ 查車結果:查無 在席資料 +
+
+
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/views/qcar3/result_page2.php b/views/qcar3/result_page2.php new file mode 100644 index 0000000..95a108a --- /dev/null +++ b/views/qcar3/result_page2.php @@ -0,0 +1,475 @@ + + + + + + + + + 歐特儀自動化服務機 + + + + + + + + + + + + + + + +
+ +
+
+
+ +   +
+ +
+ + + +
+
+
+
+ 查車結果:查無 在席資料 +
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +