set_backend.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. <?php if(substr($ModelName,0,2)=="AX"){?>
  150. data += "&isEnableLocalPowerSharging=" + document.getElementById("isEnableLocalPowerSharging").value;
  151. <?php } ?>
  152. // POST 請求必須設置表頭在 open() 下面,send() 上面
  153. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  154. request.send(data);
  155. request.onreadystatechange = function() {
  156. // 伺服器請求完成
  157. if (request.readyState == 4) {
  158. document.getElementById("loading").style.display="none";
  159. // 伺服器回應成功
  160. if (request.status == 200 && JSON.parse(request.responseText).result=="Success") {
  161. alert("<?php echo $lang->showWord("done")?>");
  162. location.href="set_backend.php";
  163. } else {
  164. alert(JSON.parse(request.responseText).message);
  165. }
  166. request = null;
  167. }
  168. }
  169. }
  170. }
  171. function formCheck()
  172. {
  173. var OcppServerURL = document.getElementById("OcppServerURL").value;
  174. var ChargeBoxId = document.getElementById("ChargeBoxId").value;
  175. var chargePointVendor = document.getElementById("chargePointVendor").value;
  176. 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,}))+/;
  177. if(OcppServerURL!=""){
  178. if(OcppServerURL.match(tests)==null){
  179. alert("OcppServerURL format error!");
  180. document.getElementById("OcppServerURL").focus();
  181. return false;
  182. }
  183. }
  184. if(ChargeBoxId!=""){
  185. if(ChargeBoxId.length>25){
  186. alert("Length of ChargeBoxId should be less than 25!");
  187. document.getElementById("ChargeBoxId").focus();
  188. return false;
  189. }
  190. }
  191. if(chargePointVendor!=""){
  192. if(chargePointVendor.length>20){
  193. alert("Length of chargePointVendor should be less than 20!");
  194. document.getElementById("chargePointVendor").focus();
  195. return false;
  196. }
  197. }
  198. return true;
  199. }
  200. <?php if(substr($ModelName,0,2)=="AX"){?>
  201. function isEnableLocalPowerSharging_changed(){
  202. if(document.getElementById("isEnableLocalPowerSharging").selectedIndex==1){
  203. document.getElementById("OcppServerURL").setAttribute("readOnly","true");
  204. document.getElementById("ChargeBoxId").setAttribute("readOnly","true");
  205. document.getElementById("chargePointVendor").setAttribute("readOnly","true");
  206. }
  207. else{
  208. document.getElementById("OcppServerURL").removeAttribute("readOnly");
  209. document.getElementById("ChargeBoxId").removeAttribute("readOnly");
  210. document.getElementById("chargePointVendor").removeAttribute("readOnly");
  211. }
  212. }
  213. <?php } ?>
  214. function isNumberKey(evt)
  215. {
  216. var charCode = (evt.which) ? evt.which : event.keyCode
  217. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  218. return false;
  219. return true;
  220. }
  221. </script>
  222. </html>