set_system_action.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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("Intensity",1);
  30. checkValue("RfidCardNumEndian",1);
  31. checkValue("PsuAcInputType",1);
  32. // $json = json_decode(file_get_contents("system.txt"), true);
  33. if($_POST['SystemId'] != ""){
  34. $json['SystemId'] = $_POST["SystemId"];
  35. }
  36. if($_POST['SystemDateTime'] != ""){
  37. $json['SystemDateTime'] = $_POST['SystemDateTime'];
  38. }
  39. if($_POST['PhaseLossPolicy'] != ""){
  40. $json['PhaseLossPolicy'] = (int)$_POST['PhaseLossPolicy'];
  41. }
  42. if($_POST['FactoryConfiguration'] != ""){
  43. $json['FactoryConfiguration'] = $_POST['FactoryConfiguration'];
  44. }
  45. if($_POST['AuthorisationMode'] != ""){
  46. $json['AuthorisationMode'] = (int)$_POST['AuthorisationMode'];
  47. }
  48. if($_POST['isAPP'] != ""){
  49. $json['isAPP'] = (int)$_POST['isAPP'];
  50. }
  51. if($_POST['isQRCode'] != ""){
  52. $json['isQRCode'] = (int)$_POST['isQRCode'];
  53. }
  54. if($_POST['isRFID'] != ""){
  55. $json['isRFID'] = (int)$_POST['isRFID'];
  56. }
  57. if($_POST['QRCodeMadeMode'] != ""){
  58. $json['QRCodeMadeMode'] = (int)$_POST['QRCodeMadeMode'];
  59. }
  60. if($_POST['QRCodeContent'] != ""){
  61. $json['QRCodeContent'] = $_POST['QRCodeContent'];
  62. }
  63. if($_POST['Intensity'] != ""){
  64. $json['Intensity'] = (int)$_POST['Intensity'];
  65. }
  66. if($_POST['RfidCardNumEndian'] != ""){
  67. $json['RfidCardNumEndian'] = $_POST['RfidCardNumEndian'];
  68. }
  69. if($_POST['PsuAcInputType'] != ""){
  70. $json['PsuAcInputType'] = $_POST['PsuAcInputType'];
  71. }
  72. if($_POST['DDSystemId1'] != ""){
  73. $json['DDSystemId1'] = $_POST["DDSystemId1"];
  74. }
  75. if($_POST['DDFactoryConfiguration1'] != ""){
  76. $json['DDFactoryConfiguration1'] = $_POST['DDFactoryConfiguration1'];
  77. }
  78. if($_POST['DDAuthorisationMode1'] != ""){
  79. $json['DDAuthorisationMode1'] = (int)$_POST['AuthorisationMode1'];
  80. }
  81. if($_POST['DDisAPP1'] != ""){
  82. $json['DDisAPP1'] = (int)$_POST['DDisAPP1'];
  83. }
  84. if($_POST['DDisQRCode1'] != ""){
  85. $json['DDisQRCode1'] = (int)$_POST['DDisQRCode1'];
  86. }
  87. if($_POST['DDisRFID1'] != ""){
  88. $json['DDisRFID1'] = (int)$_POST['DDisRFID1'];
  89. }
  90. if($_POST['DDQRCodeMadeMode1'] != ""){
  91. $json['DDQRCodeMadeMode1'] = (int)$_POST['DDQRCodeMadeMode1'];
  92. }
  93. if($_POST['DDQRCodeContent1'] != ""){
  94. $json['DDQRCodeContent1'] = $_POST['DDQRCodeContent1'];
  95. }
  96. if($_POST['DDIntensity1'] != ""){
  97. $json['DDIntensity1'] = (int)$_POST['DDIntensity1'];
  98. }
  99. if($_POST['DDRfidCardNumEndian1'] != ""){
  100. $json['DDRfidCardNumEndian1'] = $_POST['DDRfidCardNumEndian1'];
  101. }
  102. if($_POST['DDSystemId2'] != ""){
  103. $json['DDSystemId2'] = $_POST["DDSystemId2"];
  104. }
  105. if($_POST['DDFactoryConfiguration2'] != ""){
  106. $json['DDFactoryConfiguration2'] = $_POST['DDFactoryConfiguration2'];
  107. }
  108. if($_POST['DDAuthorisationMode2'] != ""){
  109. $json['DDAuthorisationMode2'] = (int)$_POST['AuthorisationMode2'];
  110. }
  111. if($_POST['DDisAPP2'] != ""){
  112. $json['DDisAPP2'] = (int)$_POST['DDisAPP2'];
  113. }
  114. if($_POST['DDisQRCode2'] != ""){
  115. $json['DDisQRCode2'] = (int)$_POST['DDisQRCode2'];
  116. }
  117. if($_POST['DDisRFID2'] != ""){
  118. $json['DDisRFID2'] = (int)$_POST['DDisRFID2'];
  119. }
  120. if($_POST['DDQRCodeMadeMode2'] != ""){
  121. $json['DDQRCodeMadeMode2'] = (int)$_POST['DDQRCodeMadeMode2'];
  122. }
  123. if($_POST['DDQRCodeContent2'] != ""){
  124. $json['DDQRCodeContent2'] = $_POST['DDQRCodeContent2'];
  125. }
  126. if($_POST['DDIntensity2'] != ""){
  127. $json['DDIntensity2'] = (int)$_POST['DDIntensity2'];
  128. }
  129. if($_POST['DDRfidCardNumEndian2'] != ""){
  130. $json['DDRfidCardNumEndian2'] = $_POST['DDRfidCardNumEndian2'];
  131. }
  132. if($_POST['DDSystemId2'] != ""){
  133. $json['DDSystemId2'] = $_POST["DDSystemId2"];
  134. }
  135. if($_POST['DDFactoryConfiguration2'] != ""){
  136. $json['DDFactoryConfiguration2'] = $_POST['DDFactoryConfiguration2'];
  137. }
  138. if($_POST['DDAuthorisationMode2'] != ""){
  139. $json['DDAuthorisationMode2'] = (int)$_POST['AuthorisationMode2'];
  140. }
  141. if($_POST['DDisAPP2'] != ""){
  142. $json['DDisAPP2'] = (int)$_POST['DDisAPP2'];
  143. }
  144. if($_POST['DDisQRCode2'] != ""){
  145. $json['DDisQRCode2'] = (int)$_POST['DDisQRCode2'];
  146. }
  147. if($_POST['DDisRFID2'] != ""){
  148. $json['DDisRFID2'] = (int)$_POST['DDisRFID2'];
  149. }
  150. if($_POST['DDQRCodeMadeMode2'] != ""){
  151. $json['DDQRCodeMadeMode2'] = (int)$_POST['DDQRCodeMadeMode2'];
  152. }
  153. if($_POST['DDQRCodeContent2'] != ""){
  154. $json['DDQRCodeContent2'] = $_POST['DDQRCodeContent2'];
  155. }
  156. if($_POST['DDIntensity2'] != ""){
  157. $json['DDIntensity2'] = (int)$_POST['DDIntensity2'];
  158. }
  159. if($_POST['DDRfidCardNumEndian2'] != ""){
  160. $json['DDRfidCardNumEndian2'] = $_POST['DDRfidCardNumEndian2'];
  161. }
  162. if($_POST['DDSystemId3'] != ""){
  163. $json['DDSystemId3'] = $_POST["DDSystemId3"];
  164. }
  165. if($_POST['DDFactoryConfiguration3'] != ""){
  166. $json['DDFactoryConfiguration3'] = $_POST['DDFactoryConfiguration3'];
  167. }
  168. if($_POST['DDAuthorisationMode3'] != ""){
  169. $json['DDAuthorisationMode3'] = (int)$_POST['AuthorisationMode3'];
  170. }
  171. if($_POST['DDisAPP3'] != ""){
  172. $json['DDisAPP3'] = (int)$_POST['DDisAPP3'];
  173. }
  174. if($_POST['DDisQRCode3'] != ""){
  175. $json['DDisQRCode3'] = (int)$_POST['DDisQRCode3'];
  176. }
  177. if($_POST['DDisRFID3'] != ""){
  178. $json['DDisRFID3'] = (int)$_POST['DDisRFID3'];
  179. }
  180. if($_POST['DDQRCodeMadeMode3'] != ""){
  181. $json['DDQRCodeMadeMode3'] = (int)$_POST['DDQRCodeMadeMode3'];
  182. }
  183. if($_POST['DDQRCodeContent3'] != ""){
  184. $json['DDQRCodeContent3'] = $_POST['DDQRCodeContent3'];
  185. }
  186. if($_POST['DDIntensity3'] != ""){
  187. $json['DDIntensity3'] = (int)$_POST['DDIntensity3'];
  188. }
  189. if($_POST['DDRfidCardNumEndian3'] != ""){
  190. $json['DDRfidCardNumEndian3'] = $_POST['DDRfidCardNumEndian3'];
  191. }
  192. if($_POST['DDSystemId4'] != ""){
  193. $json['DDSystemId4'] = $_POST["DDSystemId4"];
  194. }
  195. if($_POST['DDFactoryConfiguration4'] != ""){
  196. $json['DDFactoryConfiguration4'] = $_POST['DDFactoryConfiguration4'];
  197. }
  198. if($_POST['DDAuthorisationMode4'] != ""){
  199. $json['DDAuthorisationMode4'] = (int)$_POST['AuthorisationMode4'];
  200. }
  201. if($_POST['DDisAPP4'] != ""){
  202. $json['DDisAPP4'] = (int)$_POST['DDisAPP4'];
  203. }
  204. if($_POST['DDisQRCode4'] != ""){
  205. $json['DDisQRCode4'] = (int)$_POST['DDisQRCode4'];
  206. }
  207. if($_POST['DDisRFID4'] != ""){
  208. $json['DDisRFID4'] = (int)$_POST['DDisRFID4'];
  209. }
  210. if($_POST['DDQRCodeMadeMode4'] != ""){
  211. $json['DDQRCodeMadeMode4'] = (int)$_POST['DDQRCodeMadeMode4'];
  212. }
  213. if($_POST['DDQRCodeContent4'] != ""){
  214. $json['DDQRCodeContent4'] = $_POST['DDQRCodeContent4'];
  215. }
  216. if($_POST['DDIntensity4'] != ""){
  217. $json['DDIntensity4'] = (int)$_POST['DDIntensity4'];
  218. }
  219. if($_POST['DDRfidCardNumEndian4'] != ""){
  220. $json['DDRfidCardNumEndian4'] = $_POST['DDRfidCardNumEndian4'];
  221. }
  222. // ob_start();
  223. shell_exec('sync;sync;sync');
  224. chdir("/root");
  225. $str_json=json_encode($json);//echo $str_json;exit;
  226. exec("'./WebService' '1' '".$str_json."'",$output,$return_var);
  227. if(count($output)!=0){
  228. $jsone['result'] = "Success";
  229. $jsone['message'] = $json;
  230. echo json_encode($jsone);
  231. exit;
  232. }
  233. else{
  234. $jsone['result'] = "Error";
  235. $jsone['message'] = "Something went wrong on machine";
  236. echo json_encode($jsone);
  237. return false;
  238. exit;
  239. }
  240. // ob_end_clean();
  241. }
  242. function validateDate($date, $format = 'Y-m-d H:i:s')
  243. {
  244. $d = DateTime::createFromFormat($format, $date);
  245. return $d && $d->format($format) == $date;
  246. }
  247. function checkValue($id,$idx){
  248. if($idx==1){
  249. if($_POST[$id]!=""){
  250. if(strlen($_POST[$id])!=1){
  251. $jsone['result'] = "Fail";
  252. $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
  253. echo json_encode($jsone);
  254. exit;
  255. }
  256. if(!ereg("[0-9]",$_POST[$id])){
  257. $jsone['result'] = "Fail";
  258. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  259. echo json_encode($jsone);
  260. exit;
  261. }
  262. }
  263. }
  264. if($idx==2){
  265. if($_POST[$id]!=""){
  266. if(strlen($_POST[$id])!=1){
  267. $jsone['result'] = "Fail";
  268. $jsone['message'] = "You have entered a wrong length on " . $id . ", it should be 1 byte";
  269. echo json_encode($jsone);
  270. exit;
  271. }
  272. if(!ereg("[0-1]",$_POST[$id])){
  273. $jsone['result'] = "Fail";
  274. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be 0 or 1";
  275. echo json_encode($jsone);
  276. exit;
  277. }
  278. }
  279. }
  280. // if($idx==2){
  281. // if($_POST[$id]!=""){
  282. // if(strlen($_POST[$id])>2){
  283. // $jsone['result'] = "Fail";
  284. // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  285. // echo json_encode($jsone);
  286. // exit;
  287. // }
  288. // if(!ereg("[0-9]",$_POST[$id]) & !ereg("[0-9]{2}",$_POST[$id])){
  289. // $jsone['result'] = "Fail";
  290. // $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  291. // echo json_encode($jsone);
  292. // exit;
  293. // }
  294. // }
  295. // }
  296. }
  297. ?>