set_backend.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. </section>
  97. </article>
  98. <article class="envor-sorting-item css">
  99. <div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
  100. </article>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </section>
  107. </div>
  108. <?php
  109. include 'foot.php';
  110. ?>
  111. <script type="text/JavaScript">
  112. document.getElementById("save").onclick = function() {
  113. if(formCheck())
  114. {
  115. document.getElementById("loading").style.display="block";
  116. // 發送 Ajax 查詢請求並處理
  117. var request = new XMLHttpRequest();
  118. request.open("POST", "set_backend_action.php");
  119. // POST 參數須使用 send() 發送
  120. var data = "BackendConnTimeout=" + document.getElementById("BackendConnTimeout").value +
  121. "&OfflinePolicy=" + document.getElementById("OfflinePolicy").value +
  122. "&OfflineMaxChargeEnergy=" + document.getElementById("OfflineMaxChargeEnergy").value+
  123. "&OfflineMaxChargeDuration=" + document.getElementById("OfflineMaxChargeDuration").value+
  124. // "&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
  125. "&OcppServerURL=" + document.getElementById("OcppServerURL").value+
  126. "&ChargeBoxId=" + document.getElementById("ChargeBoxId").value;
  127. // POST 請求必須設置表頭在 open() 下面,send() 上面
  128. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  129. request.send(data);
  130. request.onreadystatechange = function() {
  131. // 伺服器請求完成
  132. if (request.readyState == 4) {
  133. document.getElementById("loading").style.display="none";
  134. // 伺服器回應成功
  135. if (request.status == 200 && JSON.parse(request.responseText).result=="Success") {
  136. alert("<?php echo $lang->showWord("done")?>");
  137. } else {
  138. alert(JSON.parse(request.responseText).message);
  139. }
  140. request = null;
  141. }
  142. }
  143. }
  144. }
  145. function formCheck()
  146. {
  147. var OcppServerURL = document.getElementById("OcppServerURL").value;
  148. 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,}))+/;
  149. if(OcppServerURL!=""){
  150. if(OcppServerURL.match(tests)==null){
  151. alert("OcppServerURL format error!");
  152. document.getElementById("OcppServerURL").focus();
  153. return false;
  154. }
  155. }
  156. return true;
  157. }
  158. function isNumberKey(evt)
  159. {
  160. var charCode = (evt.which) ? evt.which : event.keyCode
  161. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  162. return false;
  163. return true;
  164. }
  165. </script>
  166. </html>