123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- // 設置資料類型 json,編碼格式 utf-8
- header('Content-Type: application/json; charset=UTF-8');
-
- // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
- // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
- if ($_SERVER['REQUEST_METHOD'] == "GET") {
- create();
- } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
- create();
- }
- // 新建員工
- function create() {
- if($_POST['SystemDateTime'] != ""){
- if(!validateDate($_POST['SystemDateTime'])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "SystemDateTime format or content error, fill it with 'yyyy-mm-dd hh:ii:ss";
- echo json_encode($jsone);
- return false;
- }
- }
- // checkValue("AcPhaseCount",1);
- // checkValue("FactoryConfiguration",1);
- checkValue("PhaseLossPolicy",2);
- checkValue("AuthorisationMode",2);
- checkValue("isAPP",2);
- checkValue("isQRCode",2);
- checkValue("isRFID",2);
- checkValue("QRCodeMadeMode",2);
- checkValue("RfidCardNumEndian",1);
- checkValue("PsuAcInputType",1);
- // $json = json_decode(file_get_contents("system.txt"), true);
- $json['SystemId'] = $_POST["SystemId"];
- $json['SystemDateTime'] = $_POST['SystemDateTime'];
- $json['PhaseLossPolicy'] = (int)$_POST['PhaseLossPolicy'];
- $json['FactoryConfiguration'] = $_POST['FactoryConfiguration'];
- $json['AuthorisationMode'] = (int)$_POST['AuthorisationMode'];
- $json['isAPP'] = (int)$_POST['isAPP'];
- $json['isQRCode'] = (int)$_POST['isQRCode'];
- $json['isRFID'] = (int)$_POST['isRFID'];
- $json['QRCodeMadeMode'] = (int)$_POST['QRCodeMadeMode'];
- $json['QRCodeContent'] = $_POST['QRCodeContent'];
- $json['RfidCardNumEndian'] = $_POST['RfidCardNumEndian'];
- $json['PsuAcInputType'] = $_POST['PsuAcInputType'];
-
- // ob_start();
- shell_exec('sync;sync;sync');
- chdir("/root");
- $str_json=json_encode($json);//echo $str_json;exit;
- exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
- if(count($output)!=0){
- $jsone['result'] = "Success";
- $jsone['message'] = $json;
- echo json_encode($jsone);
- exit;
- }
- else{
- $jsone['result'] = "Error";
- $jsone['message'] = "Something went wrong on machine";
- echo json_encode($jsone);
- return false;
- exit;
- }
- // ob_end_clean();
- }
-
- function validateDate($date, $format = 'Y-m-d H:i:s')
- {
- $d = DateTime::createFromFormat($format, $date);
- return $d && $d->format($format) == $date;
- }
- function checkValue($id,$idx){
- if($idx==1){
- if($_POST[$id]!=""){
- if(strlen($_POST[$id])!=1){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
- echo json_encode($jsone);
- exit;
- }
- if(!ereg("[0-9]",$_POST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- if($idx==2){
- if($_POST[$id]!=""){
- if(strlen($_POST[$id])!=1){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
- echo json_encode($jsone);
- exit;
- }
- if(!ereg("[0-1]",$_POST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be 0 or 1";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- // if($idx==2){
- // if($_POST[$id]!=""){
- // if(strlen($_POST[$id])>2){
- // $jsone['result'] = "Fail";
- // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- // echo json_encode($jsone);
- // exit;
- // }
- // if(!ereg("[0-9]",$_POST[$id]) & !ereg("[0-9]{2}",$_POST[$id])){
- // $jsone['result'] = "Fail";
- // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- // echo json_encode($jsone);
- // exit;
- // }
- // }
- // }
- }
- ?>
|