set_system_action.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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("RfidCardNumEndian",1);
  29. checkValue("PsuAcInputType",1);
  30. // $json = json_decode(file_get_contents("system.txt"), true);
  31. $json['SystemId'] = $_POST["SystemId"];
  32. $json['SystemDateTime'] = $_POST['SystemDateTime'];
  33. // $json['AcPhaseCount'] = $_POST['AcPhaseCount'];
  34. $json['FactoryConfiguration'] = $_POST['FactoryConfiguration'];
  35. $json['AuthorisationMode'] = (int)$_POST['AuthorisationMode'];
  36. $json['isAPP'] = (int)$_POST['isAPP'];
  37. $json['isQRCode'] = (int)$_POST['isQRCode'];
  38. $json['isRFID'] = (int)$_POST['isRFID'];
  39. $json['QRCodeMadeMode'] = (int)$_POST['QRCodeMadeMode'];
  40. $json['QRCodeContent'] = $_POST['QRCodeContent'];
  41. $json['RfidCardNumEndian'] = $_POST['RfidCardNumEndian'];
  42. $json['PsuAcInputType'] = $_POST['PsuAcInputType'];
  43. // ob_start();
  44. shell_exec('sync;sync;sync');
  45. chdir("/root");
  46. $str_json=json_encode($json);//echo $str_json;exit;
  47. exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
  48. if(count($output)!=0){
  49. $jsone['result'] = "Success";
  50. $jsone['message'] = $json;
  51. echo json_encode($jsone);
  52. exit;
  53. }
  54. else{
  55. $jsone['result'] = "Error";
  56. $jsone['message'] = "Something went wrong on machine";
  57. echo json_encode($jsone);
  58. return false;
  59. exit;
  60. }
  61. // ob_end_clean();
  62. }
  63. function validateDate($date, $format = 'Y-m-d H:i:s')
  64. {
  65. $d = DateTime::createFromFormat($format, $date);
  66. return $d && $d->format($format) == $date;
  67. }
  68. function checkValue($id,$idx){
  69. if($idx==1){
  70. if($_POST[$id]!=""){
  71. if(strlen($_POST[$id])!=1){
  72. $jsone['result'] = "Fail";
  73. $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
  74. echo json_encode($jsone);
  75. exit;
  76. }
  77. if(!ereg("[0-9]",$_POST[$id])){
  78. $jsone['result'] = "Fail";
  79. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  80. echo json_encode($jsone);
  81. exit;
  82. }
  83. }
  84. }
  85. if($idx==2){
  86. if($_POST[$id]!=""){
  87. if(strlen($_POST[$id])!=1){
  88. $jsone['result'] = "Fail";
  89. $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
  90. echo json_encode($jsone);
  91. exit;
  92. }
  93. if(!ereg("[0-1]",$_POST[$id])){
  94. $jsone['result'] = "Fail";
  95. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be 0 or 1";
  96. echo json_encode($jsone);
  97. exit;
  98. }
  99. }
  100. }
  101. // if($idx==2){
  102. // if($_POST[$id]!=""){
  103. // if(strlen($_POST[$id])>2){
  104. // $jsone['result'] = "Fail";
  105. // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  106. // echo json_encode($jsone);
  107. // exit;
  108. // }
  109. // if(!ereg("[0-9]",$_POST[$id]) & !ereg("[0-9]{2}",$_POST[$id])){
  110. // $jsone['result'] = "Fail";
  111. // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  112. // echo json_encode($jsone);
  113. // exit;
  114. // }
  115. // }
  116. // }
  117. }
  118. ?>