set_backend.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. <div class="form-group" style="display:<?php echo $am101;?>">
  103. <label>Ocpp Security Profile</label>
  104. <select class="form-control" id="OcppSecurityProfile" name="OcppSecurityProfile" onchange="OcppSecurityProfile_changed()">
  105. <option value="0" <?php echo $obj->{'OcppSecurityProfile'}=="0"?"selected":""?>>None security</option>
  106. <option value="1" <?php echo $obj->{'OcppSecurityProfile'}=="1"?"selected":""?>>Unsecured Transport with Basic Atuentication</option>
  107. <option value="2" <?php echo $obj->{'OcppSecurityProfile'}=="2"?"selected":""?>>TLS with Basic Authentication</option>
  108. <option value="3" <?php echo $obj->{'OcppSecurityProfile'}=="3"?"selected":""?>>TLS with Client Side Certificates</option>
  109. </select>
  110. </div>
  111. <div id="OcppSecurityPasswordDiv" class="form-group" style="display:<?php echo $am101;?>">
  112. <label>Ocpp Security Password</label>
  113. <input type="text" name="OcppSecurityPassword" id="OcppSecurityPassword" class="form-control" value="<?php echo $obj->{'OcppSecurityPassword'};?>">
  114. </div>
  115. <?php if(substr($ModelName,0,2)=="AX"){?>
  116. <div class="form-group" style="display:block">
  117. <label>Local Loading Balance</label>
  118. <select class="form-control" id="isEnableLocalPowerSharging" name="isEnableLocalPowerSharging" onChange="isEnableLocalPowerSharging_changed()">
  119. <option value="0" <?php echo $obj->{'isEnableLocalPowerSharging'}=="0"?"selected":""?>>disable</option>
  120. <option value="1" <?php echo $obj->{'isEnableLocalPowerSharging'}=="1"?"selected":""?>>enable</option>
  121. </select>
  122. </div>
  123. <?php } ?>
  124. </section>
  125. </article>
  126. <article class="envor-sorting-item css">
  127. <div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
  128. </article>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </section>
  135. </div>
  136. <?php
  137. include 'foot.php';
  138. ?>
  139. <script type="text/JavaScript">
  140. <?php if(substr($ModelName,0,2)=="AX"){?>
  141. $(document).ready(function(){
  142. isEnableLocalPowerSharging_changed();
  143. });
  144. <?php } ?>
  145. OcppSecurityProfile_changed();
  146. document.getElementById("save").onclick = function() {
  147. if(formCheck())
  148. {
  149. window.location="#loadinghref";
  150. document.getElementById("loading").style.display="block";
  151. // 發送 Ajax 查詢請求並處理
  152. var request = new XMLHttpRequest();
  153. request.open("POST", "set_backend_action.php");
  154. // POST 參數須使用 send() 發送
  155. var data = "BackendConnTimeout=" + document.getElementById("BackendConnTimeout").value +
  156. "&OfflinePolicy=" + document.getElementById("OfflinePolicy").value +
  157. "&OfflineMaxChargeEnergy=" + document.getElementById("OfflineMaxChargeEnergy").value+
  158. "&OfflineMaxChargeDuration=" + document.getElementById("OfflineMaxChargeDuration").value+
  159. // "&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
  160. "&OcppServerURL=" + escape(document.getElementById("OcppServerURL").value)+
  161. "&ChargeBoxId=" + escape(document.getElementById("ChargeBoxId").value)+
  162. "&chargePointVendor=" + escape(document.getElementById("chargePointVendor").value)+
  163. "&OcppSecurityProfile=" + document.getElementById("OcppSecurityProfile").value+
  164. "&OcppSecurityPassword=" + escape(document.getElementById("OcppSecurityPassword").value);
  165. <?php if(substr($ModelName,0,2)=="AX"){?>
  166. data += "&isEnableLocalPowerSharging=" + document.getElementById("isEnableLocalPowerSharging").value;
  167. <?php } ?>
  168. // POST 請求必須設置表頭在 open() 下面,send() 上面
  169. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  170. request.send(data);
  171. request.onreadystatechange = function() {
  172. // 伺服器請求完成
  173. if (request.readyState == 4) {
  174. document.getElementById("loading").style.display="none";
  175. // 伺服器回應成功
  176. if (request.status == 200 && JSON.parse(request.responseText).result=="Success") {
  177. alert("<?php echo $lang->showWord("done")?>");
  178. location.href="set_backend.php";
  179. } else {
  180. alert(JSON.parse(request.responseText).message);
  181. }
  182. request = null;
  183. }
  184. }
  185. }
  186. }
  187. function formCheck()
  188. {
  189. var OcppServerURL = document.getElementById("OcppServerURL").value;
  190. var ChargeBoxId = document.getElementById("ChargeBoxId").value;
  191. var chargePointVendor = document.getElementById("chargePointVendor").value;
  192. 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,}))+/;
  193. if(OcppServerURL!=""){
  194. if(OcppServerURL.match(tests)==null){
  195. alert("OcppServerURL format error!");
  196. document.getElementById("OcppServerURL").focus();
  197. return false;
  198. }
  199. }
  200. if(ChargeBoxId!=""){
  201. if(ChargeBoxId.length>25){
  202. alert("Length of ChargeBoxId should be less than 25!");
  203. document.getElementById("ChargeBoxId").focus();
  204. return false;
  205. }
  206. }
  207. if(chargePointVendor!=""){
  208. if(chargePointVendor.length>20){
  209. alert("Length of chargePointVendor should be less than 20!");
  210. document.getElementById("chargePointVendor").focus();
  211. return false;
  212. }
  213. }
  214. return true;
  215. }
  216. function OcppSecurityProfile_changed(){
  217. if(document.getElementById("OcppSecurityProfile").value == "1" || document.getElementById("OcppSecurityProfile").value == "2"){
  218. document.getElementById("OcppSecurityPasswordDiv").style.display="block";
  219. }
  220. else{
  221. document.getElementById("OcppSecurityPasswordDiv").style.display="none";
  222. }
  223. }
  224. <?php if(substr($ModelName,0,2)=="AX"){?>
  225. function isEnableLocalPowerSharging_changed(){
  226. if(document.getElementById("isEnableLocalPowerSharging").selectedIndex==1){
  227. document.getElementById("OcppServerURL").setAttribute("readOnly","true");
  228. document.getElementById("ChargeBoxId").setAttribute("readOnly","true");
  229. document.getElementById("chargePointVendor").setAttribute("readOnly","true");
  230. }
  231. else{
  232. document.getElementById("OcppServerURL").removeAttribute("readOnly");
  233. document.getElementById("ChargeBoxId").removeAttribute("readOnly");
  234. document.getElementById("chargePointVendor").removeAttribute("readOnly");
  235. }
  236. }
  237. <?php } ?>
  238. function isNumberKey(evt)
  239. {
  240. var charCode = (evt.which) ? evt.which : event.keyCode
  241. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  242. return false;
  243. return true;
  244. }
  245. </script>
  246. </html>