set_backend.php 7.6 KB

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