set_backend.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. ini_set('error_reporting', E_ALL | E_STRICT);
  3. $tag_header = 'set';
  4. include 'head.php';
  5. $obj = json_decode(trim($output[3]));//var_dump($obj);
  6. $system = json_decode(trim($output[0]));
  7. $ModelName = $system->{'ModelName'};
  8. $OcppConnStatus='';
  9. switch ($obj->{'OcppConnStatus'}){
  10. case 0:
  11. $OcppConnStatus='disconnected';
  12. break;
  13. case 1:
  14. $OcppConnStatus='connected';
  15. break;
  16. }
  17. ?>
  18. <style>
  19. img {
  20. display: block;
  21. margin-left: auto;
  22. margin-right: auto;
  23. }
  24. </style>
  25. <div class="envor-content">
  26. <!--
  27. Page Title start
  28. //-->
  29. <section class="envor-page-title-1" data-stellar-background-ratio="0.5">
  30. <div class="container">
  31. <div class="row">
  32. <div class="col-lg-9 col-md-9 col-sm-9">
  33. <h1><?php echo $lang->showWord("backend"); ?></h1>
  34. </div>
  35. </div>
  36. </div>
  37. <!--
  38. Page Title end
  39. //-->
  40. </section>
  41. <!--
  42. Main Content start
  43. //-->
  44. <a id="loadinghref"><div id="loading" style="display:none;"><img src="img/giphy.gif"/></div></a>
  45. <section class="envor-section">
  46. <div class="container">
  47. <div class="row">
  48. <div class="col-lg-12">
  49. <div class="envor-sorting" id="faq-sorting">
  50. <div class="envor-toggle">
  51. <!--Common Information-->
  52. <article class="envor-sorting-item css">
  53. <header><?php echo $lang->showWord("common_information"); ?><i class="fa fa-plus"></i></header>
  54. <section>
  55. <div class="form-group" style="display:<?php echo $am101;?>">
  56. <label>Backend Connection Timeout</label>
  57. <input type="text" name="BackendConnTimeout" id="BackendConnTimeout" class="form-control" value="<?php echo $obj->{'BackendConnTimeout'};?>">
  58. <small class="form-text text-muted-red">seconds</small>
  59. </div>
  60. <div class="form-group" style="display:<?php echo $am101;?>">
  61. <label>Offline Policy</label>
  62. <select class="form-control" id="OfflinePolicy" name="OfflinePolicy">
  63. <option value="0" <?php echo $obj->{'OfflinePolicy'}=="0"?"selected":""?>>local list</option>
  64. <?php /* <option value="1" <?php echo $obj->{'OfflinePolicy'}=="1"?"selected":""?>>Phihong RFID tag</option>*/?>
  65. <option value="2" <?php echo $obj->{'OfflinePolicy'}=="2"?"selected":""?>>free charging</option>
  66. <option value="3" <?php echo $obj->{'OfflinePolicy'}=="3"?"selected":""?>>no charging</option>
  67. </select>
  68. </div>
  69. <div class="form-group" style="display:<?php echo $am101;?>">
  70. <label>Offline Max Charge Energy</label>
  71. <small class="form-text text-muted-red">kWh</small>
  72. <input type="text" name="OfflineMaxChargeEnergy" id="OfflineMaxChargeEnergy" class="form-control" value="<?php echo $obj->{'OfflineMaxChargeEnergy'};?>">
  73. </div>
  74. <div class="form-group" style="display:<?php echo $am101;?>">
  75. <label>Offline Max Charge Duration</label>
  76. <small class="form-text text-muted-red">minutes</small>
  77. <input type="text" name="OfflineMaxChargeDuration" id="OfflineMaxChargeDuration" class="form-control" value="<?php echo $obj->{'OfflineMaxChargeDuration'};?>">
  78. </div>
  79. </section>
  80. </article>
  81. <!--OCPP Backend-->
  82. <article class="envor-sorting-item css">
  83. <header><?php echo $lang->showWord("OCPP_backend"); ?><i class="fa fa-plus"></i></header>
  84. <section>
  85. <div class="form-group" style="display:<?php echo $am101;?>">
  86. <label>Ocpp Connection Status</label>
  87. <input type="text" readonly class="form-control" placeholder="<?php echo $OcppConnStatus;?>">
  88. <input type="hidden" name="OcppConnStatus" id="OcppConnStatus" value="<?php echo $obj->{'OcppConnStatus'};?>">
  89. </div>
  90. <div class="form-group" style="display:<?php echo $am101;?>">
  91. <label>Central System URL</label>
  92. <input type="text" name="OcppServerURL" id="OcppServerURL" class="form-control" value="<?php echo $obj->{'OcppServerURL'};?>">
  93. </div>
  94. <div class="form-group" style="display:<?php echo $am101;?>">
  95. <label>Charge Box Id</label>
  96. <input type="text" name="ChargeBoxId" id="ChargeBoxId" class="form-control" value="<?php echo $obj->{'ChargeBoxId'};?>">
  97. </div>
  98. <div class="form-group" style="display:<?php echo $am101;?>">
  99. <label>Charge Point Vendor</label>
  100. <input type="text" name="chargePointVendor" id="chargePointVendor" class="form-control" value="<?php echo $obj->{'chargePointVendor'};?>">
  101. </div>
  102. <?php if(substr($ModelName,0,2)=="AX"){?>
  103. <div class="form-group" style="display:block">
  104. <label>Local Loading Balance</label>
  105. <select class="form-control" id="isEnableLocalPowerSharging" name="isEnableLocalPowerSharging" onChange="isEnableLocalPowerSharging_changed()">
  106. <option value="0" <?php echo $obj->{'isEnableLocalPowerSharging'}=="0"?"selected":""?>>disable</option>
  107. <option value="1" <?php echo $obj->{'isEnableLocalPowerSharging'}=="1"?"selected":""?>>enable</option>
  108. </select>
  109. </div>
  110. <?php } ?>
  111. </section>
  112. </article>
  113. <article class="envor-sorting-item css">
  114. <div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
  115. </article>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </section>
  122. </div>
  123. <?php
  124. include 'foot.php';
  125. ?>
  126. <script type="text/JavaScript">
  127. <?php if(substr($ModelName,0,2)=="AX"){?>
  128. $(document).ready(function(){
  129. isEnableLocalPowerSharging_changed();
  130. });
  131. <?php } ?>
  132. document.getElementById("save").onclick = function() {
  133. if(formCheck())
  134. {
  135. window.location="#loadinghref";
  136. document.getElementById("loading").style.display="block";
  137. // 發送 Ajax 查詢請求並處理
  138. var request = new XMLHttpRequest();
  139. request.open("POST", "set_backend_action.php");
  140. // POST 參數須使用 send() 發送
  141. var data = "BackendConnTimeout=" + document.getElementById("BackendConnTimeout").value +
  142. "&OfflinePolicy=" + document.getElementById("OfflinePolicy").value +
  143. "&OfflineMaxChargeEnergy=" + document.getElementById("OfflineMaxChargeEnergy").value+
  144. "&OfflineMaxChargeDuration=" + document.getElementById("OfflineMaxChargeDuration").value+
  145. // "&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
  146. "&OcppServerURL=" + document.getElementById("OcppServerURL").value+
  147. "&ChargeBoxId=" + document.getElementById("ChargeBoxId").value+
  148. "&chargePointVendor=" + document.getElementById("chargePointVendor").value+
  149. "&isEnableLocalPowerSharging=" + document.getElementById("isEnableLocalPowerSharging").value;
  150. // POST 請求必須設置表頭在 open() 下面,send() 上面
  151. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  152. request.send(data);
  153. request.onreadystatechange = function() {
  154. // 伺服器請求完成
  155. if (request.readyState == 4) {
  156. document.getElementById("loading").style.display="none";
  157. // 伺服器回應成功
  158. if (request.status == 200 && JSON.parse(request.responseText).result=="Success") {
  159. alert("<?php echo $lang->showWord("done")?>");
  160. location.href="set_backend.php";
  161. } else {
  162. alert(JSON.parse(request.responseText).message);
  163. }
  164. request = null;
  165. }
  166. }
  167. }
  168. }
  169. function formCheck()
  170. {
  171. var OcppServerURL = document.getElementById("OcppServerURL").value;
  172. var ChargeBoxId = document.getElementById("ChargeBoxId").value;
  173. var chargePointVendor = document.getElementById("chargePointVendor").value;
  174. var tests=/^(ws|wss):\/\/((([0-9]{1,3}\.){3}[0-9]{1,3})|(([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}))+/;
  175. if(OcppServerURL!=""){
  176. if(OcppServerURL.match(tests)==null){
  177. alert("OcppServerURL format error!");
  178. document.getElementById("OcppServerURL").focus();
  179. return false;
  180. }
  181. }
  182. if(ChargeBoxId!=""){
  183. if(ChargeBoxId.length>25){
  184. alert("Length of ChargeBoxId should be less than 25!");
  185. document.getElementById("ChargeBoxId").focus();
  186. return false;
  187. }
  188. }
  189. if(chargePointVendor!=""){
  190. if(chargePointVendor.length>20){
  191. alert("Length of chargePointVendor should be less than 20!");
  192. document.getElementById("chargePointVendor").focus();
  193. return false;
  194. }
  195. }
  196. return true;
  197. }
  198. <?php if(substr($ModelName,0,2)=="AX"){?>
  199. function isEnableLocalPowerSharging_changed(){
  200. if(document.getElementById("isEnableLocalPowerSharging").selectedIndex==1){
  201. document.getElementById("OcppServerURL").setAttribute("readOnly","true");
  202. document.getElementById("ChargeBoxId").setAttribute("readOnly","true");
  203. document.getElementById("chargePointVendor").setAttribute("readOnly","true");
  204. }
  205. else{
  206. document.getElementById("OcppServerURL").removeAttribute("readOnly");
  207. document.getElementById("ChargeBoxId").removeAttribute("readOnly");
  208. document.getElementById("chargePointVendor").removeAttribute("readOnly");
  209. }
  210. }
  211. <?php } ?>
  212. function isNumberKey(evt)
  213. {
  214. var charCode = (evt.which) ? evt.which : event.keyCode
  215. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  216. return false;
  217. return true;
  218. }
  219. </script>
  220. </html>