set_backend.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. <div id="loading" style="display:none;"><img src="img/giphy.gif"/></div>
  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>BackendConnTimeout</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>OfflinePolicy</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>OfflineMaxChargeEnergy</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>OfflineMaxChargeDuration</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>OcppConnStatus</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>OcppServerURL</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>ChargeBoxId</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>chargePointVendor</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. document.getElementById("loading").style.display="block";
  120. // 發送 Ajax 查詢請求並處理
  121. var request = new XMLHttpRequest();
  122. request.open("POST", "set_backend_action.php");
  123. // POST 參數須使用 send() 發送
  124. var data = "BackendConnTimeout=" + document.getElementById("BackendConnTimeout").value +
  125. "&OfflinePolicy=" + document.getElementById("OfflinePolicy").value +
  126. "&OfflineMaxChargeEnergy=" + document.getElementById("OfflineMaxChargeEnergy").value+
  127. "&OfflineMaxChargeDuration=" + document.getElementById("OfflineMaxChargeDuration").value+
  128. // "&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
  129. "&OcppServerURL=" + document.getElementById("OcppServerURL").value+
  130. "&ChargeBoxId=" + document.getElementById("ChargeBoxId").value+
  131. "&chargePointVendor=" + document.getElementById("chargePointVendor").value;
  132. // POST 請求必須設置表頭在 open() 下面,send() 上面
  133. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  134. request.send(data);
  135. request.onreadystatechange = function() {
  136. // 伺服器請求完成
  137. if (request.readyState == 4) {
  138. document.getElementById("loading").style.display="none";
  139. // 伺服器回應成功
  140. if (request.status == 200 && JSON.parse(request.responseText).result=="Success") {
  141. alert("<?php echo $lang->showWord("done")?>");
  142. } else {
  143. alert(JSON.parse(request.responseText).message);
  144. }
  145. request = null;
  146. }
  147. }
  148. }
  149. }
  150. function formCheck()
  151. {
  152. var OcppServerURL = document.getElementById("OcppServerURL").value;
  153. var ChargeBoxId = document.getElementById("ChargeBoxId").value;
  154. var chargePointVendor = document.getElementById("chargePointVendor").value;
  155. 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,}))+/;
  156. if(OcppServerURL!=""){
  157. if(OcppServerURL.match(tests)==null){
  158. alert("OcppServerURL format error!");
  159. document.getElementById("OcppServerURL").focus();
  160. return false;
  161. }
  162. }
  163. if(ChargeBoxId!=""){
  164. if(ChargeBoxId.length>25){
  165. alert("Length of ChargeBoxId should be less than 25!");
  166. document.getElementById("ChargeBoxId").focus();
  167. return false;
  168. }
  169. }
  170. if(chargePointVendor!=""){
  171. if(chargePointVendor.length>20){
  172. alert("Length of chargePointVendor should be less than 20!");
  173. document.getElementById("chargePointVendor").focus();
  174. return false;
  175. }
  176. }
  177. return true;
  178. }
  179. function isNumberKey(evt)
  180. {
  181. var charCode = (evt.which) ? evt.which : event.keyCode
  182. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  183. return false;
  184. return true;
  185. }
  186. </script>
  187. </html>