set_system_action.php 3.9 KB

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