set_system_action.php 3.1 KB

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