set_system_action.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // 設置資料類型 json,編碼格式 utf-8
  3. header('Content-Type: application/json; charset=UTF-8');
  4. // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
  5. // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
  6. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  7. create();
  8. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. create();
  10. }
  11. // 新建員工
  12. function create() {
  13. if($_POST['SystemDateTime'] != ""){
  14. if(!validateDate($_POST['SystemDateTime'])){
  15. $jsone['result'] = "Fail";
  16. $jsone['message'] = "SystemDateTime format or content error, fill it with 'yyyy-mm-dd hh:ii:ss";
  17. echo json_encode($jsone);
  18. return false;
  19. }
  20. }
  21. // checkValue("AcPhaseCount",1);
  22. // checkValue("FactoryConfiguration",1);
  23. checkValue("AuthorisationMode",2);
  24. // checkValue("isAPP",2);
  25. // checkValue("isQRCode",2);
  26. // checkValue("isRFID",2);
  27. // checkValue("QRCodeMadeMode",2);
  28. // checkValue("DefaultLanguage",2);
  29. checkValue("RfidCardNumEndian",1);
  30. checkValue("PsuAcInputType",1);
  31. // $json = json_decode(file_get_contents("system.txt"), true);
  32. $json['SystemId'] = $_POST["SystemId"];
  33. $json['SystemDateTime'] = $_POST['SystemDateTime'];
  34. // $json['AcPhaseCount'] = $_POST['AcPhaseCount'];
  35. $json['FactoryConfiguration'] = $_POST['FactoryConfiguration'];
  36. $json['AuthorisationMode'] = (int)$_POST['AuthorisationMode'];
  37. // $json['isAPP'] = (int)$_POST['isAPP'];
  38. // $json['isQRCode'] = (int)$_POST['isQRCode'];
  39. // $json['isRFID'] = (int)$_POST['isRFID'];
  40. // $json['QRCodeMadeMode'] = (int)$_POST['QRCodeMadeMode'];
  41. // $json['QRCodeContent'] = $_POST['QRCodeContent'];
  42. // $json['DefaultLanguage'] = $_POST['DefaultLanguage'];
  43. $json['RfidCardNumEndian'] = $_POST['RfidCardNumEndian'];
  44. $json['PsuAcInputType'] = $_POST['PsuAcInputType'];
  45. // ob_start();
  46. shell_exec('sync;sync;sync');
  47. chdir("/root");
  48. $str_json=json_encode($json);//echo $str_json;exit;
  49. exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
  50. if(count($output)!=0){
  51. $jsone['result'] = "Success";
  52. $jsone['message'] = $json;
  53. echo json_encode($jsone);
  54. exit;
  55. }
  56. else{
  57. $jsone['result'] = "Error";
  58. $jsone['message'] = "Something went wrong on machine";
  59. echo json_encode($jsone);
  60. return false;
  61. exit;
  62. }
  63. // ob_end_clean();
  64. }
  65. function validateDate($date, $format = 'Y-m-d H:i:s')
  66. {
  67. $d = DateTime::createFromFormat($format, $date);
  68. return $d && $d->format($format) == $date;
  69. }
  70. function checkValue($id,$idx){
  71. if($idx==1){
  72. if($_POST[$id]!=""){
  73. if(strlen($_POST[$id])!=1){
  74. $jsone['result'] = "Fail";
  75. $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
  76. echo json_encode($jsone);
  77. exit;
  78. }
  79. if(!ereg("[0-9]",$_POST[$id])){
  80. $jsone['result'] = "Fail";
  81. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  82. echo json_encode($jsone);
  83. exit;
  84. }
  85. }
  86. }
  87. if($idx==2){
  88. if($_POST[$id]!=""){
  89. if(strlen($_POST[$id])!=1){
  90. $jsone['result'] = "Fail";
  91. $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
  92. echo json_encode($jsone);
  93. exit;
  94. }
  95. if(!ereg("[0-1]",$_POST[$id])){
  96. $jsone['result'] = "Fail";
  97. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be 0 or 1";
  98. echo json_encode($jsone);
  99. exit;
  100. }
  101. }
  102. }
  103. // if($idx==2){
  104. // if($_POST[$id]!=""){
  105. // if(strlen($_POST[$id])>2){
  106. // $jsone['result'] = "Fail";
  107. // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  108. // echo json_encode($jsone);
  109. // exit;
  110. // }
  111. // if(!ereg("[0-9]",$_POST[$id]) & !ereg("[0-9]{2}",$_POST[$id])){
  112. // $jsone['result'] = "Fail";
  113. // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  114. // echo json_encode($jsone);
  115. // exit;
  116. // }
  117. // }
  118. // }
  119. }
  120. ?>