set_charging_action.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. checkLength("LocalWhiteCard0");
  14. checkLength("LocalWhiteCard1");
  15. checkLength("LocalWhiteCard2");
  16. checkLength("LocalWhiteCard3");
  17. checkLength("LocalWhiteCard4");
  18. checkLength("LocalWhiteCard5");
  19. checkLength("LocalWhiteCard6");
  20. checkLength("LocalWhiteCard7");
  21. checkLength("LocalWhiteCard8");
  22. checkLength("LocalWhiteCard9");
  23. checkMaxValue("MaxChargingEnergy");
  24. checkMaxValue("MaxChargingPower");
  25. checkMaxValue("MaxChargingCurrent");
  26. checkMaxValue("AcMaxChargingCurrent");
  27. checkMaxValue("MaxChargingDuration");
  28. if($_POST['MaxChargingEnergy'] != ""){
  29. $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
  30. }
  31. if($_POST['MaxChargingPower'] != ""){
  32. $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
  33. }
  34. if($_POST['MaxChargingCurrent'] != ""){
  35. $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
  36. }
  37. if($_POST['AcMaxChargingCurrent'] != ""){
  38. $json['AcMaxChargingCurrent'] = (int)$_POST['AcMaxChargingCurrent'];
  39. }
  40. if($_POST['MaxChargingDuration'] != ""){
  41. $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
  42. }
  43. if($_POST['LocalWhiteCard0'] != ""){
  44. $json['LocalWhiteCard0'] = isset($_POST['LocalWhiteCard0'])?$_POST['LocalWhiteCard0']:"";
  45. }
  46. if($_POST['LocalWhiteCard1'] != ""){
  47. $json['LocalWhiteCard1'] = isset($_POST['LocalWhiteCard1'])?$_POST['LocalWhiteCard1']:"";
  48. }
  49. if($_POST['LocalWhiteCard2'] != ""){
  50. $json['LocalWhiteCard2'] = isset($_POST['LocalWhiteCard2'])?$_POST['LocalWhiteCard2']:"";
  51. }
  52. if($_POST['LocalWhiteCard3'] != ""){
  53. $json['LocalWhiteCard3'] = isset($_POST['LocalWhiteCard3'])?$_POST['LocalWhiteCard3']:"";
  54. }
  55. if($_POST['LocalWhiteCard4'] != ""){
  56. $json['LocalWhiteCard4'] = isset($_POST['LocalWhiteCard4'])?$_POST['LocalWhiteCard4']:"";
  57. }
  58. if($_POST['LocalWhiteCard5'] != ""){
  59. $json['LocalWhiteCard5'] = isset($_POST['LocalWhiteCard5'])?$_POST['LocalWhiteCard5']:"";
  60. }
  61. if($_POST['LocalWhiteCard6'] != ""){
  62. $json['LocalWhiteCard6'] = isset($_POST['LocalWhiteCard6'])?$_POST['LocalWhiteCard6']:"";
  63. }
  64. if($_POST['LocalWhiteCard7'] != ""){
  65. $json['LocalWhiteCard7'] = isset($_POST['LocalWhiteCard7'])?$_POST['LocalWhiteCard7']:"";
  66. }
  67. if($_POST['LocalWhiteCard8'] != ""){
  68. $json['LocalWhiteCard8'] = isset($_POST['LocalWhiteCard8'])?$_POST['LocalWhiteCard8']:"";
  69. }
  70. if($_POST['LocalWhiteCard9'] != ""){
  71. $json['LocalWhiteCard9'] = isset($_POST['LocalWhiteCard9'])?$_POST['LocalWhiteCard9']:"";
  72. }
  73. if($_POST['isBilling'] != ""){
  74. $json['isBilling'] = (int)$_POST['isBilling'];
  75. }
  76. if($_POST['Currency'] != ""){
  77. $json['Currency'] = (int)$_POST['Currency'];
  78. }
  79. if($_POST['Fee0'] != ""){
  80. $json['Fee0'] = isset($_POST['Fee0'])?round($_POST['Fee0'], 2):"";
  81. }
  82. if($_POST['Fee1'] != ""){
  83. $json['Fee1'] = isset($_POST['Fee1'])?round($_POST['Fee1'], 2):"";
  84. }
  85. if($_POST['Fee2'] != ""){
  86. $json['Fee2'] = isset($_POST['Fee2'])?round($_POST['Fee2'], 2):"";
  87. }
  88. if($_POST['Fee3'] != ""){
  89. $json['Fee3'] = isset($_POST['Fee3'])?round($_POST['Fee3'], 2):"";
  90. }
  91. if($_POST['Fee4'] != ""){
  92. $json['Fee4'] = isset($_POST['Fee4'])?round($_POST['Fee4'], 2):"";
  93. }
  94. if($_POST['Fee5'] != ""){
  95. $json['Fee5'] = isset($_POST['Fee5'])?round($_POST['Fee5'], 2):"";
  96. }
  97. if($_POST['Fee6'] != ""){
  98. $json['Fee6'] = isset($_POST['Fee6'])?round($_POST['Fee6'], 2):"";
  99. }
  100. if($_POST['Fee7'] != ""){
  101. $json['Fee7'] = isset($_POST['Fee7'])?round($_POST['Fee7'], 2):"";
  102. }
  103. if($_POST['Fee8'] != ""){
  104. $json['Fee8'] = isset($_POST['Fee8'])?round($_POST['Fee8'], 2):"";
  105. }
  106. if($_POST['Fee9'] != ""){
  107. $json['Fee9'] = isset($_POST['Fee9'])?round($_POST['Fee9'], 2):"";
  108. }
  109. if($_POST['Fee10'] != ""){
  110. $json['Fee10'] = isset($_POST['Fee10'])?round($_POST['Fee10'], 2):"";
  111. }
  112. if($_POST['Fee11'] != ""){
  113. $json['Fee11'] = isset($_POST['Fee11'])?round($_POST['Fee11'], 2):"";
  114. }
  115. if($_POST['Fee12'] != ""){
  116. $json['Fee12'] = isset($_POST['Fee12'])?round($_POST['Fee12'], 2):"";
  117. }
  118. if($_POST['Fee13'] != ""){
  119. $json['Fee13'] = isset($_POST['Fee13'])?round($_POST['Fee13'], 2):"";
  120. }
  121. if($_POST['Fee14'] != ""){
  122. $json['Fee14'] = isset($_POST['Fee14'])?round($_POST['Fee14'], 2):"";
  123. }
  124. if($_POST['Fee15'] != ""){
  125. $json['Fee15'] = isset($_POST['Fee15'])?round($_POST['Fee15'], 2):"";
  126. }
  127. if($_POST['Fee16'] != ""){
  128. $json['Fee16'] = isset($_POST['Fee16'])?round($_POST['Fee16'], 2):"";
  129. }
  130. if($_POST['Fee17'] != ""){
  131. $json['Fee17'] = isset($_POST['Fee17'])?round($_POST['Fee17'], 2):"";
  132. }
  133. if($_POST['Fee18'] != ""){
  134. $json['Fee18'] = isset($_POST['Fee18'])?round($_POST['Fee18'], 2):"";
  135. }
  136. if($_POST['Fee19'] != ""){
  137. $json['Fee19'] = isset($_POST['Fee19'])?round($_POST['Fee19'], 2):"";
  138. }
  139. if($_POST['Fee20'] != ""){
  140. $json['Fee20'] = isset($_POST['Fee20'])?round($_POST['Fee20'], 2):"";
  141. }
  142. if($_POST['Fee21'] != ""){
  143. $json['Fee21'] = isset($_POST['Fee21'])?round($_POST['Fee21'], 2):"";
  144. }
  145. if($_POST['Fee22'] != ""){
  146. $json['Fee22'] = isset($_POST['Fee22'])?round($_POST['Fee22'], 2):"";
  147. }
  148. if($_POST['Fee23'] != ""){
  149. $json['Fee23'] = isset($_POST['Fee23'])?round($_POST['Fee23'], 2):"";
  150. }
  151. // ob_start();
  152. shell_exec('sync;sync;sync');
  153. chdir("/root");
  154. $str_json=json_encode($json);
  155. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  156. if(count($output)!=0){
  157. $jsone['result'] = "Success";
  158. $jsone['message'] = $json;
  159. echo json_encode($jsone);
  160. exit;
  161. }
  162. else{
  163. $jsone['result'] = "Error";
  164. $jsone['message'] = "Something went wrong on machine";
  165. echo json_encode($jsone);
  166. return false;
  167. exit;
  168. }
  169. // ob_end_clean();
  170. }
  171. function checkMaxValue($id){
  172. if($_POST[$id] != ""){
  173. if(!is_numeric($_POST[$id])){
  174. $jsone['result'] = "Fail";
  175. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  176. echo json_encode($jsone);
  177. exit;
  178. }
  179. if($_POST[$id]>65535){
  180. $jsone['result'] = "Fail";
  181. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  182. echo json_encode($jsone);
  183. exit;
  184. }
  185. if($_POST[$id]<0){
  186. $jsone['result'] = "Fail";
  187. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  188. echo json_encode($jsone);
  189. exit;
  190. }
  191. }
  192. }
  193. function checkValue($id){
  194. if($_POST[$id] != ""){
  195. if(strlen($_POST[$id])!=1){
  196. $jsone['result'] = "Fail";
  197. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  198. echo json_encode($jsone);
  199. exit;
  200. }
  201. if(!ereg("[0-9]",$_POST[$id])){
  202. $jsone['result'] = "Fail";
  203. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  204. echo json_encode($jsone);
  205. exit;
  206. }
  207. }
  208. }
  209. function checkLength($id){
  210. if($_POST[$id] != ""){
  211. if(strlen($_POST[$id])>32){
  212. $jsone['result'] = "Fail";
  213. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
  214. echo json_encode($jsone);
  215. exit;
  216. }
  217. }
  218. }
  219. ?>