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.
82 lines
3.2 KiB
82 lines
3.2 KiB
<?php
|
|
date_default_timezone_set("Asia/Taipei");
|
|
function save_log_response($key, $pid, $account, $longitude, $latitude, $response_result){
|
|
# 儲存紀錄並輸出
|
|
#echo date("Y-m-d");
|
|
$file_path = "location_log/" . $account . "-" . date("Y-m-d") . ".ini";
|
|
$data = $key . ";" . $pid . ";" . date("H:i:s") . ";" . $longitude . ";" . $latitude . "\n";
|
|
$fp = fopen($file_path,"a"); # 如果檔案不存在擇嘗試建立再寫入
|
|
fwrite($fp, $data);
|
|
fclose($fp);
|
|
|
|
/*
|
|
$sql = "INSERT INTO location_log (account_id, privatekey, name, pid, latitude, longitude, upload_time) values " .
|
|
"('$account', '$key', '$name', '$pid', '$latitude', '$longitude', '$upload_time')";
|
|
mysqli_query($link,$sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
mysqli_close($link); #代表結束連線
|
|
*/
|
|
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
header('Content-type:text/json');
|
|
$upload_time_period = 300; # 預設XXX秒回傳一次
|
|
$key = $_REQUEST["key"];
|
|
$account = $_REQUEST["account"];
|
|
$pid = $_REQUEST["pid"];
|
|
$longitude = $_REQUEST["longitude"]; #經度
|
|
$latitude = $_REQUEST["latitude"]; #緯度
|
|
|
|
#修訂APP誤傳經緯度問題
|
|
if ((double)$latitude >= 90){
|
|
$temp = $longitude;
|
|
$longitude = $latitude;
|
|
$latitude = $temp;
|
|
}
|
|
|
|
|
|
if (($key != NULL) and ($account != NULL) and ($pid != NULL)) {
|
|
if (($longitude != NULL) and ($latitude != NULL)) {
|
|
#回覆結果
|
|
$response_result = array(
|
|
"result_code" => "1",
|
|
"upload_time_period" => $upload_time_period,
|
|
"note" => "none"
|
|
);
|
|
#將位置存入個人log檔回傳結果
|
|
save_log_response($key, $pid, $account, $longitude, $latitude, $response_result);
|
|
|
|
#將位置存入數據庫
|
|
require_once "db/database.php"; # 載入db.php來連結資料庫
|
|
$data = array(); # 設置一個空陣列來放資料is
|
|
$sql = "SELECT * FROM account where (accountid = '$account')"; # sql語法存在變數中
|
|
$data = mysqli_query($link,$sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
foreach($data as $data){
|
|
$accounttype = $data['accounttype'];
|
|
$name = $data['name'];
|
|
}
|
|
if ((strlen($accounttype) != 0) and ($accounttype == 'B')){ #保養員屬性才將位置存入
|
|
#echo "<br> pid: " . $pid;
|
|
#echo "<br> accounttype: " . $accounttype;
|
|
#echo "<br> account: " . $account;
|
|
#echo "<br> name: " . $name;
|
|
#echo "<br> update_time: " . date('Y-m-d H:i:s');
|
|
$upload_time = date('Y-m-d H:i:s');
|
|
$sql = "UPDATE location_last set pid = '$pid', name = '$name', latitude = '$latitude', longitude = '$longitude', upload_time = '$upload_time' WHERE account_id='$account'";
|
|
mysqli_query($link,$sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
|
|
$sql_1 = "INSERT INTO location_log (account_id, privatekey, name, pid, latitude, longitude, upload_time) values " .
|
|
"('$account', '$key', '$name', '$pid', '$latitude', '$longitude', '$upload_time')";
|
|
mysqli_query($link,$sql_1); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
mysqli_close($link); #代表結束連線
|
|
}
|
|
}
|
|
else {
|
|
$response_result = array(
|
|
"result_code" => "0",
|
|
"note" => "Need to be fixed!"
|
|
);
|
|
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
|
|
};
|
|
};
|
|
|
|
?>
|